View previous topic :: View next topic |
Author |
Message |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
Initializing structures in CCS? |
Posted: Wed Dec 08, 2010 8:39 pm |
|
|
In another post ( http://www.ccsinfo.com/forum/viewtopic.php?t=44178 )
I had asked about storing config data in eeprom and one example
Ttelmah had given was a structure of initial values as follows:
Code: | struct config_data {
int8 data_ok=0xAA;
int16 wash_time=200;
int16 adc_zero=40;
int16 adc_full=984;
int16 output_4mA=166;
int16 output_20mA=900;
} |
However, I am not familiar with being able to declare a structures with
initial values like that (and the compiler does not like it either). I am
familiar with the construct where you declare the structure as in
Code: | struct config_data {
int8 data;
int16 wash_time;
etc;
}
|
then being able to declare
Code: |
static struct config_data my_config = {0xA5, 30, etc}; // load defaults
|
Is there a handier way along the lines originally shown ? Searching the
compiler (version 4) manual didn't provide any insight into other ways of
declaring/initializing a structure. I was also familiar with the:
Code: | static struct config_data {
int8 data;
int16 wash_time;
etc;
} my_config = {0xA5, 30, etc};
|
Is there another way that I have not found documented ? I know CCS
doesn't always follow the standards with their enhancements, but I have
been unable to find any details.
thanks for looking !
(PIC18F14K22, compiler 4.114)
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Dec 08, 2010 10:47 pm |
|
|
I've used both methods B and C in your examples.
Method A indeed causes a compiler error.
I've also declared array's of structures and used method B to loop through the array with array[x] = const_struct and that works too.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Dec 08, 2010 10:49 pm |
|
|
Oh, and in terms of saving a structure to memory like flash or EEPROM,
I typically roll it in and out with a loop that's zero to < sizeof(struct) and then make a pointer to the structure that's +x to save the array.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed Dec 08, 2010 11:54 pm |
|
|
Thanks Ben - this is what I used to initialize the structure - I didn't bother with a template name since this structure only is used once. I used Ttelmah's block move routines to copy in and out of eeprom (at the start of main, if the first byte of eeprom doesn't match the check byte, the initialized sizeof(structure) is copied to eeprom. Seems to work fine on the test hardware
Code: | // set up default calibration factors - temps are in deg C * 10
static struct {
int8 chk1; // checkbyte in eeprom 0xA5 if settings have been stored.
int16 Tset_AMB; // ambient air set point - deg C x 10
int16 Tset_HTR; // set point for heater plate - deg C x 10
int16 Thyst; // hysterisis to use for on/off - deg C x 10
} settings = { CHK_BYTE, // check byte
20, // 2.0 degrees for ambient threshold to turn on
250, // 25.0 degrees as heater target temp
30 }; // 3.0 deg hyst |
Then, up near the start of main(), I have the following that checks for the data in eeprom.
Code: | if (read_eeprom(0) != CHK_BYTE ) // settings not stored in eeprom ?
{
EEPROM_PUT(&settings,sizeof(settings),0); // copy defaults to eeprom if needed
lcd_putc("\fWrite Defaults \n ====> EEPROM");
delay_ms(5000); // time to read message.
}
EEPROM_GET(&settings,sizeof(settings),0); // read settings into settings stuct
|
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
alexandre
Joined: 10 Dec 2010 Posts: 7
|
read_eeprom & write_eeprom with PIC18F87J11 |
Posted: Fri Dec 10, 2010 3:16 am |
|
|
Hello every body,
I just started programming PIC18F, I'm using CCS 4.049
The built-in read_eeprom and write_eeprom functions are not recognised by my compiler.
The error message is:
"*** Error 12 "main.c" Line 74(16,17): Undefined identifier -- write_eeprom"
some one would help me please.
I want to save some information in the data memory of the PIC18F87J11. According to its datasheet this PIC has 3930 Bytes of data memory.
Does there any way (other than read_eeprom() and write_eeprom() built-in functions) to manage the Data Memory of PIC18F87J11?
Thank you very much for your help Rolling Eyes |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Fri Dec 10, 2010 5:07 am |
|
|
Don't ask the same question in multiple threads. Have answered in your separate thread. |
|
|
|