Keypad multitasking – Remote Processing CAMBASIC User Manual

Page 197

Advertising
background image

Event Multitasking - 8

40 DELAY .25
50 GOTO 30
60 PRINT "match"
70 RETURN

Line 10 defines the INP task 0 to look at address 2. The bits of interest are set by the seven
param eters and are bits 0, 1 and 2. When the data at the por t is ANDe d with 7, and the value is 5
(bits 0 and 2 are high and bit 1 is low), the progr am branches to line 50.

Line 20 prints the binary representation of the port of interest so that you can see the bits pattern
while you e xperim ent.

Line 30 actually starts the tasking pr ocess.

Line 40 creates a small delay so that the binary string printing is easily readable.

Line 50 repeats the printing.

Line 60 lets you know that an interrupt has occurred.

Using START INP and STOP INP

A s sh o w n i n t he e xa m p le a bo v e, S T A R T IN P e n ab le s th e ta s k d e fi ne d by th e O N I N P st a te m e nt . G e ne r a ll y, t h e O N I N P
statements are declared at the beginning of the program for document clarity. This also makes the program r un faster by
not executing these statements in the body of the program. The START INP executes about three times faster than ON
INP.

The STOP INP halts the task checking, temporarily. It does not change any of the parameters specified by ON INP.
Executing another START INP will reactivate the task.

Tasks can be started and stopped in banks. For example:

10 START INP 0, 1, 4, 5, 7

10 STOP INP 2, 3, 4

KEYPAD MULTITASKING

CAM BASIC has built– in keypad scanner and debounce software. When activated, a keypad is scanned in the
background. When a key press is detected, the system waits 80 mS and tests again. If the key is still pressed, the system
is notified that a valid input exists. The pr ogram then jumps to a subrou tine, w hich acts on the key press.

1.

ON KE YPA D$ GO SUB tells the progra m wher e to branch w hen a key is pressed. The syntax is:

ON KEY PAD $ GO SUB line/label

The line/ label is the beginn ing of the subr outine to re act to the key pr ess. The r outine mu st end with
a RETU RN statement. If the line/label are omitted, this task is disabled.

Advertising