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 Preload and Overwrite

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



Joined: 30 Jan 2013
Posts: 2

View user's profile Send private message

EEPROM Preload and Overwrite
PostPosted: Wed Jan 30, 2013 8:51 am     Reply with quote

Greetings,

I have a quick question regarding the internal EEPROM operation on a PIC18F46K20.

I plan to preload EEPROM values using the #rom directive. I would then like to overwrite some values at runtime using the write_eeprom() function.

Am I correct to assume that the updated values will be used on every power on condition? I only want the preloaded default values for the first run after programming.

Thanks for the help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 8:58 am     Reply with quote

Yes, of course.
Remember though if you reprogram the chip, you will be back to the 'default' values, unless you set your programmer to not overwrite/erase the EEPROM.

Best Wishes
picpocket



Joined: 30 Jan 2013
Posts: 2

View user's profile Send private message

PostPosted: Wed Jan 30, 2013 8:59 am     Reply with quote

Great! Thank you very much for the reply.
Wim



Joined: 10 Sep 2014
Posts: 2

View user's profile Send private message

PostPosted: Wed Sep 10, 2014 4:40 am     Reply with quote

I would like to do the same; preload and then overwrite EEPROM.

#rom directive works (CCS 5.025d). I can see correct values in the HEX. I can load the HEX to PIC16F1827 with Pickit 2 correctly.

But, when I include write_eeprom() and try to overwrite, I get an error. Commenting it out in code below results in working PIC.

What to do?
Thanks!
Wim

Code:
#include <16F1827.h>
#device ADC=16
#use delay(internal=1MHz)



// The 16F1827 physical EEPROM address starts at 0xF000.
#rom int8 0xF000 = {0}   
#rom int8 0xF001 = {0xAA}

void main()
{
  read_eeprom(1);
  write_eeprom(0, 0);  // COMMENTED OUT WILL WORK!
  while(TRUE)
  {
     delay_ms(250);
     // I toggle a heartbeat LED here. It works. Just left it out.
  }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Sep 10, 2014 5:01 am     Reply with quote

I'd suspect fuses.

You are not specifying any, so it may well be defaulting to having the EEPROM write protected.
Wim



Joined: 10 Sep 2014
Posts: 2

View user's profile Send private message

PostPosted: Thu Sep 11, 2014 12:26 am     Reply with quote

Thanks!

The weird thing is that when the write_eeprom() is in the while loop, I can just program the device without errors.

Any suggestions on what to try besides the fuses?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 11, 2014 1:18 am     Reply with quote

This test works in MPLAB simulator with vs. 5.025 and 5.026. (I did not
test the demo version). MPLAB vs. 8.92 displays the following:
Quote:
initial values = 55, aa
Final values = 00, 00

It is successfully erasing the eeprom. I did not try it in hardware. I can
do that if necessary.
Code:

#include <16F1827.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#rom int8 0xF000 = {0x55}    // Put non-zero data in both locations
#rom int8 0xF001 = {0xAA}

//===================================
void main()
{
printf("initial values = %x, %x \r", read_eeprom(0), read_eeprom(1));

// Zero the first two EEPROM locations.
write_eeprom(0, 0); 
write_eeprom(1, 0); 

printf("Final values = %x, %x \r", read_eeprom(0), read_eeprom(1));

while(TRUE);
}
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