View previous topic :: View next topic |
Author |
Message |
Joseph88
Joined: 14 Aug 2006 Posts: 17
|
Write String to EEPROM? |
Posted: Thu Dec 28, 2006 11:00 am |
|
|
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
|
|
Posted: Thu Dec 28, 2006 11:20 am |
|
|
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
|
|
Posted: Thu Dec 28, 2006 11:25 am |
|
|
Thanks for your reply. Would you need to do the same procedure to read back what you've written to eeprom? |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 28, 2006 4:11 pm |
|
|
Yes. Last line of my reply... |
|
|
Joseph Guest
|
|
Posted: Thu Jan 04, 2007 1:32 pm |
|
|
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
|
|
Posted: Thu Jan 04, 2007 1:38 pm |
|
|
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
|
|
Posted: Thu Jan 04, 2007 1:53 pm |
|
|
Thanks PCM, that did the trick. |
|
|
|