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 CCS Technical Support

EEPROM emulation on PIC24FJ

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



Joined: 29 Nov 2013
Posts: 26

View user's profile Send private message

EEPROM emulation on PIC24FJ
PostPosted: Mon Mar 23, 2015 4:28 am     Reply with quote

Hi guys,

I need save a counter in a PIC24FJ in memory not volatile. This value is only changed 1x per day, just do not have endurance problems.
Does anyone have a stable code that makes E2PROM emulation these PICs?

Regards
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 6:38 am     Reply with quote

Well you need to set aside some space for the compiler to avoid:

Code:

#org start_address,stop_address {}


This needs to start on a page boundary and be the size of a page (see your particular chip's data sheet since you didn't supply a specific part number...there are a ton of PIC24's). If it isn't, at best it won't correctly work and at worst you will overwrite program space and crash your PIC.

After that you simply need to call write_program_memory() to write bytes (must be written in multiples of 4 bytes with the MSB always 0...so 24 bits of space. Each 4 bytes takes up 2 addresses from write_program_memory().
Code:

unsigned int32 value; 

//no larger than 24 bits
value = <whatever you want to save> & 0x00FFFFFF;
write_program_memory(&value,start_address,4);


That's the simplest method. The most complex is implementing the Application note that the microchip website provides.

Some other simple/medium complexity methods:
https://www.ccsinfo.com/forum/viewtopic.php?t=52680&highlight=pic24+eeprom+program+programme+memory
tEaM



Joined: 29 Nov 2013
Posts: 26

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 8:07 am     Reply with quote

Sorry, is the PIC24FJ128GA202.

It is possible to only use the "write_program_memory" function? It is not necessary to delete the page?
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 8:26 am     Reply with quote

The write_program_memory function _automatically erases the page, if you write to the first address in a page_.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 12:18 pm     Reply with quote

Take a look at my recent topic on this forum...

http://www.ccsinfo.com/forum/viewtopic.php?t=53530

Be careful, by design ...PIC hang on flash write and then resume...
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
tEaM



Joined: 29 Nov 2013
Posts: 26

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 12:21 pm     Reply with quote

I need your help to choose the "start_address" and "stop_address".
I can choose any address at the end of the flash?
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 23, 2015 1:58 pm     Reply with quote

You need to avoid the top four words of the program memory (so the top page), since these contain the flash config words.
So _two_ pages below the top of the program memory. Each page is 2KB (in address terms), but contains 1536 bytes of memory. So 0x14800 as a start address.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Mar 24, 2015 3:43 am     Reply with quote

I'll point you to the thread on writing the program memory on the 18F26J53 (currently only a couple of links from this one). I've just posted a demo program in this, of how to handle the memory. Most of what this involves is the same on your chip (except that you have to handle the re-arrangement of the data because every fourth byte is missing, and tweak the values to allow for the 32bit write size (the code uses 16bit).

I have used a more sophisticated version of this on the PIC24's.
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