(**************************************************************************** * PSAMPLE #4: SAMPLE4.PAS * * * * This sample will continuously read the digital input port and display * * the value bit by bit. * * * ****************************************************************************) program sample4; uses dos,crt; var bits:word; i:word; address:word; ch:char; (**************************************************************************** * FUNCTION: AskForBaseAddress * ****************************************************************************) function AskForBaseAddress(OldOne : String) : Word; const Msg : string[4] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (0000-FFFF) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if (error=0) then begin Success := 1; Dummy := NewOne; end else if (Msg = '') then begin GotoXY(AddrInputPosX, AddrInputPosY); WriteLn(OldOne); Msg := OldOne; Success := 1; Val('$' + Msg, Dummy, Error); end; until (Success = 1); AskForBaseAddress := Dummy; end; { end of AskForBaseAddress } (**************************************************************************** * * * FUNCTION: main program - global routine * * * * INPUT: None. * * * * CALLS: None. * * * * OUTPUT: None. * * * ****************************************************************************) begin clrscr; WriteLn(' Pascal SAMPLE #4: SAMPLE4.PAS '); WriteLn(' '); WriteLn(' This sample will continuously read the digital input port and display '); WriteLn(' the value bit by bit. '); WriteLn; WriteLn; Address := AskForBaseAddress('340'); port[Address+1]:=$00; (* tristate the port and set to zero *) port[Address]:=$20; (* initialize the control register *) while not keypressed do begin gotoxy(30,14); for i:=0 to 7 do begin write(ord((port[Address+1] and ($80 shr i))<>0),' '); end;{for} end;{while} ch := readkey; end.