先使用PCtoLCD2002软件生成字模,设置如下:
将数据存放以下格式:
typedef struct
{
unsigned char Index[2];
char Msk[32];
}typFNT_GB162;
const typFNT_GB162 hz16[] = {
"针",0x00,0x00,0x00,0x00,0x04,0x30,0x08,0x20,0x0F,0x20,0x10,0x20,0x16,0x2E,0x29,0xF0,
0x4A,0x20,0x1C,0x20,0x08,0x20,0x0A,0x20,0x0C,0x20,0x08,0x20,0x00,0x20,0x00,0x00,/*"针",0*/
"灸",0x00,0x00,0x01,0x00,0x01,0x40,0x02,0xC0,0x04,0x80,0x01,0x00,0x02,0xF0,0x0D,0x08,
0x01,0x30,0x11,0x40,0x0A,0x80,0x02,0x40,0x04,0x20,0x08,0x30,0x30,0x1E,0x00,0x00,/*"灸",1*/
};
typedef struct
{
unsigned char Index[2];
char Msk[72];
}typFNT_GB242;
const typFNT_GB242 hz24[] =
{
"针",0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x81,0x80,0x01,0x01,0x80,0x03,
0x00,0x80,0x02,0x60,0x80,0x07,0x80,0x80,0x04,0x00,0x80,0x08,0x40,0x9C,0x0F,0x83,
0xF8,0x11,0x1C,0x80,0x21,0x00,0x80,0x41,0xC0,0x80,0x1F,0x00,0x80,0x01,0x00,0x80,
0x01,0x20,0x80,0x01,0xC0,0x80,0x03,0x80,0x80,0x03,0x00,0x80,0x00,0x00,0x80,0x00,
0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x00,/*"针",0*/
"灸",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x32,0x00,0x00,0x7F,0x00,0x00,
0x46,0x00,0x00,0x8C,0x00,0x01,0x08,0x00,0x00,0x3C,0x00,0x00,0x63,0xC0,0x00,0xC0,
0xE0,0x03,0x30,0x20,0x04,0x21,0x80,0x00,0x21,0xC0,0x06,0x36,0x00,0x02,0x68,0x00,
0x00,0x64,0x00,0x00,0x46,0x00,0x00,0x83,0x00,0x01,0x81,0x80,0x06,0x00,0xE0,0x18,
0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,/*"灸",1*/
};
typedef struct
{
unsigned char Index[2];
char Msk[128];
}typFNT_GB322;
const typFNT_GB322 hz32[] =
{
"针",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x08,0x00,
0x00,0x70,0x0E,0x00,0x00,0x60,0x0E,0x00,0x00,0x60,0x06,0x00,0x00,0xC0,0x06,0x00,
0x00,0xCE,0x06,0x00,0x01,0xFC,0x06,0x00,0x01,0x80,0x06,0x00,0x03,0x00,0x06,0x00,
0x02,0x00,0x06,0x3C,0x06,0x78,0x07,0xFC,0x07,0xC0,0xFE,0x00,0x08,0x61,0xC6,0x00,
0x10,0x60,0x06,0x00,0x20,0x7C,0x06,0x00,0x40,0xF0,0x06,0x00,0x07,0xE0,0x06,0x00,
0x00,0x60,0x06,0x00,0x00,0x62,0x06,0x00,0x00,0x64,0x06,0x00,0x00,0x78,0x06,0x00,
0x00,0x70,0x06,0x00,0x00,0xE0,0x04,0x00,0x00,0xC0,0x04,0x00,0x00,0x00,0x04,0x00,
0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,/*"针",0*/
"灸",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
0x00,0x07,0x00,0x00,0x00,0x06,0x78,0x00,0x00,0x0D,0xB8,0x00,0x00,0x18,0x70,0x00,
0x00,0x10,0x60,0x00,0x00,0x20,0xC0,0x00,0x00,0x41,0x80,0x00,0x00,0x03,0xF0,0x00,
0x00,0x0E,0x3F,0x00,0x00,0x18,0x07,0x80,0x00,0x76,0x01,0x80,0x01,0xC6,0x00,0x00,
0x02,0x06,0x06,0x00,0x00,0x06,0x0F,0x00,0x02,0x06,0x18,0x00,0x03,0x87,0x60,0x00,
0x01,0xC6,0x80,0x00,0x00,0xCC,0xC0,0x00,0x00,0x0C,0x60,0x00,0x00,0x18,0x30,0x00,
0x00,0x18,0x18,0x00,0x00,0x30,0x0C,0x00,0x00,0xE0,0x0F,0x00,0x01,0x80,0x07,0xC0,
0x06,0x00,0x03,0xF0,0x08,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"灸",1*/
}
函数修改格式:(标红的位置是根据字号不一样要修改的)
void Fast_DrawFont_HZ32(uint8_t x, uint8_t y, uint16_t fc, uint16_t bc, uint8_t *s)
{
unsigned char i,j;
unsigned short k;
uint16_t HZnum;
HZnum=sizeof(hz32)/sizeof(typFNT_GB322);
while(*s)
{
if((*s) >= 128)
{
for (k=0;k
if ((hz32[k].Index[0]==*(s))&&(hz32[k].Index[1]==*(s+1)))
{ Lcd_SetRegion(x,y,x+32-1,y+32-1);
for(i=0;i<128;i++)
{
for(j=0;j<8;j++)
{
if(hz32[k].Msk[i]&(0x80>>j)) LCD_WriteData_16Bit(fc);
else
{
if (fc!=bc) LCD_WriteData_16Bit(bc);
}
}
}
}
}
s+=2;x+=32;
}
}
}
/*
**************************************************************************
* 函 数 名:
* 功能说明:显示汉字 16*16
* 形 参:无
* 返 回 值:无
**************************************************************************
*/
void Fast_DrawFont_HZ16(uint8_t x, uint8_t y, uint16_t fc, uint16_t bc, uint8_t *s)
{
unsigned char i,j;
unsigned short k;
uint16_t HZnum;
HZnum=sizeof(hz16)/sizeof(typFNT_GB162);
while(*s)
{
if((*s) >= 128)
{
for (k=0;k>j)) LCD_WriteData_16Bit(fc);
else
{
if (fc!=bc) LCD_WriteData_16Bit(bc);
}
}
}
}
}
s+=2;x+=16;
}
}
}
/*
**************************************************************************
* 函 数 名:
* 功能说明:显示汉字 24*24
* 形 参:无
* 返 回 值:无
**************************************************************************
*/
void Gui_DrawFont_HZ24(u16 x, u16 y, u16 fc, u16 bc, u8 *s)
{
unsigned char i,j;
unsigned short k;
uint16_t HZnum;
HZnum=sizeof(hz24)/sizeof(typFNT_GB242);
while(*s)
{
if((*s) >= 128)
{
for (k=0;k>j)) LCD_WriteData_16Bit(fc);
else
{
if (fc!=bc) LCD_WriteData_16Bit(bc);
}
}
}
}
}
s+=2;x+=24;
}
}
}
/*
**************************************************************************
* 函 数 名:
* 功能说明:显示汉字 32*32
* 形 参:无
* 返 回 值:无
**************************************************************************
*/
void Fast_DrawFont_HZ32(uint8_t x, uint8_t y, uint16_t fc, uint16_t bc, uint8_t *s)
{
unsigned char i,j;
unsigned short k;
uint16_t HZnum;
HZnum=sizeof(hz32)/sizeof(typFNT_GB322);
while(*s)
{
if((*s) >= 128)
{
for (k=0;k>j)) LCD_WriteData_16Bit(fc);
else
{
if (fc!=bc) LCD_WriteData_16Bit(bc);
}
}
}
}
}
s+=2;x+=32;
}
}
}
//向液晶屏写一个16位数据
void LCD_WriteData_16Bit(u16 Data)
{
LCD_RS_SET;
SPI_WriteData(Data>>8); //写入高8位数据
SPI_WriteData(Data); //写入低8位数据
}
/*************************************************
函数名:LCD_Set_Region
功能:设置lcd显示区域,在此区域写点数据自动换行
入口参数:xy起点和终点
返回值:无
*************************************************/
void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end)
{
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(x_start+1);
Lcd_WriteData(0x00);
Lcd_WriteData(x_end+1);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(y_start+0x1A);
Lcd_WriteData(0x00);
Lcd_WriteData(y_end+0x1A);
Lcd_WriteIndex(0x2c);
}
//向液晶屏写一个8位指令
void Lcd_WriteIndex(u8 Index)
{
//SPI 写命令时序开始
LCD_RS_CLR;
SPI_WriteData(Index);
}
//向液晶屏写一个8位数据
void Lcd_WriteData(u8 Data)
{
LCD_RS_SET;
SPI_WriteData(Data);
}