[其他产品]

PIC16F877A单片机(如何写 配置字)

[复制链接]
425|0
手机看帖
扫描二维码
随时随地手机跟帖
coshi|  楼主 | 2022-6-23 12:47 | 显示全部楼层 |阅读模式
1 MPLAB X V5.0,编译器为XC8(V2.0)

单击production—set Configuration Bit----点击 generate source code to output ----复制生成内容到main函数
watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5qKm6YaJ5LqG6LCB,size_20,color_FFFFFF,t_70,g_se,x_16.jpg



// 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

*/


第二种方法:
watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5qKm6YaJ5LqG6LCB,size_20,color_FFFFFF,t_70,g_se,x_16.jpg

上图中,配置字的值为3F7A,所以配置字也可以这样配置
__CONFIG(0x3f7A);



使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

95

主题

3301

帖子

3

粉丝