{**************************************************************************** * Digital Input Sample * * This program constantly talks to the RDI-54 pod, which must be located * * at pod address 00 (non-addressed mode). This program displays all 54 * * digital input bits and all 54 counters. Gate (hi or lo) is selectable. * ****************************************************************************} USES CommDRV, crt; 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 Hex(BB : Word) : String; Var AA, CC : Byte; DD : String; HexTable : String; Begin HexTable := '0123456789ABCDEF'; DD := '00'; DD[2] := HexTable[(BB AND $0F) + 1]; DD[1] := HexTable[((BB AND $F0) SHR 4) + 1]; Hex := DD; End; { MAIN PROGRAM } var Address, error : word; index, nybble, counter, color, value, mask : integer; charhit, key : char; returnStr, msg1, msg2: string; dStr : string[2]; messageStr : string[3]; BEGIN index := 0; nybble := 0; counter := 0; color := 0; value := 0; mask := 0; dStr := '0'; messageStr := ''; ClrScr; WriteLn; WriteLn(' Sample One : Digital Input Sample '); WriteLn; WriteLn('This program displays all 54 digital input bits and all 54 counters'); WriteLn('Pod must be set at address 00 (non-addressed mode) and be in 28800'); WriteLn('communications. No other settings are required.'); WriteLn; Address := AskForBaseAddress('300'); ClrScr; GotoXY(1,4); WriteLn('Board Configuration:'); GotoXY(1,6); WriteLn(' -- Pod must be at address 00, and 28800 baud'); WriteLn(' -- All remaining jumper settings are irrelevant'); GotoXY(1,12); WriteLn('Press any key to continue, or "E" to exit.'); key := ReadKey; if (UpCase(key) = 'E') then Halt; initCommCard(28800, Address); { Setup the 16450 chip } ClrScr; GotoXY(1,3); WriteLn(' Most significant nybble Least significant nybble'); GotoXY(17,7); WriteLn('RDI-54 Sample 1, Digital Inputs and Counters'); GotoXY(8,8); WriteLn('Press SPACE to reset current counter, ENTER to reset all counters.'); GotoXY(30,9); WriteLn('Press ESC to exit.'); repeat writePod(Address,'I'); readPod(Address,returnStr); if (Length(returnStr) = 14) then { make sure read all characters } begin GotoXY(6,5); for nybble := 1 to 14 do begin dStr[1] := returnStr[nybble]; Val('$' + dStr, value, error); mask := $08; for index := 0 to 3 do begin textcolor(7); if (value AND mask) <> 0 then Write('1') else Write('0'); mask := (mask SHR 1); end; { end for (index) loop } Write(' '); end; { end for (nybble) loop } textcolor(color); msg1 := Hex(counter); messageStr := ('c' + msg1 + messageStr); writePod(Address, messageStr); readPod(Address, returnStr); Val('$' + returnStr, value, error); GotoXY(5 + ((counter DIV 9) * 12), 12 + (counter MOD 9)); if (counter = 0) then begin if (color = 7) then color := 2 else color := 7; TextColor(color); end; msg2 := Hex(value); WriteLn(counter:2,' : ',msg2); if (keypressed) then charhit := ReadKey; case charhit of #13 : begin writePod(Address, 'rall'); readPod(Address, returnStr); counter := -1; charhit := #0; end; #32 : begin messageStr := ('r' + msg1 + messageStr); writePod(Address, messageStr); readPod(Address,returnStr); counter := (counter - 1); charhit := #0; end; end; counter := (counter + 1); counter := (counter MOD 54); end; { end if } until charhit = #27; TextColor(7); ClrScr; END.