Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to display float number to lcd

Status
Not open for further replies.

lgeorge123

Full Member level 2
Joined
Jun 13, 2004
Messages
130
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Hong Kong
Activity points
1,403
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.
 

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
 

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));
 

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.
 

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
 

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.
 
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
 
using sprintf function in keil is giving the awesome out put thank...... for ur help man
..........
can u help with asm coding ha?
 

Refer the book written by MAZIDI about 8051 & its programming........ It deals the most with ASM coding of the controller.....
Regards,
Jerin.
 

float number handling is one of the difficult part in assembly but not impossible
 

i guys i refered mazdi book of embedded system .. i need the asm coding for the floating operation...........
in c it working fine . but problem is it occupies more memory size while using sprintf fun......
 

sprintf() or ftoa() function is nice but it take lots of bytes in code so when we do not have enough memory to use it we have to use alternative method:

- float tmp; tmp=12.3456
- get integer part :int a,b; a = tmp; (so a=12)
- get float part: tmp= tmp-a; (so tmp=0.3456)
- b = tmp * 1000; (so b=345) - if 3 digit is enough
- convert a to "12" by using a/10 and a%10 method;
- convert b to "345" ; LCDstring "12"; LCDstring "." ; LCDstring "345";
 

    V

    Points: 2
    Helpful Answer Positive Rating
Re: float lcd

by this methode you cant diaplay 999.099 or 12.009 ...etc
 

Re: float lcd


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define SRL_SND(a) { TXREG=a; while(!TRMT);}
 
void send_value_flt(float vl)
{
unsigned int j,tmp;
unsigned char buff[10]={0,0,0,0,0,0,0,0,0,0},k=0;
float tmp_vl=0;
 
j=(int)vl;         //vl=11.256  tmp=11
 
      k=0;
       while(j)
            {
                buff[k++]=(j%10);
                j/=10;
                
            }
 
             SRL_SND( (buff[3]+'0') );
             SRL_SND( (buff[2]+'0') );
             SRL_SND( (buff[1]+'0') );
             SRL_SND( (buff[0]+'0') );
 
tmp=(int)vl;        //11.0025 -> 11
tmp_vl=(float)tmp;  //11 -> 11.0000
vl=(vl-tmp_vl)+1;   //11.0025-11.000+1  => 1.0025
j=(int)(vl*1000);   // (11.256-11)+1   = 1.256  //1.256*1000  // j=1256 
 
 
{
SRL_SND('.');
 
buff[0]=0;
buff[1]=0;
buff[2]=0;
buff[3]=0;
buff[4]=0;
k=0;
 while(j)
        {
                buff[k++]=(j%10);
                j/=10;
        }  
 
              SRL_SND( (buff[2]+'0') );
              SRL_SND( (buff[1]+'0') );
              SRL_SND( (buff[0]+'0') );
           
}
}
////////////////////////////////////////////////////////////////////////

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top