{*------------------------------------------------------------------- * C LANGUAGE SAMPLE 0 * * Sample program for the Analog and Digital I/O card * demonstrating register level data aquistion. * * 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('CHANNEL SELECTION: 16 Channel Single-Ended'); writeln; 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; { Init AD816 to Bip, +/-5v range } port[base+2] := $30; clrscr; writeln(' Channel Counts Volts'); writeln(' ------- ------ -----'); repeat for channel := 0 to 15 do begin { Set Channel } port[base+2] := ((port[base+2] and $F0) + channel); { Reset EOC interrupt } port[base+1] := 0; { Start A/D conversion } port[base] := 0; { Wait for EOC or timeout } i := 0; while ( ((port[base+2] and $80) < $80) and (i <= 1000) ) do i := i + 1; { if timeout display error and exit program } if (i > 1000) then begin writeln('Error: Timeout on channel'); exit; end; { end if } { Get count data } counts := port[base]; { Scaling 5v range on 8 bit device = 0.039 volts/count } volts := (counts - 128) * 0.039; { Show data } writeln(channel:14, counts:12, volts:12:3); end; { end of for channel } writeln(' Press any key to exit program'); until (KeyPressed) { end repeat } end. { end of main }