An error occurred while displaying strings on the stm32 LCD.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.