8051吧 关注:62贴子:372
  • 0回复贴,共1

问个问题,以下程序为什么会进入两遍主函数,而且中断就执行两次?

只看楼主收藏回复

#include <reg51.h>
#include <intrins.h>
sbit l1=P1^0;
sbit l2=P1^2;
unsigned char j,k;
int HM=0;
int CurTime=0;
void delay(unsigned char i);
void TIMER_ISR(void);
int Time3=2;
void Task2(void)
{
CurTime = HM;
if( Time3==CurTime/2 )//!= ?????
return;
Time3 = CurTime;
l2=~l2;
delay(50);
// l2=~l2;
}
int Time1=0;
void Task1(void)
{
CurTime = HM;
if( Time1==CurTime )
return;
Time1 = CurTime;
l1=~l1;
delay(100);
l1=~l1;
}
void main(void)
{
TH0 = 0xFC;
TL0 = 0x17;
//////////////////////////////////
TR0=1;
ET0=1;
TR1=1;
ET1=1;
EA=1;
l2=0;
l1=0;
while(1)
{
// delay(5);
//TIMER_ISR();
Task1();
Task2();
}
}
void delay(unsigned char i)//????
{
for(j=i;j>0;j--)
for(k=200;k>0;k--);
}
void TIMER_ISR(void)
{
HM++;
if(HM==5)
HM=0;
}
void interruptTimer0() interrupt 1 using 1
{ TL0=0xfe;
TH0=0x16;
//l1=~l1;
TIMER_ISR();
}
中中断只执行两次,而进入两次主函数?


IP属地:内蒙古来自Android客户端1楼2021-07-24 13:57回复