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

Preload Eeprom with Null-Terminating

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Preload Eeprom with Null-Terminating
PostPosted: Thu Apr 05, 2018 8:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 05, 2018 9:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 05, 2018 12:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 05, 2018 4:21 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 05, 2018 4:41 pm     Reply with quote

Yes, is true, at the end I get three zeros...

Thank you
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