CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to #ROM a float?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

How to #ROM a float?
PostPosted: Fri Feb 07, 2014 4:33 am     Reply with quote

How to write a float number in #ROM directive on pic18?
Ttelmah



Joined: 11 Mar 2010
Posts: 19455

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 5:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 5:14 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group