View previous topic :: View next topic |
Author |
Message |
Chicky
Joined: 04 Aug 2005 Posts: 21
|
How to display floating point variable value on 16x2 lcd? |
Posted: Wed Sep 14, 2005 6:07 pm |
|
|
Hello..
Im trying to display the contents of floating point variable on my alphanumeric 16x2 lcd..
ex: count = 123.4532 and i want to display on lcd - 'cpm 123.4532'
The floating point value keep changing because it is related to my Timer1 value as external counter divide by some number.
Anyone can help me on this? Thanx a zillion~ |
|
|
Calamar
Joined: 07 Sep 2003 Posts: 60 Location: Buenos Aires (Argentina)
|
|
Posted: Wed Sep 14, 2005 10:14 pm |
|
|
Do you use LCD.C library attached with CCS compiler ?
printf(lcd_putc"\f cpm = %f",myFloatVar);
you must give details, it's a standar LCD module ?
how did you wire it ?
There are a lot of previus topics taloking about that. _________________ Best Regards
Daniel H. Sagarra
La Plata (Argentina) |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Sep 15, 2005 7:44 am |
|
|
Is it really a floating point number? Or is it fixed point non-integer? Maybe you should print the integer part, then print ".", then print the decimal part. Doing true floats takes a lot of resources.
I often measure things in mm and print the result in meters this way. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Henk
Joined: 22 Mar 2004 Posts: 6 Location: JOHANNESBURG, SOUTH AFRICA
|
DISPLAYING FLOATING PT NUMBERS |
Posted: Sun Sep 18, 2005 1:21 am |
|
|
Depending on required number of dec. places, I multiply the float by 100, say, for 2 dec. places, then convert to an integer, which is then devide by 100000, to determine thousands, calc the remainder, div by 1000,etc, if you get the idea, remembering to display a "." for the decimal pt. The routine works well, and is adustable for 0 to 2 dec places, but can be modified for more. |
|
|
Ttelmah Guest
|
|
Posted: Sun Sep 18, 2005 2:38 am |
|
|
Worth also adding, that with the last couple of compiler versions, CCS have added support for this type of scaled integer with the '%w' printf format. The first version with this, had a fault (didn't put a '0' in front of the DP), but they have now fixed this, and indeed added an option to control this. Using such a scaled integer, results in much smaller code than a float. :-)
Best Wishes |
|
|
|