#include<reg51.h>
sbit led=P2^2;
sbit led2=P2^7;
sbit key=P1^4;
unsigned char y;
unsigned int i,j,a;
void delayy(unsigned int x)
{
unsigned int i;
for(i=0;i<x;i++);
}
void delay(unsigned char x)
{
unsigned char a,j;
for(a=0;a<248;a++)
for(j=0;j<x;j++);
}
void main()
{
unsigned int a;
while(1)
{
if(key==0)
{
delay(0);
if(key==0)
{
y++;
}
}
if(y==3)
{
y=0;
}
switch(y)
{
case 1:
{
led2=1;
for(a=0;a<300;a++)
{
led=0;
delayy(a);
led=1;
delayy(299-a);
}
for(a=0;a<200;a++)
{
led=1;
delayy(a);
led=0;
delayy(199-a);
}
};
break;
case 2:
{
led=1;
for(a=0;a<300;a++)
{
led2=0;
delayy(a);
led2=1;
delayy(299-a);
}
for(a=0;a<200;a++)
{
led2=1;
delayy(a);
led2=0;
delayy(199-a);
}
};
break;
}
}
} |