uses crt; {***************************************************************************** * This sample program will sequentially turn on all bits of the relay input * and sequentially turns them off. Each time it sets a new bit, both the * * relay output and the iso input are read and the data displayed. This * demonstrates how to read and write to a port. *} var base:integer; const multiplier : longint = 1193*2; procedure dummy; near; begin end; function readtimer : word; near; var tempword : word; begin asm pushf cli mov al,0h out 43h,al end; dummy; asm in al,40h mov bl,al end; dummy; asm in al,40h mov bh,al not bx popf mov tempword,bx end; readtimer := tempword; end; procedure timer_init; var i : integer; begin for i := 0 to 99 do begin if ((readtimer AND 1) = 0) then begin multiplier := 1193; exit; end; end; end; procedure cdelay(milliseconds : word); var stop : longint; cur, prev : word; begin prev := readtimer; stop := prev + (milliseconds * multiplier); cur := readtimer; while (cur < stop) do begin if (cur < prev) then if (stop > $10000) then stop := stop - $10000; prev := cur; cur := readtimer; end; end; 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 printbits(foo:integer); var i:integer; begin for i:=7 downto 0 do begin if foo and (1 shl i) <> 0 then write('1') else write('0'); end;{for} end;{printbits} var i,dig,opto,out:integer; begin clrscr; writeln('104-IIRO-8 Sample Program.'); writeln('This sample program will sequentially turn on all bits of the relay input'); writeln('and sequentially turns them off. Each time it sets a new bit, both the '); writeln('relay output and the relay input are read and the data displayed. This'); writeln('demonstrates how to read and write to a port, and to use the read back'); writeln('function of the board.'); base:=AskForBaseAddress('300'); gotoxy(1,10); writeln(' RELAY OUTPUT DIGITAL INPUT OPTO INPUT '); writeln(' ------------- ------------- ---------- '); i:=0; repeat dig:=port[base+3]; opto:=port[base+1]; out:=1 shl i; inc(i); i:=i mod 8; port[base+0]:=out; gotoxy(5,12); printbits(out); gotoxy(22,12); printbits(dig); gotoxy(37,12); printbits(opto); cdelay(200); until(keypressed); end.