View previous topic :: View next topic |
Author |
Message |
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
Clearing lcd characters |
Posted: Tue May 06, 2008 2:58 pm |
|
|
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
|
|
Posted: Tue May 06, 2008 3:38 pm |
|
|
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
|
|
Posted: Tue May 06, 2008 4:30 pm |
|
|
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
|
|
Posted: Tue May 06, 2008 4:56 pm |
|
|
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
|
|
Posted: Tue May 06, 2008 5:08 pm |
|
|
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
|
|
Posted: Tue May 06, 2008 5:27 pm |
|
|
That way it still fills the values from the right which shows a value in a format such as:
I need it to display as follows
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 |
|
|
|