单片机中不带字库LCD液晶屏如何显示少量汉字,一般显示汉字的方法有1.使用带字库的LCD屏,2.通过SD
卡或者外挂spi flash存中文字库,3.直接将需要的汉字取模存入mcu的flash中。
第一种方式最方便,带字库的液晶屏价格稍贵,第二种方式电路复杂价格也不便宜,第三种方法可以存储少
量必要的汉字,经济实用。将汉字字模数据存储到大数组中,通过偏移值来取出需要的汉字显示。
typedef struct _GB16 // 汉字字模数据结构 { char Index[2]; // 汉字内码索引 char Msk[32]; // 点阵码数据 }GB16_Typedef; const GB16_Typedef GB16x16[] = {//创建字库,阴码,顺向,逐行式取模 {"天",0x00,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00, 0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00, 0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40, 0x08,0x20,0x10,0x10,0x20,0x08,0xC0,0x06}, {"地",0x10,0x20,0x10,0x20,0x10,0x20,0x11,0x20, 0x11,0x2C,0xFD,0x34,0x11,0x64,0x13,0xA4, 0x11,0x24,0x11,0x34,0x11,0x28,0x1D,0x22, 0xE1,0x22,0x41,0x02,0x00,0xFE,0x00,0x00}, {"不",0x00,0x00,0x7F,0xFC,0x00,0x80,0x00,0x80, 0x01,0x00,0x01,0x00,0x03,0x40,0x05,0x20, 0x09,0x10,0x11,0x08,0x21,0x04,0x41,0x04, 0x81,0x00,0x01,0x00,0x01,0x00,0x01,0x00}, {"仁",0x08,0x00,0x08,0x00,0x08,0x00,0x13,0xFC, 0x10,0x00,0x30,0x00,0x30,0x00,0x50,0x00, 0x90,0x00,0x10,0x00,0x10,0x00,0x10,0x00, 0x17,0xFE,0x10,0x00,0x10,0x00,0x10,0x00}, } /* 其中定义的汉字结构体元素中Index[2]存放汉字,而Msk用于存放点阵码。 具体程序如下: */ void show_chinese(uint16_t x, uint16_t y, uint8_t *pstr, uint16_t pointColor, uint16_t backColor) { uint8_t bit_cnt, byte_cnt, wordNum; uint16_t color, word_index; const GB16_Typedef* p_tab; p_tab = GB16x16; wordNum = sizeof(GB24x24) / sizeof(GB24_Typedef);//汉字的个数 while(*pstr != '