|
|
View previous topic :: View next topic |
Author |
Message |
pilt1 Guest
|
EEPROM copy to RAM |
Posted: Wed May 17, 2006 5:01 pm |
|
|
Hi, i currently have an array
array[8][8]
and i store data in the EEPROM which is copyed into the array in RAM at startup
Currently i use this code:
Code: |
for(j=0;j<8;j++)
{
for(i=0;i<8;i++)
{
delay_us(10);
array[i][j] = read_EEPROM(k);
k++;
}
i=0;
}
|
This works but i am wondering if there is a better way of doing this?
Is it possible to do this using the memcpy() function?
Thanks
Pilt |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 17, 2006 5:12 pm |
|
|
Quote: | Is it possible to do this using the memcpy() function? |
No, because the EEPROM is not addressable as a PIC RAM location.
You have to use the CCS read_eeprom() function or some equivalent
of it. Someone may suggest using the typemod directive, but this
will just disguise the process. The read_eeprom() function still has
to be called. |
|
|
kypec
Joined: 20 Sep 2003 Posts: 54
|
|
Posted: Wed May 17, 2006 11:57 pm |
|
|
Just my curiosity: why are you using delay_us(10) in between readings from Data EEPROM? The read process is (almost when not counting SFR initialization overhead) as fast as reading from RAM registers, there's no need to insert any dummy wait cycles. |
|
|
Ttelmah Guest
|
|
Posted: Thu May 18, 2006 3:49 am |
|
|
As a 'comment', don't fiddle around with two counters. An 8*8 array, is 64 consecutive locations, so only one counter is needed.
I use this:
Code: |
void EEPROM_GET(int *ram_location, int num_to_move, int start_locn) {
int count;
for (count=0;count<num_to_move;count++) {
*ram_locn++=READ_EEPROM(start_locn+count);
}
}
|
Then for the case given, just call:
EEPROM_GET(array,64,0);
(Assuming that you are reading the data from the start of the EEPROM).
Now when storing multiple values into the EEPROM, I use #define,to give a 'symbolic' name for the locations of each, so would have something like:
#define EEPROM_ARRAY (0)
and use the 'sizeof' function, so you call:
EEPROM_GET(array,sizeof(array),EEPROM_ARRAY);
I also have the 'complementary' EEPROM_PUT function, for changing the stored data.
Using symbolic names, and sizes like this, means that it is easier to keep track of what is going on.
Best Wishes |
|
|
pilt1 Guest
|
|
Posted: Thu May 18, 2006 6:31 am |
|
|
Thanks that was just what i was looking for and works fine!
Now i just need to be able to read and stores 16 bit integers in EEPROM
Is it possible to use the #rom directive with a number like 1000? Does it just store this in two bytes of the EEPROM?
Thanks
Pilt |
|
|
Ttelmah Guest
|
|
Posted: Thu May 18, 2006 6:53 am |
|
|
Depends what chip you have...
On the '18' chips, the #ROM directive, assumes it is dealing with int16 values, and so you can write:
Code: |
#ROM 0xF00000 = { 0x0001,
0x1000,0x2000,
0x3000,0x4000 }
|
The values will each be stored in two consecutive EEPROM locations.
You can 'override' this behaviour, by using the 'int8' directive in the #ROM statement, which them makes it behave like it does on the 12/16 chips.
You can even use (say) an 'int32' directive, and store 4bytes per number.
Remember also, that the GET_EEPROM function, doesn't care what the 'layout' of the target is, so you can retrieve a 16bit value 'fred' from the EEPROM, with:
GET_EEPROM(&fred,64,2);
Assuming that this was stored immediately after the 64 byte array.
Best Wishes |
|
|
pilt1 Guest
|
|
Posted: Thu May 18, 2006 12:40 pm |
|
|
Hi, I am using a PIC 16F8777A and i assume you cannot use the int16 with the ROM directive?
For this i assume the only way to use the EEPROM with integers is to use routines like this:
Code: |
void write_eeprom16(int address1, int address2, int16 value)
{
int8 lowerhalf = 0;
int8 upperhalf = 0;
lowerhalf = make8(value,0);
write_eeprom(address1,lowerhalf);
upperhalf = make8(value,1);
write_eeprom(address2,upperhalf);
}
int16 read_eeprom16(int address1, int address2)
{
int16 finalvalue = 0;
int8 lowerhalf = 0;
int8 upperhalf = 0;
upperhalf = read_eeprom(address2);
lowerhalf = read_eeprom(address1);
finalvalue = make16(upperhalf,lowerhalf);
return finalvalue;
}
|
Thanks
Pilt |
|
|
|
|
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
|