#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
sbit led1 =P2^0;
sbit led2 =P2^1;
sbit led3 =P2^2;
sbit led4 =P2^3;
uchar num,num1,num2,num3;
void delay(ms)
{
uchar i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void K1()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
led1=~led1;
while(!key1);
}
}
}
void K2()
{
if(key2==0)
{
delay(10);
if(key2==0)
{
num1++;
if(num1==3)
{
num1=0;
led2=~led2;
}
}while(!key2);
}
}
void K3()
{
if(key3==0)
{
delay(10);
if(key3==0)
{
TR0=1;
delay(10);
if(num==20)
{
num=0;
led3=~led3;
TR0=0;
while(!key3);
}
else
{
TR0=0;}
}
else
{
num=0;
TR0=0;
}
}
}
void K4()
{
if(key4==0)
{
delay(2000);
if(key4==0)
{
delay(2000);
if(key4==0)
{
led4=~led4;
while(!key4);
}
}
}
}
void main()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
while(1)
{
K1(); //单按
K2(); //三按
K3(); //长按
K4(); //快2按
}
}
|