#include <REGX52.H>
#include <Key.h>
void Timer0Init(void)
{
TMOD &= 0xF0;
TMOD |= 0x01;
TL0 = 0x18;
TH0 = 0xFC;
TF0 = 0;
TR0 = 1;
ET0=1;
EA=1;
PT0=0;
}
int mod=0;
int c=0;
int T;
void main()
{
Timer0Init();
while(1)
{
// if(P3_1==0)
// {
// P2_0=0;
// mod=1;
// }
// if(c==300)
// {
// c=0;
// mod=0;
// P2_0=1;
// }
//
T=Key();
if(T==1)
{ P2_0=0;
mod=1;}
if(c==300){c=0;mod=0;P2_0=1;}
}
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count;
TL0 = 0x18;
TH0 = 0xFC;
T0Count++;
if(T0Count>=10)
{
Key();
if(mod==1){P2_0=0;c++;}
T0Count=0;
}
}
Key扫描挪出也可,注意:
需要关闭时将P2_0置1.
定时器重置时间不可过长。