| Author |
Message |
lgeorge123
Joined: 13 Jun 2004 Posts: 62
|
17 Apr 2008 14:13 how to display float |
|
|
|
|
i have two variables float number (may be 1.28 and 15.9, note the position of decimal point), can anyone tell me how to display to lcd using keil c ???
the only one way is to convert above two float number to array of ascii and then output to lcd, more trouble is how to determine the position of decimal point, the exact method i don't know !!!! mcu i am using is 89s52.
|
|
| Back to top |
|
 |
nandhu015
Joined: 11 Feb 2006 Posts: 640 Helped: 46 Location: Tamilnadu, India
|
17 Apr 2008 16:26 lcd display float |
|
|
|
|
hi lgeorge123
what i do is simply convert all of them to 0.00 precesion.
I think you got the idea.
Regards
Nandhu
|
|
| Back to top |
|
 |
RBB
Joined: 02 Jul 2007 Posts: 115 Helped: 11 Location: USA
|
17 Apr 2008 17:03 float lcd |
|
|
|
|
Can you:
1. type cast the real number to an integer
2. take the difference between the integer and the float
3. multiply the difference by some value
4. then type cast that value to an integer?
You would then have two integer values you could convert to ascii. You would then display a '.' between the two integers.
float realValue;
int intValue = (int)realValue;
float diffValue = realValue - (float)intValue;
int anotherIntValue = (int)(diffValue * 1000.0)
sprintf("%s.%s", itoa(intValue), itoa(anotherIntValue));
|
|
| Back to top |
|
 |
jit_singh_tara
Joined: 22 Dec 2006 Posts: 110 Helped: 6
|
17 Apr 2008 17:24 float to lcd |
|
|
|
|
suppose you have
23.57
1. for integral part
equate temp1(int ) to 23.57;
temp1 will be 23 only as it is of int type so 23.57 will be typecasted to 23 .you have integral value.
2. for float part
multiply the number by 100 store it in int variable(0 to 65535) say temp;
now temp = 2357
get the lower two digits as 5 and 7 (i hope you can do it).just split 2357 into 4 separate values by taking remainder (after dividing by 10).
once you have 4 separate values of 2 , 3 ,5,7 dislplay it anywhere.
|
|
| Back to top |
|
 |
gvinu4u
Joined: 10 Mar 2008 Posts: 24 Helped: 1 Location: Bengaluru
|
17 Apr 2008 17:49 ascii display |
|
|
|
|
| I recommend u to store the values in two seperate variables ie interger and float part later display it on lcd seperated by a dot
|
|
| Back to top |
|
 |
Google AdSense

|
17 Apr 2008 17:49 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
XNOX_Rambo
Joined: 13 Jul 2002 Posts: 437 Helped: 87 Location: Far out, man!
|
18 Apr 2008 0:09 display float number to lcd |
|
|
|
|
| Code: |
float xdata a, b;
char xdata str[20];
a = 1.28;
b = 15.9;
sprintf(str,"A: %4.2f B: %4.1",a,b); // Adjust the formatting to your liking.
gputs(str); // Or whatever you use to write strings to the display. |
|
|
| Back to top |
|
 |
pak_soft
Joined: 19 Feb 2008 Posts: 2
|
20 Apr 2008 17:37 display floating value on lcd |
|
|
|
|
Hi,
I use keil compiler for 8051 mcu, i use sprintf to display float number to lcd pls refer to following example. Note: sprintf take a lot of memory space, but easier to use. All you need to do is to declare one array.
| Code: |
void main() {
char buf[8]; // declare array
delay_ms(100); //settle time for lcd
lcd_init(); // initialization of lcd
lcd_clear(); //clear lcd display
sprintf (buf, "float=%f", 1.156); // here is sprintf prototype function usage
// 1.156 is just example you can change it
lcd_puts(buf); // display float number from array to lcd
} |
hope it'll help you,
regards,
pak
|
|
| Back to top |
|
 |