Content originally posted in LPCWare by -0o- on Tue Aug 06 11:33:30 MST 2013
I just need some help in understanding each GPIO's location
LPC_GPIO2->FIODIR = 0x000000FF;/* P2.xx defined as Outputs */
based on this simple code above.
this sets P2.0 - P2.13 all to "outputs" right ? as comment indicates.
a gpio can be either output '1' or input '0' only a bit to represent the direction.
if an F fits in a nibble and that F can represent sixteen pins on this controller
then why 0xFF ???
I am really confused...
one F represents something and the other F represents another thing
why is a byte required to represent something a nibble is capable of doing ?
clearly there is a logical reason behind this...
for example if I wanted to set P2.4 as an output or input, will this work ?; 0x000000F4 ???
also ...
LPC_GPIO2->FIOSET = 1 << i;
i know the SET sets a pin to a HIGH or LOW so for example if i = 9
will the microcontroller shift a 1 in the ninth bit ? to make it a HIGH ??
and since only 14 pins are classified as P2 what are the extra zeros in the 0x'000000'FF
what happens if i do this 0xFF000000 or this 0x00F000F0
i know changing them will probably do something or not.. can an expert please explain what each byte or nibble position does..
here is the full code, i really need some detailed explanation
of the GPIO bits..
#include <cr_section_macros.h>
#include <NXP/crp.h>
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
#include "lpc17xx.h"
#include "type.h"
int main (void)
{
uint32_t i, j;
/* SystemClockUpdate() updates the SystemFrequency variable */
SystemClockUpdate();
LPC_GPIO2->FIODIR = 0x000000FF;/* P2.xx defined as Outputs */
LPC_GPIO2->FIOCLR = 0x000000FF;/* turn off all the LEDs */
while(1)
{
for(i = 0; i < 8; i++)
{
LPC_GPIO2->FIOSET = 1 << i;
for(j = 1000000; j > 0; j--);
}
LPC_GPIO2->FIOCLR = 0x000000FF;
for(j = 1000000; j > 0; j--);
}
}
Thanks!