[sampleCode] GPIO Macro Definitions

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[sampleCode] GPIO Macro Definitions

463 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by behzat_c on Wed May 18 13:36:30 MST 2011
Hey everyone!

I just wrote those macros for pin input/output assignments and high/low functions. I hope someone can use them.

Any bug reports or comments will be wellcomed!

// GPIO Macro Definitions.

#define p0_high(pin) (LPC_GPIO0->FIOSET = (1 << pin))
#define p0_low(pin) (LPC_GPIO0->FIOCLR = (1 << pin))
#define p0_input(pin) (LPC_GPIO0->FIODIR &= ~(1 << pin))
#define p0_output(pin) (LPC_GPIO0->FIODIR |= (1 << pin))

#define p1_high(pin) (LPC_GPIO1->FIOSET = (1 << pin))
#define p1_low(pin) (LPC_GPIO1->FIOCLR = (1 << pin))
#define p1_input(pin) (LPC_GPIO1->FIODIR &= ~(1 << pin))
#define p1_output(pin) (LPC_GPIO1->FIODIR |= (1 << pin))

#define p2_high(pin) (LPC_GPIO2->FIOSET = (1 << pin))
#define p2_low(pin) (LPC_GPIO2->FIOCLR = (1 << pin))
#define p2_input(pin) (LPC_GPIO2->FIODIR &= ~(1 << pin))
#define p2_output(pin) (LPC_GPIO2->FIODIR |= (1 << pin))

#define p3_high(pin) (LPC_GPIO3->FIOSET = (1 << pin))
#define p3_low(pin) (LPC_GPIO3->FIOCLR = (1 << pin))
#define p3_input(pin) (LPC_GPIO3->FIODIR &= ~(1 << pin))
#define p3_output(pin) (LPC_GPIO3->FIODIR |= (1 << pin))

#define p4_high(pin) (LPC_GPIO4->FIOSET = (1 << pin))
#define p4_low(pin) (LPC_GPIO4->FIOCLR = (1 << pin))
#define p4_input(pin) (LPC_GPIO4->FIODIR &= ~(1 << pin))
#define p4_output(pin) (LPC_GPIO4->FIODIR |= (1 << pin))


--------------------------

I forgot to write, those macros written specially for LPC1769
0 Kudos
3 Replies

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Wed May 18 14:48:05 MST 2011
When using FIOSET and FIOCLR the following is mentioned in UM10360:

"Only bits enabled by 0 in FIOMASK can be altered."

That has caused me trouble before.:)
0 Kudos

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by behzat_c on Wed May 18 14:31:44 MST 2011
OMG!

That is a big one :D I was dealing with the 22. pin and left it hardcoded there.

I'm immediately editing the first post.
0 Kudos

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed May 18 14:11:42 MST 2011
That's a bug:

#define p0_input(pin) (LPC_GPIO0->FIODIR &= ~(1 << 22))

where's my pin :confused:
0 Kudos