不明白为什么 外部中断1 能打断定时器中断0 实现减速?高手给解答下?
#include <reg52.h>
sbit LED1 = P1^0;
sbit LED2 = P1^1;
sbit DIR = P1^3;
unsigned int a;
unsigned int d;
void delay(int z)
{
unsigned int b,c;
for(b=z;b>0;b--)
for(c=20;c>0;c--);
}
void init()
{
TMOD = 0X11; //定时器0,1。16位定时器
TH0 = 0xa2;
TL0 = 0xe3; //装载初值17814.
TR0 = 1; //启动定时器0
ET0 = 1; //启动定时器0中断
TH1 = 0xfd;
TL1 = 0xe8; //装载初值17814.
TR1 = 1; //启动定时器1
ET1 = 1; //启动定时器1中断
IT0 = 0; //低电平触发
EX0 = 1; //外部中断0允许
IT1 = 0; //低电平触发
EX1 = 1; //外部中断1允许
EA = 1; //开总中断
}
void main()
{
init();
while(1); // 等待中断
}
void waizhong0() interrupt 0 //开外部中断0加速
{
if(TF0==1)
{
LED1 =~LED1;
TF0=0;
TH0 =0xb7;
TL0 = 0x98;
}
}
void waizhong1() interrupt 2 //开外部中断1减速
{
if(TF0==1)
{
a++;
TF0=0;
TH0 =0;
TL0 = 0;
if(a==11)
{
LED1 =~LED1;
a=0;
}
}
}
void timer0() interrupt 1 //定时器0中断服务程序
{
TH0 = 0xa2;
TL0 = 0xe3;
LED1 = ~LED1; //电机脉冲
}
void timer1() interrupt 3 //定时器1中断服务程序
{
TH1 = 0xfd;
TL1 = 0xe8;
LED2 = ~LED2; //电机脉冲
}
|