We are working on adding builtin functions to access P1 - P4, realistically its
probably still a couple weeks away
In the meantime
#define FIO1DIR (*&H2009 C020)
#define FIO1PIN (*&H2009 C034)
#define FIO1SET (*&H2009 C038)
#define FIO1CLR (*&H2009 C03C)
#define OUTP0(bit) FIO1DIR = FIO1DIR OR (1 << bit)
#define INP0(bit) FIO1DIR = FIO1DIR AND (NOT(1 << bit))
SUB wrP1(bit,value)
if value then FIO1SET = 1 << bit else FIO1CLR = 1 << bit
END SUB
FUNCTION P1(bit)
if FIO1PIN and (1 << bit) then return -1 else return 0
END FUNCTION
Bit banged functions will work on P0.0-P0.31, there's not much need to extend
them to P1-4, but you could easily change the library source to add another
port.
Ports beyond port 0
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: Ports beyond port 0
Since then ports beyond port 0 can be accessed directly with the BASIC firmware support
P0.0 through P0.31 are IO(0) to IO(31)
P1.0 through P1.31 are IO(32) to IO(63)
P2.0 through P2.31 are IO(64) to IO(95)
P4.0 through P4.31 are IO(128) to IO(159)
These also apply to IN(x), OUT(x), DIR(x), HIGH(x) and LOW(x)
There is some penalty for this ease of use, at runtime the firmware has to compare the range of the x to determine which port to use. This adds time to the access.
Also note that IO(x), HIGH(x) and LOW(x) also set the port direction, that takes some additional time.
The fastest way to access a port is directly by reading the register and these are defined in LPC17xx.bas for the PROplus and SuperPRO
P0.0 through P0.31 are IO(0) to IO(31)
P1.0 through P1.31 are IO(32) to IO(63)
P2.0 through P2.31 are IO(64) to IO(95)
P4.0 through P4.31 are IO(128) to IO(159)
These also apply to IN(x), OUT(x), DIR(x), HIGH(x) and LOW(x)
There is some penalty for this ease of use, at runtime the firmware has to compare the range of the x to determine which port to use. This adds time to the access.
Also note that IO(x), HIGH(x) and LOW(x) also set the port direction, that takes some additional time.
The fastest way to access a port is directly by reading the register and these are defined in LPC17xx.bas for the PROplus and SuperPRO
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: Ports beyond port 0
>from the help line
>Question for assigning pins to either input or output;
>If for instance from the DIN Rail Pin Diagrams page 9, Flexible IO's, if I
want to callout P0.17,(I assume this stands for Port (0) Pin 17). as an input, I
would write " Input(17)". Is this correct?
Yes that is correct
>If I am using the High Current Driver from DIN Rail Pin Diagrams page 5, Do I
need to call out any of P1.16 through P1.23 as outputs? If so how do I
distinguish between say P0.17 from flexible IO's and P1.17 from High Current
Drivers? I assume there must be a way since P1.17 can also be configured as
digital IO's.
For simplicity the latest firmware 7.50 on ARM7s or 8.12 on Cortex parts maps
port1 to IO(x) for x=32 to 63.
If you write to an IO(48) that turns P1.16 into an output and sets that pin high
if the assigned value is not 0, or low if it is 0.
This also goes for DIR, IN, INPUT, OUT and OUTPUT keywords.
>Question for assigning pins to either input or output;
>If for instance from the DIN Rail Pin Diagrams page 9, Flexible IO's, if I
want to callout P0.17,(I assume this stands for Port (0) Pin 17). as an input, I
would write " Input(17)". Is this correct?
Yes that is correct
>If I am using the High Current Driver from DIN Rail Pin Diagrams page 5, Do I
need to call out any of P1.16 through P1.23 as outputs? If so how do I
distinguish between say P0.17 from flexible IO's and P1.17 from High Current
Drivers? I assume there must be a way since P1.17 can also be configured as
digital IO's.
For simplicity the latest firmware 7.50 on ARM7s or 8.12 on Cortex parts maps
port1 to IO(x) for x=32 to 63.
If you write to an IO(48) that turns P1.16 into an output and sets that pin high
if the assigned value is not 0, or low if it is 0.
This also goes for DIR, IN, INPUT, OUT and OUTPUT keywords.
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: Ports beyond port 0
Hi everyone,
I am an interrupt newbie, and am looking for a sample for reading all the bits
from P0. The sample provided with SuperPro consists of only P2(10), which I do
not want to use. I have a keypad with 8 pins and I want to use that.
I will appreciate if someone has some code snippet to help me.
Regards,
Chanpreet
I am an interrupt newbie, and am looking for a sample for reading all the bits
from P0. The sample provided with SuperPro consists of only P2(10), which I do
not want to use. I have a keypad with 8 pins and I want to use that.
I will appreciate if someone has some code snippet to help me.
Regards,
Chanpreet
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: Ports beyond port 0
> I am an interrupt newbie, and am looking for a sample for reading all the bits
from P0. The sample provided with SuperPro consists of only P2(10), which I do
not want to use. I have a keypad with 8 pins and I want to use that.
>
For the 17xx and 21xx NXP parts, the IO ports are accessed as 32 bit registers,
with a bit per pin. The default configuration is for the port to be an input.
You can read the state of the pin no matter what the setup (except as A/D) by
reading the PIN register. In BASIC that would be--
#include ' get the register definitions
x = FIO0PIN ' read all 32 bits of port 0
To make the pin an output, write 1 to the corresponding bits in the DIR register
FIO0DIR OR= &H55 ' make P0 pins 0,2,4,6 outputs
The OR= new in the latest compiler is the equivalent of x = x OR &H55
To make an output pin high, write a 1 to the SET register
FIO0SET = &H11 ' make P0 pins 0 and 4 high
To make an output low, write a 1 to the CLR register
FIO0CLR = &H44 ' make P0 pins 2 and 6 low
from P0. The sample provided with SuperPro consists of only P2(10), which I do
not want to use. I have a keypad with 8 pins and I want to use that.
>
For the 17xx and 21xx NXP parts, the IO ports are accessed as 32 bit registers,
with a bit per pin. The default configuration is for the port to be an input.
You can read the state of the pin no matter what the setup (except as A/D) by
reading the PIN register. In BASIC that would be--
#include ' get the register definitions
x = FIO0PIN ' read all 32 bits of port 0
To make the pin an output, write 1 to the corresponding bits in the DIR register
FIO0DIR OR= &H55 ' make P0 pins 0,2,4,6 outputs
The OR= new in the latest compiler is the equivalent of x = x OR &H55
To make an output pin high, write a 1 to the SET register
FIO0SET = &H11 ' make P0 pins 0 and 4 high
To make an output low, write a 1 to the CLR register
FIO0CLR = &H44 ' make P0 pins 2 and 6 low
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: Ports beyond port 0
You can interrupt on port 0 pins in the SuperPRO, PROplus. We haven't tried that yet, but details of the setup are in the NXP User Manual