What are Configuration Bits?
The PIC microcontroller’s configuration bits are a collection of special bits that can only be altered at program time. During an mcu reset, the configuration bits are “read” and based on each bit status a particular hardware feature of the mcu is either enabled or disabled. Some PIC microcontroller features controlled by the configuration bits include, but are not limited to, clock source, watchdog timer, brown-out detection and memory read protection

Configuration Bits of a PIC16F877a
Each PIC microcontroller of Microchip has its own set of configuration bits depending on its available features. You can find information about an mcu’s configuration bits under the “Special Features” section of its datasheet.

Taking PIC16F877a as an example, the information of its configuration bit resides in section 14.1. Below is a snapshot of the datasheet’s section to give you an idea on what to expect:

Below is an image is the configuration bits (word), representing a feature status for each bit. And below the image is a table enumerating each configuration bit feature and the available setup for each feature:

Configuration BitsMicrocontroller Features
bit 13CP: Flash Program Memory Code Protection bit
1 = Code protection off
0 = All program memory code-protected
bit 12Unimplemented: Read as ‘1’
bit 11DEBUG: In-Circuit Debugger Mode bit
1 = In-Circuit Debugger disabled, RB6 and RB7 are GPIOs
0 = In-Circuit Debugger enabled, RB6 and RB7 are dedicated to the debugger
bit 10-9WRT1:WRT0 Flash Program Memory Write Enable bits
11 = Write protection off; all program memory may be written to by EECON control
10 = 0000h to 00FFh write-protected; 0100h to 1FFFh may be written to by EECON control
01 = 0000h to 07FFh write-protected; 0800h to 1FFFh may be written to by EECON control
00 = 0000h to 0FFFh write-protected; 1000h to 1FFFh may be written to by EECON control
bit 8CPD: Data EEPROM Memory Code Protection bit
1 = Data EEPROM code protection off
0 = Data EEPROM code protected
bit 7LVP: Low-Voltage (Single-Supply) In-circuit Serial Programming Enable bit
1 = RB3/PGM pin has PGM function; low-voltage programming enabled
0 = RB3 is digital I/O, HV on MCLR must be used for programming
bit 6BOREN: Brown-out Reset Enable bit
1 = BOR enabled
0 = BOR disabled
bit 5-4Unimplemented: Read as ‘1’
bit 3PWRTEN: Power-up Timer Enable bit
1 = PWRT disabled
0 = PWRT enabled
bit 2WDTEN: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 1-0FOSC1:FOSC0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator

Setup the Configuration Bits of a PIC16F877A a mcu using MPLABX IDE
From the main menu of MPLABX IDE go to [Window] > [PIC Memory Views] > [Configuration Bits]

A tab of the Configuration Bits window will open under the editor. In each configuration bit, click on any value in the Option column and a drop down menu will appear, allowing you to select the value.

After setting all the configuration bits to the desired value, generate the source code. To generate, click the Generate Source Code to Output button in the bottom.

Below is the generated source code of the configuration bits for the PIC16F877A mcu. Save it as a header file (*.h).

Integrating the PIC Microcontroller Configuration Bits to the project
Now that you have generated a header file containing your designed setup for the configuration bit, all you need to do is to include it in your project. For the generated code above, let’s say you saved it as ‘configuration.h’, all you need to do is add the following line to your main source file.

#include "configuration.h"

Lesson Take Away
Before beginning to write the program for your mcu, your first step should always be to set your configuration bits. This is where most of the novice programmer makes mistake because the configuration bits has a major impact on how your PIC Microcontroller behave. Taking time to learn how to setup you configuration bit will save you a lot of time from debugging.

Have a fun time programming!

Close Menu