{*************************************************************************** * PASCAL LANGUAGE SAMPLE 1: SAMPLE1.PAS * * * * This is a demonstration program to be used with the AD12-8 A/D * * board. The program will display eight channels of data polled from the* * board using the A12DRV.OBJ driver module supplied with the board. * * * * LAST MODIFICATION: 2/3/98 * * * ***************************************************************************} Program startup; {$L a12drv} {$F+} USES crt; type param_array = array[1..5] of integer; dat_array = array[1..200] of integer; pnt_array = array[1..200] of word; { all of the parameters passed to the A12DRV driver must be declared globally, including the buffers which have their offset passed inside the params array } var task,status : integer; params : param_array; ch : char; pntbuf :pnt_array; datbuf :dat_array; 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 a12drv(t_off:word;p_off:word;st_off:word);external; {*************************************************************************** * PROCEDURE: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a12drv - entry point to driver package. * * * * OUTPUT: None. * * * ***************************************************************************} procedure call_driver; var t_off,p_off,st_off : word; begin { this section extracts the offset of the parameters that we will pass to the assembly driver } t_off := ofs(task); p_off := ofs(params[1]); st_off := ofs(status); status := 0; a12drv(t_off,p_off,st_off); { this section checks for an error code } if status > 0 then begin writeln; WriteLn('A status error code of ',status,' was detected.'); WriteLn('Program terminated.'); end; end; { call_driver } {************************************************************************** * PROCEDURE: setup -- local routine * * * * PURPOSE: Sets up the driver package, and sets the scaling for each of* * the 8 A/D channels. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var I :integer; Address : Word; begin ClrScr; WriteLn('Sample 1 AD12-8'); WriteLn; WriteLn('This sample reads the eight analog inputs from the AD12-8 and '); WriteLn('displays them for you.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- RANGE: 5 Volt Range (required)'); WriteLn(' -- POLARITY: Bipolar (required)'); WriteLn(' -- All remaining jumper settings are irrelevant'); WriteLn; WriteLn; WriteLn; WriteLn('Please press ENTER to continue.'); ReadLn; task := 0; params[1] := 1; { manual initialization } params[2] := Address; { starting board address } params[3] := 5; { IRQ5 -- unused } params[4] := 5; { 5V range } params[5] := 1; { bipolar mode } call_driver; { call routine to call ext module } if status = 0 then begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } { create small delay for fast computers } task := 11; params[1] := 5; params[2] := 10; { set up the driver to scale counts to volts } for I := 0 to 7 do begin task := 10; params[1] := 3; params[2] := I * 16; params[3] := -5000; { -5000 to 5000 is 10 volt bipolar range } params[4] := 5000; { which for this program is +-5V } call_driver; { call routine to call ext module } end; end; task := 11; params[1] := 5; params[2] := 10; call_driver; end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads the 8 A/D channels and displays them on the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I :integer; data :real; begin { now reset the task list index } task := 11; params[1] := 1; call_driver; { call routine to call ext module } if status = 0 then begin task := 8; params[1] := ofs(datbuf[1]); { offset to data buffer } params[2] := ofs(pntbuf[1]); { offset to point bufffer } params[3] := 8; { make 8 readings from point list } params[4] := 0; { number of samples returned here } call_driver; if status = 0 then begin {if status > 0 then error } { now if OK list the data to the screen } ClrScr; WriteLn; WriteLn(' CHANNEL VALUE'); WriteLn(' ------- ------'); for I := 1 to 8 do begin channel := (pntbuf[I] and $FF00) div 256; { upper bits are ch number } data := datbuf[I] * 0.001; { scale millivolts to volts } WriteLn(channel:10,data:12:3); end; end; end; end; { get_readings } {************************************************************************** * PROCEDURE: main -- local routine * * * * PURPOSE: Controls program flow, detects when user is ready to exit. * * * * INPUT: None. * * * * CALLS: setup - set up program and drivers. * * get_readings - read the A/D channels and display. * * * * OUTPUT: None. * * * **************************************************************************} begin ch := ' '; setup; { set up program and the driver } while (status = 0) and (ch <> 'E') and (ch <> 'e') do begin { display current values for the 8 channels } get_readings; if status = 0 then begin { if status > 0 then error } { check for program exit } WriteLn; WriteLn('Press E to exit the program. Press any other key to rescan the data...'); ch:=readkey; { wait for key press } end; end; end. { main program }