#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit d0=P1^0;
sbit d1=P2^0;
sbit d2=P2^1;
bit flag;
uchar tt;
void scan_key()
{
if(d0==0)
{
d1=0;
TR0=0;
}
}
void main()
{
TMOD=0x11;//设置定时器0为工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
flag=1;
while(1)
{
while(flag)
{
scan_key();
}
}
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==80)
{
flag=0;
d2=0;
TR0=0;
}
}
|