DECLARE SUB CtrMode (addr AS INTEGER, cntr AS ANY, mode AS INTEGER) DECLARE SUB CtrLoad (addr AS INTEGER, counter AS INTEGER, value AS INTEGER) DECLARE FUNCTION AskForBaseAddress (OldOne AS INTEGER) '***************************************************************************** ' This program will set up counter 1 with 100 and 0 with full scale ' (65535), sending out a pulse when reaching zero. ' ' Last Modified On: 2/11/98 ' '****************************************************************************** ADDRESS% = AskForBaseAddress(&H350) 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. 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 ' Enable 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 FUNCTION AskForBaseAddress (OldOne AS INTEGER) Msg$ = "" NewOne% = 0: Success = 0: Dummy% = 0 AddrInputPosX = 0: AddrInputPosY = 0 PRINT "Please enter the Base Address (0000-FFFF) for your card (in hex)" PRINT "or press ENTER for "; HEX$(OldOne%); "." PRINT ">"; AddrInputPosX = POS(0): AddrInputPosY = CSRLIN WHILE Success = 0 LOCATE AddrInputPosY, AddrInputPosX PRINT " " LOCATE AddrInputPosY, AddrInputPosX LINE INPUT Msg$ NewOne% = VAL("&H0" + LEFT$(Msg$, 4)) Success = 1 Dummy% = NewOne% IF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION