Download MPLAB XC8 C Compiler User's Guide

Transcript
How To’s
3.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 3.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 .pre extension.
3.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 Position Functions at an Address I Nominate?
How Do I Place Variables in Program Memory?
How Do I Stop the Compiler From Using Certain Memory Locations?
See, also, the following linked information in other sections.
• Why Are Some Objects Positioned Into Memory That I Reserved?
3.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 @ address
construct, see Section 5.5.4 “Absolute Variables”. This means that the address you
specify is used in preference to the variable’s symbol in generated code. Since you
nominate the address, you have full control over where objects are positioned. But, you
must also ensure that absolute variables do not overlap. Variables placed in the middle
of banks can cause havoc with the allocation of other variables and lead to “Can’t find
space” errors; see Section 3.7.6 “How Do I Fix a “Can’t find space...” Error?”. See
also, Section 5.5.2.2.4 “Changing the Default Auto Variable Allocation”, for information on moving auto variables; Section 5.5.2.1.3 “Changing the Default
Non-Auto Variable Allocation”, for moving non-auto variables; and
Section 5.5.3.2 “Changing the Default Allocation”, for moving program-space
variables.
3.4.3.2
HOW DO I POSITION FUNCTIONS AT AN ADDRESS I NOMINATE?
The easiest way to do this is to make the functions absolute by using the @ address
construct, see Section 5.8.4 “Changing the Default Function Allocation”. This
means that the address you specify is used in preference to the function’s symbol in
generated code. Since you nominate the address, you have full control over where
functions are positioned, but must also ensure that absolute functions do not overlap.
Functions placed in the middle of pages can cause havoc with the allocation of other
functions and lead to "Can’t find space" errors, see Section 3.7.6 “How Do I Fix a
“Can’t find space...” Error?”.
 2012-2013 Microchip Technology Inc.
DS50002053D-page 51