今天读公司的旧代码,看到了老的PIC单片机配置配置字的方法,就把网上质料稍稍整理了一下。
平台为:MPLAB V8.92,这个ID有两个编译选项:DEBUG和RELEASE,那么可以根据系统预定宏来自动根据选择模式,配置配置字。
一、PIC18F系列配置字编写
MUC: PIC18F4550
IDE: MPLAB V8.92
编译器:MCC18 V3.47
配置字讲解帮助手册在编译器如下目录:doc\hlpPIC18ConfigSet.chm
例如:D:\Program Files\Microchip\mplabc18\v3.47\doc\hlpPIC18ConfigSet.chm
注意:配置字文件必须只能有main.c文件包含。。。。。。
配置字编写:以18F为例
#ifdef __DEBUG
#pragma config EBTRB = OFF
#else
#pragma config EBTRB = ON
#endif
这段代码就编译预定义宏__DEBUG,然后根据用户选择编译模式自动打开和关闭读保护
例子:
#ifdef __18F46K80
#ifdef I_WANNA_DEBUG
#pragma config XINST=OFF,SOSCSEL=DIG,RETEN=ON,INTOSCSEL=LOW,\
PLLCFG=ON,FOSC=HS2,\
PWRTEN=OFF,BOREN=SBORDIS,BORV=0,WDTEN=NOSLP,WDTPS=512,\
MCLRE=ON,CANMX=PORTB,STVREN=ON,\
CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF,CPB=OFF,CPD=OFF,\
WRT0=OFF,WRT1=OFF,WRT2=OFF,WRT3=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF,\
EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF
#else
#pragma config XINST=OFF,SOSCSEL=DIG,RETEN=ON,INTOSCSEL=LOW,\
PLLCFG=ON,FOSC=HS2,\
PWRTEN=ON,BOREN=SBORDIS,BORV=0,WDTEN=NOSLP,WDTPS=512,\
MCLRE=OFF,CANMX=PORTB,STVREN=ON,\
CP0=ON,CP1=ON,CP2=ON,CP3=OFF,CPB=ON,CPD=ON,\
WRT0=ON ,WRT1=ON ,WRT2=OFF,WRT3=OFF,WRTB=ON,WRTC=ON,WRTD=ON,\
EBTR0=ON,EBTR1=ON,EBTR2=OFF,EBTR3=OFF,EBTRB=ON
#endif
#elif __18F4680
#ifdef I_WANNA_DEBUG
#pragma config OSC=HSPLL,PWRT=ON,BOREN=BOACTIVE,BORV=0,WDT=OFF,WDTPS=512,BBSIZ=4096,PBADEN=OFF,\
WRT0=OFF,WRT1=OFF,WRT2=OFF,WRT3=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF,\
EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF//
#else
#pragma config OSC=HSPLL,PWRT=ON,BOREN=BOHW,BORV=0,WDT=ON, WDTPS=512,BBSIZ=4096,PBADEN=OFF,MCLRE=OFF,\
WRT0=ON,WRT1=ON,WRT2=OFF,WRT3=OFF,WRTB=ON,WRTC=ON,WRTD=OFF,EBTR0=ON,\
EBTR1=ON,EBTR2=OFF,EBTR3=OFF,EBTRB=ON//
#endif
#elif __18F4585
#ifdef I_WANNA_DEBUG
#pragma config OSC=HSPLL,PWRT=ON,BOR=OFF,BORV=27,WDT=OFF,WDTPS=512,BBSIZ=4096,PBADEN=OFF,\
WRT0=OFF,WRT1=OFF,WRT2=OFF,WRT3=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF,EBTR0=OFF,\
EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF//
#else
#pragma config OSC=HSPLL,PWRT=ON,BOR=BOHW,BORV=27,WDT=ON, WDTPS=512,BBSIZ=4096,PBADEN=OFF,MCLRE=OFF,\
STVREN=ON,LVP=OFF,DEBUG=OFF,CP0=ON,CP1=ON,CP2=OFF,CP3=OFF,CPB=ON,CPD=OFF,\
WRT0=ON,WRT1=ON,WRT2=OFF,WRT3=OFF,WRTB=ON,WRTC=ON,WRTD=OFF,EBTR0=ON,\
EBTR1=ON,EBTR2=OFF,EBTR3=OFF,EBTRB=ON//
#endif
#elif __18F6585
#ifdef I_WANNA_DEBUG
#pragma config OSC=HSPLL,PWRT=ON,BOR=ON,BORV=27,WDT=OFF,WDTPS=256,STVR=ON,LVP=OFF,\
DEBUG=ON ,CP0=OFF,CP1=OFF,CP2=OFF,CPB=OFF,CPD=OFF,WRT0=OFF,WRT1=OFF,WRT2=OFF,\
WRTB=OFF,WRTC=OFF,WRTD=OFF,EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTRB=OFF
#else
#pragma config OSC=HSPLL,PWRT=ON,BOR=ON,BORV=27,WDT=ON, WDTPS=256,STVR=ON,LVP=OFF,MCLRE=OFF,\
DEBUG=OFF,CP0=ON ,CP1=ON ,CP2=OFF,CPB=ON ,CPD=ON ,WRT0=ON ,WRT1=ON ,WRT2=OFF,\
WRTB=ON,WRTC=ON ,WRTD=ON ,EBTR0=ON ,EBTR1=ON ,EBTR2=OFF ,EBTRB=ON
#endif
#else
#ifdef I_WANNA_DEBUG
#pragma config OSC=HSPLL,OSCS=OFF,PWRT=ON,BOR=ON,BORV=27,WDT=OFF,WDTPS=64,STVR=ON,LVP=OFF,\
DEBUG=ON ,CP0=OFF,CP1=OFF,CP2=OFF,CP3=OFF,CPB=OFF,CPD=OFF,WRT0=OFF,WRT1=OFF,WRT2=OFF,\
WRT3=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF,EBTR0=OFF,EBTR1=OFF,EBTR2=OFF,EBTR3=OFF,EBTRB=OFF
#else
#pragma config OSC=HSPLL,OSCS=OFF,PWRT=ON,BOR=ON,BORV=27,WDT=ON, WDTPS=64,STVR=ON,LVP=OFF,MCLRE=OFF,\
DEBUG=OFF,CP0=ON ,CP1=ON ,CP2=ON ,CP3=OFF ,CPB=ON ,CPD=ON ,WRT0=ON ,WRT1=ON ,WRT2=ON ,WRT3=OFF,\
WRTB=ON ,WRTC=ON ,WRTD=ON ,EBTR0=ON ,EBTR1=ON ,EBTR2=ON,EBTR3=OFF ,EBTRB=ON
#endif
#endif
愿你出走半生,归来仍是少年…