void ftoa(float f,char *buf)
{
int pos=0,ix,dp,num;
if (f<0)
{
buf[pos++]='-';
f = -f;
}
dp=0;
while (f>=10.0)
{
f=f/10.0;
dp++;
}
for (ix=1;ix<8;ix++)
{
num = f;
f=f-num;
if (num>9)
buf[pos++]='#';
else
buf[pos++]='0'+num;
if (dp==0) buf[pos++]='.';
f=f*10.0;
dp--;
}
}
I can find ftoa() on the smaller compiler... It seems to be included with the pic18 (hi-tech) only.... This is why I post it here...Look up the function FTOA() in the manual for a start. Given that you have your LCD code working
It is included in the 9.83 version of the Hi-Tech C compiler. And also in the XC8 compiler. However what we did not mention. Was the fact that it can be more easy often to work with integers. Then place the decimal sign in code. If you use the ftoa function. The use of printf will also follow in this case. And the latter function will require about 2K of code in the ROM. Then using the free versionI can find ftoa() on the smaller compiler... It seems to be included with the pic18 (hi-tech) only.... This is why I post it here...
If someone were to attempt to use that code with the typos it would not compile since f0 and ix8 would be flagged as undefined.Not my code... This is from Hitech... Good or what..
I haven't used it for negative floats.... so It never used that part... But I do remember the other typo!! but I don't use floats anymore so it has been a while...
At least you have reminded me to update it... Cheers MrChips...
Funny that! The more experience and skill you acquire in embedded C the less you use floats....
I haven't used it for negative floats.... so It never used that part... But I do remember the other typo!! but I don't use floats anymore...
...
I agree.. I haven't used them for ages... BUT!! I did a project the other day using floats... They aren't as accurate... Any precision required then its easier to use lookups... Imagine all the calculations I need to use for the geometry alone...RB said:Funny that! The more experience and skill you acquire in embedded C the less you use floats.
by Jake Hertz
by Jake Hertz
by Aaron Carman
by Duane Benson