STM32 display Chinese characters

The following information is collected for the network, found that many are "original", the author can not judge. After understanding their own finishing details Tell me find their own separate source
.

You can also refer to the article: LTDC characters STM32F429 the show _ to develop renderings (including download package)

1: a Chinese character occupied space is 2B

2: the machine code: a character code is actually stored in the computer. Such as Latin characters, in the form of ascii code is stored, and Chinese characters, is based on the district-bit code plus 0xA0, it became characters in the calculation of centralized storage code, which is machine code.

Defined character dot-matrix structure

typedef struct typFNT_GB16                 // 汉字字模数据结构
{
       signed char Index[2];               // 汉字内码索引
       char Msk[32];                       // 点阵码数据
};

Then we need to establish character, in which I am free to create a:

struct typFNT_GB16 code GB_16[] =          // 数据表
{
"饼",  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,
  
"昌", 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,
  
"除", 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,
}

Character structure wherein the elements defined in Index [2] storing characters, and for storing the Msk lattice code.
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;
				    } // end for k
			    } // end for sordByte
				p+=2;
				x += 16;
				if(x > 225)   
				{
				   x = 0;
				   y += 16; 
				 }
			 } 
		}
	}

}
Where tft_set_window (x, y, x + 15, y + 15) is provided to operate the window range, tft_wrdat (wordColor) LCD write data,
then the program displayed characters can be directly written in the main function:

int main()
{ 
	tft_init(); //TFT彩屏初始化 
	LED_Init(); //LED初始化
	tft_clear_screen(BLACK); //清屏
	show_chinese(6,20,"饼昌除",MAGENTA,YELLOW);  //YELLOW
	while(1)
		{ 
		 	led_display(); //LED闪烁
		} 
	}

Error-free code has been verified, you can refer to ideas!
Come on dry ~ ~ ~

Guess you like

Origin blog.csdn.net/zhouml_msn/article/details/90022727