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 support@ccsinfo.com

Poniter to const, is there a work around?

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








Poniter to const, is there a work around?
PostPosted: Tue Jul 26, 2005 7:12 pm     Reply with quote

Hi,

I'm attemping to use the PIC18 and have calibrations in ROM and want to access them via a pointer in memory.

Thanks for your help
valemike
Guest







PostPosted: Tue Jul 26, 2005 8:50 pm     Reply with quote

Look at this FAQ:

http://www.ccsinfo.com/faq/?19

Quote:

How can a constant data table be placed in ROM?

The compiler has support for placing any data structure into the device ROM as a constant read-only element. Since the ROM and RAM data paths are separate in the PIC, there are restrictions on how the data is accessed. For example, to place a 10 element BYTE array in ROM use:


BYTE CONST TABLE [10]= {9,8,7,6,5,4,3,2,1,0};

and to access the table use:


x = TABLE [i];
OR
x = TABLE [5];

BUT NOT


ptr = &TABLE [i];

In this case, a pointer to the table cannot be constructed.

Similar constructs using CONST may be used with any data type including structures, longs and floats.
Ttelmah
Guest







PostPosted: Wed Jul 27, 2005 2:22 am     Reply with quote

There are however 'semi workrounds', depending on the chip involved. The simplest, is to not use the const declaration, but instead use the #ROM declaration, and put the block of data at a fixed location in ROM memory, that you save and control. Perhaps the last 256 bytes in a typical system not using ICD. The contents of this block can then be accessed using 'read_program_eeprom' (provided the chip is a 'flash' part, offering this ability).
The alternative, is that the 'label_address' function will return the address in ROM, where a constant is stored, and again this can be used with read_program_eeprom to access the data. This however carries a 'caveat', that normally the data is stored with a 'retrieval header', which contains the code to allow it to be accessed, so the real data is a few bytes latter in the memory.
Chips without read_program_eeprom, cannot really be accessed except by the array method, because on these, the locations do not actually contain the required data, but 'retlw' instructions setup to return the value.

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