STM32 anti-aliasing Chinese display alternative solution sharing

Publisher:书卷气息Latest update time:2017-10-02 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I've been playing with car LCD instrumentation recently. I used Arduino+USART LCD before, but later found that Arduino's performance was not enough, so I turned to STM32. Since I needed to display mobile phone information on the LCD screen, I first used a common dot matrix font solution, but I felt that the effect was terrible, with jagged edges all over the screen. I searched the Internet, but couldn't find a more suitable solution.

It should be noted that the STM32 board I used is very simple: STM32+FSMC+TFT5-inch screen+SDIO. There is no expansion of SDRAM, but there is an advantage that a large-capacity TF card can be used, which is also the main factor that makes this solution feasible. After a lot of verbose, here is the picture:

 

the font looks very comfortable, without ugly jagged edges.
The solution is actually quite rustic:
1. Write a font extraction tool on the PC. Unlike other tools, the font extracted by this tool contains anti-aliasing information (actually grayscale information). Each pixel requires 1 byte to store. A 32*32 dot matrix font requires 1024 bytes. Assuming there are 30,000 fonts, it will take up about 30M of space. But I use a TF card, and the font information is almost negligible for the capacity of the TF card!
2. The implementation on the STM32 is even simpler. Just read the font information on the TF card, perform simple calculations with the color to be displayed, and then output it directly to the TFT.

Attached is the code for displaying dot matrix Chinese characters:
//*************** Display dot matrix Chinese characters***********
int display_hz_char(int x,int y,u16 chr){
SD_Error Status = SD_OK;
int i,x1,y1;
BYTE buff[SECTOR_SIZE*2];
u32 sec_start=hz_sec_base+(0x33ff-0x2000+1+chr-0x4e00)*hz_sector_count; //Chinese character starting sectorif
((chr>=0x2000)&&(chr<=0x33ff)){
        sec_start=hz_sec_base+(chr-0x2000)*hz_sector_count;
}
        
if((chr>=0xff00)&&(chr<=0xffef)){ //Full-width characters
        sec_start=hz_sec_base+(0x33ff-0x2000+1+0x9fbf-0x4e00+1+chr-0xff00)*hz_sector_count;
}

Status = SD_ReadMultiBlocksEx(sec_start * SECTOR_SIZE, (uint32_t*)(&buff[0]), SECTOR_SIZE, 2,true); //Read TF card sector data
if (Status != SD_OK){
        in_dma_reading=false;
        return x;
}
while (DMA_GetFlagStatus(DMA2_FLAG_TC4) == RESET){}; //Wait for DMA read operation to complete
        
i=0;        
Lcd_BlockWrite(x,x+dot_font_size-1,y,y+dot_font_size-1); //TFT block write
for(y1=0;y1        for(x1=0;x1                if(buff>0){ //background color, display with specified color
                                *(__IO u16 *) (Bank1_LCD_D) = calc_alpha(dot_font_text_color,dot_font_bkg_color,buff);
                }
                else{ //background color, display with specified background color
                                *(__IO u16 *) (Bank1_LCD_D) = font_bg_565;
                }
                i++;
                if(i>=SECTOR_SIZE*2){ //A 32-dot font needs to occupy 2 sectors (1024 bytes)        
                        i=0;
                }
        }
}
        return x+dot_font_size;
}
Finally, attach a screenshot of the PC-side font making tool:


Keywords:STM32 Reference address:STM32 anti-aliasing Chinese display alternative solution sharing

Previous article:STM32F103X general-purpose timer 2~5 input capture edge selection
Next article:STM32 USART serial port DMA receive and send mode

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号