
Event Multitasking - 6
NOTE: It is theoretically possible for the subroutine to take so long to execute that another 20 00 counts is
reached. In this unlikely case, the subroutine will interrupt itself. CAM BASIC is not recursive.
The effect of this is that the second interr upt may change var iables that the first interrupt has yet to
use. This situation ca n be avoided by careful progr amming 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 COUN T, ON COU NT 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 hardwar e requires a CM A– 26 cable and a STB– 26. Plug one end of the CM A– 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 c ounter 4 so that bit 1 of port 0 is its input.
Line 30 sets up an interrupt ever y 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 < ENT ER> 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 incr ement.
Line 90 sets up the input loop again.
Comentários a estes Manuais