Frequently Asked Questions
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® MCU, 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.
Note that in the implementation of the above table, a function call is made when a table is accessed with a subscript that cannot be evaluated at compile time.