Sunteți pe pagina 1din 3

4/2/2018 Blink LED with ARM7 LPC2148 - BINARYUPDATES

Blink LED with ARM7 LPC2148


In our previous tutorial, we have seen how to create new KEIL uVision Project for LPC2148 Microcontroller. Also we have seen how to program ARM7 LPC2148

microchip. Here we’ll explore the use of GPIO. GPIO (General Purpose Input Output) pins are the most basic peripherals in any microcontroller. As a first tutorial in

this series we’ll Blink LED with ARM7 LPC2148 Microcontroller. Although it’s simple task but still we feel good to get start with. Before we proceeds any further to

blink LED (Light Emitting Diode).

Let’s discuss about GPIO. GPIO lines of any microcontroller can be used mainly to perform two things. One is to generate digital signal and second one is to read a

digital signal. In LPC2148 microcontroller most of port pins are multiplexed, this means they’re allowed to provide multiple functions. Configuring GPIO to use

different function is out of the scope of this tutorial. Just keep in mind that by default: all functional pins i.e. Pins on PORT0 and PORT1 are set to be as GPIO so we

can directly use them in our example project.

Here we’ve listed some GPIO related registers and its functions. We need to replace ‘x’ with the port number to get the register name. Say for example: IOxPIN

register becomes IO0PIN when used for PORT0 and IO1PIN when used for PORT1. These all register names defined in the header file “lpc2148.h” Register names

defined in the header file are nothing but a pointer which holds the address of actual register in LPC2148. (‘x’ represent port number).

GPIO Related Registers In LPC2148

This register can be used to read or write values directly to the pins. Regardless of the
IOxPIN
direction set for the particular pins. It gives the current state of GPIO pin when read.

This is the GPIO direction control register. Setting a bit to ‘0’ in this register will configure the
IOxDIR
corresponding pin to be used as input while setting it to ‘1’ will configure it as output.

This register can be used to drive an ‘output’ configured pin to logic 1 i.e. HIGH. Writing zero
IOxSET does not have any effect and hence it can’t be used to drive a pin to Logic 0 i.e. LOW. For
driving pins LOW IOxCLR is used which is explained as below:

This register can be used to drive an ‘output’ configured pin to logic 0 i.e. LOW. Writing zero
IOxCLR
does not have any effect and hence it can’t be used to drive a pin to Logic 1.

Video: Blink LED with ARM7 LPC2148

BLINK LED WITH LPC2148 ARM7 Microcontroller

Example: Blink LED with ARM7 LPC2148

Let’s have a look at example project where we’ll blink LED connected to Pin P0.10. Please make sure that this LED connected in common anode configuration.

Refer the circuit connections as:

http://binaryupdates.com/blink-led-with-arm7-lpc2148/ 1/3
4/2/2018 Blink LED with ARM7 LPC2148 - BINARYUPDATES

Blink LED with ARM7 LPC2148


While writing an application to blink LED, we have to follow general steps:

Initialize a microcontroller system, which take care setup procedure like powering up peripherals, set
clock rate etc.

Connect necessary pin using pin connect block. The purpose of pin connect block is to configure
microcontroller pin to desired function. By default GPIO is enabled.

And then set or clear the bit of respective pin to turn ON & OFF LED

1 #include <lpc214x.h>
2  
3 unsigned int delay;
4  
5 int main(void)
6 {
7 IO0DIR = (1<<10);   // Configure P0.10 as Output
8
9 while(1)
10 {
11 IO0CLR = (1<<10); // CLEAR (0) P0.10 to turn LED ON
12 for(delay=0; delay<500000; delay++); // delay
13 IO0SET = (1<<10); // SET (1) P0.10 to turn LEDs OFF
14 for(delay=0; delay<500000; delay++); // delay
15 }
16 }

To download Project: Click Here

CODE EXPLANATION:

This complete program consists of only few lines of code. Let me slice down into pieces to elaborate each line

1 #include <lpc214x.h>

This include statement adds standard header file for all LPC214x series of microcontrollers. All register names has been defined in lpc214x.h file.

1 IO0DIR = (1<<10); // Configure P0.10 as Output

Since we have connected LED to Pin P0.10. We have to set Pin into an output mode. As P0.10 belongs to PORT0. The direction control bit in IO0DIR register been

used to configure this pin.

1 while(1)
2 {
3   IO0CLR = (1<<10);        // CLEAR (0) P0.10 to turn LED ON
4   for(delay=0; delay<500000; delay++); // delay
5   IO0SET = (1<<10);        // SET (1) P0.10 to turn LEDs OFF
6   for(delay=0; delay<500000; delay++); // delay
7 }

In this never ending while loop. We first have to clear a bit using IO0CLR=(1<<10), this is how we can make P0.10 to become LOW (LED turned ON). IO0SET=

(1<<10), would make output HIGH (LED turned OFF) for Pin P0.10. We have for loop in between which generate significant delay between the process of turning LED

ON and OFF.

In future we’ll explore delay function to generate accurate time delay. We hope this tutorial will be helpful to get you started. In next tutorial we’ll learn how to add

switch to our LPC2148 Microcontroller project.

Products from Amazon.in

NXP ARM7 LPC2148 Header Board Robocraze LPC2148 Arm 7 NXP Develo…

Price: INR 1,916.00 Price: Out of stock

http://binaryupdates.com/blink-led-with-arm7-lpc2148/ 2/3
4/2/2018 Blink LED with ARM7 LPC2148 - BINARYUPDATES

Login
Username

Password

Remember Me
Log In

Register | Lost your password?


| Back to Login

http://binaryupdates.com/blink-led-with-arm7-lpc2148/ 3/3

S-ar putea să vă placă și