Tuesday 20 March 2012

HOW TO INTERFACE LEDs WITH MICROCONTROLLER (AT89c51)


        In this post I will explain how to take output from microcontroller using LEDs. Before that lets check how actually a LED works ?

How LED works ?
            LED is a most suitable component to display an output status because it emits the light when it is on. It is very cheap and comes in different size and colors. The principal of working of a LED is equivalent to the p-n junction diode. The difference is, it emits the light in visible spectrum instead of heat. The forward voltage drop of LED is around 1.7v. it works around 10mA current supply.
            The circuit diagram for connection of LED is show below.
            
The circuit diagram and microcontroller code for interfacing a LED with microcontroller (AT89c51) is given below.

Component Required :
1.      8 LEDs.
2.      Microcontroller AT89c51.
3.      8 registers.
4.      12MHz crystal oscillator.
5.      10 KΩ fixed register.
6.      10 μf (25v) capacitor.

Circuit Diagram :

           
               8 LEDs are connected with port P1 of AT89c51. Here LEDs are running of negative logic means cathode of every LED is connected with Microcontroller port pin and anode of all the LEDs are connected to +5v supply so we don’t required to give +5v at the output of microcontroller in order to on the LEDs.
            We are sending the sequence of 0x055 and 0x0AA alternatively with some delay. Delay is in the range of few milliseconds.

Code :

        #include<reg51.h>

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

void main()
{
      while(1)
      {
          P1=0x00;
          delay(100);
          P1=0xff;
          delay(100);
      }
}


No comments:

Post a Comment