Remote Processing CAMBASIC User Manual

Page 195

Advertising
background image

Event Multitasking - 6

NOTE:

It is theoretica lly possible for the subrou tine to take so long to execute that a nother 20 00 counts is
reached. In this unlikely case, the subroutine will interrupt itself. CAM BASIC is not recursive.
The effe ct of this is that the seco nd interr upt may c hange var iables that the fir st interru pt has yet to
use. This situation ca n be avoided by care ful progr amm ing and by deta iling the system timing. It is
always a good idea to keep interrupt routines as short as possible.

COUNT Examples

You must do a CONF IG COUN T, O N COU NT and START COUN T 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 cr eate 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 jum per wire between scr ew terminals x and y on the STB– 26. Enter the following
p r o gr a m :

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 co nfigures c ounter 4 so that bit 1 of por t 0 is its input.

Line 30 se ts up an inter rupt ever y 1. 00 seconds tha t calls the subr outine to prin t 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
prom pt.

Line 60 forces the output bit high, which causes the counter input to go high.

Line 70 is a short delay.

Line 80 fo rces the o utput bit and the co unter inpu t low. At this point coun ter, 4 should incr ement.

Line 90 sets up the input loop again.

Advertising