Discussion in "General help Guidance and Discussion" started by    desiato    Dec 3, 2007.
Mon Dec 03 2007, 04:50 pm
#1
do anyone know how i can convert floating point quickly to ascii in C using a 8051 only,so i can display it in a LCD ?
i know i may extract the sign bit, exponent and mantissa with bitwise and convert then using a lot of divisions, but this seems to be quite slow.
Mon Dec 03 2007, 05:16 pm
#2
well.. do the calculations by multiplying the number by 100, after that.. the last two digits of your calculation will be the number after the decimal. how many decimal point you want? and what data type you are using in your calculation?

here is an example regarding my idea..
you are calculating like 10.6 x 43.2
so multiply both by 10, 1060 and 4320
the result wil be 45792, so the last digit is your number after the decimal..
simply divide it by 10 and quotient will be 4579 and remainder will be 2
display them separately.

I used this technique in my digital thermometer program where i get the average of 50 readings.
what i did was.. i added all 50 and then multiplied it by 100 and then divided by 50 so what actually was getting done here is final addition was multiplied by 2.
e.g. if x is the total.. so avg = x*100/50 = x*2
so whatever my total was, i just multiply it by 2.
lets say total was 2486 after multiplying it by 2 i get 4972, so saperate first and last two digits and display on LCD.
this is what i did in my c program
	adc_high = avg/100;
	disp_adc_high(adc_high);
	adc_low = avg%100;
	wrt_data('.');
	disp_adc_low(adc_low);
Mon Dec 10 2007, 09:26 pm
#3
Can you cast the float into an int , then use itoa(), and then convert to ASCII?

I am not familiar with the C compiler you are using.

I am very rusty - haven't done C programming for nearly a year. And am only a novice:-p
Mon Dec 10 2007, 10:25 pm
#4
if using keil ,
include stdio.h
use sprintf(buffer,"%f",My_VarFloat); // buffer is char* Varfloat is float
now u can display buffer on to lcd...
it surely works

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm
oriminna
Sat May 04 2024, 08:28 pm
scaneraNom
Sat May 04 2024, 02:21 am
gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am