Data in ROM

The PIC-18 processors are based on two separate program and data spaces. Data space is RAM, and program space is ROM. This architecture causes problem to keep initialized data10 because it can only be stored in program space.

In order to provide access to initialized data, cpik adds a loader routine to startup code. This routine is automatically activated before the main() function and copies all initialized data from program space to data space11. As a consequence, initialized data is located in RAM during execution. This feature is necessary when the data can be modified, but is not desirable when the data is read-only because it wastes RAM space.

Since version 0.5.3 cpik offers several simple ways to use data located in program space (ROM). The ROM support presented here is fully implemented with macros and a couple of run-time routines. These macros are defined in the rom.h header. This support is experimental because it prepares a definitive implementation based on a __rom keyword. However, it is perfectly usable and very efficient from both time and memory points of view.



Footnotes

... data10
such as literals like "hello !".
... space11
The loader is not included if your program does not use statically initialized data.


Subsections
Alain Gibaud 2015-07-09