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 data sheet.

Create a trivial test program (for example main.c) such as the following, which includes <xc.h>.

Compile this on the command line for your device of interest and with a command such as:

xc8 --chip=18f4520 --pre main.c

if you are using MPLAB® XC8, or something similar to:

xc32-gcc -mprocessor=32MX795F512L -E -o main.i main.c

if you are using MPLAB XC16 or XC32.

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 which are 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 main.dep or main.d dependency file which will list the full path of all headers that were included into your source.

© 2017 Microchip Technology, Inc.
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.