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

preseting eeprom

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



Joined: 27 Mar 2005
Posts: 30

View user's profile Send private message Visit poster's website

preseting eeprom
PostPosted: Tue Mar 29, 2005 7:33 am     Reply with quote

Is there a way to preprogram a memory location at the time of programming?
Ttelmah
Guest







PostPosted: Tue Mar 29, 2005 8:44 am     Reply with quote

Yes.
#ROM
You need to look in the programming spec for the particular chip family involved to find where the EEPROM 'appears', as far as the programmer is concerned, but for the 18F family, which has it at 0xF00000, you can put a block of data into the EEPROM, with:
Code:

#ROM 0xF00000 = { 0x00AA,
   0x3689,0x00E0,
   0x3688,0x00C0
}

This writes 16bit values. If you want to address the ROM as bytes, you can add 'int8' to the declaration.
On the 16 chips, the ROM defaults to 8bit mapping.

Best Wishes
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 29, 2005 6:26 pm     Reply with quote

I do it all the time to load default values. Here's the relevant code for a 16F88. Note that the EEPROM starts at location 0x2100, so I have to add that offset to each location. (It seems to be the same for the 16F family, but don't quote me.) I don't know why CCS didn't automatically put the offset for each device into the #ROM command, but I'm sure that there's a good reason.

For more details, consult the manual for #ROM.

Code:

#ROM 0x2100 = { 0x00, 0x00 }
#ROM 0x2108 = { 0x1D }  //ID number
#ROM 0x2110 = { 0x01 }  //delay between fixes
#ROM 0x2118 = { 0x01 }  //always get a fix
#ROM 0x2120 = { 0x00 }  //fix offset
#ROM 0x2128 = { 0x00 }  //VHF_START_TIME
#ROM 0x2130 = { 0x00 }  //VHF_STOP_TIME
#ROM 0x2138 = { 0x19 }  //GPS_TRANSMIT_TIME
#ROM 0x2140 = { 0xB0 }  //PULSE_RATE
#ROM 0x2148 = { 0xB1 }  //MORT_PULSE_RATE
#ROM 0x2150 = { 0x00 }  //TRACK_MOVEMENT
#ROM 0x2158 = { 0x01 }  //USE_PTT
#ROM 0x2160 = { 0x00 }  //USE_SW

_________________
In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;)
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 29, 2005 6:58 pm     Reply with quote

theMagni wrote:
I do it all the time to load default values. Here's the relevant code for a 16F88. Note that the EEPROM starts at location 0x2100, so I have to add that offset to each location. (It seems to be the same for the 16F family, but don't quote me.) I don't know why CCS didn't automatically put the offset for each device into the #ROM command, but I'm sure that there's a good reason.

For more details, consult the manual for #ROM.

Code:

#ROM 0x2100 = { 0x00, 0x00 }
#ROM 0x2108 = { 0x1D }  //ID number
#ROM 0x2110 = { 0x01 }  //delay between fixes
#ROM 0x2118 = { 0x01 }  //always get a fix
#ROM 0x2120 = { 0x00 }  //fix offset
#ROM 0x2128 = { 0x00 }  //VHF_START_TIME
#ROM 0x2130 = { 0x00 }  //VHF_STOP_TIME
#ROM 0x2138 = { 0x19 }  //GPS_TRANSMIT_TIME
#ROM 0x2140 = { 0xB0 }  //PULSE_RATE
#ROM 0x2148 = { 0xB1 }  //MORT_PULSE_RATE
#ROM 0x2150 = { 0x00 }  //TRACK_MOVEMENT
#ROM 0x2158 = { 0x01 }  //USE_PTT
#ROM 0x2160 = { 0x00 }  //USE_SW


You can use the #ROM directive to store data in the flash area too, can't you? Wouldn't this be a good reason not to add an offset. Besides, it would be one more thing that could change between chips and one more place to introduce and error!
Ttelmah
Guest







PostPosted: Wed Mar 30, 2005 2:52 am     Reply with quote

Yes. The #ROM directive is important for doing other things in the program memory, so a 'built in' offset would be a pain.
However I'd suggest something like this as a good way of being 'user friendy' for the EEPROM.
Code:

#if defined (__PCH__)
#define EE_BASE (0xF00000)
#else
#define EE_BASE (0x2100)
#endif

#define EE_BYTE(x,y) #ROM int8 EE_BASE+x = { y }

Then to put '4' into the tenth EEPROM address (remembering they start at '0'), would just need:

EE_BYTE(9,4)

The nice thing about this, is it automatically handles the fact that the 18 chips store 16bit values, and the 16 chips store 8bit values, addressing both the same way, and allowing the code to be portble between the families. :-)

Best Wishes
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