• AVR Freaks

Hot!Data overwrite on other lines - 20 x 4 dot matrix liquid crystal LCD

Author
g.ravi
Senior Member
  • Total Posts : 170
  • Reward points : 0
  • Joined: 2005/12/19 02:14:26
  • Location: India
  • Status: offline
2019/12/06 01:50:18 (permalink)
0

Data overwrite on other lines - 20 x 4 dot matrix liquid crystal LCD

Hi,
 
I'm trying to through data on 20 x 4 LCD (JHD204A). Used sprintf function and a global buffer but data is over written to other lines followed by line address.
 
static unsigned char LCD_LineBuf[C_LCD]; // Global Variable, C_LCD Macro defined with 21

XLCDCommand(0x80); // Line 1 Home address
sprintf(LCD_LineBuf, " IR: %4.2f M\xf4 ", Result_insul); // \xf4 to print Ohms symbol
XLCDPutRamString(LCD_LineBuf);

 
Some times when I try to display 10 character data and if there is any data between 11 to 20 th characters then this data is also displayed with out clearing this. I think sprintf function will take care of all these left over data and to display data with in the specified buffer length.
 
Thankyou,
Ravi.
#1

1 Reply Related Threads

    LdB_ECM
    Super Member
    • Total Posts : 436
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: Data overwrite on other lines - 20 x 4 dot matrix liquid crystal LCD 2019/12/06 03:08:55 (permalink)
    0
    sprintf does no such thing it simply puts a #0 after the end of the last character it created in the buffer to make an asciiz string. So if you had rubbish already up on the screen it obviously stays visible.
     
    You need to right pad the string with spaces to the screen width or clear the screen before writing.
     
    A hint is sprintf returns how many characters it put in the buffer
    https://www.tutorialspoin...c_function_sprintf.htm
     

    Return Value

    If successful, the total number of characters written is returned excluding the null-character appended at the end of the string, otherwise a negative number is returned in case of failure.
    post edited by LdB_ECM - 2019/12/06 03:10:01
    #2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5