新手求帮助89c52单片机关于用定时器点亮led流水灯(有图,有程序)

2025-01-04 11:32:03
推荐回答(2个)
回答1:

你程序和图都有了没你想说什么?什么问题?大概程序好像也没什么问题吧?

回答2:

#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar temp, t0, t1;
bit t2;

sbit P10 = P1^0;

void main()
{
P10 = 1;
temp = 0xfe;
P0 = temp;
P2 = 0xff;

TMOD = 0x01;
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
ET0 = 1;
EA = 1;
TR0 = 1;
while(1);
}

void timer0() interrupt 1
{
TH0 = (65536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
t0++;
if(t0 == 10) {
t0 = 0;

t1++;
if(t1 == 8) {t1 = 0; t2 = ~t2; P10 = t2;}

temp = _crol_(temp, 1);
if(t2) {P0 = temp; P2 = 255;}
else {P2 = temp; P0 = 255;}
}
}

已经试验成功。