{*-------------------------------------------------------------------- * PASCAL LANGUAGE SAMPLE 4 : SAMPLE4.PAS * * Sample program for ACCES AD12-8 A/D Converter/Counter-Timer * demonstrating register level data aquistion from the AD12-8. * * Last Modification : 2/4/98 *-------------------------------------------------------------------} Program Sample4; Uses Crt; Var Base : Word; Done : Boolean; Channel : Byte; Counts : Integer; Volts : Real; i,j : Integer; Function Deci(DS : String) : Word; var BS : String; Er : Integer; DI : Word; begin BS := '$' + DS; Val(BS, DI, Er); Deci := DI; end; Function Hex(BB : Word) : String; var AA, CC : Byte; DD : String; HexTable : String; begin HexTable := '0123456789ABCDEF'; DD := '000'; DD[3] := HexTable[(BB AND $00F) + 1]; DD[2] := HexTable[((BB AND $0F0) SHR 4) + 1]; DD[1] := HexTable[((BB AND $F00) SHR 8) + 1]; Hex := DD; end; 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 Intro; begin clrscr; writeln('Sample 4 AD12-8 ACCES I/O Products Inc.'); writeln; writeln('This sample reads the eight analog inputs from the AD12-8 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 ENTER to set base address.'); readln; ClrScr; Base := AskForBaseAddress('$300'); ClrScr; Writeln; Writeln('Address entered was ', Hex(Base), ' hexidecimal.'); Writeln('Is this the correct address for your configuration? (Y/n)'); if Upcase(ReadKey) = 'N' then begin Writeln; Writeln('Please restart program and enter correct address.'); Halt(1); end; end; {of Intro } Begin Intro; Done := False; while Not Done do begin ClrScr; Writeln(' Channel Counts Volts'); Writeln(' ------- ------ -----'); for Channel := 0 to 7 do begin Port[Base+2] := Channel; { Set channel } for i := 0 to 1000 do ; { Wait for settle count } Port[Base+1] := 0; { Start A/D conversion } j := 0; repeat { Wait for EOC or timeout } Inc(j); until ((Port[Base+2] and $80) < $80) or (j > 1000); Counts := PortW[Base] Shr 4; { Read count data } { Scaling 5v range on 12 bit device = 0.00244v/count } Volts := (Counts-2048)*0.00244; Writeln(Channel:14, Counts:12, Volts:12:3); { Display results } end; { of for Channel } Writeln; { Check if done } Writeln(' Press "E" to exit program'); Writeln(' Press any other key to update readings'); if Upcase(Readkey) = 'E' then Done := True; end; { of while not done } End. { of Sample4 }