DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '***************************************************************************** ' 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. ' '***************************************************************************** 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 " PRINT "cause two audible clicks, one for when the counter is enabled, and one" PRINT "for the pulse. There will be a delay of about five minutes between" PRINT "these occurences. A keystroke will stop the program." LOCATE 10, 1 PRINT "COM ADDRESS" ComAdr% = AskForBaseAddress(&H2A8) LOCATE 15, 1 PRINT "WATCHDOG ADDRESS" ADDRESS% = AskForBaseAddress(&H350) CLS PRINT PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(ComAdr%); " hex." PRINT " -- Watchdog Address is "; HEX$(ADDRESS%); " hex." PRINT " -- Disable jumpers should not be jumpered (required)" PRINT " -- Invert jumpers should not be jumpered (required)" PRINT " -- CTR0/CTR2 and CTR0/CTR1 should not be jumpered (required)" 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 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