当到外部中断时 定时器不是应该不能再申请中断了吗 这里是哪个中断先发生
#include<reg52.h>
unsigned char num;//定义采集的的周期
unsigned int number;//脉冲计数
unsigned char
time_Flag=0;//计时标志位
void main(void)
{unsigned int speed;
TMOD = 0X01;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
EA= 1;
TR0 = 1;
ET0 = 1;
EX0 = 1; //开启外部中断0
IT0 = 1; //下降沿触发
while(1)
{
if(Time_Flag==1)
{Time_Flag=0;
speed=number;
number=0;}
}
}
void Time0() interrupt 1
{TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
num++;if (num == 20)//定时采集周期大约 1s
{num = 0;
Time_Flag=1;
}
}
void In0() interrupt 0
{
number++;
}
一周热门 更多>