#include <reg52.h>
#define u16 unsigned int
#define u8 unsigned char
u16 s=0,id=0;
sbit k1=P3^1;
sbit k2=P3^0;
sbit L0=P2^0;
sbit L1=P2^1;
sbit L2=P2^2;
sbit L3=P2^3;
sbit L4=P2^4;
sbit L5=P2^5;
sbit L6=P2^6;
sbit L7=P2^7;
void delay(u16 i);
void key();
void tim0d();
void main()
{
tim0d();
key();
while(1)
{
key();
if(s>=400)
{
s=0;
id++;
}
switch(id)
{
case 0: L0=~L0;L7=1;break;
case 1: L1=~L1;L0=1;break;
case 2: L2=~L2;L1=1;break;
case 3: L3=~L3;L2=1;break;
case 4: L4=~L4;L3=1;break;
case 5: L5=~L5;L4=1;break;
case 6: L6=~L6;L5=1;break;
case 7: L7=~L7;L6=1;break;
case 8: L6=~L6;L7=1;break;
case 9: L5=~L5;L6=1;break;
case 10: L4=~L4;L5=1;break;
case 11: L3=~L3;L4=1;break;
case 12: L2=~L2;L3=1;break;
case 13: L1=~L1;L2=1;break;
case 14: L0=~L0;L1=1; id=0;break;
}
}
}
void delay(u16 i)
{
while(i--);
}
void key()
{
if(k1==0)
{
delay(1000);
if(k1==0)
{
TR0=1;
}
while(!k1);
}
if(k2==0)
{
delay(1000);
if(k2==0)
{
TR0=0;
id=0;
s=0;
P2=0xfe;
}
while(!k2);
}
}
void tim0d()
{
TMOD|=0X01;
TH0=0XFC;
TL0=0X18;
ET0=1;
EA=1;
TR0=0;
}
void tim0() interrupt 1
{
TH0=0XFC;
TL0=0X18;
s++;
}
|