{*-------------------------------------------------------------------- * C LANGUAGE SAMPLE 0 : * * Sample program for the Analog and Digital I/O card * demonstrating register level data aquistion from the * * Last Modification : 16 May 2002. *------------------------------------------------------------------*} uses Crt; var base : Word; function AskForBaseAddress(OldOne : String) : Word; const Msg : string[8] = '0'; var NewOne, Success, Dummy, Error : Word; AddrInputPosX, AddrInputPosY : Word; begin if (OldOne = 'OLD') then OldOne := Msg; WriteLn('Please enter the Base Address (100-FFFF) for your card (in hex)'); WriteLn('or press ENTER for ', OldOne, '. '); Write('>'); AddrInputPosX := WhereX; AddrInputPosY := WhereY; Success := 0; repeat GotoXY(AddrInputPosX, AddrInputPosY); ClrEol; Readln(Msg); Val('$' + Msg, NewOne, Error); if NewOne >= $100 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; procedure intro; begin clrscr; writeln('Sample 0'); writeln; writeln('This sample reads the sixteen analog inputs and '); writeln('displays them for you.'); writeln; writeln; writeln('Board Configuration Requirements:'); writeln; writeln('RANGE: 5 Volt Range'); writeln('POLARITY: Bipolar'); writeln; writeln('Please press any key to set base address.'); readkey; clrscr; base := AskForBaseAddress('300'); clrscr; end; { end of Intro } var channel, counts, i : integer; volts : real; begin intro; port[base+2] := $F0; { Set scan from Ch0 to Ch15 } clrscr; writeln(' Channel Counts Volts'); writeln(' ------- ------ -----'); repeat repeat port[base] := 0; { Start A/D conversion } i := 0; { Wait for EOC or timeout } while ( ((port[base+8] and $80) = $80) and (i < 32000) ) do i := i+1; if (i >= 32000) then begin { if timeout, display error & quit } channel := port[base] and $0F; writeln('Error: Timeout on channel ', channel); exit; end; { end if } channel := port[base] and $0F; { Get channel number } counts := portw[base] shr 4; { Get channel counts } { Scaling 5v range on 12 bit device = 0.00244v/count } volts := (counts-2048)*0.00244; writeln(channel:14, counts:12, volts:12:3); { Show data } until ((port[base] and $0F) = $0F); { end repeat } until (KeyPressed); end. { end of main }