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

Clearing lcd characters

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

Clearing lcd characters
PostPosted: Tue May 06, 2008 2:58 pm     Reply with quote

I have the following line on the LCD program.
Code:
lcd_gotoxy(1,2);
     printf(lcd_putc,"%3.0f", x);

However the value of x goes over 1000 which causes the value of x to be displayed as say 1000 but if x goes back below 1000 the value should be shown as say 980 but it shows the value of 9800. How is it possible to fix this as i have looked all over the net but cant find a solution other than to use a bunch of if statements in the lcd function or to clear the line each time before i write something to it but that causes the lcd to flicker.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue May 06, 2008 3:38 pm     Reply with quote

Remember that you are writing in a RAM like adjacent cells memory.
If you want to write a 4 digit value like 1000, lcd_putc() start writting in the location
pointed by gotoxy(). If you write 980, it start writing in the same location like 1000,
but it only writes 3 digits. The next digit still keep the '0' of the previous 4 digits value,
and it shows you 9800.

Try this:
Code:

     printf(lcd_putc,"\f");
     lcd_gotoxy(1,2);
     printf(lcd_putc,"%3.0f", x);
 


Humberto
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Tue May 06, 2008 4:30 pm     Reply with quote

Thanks Humberto
What i did wrong is in the way i display the characters.
I should have realised that printf(lcd_putc,"%3.0f", x); will work correctly until i reach 1000 then the %3.0f will not work anymore and i should have changed it to %4.0f.

Thanks for the advice
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Tue May 06, 2008 4:56 pm     Reply with quote

I am trying to make the display neater and PCM Programmer refered me to a site which indicates how to do it but ccs complains about a invalid format if i use the - sign such as in the following example. Is there another way to align the numbers to the left?

Code:
printf("Printing 3.141592 using %%9.3f    displays %9.3f\n", x);
printf("Printing 3.141592 using %%-9.3f   displays %-9.3f\n", x);
Printing 3.141592 using %9.3f    displays            3.142
Printing 3.141592 using %-9.3f   displays 3.142
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 06, 2008 5:08 pm     Reply with quote

The program shown below has the following output:
Code:

    1.230
   1.230
  1.230
 1.230
1.230
 


Code:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//====================================
void main()
{
float value;
value = 1.23;
printf("%9.3f \n\r", value);
printf("%8.3f \n\r", value);
printf("%7.3f \n\r", value);
printf("%6.3f \n\r", value);
printf("%5.3f \n\r", value);

while(1);
}
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Tue May 06, 2008 5:27 pm     Reply with quote

That way it still fills the values from the right which shows a value in a format such as:
Code:
  1
 12
100
I need it to display as follows
Code:
1
12
123
Meaning it should start filling at the left side such as the minus sign does on the website you refered me to.
Printing 3.141592 using %-9.3f displays 3.142
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