CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Writing (not overwriting) to eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ancient_one



Joined: 05 Jan 2012
Posts: 7

View user's profile Send private message

Writing (not overwriting) to eeprom
PostPosted: Mon Mar 05, 2012 7:05 pm     Reply with quote

I'm using PIC16F88 and i've got a file that store a lot of bytes in eeprom

Code:
const byte asciitable1[51][5] = {0x00, 0x00, 0x00, 0x00, 0x00,  // 32 SPACE
                        0x00, 0x00, 0x7d, 0x00, 0x00,  // 33 !
                        0x00, 0x70, 0x00, 0x70, 0x00,  // 34 "
                        0x14, 0x7f, 0x14, 0x7f, 0x14,  // 35 #
....


Now i need to write&read a data struct into eeprom at runtime, how can i find a free address that will not overwrite my asciitable const?

I use:
Code:
typedef struct {
   unsigned char string[32];
   int8 hscroll;
   int8 vscroll;
} packet;
void write_eeprom_packet()
{
   int8 i;
   for (i = 0; i < sizeof(packet); i++)
   write_eeprom(EEPROMADDRESS+i, *(p+i));
}
void read_eeprom_packet()
{
   int8 i;
   for (i = 0; i < sizeof(packet); i++)
      *(p+i) = read_eeprom(EEPROMADDRESS+i);
}


I need to know a free address for EEPROMADDRESS[/code]
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Mar 05, 2012 8:00 pm     Reply with quote

There is no concept of memory management or file system management for the EEPROM. You, as the application developer decide where you place content in the EEPROM.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2012 10:47 pm     Reply with quote

Quote:
const byte asciitable1[51][5]

This array is stored in flash memory. That is not the same type of
memory as Data EEprom. The write_eeprom() and read_eeprom()
functions do not operate on Flash memory.

The write_eeprom() and read_eeprom() functions operate on Data EEprom. The 16F88 has 256 bytes of Data EEprom, so those two
functions expect an address of 0 to 255.

You can just choose 0 as the starting address for your 34-byte packet.
Put the packet at the start of the Data EEprom. Example:
Code:

#define EEPROMADDRESS  0
Can



Joined: 26 Feb 2012
Posts: 23

View user's profile Send private message Visit poster's website

PostPosted: Thu Mar 08, 2012 3:20 am     Reply with quote

If i understand your question right you can just allocate the first byte of the EEPROM for memory mapping. Whenever you write to EEPROM, you can just update the memory map. So whenever you read the first byte in the EEPROM you have your last written address (or if you make a +1 you get the first available address)

Best
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 1:38 pm     Reply with quote

from my hard won experience , i might add data EEPROM has plenty of opportunities to give you grief.

1- the TIME to do a write is significant compared to nearly any other CCS intrinsic function- and you NEVER want to do a data eeprom write from inside an ISR

2- eeprom is FRAGILE , and an excessive number of writes can leave
addresses nonfunctional

3- without a decently robust means of TESTING that a given location is data and not trash - you ought to allocate an extra byte or word to verifying the
integrity of what you wrote -i am speaking of checksum ( byte or word ) or CRC test -otherwise you are courting trouble over the very long haul

just my 2 cents
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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