STM32F4_LCD显示汉字

        LCD显示汉字和显示图片、数字、字符的原理是一样的,都是将汉字、图片、数字以及字符转换点阵,进而通过函数扫描点阵在LCD上显示;正点提供汉字取字模软件 PCtoLCD2002完美版

具体步骤:

        1. 打开取字模软件,设置字模选项;设置完成后点击确认

STM32F4_LCD显示汉字_第1张图片

STM32F4_LCD显示汉字_第2张图片

        2. 输入汉字,生成字模,然后将生成的字模赋值到 MDK5 中,当然也可以创建一个 .h 文件,主要看个人习惯;

STM32F4_LCD显示汉字_第3张图片

        3. 最重要的是在 LCD.c 文件中写 LCD_ShowChinese 函数,实现在 LCD 上显示汉字的功能;

//参数
//x y 起点坐标
//num 要显示的汉字对应于字库中的数值
//size 要显示的汉字的大小
//mode 对应模式

void LCD_ShowChinese(u8 x,u8 y,u8 num,u8 size,u8 mode)
{
    u8 temp,t,t1;
    u8 y0=y;
    u8 csize=(size/8 + ((size%8)?1:0)) * size;  //16/8+1
    for(t=0;t
const unsigned char chinese[30][36]={
    {0x01,0x00,0x01,0x00,0x77,0xFE,0x11,0x24,0x11,0x24,0x11,0x24,0x17,0xFE,0xF1,0x00,
     0x10,0x81,0x11,0x02,0x1E,0x0C,0x12,0xF0,0x72,0x0C,0x02,0x82,0x03,0x01,0x00,0x00},/*"嵌",0*/

    {0x00,0x01,0x00,0x02,0x00,0x04,0x00,0x08,0x00,0x30,0x80,0xC0,0x47,0x00,0x38,0x00,
     0x07,0x00,0x00,0xC0,0x00,0x30,0x00,0x0C,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x00},/*"入",1*/

    {0x08,0x00,0x08,0x04,0x09,0x06,0x09,0x04,0x09,0xFC,0x09,0x08,0x09,0x08,0x08,0x08,
     0x08,0x00,0xFF,0xC0,0x08,0x30,0x08,0x08,0x88,0x04,0x68,0x02,0x08,0x1F,0x00,0x00},/*"式",2*/
    
    {0x1F,0xC4,0x10,0x86,0xFF,0xFC,0x10,0x88,0x1F,0x9C,0x00,0x00,0x18,0x02,0x50,0x12,
     0x37,0x92,0x14,0x92,0xF4,0xFE,0x14,0x92,0x37,0x92,0x50,0x12,0x18,0x02,0x00,0x00},/*"螳",3*/
    
    {0x1F,0xC4,0x10,0x86,0xFF,0xFC,0x10,0x88,0x1F,0x9C,0x00,0x00,0x3F,0xFE,0xA4,0x84,
     0x64,0xA8,0x3F,0x9C,0x00,0x00,0x7F,0xFF,0x42,0x10,0x4D,0x08,0x70,0xF0,0x00,0x00},/*"螂",4*/
    
    {0x08,0x20,0x08,0x22,0x08,0x41,0xFF,0xFE,0x08,0x80,0x29,0x00,0x27,0xFF,0x24,0x90,
     0x24,0x90,0xFF,0xFE,0x24,0x90,0x24,0x92,0xA4,0x91,0x67,0xFE,0x20,0x00,0x00,0x00},/*"捕",5*/
    
    {0x00,0x04,0x1F,0xC6,0x10,0x84,0xFF,0xF8,0x10,0x88,0x1F,0x9C,0x00,0x00,0x9F,0xC8,
     0x52,0x48,0x32,0x48,0x1F,0xFF,0x32,0x48,0x52,0x48,0x9F,0xC8,0x00,0x08,0x00,0x00},/*"蝉",6*/
    
    {0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",7*/
    
    {0x00,0x00,0x00,0x00,0x79,0x1E,0x09,0x11,0x09,0x11,0x09,0x11,0x09,0x11,0xF9,0x11,
     0x09,0x11,0x09,0x11,0x09,0x11,0x09,0xF1,0x78,0x01,0x00,0x07,0x00,0x00,0x00,0x00},/*"岂",8*/
    
    {0x04,0x81,0x18,0x82,0xF0,0x8C,0x10,0xB0,0x1F,0xC0,0x10,0xB0,0x10,0x8E,0x00,0x80,
     0x00,0x00,0x3F,0xFC,0x20,0x08,0x20,0x08,0x20,0x08,0x3F,0xFC,0x00,0x00,0x00,0x00},/*"知",9*/
    
    {0x08,0x00,0x08,0x00,0x48,0x00,0x4B,0xF9,0x4A,0x4A,0xFA,0x4C,0x4A,0x48,0x4F,0xF8,
     0x4A,0x48,0xFA,0x4C,0x4A,0x4A,0x4B,0xF9,0x48,0x00,0x08,0x00,0x08,0x00,0x00,0x00},/*"黄",10*/
    
    {0x00,0x80,0x08,0x80,0x11,0x00,0x61,0xFF,0x02,0xAA,0x02,0xAA,0x04,0xAA,0xF4,0xAA,
     0x0A,0xFE,0x09,0xAA,0x10,0xAA,0x40,0xAA,0x20,0xAA,0x10,0x82,0x00,0x00,0x00,0x00},/*"雀",11*/
    
    {0x10,0x40,0x10,0x80,0x11,0x00,0x13,0xFF,0x1C,0x02,0x30,0x82,0xD0,0x82,0x10,0x82,
     0x10,0x82,0x17,0xFE,0x10,0x82,0x10,0x82,0x10,0x82,0x10,0x82,0x10,0x02,0x00,0x00},/*"在",12*/
    
    {0x00,0x02,0x00,0x04,0x00,0x18,0x3F,0xE0,0x24,0x00,0x24,0x7F,0x24,0x42,0x24,0x42,
     0x44,0x42,0x44,0x42,0x44,0x42,0xC4,0x42,0x44,0x7F,0x04,0x00,0x04,0x00,0x00,0x00},/*"后",13*/
    
    {0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xCC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",14*/
};

        4. 编写相应的主函数

int main(void)
{ 
    
	u8 lcd_id[12];				//存放LCD ID字符串
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
	delay_init(168);      //初始化延时函数
	uart_init(115200);		//初始化串口波特率为115200
	
    LED_Init();
 	LCD_Init();           //初始化LCD FSMC接口
	POINT_COLOR=BLACK;      //画笔颜色:红色
	sprintf((char*)lcd_id,"LCD ID:%04X",lcddev.id);//将LCD ID打印到lcd_id数组。
        
    LCD_Clear(WHITE);
 
    //size=16
    LCD_ShowChinese(50,100,3,16,0);                 //螳
    LCD_ShowChinese(50+16,100,4,16,0);              //螂
    LCD_ShowChinese(50+2*16,100,5,16,0);            //捕
    LCD_ShowChinese(50+3*16,100,6,16,0);            //蝉
    LCD_ShowChinese(50+4*16,100,7,16,0);            //,
    LCD_ShowChinese(50+5*16,100,8,16,0);            //岂
    LCD_ShowChinese(50+6*16,100,9,16,0);            //知
    LCD_ShowChinese(50+7*16,100,10,16,0);           //黄
    LCD_ShowChinese(50+8*16,100,11,16,0);           //雀
    LCD_ShowChinese(50+9*16,100,12,16,0);           //在
    LCD_ShowChinese(50+10*16,100,13,16,0);          //后
    LCD_ShowChinese(50+11*16,100,14,16,0);          //!
    
    while(1)
    {
        LED0=!LED0;
        delay_ms(500);
    }
}

        5. 实验现象

 

你可能感兴趣的:(STM32,stm32,单片机,嵌入式硬件)