LCD displays a small number of Chinese characters in STM32

Publisher:TranquilMind88Latest update time:2018-08-17 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

How to display Chinese characters (only Chinese characters) on the LCD display in STM32? The following is my little opinion on this issue. If you have any questions, I hope readers will leave a message;


The following program mainly operates on the library functions in STM32:


To display Chinese characters on LCD, you first need to modulate the Chinese characters. We all know that the space occupied by a Chinese character is 2B. Next, use the modulo software to modulo the Chinese characters to be displayed (note that some modulo software may have problems).


Here we need to add a piece of knowledge, which is the storage form of Chinese characters in computers:


 Input code: Chinese characters are numerous and complex in shape. There are 6,000 to 7,000 commonly used Chinese characters, which is much more than the 26 letters of the English alphabet. When using Chinese characters in a computer system, the first problem encountered is how to input Chinese characters into the computer. In order to be able to use the Western standard

For keyboard input, a corresponding encoding method must be designed for Chinese characters. Chinese character encoding methods are mainly divided into three categories: digital encoding, phonetic encoding and glyph encoding. 

Internal code: The actual storage code of characters in the computer. For example, Western characters are stored in the computer in the form of ASCII code, while our Chinese characters are stored in the computer by adding A0H (hexadecimal) to the area code, which becomes the storage code of Chinese characters in the computer set, that is, the internal code. Chinese character dot matrix code is a code that uses black and white dot matrix to represent the shape of Chinese characters.

Define Chinese character dot matrix structure

typedef struct typFNT_GB16 // Chinese font data structure

{

       signed char Index[2]; // Chinese character internal code index

       char Msk[32]; // dot matrix code data

};


Next, create the font library you need. Here I create one at random:


struct typFNT_GB16 code GB_16[] = // data table

{

"Pie", 0x20,0x00,0x21,0x08,0x20,0x90,0x3C,0x00,

      0x47,0xFC,0x48,0x90,0xA0,0x90,0x20,0x94,

      0x27,0xFE,0x20,0x90,0x20,0x90,0x24,0x90,

      0x28,0x90,0x31,0x10,0x22,0x10,0x04,0x10,



"Chang", 0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,

      0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x08,

      0x3F,0xFC,0x20,0x08,0x20,0x08,0x3F,0xF8,

      0x20,0x08,0x20,0x08,0x3F,0xF8,0x20,0x08,



"Division", 0x00,0x40,0x78,0x40,0x48,0xA0,0x50,0xA0,

      0x51,0x10,0x62,0x0E,0x55,0xF4,0x48,0x40,

      0x48,0x50,0x4F,0xFC,0x68,0x40,0x51,0x50,

      0x42,0x4C,0x44,0x44,0x41,0x40,0x40,0x80,

}


In the defined Chinese character structure element, Index[2] stores Chinese characters, and Msk is used to store dot matrix codes.


The specific procedures are as follows:


void show_chinese(uint16_t x, uint16_t y, uint8_t *p, 

                     uint16_t wordColor, uint16_t backColor)

{

uint8_t i, wordByte ;

uint16_t color,wordNum;



u8 k=0;


while(*p != '\0')

{




for(wordNum=0;wordNum<3;wordNum++)

{

if(*p==chinese[wordNum].Index[0] && *(p+1)==chinese[wordNum].Index[1])

tft_set_window(x, y, x+15, y+15);  

for(wordByte = 0;wordByte < 32; wordByte++)

{

uint8_t color = chinese[wordNum].Msk[wordByte];

for ( k = 0;k<8; k++) 

{

if ((color&0x80) == 0x80)

{

tft_wrdat(wordColor);

else

{

tft_wrdat(backColor);


color = color<<1;

}

 

}

p+=2;

x += 16;

if(x > 225)   

{

x = 0;

and += 16; 

}

 

}






}


}


Among them, tft_set_window(x, y, x+15, y+15) sets the window range to be operated, and tft_wrdat(wordColor) LCD writes data.


Then you can directly write the Chinese character display program in the main function:


int main()

tft_init(); //TFT color screen initialization 

LED_Init(); //LED initialization

tft_clear_screen(BLACK); //清屏

show_chinese(6,20,"饼昌除",MAGENTA,YELLOW);  //YELLOW

while(1)

led_display(); //LED flashes


}


You should all be very clear about the specific initialization of LED and TFT, so I won’t go into details here.


Keywords:STM32 Reference address:LCD displays a small number of Chinese characters in STM32

Previous article:Three common mistakes when using KEIL5 for STM32 development
Next article:keil MDK5 builds STM32 development environment

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号