Discussion in "8051 Discussion Forum" started by    aimseeker    Feb 7, 2011.
Mon Feb 07 2011, 07:18 PM
#1
Hey everyone...
I have got two questions..
1.While programming 8051 in C ... Is there a more effective(in saving memory) way to deal with decimal points .... Though we all know that we can just create a variable "float" or "double" and do "multiplications" and "division" on them easily but doing that wont be an effective way to program 8051 using C language....

2. I used a sprintf function in a program to convert a "floating" value to string and display it on LCD, but an engineer at my workplace told me not to do that instead i should write my own "effective" function to display a "floating" value on Lcd.. I would like to know what other options do i have??

Thanks in advance...
Tue Feb 08 2011, 05:57 PM
#2
waiting for others... I also want to know tha t
Tue Feb 08 2011, 06:32 PM
#3
there are some ways to doing this
u can see these attachments
ieee math file is for ieee standard math calculations

Attachment

Attachment

 romel_emperado like this.
Tags float to asciiftoafloat lcddecimal number lcdfloating point lcd display
Tue Feb 08 2011, 07:01 PM
#4

1.While programming 8051 in C ... Is there a more effective(in saving memory) way to deal with decimal points .... Though we all know that we can just create a variable "float" or "double" and do "multiplications" and "division" on them easily but doing that wont be an effective way to program 8051 using C language....


Effectiveness does depends on the way of writing code. especially incase of floating points. Usually the companies who make C compilers does take care of the efficiency of the program in all respect. But its not bad to try it on your own. You can see examples in majoka's post. you can also find some math libraries in our download section.

2. I used a sprintf function in a program to convert a "floating" value to string and display it on LCD, but an engineer at my workplace told me not to do that instead i should write my own "effective" function to display a "floating" value on Lcd.. I would like to know what other options do i have??


Its usually not recommended to use %f in sprintf. but %d is ok to use. wont effect much. so if you want a floating point to be displayed, consider it as a decimal before displaying it.

Lets take an example to explain:
you have a nnumber 20.34 (or any number) and you want this number to be displayed with 2 decimal precision. so... what we do is reserve 2 decimal points
how? like this:
float f = 20.34;
int i; //this will store our number in integer format
i = f * 100; //multiply by 100 so we reserve 2 decimal places in a float
//i iwll now have 2043 in it :)


now come to the display part, as i said using %d will not harm at all
so we use the same sprintf method.
int count; //this will store how many bytes written to buffer
char buff[6]; //this will be used to display

count = sprintf(buff, "%d", i); //i is number from example

//i am assuming disp_str is function to display string
disp_str(buff, 2); //display 2 bytes from buffer on display
//we know we have 2 decimal places so next on lcd has to be a point
disp_str(".", 1); //display a point
//now comes the decimal point
disp_str(buff+2, 2); //we incremented buff by 2 coz we already display the integer part

so you see we did not use any %f switch which makes this floating free ascii conversion though it seems a bit lenthy but if you put this in a function, its much smaller than any converter function


[ Edited Tue Feb 08 2011, 07:02 PM ]
 romel_emperadomajoka like this.
Tags float to asciiftoafloat lcddecimal number lcdfloating point lcd display
Wed Feb 09 2011, 02:27 AM
#5
thanks for that explanation ajay although it's looks lengthy but a good basic example for beginners like me..

let me copy your explaination to my learning thread...

Get Social

Information

Powered by e107 Forum System

Conversation

No messages yet.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 128, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123