DECLARE SUB CtrMode (addr AS INTEGER, cntr AS ANY, mode AS INTEGER) DECLARE SUB CtrLoad (addr AS INTEGER, counter AS INTEGER, value AS INTEGER) '***************************************************************************** ' This program will set up counter 1 with 100 and 0 with full scale ' (65535), sending out a pulse when reaching zero. '****************************************************************************** ADDRESS% = &H350 ' The Base address of the watchdog board. CLS PRINT "QuickBasic Sample #1: Use Of Counter/Timer Chip with Watchdog" PRINT "This program demonstrates how to program the 82C54 counter/timer" PRINT "chip on the Watchdog Timer board. The Watchdog address should be set" PRINT "to 350 hex. A keystroke will stop the program." PRINT "Press any key to start." CH$ = INPUT$(1) ' Grab keystroke. outbyte% = INP(ADDRESS% + 7) ' Disable counters CALL CtrMode(ADDRESS%, 0, 3) ' set counter 0 to mode 3 CALL CtrLoad(ADDRESS%, 0, &HFFFF) ' and load it with full scale CALL CtrMode(ADDRESS%, 1, 2) ' set counter 1 to mode 2 CALL CtrLoad(ADDRESS%, 1, &H64) ' and load with 64 hex CALL CtrMode(ADDRESS%, 2, 1) ' set mode on counter 2 OUT ADDRESS + 7, 0 ' Disable counters FOR Times = 1 TO 1000 CALL CtrMode(ADDRESS%, 1, 2) CALL CtrLoad(ADDRESS%, 1, &HFFFF) PRINT "Updating counter 1. Loop number : "; Times LOCATE 6, 1 NEXT Times PRINT PRINT "Waiting for timeout . . ." key$ = "" WHILE ((INP(ADDRESS% + 4) AND 128) = 128) AND (key$ = "") ' Check first bit for near timeout key$ = INKEY$ WEND PRINT IF (key$ = "") THEN PRINT "Watchdog timed out successfully." ELSE PRINT "Timeout aborted!" END SUB CtrLoad (addr AS INTEGER, counter AS INTEGER, value AS INTEGER) OUT addr + counter, value MOD 256 OUT addr + counter, value / 256 END SUB SUB CtrMode (addr AS INTEGER, cntr AS INTEGER, mode AS INTEGER) ctrl% = (cntr * 64) OR &H30 OR (mode * 2) OUT addr + 3, ctrl% END SUB