1、对于PIC来说,状态字的配置尤其重要,其直接影响MCU的正常工作与否;
2、以PIC18F45K22为例,打开mplab8.92,
3、我们就可以看到配置字的说明文档:
4、比如:Oscillator Selection bits:(振荡器选择配置字)
HS是使用超过4M的石英晶体振荡器(外部晶振),其中HSHP为大于16Mhz,HSMP为4-16Mhz;XT是使用1M到4M的石英晶体振荡器。LP是使用低于1M的陶瓷振荡器,上述都是用外部晶振,只是所用晶振的材质和频率不同。RC是不使用外部晶振,直接用内部的RC时钟电路。其中HS和XT因为用石英晶体振荡器,所得时钟比较准确,适用于各种串口、can、TCPIP通信的场合。但缺点是频率大所以功耗也大。用LP和RC的特点是功耗小,但LP频率低,陶瓷振荡器输出的时钟精度不够高,RC的误差更大。适用于不用通信的普通控制场合。
5、#pragma config FOSC=HSMP,PLLCFG=OFF,PRICLKEN =OFF,FCMEN=OFF,IESO=OFF,PWRTEN=ON,BOREN=SBORDIS,WDTEN=OFF,MCLRE=EXTMCLR
// CONFIG
*#pragma config FOSC = INTRCCLK // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
*#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
*#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
*#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
*#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
*#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
*#pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
*#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
*#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)