369
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
uses may be configured for input or output automatically. For such lines, when the
corresponding special function block is disabled, the state of the output buffer is
restored automatically to what it used to be prior to enabling this function block.
Note that I/O line and port names are platform-specific and are defined by
pl_io_num and pl_io_port_num enums respectively. The declarations for these
enums can be found in the "Platform-dependent Constants" section of your
platform documentation.
Working With Interrupts
Some platforms have a number of I/O lines that can work as interrupt inputs. To
enable a particular interrupt line, select it using the
property and
enable the line with the
property:
'enable interrupt line #0
io.intnum=PL_INT_NUM_0
io.intenabled=YES
Once the line has been enabled, the change in this line's state will generate an
event. The linestate argument of this event is bit-encoded: each bit of
the value represents one interrupt line. For the PL_INT_NUM_0, the corresponding
bit is bit 0, for PL_INT_NUM_1 -- bit 1, and so on. A particular bit of the linestate
argument is set when the state change (from LOW to HIGH, or from HIGH to LOW)
has been detected on the related interrupt line. Event handler for the
event can then determine what triggered the interrupt:
Sub
On
_io_int(linestate
As
Byte
)
'check if it is the interrupt line #0 that has caused the interrupt
If
linestate
And
&h01 <>0
Then
'yes, interrupt has been triggered by the interrupt line #0
...
End
If
End
Sub
Please, note that the word "interrupt" is used here is a somewhat loose sense. On
traditional microcontrollers, interrupt line status change causes a near-
instantaneous pause to the execution of the main code and a jump to an "interrupt
routine". Hence, the term "interrupt" -- the execution of the main code gets
interrupted.
With the io object, the interrupt line state change does not disrupt the execution of
the any event handler or reordering of pending events in the event
. The
event is added to the end of the event queue and is not handled until
all earlier events are processed. Therefore, nothing is actually interrupted. Note
also that there is no guaranteed interrupt response speed here -- the time between
line state change detection and the execution of the
event handler
depends on the number of prior events waiting in the queue and, hence, cannot be
pre-determined with any certainty.
Further, there may be only one on_io_int event waiting in the event queue.
371
370
373
373
7
373
373