367
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
io.portnum=2
'select port #2
io.portenabled=&hFF
'this means that every port line's output buffer will
be enabled (&hFF=&b11111111)
'output &h55: port lines 0, 2, 4, and 6 will be at HIGH, 4 remaining lines
will be at LOW (&h55=&b01010101)
io.portstate=&h55
'output another value
op.portstate=0
'configure the port for input and read its state
io.portenabled=0
x=io.portstate
This way of controlling the lines/ports of your device is good when you are going to
manipulate the same line/port repeatedly. Performance is improved because you
select the line/port once and then address this line/port as many times as you
need.
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.
On many devices, a number of I/O lines may be shared with inputs/outputs of
special function blocks (serial ports, etc.). When a special function block is
enabled, I/O lines it uses cannot (should not) be manipulated though the io object.
Line/Port Manipulation Without Pre-selection
I/O line manipulation without pre-selection is good when you need to deal with
several I/O lines at once. For this, use
,
methods. These methods require the line number to be supplied directly, as a
parameter. Therefore, pre-selection with the
property is not necessary.
Moreover, executing these methods leaves the io.num value intact.
Here is an example of a serialized clock/data output. The clock line is
PL_IO_NUM_0 and the data line is PL_IO_NUM_1. Notice how this is implemented
-- clock line is preselected once, then set LOW and HIGH using the
property. Meanwhile, the data line is updated using the io.lineset method. The
variable x supposedly carries a bit of data to be output (where x gets is data is not
shown).
Dim
f
As
Byte
Dim
x
As
low_high
io.num=PL_IO_NUM_0
'pre-select the clock line
For
f=0
To
7
...
'obtain the value of the next bit, put it into x (not shown)
io.state=LOW
'set the clock line LOW (the clock line has already been
preselected)
io.lineset(PL_IO_NUM_1,x)
'output the next data bit
io.state=HIGH
'set the clock line HIGH (the clock line has already been
preselected)
Next
f
Direct port manipulation is achieved using
and
methods.
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.
372
371
371
372
375
374
373