STM32 TFT touch screen: process analysis displayed by LCD_ShowChar

Publisher:omicron25Latest update time:2018-10-16 Source: eefocusKeywords:stm32  LCD_ShowChar Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    When using a TFT touch screen and wanting to display strings, graphics or numbers, you will find that there is a most important function LCD_ShowChar in their library functions. It seems that few people have analyzed this function. Although it is simple, it is still a bit confusing.

    Let me post the code of this function first. Since the function display is divided into overlay display and non-overlay display, the principles are similar, so you should understand it just by analyzing the non-overlay part.

void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode)

{    

    u8 temp,t1,t;

u16 y0=y;

u16 colortemp=POINT_COLOR;               

num=num-' '; //Get the offset value

if(!mode) //non-overlapping mode

{

   for(t=0;t

   {   

if(size==12)temp=asc2_1206[num][t]; //Call 1206 font

else temp=asc2_1608[num][t]; //Call 1608 font                    

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

{    

       if(temp&0x80)POINT_COLOR=colortemp;

else POINT_COLOR=BACK_COLOR;

LCD_DrawPoint(x,y);

temp<<=1;

y++;

if(x>=lcddev.width){POINT_COLOR=colortemp;return;}//Out of area

if((y-y0)==size)

{

y=y0;

x++;

if(x>=lcddev.width){POINT_COLOR=colortemp;return;}//Out of area

break;

}

}    

   }    

}

    1206 font and 1608 font are two different font sizes, one is 6 points horizontally and 12 points vertically, and the other is 8 points horizontally and 16 points vertically. From the judgment statement, we can see that the code tables corresponding to the two are different. This code table is a two-dimensional array in font.h. We use 1608 font here, taking the letter "M" as an example. Check the array corresponding to "M" in the code table, as follows:

{0x10,0x04,0x1F,0xFC,0x1F,0x00,0x00,0xFC,0x1F,0x00,0x1F,0xFC,0x10,0x04,0x00,0x00},

    ' ' is the beginning of the code table. The offset is obtained by subtracting ' ' from the letter, which is the row number of the two-dimensional array. At the beginning of the first loop, the temporary variable temp is assigned the first value of the array. Since it is a 1608 font, there are also 16 numbers in an array. The first loop is to let temp traverse these 16 numbers.

    Then the second loop starts. Since each number in the array is 8 bits, and temp is shifted left by one bit each loop, the second loop is 8 times. After judging by if(temp&0x80), if the highest bit of the number is 1, the color of the point to be drawn is the font color. If it is not 1, the color of the point to be drawn is the background color. (PS: The point drawing function LCD_DrawPoint is still very simple. In general, it writes the point color we want to write to the GRAM register R20h, R21h. The basic operation is O(∩_∩)O)

    Each time it shifts, y will increment by itself. The second loop is 8 times, and the size is 16. That is to say, after reading two numbers in the array, y will be cleared after 16 increments, and then x will be incremented by 1, just like a column scan. After a column of 16 points, it will move on to the next column.

    The part beyond the area means that it exceeds the size, and it will return after drawing a point. The following describes the process of drawing points using "M" as an example.

    The first 8

0x10 (0,3)

0x04 (0,13)

0x1F (1,3),(1,4),(1,5),(1,6),(1,7)

0xFC (1,8),(1,9),(1,10),(1,11),(1,12),(1,13)

0x1F (2,3),(2,4),(2,5),(2,6),(2,7)

0x00 None

0x00 None

0xFC (3,8),(3,9),(3,10),(3,11),(3,12),(3,13)

    8 after the meter

0x1F (4,3),(4,4),(4,5),(4,6),(4,7)

0x00 None

0x1F (5,3),(5,4),(5,5),(5,6),(5,7)

0xFC (5,8),(5,9),(5,10),(5,11),(5,12),(5,13)

0x10 (6,3)

0x04 (6,13)

0x00 None

0x00 None

    This is not intuitive. Use Matlab's scatter(x,y) to draw a point, and it is exactly the "M" graphic displayed on the TFT screen.

STM32 TFT touch screen (ILI9320) (1): Process analysis through LCD_ShowChar display
    The above is the whole process of ILI9320 dot plotting function LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode). I hope that those who are learning for the first time can understand it.


Keywords:stm32  LCD_ShowChar Reference address:STM32 TFT touch screen: process analysis displayed by LCD_ShowChar

Previous article:STM32 tick timer (1): The location of the tick timer in the kernel
Next article:STM32 DMA receives data from the serial port

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号