{**************************************************************************** * Pascal SAMPLE: SAMPLE3.PAS * * * * This is a demonstration program to be used with the ad8 A/D * * board. The program will prompt for a D/A channel and a digital value * * to output. Entering a channel > 1 exits the program. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 3 to perform D/A conversions. * * * * Set the IRQ jumper to IRQ5. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program sample3; {$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: Performs digital to analog conversions. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************} var ch : string; v : integer; c : integer; Address : word; BEGIN ClrScr; WriteLn(' SAMPLE3.PAS : AD8-16 D/A OUTPUTS'); WriteLn; WriteLn('This is a demonstration program to be used with the AD8 A/D board.'); WriteLn('The program will prompt for a D/A channel and a digital value to output.'); WriteLn; 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; 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; { Begin the conversion } GotoXY(1,7); WriteLn('Enter DAC number (0 or 1, any other to exit):'); GotoXY(1,9); WriteLn(' Enter number of digital counts (0-255):'); task := 3; { Analog Output Task } while (status = 0) do { loop until driver error } begin GotoXY(48,7); readln(param[1]); { fetch D/A number } if param[1] > 1 then begin ClrScr; halt; { if not 0 or 1 then exit } end; GotoXY(48,9); readln(param[2]); { fetch digital value } call_driver; { go set the DAC } end; END. { main }