'Dimension the parameter passing variables and data buffer DIM index%, task%, status%, params%(10) DIM buf%(200) COMMON SHARED params%(), buf%() 'Declare the driver entry point DECLARE SUB ctr5drv (task%, BYVAL params%, status%) DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) CLS PRINT " QSAMPLE1.BAS : INTERRUPT OPERATION " PRINT " " PRINT " This is a demonstration program to be used with the CTR-5 Counter " PRINT " timer board. The program will set up all five counters to count down " PRINT " from a different level, then use interrupts to read the count at a given " PRINT " interval. The results are then displayed on the screen. Note that this " PRINT " program uses segments, which should not be used by anything else. For " PRINT " instance, this program as is cannot be run in the Borland C desktop, or " PRINT " the program will lock up the system. " PRINT " " Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT " Board Configuration: " PRINT PRINT " -- Base Address is "; HEX$(Address%); " hex" PRINT " -- The IRQ5 jumper should be installed (required)" PRINT " -- On board clock should be set to 1 MHz (required)" PRINT " -- An external jumper from pin 1 to pin 30. (required)" PRINT " -- An external jumper from pin 11 to pin 2. (required)" PRINT " -- All remaining jumper settings should not be altered." PRINT : PRINT : PRINT PRINT " Press ENTER to continue" INPUT " "; msg$ ' LAST MODIFICATION: 2/5/98 CLS '***************************************************************************** '* PROCEDURE: main -- local routine * '* * '* PURPOSE: Controls program flow, detects when user is ready to exit. * '* * '* INPUT: None. * '* * '* CALLS: setup - set up program and drivers. * '* getreadings - perform the interrupts * * '***************************************************************************** GOSUB setup 'set up program and the driver ch$ = "" DO UNTIL ch$ = "e" GOSUB getreadings 'do the interrupts ' check for program exit PRINT PRINT PRINT " Press E to exit the program. Press any other key to rescan for data..." ch$ = INPUT$(1) ' read a char from the keyboard LOOP CLS END ' main program '***************************************************************************** '* PROCEDURE: setup -- local routine * '* * '* PURPOSE: Sets up the driver and counter board. * '* * '* INPUT: None. * '* * '* CALLS: calldriver - entry point to driver package. * '* * '***************************************************************************** setup: ' initialize the board params%(1) = Address% ' assign the base address params%(2) = 1 ' FOUT divider ratio = 1 params%(3) = 15 ' FOUT source = F5 params%(4) = 0 ' counter 2 compare disabled params%(5) = 0 ' counter 1 compare disabled params%(6) = 0 ' disable time of day task% = 0 GOSUB calldriver FOR i = 1 TO 5 ' set up each counter params%(1) = i ' counter number params%(2) = 0 ' no gating required params%(3) = 0 ' positive edge counting params%(4) = 11 ' count source = F1 params%(5) = 0 ' disable special gate params%(6) = 0 ' reload from load params%(7) = 1 ' count repetitively params%(8) = 0 ' count binary params%(9) = 0 ' count down params%(10) = 2 ' terminal count toggle task% = 1 GOSUB calldriver task% = 3 ' load counter params%(1) = i ' counter number params%(2) = 1000 * i + 1000 ' number of counts to make GOSUB calldriver NEXT i task% = 2 ' load all counters params%(1) = 2 params%(2) = 1 params%(3) = 1 params%(4) = 1 params%(5) = 1 params%(6) = 1 GOSUB calldriver task% = 2 ' arm the counters params%(1) = 1 params%(2) = 1 params%(3) = 1 params%(4) = 1 params%(5) = 1 params%(6) = 1 GOSUB calldriver RETURN ' end setup '***************************************************************************** '* PROCEDURE: getreadings -- local routine * '* * '* PURPOSE: Reads the data and displays it on the screen. * '* * '* INPUT: None. * '* * '* CALLS: calldriver - entry point to driver package. * '* * '***************************************************************************** getreadings: task% = 7 ' install interrupts params%(1) = 10 ' number of interrupts params%(2) = &H7000 ' these are the segments to params%(3) = &H7100 ' store the readings from params%(4) = &H7200 ' each counter params%(5) = &H7300 params%(6) = &H7400 params%(7) = 0 ' start on IP0 disabled params%(8) = 5 ' IRQ5 used for interrupts GOSUB calldriver ' wait for the interrupts to complete task% = 8 params%(1) = 1 WHILE params%(1) > 0 params%(1) = 0 params%(2) = 0 GOSUB calldriver WEND ' transfer the imformation in the segments for each counter into ' the data array. params%(3) = &H6F00 FOR i = 1 TO 5 ' for each counter index% = (i - 1) * 20 + 1 task% = 9 params%(1) = 10 params%(2) = 0 params%(3) = params%(3) + &H100 params%(4) = VARPTR(buf%(index%)) GOSUB calldriver NEXT i ' display the counter values CLS LOCATE 5, 10 PRINT "PASS CTR 1 CTR 2 CTR 3 CTR 4 CTR 5" LOCATE 6, 10 PRINT "---- ----- ----- ----- ----- -----" FOR i = 1 TO 10 LOCATE 6 + i, 10 PRINT USING "###"; i FOR J = 0 TO 4 index% = J * 20 + i LOCATE 6 + i, ((J + 1) * 10) + 3 PRINT USING "##########"; buf%(index%) NEXT J NEXT i RETURN ' end getreadings '***************************************************************************** '* PROCEDURE: call_driver -- local routine * '* * '* PURPOSE: Performs the call to the driver package. * '* * '* INPUT: None. * '* * '* CALLS: ctr5drv - entry point to driver package. * '* * '***************************************************************************** calldriver: CALL ctr5drv(task%, VARPTR(params%(1)), status%) IF status > 0 THEN ' an error has occured PRINT "A status error code of"; status%; " was detected." PRINT "Program terminated." SYSTEM END IF RETURN 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