新手写了个16行32列的LED显示屏的51程序,但是在实现LED显示屏每隔1秒循环亮灭过程中只有中间2行能实现,第一行和最后一行不能实现,什么原因?各位大神帮帮忙啊
#include "reg51.h"
#define uchar unsigned char
uchar time;
sbit A1 = P0^0;
sbit B1 = P0^1;
void LineScan(char line)
{
switch(line)
{
case 0: A1=0;B1=0;
break;
case 1: A1=1;B1=0;
break;
case 2: A1=0;B1=1;
break;
case 3: A1=1;B1=1;
break;
default:
break;
}
}
void initTimer(void)
{
TMOD=0x1;
TH0=0xd8;
TL0=0xf0;
}
void timer0(void) interrupt 1
{
TH0=0xd8;
TL0=0xf0;
//add your code here.
time++;
}
void main(void)
{
initTimer();
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(time==50) //中断50次,0.5s
{
time=0;
LineScan(0);
}
if(time==50) //中断100次,1s
{
time=0;
LineScan(1);
}
if(time==50) //中断150次,1.5s
{
time=0;
LineScan(2);
}
if(time==50) //中断200次,2s
{
time=0;
LineScan(3);
}
}
}
{
if(time==50) //中断50次,0.5s
{
LineScan(0);
}
if(time==100) //中断100次,1s
{
LineScan(1);
}
if(time==150) //中断150次,1.5s
{
LineScan(2);
}
if(time==200) //中断200次,2s
{
time=0;
LineScan(3);
}
}
最后一次再清 time , 试看看了.
一周热门 更多>