View previous topic :: View next topic |
Author |
Message |
jacktaylor
Joined: 02 Sep 2017 Posts: 75
|
Text on LCD moved from column |
Posted: Mon May 14, 2018 2:55 pm |
|
|
Hello friends.
I have this simple prototype function in my program. I do not know why the value of the entire 8-bit pulse variable is being printed on LCD column 12. The same is true of the variable VAL that does not appear on the LCD, since it is outside the 16-column LCD field. The variable temperature is printed in the correct position, ie in column 6 of the LCD. Can anyone help with this problem?
Code: |
void readtemp()
{
temperature = ds1820_read();
lcd_gotoxy(1,1);
printf(lcd_putc,"PWM:%.0u",pulse);
lcd_gotoxy(1,2); //lcd_gotoxy para coluna, linha
printf(lcd_putc,"TMP:%.0f VAL:%.0u",temperature,value);
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon May 14, 2018 4:32 pm |
|
|
hmm... what LCD module and which LCD driver ? kinda important as not all LCD modules use the same firmware to access them. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Text on LCD moved from column |
Posted: Mon May 14, 2018 5:34 pm |
|
|
jacktaylor wrote: | I do not know why the value of the entire 8-bit pulse variable is being printed on LCD column 12. The same is true of the variable VAL that does not appear on the LCD, since it is outside the 16-column LCD field.
printf(lcd_putc,"TMP:%.0f VAL:%.0u",temperature,value);
|
I assume you want .0 in front of the 'value'.
Try doing the printf like this:
Code: |
printf(lcd_putc,"TMP:%.0f VAL: .0%u", temperature, value);
|
Then it won't print it in column 18. It should print in column 13. |
|
|
jacktaylor
Joined: 02 Sep 2017 Posts: 75
|
|
Posted: Tue May 15, 2018 9:41 am |
|
|
Thank you PCM Programmer. The text has now been printed at the desired LCD position.
Actually what I really wanted was to have no decimal places after the value of the LCD variable.
When I use it printf(lcd_putc,"TMP:%f VAL:%u",temperature,value); 85.00 is printed for the TEMP: variable on the 16x2 LCD. and VAL: is set to 12.
When I use it printf(lcd_putc,"TMP:%.0f VAL:%u",temperature,value); 85 is printed for the TEMP: variable on the 16x2 LCD. and VAL: is set to 128.
ie the second case is what I need for my program. It's strange because I believe when using printf (lcd_putc, "TMP:% f VAL:% u", temperature, value); TMP could not be printed to 2 decimal places.
value represents the PWM sitting in the program as a function of temperature. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Tue May 15, 2018 12:54 pm |
|
|
If you don't want any decimals, print it as an integer:
printf(lcd_putc,"TMP:%ld VAL:%u",(signed int16)temperature,value);
Why would you think a float would default to not printing decimals?....
Converting to an int and printing as this will result in slightly smaller and faster code. |
|
|
jacktaylor
Joined: 02 Sep 2017 Posts: 75
|
|
Posted: Mon May 21, 2018 3:57 pm |
|
|
Thanks Ttelmah for the help. |
|
|
|