打印
[PIC®/AVR®/dsPIC®产品]

PIC单片机默认配置位

[复制链接]
8816|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
对配置位不熟悉,不是很清楚每一个的具体的配置,在我的一个程序(PIC18F452)中只写了下面3句(XC8)
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config OSC = HS
编译的时候虽然可以,但是有警告。
(1311) missing configuration setting for config word 0x300002, using default (warning)
XC8中默认的单片机配置是怎样的 ?
沙发
bill_shi68| | 2014-4-15 22:32 | 只看该作者
使用MPLAB开发环境吗?
如果是可以在CONFIG配置窗口中配置CONFIG BITS

使用特权

评论回复
板凳
就是一个菜鸟|  楼主 | 2014-4-15 22:55 | 只看该作者
MPLAB 8.6,我知道那里有个,新手一枚,但是不清楚都要设置哪些?
软件默认的配置是怎样的

使用特权

评论回复
地板
yewuyi| | 2014-4-16 13:08 | 只看该作者

//----------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef              debug
__CONFIG(FOSC_INTOSC&WDTE_ON&PWRTE_ON&MCLRE_ON&CP_ON&CPD_ON&BOREN_ON&CLKOUTEN_OFF&IESO_OFF&FCMEN_OFF);
__CONFIG(WRT_ALL&VCAPEN_OFF&PLLEN_OFF&STVREN_ON&BORV_25&LVP_ON);
#endif

使用特权

评论回复
5
yewuyi| | 2014-4-16 13:08 | 只看该作者
这是我用的PIC16F1938的CONFIG,把它拷贝放到main.c文件中即可

使用特权

评论回复
6
就是一个菜鸟|  楼主 | 2014-4-16 22:27 | 只看该作者
yewuyi 发表于 2014-4-16 13:08
这是我用的PIC16F1938的CONFIG,把它拷贝放到main.c文件中即可

感谢版本的回答。我刚将上面的配置代码放到main.c中,编译不过。
main.c:
    22:        #ifndef             // debug
                                   ^ (108) #if[n][def] without an argument
    23:        __CONFIG(FOSC_INTOSC&WDTE_ON&PWRTE_ON&MCLRE_ON&CP_ON&CPD_ON&BOREN_ON&CLKOUTEN_OFF&IESO_OFF&FCMEN_OFF);
                         (171) wrong number of preprocessor macro arguments for "__CONFIG" (1 instead of 2) ^ (warning)
__CONFIG: 23: (171) wrong number of preprocessor macro arguments for "___mkstr" (0 instead of 1) (warning)
___mkstr: 23: (171) wrong number of preprocessor macro arguments for "___mkstr1" (0 instead of 1) (warning)
    24:        __CONFIG(WRT_ALL&VCAPEN_OFF&PLLEN_OFF&STVREN_ON&BORV_25&LVP_ON);
                                                                      ^ (171) wrong number of preprocessor macro arguments for "__CONFIG" (1 instead of 2) (warning)
__CONFIG: 24: (171) wrong number of preprocessor macro arguments for "___mkstr" (0 instead of 1) (warning)
___mkstr: 24: (171) wrong number of preprocessor macro arguments for "___mkstr1" (0 instead of 1) (warning)
(908) exit status = 1
(908) exit status = 1
Halting build on first failure as requested.

我用的是MPLAB 8.7 (XC8),是我编译器的问题吗

使用特权

评论回复
7
yklstudent| | 2014-4-17 07:33 | 只看该作者
// PIC18F452 Configuration Bit Settings

#include <xc.h>

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

// CONFIG1H
#pragma config OSC = HS         // Oscillator Selection bits (HS oscillator)
#pragma config OSCS = OFF       // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bit (Brown-out Reset enabled)
#pragma config BORV = 20        // Brown-out Reset Voltage bits (VBOR set to 2.0V)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 128      // Watchdog Timer Postscale Select bits (1:128)

// CONFIG3H
#pragma config CCP2MUX = ON     // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)

// CONFIG4L
#pragma config STVR = ON        // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
#pragma config LVP = OFF        // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) not code protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) not write protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)

使用特权

评论回复
8
yklstudent| | 2014-4-17 07:35 | 只看该作者
看提示就应该知道什么意思
你的人工设置配置位信息不全
所以缺失的部分提示你使用默认设置

使用特权

评论回复
9
yewuyi| | 2014-4-17 08:18 | 只看该作者
我简直服了YOU .

我那是PIC16F1938的配置位宏,你的芯片型号不一样,当然不能原封不动的照抄,我发给你只是让你参照看看,你应当根据你自己的芯片型号进行适当修改。

你不是不熟需配置位的问题,而是基本的C语言知识严重缺乏,否则的话,不会在大家已经如此提示的基础上还依然搞不懂。

使用特权

评论回复
10
就是一个菜鸟|  楼主 | 2014-4-17 09:42 | 只看该作者
yewuyi 发表于 2014-4-17 08:18
我简直服了YOU .

我那是PIC16F1938的配置位宏,你的芯片型号不一样,当然不能原封不动的照抄,我发给你只 ...

:L 谢谢指教,我本来也觉得不同的芯片配置位是不一样的,你说直接copy,我就试了下。

使用特权

评论回复
11
就是一个菜鸟|  楼主 | 2014-4-17 09:52 | 只看该作者
yklstudent 发表于 2014-4-17 07:35
看提示就应该知道什么意思
你的人工设置配置位信息不全
所以缺失的部分提示你使用默认设置 ...

是的,人工配置不全。你上面的就是我想要的。谢谢

使用特权

评论回复
12
yklstudent| | 2014-4-17 13:33 | 只看该作者
楼主就偷个懒吧
安装MPLAB X环境
自带配置位生产工具
感觉好用多了
至于要怎么设置,看芯片手册

使用特权

评论回复
13
就是一个菜鸟|  楼主 | 2014-4-17 16:30 | 只看该作者
yklstudent 发表于 2014-4-17 13:33
楼主就偷个懒吧
安装MPLAB X环境
自带配置位生产工具

我起初也是这么想的,后来觉得还是了解清楚比较好,毕竟还在学习中,哪天精通了的,可以考虑:)

使用特权

评论回复
14
bill_shi68| | 2014-4-17 20:01 | 只看该作者
参照Datasheet中的说明,在MPLAB IDE的config bit 窗口中设置(代码文件中不能再有配置代码,否则按代码配置进行处理)

使用特权

评论回复
15
就是一个菜鸟|  楼主 | 2014-4-19 09:16 | 只看该作者
bill_shi68 发表于 2014-4-17 20:01
参照Datasheet中的说明,在MPLAB IDE的config bit 窗口中设置(代码文件中不能再有配置代码,否则按代码配 ...

谢谢答复。我是想尝试用代码进行配置的

使用特权

评论回复
16
wangtao478552| | 2014-12-26 10:32 | 只看该作者
就是一个菜鸟 发表于 2014-4-19 09:16
谢谢答复。我是想尝试用代码进行配置的

哎,有点无语,用MPLAB可视化配置完只是生成代码,需要自己拷到程序里,那代码你是可以改可以研究的,人叫你用MPLAB你可以把它当学习的工具啊...

使用特权

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

本版积分规则

8

主题

44

帖子

0

粉丝