Thursday, June 12, 2014

Interfacing LED's with a micro controller(AT89c51)

In this chapter we will learn how to interface LED using Micro controller. Here I have used the micro controller AT89c51. 
The AT89C51 is a low-power, high-performance C MOS 8-bit microcomputer with 4K
bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmel’s high-density nonvolatile memory technology and is compatible with the industry-standard MCS-51 instruction set and pin-out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash
on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides
a highly-flexible and cost-effective solution to many embedded control applications.
First let's see the architecture of AT89c51
 As you can see, the controller has 40 pins, of them 32 pins are the parallel ports that are used for interfacing. These 32 pins are divided into 4 ports having 8pins for each. They are named as port 1, port 2, port 3, port 4. 
Port 1:- p0.0,p0.1,p0.2,p0.3,p0.4,p0.5,p0.6,p0.7 ( pin no: 39-32)
Port 2- p1.0,p1.1,p1.2,p1.3,p1.4,p1.5,p1.6,p1.7 ( pin no: 1-8)
Port 3:- p2.0,p2.1,p2.2,p2.3,p2.4,p2.5,p2.6,p2.7 ( pin no: 28-21)
Port 4:- p3.0,p3.1,p3.2,p3.3,p3.4,p3.5,p3.6,p3.7 ( pin no: 10-17) 
Pin 18 and 19 are for connecting crystal oscillator, pin 20 is ground and 40 is vcc. 
You can use any/all of the 4 ports to interface LED's. In this experiment i had selected the Port  1:(p 0.0 - p0.7).

In this experiment we are going to interface 8 LED's. 

Components required:-


1.      8 LEDs.
2.      Micro controller AT89c51.
3.      8 registers. (330 ohm)
4.      12MHz crystal oscillator.
5.      10 KΩ fixed register.
6.      10 μf (25v) capacitor.

Circuit diagram

 

 


  Connections are made as per the circuit diagram. Here LED's are running of negative logic. That means normally every pin of port 1 have +5v as output. Here cathode of every LED is connected with Micro controller port pin and anode of all the LED's are connected to +5v supply. Thus both the legs of LED are supplied with +5v. So we  required to give 0v at the output of micro controller in order to 'ON' the LED's.

            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; // this code turns ON the LED's
          delay(100);
          P1=0xff;  // this code turns OFF the LED's
          delay(100);
      }
}

If port 2 is used then the code becomes :-

  #include<reg51.h>


void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P2=0x00;    // P1 changed to P2. If p3 is used then write P3 here.
          delay(100);
          P2=0xff;
          delay(100);
      }
}

 If more than one port is used then the circuit diagram becomes:-

 


 Here Port 1 and Port 3 are together used for interfacing 16 LED's. 




Code (All 16 turned ON at a times)

        #include<reg51.h>

void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P1=0x00; // this code turns ON the LED's in Port 1
            P3=0x00; // this code turns ON the LED's in Port 3
          delay(100);
          P1=0xff;  // this code turns OFF the LED's in Port 1
            P3=0xff;  // this code turns OFF the LED's in Port 3
          delay(100);
      }
}
Code (Only 8 LED's turned ON at a times)

        #include<reg51.h>

void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P1=0x00; // this code turns ON the LED's in Port 1
            P3=0xff;  // this code turns OFF the LED's in Port 3
          delay(100);
          P1=0xff;  // this code turns OFF the LED's in Port 1
            P3=0x00; // this code turns ON the LED's in Port 3
           
          delay(100);
      }
}
tags: interfacing LED with PIC, embedded projects for beginners, embedded tutorials for beginners, LED interfacing circuits, LED tutorials, LED blinking circuits, LED blinking tutorials, AT89c51 beginners projects, AT89c51 tutorials, micro controller tutorial projects, micro controller circuits for beginners

0 comments:

Post a Comment