【51单片机用数码管显示流水灯的种类是按钮控制数码管加一和流水灯】2022-6-14

缘由

cpp 复制代码
#include "REG52.h"
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64}; //共阴0~F消隐减号
unsigned char Js=0, miao=0;//中断计时 秒 分 时 毫秒
sbit k0=P3^0;
sbit k1=P3^1;
void smxs(unsigned char mz, unsigned char w)
{
    unsigned char Xd=0;
    P0=255;
    P0=255-smgduan[mz];
    P2=w;
    while(++Xd);
}
void ZhongDuanSheZhi()
{
    TH0+=(65536-9216/2)/256;/*11.0592MHz定时器赋初值,定时5ms触发中断,自动补偿方式*/
    TL0+=(65536-9216/2)%256; 
    TMOD=0X01;//16位定时器/计数器
    TR0=1; //启动定时器T0。
    ET0=1; //开启定时器
    EA=1; //全局中断开关
}
void main()
{
    unsigned char Xd=0,qh=0,ci=0;//消抖
		unsigned int shu=0;P1=0;
    ZhongDuanSheZhi();
    while(1)
    {
			if(k0==0&&++Xd==0)
			{
				if(++qh>4)qh=0;
				(qh==1?P1=240:qh==2?P1=3:qh==3?P1=128:qh==4?P1=1:qh==0?P1=0:0);
				while(k0==0);
			}
			if(k1==0&&++Xd==0){P1=0;if(qh==0)qh=5;else qh=0;smxs(qh,1);while(k1==0);}
			if(qh>0&&qh<5)smxs(qh,1);else smxs(qh,16);
			if(Js>=100)
			{
				Js=0;
				if(qh==0){if(P1==1)P1=0;else P1=1;}
				else if(qh==1){if(P1==240)P1=15;else P1=240;}
				else if(qh==2){if(P1<192)P1*=2;else P1=3;}
				else if(qh==3){if((P1/=2)==0)P1=128;else;}
				else if(qh==4)++P1;else;
			}
    }
}
void ZhongDuan() interrupt 1
{
    ++Js;
    TH0+=(65536-9216/2)/256;
    TL0+=(65536-9216/2)%256;        
}
相关推荐
tingshuo29174 小时前
S001 【模板】从前缀函数到KMP应用 字符串匹配 字符串周期
笔记
RuoZoe10 小时前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_4 天前
C语言内存函数
c语言·后端
西岸行者5 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言
czy87874755 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
starlaky5 天前
Django入门笔记
笔记·django
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意5 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
一个人旅程~5 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