Configuration Settings of 18F4550 in a header file

microchipmplabxprogramming

Recently I was wondering if is there any option to move my Configuration bits to a header file?.
right now I'm using the 18f4550 microcontroller,with mplabx IDE,and my developed code entirely is in one principal file called main.c,in order to improve the debugging process with my code,I would like to receive any advice for structure code development.
I've tested with something like this but I can not reproduce it in my mplabx.

 
#include < stdio.h>
#include < delays.h>
#include < p18f4550.h>
#include < timers.h>
#include < xlcd.h>

#pragma config PLLDIV = 5 // (CRISTAL DE 20 MHz),Divide by 5 (20 MHz oscillator input) #pragma config USBDIV = 2 //USB clock source comes from the 96 MHz PLL divided by 2 #pragma config CPUDIV=OSC1_PLL2 //Primary Oscillator Src/1][96 MHz PLL Src/2] cpu trabajara a 48Mhz. #pragma config FOSC = HSPLL_HS //HS oscillator, PLL enabled (HSPLL) #pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled #pragma config IESO = OFF //Oscillator Switchover mode disabled #pragma config PWRT = ON //Power-up Timer Enable bit #pragma config BOR = OFF //Brown-out Reset Enable bits: Brown-out Reset //enabled in hardware only (SBOREN is disabled) #pragma config BORV = 0 //Brown-out Reset Voltage bits,Maximum. #pragma config VREGEN = ON // USB voltage regulator enabled #pragma config WDT = OFF //WDT disabled (control is placed on the SWDTEN bit) #pragma config WDTPS = 32768 //Watchdog Timer Postscale Select bits>> 1:32768 #pragma config MCLRE = ON //MCLR pin enabled; RE3 input pin disabled #pragma config LPT1OSC = OFF //Timer1 configured for higher power operation #pragma config PBADEN = OFF //PORTB<4:0> pins are configured as digital I/O on Reset //If i need to use the RBx as analog in/out set this bit to ON #pragma config STVREN = OFF //Stack full/underflow will not cause Reset #pragma config LVP = OFF //PROGRAMACION EN BAJO VOLTAJE #pragma config XINST = OFF // Instruction set extension and Indexed Addressing mode enabled //the above bit is used enterely for debug program in circuit (ICPORT) #pragma config CP0 = OFF //Code Protection bit disable for 0,1,2 #pragma config CP1 = OFF // #pragma config CP2 = OFF // #pragma config CPB = OFF //Boot Block Code Protection bit: #pragma config CPD = OFF //Data EEPROM Code Protection bit. #pragma config WRT0 = OFF //Write Protection bit for 0,1,2 is not write-protected #pragma config WRT1 = OFF #pragma config WRT2 = OFF #pragma config WRTB = OFF //PROTECCI?N DE ESCRITURA PARA EL BLOCK DE BOOT #pragma config WRTC = OFF //Configuration Register Write Protection bit,disable #pragma config WRTD = OFF //Data EEPROM Write Protection bit,is not write protected #pragma config EBTR0 = OFF //000800-001FFFh #pragma config EBTR1 = OFF //Boot Block Table Read Protection bit,disable between #pragma config EBTRB = OFF //000000-0007FFh and 002000-003FFFh #pragma config CCP2MX = OFF #pragma config DEBUG = ON //ENABLE FOR PICKIT 3 #define hola=3;

void main(void){ ..code }

After do this I might have something like this

#include < stdio.h> #include < delays.h> #include < p18f4550.h> #include < timers.h> #include < xlcd.h> #include < bits.h> // or something like that #define hola=3;

void main(void){ ..code }

Any advice or suggestion will be ok.

Best Answer

Yes, of course this is possible. You don't say what compiler you are using, but this doesn't matter too much.

You can create a file called config.h and add it to your project in MPLABX. Put all of your configuration defines into that file.

In your main.c you can then:

#include "config.h"

(Note if you are using XC8 you should be including xc.h and not p18f4550.h)