|
|
View previous topic :: View next topic |
Author |
Message |
sprotch
Joined: 29 Sep 2005 Posts: 7
|
ROM questions |
Posted: Tue Oct 18, 2005 1:57 am |
|
|
Hi all!
I'm new in PIC programming and want to store data in ROM but can't understand the difference between several functions. My purpose is to store data (string) in ROM during a configuration session and then use it in normal runtime.
1. Configuration of PIC: connected to a PC >> store constant data
2. Run the programm detached from PC >> use of the constants
What is the best option and what are the differences between, write_eeprom(), write_program_eeprom() and write_program_memory()?
And what does exactly the #ROM directive? Can it be used to declare a symbolic name for an eeprom adress? Can it be used with read_eeprom() and write_eeprom() ? |
|
|
Ttelmah Guest
|
|
Posted: Tue Oct 18, 2005 2:35 am |
|
|
Starting at the end.
The #ROM directive, allows values to be placed at an address in the chips ROM memory, _when it is programmed_. So if you are using a block at a particular address to contain a string of data, you can include a set of 'default' values in the compiled code. The block can be in program memory, or the EEPROM, by just selecting the right address.
There is a caveat with using a 'symbolic name', in that if you declare a constant, what is stored will include the retrieval code, placing the actual data slightly further up the memory. Hence it is really safer to use the ROM directive, and place the data yourself.
There is really little difference between using program memory, and the internal EEPROM, except _durability_, and the use of space in the program memory area. The EEPROM, typically has aboput 100* the 'life' in terms of read/write cycles, than the program memory.
Consider something like:
Code: |
struct constants {
int8 demo1;
int16 demo2;
char strvalue[10];
} memory_version;
#define CONST_IN_EE &memory_version,sizeof(struct constants),0
void EEPROM_GET(int *ptr,int num,int addr)
{
int count;
for (count=0;count<num;count++) {
*ptr++=READ_EEPROM(addr+count);
}
}
void EEPROM_PUT(int *ptr,int num,int addr)
{
int count;
for (count=0;count<num;count++) {
WRITE_EEPROM(addr+count,*ptr++);
}
}
|
Then you have a structure called 'constants', containing the current version, and when you want to write this to EEPROM, can just use:
EEPROM_PUT(CONST_IN_EE);
and when you want to read these, use:
EEPROM_GET(CONST_IN_EE);
You can declare other structures/variables to access the same way.
There is little difference between the 'program_memory', and eeprom versions of the functions, accept what memory they actually access, and the fact that the processor will suspend operation for the entire write cycle, when you access the program memory (you can't be changing this memory, while your code is running from it).
The eeprom is designed for exactly this job, which is why it is there.
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
|