View previous topic :: View next topic |
Author |
Message |
picpocket
Joined: 30 Jan 2013 Posts: 2
|
EEPROM Preload and Overwrite |
Posted: Wed Jan 30, 2013 8:51 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19365
|
|
Posted: Wed Jan 30, 2013 8:58 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
picpocket
Joined: 30 Jan 2013 Posts: 2
|
|
Posted: Wed Jan 30, 2013 8:59 am |
|
|
Great! Thank you very much for the reply. |
|
![](templates/subSilver/images/spacer.gif) |
Wim
Joined: 10 Sep 2014 Posts: 2
|
|
Posted: Wed Sep 10, 2014 4:40 am |
|
|
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.
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19365
|
|
Posted: Wed Sep 10, 2014 5:01 am |
|
|
I'd suspect fuses.
You are not specifying any, so it may well be defaulting to having the EEPROM write protected. |
|
![](templates/subSilver/images/spacer.gif) |
Wim
Joined: 10 Sep 2014 Posts: 2
|
|
Posted: Thu Sep 11, 2014 12:26 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 11, 2014 1:18 am |
|
|
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);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|