基于MPLAB X IDE配置位设置讲解

基于MPLAB X IDE 配置位配置:

在PICLF1823的数据手册中可以找到两个配置寄存器。一个是配置字1 ,一个是配置字2.

对于初学者来说如此多的配置选项,该如何配置呢?我们要抓主重点。

配置字中最重要的配置选项就是:

看门狗配置 如:WDTE<1;0>; 一般选择关闭看门狗

MCLRE复位脚的配置 如:MCLRE;一般选择复位脚作I/O

震荡器的选择: 如:FOSC<2:0>;根据实际情况配置,我这里一般选择用 INTOSC 内部振荡器.

因为如果这三个没有配置好的话程序根本无法运行。其他配置可以看数据手册此不赘述。

MPLAB X IDE和MPLAB IDE 8不同。

MPLAB IDE 8 可以再界限中选择配置位就行。配置选项可以不写在代码中。

MPLAB X IDE 如果要配置的话必须在代码中写出配置。

1、打开MPLAB X IDE  在菜单栏中 点击Window->PIC  Memory Veiws->Configuration bits,先选好配置位:

2、点击“输出生成源代码”,即可生成如下代码:

// PIC16F1824 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>


// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1
#pragma config FOSC = ECH       // Oscillator Selection (ECH, External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin)
#pragma config WDTE = ON        // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)

3、简化代码

通过用逗号分隔每个设置 / 值对,可以使用一条 pragma 伪指令来编程多个设置。例如,
以上示例可以使用一条 pragma 伪指令指定,如下所示。
#pragma config FOSC = ECH, WDTE = ON ,PWRTE = OFF,MCLRE = ON^^^^^^^

4、注意事项:
config pragma 伪指令不会生成可执行代码。它们都应放置在函数
定义之外,以免影响函数代码的操作。






  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值