CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Text on LCD moved from column

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jacktaylor



Joined: 02 Sep 2017
Posts: 75

View user's profile Send private message Send e-mail

Text on LCD moved from column
PostPosted: Mon May 14, 2018 2:55 pm     Reply with quote

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);
}

Rolling Eyes
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 14, 2018 4:32 pm     Reply with quote

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

View user's profile Send private message

Re: Text on LCD moved from column
PostPosted: Mon May 14, 2018 5:34 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue May 15, 2018 9:41 am     Reply with quote

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: 19509

View user's profile Send private message

PostPosted: Tue May 15, 2018 12:54 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon May 21, 2018 3:57 pm     Reply with quote

Thanks Ttelmah for the help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group