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

#rom used to initialize float into EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Bedros B
Guest







#rom used to initialize float into EEPROM
PostPosted: Thu Oct 01, 2009 6:40 am     Reply with quote

I want to use the #ROM preprocessor directive to preload the PIC16F1936 EEPROM with values at the time of programming the chip. This works well if the variables are integers 8, 16 or 32 bit by using left shift commands for example:
Code:

#define putLong(value) {value,(value>>8),(value>>16),(value>>24)}
#rom 0x0f000 = putLong(0x12345678)
#rom 0x0f004 = putLong(0x9ABCDE)
…etc…

But how can I store floating point numbers?
Are there any preprocessor directives that can help me?

Thanks
Bedros
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 01, 2009 1:39 pm     Reply with quote

Use the FloatConv.exe program contained in this zip file to convert
a floating point number from Microchip 32-bit format to four hex bytes:
http://www.piclist.com/images/floatconv10.zip
(Drag the exe file onto your desktop and click on it).

Then put the bytes in a #rom statement at the data eeprom address.
Then read the data eeprom in your program with read_eeprom().
The test program shown below will display:
Quote:
1.234

Code:

#include <16F1936.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// Embed the 4 bytes for 1.234 (from FloatConv.exe) into eeprom.
#rom 0xF000 = {0x7F, 0x1D, 0xF3, 0xB6}

float read_float_eeprom(int8 addr)
{
int8 i;
float data;

for(i=0; i<4; i++)
    *((int8*)&data + i) = read_eeprom(addr + i);

return(data);
}

//======================================
void main(void)
{
float temp;

temp = read_float_eeprom(0);

printf("%4.3f", temp);
   
while(1);
}
bedros b
Guest







PostPosted: Thu Oct 01, 2009 3:39 pm     Reply with quote

Thanks for the info.
The "floatconv.exe" program is very useful.
Makes it almost possible to do it manually as you suggested.

I was hoping to have a simpler way, so it becomes simple
to change the float values as required.

Thanks again
Bedros
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 02, 2009 6:25 am     Reply with quote

Just for future reference, if you have the CCS IDE, the Numeric Converter from the Tools menu does the same job as the floatconv tool above. You still need to manually copy the hex values, though.
_________________
Andrew
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