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.
Previous article:Three common mistakes when using KEIL5 for STM32 development
Next article:keil MDK5 builds STM32 development environment
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Uncover the mystery of MOS tube damage! What other reasons do you know?
- Let's discuss whether GaN materials are a key technology in 5G applications.
- FPGA Basics (I)
- Sensortile.box
- [GD32E231 DIY Contest]——02. New project engineering and engineering configuration
- Please help me solve the following two pictures, mirror current source problem. Thank you very much
- TI's 10/15-cell Li-ion and Phosphate battery solutions
- UV Sterilization Box TI Solution
- 【TI recommended course】#TI millimeter wave radar technology introduction#
- The new version of the Download Center is officially launched!