DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) 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 CtrRead! (addr AS INTEGER, c AS LONG) DECLARE SUB adinit (baseaddr AS INTEGER) CONST COUNTEROFFSET = &HC CONST CLKSELINT = &H1 'OR to select the internal 1MHz clock, cntr 0 CONST CLKSELEXT = &HFE 'AND to select an external clock CONST ADC0CNTR2 = &H2 'OR to start A/DC conversions from counter 2 CONST ADC1EXTRIG = &H4 'OR to start A/DC conv. from the ext. trigger CONST DISABLECONV = &H6 'AND to clear ADC0 and ADC1 CONST ADCEOCIRQ = &H8 'OR to generate IRQ at A/DC EOC CONST CNTR2IRQ = &H10 'OR to generate IRQ from counter 2 CONST DISABLEIRQ = &HE7 'AND to disable IRQ generation CONST STARTCONV2 = &H20 'OR to allow a 'base+4 read' to start conv. CONST STARTCONV1 = &HDF 'AND to allow a 'base+2 write' to start conv. CONST CNTR1ENABLE = &H40 'OR to enable counter 1, gate1 CONST CNTR2ENABLE = &H80 'OR to enable counter 2, gate2 CONST DISABLECNTR = &H3F 'AND to disable both counters CONST ADCCONTROL = 2 'select ADC chan# (4); gain (2) CLS PRINT "*****************************************************************************" PRINT "* SAMPLE3.C : COUNTER/TIMER *" PRINT "* *" PRINT "* This program will load counter 0 with 100 counts, counter 1 *" PRINT "* with 1000 counts, and counter 2 with 10 counts. *" PRINT "* *" ' * LAST MODIFICATION: May 2, 1996 * ' * * PRINT "*****************************************************************************" baseaddr% = AskForBaseAddress(&H340) CALL adinit(baseaddr%) CALL CtrMode(baseaddr% + COUNTEROFFSET, 0, 3) CALL CtrMode(baseaddr% + COUNTEROFFSET, 1, 3) CALL CtrMode(baseaddr% + COUNTEROFFSET, 2, 3) CALL CtrLoad(baseaddr% + COUNTEROFFSET, 0, 100) CALL CtrLoad(baseaddr% + COUNTEROFFSET, 1, 1000) CALL CtrLoad(baseaddr% + COUNTEROFFSET, 2, 10) CLS WHILE INKEY$ = "" LOCATE 4, 1 PRINT "decrementing between 100 and 0" PRINT "counter 0 = "; USING "#####"; CtrRead(baseaddr% + COUNTEROFFSET, 0) LOCATE 7, 1 PRINT "decrementing between 1000 and 0" PRINT "counter 1 = "; USING "#####"; CtrRead(baseaddr% + COUNTEROFFSET, 1) LOCATE 10, 1 PRINT "decrementing between 10 and 0" PRINT "counter 2 = "; USING "#####"; CtrRead(baseaddr% + COUNTEROFFSET, 2) WEND END SUB adinit (baseaddr AS INTEGER) temp = INP(baseaddr) control% = 0 control% = control% AND DISABLEIRQ control% = control% AND DISABLECONV ' use software to start a conv. control% = control% OR STARTCONV1 ' read base+3 to start a conv. control% = control% OR CLKSELINT ' enable internal clock control% = control% OR CNTR1ENABLE ' enable counter 1 control% = control% OR CNTR2ENABLE ' enable counter 2 OUT baseaddr, control% 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% ELSEIF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION 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 CtrRead! (addr AS INTEGER, c AS LONG) OUT addr + 3, c * 64 temp! = INP(addr + c) temp2! = INP(addr + c) temp2! = temp2! * 128 CtrRead! = temp! + temp2! * 2 END FUNCTION