猿问

c语言中断问题

led0是中断,led1,2,3是我测试用的,中断返回不应该是回到while(1)里吗?为什么led2一直是灭的,它不应该和led3一样是闪烁的吗?

#include <reg52.h>

typedef unsigned char u8;

typedef unsigned int u16;

sbit led0 =  P1^0;

sbit led1 =  P1^1;

sbit led2 =  P1^2;

sbit led3 =  P1^3;

u8 timer;

void delay(u16 num)

{

u16 x,y;

for(x=num; x>0; x--)

for(y=110; y>0; y--)

{

;//??1ms

}

}

void main (void)

{

  TMOD = 0x01;

  TH0 = (65535-50000)/256;

led1 = 0;

delay(300);

led1 = 1;

  TL0 = (65535-50000)%256;

  EA = 1;

  ET0 = 1;

  TR0 = 1;

  while(1)

  {


  led2 = 0;

delay(100);

  led2 = 1;

delay(100);

  }

}

void timer_ser(void) interrupt 1

{

  TH0 = (65535-50000)/256;

led3 = 0;

delay(100);

led3 = 1;

delay(100);

  TL0 = (65535-50000)%256;

  timer ++;

  if(timer == 20)

  {

    timer = 0;

led0 = ~led0;

  }

}


慕田峪6419932
浏览 1100回答 1
1回答

慕田峪6419932

我用的是protues仿真,我又改了几下代码,感觉好像是 protues有问题?
随时随地看视频慕课网APP
我要回答