188数码管新版本,简单易懂
LED188.c
新版本解决以下问题
1.减少占用内存,仅需一个数组便可解决0-9的显示,如果需要显示abcdef,可以在数组后面增加元素,且存放在ROM中。
2.解决了亮度不均匀的问题,逐段扫描,所有段码点亮的时间是一致的,如果再出现亮度不均,必定是硬件问题了。
3.残影问题和本程序没关系,主要是MCU管脚翻转频率过慢,导致管脚还有残留电压,所以需要设置到最大频率,另外尽可能提高扫描速度。
4.这是最终版本,也是量产产品的版本,分享不易,大家看后点赞收藏吧。
#include "LED188.h" uc8 number_table[11]={ 0x77,//0 0x42,//1 0x6D,//2 0x6E,//3 0x5A,//4 0x3E,//5 0x3F,//6 0x46,//7 0x7F,//8 0x7E,//9 0x00//nop }; void Set_ALL_LED_IN(void) { LED1_IN();LED2_IN();LED3_IN();LED4_IN();LED5_IN(); } void Set_ALL_LED_Low(void) { LED1_L();LED2_L();LED3_L();LED4_L();LED5_L(); } DisplayData Disp_data; void Refresh_displaysram(void) { Disp_data.ESsram =number_table[Disp_data.eshi]; Disp_data.EGsram =number_table[Disp_data.ege]; } void Display_Tube(void)//放在定时器中断,1ms运行 { static u8 case_cnt=0x00; if(!Disp_data.B_EN) { Set_ALL_LED_Low(); return; } Set_ALL_LED_IN(); if(case_cnt<4) {LED1_L();LED1_OUT();} else if(case_cnt<8) {LED2_L();LED2_OUT();} else if(case_cnt<12) {LED3_L();LED3_OUT();} else if(case_cnt<16) {LED4_L();LED4_OUT();} else if(case_cnt<18) {LED5_L();LED5_OUT();} else { case_cnt=0; LED1_L();LED1_OUT(); } switch(case_cnt) { case 0x00:if(GetBit(Disp_data.EGsram,6))LED2_H(); break;//1 case 0x01:if(GetBit(Disp_data.EGsram,5))LED3_H(); break; case 0x02:if(GetBit(Disp_data.EGsram,4))LED4_H(); break; case 0x03:if(GetBit(Disp_data.EGsram,3))LED5_H(); break; case 0x04:if(GetBit(Disp_data.EGsram,2))LED1_H(); break; case 0x05:if(GetBit(Disp_data.ESsram,6))LED3_H(); break; case 0x06:if(GetBit(Disp_data.ESsram,5))LED4_H(); break; case 0x07:if(GetBit(Disp_data.ESsram,0))LED5_H(); break;//2 case 0x08:if(GetBit(Disp_data.EGsram,1))LED1_H(); break; case 0x09:if(GetBit(Disp_data.ESsram,2))LED2_H(); break; case 0x0A:if(GetBit(Disp_data.ESsram,1))LED4_H(); break; case 0x0B:if(GetBit(Disp_data.ESsram,4))LED5_H(); break; case 0x0C:if(GetBit(Disp_data.EGsram,0))LED1_H(); break; case 0x0D:if(Disp_data.B_EBAI) LED2_H(); break; case 0x0E:if(Disp_data.B_EBAI) LED3_H(); break; case 0x0F:if(GetBit(Disp_data.ESsram,3))LED5_H(); break; case 0x10:if(Disp_data.B_PER) LED2_H(); break; case 0x11:if(Disp_data.B_FCHG) LED3_H(); break; default:case_cnt=0; break; } case_cnt++; } void Dispdata_Init(void) { Disp_data.init_cnt =2;//开机全显2s Disp_data.B_EN =1;//0=关屏 Set_ALL_LED_Low(); //熄灭所有管脚 } void Refresh_188Data(void) { if(!Disp_data.B_JC) return; Disp_data.B_JC=0; Disp_data.B_PD=0; Disp_data.B_LowV=0; Disp_data.B_PER=1; Disp_data.B_TOG=!Disp_data.B_TOG; Disp_data.SOC=88; //可以显示0-199的数字 Disp_data.B_CHGING=0;//1=充电个位闪烁 Disp_data.B_LowV=0; //1=低电个位闪烁 if(Disp_data.SOC>99) { Disp_data.B_EBAI=1; Disp_data.eshi=(Disp_data.SOC-100)/10; Disp_data.ege=Disp_data.SOC%10; } else { Disp_data.B_EBAI=0; Disp_data.eshi=Disp_data.SOC/10; Disp_data.ege=Disp_data.SOC%10; if(!Disp_data.eshi) Disp_data.eshi=0x0A; if(Disp_data.B_TOG && (Disp_data.B_CHGING||Disp_data.B_LowV)) Disp_data.ege=0x0A; } if(Disp_data.init_cnt)//修改此值,实现开机全显,错误全闪的时间和次数 { Disp_data.init_cnt--; if(Disp_data.init_cnt<2) Disp_data.B_TOG=1; if(Disp_data.B_TOG) { Disp_data.B_PER =1; Disp_data.B_PD =1; Disp_data.B_EBAI=1; Disp_data.eshi =8; Disp_data.ege =8; } else { Disp_data.B_PER =0; Disp_data.B_PD =0; Disp_data.B_EBAI=0; Disp_data.eshi =10; Disp_data.ege =10; } } Refresh_displaysram(); }