Author Topic: PIC18: Loading a value into EEPROM at compile / program time.  (Read 3443 times)

0 Members and 1 Guest are viewing this topic.

Offline DTJTopic starter

  • Frequent Contributor
  • **
  • Posts: 997
  • Country: au
PIC18: Loading a value into EEPROM at compile / program time.
« on: January 02, 2017, 04:38:44 am »
I'm using MPLABx, XC8 lite and a P18LF14k22

I want to program a value (a preset 'address') into the EEPROM when its programmed. How do I do this under XC8.

Previously under C18 I used the following and it worked fine:

Code: [Select]
#pragma romdata eedata_scn=0xf00000 // 3 lines instruct compiler to
rom unsigned char eedata_values[1] = {'0'}; // preload address "0" ==> eeprom
#pragma romdata



Below is what I think is the appropriate section from the XC8 Compiler User Manual:

Quote
2.5.9 EEPROM Objects
The __eeprom qualifier can be used to indicate that variables should be positioned in
EEPROM.

Use the native keywords discussed in the Differences section to look up information on
the semantics of this qualifier.
Some devices may not implement EEPROM. Use of this qualifier for such devices
generates a warning. Stack-based (auto and parameter) variables cannot use the
__eeprom specifier.

2.5.9.1 EXAMPLE
The following shows a variable qualified using __eeprom.

__eeprom int serialNos[4];


2.5.9.2 DIFFERENCES
The 8-bit compilers have used the qualifier, eeprom, to indicate this meaning for some
devices.

The 16-bit compilers have used the space attribute to allocate variables to the memory
space used for EEPROM.


2.5.9.3 MIGRATION TO THE CCI

For 8-bit compilers, change any occurrence of the eeprom qualifier to __eeprom, e.g.,
from:
eeprom char title[20];

to:

__eeprom char title[20];

For 16-bit compilers, change any occurrence of the eedata space attribute to
__eeprom, e.g., from:

int mainSw __attribute__ ((space(eedata)));

to:

int __eeprom mainSw;


2.5.9.4 CAVEATS

MPLAB XC8 does not implement the __eeprom qualifiers for any PIC18 devices; this
qualifier works as expected for other 8-bit devices.


How do I interpret that?

It seems to be saying that you can't write values to EEPROM directly in the compiler for 8 bit / P18 devices with XC8
I've tried a few variations of the __eeprom / eeprom command but they won't compile.

Google's not been helpful to me today! Anyone know how I should do this please.

 
 

Offline DTJTopic starter

  • Frequent Contributor
  • **
  • Posts: 997
  • Country: au
Re: PIC18: Loading a value into EEPROM at compile / program time.
« Reply #1 on: January 02, 2017, 05:53:59 am »
As usual shortly after posting I manage to answer my own question!

As I can't delete my post I'll pop the solution here just in case other noobies like me find it useful.



I managed to get the __EEPROM_DATA() macro to work. Placing it after the includes in my code.


Quote
__EEPROM_DATA(0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00); //fill first 8 locations

//macro must contain 8 elements, set unused ones to zero --> 0x00

//__EEPROM_DATA(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);  // addr: 0x00 ... 0x07
//__EEPROM_DATA(0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88);  // addr: 0x08 ... 0x0F
//__EEPROM_DATA(0x55, 0x66, 0x87, 0x65, 0xFF, 0xFF, 0xFF, 0xFF);  // addr: 0x10 ... 0x17

It seems others have had the problem too:
http://electronics.stackexchange.com/questions/108310/pre-defining-eeprom-values-in-xc8-compiler
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf