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

Reserving a fixed memory location for serial numbering.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
h.a.j.molenaar



Joined: 04 May 2005
Posts: 9

View user's profile Send private message

Reserving a fixed memory location for serial numbering.
PostPosted: Wed May 04, 2005 8:40 am     Reply with quote

Hi all. I want to use a serial number which must be read by the firmware itself. My programmer (BeeProg) can insert an incremental number in the program memory.

I want to do like this (PIC12F683).
unsigned long int const value = 0x0000;

I want this on a fixed memory location, preferably at the end of the map.
This is at 07FD.

How do I do this or is there a more better way?

Thanks, Hugo
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed May 04, 2005 9:25 am     Reply with quote

From the manual:

Quote:

#ROM


Syntax:
#rom address = {list};



Elements:
address is a ROM word address, list is a list of words separated by commas



Purpose:
Allows the insertion of data into the .HEX file. In particular, this may be used to program the '84 data EEPROM, as shown in the following example.



Note that this directive does not prevent the ROM area from being used. See #ORG to reserve ROM.



Examples:
#rom 0x2100={1,2,3,4,5,6,7,8}



Example Files:
None



Also See:
#org



Quote:

#ORG


Syntax:
#org start, end

or

#org segment

or

#org start, end {}

or

#org start, end auto=0

#ORG start,end DEFAULT

or

#ORG DEFAULT



Elements:
start is the first ROM location (word address) to use, end is the last ROM location, segment is the start ROM location from a previous #org



Purpose:
This directive will fix the following function or constant declaration into a specific ROM area. End may be omitted if a segment was previously defined if you only want to add another function to the segment.



Follow the ORG with a {} to only reserve the area with nothing inserted by the compiler.



The RAM for a ORG'ed function may be reset to low memory so the local variables and scratch variables are placed in low memory. This should only be used if the ORG'ed function will not return to the caller. The RAM used will overlap the RAM of the main program. Add a AUTO=0 at the end of the #ORG line.



If the keyword DEFAULT is used then this address range is used for all functions user and compiler generated from this point in the file until a #ORG DEFAULT is encountered (no address range). If a compiler function is called from the generated code while DEFAULT is in effect the compiler generates a new version of the function within the specified address range.



Examples:
#ORG 0x1E00, 0x1FFF

MyFunc() {

//This function located at 1E00

}



#ORG 0x1E00

Anotherfunc(){

// This will be somewhere 1E00-1F00

}



#ORG 0x800, 0x820 {}

//Nothing will be at 800-820



#ORG 0x1C00, 0x1C0F

CHAR CONST ID[10}= {"123456789"};

//This ID will be at 1C00

//Note some extra code will

//proceed the 123456789



#ORG 0x1F00, 0x1FF0

Void loader (){

.

.

.

}



Example Files:
loader.c



Also See:
#ROM

Ttelmah
Guest







PostPosted: Wed May 04, 2005 10:17 am     Reply with quote

Another poster has already given you details of how to reserve a location, and write something at it.
Unfortunately, you cannot access this like a const variable though. The problem is that when you declare a const variable, the compiler actually inserts a 'header', which then allows the data to be read, in front of the data. A const variable uses significantly more memory, than the actual size of the value to be stored. the nature of this, depends on the chip involved (more latter...)

So you can declare a block of memory at a location, using #ROM, like:
#ROM 0x7FD = {12,34,56,78}

Four bytes will be stored at 0x7FD. However to access it, you will need to use the 'read_program_memory' function to read the data.
There are some 'caveats' though. On a 18chip, ROM stores 16bit values at each location. On smaller chips the size of each value is limited by the chip. The read function similarly only returns whatever data size actually exists at the location.

The big problem for you, is that the read function requires a chip that supports direct reading of the program memory using the registers for internal flash programming. Your chip does not support this. On chips without this ability, a 'const', is stored using the upper part of each instruction, combined with a 'RETLW' instruction. So when you declare a four byte constant, these values are not directly stored in the chip. Instead three instructions set the bank registers, then the offset of the required byte is added to the PC, to trigger a jump to the required return instruction, and the values are stored as a 'table' of RETLW instructions in the next few bytes. The instruction, then returns to the caller, with the required value. This means that you can only store byte values that contain the RETLW instruction. If a programmer changed one of these into another instruction, the code will fail...

So, though your programmer can insert an incremental number into program memory, this feature is not useable with the chip you have!. However there is one possibility. If your programmer can insert the value at the addresses for the internal EEPROM (0x2100 to 0x21FF), this is accessible by the read_program_eeprom instruction.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 04, 2005 11:45 am     Reply with quote

Quote:
for the internal EEPROM (0x2100 to 0x21FF), this is accessible by
the read_program_eeprom instruction.

You mean the read_eeprom() function.
Ttelmah
Guest







PostPosted: Wed May 04, 2005 3:15 pm     Reply with quote

Yes.
Slip of the keyboard.

Best Wishes
h.a.j.molenaar



Joined: 04 May 2005
Posts: 9

View user's profile Send private message

PostPosted: Sun May 08, 2005 11:44 pm     Reply with quote

I like to thank the contributors for their response.
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