1 MPLAB X V5.0,编译器为XC8(V2.0) 单击production—set Configuration Bit----点击 generate source code to output ----复制生成内容到main函数
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
// CONFIG #pragma config FOSC = EXTRC // Oscillator Selection bits (RC oscillator) #pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled) #pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF.
#include <xc.h>
2 MPLAB V5.0,编译器为PICC第一种方法: // Config Register: CONFIG 配置字 __CONFIG(FOSC_HS&WDTE_OFF&LVP_OFF);//高斯速晶振,看门狗关闭,低压编程关闭 //__CONFIG(0x3f7A); // 和上一条语句等价 /* 配置字的解释说明: // HS oscillator 大于4M晶振 // XT oscillator 400K-4M晶振 // LP oscillator 小于400K晶振 // RC oscillator 阻容震荡,单片机不接晶振,外接电阻和电容来震荡,精度低,受温度影响大
// WDT enabled #define WDTE_ON 0xFFFF // WDT disabled #define WDTE_OFF 0xFFFB
// Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit // RB3/PGM pin has PGM function; low-voltage programming enabled #define LVP_ON 0xFFFF // RB3 is digital I/O, HV on MCLR must be used for programming #define LVP_OFF 0xFF7F */
第二种方法:
上图中,配置字的值为3F7A,所以配置字也可以这样配置
__CONFIG(0x3f7A);
|