How To Interface An LED With 8051 Microcontroller
How To Interface An LED With 8051 Microcontroller
8051 Microcontroller
We are very familiar with “Hello world!” basic program code in the initial stage of
any programming language to learn some basic things. Similarly to get started with 8051
Microcontroller, LED interfacing is a basic thing in Microcontroller interfacing
programming. Each Microcontroller is different in its architecture, but the interfacing
concept almost all same for all Microcontroller. This tutorial will give you an LED
interfacing with 8051.
Interfacing is a method, that provides communication between Microcontroller and the
interface device. An interface is either Input device, or output device, or a storage
device, or processing device.
Input Interface Devices: Push button switch, Keypad, Infrared sensor, Temperature sensor,
gas Sensor etc. These devices provide some information to the Microcontroller, and this
is called as input data.
Output Interface Devices: LED, LCD, Buzzer, Relay driver, DC Motor Driver, 7-Segment
Display etc.
Storage Interface Devices: Used to store/ retain the data, example, SD card, EEPROM,
DataFlash, Real Time Clock, etc.
MicroController Interfacing Model
LED is a semiconductor device used in many electronic devices, mostly used for signal
transmission /power indication purposes. It is very cheaply and easily available in a
variety of shape, color, and size. The LEDs are also used for design message display
boards and traffic control signal lights etc.
It has two terminals positive and negative as shown in the figure.
LED Polarity
The only way to know polarity is either to test it with a multimeter or by carefully
observing inside the LED. The larger end inside the led is -ve (cathode) and the shorter
one is +ve (anode), that is how we find out the polarity of the LED. Another way to
recognize the polarity is, connecting leads, POSITIVE terminal has more length than
NEGATIVE terminal.
LED Interfacing to 8051
There are two ways which we can interface LED to the Microcontroller 8051. But the
connections and programming techniques will be different. This article provides the
information on LED interfacing with 8051 and LED blinking code for AT89C52/
AT89C51 Microcontroller.
Observe carefully the interface LED 2 is in forward biased because the input voltage of
5v connected to the positive terminal of the LED, So here the Microcontroller pin should
be at LOW level. And vice versa with the interface 1 connections.
The resistor is important in LED interfacing to limit the flowing current and avoid
damaging the LED and/or MCU.
Interface 1 will glow LED, only if the PIN value of the MC is HIGH as current flows towards the
ground.
Interface 2 will glow LED, only if the PIN value of the MC is LOW as current flows towards PIN due
to its lower potential.
The circuit diagram is shown in below. An LED is connected to the pin-0 of port-1.
Proteus Simulation Circuit
I will explain the program code in detail. Furthermore, refer this link “Embedded C
Programming Tutorial with Keil Language”. A crystal of 11.0592 MHz is connected for
generating the clock. As we know that 8051 Microcontroller executes an instruction in
12 CPU cycles [1], hence this 11.0592Mhz crystal makes this 8051 run at 0.92 MIPS
(Million of instructions per second).
In the code below, the LED is defined as the pin 0 of the port 1. In the main function,
LED is toggled after every half second. The ‘delay’ function executes null statements
every time when it executes.
CODE
#include<reg51.h>
sbit LED= P1^0; // pin0 of port1 is named as LED
//Function declarations
void cct_init(void);
int main(void)
cct_init();
while(1)
LED=0;
delay(60000);
LED=1;
delay(60000);
void cct_init(void)
{
P0= 0x00;
P1= 0x00;
P2= 0x00;
P3= 0x00;
int i;
for( i=0; i<a; i++) // Null statement execution i.e, delay time
This article gives the information about how the LED interfacing with the 8051. This is
the fundamental interfacing concept for 8051 microcontroller projects.
I hope by reading this article you have got basics knowledge about how to interface
LED module with the 8051. If you have any queries regarding this article or about
the microcontroller projects, please don’t hesitate to feel free to comment in the below
section.