LED INTERFACING WITH 8051
This tutorial/project is LED interfaced with microcontroller (µC) AT89S52. The blinking (ON/OFF) of LED should be controlled with predefined time delay by microcontroller.
Synopsis

This tutorial/project is LED interfaced with microcontroller (µC) AT89S52. The blinking (ON/OFF) of LED should be controlled with predefined time delay by microcontroller. AT89S52, which belongs to the family of 8051 series of microcontrollers, is very commonly used by a large community of hobbyist and engineers. Its simplicity and ease of programming with inbuilt features easily makes its position in the top preferred list of microcontroller for both beginners and advanced user. LED is a particular type of diode which converts electrical energy into light. LED stands for “Light Emitting Diode.” They are very cheap and easily available in a variety of shape, size and colors. They find multiple applications as indicators during experimentations to check the validity of results at different stages.

Description

The principle of operation of LEDs is simple. The commonly available LEDs have a drop voltage of 1.7 V and need 10 mA to glow at full intensity. The following circuit describes “how to glow a LED”. The AT89S52 microcontroller can sink (“absorb”) or source (“give out”) a small amount of current. A series resistor is also required to limit the current. LED’s anode directly connected to GPIO pins of microcontroller and cathode is connected to ground which is sink mode. In this mode controller supply current. When controller pin high (1) LED will glow and pin will low (0) LED does not glow. However the output of the controller is not sufficient enough to drive the LEDs, so the LED will not glow at full illumination. In source mode operation is vice versa which means supply provided to the controller. The fig 1 shows the pins of LED. The fig 2 shows the mode of LED connection with controller.

Resister value calculation

The value of resistance R can be calculated using the equation, R=(V-Vd)/Id Where V input voltage, Vd LED voltage Id LED current R= (V-1.7)/10 mA Since most of the controllers work on 5V, so substituting V= 5V, the value of resistance comes out to be 330 ohm. The resistance 220 ohm, 470 ohm is commonly used substitute in case 330 ohm is not available.



Application

• LEDs are widely used in many applications like in seven segments.

• They are used in dot matrix displays.

• They can be used for street lights.

• They are used as indicators.

• They can be used in traffic lights.

• They are used in emergency lights

Proteus design for LED interfacing with 8051


Orcad design for LED interfacing with 8051


LED interfacing with 8051

/*  Name     : main.c
 *  Purpose  : Source code for LED Interfacing with AT89C52.
 *  Author   : Gemicates
 *  Date     : 2014-01-12
 *  Website  : www.gemicates.org
 *  Revision : None
 */
 
#include <REGX52.H>						//header file for AT89c52 series

#define ledport P0						//To set a port pins as output
sbit LED9=P3^7;							//To set a single pin(P3.7) as output
sbit LED10=P1^6;						//To set a single pin(P1.6) as output
sbit SW	 =P1^7;							//To set a single pin(P1.7) as output

unsigned char log=0;					        //Global variable declaration

void delay(int msec)					        //delay function declaration
{							        //This function produces a delay in msec
	int i,j;
	for(i=0;i<msec;i++)
	for(j=0;j<1275;j++);
}


void main()							//main function
{
	SW=0;							//make as a input pin P1^7
	while(1)						//Repeat(loop) forever
	{
		//port declaration
		ledport=0x00;					//P0 LEDs will be ON
		delay(50);
		ledport=0xFF;					//P0 LEDs will be OFF
		
		//single pin declaration
		LED9=0;						//LED 9 will be ON state
		delay(50);					//function call for delay
		LED9=1;						//LED 9 will be OFF state
		delay(50);
		
		//push button declaration
		if((SW==1)&&(log==0))			        //LED turn ON using Push Button
		{
			LED10=0;
			delay(50);
			log=1;
		}
		if((SW==1)&&(log==1))
		{
			LED10=~LED10;				// Toggle state
			delay(50);
			log=0;
		}
		
	}
}

Error message here!

Show Error message here!


Forgot your password?

Error message here!

Send OTP

Error message here!

Show Error message here!


Lost your password? Please enter your email address. You will receive a password you Need.

Send Error message here!


Back to log-in

Close