#include <REGX52.H>
#include "Delay.h"
void Timer0Init(void)
{
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0=1;
EA=1;
PT0=0;
}
unsigned char Key_2=0;
void main()
{
Timer0Init();
IT0 = 1; //设置为下降沿触发
EX0 = 1; //外部中断0中断允许位
EA = 1;
while(1)
{
}
}
Int0() interrupt 0 using 1
{
P1_2=0;
Key_2=1;
}
void Timer0_Routine() interrupt 1 //1ms进入一次
{
static unsigned int T0Count,x2=0;
TL0 = 0x18; //设置定时初值
TH0 = 0xFC; //设置定时初值
T0Count++;
if(T0Count>=100)//每100ms进入一次
{
T0Count=0;
if(Key_2==1)
{
x2++;//
if(x2>50){P1_2=1;Key_2=0;x2=0;}
}
}
}