Configuraciones de configuración de 18F4550 en un archivo de encabezado

0

Recientemente me preguntaba si hay alguna opción para mover mis bits de configuración a un archivo de encabezado. En este momento estoy usando el microcontrolador 18f4550, con mplabx IDE, y mi código desarrollado está completamente en un archivo principal llamado main.c, para mejorar el proceso de depuración con mi código. Me gustaría recibir cualquier consejo para el código de estructura. desarrollo. He probado con algo como esto pero no puedo reproducirlo en mi 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 }

Después de hacer esto podría tener algo como esto


#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 }

Cualquier consejo o sugerencia estará bien.

    
pregunta c1b3r

1 respuesta

2

Sí, por supuesto que esto es posible. No dices qué compilador estás usando, pero esto no importa demasiado.

Puede crear un archivo llamado config.h y agregarlo a su proyecto en MPLABX. Ponga todas sus configuraciones definidas en ese archivo.

En tu main.c puedes:

#include "config.h"

(Tenga en cuenta que si está utilizando XC8, debe incluir xc.h y no p18f4550.h)

    
respondido por el David

Lea otras preguntas en las etiquetas