【51单片机4位数码管左右移位显示0-9不用数组】2022-4-19
缘由51单片机,89c52的-嵌入式-CSDN问答
实现所有功能
#include "REG52.h"
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,119,124,57,94,121,113,118,128,255,64,0};//0-9A-FH.消隐-全显
unsigned char Js=0,miao=0,fen=0,shi=0,y=6,t=23,ls=0;//中断计时
void smxs(unsigned char mz,unsigned char w,unsigned char d)
{
unsigned char Xd=0;
P0=255;
P0=(255-(d==1?SmZiFu[mz]:(SmZiFu[mz]|0x80)));//小数点闪烁
P2=w;
while(++Xd);
}
void main()
{
unsigned char Xd=0,xz=255,cs=4,ss=20,s1=0,s2=0,s3=2,s4=3;
unsigned int wei=47474;unsigned long yw = 123; P0=P1=P2=P3=Js=0;
ZhongDuanSheZhi();
while(1)
{
if(!s2||s2==5||s2==6)
{
smxs(yw/1000,1,1);smxs(yw/100%10,2,1);smxs(yw/10%10,4,1);smxs(yw%10,8,1);
}
else P0=P2=0;
if(Js==20)
{
if(!s1){
yw=yw%1000*10+cs;
if(++cs>9)cs=0;else;
if(yw==123){cs=9;++s1;}else;
}else if(s2<6)smxs(++s2,1,1);else;
if(s2==6){
yw=yw/10+cs*1000;
if(--cs==255)cs=9;else;
if(yw==123){cs=4;--s1;s2=0;TR0=0;}else;
}
Js=0;
}
}
}
void ZhongDuan() interrupt 1
{
++Js;
TH0=0X4C;//0X4C 50 0XDC 10
TL0=0X00;
}