共阳数码管显示:com1 com2 com3显示数字正常,但com4位选控制的这六个灯,前三个为单位显示,后三个为电量显示,单位或电量显示时,正常是不需要亮的灯是不亮,但是不亮时会微微发亮?我也明白是前面显示数字的段码影响的,这种问题有解决办法吗?
单片机源程序如下:
#include "display.h"
//共阳数码管编码表
unsigned char code leddata[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0x00};
//0, 1, 2 3 4 5 6 7 8 9 A B C D E F 16 17
//数据显示缓冲区
unsigned char LEDBuf[]= {17,17,17,3,3};
//位选信号
unsigned char code PLACE_CODE[] ={0xfd,0xfb,0xf7,0xdf};
//1111 1101 1111 1011 1111 0111 1101 1111
//单位段码
unsigned char code unit[] ={0xfe,0xfd,0xfb,0xf8};
// 1111 1110 /1111 1101/1111 1011 //1111 1000
//电池段码
unsigned char code BAT[] ={0xFF,0xEF,0xCF,0x8F};
// 1111 1111/1110 1111/1100 1111/1000 1111; // 1000 1111
unsigned char digdot0=0,digdot1=0;
void Display()
{
unsigned char i;
//1.送段码
//2.送位选
//3.延时 1ms 全部数码管显示时间<10ms内
//4.消隐
switch(i)
{
case 0:
duan=0xff;
duan=leddata[LEDBuf[0]];
if(digdot0==1)
{
duan=leddata[LEDBuf[0]]&0x7f;
}
wei=PLACE_CODE[0];
i++;
break;
case 1:
duan=0xff;
duan=leddata[LEDBuf[1]];
if(digdot1==1)
{
duan=leddata[LEDBuf[1]]&0x7f;
}
wei=PLACE_CODE[1];
i++;
break;
case 2:
duan=0xff;
duan=leddata[LEDBuf[2]];
wei=PLACE_CODE[2];
i++;
break;
case 3:
duan=0xff;
duan=unit[LEDBuf[3]];
wei=PLACE_CODE[3];
i++;
break;
case 4:
duan=0xff;
duan=BAT[LEDBuf[4]];
wei=PLACE_CODE[3];
i=0;
break;
default:break;
}
}
下面是把case3 和case4 段码相与一起送也试过,也不行!
——————————————————————————————————————————————————————————
case 3:
duan=0xff;
duan=unit[LEDBuf[3]];
wei=PLACE_CODE[3];
i++;
break;
case 4:
duan=0xff;
duan=BAT[LEDBuf[4]];
wei=PLACE_CODE[3];
i=0;
break;
合并一起送段码也不行。
case 3:
duan=0xff;
duan=unit[LEDBuf[3] & BAT[LEDBuf[4]];
wei=PLACE_CODE[3];
i=0;
break;
下面是更新了wulin老师的代码,故障现像依旧。
#include "display.h"
//共阳数码管编码表
unsigned char code leddata[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0x00};
//0, 1, 2 3 4 5 6 7 8 9 A B C D E F 16 17
//数据显示缓冲区
unsigned char LEDBuf[]= {17,17,17,3,3};
//位选信号
unsigned char code PLACE_CODE[] ={0xfd,0xfb,0xf7,0xdf};
// 1111 1101/1111 1011/1111 0111/1101 1111
//单位段码
unsigned char code unit[] ={0xfe,0xfd,0xfb,0xf8};
// 1111 1110 /1111 1101/1111 1011 /1111 1000
//电池段码
unsigned char code BAT[] ={0xFF,0xEF,0xCF,0x8F};
// 1111 1111/1110 1111/1100 1111/1000 1111; / 1000 1111
unsigned char digdot0=0,digdot1=0;
void Display()
{
static unsigned char i;//静态变量
duan=0xff;//段消隐
switch(i)
{
case 0:
wei=PLACE_CODE[0];
if(digdot0==1) duan=leddata[LEDBuf[0]]&0x7f;
else duan=leddata[LEDBuf[0]];
break;
case 1:
wei=PLACE_CODE[1];
if(digdot1==1) duan=leddata[LEDBuf[1]]&0x7f;
else duan=leddata[LEDBuf[1]];
break;
case 2:
wei=PLACE_CODE[2];
duan=leddata[LEDBuf[2]];
break;
case 3:
wei=PLACE_CODE[3];
duan=unit[LEDBuf[3]];
break;
case 4:
wei=PLACE_CODE[3];
duan=BAT[LEDBuf[4]];
break;
default:break;
}
i=++i%5;
}
现象更新:1.今天发现是com4的哪路不对(单位和电量显示灯都会随显示数字的变化微亮),com1 com2 com3显示数字没有这种现像。也就是说com4控制的这路好像没有消隐。 |