Steps to perform the setting of Configuration bits

Topic Progress:

All Microchip 8-bit PIC devices must be configured to ensure correct operation. Some configuration settings affect fundamental operation of the device, like those for the instruction clock. If that setting is incorrect, the clock may not run.
The number and type of configuration settings vary from device to device.The following steps describe how to use the window to get the information to complete the pragmas.

  • Step 1: Select Window>PIC Memory Views>Configuration Bits from the menus.

[fusion_imageframe image_id=”4396″ style_type=”none” stylecolor=”” hover_type=”liftup” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”yes” gallery_id=”” lightbox_image=”http://learn.openlabpro.com/wp-content/uploads/2018/03/image5.png” alt=”” link=”” linktarget=”_self” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]http://learn.openlabpro.com/wp-content/uploads/2018/03/image5.png[/fusion_imageframe]

  • step 2: Review every setting
  1. Oscillator section
  2. Watchdog Timer
  3. Code protection
  4. Extended Instruction Set
  • Step 3: Generates the pragmas that can implement the settings you have chosen. Click the Generate Source Code to Output button. The generated code will appear in the Config Bits Source window.

[fusion_imageframe image_id=”4398″ style_type=”none” stylecolor=”” hover_type=”liftup” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”yes” gallery_id=”” lightbox_image=”http://learn.openlabpro.com/wp-content/uploads/2018/03/image6.png” alt=”” link=”” linktarget=”_self” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]http://learn.openlabpro.com/wp-content/uploads/2018/03/image6.png[/fusion_imageframe]

Steps 4: Copies code from this window to your source file

#include <xc.h>
// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
// CONFIG1H
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
// CONFIG3H
#pragma config CCP2MX = OFF     // CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
  • Both internal and external clock can be used in PIC18F4550.Here setting an external clock of frequency 20MHz.
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif