____________________________________________________________________________________________________
____________________________________________________________________________________________________ _______________________________________________________________________________________________
1. Program of led interfacing with 8051
/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- BLINK LEDs ON PORT2
******************************************************/
#include<reg51.h> // this is the header file used in programming of AT89C51
void delay(int x,int y); // delay function
sbit a=P2^0; // access pin P2.0 as a name a
sbit b=P2^1; // access pin P2.1 as a name b
sbit c=P2^2; // access pin P2.2 as a name c
sbit d=P2^3; // access pin P2.3 as a name d
sbit e=P2^4; // access pin P2.4 as a name e
sbit f=P2^5; // access pin P2.5 as a name f
sbit g=P2^6; // access pin P2.6 as a name g
sbit h=P2^7; // access pin P2.7 as a name h
void main()
{
while(1) //super loop (infinite loop)
{
a=b=c=d=e=f=g=h=1; // leds on
delay(100,100); // halt for some time
a=b=c=d=e=f=g=h=0; // leds off
delay(100,100); // halt for some time
}
}
void delay(int x,int y) // delay function
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
2. Program of ALTERNATE LED GLOW With 8051
/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- JUST ALTERNATE BLINKING OF LED ON PORT2
******************************************************/
#include<reg51.h> // this is the header file used in programming of AT89C51
void delay(int x,int y); // delay function
sbit a=P2^0; // access pin P2.0 as a name a
sbit b=P2^1; // access pin P2.1 as a name b
sbit c=P2^2; // access pin P2.2 as a name c
sbit d=P2^3; // access pin P2.3 as a name d
sbit e=P2^4; // access pin P2.4 as a name e
sbit f=P2^5; // access pin P2.5 as a name f
sbit g=P2^6; // access pin P2.6 as a name g
sbit h=P2^7; // access pin P2.7 as a name h
sfr xyz=0xa0; // sfr means special function register
// 0x0a is the address of port2
void main()
{
while(1) //for undifined loop
{
xyz=0xaa; // alternate led on and off
/* binary code of 0xaa=10101010
lower value of 0xaa goes to P2.0 ,2nd lower value of 0xaa goes to P2.1 and so on
*/
delay(100,100); // hault for some time
xyz=0x55; // alternate led on and off
/* binary code of 0x55=01010101
lower value of 0x55 goes to P2.0 ,2nd lower value of 0x55 goes to P2.1 and so on*/
delay(100,100); // hault for some time
}
}
void delay(int x,int y) // delay function
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<y;j++);
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
3. Program of DIFFERENT PATTERN LED GLOW with 8051
/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- THREE DIFFERENT PATTERN OF LED ON PORT2
******************************************************/
#include<reg51.h>
#include<math.h>
void delay();
sfr led=0xa0; //access port2 as a variable name led
char ar[]={0x81,0x42,0x24,0x18,0x24,0x42,0x81};
void main()
{
int n,j,i;
while(1)
{
n=2;
while(n--)
{
for(i=0;i<8;i++)
{
led=pow(2,i);
// pow is function defined in math.h it make power of 2 as i
// when i=0, pow(2,i)=1;
// when i=1, pow(2,i)=2;
// when i=2, pow(2,i)=4;
// when i=3, pow(2,i)=8;
delay();
}
for(i=7;i>=0;i--)
{
led=pow(2,i);
// pow is function defined in math.h it make power of 2 as i
// when i=0, pow(2,i)=1;
// when i=1, pow(2,i)=2;
// when i=2, pow(2,i)=4;
// when i=3, pow(2,i)=8;
delay();
}
}
n=2;
while(n--)
{
for(i=0;i<7;i++)
{
led=ar[i];
delay();
}
}
n=2;
while(n--)
{
led=0x00;
delay();
led=0x01;
delay();
led=0x03;
delay();
led=0x07;
delay();
led=0x0f;
delay();
led=0x1f;
delay();
led=0x3f;
delay();
led=0x7f;
delay();
led=0xff;
delay();
led=0xfe;
delay();
led=0xfc;
delay();
led=0xf8;
delay();
led=0xf0;
delay();
led=0xe0;
delay();
led=0xc0;
delay();
led=0x80;
delay();
led=0x00;
delay();
led=0x80;
delay();
led=0xc0;
delay();
led=0xe0;
delay();
led=0xf0;
delay();
led=0xf8;
delay();
led=0xfc;
delay();
led=0xfe;
delay();
led=0xff;
delay();
led=0x7f;
delay();
led=0x3f;
delay();
led=0x1f;
delay();
led=0x0f;
delay();
led=0x07;
delay();
led=0x03;
delay();
led=0x01;
delay();
led=0x00;
delay();
}
}
}
void delay()
{
int i;
for(i=0;i<30000;i++);
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)