![](https://csdnimg.cn/release/download_crawler_static/73453970/bg14.jpg)
MPLAB
®
XC8 C Compiler User’s Guide for PIC
®
MCU
DS50002737A-page 20 2012-2018 Microchip Technology Inc.
2.4.2.5 HOW DO I FIND THE NAMES USED TO REPRESENT SFRS AND BITS?
Special function registers, and the bits within them, are accessed via special variables
that map over the register (see Section 2.4.2.4 “How Do I Access SFRs?”). However,
the names of these variables sometimes differ from those indicated in the data sheet
for the device you are using.
If required, you can examine the <xc.h> header file to find the device-specific header
file that is relevant for your device. This file will define the variables that allow access
to these special variables. However, an easier way to find these variable names is to
look in any of the preprocessed files left behind from a previous compilation. Provided
the corresponding source file included <xc.h>, the preprocessed file will show the
definitions for all the SFR variables and bits for your target device.
If you are compiling under MPLAB X IDE, the preprocessed file(s) are left under the
build/default/production directory of your project for regular builds, or under
build/default/debug for debug builds. They are typically left in the source file
directory if you are compiling on the command line. These files have a .i extension.
2.4.3 Memory Allocation
Here are questions relating to how your source code affects memory allocation.
• How Do I Position Variables at an Address I Nominate?
• How Do I Place a Variable Into a Unique Section?
• How Do I Position a Variable Into an Address Range?
• How Do I Position Functions at an Address I Nominate?
• How Do I Place Variables in Program Memory?
• How Do I Place a Function Into a Unique Section?
• How Do I Position a Function Into an Address Range?
• How Do I Place a Function Into a Unique Section?
See also the following linked information in other sections.
• Why Are Some Objects Positioned Into Memory That I Reserved?
• How Do I Use High-Endurance Flash for Data, Not Code?
2.4.3.1 HOW DO I POSITION VARIABLES AT AN ADDRESS I NOMINATE?
The easiest way to do this is to make the variable absolute by using the
__at(address) construct (see Section 4.5.4 “Absolute Variables”), but you might
consider also placing the variable in a unique section (see Section 4.15.3 “Changing
and Linking the Allocated Section”). Absolute variables use the address you nominate
in preference to the variable’s symbol in generated code.
2.4.3.2 HOW DO I PLACE A VARIABLE INTO A UNIQUE SECTION?
Use the __section() specifier to have the variable positioned in a new section
(psect). After this has been done, the section can be linked to the desired address by
using the -Wl driver option. See Section 4.15.3 “Changing and Linking the Allocated
Section” for examples of both these operations.
2.4.3.3 HOW DO I POSITION A VARIABLE INTO AN ADDRESS RANGE?
You need to move the variable into a unique psect (section), define a memory range,
and then place the new section in that range.
Use the __section() specifier to have the variable positioned in a new section. Use
the -Wl driver option to define a memory range and to place the new section in that
range. See Section 4.15.3 “Changing and Linking the Allocated Section” for examples
of all these operations.