3.2 Configuration Bits
The configuration bits of your device must always be set to appropriate values. It is unlikely your program will execute correctly, or at all, if these are not valid. You should consult your device data sheet to ensure that you understand the function of each configuration setting and the appropriate value that should be used.
You can use the MPLAB X IDE to assist in the creation of the code necessary to set the configuration bits, but any code it produces must be copied into a source file that is a part of your project.
CONFIG
directive, for
example:CONFIG "WDTE=OFF" // WDT Disabled; SWDTEN is ignored
As shown in the example code, you typically provide setting-value pairs to
these directives, setting each configuration bit to the desired state, but an entire
configuration word can also be programmed using one directive, if required. The
CONFIG
directive can also be used to set the device's IDLOC bits,
where relevant.
Note that the setting-value pairs in the example code are quoted. This is to ensure that
there can be no interaction between any predefined preprocessor macros (when the
preprocessor is enabled) and the CONFIG
directive data. It is
recommended that quotes always be used.
If you are not using the MPLAB X IDE, the configuration bit settings and values
associated with each device can be determined from an HTML guide. Open either the
pic18_chipinfo.html
guide for PIC18 devices or the
pic_chipinfo.html
guide for all other devices. These are located in
the docs
directory in the MPLAB XC8 C Compiler distribution that
contains your PIC Assembler. Click the link to your target device and the page will show
you the settings and values that are appropriate for your directives. Note that the
usage examples shown in these HTML guides demonstrate the #pragma
config
directive used with C code as well as the CONFIG
directive, for the PIC Assembler (shown above). Ensure you follow the “PIC-AS config
Usage” examples.