Register Port Access

 
Description


On the LPC2103 (ARMmite, ARMexpress LITE and PRO there is only one 32 bit IO port.  On the LPC2138 in the ARMweb and DINkit, there are 10 additional lines in a second port.   On the LPC17xx of the SuperPRO and PROplus there are 4 ports that have a subset of the 32 pins connected to the outside.

Those are controlled by a DIR register, SET and CLR registers.   The state of the pin can be read at anytime with the PIN register.  Each of these registers consists of 32 bits each bit corresponding to a pin.   When a bit in the DIR register is 1, then that pin is an output.  The state of that output can be controlled by writing a 1 to that bit of the SET register to make it high or 1 to that pin of the CLR register to make it low.   Writing 0s to the SET and CLR registers do not affect those pins.

Example

 

On the SuperPRO and PROplus:

#include <LPC17xx.bas>

' Set port 2 pins 1 through 9 as an output and drive it every other bit high
FIO2DIR = FIO2DIR or ( &H3FE)

FIO2SET = &H2AA
FIO2CLR = &H154

' read value of P2.8 and 9
x = FIO2PIN and &H300

' change bit 9 back to an input
FIO2DIR = FIO2DIR and NOT(1<<9)

On the ARMweb or DINkit:

#include <LPC21xx.bas>   

SCB_SCS  = 3            ' required to enable port1 for firmware before 7.47

' Set port 1 pins 1 through 9 as an output and drive it every other bit high
FIO1DIR = FIO1DIR or ( &H3FE)

FIO1SET = &H2AA
FIO1CLR = &H154

' read value of P1.8 and 9
x = FIO1PIN and &H300

' change bit 9 back to an input
FIO1DIR = FIO1DIR and NOT(1<<9)

Differences from other BASICs

See also