{**************************************************************************** * PASCAL SAMPLE: SAMPLE1.PAS * * * * This is a demonstration program to be used with the ad8 A/D * * board. The program will perform constant differential conversions of * * all eight channels and display the results. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 1 to perform A/D conversions. * * * * Set the IRQ jumper to IRQ5. * * The differential/single ended jumper should be installed to DIF. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program sample1; {$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,i : 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: Performs a constant scan of 8 differential channels. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************} var ch : string; Address: word; begin ClrScr; WriteLn(' SAMPLE1.PAS : AD8-16 A/D POLLED DATA'); WriteLn; WriteLn('This is a demonstration program to be used with the AD8 A/D board.'); WriteLn('The program will perform constant differential conversions of'); WriteLn('all eight channels and display the results.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Polarity set to bipolar (required)'); WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- The range is from -5 to 5 volts (required)'); WriteLn(' -- Differential mode inputs (required)'); WriteLn(' -- All remaining jumper settings are irrelevant.'); WriteLn; 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; { Begin the acquisition } task := 1; { Analog Input Task } param[2] := 1; { +/- 5V range, 0 would be +/-127mV } i := 0; while keypressed = FALSE do { loop until key is pressed } begin param[1] := i; { channel number to be scanned } call_driver; GotoXY(1,7+i); WriteLn('Channel:',i:2,' value: ',param[3]:4); i := ((I + 1) mod 8); GotoXY(1,17); WriteLn('Press any key to terminate the program.'); end; if status = 0 then clrscr; end. { main }