IO
 
Syntax

IO ( expression )
Description


IO is the simple way to access or control the pins.  When IO (expression) is read or on the right hand side of the = sign , the pin corresponding to expression is converted to an input and the value on that pin is read.

When assigning a value to IO(expression), or on the left hand side of the = sign, then pin expression is converted to an output and the logic value is written to the pin, 0 writes a low level any other value sets the pin high.  When read IO returns a 0 or -1. Why -1 and 0?  The main reason is that operations of operators like NOT are assumed to be bit-wise until there is a Boolean operation in the expression, and NOT 0 is equal to -1.  When setting a pin state with IO(x) = 0 then the pin becomes low, any other value and the pin becomes high, so IO(x) =1 and IO(x) = -1 both set the pin high.

Using IO simplifies pins that are being used as both inputs and outputs.  As it also sets direction it will be slower than IN, OUT, or Px(y)

The ARMmite allows control of 24 pins (0..23), with pins 16..23 shared with the AD pins. On reset or power up the AD pins are configured as AD inputs.  To change those to digital IOs, the user must individually specify a control direction using INPUT(x), OUTPUT(x), DIR(x),  or IO(x) commands.  After that they will remain digital IOs until the next reset or power up. 

For the ARMmite, PRO, ARMexpress and ARMexpress LITE these pin numbers correspond to the pin numbers shown in the Hardware Section. The numbering was assigned by physical location on the board. So DIR, HIGH, IN, INPUT, IO, LOW, OUT and OUTPUT use these physical pin assignments. But P0(pin) will use the bit assigned by NXP. Going forward new board designs will maintain the bit assignment from NXP for all keywords.

For the ARMweb, DINkit, SuperPRO, PROplus and PROstart these pin numbers correspond only to the Port 0 assigned by NXP, for instance DIR(12) corresponds to P0(12)

With version 7.52/8.12 of the firmware, ports beyond port 0, can be accessed as 32-63 for port 1, 64-95 for port 2, and so on. Or you may use the P1 .. P4 commands .

Example

' Set pin 9 as an output and drive it high
IO(9) = 1

IO(9) = NOT IN(9)   ' invert pin DO NOT USE IO(9) as that would be ambiguous for controlling the direction of the pin

' Set pin 8 as an input and reads its value
x = IO(8)


Differences from other BASICs

See also