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

How to read eeprom data.

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



Joined: 04 Jan 2014
Posts: 2

View user's profile Send private message

How to read eeprom data.
PostPosted: Fri Sep 25, 2015 3:02 pm     Reply with quote

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:
Code:
writing is done!
5



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!)
Code:
?


please someone help me..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 25, 2015 4:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 26, 2015 1:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 26, 2015 6:44 am     Reply with quote

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!
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