USES Crt; CONST ADDRESS : WORD = $350; { The Base address of the watchdog board. } procedure CtrMode(cntr,mode:byte); var ctrl:byte; begin ctrl := (cntr shl 6) or $30 or (mode shl 1); port[ADDRESS+3] := ctrl; end; procedure LoadCtr(c,val:integer); begin port[ADDRESS+c] := lo(val); port[ADDRESS+c] := hi(val); end; { ****************************************************************************** PROCEDURE set_counter Purpose: This procedure performs the setup operations on the 82C54 counter/ timer chip. ****************************************************************************** } PROCEDURE set_counter; VAR temp,control_word : BYTE; BEGIN temp:=port[ADDRESS+7]; CtrMode(0,3); {program the counters for the REQUIRED modes} CtrMode(1,2); CtrMode(2,1); LoadCtr(0,-1); {-1 is full load value, long reset and high granular} LoadCtr(1,10); END; { End set_counter } VAR read_back : BYTE; loop : WORD; ch : CHAR; aborted : boolean; BEGIN clrscr; writeln('Pascal Sample #1: Use Of Counter/Timer Chip with Watchdog'); writeln('This program demonstrates how to program the 82C54 counter/timer'); writeln('chip on the Watchdog Timer board. The Watchdog address should be set'); writeln('to 350 hex. A keystroke will stop the program.'); writeln; writeln('Press any key to start.'); ch := readkey; { Grab keystroke. } set_counter; { programs counters } port[ADDRESS+7] := 0; { Starts counters counting } for loop := 1 to 1000 do begin CtrMode(1,2); LoadCtr(1,10); {prompt counter 1--don't need to prompt 0} Writeln('Updating counter 1. Loop number : ', loop); GotoXY(1, 7); end; writeln; writeln('Waiting for timeout . . .'); aborted := false; repeat read_back := port[ADDRESS+4]; { load control value } aborted := KeyPressed; until ((aborted) OR ((read_back AND 128) = 0)); { check for bit 0 } writeln; if (aborted) then writeln('Timeout aborted!') else writeln('Watchdog timed out successfully.'); END.