为什么定时器中断/**/中隐去的内容放到主函数while(1)里,led只亮一次,放在定时器中断里就可以反复亮灭
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit led=P2^7;
sbit jum=P3^2;
uint x;
uchar n,num;
void init()
{
num=0;
led=0;
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
/* if(num==10)
{
led=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
if(num==20)
{
num=0;
led=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num=0;
} */
}
void main()
{
init();
TMOD=0X11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(num==10)
{
led=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
if(num==20)
{
num=0;
led=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num=0;
n++;
}
}
} |