Sonsivri

Electronics => Pic C Languages => Topic started by: pumper on June 17, 2012, 01:15:35 13:15



Title: c18 and xc8 flash and eeprom variables?
Post by: pumper on June 17, 2012, 01:15:35 13:15
hi
my question is that:
we have a constant that we want to store in program memory.is this true:

Code:
const char c="hi";
char a;
a=c;
printf("a is %S",c);
and similar to it for eeprom data:
Code:
eeprom char c="hi";
a=c;
printf("a is %S",c);


Title: Re: c18 and xc8 flash and eeprom variables?
Post by: metal on June 17, 2012, 10:15:13 22:15
Section "3.5.2 Variables in Data Space Memory" states:

Most variables are ultimately positioned into the data space memory. The exceptions are non-auto variables which are qualified as 'const', which are placed in the program memory space, or 'eeprom' qualified variables.

But concerning EEPROM, the story is a bit different. Look inside XC compiler user's guide: "3.5.5 Variables in EEPROM". This section is more than enough to give you understanding on how to deal with EEPROM. We are talking about PIC18. Also, read "3.4.8.4 EEPROM TYPE QUALIFIER", you will notice that the 'eeprom' type qualifier is recognized by the compiler for baseline and mid-range devices only. If the --STRICT option is used, this qualifier is changed to __eeprom. So you have to stick to things you are going to read in "3.5.5 Variables in EEPROM" when working with PIC18, hence you will have to use __EEPROM_DATA() macro that is explained in "3.5.5.1 EEPROM INITIALIZATION".

Tha manual can be found in your installation folder:
C:\Program Files\Microchip\xc8\v1.00\docs\manual.pdf



P.S. I tried eeprom qualifier with PIC12F675 and still XC8 compiler could not recognized it and issues errors 195 and 312. On PIC18F458 I tried __EEPROM_DATA() macro, and eeprom read and write functions, they worked successfully.