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

Pointers to ROM data

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



Joined: 18 Nov 2013
Posts: 167

View user's profile Send private message

Pointers to ROM data
PostPosted: Thu Jul 09, 2026 10:48 am     Reply with quote

In the past when I tried to access data in ROM using a pointer it would fail. I have a new application I'm writing and would like to try that again. Perhaps I was doing something wrong.
Example:
Code:

const uint_8 band0_data[] = {
  0x00,   
  0x40,   
  0x2B,   
  0x5D, 
  0x00   
}

void read_data()
{
   uint_8 *ptr = band0_data;
   for int i=0; i < sizeof(band0_data); i++, ptr++ )
   {
      SetReg(*ptr);  <-- this didn't work
      SetReg(band0_data[i]);  <-- this works
   }

I'm using an 18LF1455 and PCH v5.124.
jeremiah



Joined: 20 Jul 2010
Posts: 1424

View user's profile Send private message

PostPosted: Thu Jul 09, 2026 11:24 am     Reply with quote

Try changing
Code:
 const uint_8 band0_data[] = { 


to

Code:
 rom uint_8 band0_data[] = { 


and change

Code:
uint_8 *ptr = band0_data;


to

Code:
rom uint_8 *ptr = band0_data;


Unless things have changed since I last checked long ago, you cannot make a pointer to a const declared table because it doesn't build it like a normal table. In the old days you had to use the 'rom' keyword instead of 'const'

Also uint_8 is not a standard type. Did you mean uint8_t perchance?
SeeCwriter



Joined: 18 Nov 2013
Posts: 167

View user's profile Send private message

PostPosted: Thu Jul 09, 2026 11:56 am     Reply with quote

Yes, that was a typo with uint8_t.

Thanks, I will give it a try.
Ttelmah



Joined: 11 Mar 2010
Posts: 20108

View user's profile Send private message

PostPosted: Thu Jul 09, 2026 12:47 pm     Reply with quote

There is also the question of 'what chip'?.
There are different 'tricks' to allow this on different chip families.

As has already been posted, rom supports pointers in general.
On PIC24/30/44, you could add #device PSV=TRUE near the start of
the code, and the pointers will then work directly to the const data
(this is a feature supported by most of these chips 'Program Space Visibility'
which allows a window to be created to the ROM in RAM).
The compiler does also have a feature 'PASS_STRINGS=IN_RAM', which would
allow string arrays to have pointers generated to them. If you changed your
data to be in the form of a char array, you could 'sneak' this to allow the
pointers to const to be used.
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