Setting Configuration Bits Of Pic Microcontroller

Pic microcontroller are versatile and widely used devices in the field of embedded systems. In order to configure the microcontroller to meet specific requirements, it is essential to understand and modify the configuration bits. These configuration bits determine various operating modes of the microcontroller, such as clock source, watchdog timer, power-up timer, brown-out reset, low-voltage programming, data EEPROM memory code protection, flash program memory write, in-circuit debugger mode, and flash memory code protection. This guide will provide step-by-step instructions on how to set the configuration bits of the pic microcontrollersusing popular development environments like MikroC and MPLAB, ensuring optimal performance and functionality.

Configuration Bits Introduction

Some special bits that can only be modified at the time of programming are called configuration bits. Configuration bits specify some of the operating modes of microcontroller.  These bits are “read” during the reset and enable or disable the hardware features of microcontroller.

In PIC microcontrollers, configuration bits (often referred to as “configuration registers” or simply “config bits”) are special settings that determine various aspects of the microcontroller’s behavior and operation. These bits are typically set during the programming process and are stored in non-volatile memory (usually a part of the microcontroller’s flash memory) to configure fundamental parameters of the microcontroller.

Procedure for Setting the Configuration Bits Pic Microcontroller

MikroC users can edit these configuration bits by editing the project settings:
Project >> Edit Project

MPLAB users can edit these configuration bits by using Configuration Bits tool. Windows>> PIC Memory Views>> Configuration Bits

configuration bits of pic microcontroller

Settings will be open now. Change the MCU Name to P16F877A MCU Clock Frequency to 8.00 MHz:

Here are some common configuration bits found in PIC microcontrollers:

  1. Clock Source
  2. Watchdog Timer
  3. Power-up Timer
  4. Brown-out Reset
  5. Low-Voltage (Single-Supply)
  6. Data EEPROM Memory Code Protection
  7. Flash Program Memory Write
  8. In-Circuit Debugger Mode
  9. Flash Memory Code Protection

Oscillator

It produces a periodic and oscillating waveform (a sine wave or a square wave).  Oscillators mainly convert DC from a power supply to AC signal. Oscillator works at a certain frequency, which is usually determined by a quartz crystal. When a direct current is applied to crystal, it vibrates at a frequency that depends on its thickness, and on the manner in which it is cut from the original mineral rock.

For PIC16F877A, Oscillators have upto 4 different modes:

LPLow Frequency (Power) Crystal  
XTCrystal/Resonator  
HSHigh Speed Crystal/Resonator  
RCExternal Resistor/Capacitor  

The LPXT, and HS clock modes require an external crystal or resonator to be connected to the microcontroller. The RC clock mode requires an external resistor and capacitor to set the oscillator frequency.Each mode is optimized for a different frequency range. Which mode to be select, it all depends upon the desired output configuration.

LP:

  • Selects the lowest gain setting for the internal inverter-amplifier.
  • Lowest current consumption of the three modes.
  • Designed to drive a 32.768 KHz crystal.

XT:

  • Selects the intermediate gain for the internal inverter-amplifier.
  • Typically selected for crystals in the range of 4 MHz or lower.

HS:

  • Selects the highest gain setting for the internal inverter-amplifier.
  • Highest current mode.
  • Typically used with crystals above the 4 MHz range.

Operation

If we select the desired frequency for example 8MHz, then Oscillator must be HS.The crystal is connected to the OSC1 and OSC2 pins of microcontroller. It will also require capacitors on each pin in the range of 15pf-30pf.

Watchdog Timer

We may encounter a situation where the microcontroller is not working properly. In such cases, we usually reset the microcontroller using the reset button. However, relying on the reset button as a solution every time is not ideal. To address this issue, we employ a watchdog timer.

A watchdog timer is an electronic timer integrated into microcontrollers that detects and rectifies the aforementioned problems. It functions as a simple counter that generates pulses to restart the microcontroller unit. The output of the watchdog timer is directly linked to the microcontroller’s reset signal. Essentially, it is a continuously running counter where our program needs to write zero each time it executes correctly. If the program gets stuck and fails to write zero, the counter will reach its maximum value and trigger the watchdog timer to reset the microcontroller.

Operation

Watchdog timer (WDT), when enabled, the processor automatically resets.

  • 1=Enable WDT
  • 0=Disable WDT

Power-Up Timer

When a reset occurs, the quick startup of Microcontroller again can cause problems. To avoid such conditions, a fixed start up delay of 72 ms is provided by this timer. It delays the PIC MCU until the operating voltage VDD rises to its full value. So, this process ensures that the supply voltage is stable before the clock starts up.

Operation

Power-up Timer (PWT), when enabled, creates delay when the device will be in Reset state.

  • 1 = Disable PWT
  • 0=Enable PWT

