{*------------------------------------------------------------------- * Pascal LANGUAGE SAMPLE 0 * * Sample program for the A/D Converter/Counter-Timer * demonstrating register level data aquistion. * * Last Modification : 16 May 2002. *------------------------------------------------------------------*} program sample0; Uses Crt; 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 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 } const baseaddr : string = '300'; var base : Word; channel, counts : integer; volts : real; i,j : integer; begin clrscr; writeln('Sample 0'); writeln; writeln('This sample reads the eight analog inputs and '); writeln('displays them for you.'); writeln; writeln('Board Configuration Requirements:'); writeln; writeln('RANGE: 5 Volt Range'); writeln('POLARITY: Bipolar'); writeln; writeln; writeln; writeln('Please press any key to set base address.'); readln; clrscr; base := AskForBaseAddress(baseaddr); { end of Intro } clrscr; writeln(' Channel Counts Volts'); writeln(' ------- ------ -----'); {THIS IS THE DATA ACQUISITION SECTION =====================================} repeat GotoXY(1,4); for channel := 0 to 7 do begin port[base+2] := channel; { Set channel } for i := 0 to 32000 do; { Wait for settle count } port[base+1] := 0; { Start A/D conversion } j := 0; { Wait for EOC or timeout } while (((port[base+2] and $80) >= $80) and (j < 32000)) do j := j+1; counts := portw[base] shr 4; { Read count data } { Scaling 5v range on 12 bit device = 0.00244v/count } volts := (counts-2048.0)*0.00244; { Display results } writeln(channel:14,counts:12,volts:12:3); end; {end for} {=======================================================================} writeln(' Press any key to exit program'); until (KeyPressed); { end repeat } end. { end of main }