缘由.利用51单片机按键控制动态数码管显示数字,用独立按键控制实现"显示数字"(个位)以差值1进行加减_编程语言-CSDN问答
cpp
#include "reg52.h"
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,128,0};//0-9.
sbit k1=P3^0;
sbit k2=P3^1;
void main()
{//缘由https://ask.csdn.net/questions/8006751/54343964
unsigned char ys=0,sy=0,xd=0,ls=0;
while(1)
{
if(++ys==0)
{
P0=P1=255;
P0=1;
P1=255-SmZiFu[sy];
}
if(k1==0&&++xd==0){while(k1==0);if(sy<9)++sy;}
if(k2==0&&++xd==0){while(k2==0);if(sy)--sy;}
}
}

cpp
#include "reg52.h"
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,128,0};//0-9.
sbit k1=P3^0;
sbit k2=P3^1;
void main()
{//缘由https://ask.csdn.net/questions/8006751/54343964
unsigned char ys=0,sy=0,xd=0,ls=0;
while(1)
{
if(++ys==0)
{
P0=P1=255;
++ls;
P0=ls;
if(ls==1)P1=255-SmZiFu[sy/10];
if(ls==2)P1=255-SmZiFu[sy%10];
if(ls==2)ls=0;
}
if(k1==0&&++xd==0){while(k1==0);if(sy<9)++sy;}
if(k2==0&&++xd==0){while(k2==0);if(sy)--sy;}
}
}

cpp
#include <REGX52.H>
#include <INTRINS.H>
void Delay(unsigned int xms)
{
unsigned char data i, j;
while(xms){
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
xms--;
}
}
void smg(unsigned char Location,Number)
{
unsigned char smgWeiShu[]={0xe3,0xe7,0xeb,0xef,0xf3,0xf7,0xfb,0xff};
unsigned char smgNumber[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
P2=smgWeiShu[Location];
P0=smgNumber[Number];
Delay(1);
P0=0x00;
}
void main()
{
unsigned int i=0;
while(1)
{
if (P3
...
P3_1==0)
{
Delay(20);
while(P3_1==0);
Delay(20);
if(i<9)
{
i++;
}
smg(0,i);
}
else if(P3_0==0)
{
Delay(20);
while(P3_0==0);
Delay(20);
if(i>0)
{
i--;
}
Delay(20);
smg(0,i);
}
else{
smg(0,i);
}
}
}
...
这个代码就可以完成
...
10-06 21:44
但是有缺陷
...