最近在调毕业设计的板子,在调试OLED的过程中发现了一个汉字显示上的BUG;
初始汉字显示函数:
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{
u8 t,adder=0;
OLED_Set_Pos(x,y);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
adder+=1;
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
adder+=1;
}
}
取字模的数组表
/*************************智能开关********************/
{
0x00,0x00,0xA0,0x60,0x58,0xF6,0x50,0xA8,0x28,0x70,0x90,0x90,0x50,0x30,0x10,0x00},
{
0x00,0x00,0x04,0x02,0x01,0x00,0x7E,0x4A,0x2A,0x2A,0xFE,0x02,0x00,0x00,0x00,0x00},/*"智",37*/
{
0x00,0x00,0x60,0x50,0x4C,0xC4,0x30,0x00,0x7E,0x90,0x90,0x88,0x40,0x00,0x00,0x00},
{
0x00,0x00,0x34,0x0B,0x0B,0x66,0x39,0x00,0x1F,0x24,0x44,0x42,0x20,0x30,0x00,0x00},/*"能",38*/
{
0x00,0x80,0x80,0x80,0x80,0x90,0xF8,0x88,0x88,0xF8,0x88,0x88,0x40,0x40,0x00,0x00},
{
0x00,0x00,0x00,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00},/*"开",39*/
{
0x00,0x00,0x00,0x00,0x00,0x48,0x58,0xC0,0x20,0x38,0x26,0x00,0x00,0x00,0x00,0x00},
{
0x00,0x00,0x00,0x42,0x22,0x12,0x0D,0x03,0x05,0x09,0x31,0x61,0x61,0x41,0x40,0x00},/*"关",40*/
使用此函数时,当调用Hzk[][32]数组中所存放的第37个汉字时,会出现如下显示:
可以看出,汉字被砍成了两半,并且上下颠倒,而在数组中所存放的前32个汉字能够正常显示,基于这种情况,只能够分段处理数组中的两行数据。
修改后的代码:
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{
u8 t,adder=0;
OLED_Set_Pos(x,y);
if(no < 32)
{
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
adder+=1;
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
adder+=1;
}
}
if(no >= 32)
{
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no-1][t],OLED_DATA); //处理所存放的第33个汉字时,首先写入第二行数据
adder+=1;
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
adder+=1;
}
}
}