{**************************************************************************** * Pascal SAMPLE: SAMPLE2.PAS * * * * This is a demonstration program to be used with the ad8 A/D * * board. The program will perform 80 interrupt driven acquisitions on * * channel 0 and display the results. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 7 to perform and monitor the interrupt process. * * * * Set the IRQ jumper to IRQ5. * * The differential/single ended jumper should be installed to SE. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program sample2; {$L ad8drv} {$F+} USES crt; type param_array = array[1..5] of integer; dat_array = array[1..100] of integer; { all of the parameters passed to the ad8DRV 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; buf : dat_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: display_data -- local routine * * * * PURPOSE: Displays the data from the buffer after interrupts. * * * * INPUT: None. * * * * CALLS: None. * * * * OUTPUT: None. * * * ****************************************************************************} procedure display_data; var k,j,index :integer; begin WriteLn; for j := 0 to 7 do begin for k := 1 to 10 do begin index := j * 10 + k; write(buf[index]:6); end; WriteLn; end; end; { display_data } {**************************************************************************** * FUNCTION: main -- local routine * * * * PURPOSE: Performs data acquisition using interrupts. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************} var ch : string; Address:word; begin ClrScr; WriteLn(' AD8-16 A/D DATA VIA INTERRUPTS'); WriteLn; WriteLn('This is a demonstration program to be used with the ad8 A/D board.'); WriteLn('The program will perform 80 interrupt driven acquisitions on channel 0'); WriteLn('and display the results.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- Single ended mode (bottom pins) (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; { initialize driver } param[1]:= Address; { set base address } param[2] := 1; { 1 = single ended -- 0 = differential} param[3] := 1; { bipolar mode -- 0 would be unipolar } param[4] := 5; { IRQ line as jumpered on the board } call_driver; if status > 0 then halt; task := 7; param[1] := 1; { subtask 1, setup and begin } param[2] := 80; { number of scans desired } param[3] := 0; { channel we wish to scan } param[4] := 1; { gain code we want for the readings } param[5] := ofs(buf[1]); call_driver; if status > 0 then halt; { loop until driver indicates completion of readings } task := 7; param[1] := 2; { select subtask 2, check for completion of interrupts } param[2] := 1; { number of conversion left, is returned here. } while param[2] > 0 do begin call_driver; { sets param[2] to number of scans remaining } if status > 0 then halt; end; display_data; end. { main }