51单片机数码管动态显示从右往左

求大神们救救孩子,因为C语言学的比较差,所以写了一周都没写正确要求(1)数码管从右往左显示(类似流水灯)117331就是一开始数码管:(第一次显示)_ _ _1。(第二次显示)_ _ 11。(第三次显示)_ 117。 (第四次显示)1173。(第五次显示)1733。(第六次显示)7331。 (第七次显示)331_。(第八次显示)31_ _。(第九次显示)1_ _ _。就是像流水灯一样从右往左动态显示 ,下划线是代表没有显示,在这里标出来方便大神们明白!图是计算器的仿真,也能显示的。救救孩子吧!

这是四位数码管从右从左流动显示,像滚动字幕一样的。用不着矩阵按键哪。

其实程序很简单,没那么复杂。程序如下

#include <reg51.h>

#define uchar unsigned char

#define uint  unsigned int

uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};//共阴段码码,0x00为灭

void delay()//延时子程序

{

uint y;

for(y=400;y>0;y--);

}

void main()

{

uchar n,x;

while(1)

{

n++;

if(n>50)//n为显示一屏显示次数,n大小可调节流动速度

{

n=0;

x++;//从下一个位置开始显示

if(x>8)x=0;

}

}

}

仿真结果

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-31
#include <reg51.h>
#define uchar unsigned char
#define uint  unsigned int

uchar data ds[4];


uchar code table[]={  
//共阴极字型码
0x3f,  //--0
0x06,  //--1
0x5b,  //--2
0x4f,  //--3
0x66,  //--4
0x6d,  //--5
0x7d,  //--6
0x07,  //--7
0x7f,  //--8
0x6f,  //--9
0x00,   //--NULL
0x40, //-
};




//位码
code uchar wei[]={0xfe,0xfd,0xfb,0xf7};
//code uchar wei[]={0x01,0x02,0x04,0x08};
void display() //显示子程序
{
static uchar a;
if(++a>3)a=0;
P2|=0x0f;
P0=table[ds[a]];
P2&=wei[a];
}


#define LENG 6//长度
uchar hc[LENG]={1,1,7,3,3,1,};//显示的嫩荣
uint jsbz=0;
uchar xsbz=0;
void xs(){
char i,i1;
for(i=3,i1=xsbz;i>=0;i--,i1--){
if((i1<0)||(i1>=LENG))ds[i]=10;
else ds[i]=hc[i1];
}

}
//主程序
void main()
{
TMOD=0X01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;

while(1)
{
xs();
;
}
}



void time0(void) interrupt 1 using 1  //定时中断子程序
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
display();
if(++jsbz>=1000){
jsbz=0;
if(++xsbz>=(LENG+3))xsbz=0;
}

}