{ ***************************************************************************** * PASCAL LANGUAGE SAMPLE 5: SAMPLE5.PAS * * * * This program demonstrates the use of driver task 20 to read the * * frequency of an unknown TTL waveform. The following pins should * * be jumpered as described below: * * PIN 4 (CLK1) TO PIN 6 (OUT2) * * PIN 5 (OUT1) TO PIN 26 (IP2) AND PIN 21 (GATE0) * * Connect the unknown waveform to PIN 2 (CLK0) and PIN 11 (COMMON) * * * * LAST MODIFICATION: 2/4/98 * * * ***************************************************************************** } USES Crt; {$L A12GDRV.OBJ} {$F+} PROCEDURE a12gdrv(task,param,statcode:integer);EXTERNAL; { These variable MUST be declared as global. They are the ones whose offsets are passed to the A12GDRV routine. If they are not global then the driver will not find their segment. } VAR statcode,task : INTEGER; param : ARRAY[1..5] OF INTEGER; datbuf: ARRAY[0..23] OF INTEGER; 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 } { ***************************************************************************** * FUNCTION: call_driver -- local routine * * * * PURPOSE: Performs the call to the driver package. * * * * INPUT: None. * * * * CALLS: a12gdrv - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ***************************************************************************** } FUNCTION call_driver:INTEGER; VAR char_input : char; BEGIN { this section extracts the offset of the parameters that we will pass to the assembly driver } a12gdrv(ofs(task),ofs(param[1]),ofs(statcode)); { this section checks for an error code } call_driver := statcode; if statcode > 0 then begin WriteLn('TASK ',task,' has returned an error code of ',statcode,'.'); WriteLn('Press ''C'' to continue, any other key to exit.'); Char_Input := UpCase(Readkey); If Char_Input = 'C' Then call_driver := 0 Else call_driver := statcode; end; END; { end call_driver } { ***************************************************************************** * FUNCTION: setup -- local routine * * * * PURPOSE: Sets up the driver package. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * * * ***************************************************************************** } FUNCTION setup:INTEGER; VAR I,status:INTEGER; Address : WORD; ch : CHAR; BEGIN ClrScr; WriteLn(' SAMPLE5.PAS : AD12-8G MEASURE FREQUENCY'); WriteLn; WriteLn(' This sample demonstrates the use task 20 to measure the frequency'); WriteLn('of an unknown TTL waveform.'); WriteLn; Address := AskForBaseAddress('350'); ClrScr; WriteLn; WriteLn; WriteLn; WriteLn('Board Configuration:'); WriteLn; WriteLn(' -- Jumper IRQ5 should be installed (required)'); WriteLn(' -- The following pins should be jumpered: (required)'); WriteLn(' PIN 4 (CLK) TO PIN 6 (OUT 2)'); WriteLn(' PIN 5 (OUT1) TO PIN 26 (IP2) AND PIN 21 (GATE0)'); WriteLn(' -- Connect the unknown waverform to PIN 2 (CLK0) and PIN 11 (COMMON)'); WriteLn(' -- All remaining jumper settings are irrelevant'); WriteLn; WriteLn; WriteLn; WriteLn; WriteLn('Please press any key to run the program.'); while not keypressed do; ch := readkey; ClrScr; task := 0; param[1] := Address; { starting board address } param[2] := 5; { IRQ5 } param[3] := 1; { set for programmable gains } status := call_driver; { call routine to call ext module } setup := status; END; { end setup } { ***************************************************************************** * FUNCTION: get_readings -- local routine * * * * PURPOSE: This function calls task 0 to measure the frequency of the * * unknown waveform. * * * * INPUT: None. * * * * CALLS: call_driver - entry point to driver package. * * * * OUTPUT: Returns the error code supplied by the driver routine. * ***************************************************************************** } FUNCTION get_readings:INTEGER; VAR status : INTEGER; freq : REAL; BEGIN task := 20; param[1] := 1000; { Choose a 1000 mS gate pulse } status := call_driver; if status <> 0 then exit; freq := param[2]; WriteLn('The frequency is ',freq:8:2,'.'); get_readings := status; END; { end get_readings } VAR status: INTEGER; ch : char; BEGIN status := setup; { set up program and the driver } if (status <> 0) then exit; { is status > 0 then board error } repeat WriteLn; status := get_readings; { display current A/D values } if (status <> 0) then exit; { if status > 0 then error } { check for program exit } WriteLn('Press E to exit the program. Press any other key to rescan the data...'); while not keypressed do; { wait for key press } ch := readkey; { read the char } until ((ch = 'E') OR (ch = 'e')); END. { end main program }