![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
cwf713
Joined: 10 Sep 2003 Posts: 4
|
pointers to struct? |
Posted: Tue Mar 21, 2006 9:39 am |
|
|
Hello all,
I am migrating from 16F877 to 18F4525 and am having trouble with code that reads a data structure from data eeprom. I am using PCH v 3.6.0.98 and I get the error "invalid type conversion" when compiling the following code:
Code: |
#define data_size 12 // the number of bytes of data contained in the struct.
struct data
{
long magicnum;
signed level;
signed gain;
signed long ref_os;
int ext_ref_freq;
int address;
signed ref_state;
short other;
short remote;
short rs485;
short extref;
short rs422;
short rs232;
short ref_int;
short ref_ext;
short ref_auto;
short dummy1; //not used for anything, allows us to have an even amount of memory.
short dummy2; //not used for anything, allows us to have an even amount of memory.
short dummy3; //not used for anything, allows us to have an even amount of memory.
short dummy4; //not used for anything, allows us to have an even amount of memory.
short dummy5; //not used for anything, allows us to have an even amount of memory.
short dummy6; //not used for anything, allows us to have an even amount of memory.
short dummy7; //not used for anything, allows us to have an even amount of memory.
int chksum; //data checksum - equal to everything in the struct except this number
// mod 255.
};
struct data current_data;.
.
.
.
void data_startup(void)
{
struct data *tmp;
int magicnuml,magicnumh;
char magicnum[2];
long int i;
short rewrite = 1;
magicnuml = read_eeprom(0);
magicnumh = read_eeprom(1);
magicnum[0] = magicnuml;
magicnum[1] = magicnumh;
if((magicnuml == 0x4A) && (magicnumh == 0x53)) // if good data is stored in the eprom, lets get it and use it.
{
rewrite = 0;
tmp = ¤t_data;
for(i = 0;i < data_size;i++)
{
tmp[i] = read_eeprom(i);
}
if(chksum() != current_data.chksum) // checksum failed, rewrite eeprom
rewrite = 1;
}
if(rewrite) // if the eeprom doesn't do it for us, lets go with a resonable set of defaults.
{
current_data.magicnum = 0x534A;
current_data.level = 10;
current_data.gain = 0;
current_data.ref_os = 0;
current_data.ext_ref_freq = 10;
current_data.address = 0;
current_data.ref_state = 0;
current_data.other = 1;
current_data.remote = 0;
current_data.rs485 = 0;
current_data.extref = 0;
current_data.rs232 = 1;
current_data.rs422 = 0;
current_data.rs485 = 0;
current_data.ref_int = 1;
current_data.ref_ext = 0;
current_data.ref_auto = 0;
current_data.chksum = chksum();
write_data_eeprom();
}
temp_data = current_data;
}
void write_data_eeprom()
{
long int i;
struct data *tmp;
current_data.chksum = chksum();
tmp = ¤t_data;
for(i = 0; i < data_size; i++)
{
write_eeprom(i,tmp[i]);
}
}
|
The tmp[i] = read_eeprom(i); line causes an invalid type conversion but
the write_eeprom(i,tmp[i]) line does not. This code worked fine with my old PCM compiler for the 16F877. Any thoughts or ideas are much appreciated. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Mar 21, 2006 10:24 am |
|
|
The read and write eeprom functions for the 18f4525, require a long address (because there is 1K of eeprom). This may be causing the problem. Try manually casting 'i' to a long, or using a long variable to hold this value.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
cwf713
Joined: 10 Sep 2003 Posts: 4
|
|
Posted: Thu Mar 23, 2006 8:10 am |
|
|
Thank you for the response. I changed the line "struct data *tmp" to "int *tmp" and the code compiled with no errors. However, the eeprom did not work until I disabled interrupts while writing to it (as per the 18F4525 data sheet).
Cheers |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|