(***************************************************************************** * This sample program will sequentially turn on all bits of port 0 of the * * IOD64 and then sequentially turn them off. Each time it sets a new bit, * * both port 0 and port 1 are read and the data displayed. This * * demonstrates how to read and write to a port, and to use the read back * * function of the board. * *****************************************************************************) program sample1(input,output); uses crt; (* these are the port address offsets for reading and control of the IRRO-8 *) CONST Port0: word = $300; Port1: word = $301; Control: word = $308; TYPE port_array = array[0..3] of byte; (***************************************************************************** * FUNCTION: signon -- local routine * * PURPOSE: To display an initial sign on message on the screen. * *****************************************************************************) procedure signon; begin ClrScr; GotoXY(16,1); WriteLn(' I O D 6 4 C A R D S A M P L E P R O G R A M '); GotoXY(17,6); WriteLn(' PORT 0 OUTPUT PORT 0 INPUT PORT 1 INPUT'); GotoXY(17,7); WriteLn(' ------------- ------------ ------------ '); GotoXY(27,10); WriteLn(' PRESS ANY KEY TO EXIT PROGRAM '); end; (* signon *) (***************************************************************************** * FUNCTION: write_port_data -- local routine * * PURPOSE: Displays the current port values on the screen. * *****************************************************************************) procedure write_port_data(current:port_array); var x,y,index1,index :word; value :byte; begin x := 20; (* starting x coordinate to write data to screen *) y := 8; (* constant y coordinate to write data to screen *) for index := 0 to 2 do (* for each array member *) begin value := current[index]; for index1 := 0 to 7 do (* for each bit in array member *) begin GotoXY(x,y); if (value mod 2) <> 0 then write('1') else write('0'); value := value div 2; (* roll next display bit *) x:=x+1; end; x:=x+10; end; end; (* write_port_data *) (**************************************************************************** * FUNCTION: AskForBaseAddress * * PURPOSE: Allows the user to input the base address * *****************************************************************************) 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 -- external routine * *****************************************************************************) var current :port_array; shift_left :boolean; ch :char; begin signon; (* print the start up message *) current[0] := 0; shift_left := TRUE; ClrScr; WriteLn(' SAMPLE 1.PAS : IOD-64S'); WriteLn; WriteLn('This sample program will sequentially turn on all bits of port 0 of the'); WriteLn('IOD64 and then sequentially turns them off. Each time it sets a new bit,'); WriteLn('both port 0 and port 1 are read and the data displayed. This'); WriteLn('demonstrates how to read and write to a port, and how to use the read '); WriteLn('back function of the board.'); GotoXY(1,9); Port0 := AskForBaseAddress('300'); Port1 := Port0 + 1; Control := Port0 + 8; ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn('Press a key to continue'); ch := readkey; ClrScr; signon; port[Control]:=$01; while not keypressed do (* loop until key pressed *) begin port[Port0] := current[0]; (* write value to relays *) delay(10); current[1] := port[Port0]; (* read back what we wrote to relays *) current[2] := port[Port1]; (* read the data on opto inputs *) write_port_data(current); (* write new data to screen *) delay(700); (* compute value to turn on/off next bit in line *) if current[0] = 0 then shift_left := TRUE; if current[0] = 255 then shift_left := FALSE; if shift_left then current[0] := current[0] * 2 + 1 else current[0] := (current[0] - 1) div 2; end; ClrScr; end. (* main program *)