Specifications

Event Multitasking - 8
parameters and are bits 0, 1 and 2. When the data at the port is ANDed with 7, and the value is 5
(bits 0 and 2 are high and bit 1 is low), the program 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 experiment.
Line 30 actually starts the tasking process.
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
As shown in the example above, START INP enables the task defined by the ON INP statement. Generally, the ON INP
statements are declared at the beginning of the program for document clarity. This also makes the program run 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
CAMBASIC 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 program then jumps to a subroutine, which acts on the key press.
1. ON KEYPAD$ GOSUB tells the program where to branch when a key is pressed. The syntax is:
ON KEYPAD$ GOSUB line/label
The line/label is the beginning of the subroutine to react to the key press. The routine must end with
a RETURN statement. If the line/label are omitted, this task is disabled.
2. KEYPAD$ function returns either a one–character string that has been assigned to each key or the
numerical position of the key. The two variations are:
A$=KEYPAD$(0)
returns a string character to a string variable. The assignment is shown below. A null string is
returned if no key was pressed. This variation is most useful where a single character can be assigned
to match the keypad marking.