LPC2148 – GPIO Tutorial

Hi all, Now we are going to see LPC2148 GPIO Tutorial. Before that please read the Introduction of LPC2148.

Before going to GPIO Registers, We should know about PINSEL register.

LPC2148 GPIO Tutorial

PINSEL Register

A 32 bit register which is used to select the function of the pins in which the user needs it to operate. As i said there are four functions for each pins of the controller, in which the first function one was GPIO ( General Purpose Input Output ). It means that the pin can either act as a Input or Output with no specific functions. 

There are totally three PINSEL register in LPC2148 Controller in order to control the functions of the Pins in the respective ports. The classification is given below

PINSEL0 – Controls functions of Port0.0 – Port0.15

PINSEL1 – Controls functions of Port0.16-Port0.31

PINSEL2 – Controls functions of Port1.16-Port1.31


pinsel LPC2148 - GPIO Tutorial


pinsel1 LPC2148 - GPIO Tutorial


LPC2141/2/4/6/8 has two 32-bit General Purpose I/O ports. Total of 30 input/output and a single output only pin out of 32 pins are available on PORT0. PORT1 has up to 16 pins available for GPIO functions. PORT0 and PORT1 are controlled via two groups of 4 registers.

Registers for GPIO

1-6 LPC2148 - GPIO Tutorial



This register provides the value of port pins that are configured to perform only digital functions. The register will give the logic value of the pin regardless of whether the pin is configured for input or output, or as GPIO or an alternate digital function. As an example, a particular port pin may have GPIO input, GPIO output, UART receive, and PWM output as selectable functions. Any configuration of that pin will allow its current logic state to be read from the IOPIN register.

gpio2 LPC2148 - GPIO Tutorial

If a pin has an analog function as one of its options, the pin state cannot be read if the analog configuration is selected. Selecting the pin as an A/D input disconnects the digital features of the pin. In that case, the pin value read in the IOPIN register is not valid. Writing to the IOPIN register stores the value in the port output register, bypassing the  need to use both the IOSET and IOCLR registers to obtain the entire written value. This  feature should be used carefully in an application since it affects the entire port.


This register is used to produce a HIGH level output at the port pins configured as GPIO in an OUTPUT mode. Writing 1 produces a HIGH level at the corresponding port pins. Writing 0 has no effect. If any pin is configured as an input or a secondary function, writing 1 to the corresponding bit in the IOSET has no effect. Reading the IOSET register returns the value of this register, as determined by previous writes to IOSET and IOCLR (or IOPIN as noted above). This value does not reflect the effect of any outside world influence on the I/O pins.

gpio3 LPC2148 - GPIO Tutorial


This word accessible register is used to control the direction of the pins when they are configured as GPIO port pins. Direction bit for any pin must be set according to the pin functionality.

gpio4 LPC2148 - GPIO Tutorial


This register is used to produce a LOW level output at port pins configured as GPIO in an OUTPUT mode. Writing 1 produces a LOW level at the corresponding port pin and clears the corresponding bit in the IOSET register. Writing 0 has no effect. If any pin is configured as an input or a secondary function, writing to IOCLR has no effect.

gpio5 LPC2148 - GPIO Tutorial

So this is the theory of LPC2148 GPIO. If you have any doubt in this please see the real time example below. Then you will understand.

LED Interfacing

We already know about the LED and its operation. So we move to programming now. Go through the code below.


led-blink LPC2148 - GPIO Tutorial


Switch Interfacing


switch LPC2148 - GPIO Tutorial


Here I’ve given some exercise for your practice. Please try that.

1. Blink alternate LEDs in Port1

2. Blink LEDs in cyclic fashion

Thank you guys. In our next tutorial we will see LCD interfacing. If you have any doubt please ask us.

%d bloggers like this: