GPIO Programming
GPIO Programming
Applications of GPIO
• General purpose I/O
• • Driving LEDs, or other indicators
• • Controlling off-chip devices
• • Sensing digital inputs
• When getting started in embedded programming, GPIO (viz. General
Purpose Input Output) pins are important.
• The use of GPIO is not limited to driving LEDS but can be also used for
reading digital signal , generating triggers for external components ,
controlling external devices etc….
• Most of the function oriented pins on lpc214x Microcontrollers are
grouped into ports. lpc2148 has 2 ports viz. Port 0 and Port 1.
• Port 0 is a 32 bit wide I/O port (i.e it can be used for max 32 pins
where each pin refers to a corresponding bit) and has dedicated
direction bits for each of the pins present in the port. 28 out of the 32
pins can be used as bi-directional I/O (digital) pins. Pins P0.24 , P0.26
& P0.27 are unavailable for use and Pin P0.30 can be used as output
pin only.
• Port 1 is also a 32 bit wide I/0 port but Pins 0 to 15 i.e P1.0 –
P1.15 are unavailable for use and this port too has a dedicated
direction bit for each of the usable pins.
Pin connect block
• Allows individual pin configuration.
• The purpose of the Pin connect block is to configure the
microcontroller pins to the desired functions.
• In lpc214x MCUs most of the PINS are Multiplexed i.e. these pins can
be configured to provide different functions.
• The functions of the Pins in Port 0 & 1 can be selected by
manipulating appropriate bits in PINSEL0/1/2 registers.
• assigning ’0′ to these registers forces the corresponding pins to be
used as GPIO
• Since by default all pins are configured as GPIOs we dont need to
explicitly assign zero value to PINSELx registers in GPIO programming.
IO0SET=1<<16;
delay ();
IO0CLR=1<<16;
delay();
}
}
void delay(void)
{
int z, c;
c=0;
for(z=0; z<4000000; z++) // You can edit this as per your needs
{
c++;
}
}