Finding the Names of Device Registers

The following tip reliably confirms the names you should use for special function registers in C code. This is useful since the C identifiers used to access registers might not always be identical to those shown in the datasheet.

Create a trivial test program which includes <xc.h>. For example, main.c:

Compile the program above on the command line for your device with a command such as:
xc8 --chip=18f4520 --pre main.c if you are using MPLAB® XC8.

If you are using MPLAB XC16 or XC32, the command might look like this:
xc32-gcc -mprocessor=32MX795F512L -E -o main.i main.c.

These commands use the --PRE or -E options to stop compilation after the preprocessing stage so that you will be able to examine the pre-processed output file (main.pre or main.i, respectively for this example). This output file will contain the definitions for all the device-specific special function registers and bits within those registers.

Using this technique means you do not need to find the relevant header files for your device and determine if conditional code is appropriate for your build. However, if you would like a list of all the files included, do the following:
For XC8 compile as above, but replace the --PRE with --DEP=list,sys,stop. For XC16 or XC32, replace -E with -MD. These options will create, for example, a main.dep or main.d dependency file which will list the full path of all the headers that were included in your source.

© 2023 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.