DIR ( expression )

The DIR keyword is for compatibility with PBASIC, and to support multiple ports on newer ARM devices.

DIR (expression) can be used to set or read the direction of the pins.  If DIR (expression) value is 0 then that pin is an input, otherwise for other values the pin is an output.

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(11) corresponds to P0(11)

With version 8.11 of the firmware, ports beyond port 0, can be accessed as 32-63 for port 1, 64-95 for port 2, and so on. 

As of version 8.25-SuperPRO and 8.26-BASICchip of the firmware, using INPUT will also convert AD pins to digital function.  To switch back you would need to program the PINSEL register manually (see the NXP User Manual).


DIR(4) = 0  ' Set pin 4 as an input

DIR(12) = 1   ' Set pin 12 as an output

On the extended ports for the SuperPRO DIR BASIC style use the following

DIR(64+10) = 1       ' makes P2(10) an output

while 1
  P2(10) = x and 1           ' blinky for the SuperPRO and PROplus

Differences from other BASICs

See also