|
|
View previous topic :: View next topic |
Author |
Message |
albhee
Joined: 04 Jan 2014 Posts: 2
|
How to read eeprom data. |
Posted: Fri Sep 25, 2015 3:02 pm |
|
|
Hi,
My CCS C compiler version is 5.008
My MCU : PIC18f2520
I am trying to save a data in the eeprom. After successfully saving the data i reprogram the chip this time for only read that data, but i am having any data only '?'. Please someone help me.
I attached the code i tried for both condition and terminal output too.
For reading and writing:
Code: | #include <18f2520.h>
#device adc=10
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(crystal = 20MHz)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7, parity=N, stop=1)
#include <string.h>
void main(){
write_eeprom(0x0,0x35); // 0x35 = '5'
delay_ms(500);
printf("writing is done!\n");
unsigned int8 value=read_eeprom(0x0);
delay_ms(500);
putc(value);
while(TRUE){
}
} |
This code worked perfectly..
Result is:
But,
when i tried this code:
Code: | void main(){
// write_eeprom(0x0,0x35);
// delay_ms(500);
// printf("writing is done!\n");
unsigned int8 value=read_eeprom(0x0);
delay_ms(500);
putc(value);
while(TRUE){
}
}
|
Now i am getting: (just a question mark!)
please someone help me.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 25, 2015 4:34 pm |
|
|
Do you have your programmer (Pickit 3, ICD3, CCS ICDU-64, etc.) set
to preserve eeprom ? Probably not. Your programmer is probably
erasing the eeprom when you program your PIC with the 2nd program.
Look at the settings window for your programmer. It will have a tickbox
for "Preserve eeprom on program" (which means don't erase it during
programming). Select that tickbox.
If you still have problems, then post the name of your programmer
(Pickit 2, Pickit 3, ICDU-64, or ? ). |
|
|
albhee
Joined: 04 Jan 2014 Posts: 2
|
|
Posted: Sat Sep 26, 2015 1:59 am |
|
|
Thank you so much, PCM programmer..
i am using PICKit2. you are right, i was erasing eeprom every time i programmed the chip. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat Sep 26, 2015 6:44 am |
|
|
Hi,
Also, 'inline' variable declarations are generally not allowed in 'C'. You can often get away with it in CCS 'C', but it's considered bad form. Declare all variables at the top of your routines. _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
|
|
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
|