Brown-out Reset

When a drop in voltage comes or the voltage becomes less than threshold voltage, RAM memory may get corrupted and the device will not run properly, this condition is called Brown out.

Operation

Brown-out Reset (BOR), when enabled, resets the device if the supply voltage VDD drops below VBOR for time longer than TBOR. Once this situation occurs, the device will remain in Brown-out reset until VDD rises above VBOR.

  • VBOR    about 4V
  • TBOR     about 100 µS
  • 1=Enable BOR
  • 0=Disable BOR

Low-Voltage (Single-Supply)

These microcontrollers can be serially programmed. This allows customers to program the microcontroller just before shipping the product. When using ICSP (In-Circuit Serial Programming), it must be supplied at 4.5V to 5.5V. (Usually Higher voltages=8V)

The LVP (low voltage programming) bit of the configuration enables low voltage ICSP programming. It will allow microcontroller to program though ICSP by using VDD source within the operation voltage range. So in short we can say that VDD does not have to bring to high voltage.

Operation

In this mode, the RB3/PGM pin is dedicated to the programming function.During programming, VDD is applied to the MCLR pin. To enter Programming mode, VDD must be applied to the RB3/PGM provided the LVP bit is set. By default from the factory the LVP bit is set to 1. If Low-Voltage Programming mode is not used, the LVP bit can be programmed to a ‘0’

  • 1= Enabled LVP
  • 0= Disabled LVP

Data EEPROM Memory Code Protection

PIC16F877A has an internal EEPROM. Two bits, CPD and WRTD, protect the entire data EEPROM. External reads and writes to the data EEPROM are controlled by CPD. The CPD Configuration Bit protects this region of memory against read and external write operations (such as In-circuit Serial Programming).

Operation

  • 1 = Data EEPROM code protection off         (Disable)
  • 0 = Data EEPROM code-protected               (Enable)

Flash Program Memory Write

These bits enable writing in the flash memory by the use of EECON. We can write data directly into the Flash memory by the device firmware. Simply, we can say that the sectors of our choice can be selected for the recording of data or for the In-circuit Serial Programming.

In-Circuit Debugger Mode

Debugging process allows the execution and tracking the code. This process read variables and execution step-by-step. Pins RB6 and RB7 can be used as in-circuit debugger pins.

Operation

  • 1=In-Circuit Debugger Disabled
  • 0=In-Circuit Debugger Enabled (RB6 and RB7 are dedicated to the Debugger)

When enabled>>debug process
When disabled>>allows use as digital inputs and outputs

Flash Memory Code Protection

If the program is stored in the flash memory then this bit is responsible for enabling the code protection.

Operation

Once enabled, the Flash memory (program memory) will be copy and protected. It cannot be read then.

  • 1=Protection Code off                                                (CP Disabled)
  • 0=All Program memory code Protected                     (CP Enable)

These settings are stored in a configuration word or bytes, and programmers use these tools to configure the microcontroller before programming it. Properly configuring these bits is essential to ensure that the microcontroller operates as intended for a specific application.

Conclusion

In conclusion, understanding and modifying the configuration bits of PIC microcontrollers is crucial for achieving the desired functionality and performance in embedded systems. These configuration bits determine various operating modes of the microcontroller, such as clock source, watchdog timer, power-up timer, brown-out reset, low-voltage programming, data EEPROM memory code protection, flash program memory write, in-circuit debugger mode, and flash memory code protection. By following the step-by-step instructions provided in this guide, users can confidently configure the PIC microcontroller using popular development environments like MikroC and MPLAB, ensuring optimal performance and functionality for their projects. Proper configuration of these bits is essential for the successful implementation of microcontroller-based systems.

Related content:

5 thoughts on “Setting Configuration Bits Of Pic Microcontroller”

  1. Hi dear Bilal
    when I am at programming process , opening a project file I receive this massage form my PPP V3.
    invalid HEX file integer òxro` is not a valid value
    where to go to get this value ?
    Thankyou..

    Reply
  2. hi
    the problem of PPPV3 IS FOUND OUT OUT
    IT IS OK NOW.
    It was very easy only thing to take the file in memory registration .

    Reply
  3. I am using PIC16F877A well programmed for driving EBM001 gLCD & according to my tests with my scope I receive good outputs from my programmed get out put gets. True RMS 1.39 to 2.49 . Frequency 140Khz to 00 . I check the the drive with only one second setting the delay icon. Crystal driver is 8 MHz ,one sec is only used for clearing the display
    what I want to know do we need to use an amplifier IC for amplifying the data & clock pulses ?
    I am working on this in my all the spare times I have, If I find the solution be for I receive any help from any helper
    I write or inform you dears.

    Reply

Leave a Comment