MPLAB X IDE® Viewing and Setting Configuration Bits

Last modified by Microchip on 2024/06/24 06:30

Configuration bits are a collection of specialized bits that can only be modified at program time. Configuration bits are read during reset and enable or disable hardware features in the microcontroller. The features controlled by the configuration bits include but are not limited to, the clock source, Watchdog Timer, brown-out detection, and memory read protection. Configuration bits are not executable code. Essentially, they are fuses located in the program memory space.

How Configuration Bits Are Set

Each Microchip device has its own set of configuration bits. Individual device datasheets contain the definition for each of the bits. For example, find configuration bit information in the Special Features section of most PIC® MCU datasheets.

The setting for each configuration bit can be determined by directives written in the application software. The syntax for the configuration bit settings is available from the compiler or associated library manual. For example, the MPLAB® XC8 compiler manual contains information on setting configuration bits using #pragma, whereas the AVR® Libc manual contains information on setting fuses (avr/fuse.h) and lockbits (avr/lock.h) using macros.

This tutorial will show how to generate the proper configuration code without consulting the compiler manual for the proper syntax.

Back to top

How to Display the Configuration Bits Window

From the main menu, select Window > Target Memory Views > Configuration Bits. The Configuration Bits window will open in a tab in the Output area under the editor.

Open configuration bits window

Note: Read Device Memory read-target-project.png is required for AVR and SAM devices to ensure correct configuration bit values before editing. When device memory is read, the window text changes from red to black.

AVR8 Open Config Bits window

Back to top

How to Set Configuration Bits

In the Configuration Bits window, click on any value in the Options column and it will turn into a combo box that will allow you to select the value you desire. The example below shows the Watchdog Timer changed from enabled to disabled.

Configuration bits window

Back to top

How to Generate Initialization Code

Although you can read, change, and write device configuration bits using the Configuration Bits window, these settings will only apply to the current device. To ensure any device programmed with the application will have the correct setup of configuration bits, controls on the window can generate code to be placed in your application.

Note: The code generation feature is currently not available for SAM devices using the Arm® GCC compiler.

Click on the Generate Source Code to Output button.

GenerateConfigBits.png

The Integrated Development Environment (IDE) will automatically generate the code necessary to initialize all the configuration bits to the settings you specified in the window. This code may now be copied and pasted into one of your source files, or you may save it to its own file and add it to your project. To save the file, right-click anywhere in the Output window and select Save As from the popup menu.

ConfigBitsSaveAs.png

This code may optionally be inserted into the source file focused in the Editor. To insert the code, right click in the Configuration Bits window and select Insert Source Code in Editor from the popup menu. The Toolbar button will also insert the code.
ConfigBitsInsertSrc.png

Back to top