|
三位數(shù)碼管的顯示問題,因為之前的掃描方式亮度不均勻,換了下面這種掃描方式,但更換后發(fā)現(xiàn)數(shù)值顯示有問題 如我輸入值為 1.1 數(shù)碼管三位 應(yīng)為 1 . 1 0 ; 實際顯示我拍照了 請看大圖
調(diào)試了一下 disx 值 固定為 0 ,1 , 2 , 3時 對應(yīng)的位選上顯示的數(shù)值都是正常的 ,但是設(shè)為 disx++; 后就不正常了 。
小白技術(shù)不太行 尋求幫助,給我點思路 ,我自己修改就可以的 感謝
#include "smg.h"
#include "STC8H.H"
#include "button.h"
#include "eeprom.h"
extern void abc(int c);
// 數(shù)碼管位選引腳定義
#define DIGIT1 P13
#define DIGIT2 P15
#define DIGIT3 P17
#define DIGIT4 P10
unsigned char segmentCodes[] = {
0x3F, // 0
0x06, // 1
0x5b, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F, // 9
0x80, // .
};
void smg_io_init()
{
P1M0 |= 0xee;
P1M1 &= ~0xee;
P3M0 |= 0x31;
P3M1 &= ~0x31;
P5M0 |= 0x30;
P5M1 &= ~0x30;
SEG_A = 0;
SEG_B = 0;
SEG_C = 0;
SEG_D = 0;
SEG_E = 0;
SEG_F = 0;
SEG_G = 0;
SEG_DP = 0;
}
char dppos = 0; // 默認(rèn)小數(shù)點位置在最后一位(百分位)
char displayBuffer[4] = {0}; // 存儲待顯示的數(shù)字,包括整數(shù)、小數(shù)點和兩位小數(shù)部分
char disx = 0;
char AJ ;
void DisplayVoltage(double voltage) {
unsigned int sw,gw,x1, x2,number,xs;
float abc;
number = (int)voltage;
abc = voltage - number;
// 將電壓值轉(zhuǎn)換為整數(shù)和小數(shù)部分
sw = number/10 ;
gw = number%10 ;
abc *= 100;
x1 = (int)abc/10;
x2 = (int)abc%10;
xs = 10;
// 設(shè)置顯示緩沖區(qū)
if (voltage >= 10.00) {
displayBuffer[0] = sw ; // 十位數(shù)
displayBuffer[1] = gw ;
displayBuffer[3] = xs ;
displayBuffer[2] = x1;//
dppos=2;
} else {
displayBuffer[0] = gw ; // 個位數(shù)
displayBuffer[3] = xs; // 個位數(shù)
displayBuffer[1] = x1; // 個位數(shù)
displayBuffer[2] = x2; // 小數(shù)點后一位
dppos=1;
}
}
int f;
extern x1;
unsigned int digit ;
void DisplayVoltage1() {
unsigned char mask = 0x01;
f++;
DIGIT1 = 1;
DIGIT2 = 1;
DIGIT3 = 1;
// 根據(jù)digitIndex選中對應(yīng)的數(shù)碼管
switch (disx) {
case 0:
DIGIT1 = 0;
DIGIT2 = 1;
DIGIT3 = 1;
break;
case 1:
DIGIT1 = 1;
DIGIT2 = 0;
DIGIT3 = 1;
break;
case 2:
DIGIT1 = 1;
DIGIT2 = 1;
DIGIT3 = 0;
break;
case 3:
if(dppos == 1) {
DIGIT1 = 0;
DIGIT2 = 1;
DIGIT3 = 1;
}
else if(dppos == 2) {
DIGIT1 = 1;
DIGIT2 = 0;
DIGIT3 = 1;
}
break;
}
digit = displayBuffer[disx];
switch (f-1) {
case 0: SEG_A = (segmentCodes[digit] & mask) ? 1 : 0; break;
case 1: SEG_B = (segmentCodes[digit] & (mask << 1)) ? 1 : 0; break;
case 2: SEG_C = (segmentCodes[digit] & (mask << 2)) ? 1 : 0; break;
case 3: SEG_D = (segmentCodes[digit] & (mask << 3)) ? 1 : 0; break;
case 4: SEG_E = (segmentCodes[digit] & (mask << 4)) ? 1 : 0; break;
case 5: SEG_F = (segmentCodes[digit] & (mask << 5)) ? 1 : 0; break;
case 6: SEG_G = (segmentCodes[digit] & (mask << 6)) ? 1 : 0; break;
case 7: SEG_DP =(segmentCodes[digit] & (mask << 7)) ? 1 : 0; break;
}
if (f == 9) {
disx++;
if(disx > 3)
disx=0;
}
else if(f > 9 ) f = 0;
}------------------------------------------------------------------------------
void Timer0_Init() //100微秒@11.0592MHz
{
//定時器時鐘12T模式
TMOD &= 0xf0; //設(shè)置定時器模式
TMOD |= 0x01;
TL0 = 0xCD; //設(shè)置定時初始值
TH0 = 0xD4; //設(shè)置定時初始值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時器0開始計時
ET0 = 1;
EA = 1;
}
void TM0_Isr() interrupt 1 //每隔兩毫秒
{
DisplayVoltage1();
TL0 = 0xCD; //設(shè)置定時初始值
TH0 = 0xD4; //設(shè)置定時初始值
}
|
|