{**************************************************************************** * Pascal SAMPLE: SAMPLE5.PAS * * * * This is a demonstration program to be used with the ad8 A/D * * board. The program will constantly read the digital input until a * * key is pressed. When a key is pressed the program exits. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 2 to read digital I/O. * * * * Set the IRQ jumper to IRQ5. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program sample5; {$L ad8drv} {$F+} USES crt; type param_array = array[1..5] of integer; { all of the parameters passed to the AD12DRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; param : param_array; procedure ad8drv(t_off:word;p_off:word;st_off:word);external; 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: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: ad8drv - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; begin ad8drv(ofs(task),ofs(param[1]),ofs(status)); { this section checks for an error code } if status > 0 then begin WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {**************************************************************************** * FUNCTION: main -- local routine * * * * PURPOSE: Inputs data from the digital input bits. * * * * INPUT: None. * * * * CALLS: call_driver * * * * OUTPUT: None. * * * ****************************************************************************} var ch : string; Address : word; BEGIN ClrScr; WriteLn(' SAMPLE5.PAS : AD8-16 DIGITAL DATA'); WriteLn; WriteLn('This is a demonstration program to be used with the AD8 A/D board.'); WriteLn('The program will constantly read the digital input until a key is pressed.'); WriteLn('When a key is pressed the program exits.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- Differential mode inputs (required)'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; WriteLn; WriteLn('Please press any key to run the program.'); while not keypressed do; ch := ReadKey; ClrScr; task := 0; { Setup driver } param[1] := Address; { Assign the Base Address } param[2] := 0; { differential mode inputs, 1 would be S/E } param[3] := 1; { bipolar mode, 0 would be unipolar } param[4] := 5; { IRQ line jumpered on board } call_driver; if status > 0 then halt; GotoXY(1,7); WriteLn('Digital value read:'); WriteLn; WriteLn; WriteLn; WriteLn('Press any key to terminate the program.'); task := 2; { Read digital input task } while keypressed = FALSE do { loop until key is pressed } begin call_driver; { call the driver to read digital } if status > 0 then { if error then exit } begin ClrScr; halt; end; GotoXY(21,7); WriteLn(param[1]); { print the digital value } end; ClrScr; END.