Use stm32 to control the display current and voltage parameters of the LCD screen.
The expected result is as follows:
However, the actual result is as follows.
It can be seen that the current parameter is followed by several more characters "Volta", which is just the first part of the content to be displayed in the next line.
Try to shorten the value of the current parameter. For example, change the value of 20.54 to 2.54. It is normal. The cause of this problem may be related to the length of the string to be displayed. So I looked at the Code related to current display, from definition to calling the LCD module API.
Char current_display [15]; // defines a sprintf (current_display, "current = %. 3fa ", current); // write the current parameter string current_len = strlen (current_display) to current_display; // calculate the length of current_display ili9320_line (160, (u8 *) current_display, current_len, charcolor, bkcolor); // call the LCD api to write the display content to the LCD screen.
Since the problem is related to the length of the string to be displayed, it is also related to the length of current_display defined in the first line. So modify the length (currently 15 ). It is normal that the length is greater than or equal to 16. 16 is the length of "current = 255.540a.
That is to say, if the length of the first defined array is not greater than the actual length of the string to be displayed (current_display), the above problem will occur.
But why?
Check the second line of code. After executing this line of code, the current_display is the actual length of the subsequent string plus 1 (because there is an ending character)
The strlen function in the third row obtains the actual length of the string.
Therefore, when the fourth line calls the API to write the screen, if the length defined by the current_display array is not greater than the actual length of the character to be displayed (current_display), when writing the current_len character, the end character of the string has not yet been met, so we will write the subsequent string. Until the end character is reached or the screen of the line is full.