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 CCS Technical Support

pointers to struct?

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



Joined: 10 Sep 2003
Posts: 4

View user's profile Send private message

pointers to struct?
PostPosted: Tue Mar 21, 2006 9:39 am     Reply with quote

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 = &current_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 = &current_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.
Ttelmah
Guest







PostPosted: Tue Mar 21, 2006 10:24 am     Reply with quote

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
cwf713



Joined: 10 Sep 2003
Posts: 4

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 8:10 am     Reply with quote

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
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