{**************************************************************************** * Pascal SAMPLE: SAMPLE4.PAS * * * * This is a demonstration program to be used with the ad8 A/D * * board. The program will prompt for a counter number, a counter mode * * and a load divisor value. A channel number greater than 2 exits. * * * * This program demonstrates the use of task 0 to initialize the driver * * and task 5 to manipulate the counter. * * * * Set the IRQ jumper to IRQ5. * * The counter clk jumper should be installed. * * * * LAST MODIFICATION: 2/4/98 * * * ****************************************************************************} program sample4; {$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 setup and control of the counters. * * * * INPUT: None. * * * * CALLS: call_driver, * * * * OUTPUT: None. * * * ****************************************************************************} var ch : string; Address : word; BEGIN ClrScr; WriteLn(' SAMPLE4.PAS : AD8-16 COUNTER OPERATIONS'); WriteLn; WriteLn('This is a demonstration program to be used with the AD8 A/D board.'); WriteLn('The program will prompt for a counter number, a counter mode and a'); WriteLn('load diviser value. A channel number greater than 2 exits the program.'); 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(' -- The counter clk jumper should be installed (required)'); WriteLn(' -- All remaining jumper settings are irrelevant'); 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; GotoXY(1,7); WriteLn('Enter counter number ( 0 thru 2, any other to exit):'); GotoXY(1,9); WriteLn(' Enter the counter mode(0 - 5):'); GotoXY(1,11); WriteLn(' Enter the counter load value:'); task := 5; { counter Output Task } while status = 0 do { loop until driver error } begin GotoXY(54,7); readln(param[1]); { fetch counter number } if param[1] > 2 then { if not 0 thru 2 then exit } begin ClrScr; halt; end; GotoXY(54,9); readln(param[2]); { fetch counter mode } GotoXY(54,11); readln(param[3]); { fetch counter load value } call_driver; { go set the counter } end; END.