#include<reg51.h>
unsigned char flag,num,keyn;
sbit KEY=P1^0;
sbit LED=P1^1;
void delay(unsigned int a)
{
unsigned int i,j;
for(i=0;i<a;i++)
for(j=0;j<125;j++);
}
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num>20)
{
num=0;
flag=0xff;
}
}
void keyscan()
{
if(P1.0==0)
{
delay(10);
TR0=1; //有效按键启动定时器
if(P1.0==0)keyn++;
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
num=0;
keyn=0;
while(1)
{
flag=0x00;
while(flag==0x00)//等待1秒定时结束
{
keyscan();
}
if(keyn>=2)
{
LED=0; //1秒内按两次键,灯亮
keyn=0;
TR0=0;
}
}
}
大神们 帮忙看看 |