博士
最后登录1970-1-1
在线时间 小时
注册时间2016-7-16
|
本帖最后由 Mr.Guo 于 2016-9-1 16:30 编辑
最近在万年历其中农历汉字显示部分遇到 了点问题:
1.首先避开SD卡字库 ,在代码中采用取字模的办法。
2.设计思路:字模存放在数组中,数组采用结构体封装。
3.设计显示函数,显示函数在结构体中取字模显示。
问题:在显示函数设计API的时候不知道该怎么做???
struct Sky_Code
{
unsigned char sky_code1[128]; //字体为32X32
unsigned char sky_code2[128];
unsigned char sky_code3[128];
unsigned char sky_code4[128];
unsigned char sky_code5[128];
unsigned char sky_code6[128];
unsigned char sky_code7[128];
unsigned char sky_code8[128];
unsigned char sky_code9[128];
unsigned char sky_code10[128];
};
void Dis_skycode(uint16_t x, uint16_t y, uint16_t color,struct Sky_Code *sky) //这个接口怎么设计
{
uint8_t page , column;
uint32_t tmp_char=0;
uint32_t number[128]; //当初的思路是:通过API把结构体某成员传递进来 ,然后把该成员赋值给number数组
LCD_OpenWindow(x, y, 32, 32);
LCD_ILI9341_CMD(0X2C);
for(page=0; page< 32; page++)
{
tmp_char=(number[page*4]<<24);
tmp_char|=(number[4*page+1]<<16);
tmp_char|=(number[4*page+2]<<8);
tmp_char|=number[4*page+3];
for (column=0; column< 32; column++)
{
if ( tmp_char & (0x01<<31) )
{
LCD_WR_Data(color);
}
else
{
LCD_WR_Data(BACKGROUND);
}
tmp_char <<= 1;
}
}
}
为什么要这样做???因为农历日期显示需要39个汉字 如果每个字体显示都编写一个显示函数那代码就要1k多行。
执行的功能是一样。唯一不一样的是字模。也就是传入的数组不一样。。。针对这一点想到了用结构体封装数组,然后通过结构体来操作显示函数。
求大神指点》》》或者那位大神有更好的方法
/*******************************************************************************************************************************************/
问题已解决:
第一种方案:直接使用数组做为显示函数的变量输入。这是最简单的。
第二种方案:还是把数组用结构体封装,用结构体成员作为输入变量。
/*******************************************************************************************************************************************/
方案一:
数组定义参考上边的。
void Dis_skycode11(uint16_t x, uint16_t y, uint16_t color,unsigned char v[128])
{
uint8_t page , column;
uint32_t tmp_char=0;
LCD_OpenWindow(x, y, 32, 32);
LCD_ILI9341_CMD(0X2C);
for(page=0; page< 32; page++)
{
tmp_char=(v[page*4]<<24);
tmp_char|=(v[4*page+1]<<16);
tmp_char|=(v[4*page+2]<<8);
tmp_char|=v[4*page+3];
for (column=0; column< 32; column++)
{
if ( tmp_char & (0x01<<31) )
{
LCD_WR_Data(color);
}
else
{
LCD_WR_Data(BACKGROUND);
}
tmp_char <<= 1;
}
}
}
方案二:
struct typFNT_GB16 // 汉字字模数据结构
{
unsigned char Index[3]; // 汉字内码索引
unsigned char Msk[128]; //点阵码数据
};
const struct typFNT_GB16 codeGB_16[] = // 字库 字码
{
"子",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0xFF,0xFF,0xE0,0x00,0x00,0x01,0xE0,0x00,0x00,0x03,0x00,0x00,0x00,0x06,0x00,
0x00,0x00,0x18,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x10,0x00,0x01,0x80,0x38,0x3F,0xFF,0xFF,0xFC,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x3F,0x80,0x00,0x00,0x07,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
"丑",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xE0,0x04,0x0C,0x00,0xC0,0x00,0x0C,0x00,0xC0,
0x00,0x0C,0x00,0xC0,0x00,0x0C,0x00,0xC0,0x00,0x0C,0x00,0xC0,0x00,0x0C,0x00,0xC0,0x00,0x08,0x01,0x80,0x00,0x08,0x01,0x80,0x00,0x18,0x01,0x80,0x07,0xFF,0xFF,0x80,
0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,0x00,0x18,0x01,0x80,
0x00,0x10,0x01,0x80,0x00,0x30,0x01,0x80,0x00,0x30,0x03,0x10,0x00,0x30,0x03,0x38,0x3F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor)
{
unsigned int i,j,k,a;
uint8_t page , column;
uint32_t tmp_char=0;
uint32_t table[128];
LCD_ILI9341_CMD(0X2C);
for (k=0;k<1280;k++)
{
if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1]))
{
for(i=0;i<128;i++)
{
unsigned short m=codeGB_16[k].Msk;
table=m;
}
for(page=0; page<32; page++)
{
tmp_char=(table[page*4]<<24);
tmp_char|=(table[4*page+1]<<16);
tmp_char|=(table[4*page+2]<<8);
tmp_char|=table[4*page+3];
for (column=0; column< 32; column++)
{
if ( tmp_char & (0x01<<31) )
{
LCD_WR_Data(fColor);
}
else
{
LCD_WR_Data(BACKGROUND);
}
tmp_char <<= 1;
}
}
}
}
}
|
|