{*************************************************************************** * PASCAL LANGUAGE SAMPLE 3: SAMPLE3.PAS * * * * This is a demonstration program to be used with the AD12-8 A/D * * board and an AIM-16. The program will display the set of data channels* * described by the SETUP.CFG file created by the setup programs. The data* * channels are 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; procedure a12drv(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: 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: Calls the driver to do an auto configuration from the file * * called setup.cfg. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure setup; var I : integer; Address : Word; begin ClrScr; WriteLn('Sample 3 AD12-8'); WriteLn; WriteLn('This sample reads the analog inputs from the AD12-8 and any'); WriteLn('expansion boards, as determined by the SETUP.CFG file.'); WriteLn; WriteLn('Board Configuration Requirements:'); WriteLn; WriteLn('PLEASE SEE FILE: SETUP.CFG'); WriteLn; WriteLn; WriteLn; Address := AskForBaseAddress('350'); 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 } { this is for faster computers, ie 386 or fast 286 } if status = 0 then begin task := 11; params[1] := 5; params[2] :=300; { good delay for a 386 25MHz } call_driver; end; end; { setup } {************************************************************************** * PROCEDURE: get_readings -- local routine * * * * PURPOSE: Reads the 16 points in the point list and displays them on * * the screen. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: None. * * * **************************************************************************} procedure get_readings; var channel,I,gain :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] := 16; { 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 GAIN'); WriteLn(' ------- ------ ----'); for I := 1 to params[4] do begin channel:=(pntbuf[I] and $ff00) div 256; { upper bits = ch number } data := datbuf[i]; gain:=pntbuf[I] and 255; WriteLn(channel:10,datbuf[i]:12,gain:7); 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 program. Any other key to continue...'); ch:=readkey; { wait for key press } end; end; END. { main program }