5.3.7 14-byte Config Bits Registers

5.3.7.1 Introduction

The MCC Melody Configuration Bits System Driver generates APIs to support device hardware setup on PIC18F-Q20 target MCUs.

The Configuration settings allow the user to select the oscillators, reset sources and memory 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.3.7.2 Supported Device Families

PIC18F-Q20 PIC18F-Q24

5.3.7.3 Required Header Files:


#include "mcc_generated_files/config_bits.h"

5.3.7.4 Sample Code

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->EC (external clock) above 8 MHz
#pragma config RSTOSC = EXTOSC     // Reset Oscillator Selection->EXTOSC operating per FEXTOSC bits (device manufacturing default)

//CONFIG2
#pragma config CLKOUTEN = OFF     // Clock out Enable bit->CLKOUT function is disabled
#pragma config PR1WAY = ON     // PRLOCKED One-Way Set Enable bit->PRLOCKED bit can be cleared and set only once
#pragma config BBEN = OFF     // Boot Block enable bit->User PFM code protection disabled
#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->Fail-Safe Clock Monitor enabled
#pragma config FCMENP = ON     // Fail-Safe Clock Monitor - Primary XTAL Enable bit->Fail-Safe Clock Monitor enabled; timer will flag FSCMP bit and OSFIF interrupt on EXTOSC failure.
#pragma config FCMENS = ON     // Fail-Safe Clock Monitor - Secondary XTAL Enable bit->Fail-Safe Clock Monitor enabled; timer will flag FSCMS bit and OSFIF interrupt on SOSC failure.

//CONFIG3
#pragma config MCLRE = EXTMCLR     // MCLR Enable bit->If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR 
#pragma config PWRTS = PWRT_OFF     // Power-up timer selection bits->PWRT is disabled
#pragma config MVECEN = OFF     // Multi-vector enable bit->Interrupt contoller does not use vector table to prioritze interrupts
#pragma config IVT1WAY = ON     // IVTLOCK bit One-way set enable bit->IVTLOCKED bit can be cleared and set only once
#pragma config LPBOREN = OFF     // Low Power BOR Enable bit->Low-Power BOR disabled
#pragma config BOREN = ON     // Brown-out Reset Enable bits->Brown-out Reset enabled , SBOREN bit is ignored

//CONFIG4
#pragma config BORV = VBOR_1P9     // Brown-out Reset Voltage Selection bits->Brown-out Reset Voltage (VBOR) set to 1.9V
#pragma config PPS1WAY = ON     // PPSLOCK bit One-Way Set Enable bit->PPSLOCKED bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
#pragma config STVREN = ON     // Stack Full/Underflow Reset Enable bit->Stack full/underflow will cause Reset
#pragma config LVP = ON     // Low Voltage Programming Enable bit->Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
#pragma config DEBUG = OFF     // Debug enable bit->Backround debugger disabled
#pragma config XINST = OFF     // Extended Instruction Set Enable bit->Extended Instruction Set and Indexed Addressing Mode disabled

//CONFIG5
#pragma config WDTCPS = WDTCPS_31     // WDT Period selection bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF     // WDT operating mode->WDT Disabled; SEN is ignored

//CONFIG6
#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 selector->Software Control (when WDTE != 0b00)

//CONFIG7
#pragma config VDDIO2MD = STANDARD_RANGE     // VDDIO2 supply mode bit->Standard Operating Range (VDDIO2 >= 1.62V)
#pragma config VDDIO3MD = STANDARD_RANGE     // VDDIO3 supply mode bit->Standard Operating Range (VDDIO3 >= 1.62V)

//CONFIG8
#pragma config BBSIZE = BBSIZE_16384     // Boot Block Size Selection bits->Boot Block size is 16384 words

//CONFIG9
#pragma config SAFSZ = SAFSZ_NONE     // SAF Block Size Selection bits->NONE

//CONFIG10
#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 registers are 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 WRTAPP = OFF     // Application Block Write Protection bit->Application Block is not write-protected

//CONFIG11
#pragma config CP = OFF     // User Program Flash Memory (PFM) Code Protection bit->User PFM code protection is disabled

//CONFIG12
#pragma config CPD = OFF     // Data EEPROM Code Protection bit->Data EEPROM code protection is disabled

//CONFIG14
#pragma config SAFLOCK = OFF     // SAF Lock Enable bit->SAF Lock disabled


/**
 End of File
*/

5.3.7.5 Module Documentation

5.3.7.5.1 CONFIGBITS Driver

This file contains the API prototype for the Configuration Bits driver.

Module description

This file contains the API prototype for the Configuration Bits driver.

Version: Driver Version 1.0.1 Package Version 1.0.2

5.3.7.5.2 System Driver

This file contains the API prototype for the System Driver.

Module description

This file contains the API prototype for the System Driver.

Version: Driver Version 1.0.2 Package Version 1.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.

Parameters:
None.
Returns:

None.

5.3.7.6 File Documentation

5.3.7.6.1 source/config_bits.c File Reference

This file contains the API implementation for the Device Configuration Bits driver.

Detailed Description

This file contains the API implementation for the Device Configuration Bits driver.

Configuration Bits Generated Driver Source File

Version: Driver Version 1.0.1 Package Version 1.0.2

5.3.7.6.2 source/config_bits.h File Reference

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

Detailed Description

Configuration Bits Generated Driver Header File

5.3.7.6.3 source/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 1.0.2 Package Version 1.0.2

5.3.7.6.4 source/system.h File Reference

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "config_bits.h"
#include "../system/pins.h"
#include "../system/mvio.h"
#include "../system/interrupt.h"
#include "../system/clock.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