8位数码管滚动显示2011023011
时间:10-02
整理:3721RD
点击:
这是8位数码管静态显示20110230,请求各位大神:如何让数字依次向左滚动,把所有的数字(2011023011)都显示出来,真心希望大神在下面的程序上改一下,急需!谢谢!
#include <reg52.h>
#define uchar unsigned char
uchar xuehao[] = {2 , 0, 1 , 1 , 0 , 2 , 3, 0} ;
code uchar ledcode[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,0x7f, 0x6f, 0x77, 0x7c,0x39, 0x5e, 0x79, 0x71};
code uchar ledseg[] = {0xfe , 0xfd, 0xfb , 0xf7 , 0xef , 0xdf , 0xbf , 0x7f} ;
void Delay (void)
{
uchar i ;
for (i = 0 ; i < 100 ; i ++) ;
}
void main (void)
{
uchar i ;
while (1)
{
for (i = 0 ; i < 8 ; i ++)
{
P0 = ledcode[xuehao[i]];
P2 = ledseg[i] ;
Delay () ;
P2 = 0xff ;
}
}
}
#include <reg52.h>
#define uchar unsigned char
uchar xuehao[] = {2 , 0, 1 , 1 , 0 , 2 , 3, 0} ;
code uchar ledcode[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,0x7f, 0x6f, 0x77, 0x7c,0x39, 0x5e, 0x79, 0x71};
code uchar ledseg[] = {0xfe , 0xfd, 0xfb , 0xf7 , 0xef , 0xdf , 0xbf , 0x7f} ;
void Delay (void)
{
uchar i ;
for (i = 0 ; i < 100 ; i ++) ;
}
void main (void)
{
uchar i ;
while (1)
{
for (i = 0 ; i < 8 ; i ++)
{
P0 = ledcode[xuehao[i]];
P2 = ledseg[i] ;
Delay () ;
P2 = 0xff ;
}
}
}
加一个左移循环算法,另外再用一个数组,
void main (void)
{
uchar i,num;
num = 0;
while (1)
{
for (i = 0 ; i < 8 ; i ++)
{
P0 = ledcode[xuehao[i + num]];
P2 = ledseg[i] ;
Delay () ;
P2 = 0xff ;
}
Delay () ; //延时显示
Delay () ;
if(num == 2) num = 0; //显示滚动,10 - 8 = 2
else num ++;
}
}
搞懂原理:定时依次送数