LED interfacing with Microcontroller - LPC2148

Updated: Feb 15

LPC 2148 is a 32 - bit ARM-7 microcontroller, manufactured by Philips. It has two I/O ports for interfacing different devices. In this tutorial interfacing of LED is explained.

An LED can be interfaced either using current sourcing or current sinking mode, here we are using current souring mode. In the current sourcing mode the current required to drive the LED is provided by the microcontroller itself. The LED is connected to pin number 1 of the port 0 i.e. P0.1.

Step1: First we have to configure P0.1 in the GPIO mode, by default all the port pins are configured in the GPIO mode. There are three registers which are used for this purpose: PINSEL0 - For PORT 0 ( PiN 0 -15) PINSEL1- For PORT 0 (PIN 16 - 31) PINSEL2 - For PORT 1 (PIN 16 -31) PINSEL0 & = 0xFFFF FFF3 Step 2: Configure P0.1 in the output mode. IOxDIR register is used to configure ports in the input/output mode. The LED is connected to P0.1 so we will configure the pin in the output mode. IO0DIR - Used for PORT 0 IO1DIR - Used for PORT 1 A port pin is configured in the output mode by writing logic one in the corresponding bit position of the IOxDIR register. Here we have to set (logic 1) bit no 1 of the IO0DIR register. IO0DIR |=(1<<1) Program: #include<LPC214x.h> #include<stdint.h> void Delay(int); int main() { PINSEL0 &=0xFFFF FFF3; IO0DIR|=(1<<1); while(1) { IO0SET=(1<<1); Delay(20000); IO0CLR=(1<<1); Delay(20000); } } void Delay(int d) { int i; for(i=0;i<=d;i++); }

79 views0 comments

Recent Posts

See All

DC Motors are widely used in embedded systems. This tutorial explains driving a DC motor using ARM-7 Architecture based LPC2148 Microcontroller. DC motors are available in different ratings. Selection