打卡等级:以坛为家II
打卡总天数:563
最近打卡:2026-03-07 13:04:41
已绑定手机
金牌会员
积分 2240
在調試AI8H8K64TL內置的LED驅動器驅動點陣LED的時候,發現更新數據的不能太快,不然就會有亮度不均的問題出現(并不是因為刷新率低頻閃),如果數據更新慢,就顯示很穩定,看不出有亮度不均的問題,看哪位大神有沒好的辦法處理這個,感覺是是LED驅動器的一個瓶頸?
燒錄用40MHZ,調整這個值就可以看出有沒閃爍,unsigned int delay_val = 50; // 初始延时 500ms,可修改以改变速度
#include <STC8H.H>
#include <intrins.h>
#include <absacc.h>
// ================== NUM字模表(数字0-9) ==================
unsigned char code NUM[][8] = {
{0x70,0x88,0x98,0xA8,0xC8,0x88,0x70,0x00}, // 0
{0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00}, // 1
{0xF0,0x08,0x08,0x70,0x80,0x80,0xF8,0x00}, // 2
{0xF0,0x08,0x08,0x30,0x08,0x08,0xF0,0x00}, // 3
{0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00}, // 4
{0xF8,0x80,0xF0,0x08,0x08,0x08,0xF0,0x00}, // 5
{0x70,0x80,0xF0,0x88,0x88,0x88,0x70,0x00}, // 6
{0xF8,0x08,0x10,0x20,0x40,0x40,0x40,0x00}, // 7
{0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00}, // 8
{0x70,0x88,0x88,0x78,0x08,0x88,0x70,0x00} // 9
};
// ================== 配置参数(根据调试结果) ==================
#define ROW_REVERSE 1 // 数组行序颠倒(NUM[][0]对应物理最后一行)
#define BIT7_IS_LEFT 1 // 字节的最高位(bit7)对应最左边列
#define COL_REVERSE 0 // 列序正常(左边数字的列0对应SEG0)
// ================== 全局变量 ==================
unsigned char i, r, c;
unsigned int row_data[8];
// ================== 函数声明 ==================
void Init(void);
void Display_Two_Digits_To_Region(unsigned char d_left, unsigned char d_right,
unsigned char xdata *p_low, unsigned char xdata *p_high);
void Delay_x10ms(unsigned int x); // x * 10ms 延时
// ================== 初始化 ==================
void Init(void)
{
unsigned char xdata *p;
P_SW2 |= 0x80;
P0M0 = 0x0F; P0M1 = 0x00;
P1M0 = 0x00; P1M1 = 0x00;
P2M0 = 0xFF; P2M1 = 0x00;
P3M0 = 0xF0; P3M1 = 0x00;
P4M0 = 0xFF; P4M1 = 0x00;
P5M0 = 0x00; P5M1 = 0x00;
P2DR = 0x00;
COMEN = 0xFF;
SEGENL = 0xFF;
SEGENH = 0xFF;
LEDCTRL = 0xA0; // 自动切换极性,硬件处理共阴/共阳
LEDCKS = 0x00;
// 清空所有显示RAM
p = (unsigned char xdata *)0xFB10; for (i = 0; i < 8; i++) p = 0;
p = (unsigned char xdata *)0xFB18; for (i = 0; i < 8; i++) p = 0;
p = (unsigned char xdata *)0xFB20; for (i = 0; i < 8; i++) p = 0;
p = (unsigned char xdata *)0xFB28; for (i = 0; i < 8; i++) p = 0;
EA = 1;
}
// ================== 将两个数字显示到指定区域 ==================
void Display_Two_Digits_To_Region(unsigned char d_left, unsigned char d_right,
unsigned char xdata *p_low, unsigned char xdata *p_high)
{
for (r = 0; r < 8; r++) row_data[r] = 0;
for (r = 0; r < 7; r++) {
unsigned char row_left, row_right;
if (ROW_REVERSE) {
row_left = NUM[d_left][6 - r];
row_right = NUM[d_right][6 - r];
} else {
row_left = NUM[d_left][r];
row_right = NUM[d_right][r];
}
// 左边数字占 bit0~4
for (c = 0; c < 5; c++) {
unsigned char bit_mask = BIT7_IS_LEFT ? (0x80 >> c) : (1 << c);
if (row_left & bit_mask) {
unsigned char target_c = COL_REVERSE ? (4 - c) : c;
row_data[r] |= (1 << target_c);
}
}
// 右边数字占 bit5~9
for (c = 0; c < 5; c++) {
unsigned char bit_mask = BIT7_IS_LEFT ? (0x80 >> c) : (1 << c);
if (row_right & bit_mask) {
unsigned char target_c = COL_REVERSE ? (4 - c) : c;
row_data[r] |= (1 << (target_c + 5));
}
}
}
for (r = 0; r < 7; r++) {
p_low[r] = (unsigned char)(row_data[r] & 0xFF); // SEG0~7
p_high[r] = (unsigned char)((row_data[r] >> 8) & 0x03); // SEG8~9
}
p_low[7] = 0;
p_high[7] = 0;
}
void Delay_x10ms(unsigned int x)
{
unsigned char i, j;
while (x--) {
_nop_(); _nop_();
i = 144; j = 157;
do { while (--j); } while (--i);
}
}
// ================== 主函数 ==================
void main(void)
{
unsigned int count = 0; // 计数值 0~1000
unsigned char thou, hund, tens, ones;
unsigned int delay_val = 50; // 初始延时 500ms,可修改以改变速度
Init();
// 共阴区和共阳区地址指针
unsigned char xdata *p_low_cath = (unsigned char xdata *)0xFB10;
unsigned char xdata *p_high_cath = (unsigned char xdata *)0xFB18;
unsigned char xdata *p_low_anod = (unsigned char xdata *)0xFB20;
unsigned char xdata *p_high_anod = (unsigned char xdata *)0xFB28;
while (1)
{
// 分解四位数字
thou = count / 1000;
hund = (count % 1000) / 100;
tens = (count % 100) / 10;
ones = count % 10;
// 共阴区显示千位和百位
Display_Two_Digits_To_Region(thou, hund, p_low_cath, p_high_cath);
// 共阳区显示十位和个位
Display_Two_Digits_To_Region(tens, ones, p_low_anod, p_high_anod);
// 延时(调整速度)
Delay_x10ms(delay_val);
// 计数递增,到1000后归零
count++;
if (count > 1000) count = 0;
}
}
Your browser does not support video tags.