5.2.7 5-byte Config Bits Registers with Block Write Protect

Also includes Clock Switching, Fail Safe Enable, and DAC buffer settings

5.2.7.1 Introduction

The Configuration settings allow the user to select the oscillators, reset sources, individual memory area protection from the several options available on the device. They are latched in place at the power-up and also after programming of the device.

5.2.7.2 Supported Device Families

PIC16F171xx PIC16F181xx PIC16(L)F191xx PIC16(L)F184xx PIC16(L)F153xx

5.2.7.3 Required Header Files:

#include "mcc_generated_files/system/config_bits.h"

5.2.7.4 Module Documentation

5.2.7.4.1 CONFIGBITS Driver

This is the generated header file for the Configuration bits driver.

Module description

This is the generated header file for the Configuration bits driver.

Version: Driver Version 2.0.1
Note: The below code is an example code only and the value for each config bit setting will vary depending on the setup on the Configuration Bits module.

//CONFIG1
#pragma config FEXTOSC = ECH    // External Oscillator Selection bits->EC (external clock) above 16 MHz
#pragma config RSTOSC = EXTOSC    // Reset Oscillator Selection bits->EXTOSC operating per FEXTOSC bits
#pragma config CLKOUTEN = OFF    // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2
#pragma config CSWEN = ON    // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config VDDAR = HI    // VDD Range Analog Calibration Selection bit->Internal analog systems are calibrated for operation between VDD = 2.3 - 5.5V
#pragma config FCMEN = ON    // Fail-Safe Clock Monitor Enable bit->Fail-Safe Clock Monitor enabled

//CONFIG2
#pragma config MCLRE = EXTMCLR    // Master Clear Enable bit->If LVP = 0, MCLR pin is MCLR; If LVP = 1, RA3 pin function is MCLR
#pragma config PWRTS = PWRT_OFF    // Power-up Timer Selection bits->PWRT is disabled
#pragma config LPBOREN = OFF    // Low-Power BOR Enable bit->ULPBOR disabled
#pragma config BOREN = ON    // Brown-out Reset Enable bits->Brown-out Reset enabled, SBOREN bit is ignored
#pragma config DACAUTOEN = OFF    // DAC Buffer Automatic Range Select Enable bit->DAC Buffer reference range is determined by the REFRNG bit
#pragma config BORV = LO    // Brown-out Reset Voltage Selection bit->Brown-out Reset Voltage (VBOR) set to 1.9V
#pragma config ZCD = OFF    // ZCD Disable bit->ZCD module is disabled; ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
#pragma config PPS1WAY = ON    // PPSLOCKED One-Way Set Enable bit->The PPSLOCKED bit can be cleared and set only once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented
#pragma config STVREN = ON    // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset
#pragma config DEBUG = OFF    // Background Debugger->Background Debugger disabled

//CONFIG3
#pragma config WDTCPS = WDTCPS_31    // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF    // WDT Operating Mode bits->WDT Disabled, SEN is ignored
#pragma config WDTCWS = WDTCWS_7    // WDT Window Select bits->window always open (100%); software control; keyed access not required
#pragma config WDTCCS = SC    // WDT Input Clock Select bits->Software Control

//CONFIG4
#pragma config BBSIZE = BB512    // Boot Block Size Selection bits->512 words boot block size
#pragma config BBEN = OFF    // Boot Block Enable bit->Boot Block disabled
#pragma config SAFEN = OFF    // Storage Area Flash (SAF) Enable bit->SAF disabled
#pragma config WRTAPP = OFF    // Application Block Write Protection bit->Application Block is NOT write protected
#pragma config WRTB = OFF    // Boot Block Write Protection bit->Boot Block is NOT write protected
#pragma config WRTC = OFF    // Configuration Register Write Protection bit->Configuration Register is NOT write protected
#pragma config WRTD = OFF    // Data EEPROM Write Protection bit->Data EEPROM is NOT write protected
#pragma config WRTSAF = OFF    // Storage Area Flash (SAF) Write Protection bit->SAF is NOT write protected
#pragma config LVP = ON    // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/Vpp pin function is MCLR. MCLRE Configuration bit is ignored

