第一步定义字库
const uint8_t HANZI_TAB16[][16]=
{
{0x00,0x00,0x20,0x13,0x0A,0x02,0x42,0x23,0x0A,0x0A,0x12,0x12,0x24,0x24,0x0B,0x00},
{0x00,0x20,0x20,0xFC,0x24,0x24,0x20,0xF8,0x88,0x88,0x48,0x50,0x20,0xD0,0x0C,0x00},/*"波",0*/
{0x00,0x00,0x27,0x14,0x05,0x45,0x25,0x05,0x15,0x15,0x21,0x22,0x42,0x44,0x08,0x00},
{0x00,0x04,0xC4,0x44,0x54,0x54,0x54,0x54,0x54,0x54,0x14,0x84,0x44,0x44,0x1C,0x00},/*"测",0*/
{0x00,0x01,0x01,0x7F,0x05,0x09,0x11,0x60,0x1F,0x10,0x1F,0x10,0x1F,0x00,0x7F,0x00},
{0x00,0x00,0x00,0xFC,0x40,0x20,0x10,0x0C,0xF0,0x10,0xF0,0x10,0xF0,0x00,0xFC,0x00},/*"查",0*/
{0x00,0x00,0x1F,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x20,0x40,0x00},
{0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"厂",0*/
{0x00,0x01,0x21,0x21,0x21,0x21,0x3F,0x01,0x01,0x41,0x41,0x41,0x41,0x7F,0x00,0x00},
{0x00,0x00,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x04,0x04,0x04,0x04,0xFC,0x04,0x00},/*"出",0*/
{0x00,0x00,0x78,0x48,0x49,0x52,0x55,0x48,0x48,0x4B,0x48,0x72,0x42,0x44,0x41,0x00},
{0x00,0x40,0x40,0xA0,0x10,0x08,0xF4,0x40,0x40,0xF8,0x40,0x48,0x44,0x44,0xC0,0x00},/*"除",0*/
{0x00,0x10,0x10,0x12,0x12,0x7A,0x17,0x12,0x12,0x12,0x12,0x1A,0x62,0x02,0x01,0x00},
{0x00,0x40,0x40,0x48,0x58,0xE8,0x48,0x48,0x48,0x48,0x58,0x40,0x04,0x04,0xFC,0x00},/*"地",0*/
{0x00,0x02,0x02,0x03,0x02,0x02,0x1F,0x10,0x10,0x10,0x1F,0x00,0x24,0x22,0x42,0x00},
.....
};
//第二步字库做成字典
const uint8_t HZ_DIC[]=
{
"波测查厂出除地点动度断分"
"复关合恢记加间降接开看控"
"录路率明期器清热日设湿时"
"手特通温无线信照值址制置"
"自报警结节远程"
};
//第三 实现从字库查找 字符
void GUI_ShowChanese(uint8_t x,uint8_t y,uint8_t Mode,uint16_t GBK,uint8_t Char_Size)
{
uint16_t N=0x00;
uint16_t GBKTmp;
const uint8_t *pDat;
pDat=HZ_DIC;
while(*pDat)
{
GBKTmp=*pDat++;
GBKTmp<<=8;
GBKTmp|=*pDat++;
if(GBKTmp==GBK)break;
N+=2;
}
pDat=&HANZI_TAB16[N][0];
GUI_PutHZ(x,y,(uint8_t *)pDat,8,16);//显示另一半
pDat=&HANZI_TAB16[N+1][0];
GUI_PutHZ(x+8,y,(uint8_t *)pDat,8,16);//显示另一半
}
void GUI_ShowString(uint8_t x,uint8_t y,uint8_t Mode,const uint8_t *str,uint8_t Char_Size)
{
uint16_t GBK;
if(Mode)GUI_SetColor(1,0);
else GUI_SetColor(0,1);
while (*str!='\0')
{
if((*str>=' ')&&(*str<0x80))
{
GUI_ShowChar(x,y,Mode,*str++,Char_Size);//显示字母
if(Char_Size==0x0C)x+=6;
else x+=0x08;
}
if(*str>=0xA0)
{
GBK=*str++;
GBK<<=8;
GBK|=*str++;
GUI_ShowChanese(x,y,Mode,GBK,Char_Size);//显示汉字
x+=Char_Size;
}
#ifdef __SWAP__XY__
if(x>=GUI_LCM_YMAX)x=0,y+=Char_Size;
if(y>=GUI_LCM_XMAX)x=0,y=0;
#else
if(x>=GUI_LCM_XMAX)x=0,y+=Char_Size;
if(y>=GUI_LCM_YMAX)x=0,y=0;
#endif
}
}
最后在你需要的地方调用 void GUI_ShowString(uint8_t x,uint8_t y,uint8_t Mode,const uint8_t *str,uint8_t Char_Size)
就行了 例如
GUI_ShowString(0,8,1,“hi,你好中国",16);
|