'***************************************************************************** ' QuickBasic Language Sample #3 : SAMPLE3.BAS ' ' This program will set up counter 2 to decrement from 101 hex ' sending out a pulse when reaching zero. The value of the ' counter will be read and displayed until zero is reached. Because the ' counter is extremely fast, the program will rarely catch it at zero, ' so execution will end soon after that point is reached. ' '***************************************************************************** DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) Address% = &H350 ' The Base address of the watchdog board. COMADR% = &H2A8 ' The Base Address of the UART chip on the ' board. counterval = &H101 CLS PRINT " SAMPLE 3.BAS : Use Of Counter/Timer Chip" PRINT PRINT "This program demonstrates how to program the 8253-5 counter/timer" PRINT "chip on the Watchdog Timer board. If the card has the optional relay," PRINT "the chip will send a pulse that will trip the relay. This should cause" PRINT "two audible clicks, one for when the counter is enabled, and one for " PRINT "the pulse. There will be a delay of about five minutes between these" PRINT "occurences. The Watchdog circuit can be disabled by installing a" PRINT "jumper at the location marked WDOG. A keystroke will stop the program." LOCATE 11, 1 PRINT "COM ADDRESS" COMADDR% = AskForBaseAddress!(&H2A8) LOCATE 17, 1 PRINT "WATCHDOG ADDRESS" Address% = AskForBaseAddress!(&H350) CLS PRINT PRINT PRINT "Board Configuration:" PRINT PRINT " -- COM base Address is "; HEX$(COMADR%); " hex." PRINT " -- WATCHDOG base Address is "; HEX$(Address%); " hex." PRINT " -- All remaining jumper settings are irrelevant." PRINT : PRINT : PRINT PRINT "Press a key to continue." ch$ = INPUT$(1) CLS OUT COMADR% + 4, 4 ' The output to the relay is ' controlled by a bit in the UART. ' Setting this bit opens the line ' to the relay and causes the first ' click. ' Send new value to the UART. controlword% = &HB0 ' Set counter 2, Read/Load Least Sig Byte ' then Most Sig Byte, Mode 0, binary count OUT Address% + 3, controlword% ' Write control word to the counter ' control register. OUT Address% + 2, &H1 ' Write 101 hex to counter 2 ' register. OUT Address% + 2, &H1 ' Write 101 hex to counter ' 2 register. delay = 1000 DO UNTIL delay = 0 delay = delay - 1 LOOP DO lastvalue = counterval OUT Address% + 3, &H80 ' Counter Latching: Allows for the reading ' of both bytes without halting the counter. readback = INP(Address% + 2) ' Read Least Significant Byte counterval = readback ' Move low byte into storage readback = INP(Address% + 2) ' Read Most Significant Byte counterval = counterval + (readback * 256) LOCATE 1, 1 PRINT "Value read from counter: "; counterval LOCATE 20, 1 PRINT "Press any key to quit..."; LOOP UNTIL (lastvalue < counterval) OR (INKEY$ <> "") IF INKEY$ <> "" THEN ch$ = INPUT$(1) ' Strip keystroke from buffer. 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