8888.jpg (143 KB, 下載次數: 39)
下載附件
2022-11-8 11:06 上傳
共陽數碼管顯示: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控制的這路好像沒有消隱。 |