GPIO program for LPC812

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

GPIO program for LPC812

945 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by karthigowri on Mon Mar 28 21:33:08 MST 2016
Hi,
  I have LPC812 controller and want to access the GPIO without using existing GPIO functions form LPCOPEN.I tried the coding for generating output from Pin P0_17. But i did not get the output.pls help me..........

My coding is....

void GPIO_Initialize(void)
{
LPC_SYSCTL->SYSAHBCLKCTRL |= 1<<6;   //enable clock for GPIO registers

LPC_SWM->PINENABLE0 |= 0xFFFF;  //Enable default function (GPIO)

LPC_GPIO_PORT->DIR[0] |= ((1<<17));//make pins P0_17 as Output

}

int main()
{
GPIO_Initialize();

while(1)
{
LPC_GPIO_PORT->PIN[0] = 1<<17;  //Set high to pin P0_17
}
}


Labels (1)
0 Kudos
4 Replies

556 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

556 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by IanB on Mon Apr 04 14:27:17 MST 2016
If you need to manipulate one bit at a time, you'll get the smallest code by using the PBYTE registers. There are 18 of them, one for each pin. Writing 0x01 to them sets the output high, writing zero sets it low. Reading gives 0x01 or 0 depending whether the pin is high or low.
0 Kudos

556 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Wed Mar 30 12:20:38 MST 2016

Quote: Wojtkingson

LPC_GPIO_PORT->PIN[0] |= (1<<17); //Set high to pin P0_17
- Read values of port and change only one bit (PIO0_17), which you need.


Or even better, use the SET register:
LPC_GPIO_PORT->SET[0] = (1<<17); //Set high to pin P0_17

(I hope this is correct, I haven't tested it.)
0 Kudos

556 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Wojtkingson on Wed Mar 30 05:46:22 MST 2016
Hi,

I would make these changes:

Remove this from your code. PINENABLE0 affects only pins PI0_0, PIO0_1, PIO0_3, PIO0_2, PIO0_8, PIO0_9, PIO0_5, PIO0_6 So there is no need to do this line of code for PIO0_17, this line of code may cause you some problems.

LPC_SWM->PINENABLE0 |= 0xFFFF; //Enable default function (GPIO)


Change this line of code
LPC_GPIO_PORT->PIN[0] = 1<<17; //Set high to pin P0_17
- You are changing all bits in PORT0 to 0, except PIO0_17 which is set to one
to
LPC_GPIO_PORT->PIN[0] |= (1<<17); //Set high to pin P0_17
- Read values of port and change only one bit (PIO0_17), which you need.
0 Kudos