Specifications
Event Multitasking - 6
NOTE: It is theoretically possible for the subroutine to take so long to execute that another 2000 counts is
reached. In this unlikely case, the subroutine will interrupt itself. CAMBASIC is not recursive. The
effect of this is that the second interrupt may change variables that the first interrupt has yet to use.
This situation can be avoided by careful programming and by detailing the system timing. It is
always a good idea to keep interrupt routines as short as possible.
COUNT Examples
You must do a CONFIG COUNT, ON COUNT and START COUNT for each counter you intend to use. You may
reconfigure a counter to another address or to a different condition at any time, as long as the counter has been disabled by
CLEAR COUNT.
The example below lets you get a feel for the operation of the counter while at your desk. You can create output pulses by
pressing keys on your PC. These pulses are then jumpered back into a counter.
The hardware requires a CMA–26 cable and a STB–26. Plug one end of the CMA–26 into the parallel port and the other
end into the STB–26. Place a jumper wire between screw terminals x and y on the STB–26. Enter the following program:
10 CONFIG PIO 0,0,1,0,1,1
20 CONFIG COUNT 4,0,1
30 ON TICK 0,1 GOSUB .. pr_count
40 START COUNT 4
50 INPUT A$
60 BIT 0,1,ON
70 DELAY .05
80 BIT 0,1,OFF
90 GOTO 50
100 ..pr_count
110 PRINT COUNT(4)
120 RETURN
Line 10 configures the 82C55 so that port A is an input port and port B is an output port. It assumes
that the 82C55 is at address 0.
Line 20 configures counter 4 so that bit 1 of port 0 is its input.
Line 30 sets up an interrupt every 1.00 seconds that calls the subroutine to print the count.
Line 40 starts the counter.
Line 50 provides a convenient way to get keyboard input. Just enter <ENTER> when you see the
prompt.
Line 60 forces the output bit high, which causes the counter input to go high.
Line 70 is a short delay.
Line 80 forces the output bit and the counter input low. At this point counter, 4 should increment.
Line 90 sets up the input loop again.
Line 110 prints the count in the counter.
Line 120 returns execution to the place where the one–second interrupt occurred.