(***************************************************************************** * * * SAMPLE6.PAS : COUNTER/TIMER * * * * This program will acquire data at the rate input to pin 25. * * * *****************************************************************************) program sample6; uses crt; const DEFAULT_ADDRESS='340'; (* returns the 'busy' bit, high = conversion in progress *) function CheckForBusy(base : word) : boolean; begin CheckForBusy := ((port[base+2] AND $80) = $80); end; (**************************************************************************** * FUNCTION: AskForBaseAddress * ****************************************************************************) 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: main program * ****************************************************************************) var data:word; timeout:longint; chan:word; base:integer; ch:char; BEGIN chan := 0; ClrScr; WriteLn(' Pascal SAMPLE #6: SAMPLE6.PAS '); WriteLn(' '); WriteLn('This program will read data from channel 0 on the A/D card'); WriteLn('at the rate input to pin 25 (active low edge to start).'); WriteLn('Therefore, to use this sample, a signal must be provided to this'); WriteLn('pin. It is possible to use the output of the counter, or any'); WriteLn('frequency generator.'); base:= AskForBaseAddress( DEFAULT_ADDRESS); port[base+2]:=chan; (* setup channel and gain (gain code 0, gain of 1) *) port[base+0]:=$F4; while not keypressed do begin timeout:=655354; (* wait for start of conversion *) while (NOT CheckForBusy(base) AND (timeout > 0)) do dec(timeout); (* wait for end of conversion *) while (CheckForBusy(base) AND (timeout > 0)) do dec(timeout); data:=(portw[base+6] SHR 4) AND $0FFF; (* read data from conversion *) gotoxy(10,12+chan); ClrEol; WriteLn('Channel: ',chan,' Data Read: ',data); if (timeout = 0) THEN BEGIN WriteLn('A/D Timeout Error'); WriteLn; END else ClrEol; INC(chan); chan := chan MOD 8; port[base+2]:=chan; (* setup next channel *) END; ch := readkey; gotoxy(1,20); END.