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

Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

ananyagupta
Tue Dec 03 2019, 07:53 AM
wells
Mon Nov 25 2019, 08:25 PM
auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM

Online

Guests: 39, Members: 0 ...

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

Members: 38107
Newest member: ananyagupta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Nov 29 2019, 04:24 AM
" Is it possible to interface a fingerprint scanne...
ilylily07 Avatar
Posted By ilylily07
Thu Nov 28 2019, 03:50 PM
You will not find any code for an 8051 as no one w...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 05:44 PM
You will not find any code for an 8051 as no one w...
ilylily07 Avatar
Posted By ilylily07
Tue Nov 26 2019, 04:13 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 26 2019, 12:08 AM
I tracked down a OV7670 data sheet.The OV7670 puts...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 25 2019, 04:38 PM
The 8051 has too little memory to do anything us...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM