View previous topic :: View next topic |
Author |
Message |
varadharaj
Joined: 09 Apr 2012 Posts: 19 Location: Salem
|
Reg: glcd jhd12864e interfacing with pic16f877a |
Posted: Mon Nov 19, 2012 6:00 am |
|
|
Hi,
I am trying to interface jhd12864e with pic16f877a. I need to display the temperture value in the screen.
I am using GLCD.C driver for my project. For string letters the output is proper. How to display the floating point numbers and numbers?
in lcd.c, we are having printf(lcd_putc,"%ld",value);
likewise is there any method to print the numbers?
Is there any example program for that ?
Thank you.. _________________ Embedding Innovation |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Nov 19, 2012 7:39 am |
|
|
Hi,
You need to use the 'sprintf' function to convert your numerical readings (all types) into a string. Here is an example of some code I use to do this:
Code: |
adc_value = read_adc_average(0);
volts = (float)(adc_value * 4.096 * 4)/1023.0;
sprintf(NumDisplay,"%2.2f", volts);
glcd_text14X21(25,5,NumDisplay, ON);
|
Note, that 'read_adc_average()', and 'glcd_text14X21()' are my own functions, so you'll have to substitute the functions you have!
John |
|
|
varadharaj
Joined: 09 Apr 2012 Posts: 19 Location: Salem
|
|
Posted: Mon Nov 19, 2012 10:30 pm |
|
|
Hi,
thanks for your quick response. Do i need to erase the data on the screen every time? Otherwise it is showing unwanted characters..
i tried glcd_init(ON); function ... but every time it is giving flickering.
Thanks _________________ Embedding Innovation |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Nov 20, 2012 2:01 am |
|
|
So long as you write the text at the same location, the key is to just write a little more. So (for instance) - based upon what has already been posted:
"%2.2f "
Note the two trailing spaces.
Now, provided your number never changes by more than a factor of 100* between values, the old numbers will get overwritten by the new and spaces.
As a comment, '2.2', is not actually a legal %f formatter. It'll work, but only by continuously overflowing. In C formatters, the number in front of the decimal point, is the _total field width_, _not_ the number of digits in front of the decimal. The correct formatter for two digits in front of the decimal, is '%5.2f '
Best Wishes |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Nov 20, 2012 7:40 am |
|
|
Hi,
I'm not sure I agree that you can avoid erasing the old text simply by "write
the text at the same location". We are talking about a GLCD here, and most
GLCD drivers simply draw a text character at a specific screen location. If
you continuously write to that same location with different data, all the pixels
in that location will slowly fill up! You can rewrite the common GLCD drivers
to avoid this, or just before you update the field with new data, you can
write the old data again with the COLOR parameter set to 0 (zero). This
will effectively erase the previous text. You definitely do not want to call
the glcd_init() function repeatedly, as the display will flicker as you have seen.
Ttelmah, thank for pointing out the error in my float formatting. That code
is quite old, and predates my 'enlightenment' I should have caught
that before posting!
John |
|
|
varadharaj
Joined: 09 Apr 2012 Posts: 19 Location: Salem
|
|
Posted: Tue Nov 20, 2012 10:58 pm |
|
|
@ ezflyr,
Thanks for your suggestions ... It is working now...
@ Ttelmah,
Thanks to you for giving your points on the floating number specification.
I have seen lot of useful suggestions in this forum from you.
Thanks a Lot .... _________________ Embedding Innovation |
|
|
|