LPC 21xx Microcotroller Programming Starting

When getting started in embedded programming, GPIO (viz. General Purpose Input Output) pins are one of the first things played with. Its also quite evident that the most popular embedded systems Program is Blinking LED i.e a LED connected to pin on the Microcontroller that keeps blinking. 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 and what not. In this tutorial we see how to use and program GPIO Pins for lpc214x ARM 7 microcontrollers from NXP/Philips.

In this tutorial we also learn to make a project in keil MDK with a blinking LED.

First of all make download Keil MDK from keil official Site ,install it and open it .

Go to the project menu and and make new project from their choose micro-controller from NXP family to LPC214x. and add Startup file to project. create new file name as extension of type .c. add file to the source project.

include hedder file as #include “lpc21xx.h” to the code.

First we start with GPIO (General purpose INPUT and OUTPUT) Pins. the LPC21xx controllers have two ports with 32 pins each as it is mirco-controller with 32 bit resistor.

there are four resister PIN , DIR , SET, CLR for each pin of 2 ports.

DIR - this resistor is used to set direction of pins.

Example of using this resistor is IO0DIR |= (1<<6); it will set pin 6 of port 0 as output.

void Direction_Set(unsigned int Port_No,unsigned int Pin_No,char Direction)
{
switch(Port_No)
{
case 0:
if(Direction)
{
IO0DIR |= (1<<Pin_No);
}
else
{
IO0DIR &= ~(1<<Pin_No);
}
break;
case 1:
if(Direction)
{
IO1DIR |= (1<<Pin_No);
}
else
{
IO1DIR &= ~(1<<Pin_No);
}
break;
}
}

SET  - this resistor is used to set pin/port of microcontroller. example of this resistor is IO1SET |= (1<<10); this will set Pin 10 of port 1.

void Set_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
IO1SET |= (1<<Pin_No);
}
else
{
IO0SET |= (1<<Pin_No);
}
}

Here is the function provided for Set pins of microcontroller.

 

CLR -  This resistor is used to clear Port/Pin of micro-controller. example of this resistor is as IO1CLR |= (1<<10);  .

void Clear_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
IO1CLR |= (1<<Pin_No);
}
else
{
IO0CLR |= (1<<Pin_No);
}
}

PIN - this resistor is used to take input from pins/port.
int Read_Pin(unsigned int Port_No,unsigned int Pin_No)
{
if(Port_No)
{
return (IO1PIN&(1<<Pin_No));
}
else
{
return (IO0PIN&(1<<Pin_No));
}
}

——————————————————————————————————————–

int Read_Port(unsigned int Port_No)
{
if(Port_No)
{
return (IO1PIN);
}
else
{
return (IO0PIN);
}
}