菜鸟问个简单的灯闪烁问题
# include <reg52.h>
char a=0;
void main()
{ TMOD = 0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{P1=0;
if(a == 20)
P1=0xff;
}
}
void i() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}
为什么这段代码,8个LED不会闪烁呢?用定时器或延迟函数都不行!请问各位高手这是怎么回事呀?我用软件单步看P1的变化是对的!!求帮忙啊!谢谢了!
[解决办法]
# include <reg52.h>
char a=0;
void main()
{ TMOD = 0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{ P1=0;
if(a >= 20)
{
P1=0xff;
if(a==40){
a=0;
}
}
}
}
void i() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}
[解决办法]
#include <reg52.h> char a = 0;void main(){ TMOD = 0x01; TH0 = (65536 - 50000) / 256; TL0 = (65536 - 50000) % 256; EA = 1; ET0 = 1; TR0 = 1; while (1) { ; }}void i() interrupt 1{ TH0 = (65536-50000) / 256; TL0 = (65536-50000) % 256; if (++a > 20) { a = 0; // 试试吧! P1 = ~P1; }}