【蓝桥杯单片机笔记】4-数码管动态显示

动态显示思路
逐个显示+极短的延时
例如在蓝桥杯开发板上动态显示U 3.14

#include"reg52.h"
//                              0    1     2     3     4     5     6     7     8     9     A     B     C     D     E     F
unsigned char code duanma[]={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71,
//black  -    H      J     K     L    N      o     P     U     t    G     Q     r    M      y
~0x00,~0x40,~0x76,~0x1E,~0x70,~0x38,~0x37,~0x5C,~0x73,~0x3E,~0x78,~0x3d,~0x67,~0x50,~0x37,~0x6e};

unsigned char code duanma_Dot[]= {~0xBF,~0x86,~0xDB,~0xCF,~0xE6,~0xED,~0xFD,~0x87,~0xFF,~0xEF,~0x46};
//                                   0.    1.    2.    3.    4.    5.    6.    7.    8.    9.   -1
void SelectHC573(unsigned char n){
	switch(n){
		case 4:
			P2 = (P2 & 0x1f) | 0x80;
			break;
		case 5:
			P2 = (P2 & 0x1f) | 0xa0;
			break;
		case 6:
			P2 = (P2 & 0x1f) | 0xc0;
			break;
		case 7:
			P2 = (P2 & 0x1f) | 0xe0;
			break;	
	}
}

void Display(unsigned char value,unsigned char pos){
	SelectHC573(7);
	P0 = 0xff;
	SelectHC573(6);
	P0=0x01<<pos;
	SelectHC573(7);
	P0=value;
	
}

void InitSystem(){
	SelectHC573(4);
	P0=0xff;
	SelectHC573(5);
	P0=0x00;
}

void delay(unsigned char t){
	while(t--);
}

void show(){
		Display(duanma[31],0);
	delay(50);
		Display(duanma[25],1);
	delay(50);
		Display(duanma[10],2);
	delay(50);
		Display(duanma[22],3);
	delay(50);
}

int main(){
	InitSystem();
	while(1){
	show();
	}
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沅_Yuan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值