Pages

Powered By Blogger

Friday, 17 June 2011

led dancing with switch


Pgm1:led dancing with switch
#include<reg51.h>
#define led P0
sbit sw=P1^0;
void delay(unsigned char);
void main()
{
P0=0xff;
while(1)
{
if(sw==1)
{
led=0x55;
delay(100);
led=0xaa;
delay(100);
}
else
{
led=0xaa;
delay(100);
led=0x55;
delay(100);
}
}
}
void delay(unsigned char b)
{
unsigned char i,j;
for(i=0;i<5;i++)
for(j=0;j<b;j++);
}
Prg2:led dancing
#include<reg51.h>
#define led P0
sbit sw=P1^0;
void delay(unsigned char);
void main()
{
P0=0xff;
while(1)
{
led=0x55;
delay(100);
led=0xaa;
delay(100);
}
}
}
void delay(unsigned char b)
{
unsigned char i,j;
for(i=0;i<5;i++)
for(j=0;j<b;j++);
}

No comments: