View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
Preload Eeprom with Null-Terminating |
Posted: Thu Apr 05, 2018 8:39 am |
|
|
Hi,
I have a doubt, I need preload the eeprom of a Pic18FXXX with a string value but a NULL-Terminating, this definition is OK?
Code: | #ROM 0xF000EC = {"0054123456789\0"} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Apr 05, 2018 9:32 am |
|
|
Obvious answer is to try it, see what gets written to the EEPROM. I suspect as written it would write a ...9 then a slash then a zero . |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 05, 2018 12:30 pm |
|
|
The quoted string automatically puts a zero at the end. The "\0" adds
an additional zero at the end. Your posted code will put two zeros at
the end.
To see this, compile the following program using MPLAB vs. 8.92.
Then go to this menu: View / EEPROM
Code: | #include <18F46K22.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOPBADEN
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
#rom getenv("EEPROM_ADDRESS") = {"0054123456789\0"}
//======================================
void main()
{
while(TRUE);
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Apr 05, 2018 4:21 pm |
|
|
hmm, that's interesting... I compile the program and yes, two zeros on the end.
curious as to why, I went to the manual
from the manual...
address is a ROM word address, list is a list of words separated by commas
NO mention that 'strings' can be in the list...hmm.
I'd have thought everything between the double quotes would have been treated as string characters, 0x39 for the "9" and the "/" would be a string as well, not the 'command code' for a null. The 2nd " would be the 'command' to say 'end of string, and the compilerwould add the null terminator. |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Thu Apr 05, 2018 4:41 pm |
|
|
Yes, is true, at the end I get three zeros...
Thank you |
|
|
|