IO -- for backward compatibility, use INPUT and IN or OUTPUT and OUT
 
Syntax

IO ( expression )
Description


IO is a more complex way to access or control the pins.  When IO (expression) is read, the pin corresponding to expression is converted to an input and the value on that pin is returned.

When assiging a value to IO(expression), 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 bitwise 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, HIGH or LOW.

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, 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 3 corresponds to P0.3

For port pins after Port 0, 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