Home

Placing a Constant Variable or Function in an Absolute Flash Address

E-mail Print PDF
( 0 Votes )
Questions:
1. I would like to place a constant variable in an absolute address in Flash.  I will place information like version and serial number in this absolute address. How do I do this?
2. I would like to place a function in an absolute address in Flash.  How do I do this?

Answer:  You can place either a constant variable or a function in absolute address in flash using the #pragma abs_address directive.

For example, to place constant variables in absolute address 0x3FC0:
#pragma abs_address 0x3FC0
const BYTE Version = 0x01;  // This byte is placed in address 0x3FC0
const char SerialNumber[] = "1234567890";  // This string is placed from address 0x3FC1
#pragma end_abs_address

To place a function "MyFunction" at address 0x1000, the same approach may be used.
#pragma abs_address 0x1000
void MyFunction(void)
{
    // Function code here
}
#pragma end_abs_address
Comments (0)
Only registered users can write comments!