PORT P0..P4

 
Syntax

Pn ( expression )      '  where n is 0 through 4
Description


Px allows you to read or write individual pins using the NXP assigned port and pin number.  When Pn (expression) is read, the logic state of the pin corresponding to expression is returned.

When assigning a value to Pn(expression), then pin expression is set to that value if that pin has been assigned to be an output by writing to FIOxDIR. 

When read Pn(x) 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 Pn(x) = 0 then the pin becomes low, any other value and the pin becomes high, so Pn(x) =1 and Pn(x) = -1 both set the pin high.

These pin numbers correspond to the port pin assignments from NXP. 

This feature is part of the compiler and requires version 8.04c or later.  It has not been added to the on-chip compiler of the ARMweb.  Access to IO pins using Px commands is optimized by the compiler for the SuperPRO and PROplus.  These do work for the BASICchip, but have not been optimized yet.

Example

 

On the SuperPRO and PROplus:

#include <LPC17xx.bas>

' Set pin 9 as an output and drive it high
FIO1DIR = FIO1DIR OR (1<<9)
P1(9) = 1

P1(9) = NOT (P1(9) and (1 <<9))   ' invert pin P1(9) -- works as you can always read the state of a pin

' read value of P1(8)
x = P1(8)

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

Differences from other BASICs

See also