|
|
View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
eeprom locations |
Posted: Sun Sep 11, 2011 3:58 am |
|
|
Dear all, I am trying to assign a particular eeprom location to a variable but for some reason the compiler is giving me an error "Expecting an identifier". What could be wrong? I am using 18F4520 and the code is below:
Code: | #rom int 0xf00000={1,2,3,4,5}
#define last_scene 1
#define butt1_scene 2
#define butt2_scene 3
#define butt3_scene 4
#define butt4_scene 5 |
thanks for your help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun Sep 11, 2011 10:06 am |
|
|
Several parts:
1) A #define, does not define a variable. It is a _text_ substitution during compilation. So wherever you have the word 'last_scene' for example, the number '1' will be substituted. So if you tried to execute:
last_scene=10;
The resulting 'real' code would be '1=10'. An impossible operation, since a variable identifier is _needed_ on the left of the equation. This is what the compiler is complaining about.
2) The PIC does not have a single linear memory space. It has RAM memory (addressable by variables), and ROM memory in a separate address space. Then the EEPROM exists in a third address space. You can't read/write directly to the address spaces other than the RAM one (there is a sort of way round this, but more complex than it is worth....).
3) Look at the read_eeprom, and write_eeprom functions. These would accept your defined address and a value to read/write. The best way to use the EEPROM.
4) You can access EEPROM as if it is in your memory space, by allocating the read/write functions with ADDRESSMOD. However bulky, and prone to errors.
Big caveat. Be careful how often you change things with any route. If you read/write the EEPROM as if it is a variable, you can kill the chip in a few hours. The EEPROM is designed to be updated _infrequently_.
Best Wishes |
|
|
|
|
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
|