Компютърна периферия

uses CRT;

const LPT = $378; { Bazov port }

LPT_DATA : word = LPT; { LPT data }

LPT_CR : word = LPT + 2; { LPT control register }


LPT_SR : word = LPT + 1; { LPT status register }

{ Ako e prekusnata operaciiata, funciiata shte vurne false }

function WaitForHalfByte : boolean;

var BusySignal : byte;

begin

port[ LPT_DATA ]:= 0;

{ write( '.' );}

repeat

BusySignal:= port[ LPT_SR ] and $80;

until ( BusySignal = 0 ) or ( keypressed );

WaitForHalfByte:= not keypressed;

if keypressed then

readkey;

end;

function ReceiveByte( var data : byte ) : boolean;

var error : boolean;

begin

{Izchakwane za priemane }

error := not WaitForHalfByte;

if not error then

begin

data:= 0;

{Izvlichane na starshata chast ot bajta}

data:= ( port[ LPT_SR ] shl 1 ) and $F0;

{Gotownost za priemane}

port[ LPT_DATA ]:= $10;

delay( 1 );

{Izchakwane}

error:= not WaitForHalfByte;

if not error then

begin

data:= data or ( ( port[ LPT_SR ] shr 3 ) and $0F );

{Gotownost za priemane}

port[ LPT_DATA ]:= $10;

delay( 1 );

end;

end;


ReceiveByte:= not error;

end;

procedure ReceiveBlock( pData : pointer; nMaxData : byte );

var BlockSize : byte;

i : byte;

begin

error:= not ReceiveByte( BlockSize );

if not error then

begin

if BlockSize > nMaxData then

BlockSize:= nMaxData;


for i:= 0 to BlockSize do

Receive

end;

end;

procedure ReceiveFile;

var data : byte;

error : boolean;

begin

write('Wait for file transfer...');

repeat

error:= not ReceiveByte( data );

until error or ( data = $AD );

if not error then

begin

writeln('OK');

end;

end;

procedure chat;

var data : byte;

exitF : boolean;

begin

repeat

exitF:= not ReceiveByte( data );

write( chr( data ) );

until exitF or ( data = 27 );

end;

begin

clrscr;

chat;

end.




Други реферати:
Вирусни хепатити А-В-С-D
Вътреочно налягане
Кръв. Кръвна плазма
АВО хеполитична болест на новороденото
Бронхиектазна болест


Изтегли реферата



Бронхиектазна болест - Facebook Image
Сайтът се поддържа от DH Studio | pomagalo1.com © 2012 | Общи условия