(**************************************************************************** * Pascal SAMPLE #0: SAMPLE0.PAS * ****************************************************************************) program sample0; Uses Crt; function CheckForBusy(base : word) : boolean; begin CheckForBusy := ((port[base+2] AND $80) = 0); 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 } const baseaddr : string = '340'; var data : word; address : word; timeout:longint; chan:word; begin clrscr; timeout := 655354; writeln('Sample 0'); writeln; writeln('This program will read data from all channels on the A/D card.'); address := AskForBaseAddress(baseaddr); writeln; gotoxy(1,19); writeln('Press any key to exit.'); port[address+2] := 0; port[address+0] := $04; while (NOT KeyPressed) do begin delay(250); gotoxy(1,10); for chan:=0 to 7 do begin timeout := 655354; port[address+2]:=chan; delay(2); port[address+3]:=0; while (NOT CheckForBusy(address) AND (timeout > 0)) do dec(timeout); if timeout=0 then write('A/D timeout') else clreol; data:=portw[address+6]; writeln('Chan',chan:2,' Data Read: ', (data shr 4):4); end;{end for} end;{end while} gotoxy(1,20); end.