//CONFIG5
#pragma config CP = OFF    // Program Flash Memory Code Protection bit->Program Flash Memory code protection is disabled
#pragma config CPD = OFF    // Data EEPROM Code Protection bit->Data EEPROM code protection is disabled
Example Code
Note: The code will vary based on the configuration of the user.
#pragma config FEXTOSC = ECH    // External Oscillator Selection bits->EC above 8MHz; PFM set to high power
#pragma config RSTOSC = EXT1X    // Reset Oscillator Selection bits->EXTOSC operating per FEXTOSC bits
#pragma config CLKOUTEN = OFF    // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2
#pragma config CSWEN = ON    // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON    // Fail-Safe Clock Monitor Enable bit->FSCM timer enabled

#pragma config MCLRE = ON    // Master Clear Enable bit->MCLR pin is Master Clear function
#pragma config PWRTS = OFF    // Power-up Timer Selection bits->PWRT disable
#pragma config LPBOREN = OFF    // Low-Power BOR Enable bit->ULPBOR disabled
#pragma config BOREN = ON    // Brown-out Reset Enable bits->Brown-out Reset Enabled, SBOREN bit is ignored
#pragma config BORV = LO    // Brown-out Reset Voltage Selection bit->Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices
#pragma config ZCD = OFF    // ZCD Disable bit->Zero-cross detect circuit is disabled at POR.
#pragma config PPS1WAY = ON    // PPSLOCKED One-Way Set Enable bit->The PPSLOCK bit can be cleared and set only once in software
#pragma config STVREN = ON    // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset

#pragma config WDTCPS = WDTCPS_31    // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF    // WDT Operating Mode bits->WDT Disabled, SWDTEN is ignored
#pragma config WDTCWS = WDTCWS_7    // WDT Window Select bits->window always open (100%); software control; keyed access not required
#pragma config WDTCCS = SC    // WDT Input Clock Select bits->Software Control

#pragma config BBSIZE = 512    // Boot Block Size Selection bits->Boot Block Size (Words) 512
#pragma config BBEN = OFF    // Boot Block Enable bit->Boot Block disabled
#pragma config SAFEN = OFF    // Storage Area Flash (SAF) Enable bit->SAF disabled
#pragma config WRTAPP = OFF    // Application Block Write Protection bit->Application Block NOT write-protected
#pragma config WRTB = OFF    // Boot Block Write Protection bit->Boot Block NOT write-protected
#pragma config WRTC = OFF    // Configuration Register Write Protection bit->Configuration Words NOT write-protected
#pragma config WRTD = OFF    // Data EEPROM Write Protection bit->Data EEPROM NOT write-protected
#pragma config WRTSAF = OFF    // Storage Area Flash (SAF) Write Protection bit->SAF NOT write-protected
#pragma config LVP = ON    // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/Vpp pin function is MCLR.

#pragma config CP = OFF    // Program Flash Memory Code Protection bit->UserNVM code protection disabled

5.2.7.4.2 System Driver

This is the generated header file for the System driver.

Module description

This is the generated header file for the System driver.

Version: Driver Version 2.0.2
Functions
  • void SYSTEM_Initialize (void)

    Initializes the system module. This routine is called only once during system initialization, before calling other APIs.

Function Documentation

SYSTEM_Initialize()

void SYSTEM_Initialize (void )

Initializes the system module. This routine is called only once during system initialization, before calling other APIs.

Section: Included Files

Parameters:
None.
Returns:

None.

Section: Included FilesSection: Driver APIs

5.2.7.5 File Documentation

5.2.7.5.1 source/system/config_bits.h File Reference

#include "../system/clock.h"

Detailed Description

Configuration Bits Generated Driver Header File

5.2.7.5.2 source/system/src/config_bits.c File Reference

This is the generated Device Configuration bits file.

Detailed Description

This is the generated Device Configuration bits file.

Configuration Bits Generated Driver Source File

Version: Driver Version 2.0.1

5.2.7.5.3 source/system/src/system.c File Reference

This file contains the API implementation for the System driver.

#include "../system.h"

Functions

  • void SYSTEM_Initialize (void)

    Initializes the system module. This routine is called only once during system initialization, before calling other APIs.

Detailed Description

This file contains the API implementation for the System driver.

System Driver Source File

Version: Driver Version 2.0.2

5.2.7.5.4 source/system/system.h File Reference

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "config_bits.h"
#include "../system/clock.h"
#include "../system/pins.h"
#include "../system/interrupt.h"

Functions

  • void SYSTEM_Initialize (void)

    Initializes the system module. This routine is called only once during system initialization, before calling other APIs.

Detailed Description

System Driver Header File