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

Write String to EEPROM?

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



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

Write String to EEPROM?
PostPosted: Thu Dec 28, 2006 11:00 am     Reply with quote

Can someone give me an example on how i would write a text string to eeprom?

I've been trying what's described below but it won't compile. I'm using the 18f4525

char result[6]="hello"

void main{
write_eeprom(0x00,&result);
result = read_eeprom(0);
printf("eeprom info:%x", result);
}

Thanks and Happy Holidays.
Joe
Ttelmah
Guest







PostPosted: Thu Dec 28, 2006 11:20 am     Reply with quote

write_eeprom, transfers just one byte. You need:
Code:

write_string(int8 address, int8 string[])
{
int8 ctr=0;

do{
   write_eeprom(address++, string[ctr]);
   }while (string[ctr++] != 0);

}

This writes the bytes from the string up to, and including the terminating null.
You would need a similar retrieval function to get the data back.

Best Wishes
Joseph88



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

PostPosted: Thu Dec 28, 2006 11:25 am     Reply with quote

Thanks for your reply. Would you need to do the same procedure to read back what you've written to eeprom?
Ttelmah
Guest







PostPosted: Thu Dec 28, 2006 4:11 pm     Reply with quote

Yes. Last line of my reply...
Joseph
Guest







PostPosted: Thu Jan 04, 2007 1:32 pm     Reply with quote

I'm trying to save some info into memory, then read them back to print them onto a LCD. The problem that i'm having is that the "hello" that is printed on the LCD has 4 additional gibberish characters added onto the end. Any help will be appreciated.

Code:

char lcdText[16]="hello";

void write_string(int8 address, int8 string[]) {
      int8 ctr=0;
      while (string[ctr]!=0){   
      write_eeprom(address++,string[ctr]);   
      ctr++;
   }
}

void read_string(int8 address, char lcdText) {
      int i =0;
    char string[8];
    for (i=0; i<=strlen(lcdText)-1; i++){
       string[i]=read_eeprom(address++);   
    }
printf(lcd_putc, "%s", string);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 04, 2007 1:38 pm     Reply with quote

You're not terminating the string when you read it from eeprom.
You've only got the text. You need to append a 0x00 byte at the end
of the text.
Guest








PostPosted: Thu Jan 04, 2007 1:53 pm     Reply with quote

Thanks PCM, that did the trick.
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