【51单片机独立按键控制数码管自增自减】2023-10-5

缘由.利用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
但是有缺陷
...
相关推荐
ComputerInBook1 小时前
C++中“概念”(concept)之含义
开发语言·c++·概念·concept
程序员老舅1 小时前
Linux:谁把根目录卸载了?
linux·c++·容器·linux内核·文件系统·根目录
2301_800895101 小时前
第十四届蓝桥杯国赛b组真题---备战国赛版h
算法·蓝桥杯·深度优先
生信之灵1 小时前
告别模板配准:LAMNr Flow如何用一次求逆破解多模态解剖对齐难题
人工智能·算法
SHARK_pssm1 小时前
【数据结构——复杂度】
c语言·数据结构·经验分享·笔记
焜昱错眩..1 小时前
力扣周赛难题 3906.统计网格路径中好整数的数目——自我拆解学习与分析(数位dp上下界的奇妙)
学习·算法·leetcode·动态规划
石山代码1 小时前
c++类型判断
开发语言·c++
wangl_921 小时前
初探 C# 15 的 Union Types
java·开发语言·算法·c#·.net·.net core