About the font design of single chip microcomputer
[Copy link]
When LCD display is needed, the display of Chinese characters has not been so convenient (without a *font library).
If you are just taking a model, you have to consider the time and flash resources required to make a font library. For UCOS, just like the broken development board used by the OP, there is only 256K flash, and a 16*16 GB dot matrix font library will take up 200K+, so it is naturally impossible to put user source code in it. So
, the OP started to use the * font library. Here are some of the problems encountered with the * font library. If it is useful, please give the OP a thumbs up, hahahaha
1. For GB2312, you can search on Baidu.
2. Fonts are usually made of flash devices and use SPI protocol for communication. Usually, a 4-megabyte chip is enough to store commonly used fonts.
3. Self-made fonts. Finally, the resources used by the OP will be posted. Detailed process (add some formatting to make it easier to read, hahaha):
The first step, of course, requires you to write the initialization and read and write functions of the SPIflasn you are using (I use W25X16, 2M, the maximum transmission rate is 74MHZ, very fast; write function: void W25X_Write_Bytes(uint32_t addr,u8* pBuffer, u16 nBytes) Note: When writing W25X16, you need to erase it first. Read function: void W25X_Read_Bytes(uint32_t addr, u8* pBuffer, u16 nBytes)
The second step is to write the serial port transmission function, using the serial port interrupt method, the baud rate is set to 115200 (no problem with the test), and write a byte of external input immediately after receiving it. The speed is doubled compared to the previous method of using two characters to represent one byte.
Code:
view plaincopy to clipboardprint?
u8 result;
u32 pAddr=0;
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)
{
result = USART_ReceiveData(USART1);
W25X_Write_Bytes(pAddr++,&result,1);
USART_ClearITPendingBit( USART1, USART_IT_RXNE); // Clear serial port acceptance interrupt
}
}
The third step is to set a button to perform the erase operation, and interact through the serial port or LCD to prompt whether the erase is completed. You can write to FLASH.
Step 4: Make a Chinese character library. The GB3212 library contains 6768 simplified Chinese characters. First, open the "Get Dot Matrix.exe" software, and then open the "Character Library.txt" file in the software. Then select the modulus method, and you can set the font style, size, and direction settings. Pay attention to the "Direction Settings" option. Here, in order to correspond to the display program in the project, select - horizontal modulus, high position sitting. For other options, just modify the display program appropriately. Then click the "Output" button to get the character array file (temp.txt) in the directory.
Step 5: Arrange the font file. The font array file obtained in the previous step cannot be used directly. It needs to be arranged to be suitable for serial port transmission. Remove various comment symbols and punctuation characters, and only keep the hexadecimal format consisting of two characters. Then rename "temp.txt" to "HzLib.txt", and then run "Arrange Font Library.exe". At this time, you will get the arranged font library "OutHzLib.txt" and then you can directly send the font library to the MCU through the serial port.
Step 6, send data via the serial port. It is recommended to use the serial port debugging software in the attachment, because some software seems to have some problems with the file sending function. I have also tested two serial port debugging software, and both cannot get results. If there are other good ones, it is also OK, as long as the purpose is achieved. Set the serial port parameters, then check "Send in hexadecimal" in the sending area settings, click the "Start file data source" option, select the prepared font "OutHzLib.txt", and do not click "File Load".
Step 7, open the serial port, connect the board to the power supply, first erase the Flash, and when the erase is complete, click the serial port to send, and then slowly wait for the font to be written into the FLASH. The test was conducted at a baud rate of 115200, with a modulus size of 16*16, and it took 70 seconds, which does not seem to be too long. If the modulus is larger, it will take longer. After writing the font, you can call the font in the project to display Chinese (see the project for the operation of taking the GBK internal code). In addition, if the flash capacity is large enough, you can also write fonts of other font styles and sizes to make a dedicated font chip.
4.Xbao is a piece of paper, economical and affordable, and can be used anytime. After the font library is ready, the only thing left is how to use it.
In addition,
1. It is recommended to use bus-type SPI, the speed is absolutely guaranteed. The specific code depends on the respective board.
2. If using software SPI, send a paragraph:
view plaincopy to clipboardprint?
#define MOSI_H GPIO_SetBits(GPIOA, GPIO_Pin_5)
#define MOSI_L GPIO_ResetBits(GPIOA, GPIO_Pin_5)
#define SCLK_H GPIO_SetBits(GPIOA, GPIO_Pin_7)
#define SCLK_L GPIO_ResetBits(GPIOA, GPIO_Pin_7)
#define MISO_ H GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0)
void spi_init(void)
{
CE_25_1; MOSI_H; MISO_H; SCLK_H;
}
unsigned char SPI_SendByte(unsigned char dt)
{ u8 i; u8 temp=0;
for(i=8;i>0;i--)
{
if(dt&0x80)MOSI_H;
else MOSI_L; SCLK_L; SCLK_H; temp<<=1; dt<<=1;
if(MISO_H) temp++;
}
return temp;
}
|