You are on page 1of 13

8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX




 report this ad



Sidebar



 LPC2148
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.

Post Contents [hide]

1 LPC2148 GPIO Tutorial


2 PINSEL Register
2.1 PINSEL0
2.2 PINSEL1

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 1/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

3 I/O PORT
4 Registers for GPIO
5 REGISTER DESCRIPTION
5.1 1. IOPIN
5.2 2. IOSET
5.3 3. IODIR
5.4 4. IOCLR
6 LED Interfacing
6.1 OUTPUT
7 Switch Interfacing
7.1 OUTPUT
8 TASKS
8.0.1 Share this:

8.0.2 Like this:

 8.0.3 Related




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

PINSEL0
https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 2/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX











https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 3/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

PINSEL1











https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 4/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX











https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 5/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

I/O PORT
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











REGISTER DESCRIPTION
1. IOPIN
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.

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.

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 6/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

2. IOSET
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.









 3. IODIR

 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.

4. IOCLR
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.

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 7/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

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.

1 #include<lpc214x.h>
2
3 void delay();
4 void main()
5 {
6 IO0DIR |=0XfffffFFF; //Port 0 is now acting as a output pin
 7 while(1) {
8 IOSET0 |=0XfffffFFF; //Port 0's all pins are high now (LED is glowing)

 9 delay();
10 IOCLR0 |=0XFFFfffff; //Port 0's all pins are low now (LED is OFF)

 11 delay();
 12 }

13 }

 14
15 void delay()

 16 {
17 unsigned int i;
18 for(i=0;i<30000;i++);
19 }

OUTPUT

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 8/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

Switch Interfacing
1 #include<lpc214x.h>
2
3 void delay();
4 void main()
5 {
6 IO0DIR |=0XfffffFFF; //Port 0 is now acting as a output pin
7 IO1DIR = 0x0; //Port 1 is now acting as a input pin
8 while(1)
9 {
10 if((IO1PIN & (1<<16)) ==0) //Checking 16th pin of Port 1
11 IOSET0 |=0XfffffFFF; //Port 0's all pins are high now (LED is glowing)
12 else
13 IOCLR0 |=0XFFFfffff; //Port 0's all pins are low now (LED is OFF)
14 }
15
 16 }
17

 18 void delay()
 19 {

20 unsigned int i;

 21 for(i=0;i<30000;i++);
22 }



 OUTPUT

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

1. Blink alternate LEDs in Port1


https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 9/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

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.











I2C-PC Interface LPC2148 Tutorials Password Based LCD Interfacing with


(ARM7 Door Open System LPC2148 ARM7
Using LPC2148
Ad www.i2cchip.com embetronicx.com embetronicx.com embetronicx.com

Embedded Interview Linux Device Driver LPC2148 Projects FreeRTOS LCD


Topics FAQ in Tutorial Part 22 – Archives Interfacing with
Companies Mutex in Linux Kernel LPC2148

embetronicx.com embetronicx.com embetronicx.com embetronicx.com

Share this:

Share 0
Post
Tweet SHARE  Print  WhatsApp Share 0

 Telegram Save

Like this:

Loading...

Related

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 10/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

LPC2148 - Timer/Counter Tutorial LPC2148 - Introduction PIC16F877A GPIO Tutorial


In "LPC2148" In "LPC2148" In "PIC16F877A"











https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 11/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

Sponsored Links

Life in ANA Avant Garde creates an aura of its own. 2 BHK Property in Mira Road at 84 Lacs*
Avant Garde

Buy Shop/ Business Insurance Today. Get Coverage Against Fire, Theft, Burgalry, Natural Calamities
Policybazaar.com

New Low Price on Flights leaving from Pandharpur


Tripbase

 News without the Noise


YouTube | Logically


 0 Comments
 EmbeTronicX 
1 Login


 Recommend t Tweet f Share Sort by Newest




Start the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Be the first to comment.

ALSO ON EMBETRONICX

Gas Leakage Detection System using 8051 PIC16F877A – ADC Tutorial


2 comments • a year ago 1 comment • a year ago
EmbeTronicX — Yes it is available. That is pullup Vineeth S.R — Very good tutorial :D thank you very
resistor much!!
Can you please explain the line 73:adcval=

Rain Sensor Interfacing with PIC16F877A 8051 – Ultrasonic Sensor Interfacing


2 comments • a year ago 6 comments • a year ago
EmbeTronicX — You have to use MPLab...Mikroc EmbeTronicX — Hi Kavita,Thanks for commenting.
and MPLab are different IDE. You cannot use this In program, we did not use Timer 1. If you see
source code in mikroc. You have to implement this there, we used TH0, TL0, TR0. So it is respected to

✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 12/13
8/3/2019 LPC2148 GPIO Tutorial (LED, Switch Interfacing) | EmbeTronicX

https://embetronicx.com/tutorials/microcontrollers/lpc2148/lpc2148-gpio-tutorial-led-interfacing/ 13/13

You might also like