Saturday, 11 February 2012

Awesome LED projects with 8051










I like playing with LEDs but mostly when you search about LED project with 8051 you will only get only “blinking LEDs with 8051”.here I present some awesome LED projects. So enjoy. All the codes are written by me. 
 
Circuit diagram:
Description:

For all LED projects I used combination of 4 green and 4 red LEDs. For these projects I used negative logic i.e. when 8051 will supply   ‘0’ LED will glow and when ‘1’  they don’t. Because 8051 have poor current sourcing capability and good current sinking capability.330 ohm resisters are used to restrict the current  through LEDs .If you don’t get desired brightness then use LEDs without resisters. Power on reset circuitry is used here however you can connect a push –to-on button for  manual reset. 

Code:

Micro: AT89S52
Code language: embedded C
Compiler: kiel micro vision
Programming software: ISP programmer by Asim Khan
Programming hardware: Homemade (using Atmel ISP cable)you can visit my blog for this detail.
Note : following program produce different effects so load them one by one. for direct ready to burn hex codes visit our blog.

Program:1
#include<reg51.h>

//declaratiobn of LED names
sbit r1=P0^0;
sbit g1=P0^1;
sbit r2=P0^2;
sbit g2=P0^3;
sbit r3=P0^4;
sbit g3=P0^5;
sbit r4=P0^6;
sbit g4=P0^7;
// declaring delay function
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( )
{
   int n=50;
       while(1)
       {
 
   //forward movment
      g1=1,g2=1,g3=1,g4=1;
      r1=0,r2=1,r3=1,r4=1;
      delay(n);
      g1=0;
      delay(n);
      r2=0;
      delay(n);
      g2=0;
      delay(n);
      r3=0;
      delay(n);
      g3=0;
      delay(n);
      r4=0;
      delay(n);
      g4=0;
      delay(n);
      //reverse movement
      g1=1,g2=1,g3=1,g4=0;
      r1=1,r2=1,r3=1,r4=1;
      delay(n);
      r4=0;
      delay(n);
      g3=0;
      delay(n);
      r3=0;
      delay(n);
      g2=0;
      delay(n);
      r2=0;
      delay(n);
      g1=0;
      delay(n);
      r1=0;
      delay(n);
       }
      }



 
Program:2

#include<reg51.h>

//declaratiobn of LED names
sbit r1=P0^0;
sbit g1=P0^1;
sbit r2=P0^2;
sbit g2=P0^3;
sbit r3=P0^4;
sbit g3=P0^5;
sbit r4=P0^6;
sbit g4=P0^7;
// declaring delay function
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(void)
{
  n=50;
 while(1)
   {
   g1=1,g2=1,g3=1,g4=1;
   r1=0,r2=1,r3=1,r4=1;
   delay(n);
   g1=0,r1=1;
   delay(n);
   g1=1;r2=0;
   delay(n);
   r2=1,g2=0;
   delay(n);
   g2=1,r3=0;
   delay(n);
   r3=1,g3=0;
   delay(n);
   g3=1,r4=0;
   delay(n);
   r4=1,g4=0;
   delay(n);
   }
}


Cheak out videos:

No comments:

Post a Comment