{*------------------------------------------------------------------- * Sample program for the IDI-48 demonstrating register level access * of input data *------------------------------------------------------------------*} Uses Crt; Const ofs : Array[0..5] of Byte = ( 0,1,2,4,5,6 ); Var Address : word; Prt : Byte; Input : Byte; Data : Byte; Mask : Byte; S : String; C : Char; i : Integer; Valid : Boolean; Done : Boolean; Function Deci(DS : String) : Word; var BS : String; Er : Integer; DI : Word; begin BS := '$' + DS; Val(BS, DI, Er); Deci := DI; end; Function Hex(BB : Word) : String; var AA, CC : Byte; DD : String; HexTable : String; begin HexTable := '0123456789ABCDEF'; DD := '000'; DD[3] := HexTable[(BB AND $00F) + 1]; DD[2] := HexTable[((BB AND $0F0) SHR 4) + 1]; DD[1] := HexTable[((BB AND $F00) SHR 8) + 1]; Hex := DD; end; 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 } Procedure Intro; begin ClrScr; Writeln(' SAMPLE 1.PAS : IDI-48'); Writeln; Writeln('Demonstration program for accessing IDI-48 input data.'); Writeln('Program reads each of the IDI-48''s input ports'' 16 input'); Writeln('channels and displays on/off status of those channels.'); WriteLn; WriteLn; WriteLn; Address:=AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- If you are using the IDI-48 option C card, all mode switches'); WriteLn(' should show OFF.'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Press ENTER to continue.'); ReadLn; ClrScr; end; { of Intro } {*-------------------------------------------------------------------- * Main Program *-------------------------------------------------------------------} Begin Intro; Done := False; Valid := False; While Not Valid do begin ClrScr; WriteLn; WriteLn; WriteLn; Write('Enter the input port to read (0,1,2): '); Prt := Ord(ReadKey) - Ord('0'); if (Prt >= 0) And (Prt <= 2) then Valid := True; end; While (Not Done) do begin ClrScr; GotoXY(32,2); Writeln(' Reading Port ', Prt); GotoXY(32,3); Writeln('Input Status'); GotoXY(32,4); Writeln('----------------'); { Read the first 8 input channels of current port } Data := Port[Address + ofs[2*Prt]]; Mask := 1; for Input := 0 to 7 do begin GotoXY(32,5+Input); if ((Mask And Data) > 0) then Writeln(input:3,' ON ') else Writeln(input:3,' OFF'); Mask := Mask Shl 1; end; { of for input } { Read second 8 input channels for current port } Data := Port[Address + ofs[(2*Prt)+1]]; Mask := 1; for Input := 0 to 7 do begin GotoXY(32,13+Input); if ((Mask And Data) > 0) then Writeln(input+8:3,' ON ') else Writeln(input+8:3,' OFF'); Mask := Mask Shl 1; end; { of for input } Writeln; Writeln; GotoXY(15,24); Writeln('Press "Q" to quit; press any other key to re-read the port'); c := UpCase(ReadKey); if c = 'Q' then Done := True; end { of while not done } End. { of main program }