Configuration Bits for 16-bit PIC® MCUs

Configuration Bits - are a collection of binary data located in the flash program memory of a PIC® Microcontroller (MCU). Configuration bits are programmed into the PIC MCU with the application code. These bits are not executable code as their addresses are not accessible by the program counter. Configuration bits are derived from compiler directives placed into the code by you, the application developer.

Configuration bits are read by the MCU when exiting a reset and cannot be modified during run-time. Upon exiting reset the configuration bits are used to complete circuitry which enables or disables hardware features of the MCU.

The Special Features of MCU operations controlled by the configuration bits include:

  1. System Clocking
  2. Power Management
  3. Device Security
  4. Operating Characteristics

The configuration bits and settings vary across devices due to different feature sets. Check your datasheet for the specifics of the PIC® MCU configuration bits you are using.

This page describes what features are controlled by configuration bits and how to generate them in source code.

Location and Format

The configuration bits for the PIC24/dsPIC33 MCU family are combined into two 24-bit words called CONFIG1 and CONFIG2. The configuration words are located beyond the reach of the program counter in the upper half of the MCU's program memory space (Configuration Memory Space) starting at 0xF80000 as shown:

Configuration bits are generated by compiler directives inserted into the application's source code. When a PIC® MCU project is built, the configuration bit settings are embedded in the HEX output file. The configuration bits are programmed into the PIC® along with the application program.

The following CONFIG1 & CONFIG2 registers are defined for the PIC24FJ128GA010 MCU:

CONFIG1 (Upper Third)

U-1 U-1 U-1 U-1 U-1 U-1 U-1 U-1
bit 23 bit 16

CONFIG1 (Middle Third)

r-0 R/PO-1 R/PO-1 R/PO-1 R/PO-1 R/PO-1 U-1 R/PO-1
bit 15 bit 8

CONFIG1 (Lower Third)

R/PO-1 R/PO-1 U-1 R/PO-1 R/PO-1 R/PO-1 R/PO-1 R/PO-1
bit 7 bit 0

CONFIG2 (Upper Third)

U-1 U-1 U-1 U-1 U-1 U-1 U-1 U-1
bit 23 bit 16

CONFIG2 (Middle Third)

R/PO-1 U-1 U-1 U-1 U-1 R/PO-1 R/PO-1 R/PO-1
bit 15 bit 8

CONFIG2 (Lower Third)

R/PO-1 R/PO-1 R/PO-1 U-1 U-1 U-1 R/PO-1 R/PO-1
bit 7 bit 0

Detailed descriptions of the PIC24FJ128GA010 MCU's configurable hardware options are provided in the Special Features section of the device data sheet found here.

Generating Configuration Bits in C Code

Microchip's MPLAB® XC16 C compiler accepts #pragma directives to set the configuration bits.

The syntax for generating configuration bits:

Sample of Setting Configuration Bits in C

When setting configuration bits using C it is not necessary to know the word which contains the bit being set.

All that is needed is the configuration bit name and the desired value.

Unspecified configuration options are programmed with MCU defaults (per the data sheet).

The header files for each PIC24/dsPIC33 device contain the CONFIG_BIT_NAMEs and CONFIG_VALUEs.
A full list of the settings for all 16-bit MCUs/DSCs can be found in XC16's documentation folder (C:\Program Files\Microchip\xc16\<version>\docs) in the file config_index.html

Once written, the compiler directives must be added to the PIC® MCU project in one of three ways:

  1. In a 'stand alone' C source file which is added to the project.
  2. In a header (.h) file placed in the project with an #include statement.
  3. Placed directly inside one of the source code files already in the project.

Developers using the XC16 compiler can refer to the Configuration Bits section of the MPLAB® X IDE Tutorial to see shortcuts for generating the code needed to set the configuration bits.

© 2018 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.