Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
How to #ROM a float?
Posted: Fri Feb 07, 2014 4:33 am
How to write a float number in #ROM directive on pic18?
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
Posted: Fri Feb 07, 2014 5:10 am
This is where the pconvert tool with the compiler comes in really useful.
Type in the float 'Microchip float32' format, and in the 'hex' line it gives the bytes needed to represent this. Cut and paste into the #ROM statement.
Best Wishes
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
Posted: Fri Feb 07, 2014 5:14 am
I think it might be done if you calculate the float value each time you read and wtite into rom. E.g. If you have two digits following decimal point, just multiply float value by 10^n then store it into rom.
n - number of digits following decimal point
Code:
unsigned int16 float_to_store;
float f=5.65
float_to_store = f*100;
//write into rom as 565
//to read it back devide it.
f=(float)float_to_store/100;
I hope you get the idea. Just multiply/devide(10^n) the float so you can transduce the float value to decimal and back. _________________ A person who never made a mistake never tried anything new.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum