View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
I am lost the embedding data EEPROM |
Posted: Wed Nov 11, 2009 2:30 pm |
|
|
Hi, I am use the #ROM preprocessor directive to embedding data EEPROM during programming the pic18f452, but when I want to to read this data, it simply altered or lost, there is something I am forgetting?
Code: | #rom int8 0xf00001 = {"21"}
#rom int8 0xf0002D = {"OFF"}
#rom int8 0xf00039 = {"00:10:00"} |
But when I do the simulation using the proteus everything is OK |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 11, 2009 2:51 pm |
|
|
Post a very short, compilable test program that shows the problem.
Post your compiler version. |
|
|
Guest
|
|
Posted: Wed Nov 11, 2009 3:52 pm |
|
|
Hi PCM programmer, here is my code:
Code: | #include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7)// RS232 Estándar
int i;
#rom int8 0xf00001 = {"21"}
#rom int8 0xf0002D = {"OFF"}
#rom int8 0xf00039 = {"00:10:00"}
void main(){
char buffer [8];
for (i = 0 ; i<8 ; i++)
buffer[i] = read_eeprom(57+i);
printf("%s ",buffer);
while (true);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 11, 2009 3:58 pm |
|
|
What's a string ? Look at a FAQ:
http://www.macdonald.egate.net/CompSci/hstrings.html
He says:
Quote: |
In C, a string is stored as a null-terminated char array.
This means that after the last truly usable char there is
a null, hex 00, which is represented in C by '\0'. |
Look at your code:
Quote: |
#rom int8 0xf00039 = {"00:10:00"}
char buffer [8];
for (i = 0 ; i<8 ; i++)
buffer[i] = read_eeprom(57+i);
printf("%s ",buffer);
|
Your string buffer doesn't have room for the 0x00 at the end,
and you don't put it there. It's not a string. |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Fri Nov 13, 2009 8:04 am |
|
|
You're right |
|
|
|