View previous topic :: View next topic |
Author |
Message |
hwk Guest
|
floats in eeprom |
Posted: Sat Feb 03, 2007 10:34 am |
|
|
float get_float(long int n)
{
int i,y;
float data_f=0;
printf("%2X\n\r",n);
for(i=0;i<4;i++){
*(&data_f+i)=read_eeprom(i+n);
y=read_eeprom(i+n);
printf("%2X\n\r",y);
}
printf("%f\n\r",data_f);
return (data_f);
} [/code]
hello,
using above code. diregard the printf statements.debug only. if the eeprom contains 0x7f,0x00,0x00,0x00 this module returns decimal 127. It should be decimal 1. this code has worked for a year. I recently upgraded to the most recent version of PCH and this portion of code does not work.
this is on a PIC18F2620.
any help would be graetly appreciated
thanks
eaton[/code] |
|
|
hwk Guest
|
code that worked |
Posted: Sat Feb 03, 2007 12:58 pm |
|
|
float get_float(long int n)
{
int i,y;
float data_f=0;
int *p;
p=&data_f;
for(i=0;i<4;i++){
//y=read_eeprom(i+n);
//*(&data_f+i)=read_eeprom(i+n);
*(p+i)=read_eeprom(i+n);
}
return (data_f);
}
this finally worked. is there some subtle difference in the compiler that I'm missing. the line //*(&data_f+i)=read_eeprom(i+n); should work i think. the line *(p+i)=read_eeprom(i+n); is essentialy the same and it does work. Can anybody provide an explanation?
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 03, 2007 1:19 pm |
|
|
CCS recently made a change in the compiler operation that affects your
code. See the versions page here:
http://www.ccsinfo.com/devices.php?page=versioninfo
Here is the change:
Quote: |
4.021 The & unary operator by default no longer returns a generic (int8 *) |
This means that to make your code work, you must cast the address
to a char pointer:
Quote: | *((char *)(&data_f) + i) = read_eeprom(i+n); |
|
|
|
hwk Guest
|
|
Posted: Sat Feb 03, 2007 3:01 pm |
|
|
thanks PCM
that explains it. Insidious little bug. I have to make more time for reading the version changes. |
|
|
|