Storing constant data in program memory
Revision as of 13:27, 4 February 2008
Your PIC has a relatively large amount of program memory (32 Kbytes) but relatively little data memory (1536 bytes). For some applications, we want to have lookup tables or calibration data stored on our PIC, but we don't want it hogging data memory. This project is to demonstrate how to write a program that stores constant data in program memory. Test your ability to do this by creating a look-up table for the sin function. This is a 1-d array with integer index corresponding to an angle (e.g., numbers 0 to 89 if the index is in degrees; angles in other quadrants can be determined by simple transformations). Depending on your choice of int8, int16, or float to represent the number, what angle resolution can you use for the index before you reach the limits of program memory?
See p. 43 of the PIC MCU C Compiler book.
Finally, give sample code for storing data in the EEPROM, too.
Your PIC has a relatively large amount of program memory (32 Kbytes) but relatively little data memory (1536 bytes). For some applications, we want to have lookup tables or calibration data stored on our PIC, but we don't want it hogging data memory. The CCS C Compiler provides a few different ways to use program memory for data. They are discussed below.
The CONST qualifier will place variables into program memory. If the keyword CONST is used before the identifier, the identifier is treated as a constant. These constants need to be initialized and cannot be changed at run-time.
The ROM qualifier puts data in program memory with 3 bytes per instruction space. The address used for ROM data is a true byte address not a physical address.
Another method that can be used to assign data to program memory is the #rom.
The compiler provides built in functions to place data in program memory.