view plaincopy to clipboardprint?
平台为:MPLAB V8.92,这个ID有两个编译选项:DEBUG和RELEASE,那么可以根据系统预定宏来自动根据选择模式,配置配置字。
一、PIC18F系列配置字编写
MUC: PIC18F4550
IDE: MPLAB V8.92
编译器:MCC18 V3.47
配置字讲解帮助手册在编译器如下目录:doc\hlpPIC18ConfigSet.chm
例如:D:\Program Files\Microchip\mplabc18\v3.47\doc\hlpPIC18ConfigSet.chm
注意:配置字文件必须只能有main.c文件包含。。。。。。
配置字编写:以18F为例
#ifdef __DEBUG
#pragma config EBTRB = OFF
#else
#pragma config EBTRB = ON
#endif
这段代码就编译预定义宏__DEBUG,然后根据用户选择编译模式自动打开和关闭读保护
例子:
#ifndef __PIC18F4550_CONFIG_H__
#define __PIC18F4550_CONFIG_H__
#include
//看门狗
#define WDT_ENABLE 0//1:打开;0:关闭
//USB
#define USB_ENABLE 0//1:打开;0:关闭
//PLL Prescaler Selection bits
//96 MHz PLL Prescaler
/*
PLLDIV = 1 No divide (4 MHz input)
PLLDIV = 2 Divide by 2 (8 MHz input)
PLLDIV = 3 Divide by 3 (12 MHz input)
PLLDIV = 4 Divide by 4 (16 MHz input)
PLLDIV = 5 Divide by 5 (20 MHz input)
PLLDIV = 6 Divide by 6 (24 MHz input)
PLLDIV = 10 Divide by 10 (40 MHz input)
PLLDIV = 12 Divide by 12 (48 MHz input)
*/
#pragma config PLLDIV = 5
//CPU System Clock Postscaler
/*
CPUDIV = OSC1_PLL2 [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
CPUDIV = OSC2_PLL3 [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
CPUDIV = OSC3_PLL4 [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4]
CPUDIV = OSC4_PLL6 [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6]
*/
#pragma config CPUDIV = OSC1_PLL2
//USB Clock Selection bit
//used in Full Speed USB mode only; UCFG:FSEN = 1
//USBDIV = 1 Clock source from OSC1/OSC2
//USBDIV = 2 Clock source from 96 MHz PLL/2
#pragma config USBDIV = 2
//Oscillator Selection bits
/*
FOSC = XT_XT XT oscillator, XT used by USB
FOSC = XTPLL_XT XT oscillator, PLL enabled, XT used by USB
FOSC = ECIO_EC External clock, port function on RA6, EC used by USB
FOSC = EC_EC External clock, CLKOUT on RA6, EC used by USB
FOSC = ECPLLIO_EC External clock, PLL enabled, port function on RA6, EC used by USB
FOSC = ECPLL_EC External clock, PLL enabled, CLKOUT on RA6, EC used by USB
FOSC = INTOSCIO_EC Internal oscillator, port function on RA6, EC used by USB
FOSC = INTOSC_EC Internal oscillator, CLKOUT on RA6, EC used by USB
FOSC = INTOSC_XT Internal oscillator, XT used by USB
FOSC = INTOSC_HS Internal oscillator, HS used by USB
FOSC = HS HS oscillator, HS used by USB
FOSC = HSPLL_HS HS oscillator, PLL enabled, HS used by USB
*/
#pragma config FOSC = HSPLL_HS
//Fail-Safe Clock Monitor Enable bit
#pragma config FCMEN = OFF
//Internal/External Oscillator Switchover bit
#pragma config IESO = OFF
//Power-up Timer Enable bit
#pragma config PWRT = ON
//Brown-out Reset Enable bits
#pragma config BOR = ON
//Brown-out Voltage bits
#pragma config BORV = 3
//USB Voltage Regulator Enable bit
//VREGEN = OFF USB voltage regulator disabled
//VREGEN = ON USB voltage regulator enabled
#if USB_ENABLE
#pragma config VREGEN = ON
#else
#pragma config VREGEN = OFF
#endif
//Watchdog Timer Enable bit
#ifdef __DEBUG
#pragma config WDT = OFF
#else
#if WDT_ENABLE
#pragma config WDT = ON
#else
#pragma config WDT = OFF
#endif
#endif
//Watchdog Timer Postscale Select bits
/*
WDTPS = 1 1:1
WDTPS = 2 1:2
WDTPS = 4 1:4
WDTPS = 8 1:8
WDTPS = 16 1:16
WDTPS = 32 1:32
WDTPS = 64 1:64
WDTPS = 128 1:128
WDTPS = 256 1:256
WDTPS = 512 1:512
WDTPS = 1024 1:1024
WDTPS = 2048 1:2048
WDTPS = 4096 1:4096
WDTPS = 8192 1:8192
WDTPS = 16384 1:16384
WDTPS = 32768 1:32768
*/
//看门狗时钟:4ms
#pragma config WDTPS = 256
//MCLR Pin Enable bit
#pragma config MCLRE = ON
//Low-Power Timer 1 Oscillator Enable bit
#pragma config LPT1OSC = OFF
//PORTB A/D Enable bit
#pragma config PBADEN = OFF
//CCP2 MUX bit
#pragma config CCP2MX = OFF
//Stack Full/Underflow Reset Enable bit
#pragma config STVREN = ON
//Single-Supply ICSP Enable bit
#pragma config LVP = OFF
//Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit
#pragma config ICPRT = OFF
//Extended Instruction Set Enable bit
#pragma config XINST = OFF
//Background Debugger Enable bit
#ifdef __DEBUG
#pragma config DEBUG = ON
#else
#pragma config DEBUG = OFF
#endif
//Code Protection bit Block 0
#pragma config CP0 = OFF
//Code Protection bit Block 1
#pragma config CP1 = OFF
//Code Protection bit Block 2
#pragma config CP2 = OFF
//Code Protection bit Block 3
#pragma config CP3 = OFF
//Boot Block Code Protection bit
#pragma config CPB = OFF
//Data EEPROM Code Protection bit
#pragma config CPD = OFF
//Write Protection bit Block 0
#pragma config WRT0 = OFF
//Write Protection bit Block 1
#pragma config WRT1 = OFF
//Write Protection bit Block 2
#pragma config WRT2 = OFF
//Write Protection bit Block 3
#pragma config WRT3 = OFF
//Boot Block Write Protection bit
#pragma config WRTB = OFF
//Configuration Register Write Protection bit
#ifdef __DEBUG
#pragma config WRTC= OFF
#else
#pragma config WRTC= ON
#endif
//Data EEPROM Write Protection bit
#pragma config WRTD = OFF
//Table Read Protection bit Block 0
#pragma config EBTR0 = OFF
//Table Read Protection bit Block 1
#pragma config EBTR1 = OFF
//Table Read Protection bit Block 2
#pragma config EBTR2 = OFF
//Table Read Protection bit Block 3
#pragma config EBTR3 = OFF
//Boot Block Table Read Protection
#ifdef __DEBUG
#pragma config EBTRB = OFF
#else
#pragma config EBTRB = ON
#endif
#endif
二、PIC32MX系列配置字编写
MCU: PIC32MX564F128L
IDE: MPLAB V8.92
编译器:C32 V2.02 (本版本不支持MZ系列,XC32支持)
参考手册同样:D:\Program Files\Microchip\mplabc32\v2.02\doc\hlpPIC32MXConfigSet
说明:这个例子没有用预定义宏__DEBUG进行处理,请自行设置
#ifndef __PIC32CONFIG_H__
#define __PIC32CONFIG_H__
/*****用户自定义16位值标识***********/
//#pragma config USERID =
/*****影子寄存器分配中断优先级*******/
#pragma config FSRSSEL =PRIORITY_7//PRIORITY_0/PRIORITY_1/PRIORITY_2
//PRIORITY_3/PRIORITY_4/PRIORITY_5
//PRIORITY_6/PRIORITY_7
/*****CAN引脚选择********************/
#pragma config FCANIO =ON//ON:Default CAN I/OOFF:Alternate CAN I/O
/*****USBID控制位********************/
#pragma config FUSBIDIO =OFF//ON:Controlled by the USB Module
//OFF:Controlled by Port Function
/*****VBUSON控制位*******************/
#pragma config FVBUSONIO= OFF//ON:Controlled by USB Module
//OFF:Controlled by Port Function
/*****PLL输入分频比******************/
#pragma config FPLLIDIV =DIV_5//4MHz<= Fin <=5MHz
//DIV_1/DIV_2/DIV_3/DIV_4/DIV_5
//DIV_6/DIV_10/DIV_12
/*****PLL倍频系数********************/
#pragma config FPLLMUL =MUL_20//MUL_15/MUL_16/MUL_17/MUL_18/MUL_19
//MUL_20/MUL_21/MUL_24
/*****USB PLL输入分频比**************/
#pragma config UPLLIDIV =DIV_2//Fin=4MHz
//DIV_1/DIV_2/DIV_3/DIV_4/DIV_5/DIV_6
//DIV_10/DIV_12
/*****USB PLL 使能位*****************/
#pragma config UPLLEN =OFF//ON:使能OFF:禁止
/*****PLL后分频器********************/
#pragma config FPLLODIV =DIV_1//DIV_1/DIV_2/DIV_4/DIV_8/DIV_16/DIV_32/DIV_64/DIV_256
/*****振荡器选择*********************
FNOSC = FRC Fast RC Osc (FRC)
FNOSC = FRCPLL Fast RC Osc with PLL
FNOSC = PRI Primary Osc (XT,HS,EC)
FNOSC = PRIPLL Primary Osc w/PLL (XT+,HS+,EC+PLL)
FNOSC = SOSC Low Power Secondary Osc (SOSC)
FNOSC = LPRC Low Power RC Osc (LPRC)
FNOSC = FRCDIV16 Fast RC Osc w/Div-by-16 (FRC/16)
FNOSC = FRCDIV Fast RC Osc w/Div-by-N (FRCDIV)
*************************************/
#pragma config FNOSC =PRI
/*****辅助振荡器选择位***************/
#pragma config FSOSCEN = OFF//OFF:Disabled ON:Enabled
/*****内/外部振荡器切换位************/
#pragma config IESO =OFF//OFF:Disabled ON:Enabled
/*****主振荡器配置位*****************
POSCMOD = EC External clock mode
POSCMOD = XT XT osc mode
POSCMOD = HS HS osc mode
POSCMOD = OFF Primary osc disabled
*************************************/
#pragma config POSCMOD=HS
/*****CLKO使能位*********************/
#pragma config OSCIOFNC=OFF//OFF:Disabled ON:Enabled
/*****外设总线时钟分频比*************/
#pragma config FPBDIV=DIV_1//DIV_1/DIV_2/DIV_4/DIV_8
/*****时钟切换和监视器选择配置位*****
FCKSM = CSECME Clock Switch Enable, FSCM Enabled
FCKSM = CSECMD Clock Switch Enable, FSCM Disabled
FCKSM = CSDCMD Clock Switch Disable, FSCM Disabled
*************************************/
#pragma config FCKSM=CSDCMD
/*****看门狗时钟后分频比*************
WDTPS = PS1 1:1
WDTPS = PS2 1:2
WDTPS = PS4 1:4
WDTPS = PS8 1:8
WDTPS = PS16 1:16
WDTPS = PS32 1:32
WDTPS = PS64 1:64
WDTPS = PS128 1:128
WDTPS = PS256 1:256
WDTPS = PS512 1:512
WDTPS = PS1024 1:1024
WDTPS = PS2048 1:2048
WDTPS = PS4096 1:4096
WDTPS = PS8192 1:8192
WDTPS = PS16384 1:16384
WDTPS = PS32768 1:32768
WDTPS = PS65536 1:65536
WDTPS = PS131072 1:131072
WDTPS = PS262144 1:262144
WDTPS = PS524288 1:524288
WDTPS = PS1048576 1:1048576
*************************************/
#pragma config WDTPS=PS2
/*****看门狗使能位*******************/
#pragma config FWDTEN=OFF //ON:WDT Enabled OFF:WDT Disabled (SWDTEN Bit Controls)
/*****ICE/ICD Comm Channel Select****
ICESEL = ICS_PGx1 ICE EMUC1/EMUD1 pins shared with PGC1/PGD1
ICESEL = ICS_PGx2 ICE EMUC2/EMUD2 pins shared with PGC2/PGD2
*************************************/
#pragma config ICESEL=ICS_PGx1
/******程序闪存写保护位**************
PWP = PWP512K First 512K
PWP = PWP508K First 508K
PWP = PWP504K First 504K
PWP = PWP500K First 500K
PWP = PWP496K First 496K
PWP = PWP492K First 492K
PWP = PWP488K First 488K
PWP = PWP484K First 484K
PWP = PWP480K First 480K
PWP = PWP476K First 476K
PWP = PWP472K First 472K
PWP = PWP468K First 468K
PWP = PWP464K First 464K
PWP = PWP460K First 460K
PWP = PWP456K First 456K
PWP = PWP452K First 452K
PWP = PWP448K First 448K
PWP = PWP444K First 444K
PWP = PWP440K First 440K
PWP = PWP436K First 436K
PWP = PWP432K First 432K
PWP = PWP428K First 428K
PWP = PWP424K First 424K
PWP = PWP420K First 420K
PWP = PWP416K First 416K
PWP = PWP412K First 412K
PWP = PWP408K First 408K
PWP = PWP404K First 404K
PWP = PWP400K First 400K
PWP = PWP396K First 396K
PWP = PWP392K First 392K
PWP = PWP388K First 388K
PWP = PWP384K First 384K
PWP = PWP380K First 380K
PWP = PWP376K First 376K
PWP = PWP372K First 372K
PWP = PWP368K First 368K
PWP = PWP364K First 364K
PWP = PWP360K First 360K
PWP = PWP356K First 356K
PWP = PWP352K First 352K
PWP = PWP348K First 348K
PWP = PWP344K First 344K
PWP = PWP340K First 340K
PWP = PWP336K First 336K
PWP = PWP332K First 332K
PWP = PWP328K First 328K
PWP = PWP324K First 324K
PWP = PWP320K First 320K
PWP = PWP316K First 316K
PWP = PWP312K First 312K
PWP = PWP308K First 308K
PWP = PWP304K First 304K
PWP = PWP300K First 300K
PWP = PWP296K First 296K
PWP = PWP292K First 292K
PWP = PWP288K First 288K
PWP = PWP284K First 284K
PWP = PWP280K First 280K
PWP = PWP276K First 276K
PWP = PWP272K First 272K
PWP = PWP268K First 268K
PWP = PWP264K First 264K
PWP = PWP260K First 260K
PWP = PWP256K First 256K
PWP = PWP252K First 252K
PWP = PWP248K First 248K
PWP = PWP244K First 244K
PWP = PWP240K First 240K
PWP = PWP236K First 236K
PWP = PWP232K First 232K
PWP = PWP228K First 228K
PWP = PWP224K First 224K
PWP = PWP220K First 220K
PWP = PWP216K First 216K
PWP = PWP212K First 212K
PWP = PWP208K First 208K
PWP = PWP204K First 204K
PWP = PWP200K First 200K
PWP = PWP196K First 196K
PWP = PWP192K First 192K
PWP = PWP188K First 188K
PWP = PWP184K First 184K
PWP = PWP180K First 180K
PWP = PWP176K First 176K
PWP = PWP172K First 172K
PWP = PWP168K First 168K
PWP = PWP164K First 164K
PWP = PWP160K First 160K
PWP = PWP156K First 156K
PWP = PWP152K First 152K
PWP = PWP148K First 148K
PWP = PWP144K First 144K
PWP = PWP140K First 140K
PWP = PWP136K First 136K
PWP = PWP132K First 132K
PWP = PWP128K First 128K
PWP = PWP124K First 124K
PWP = PWP120K First 120K
PWP = PWP116K First 116K
PWP = PWP112K First 112K
PWP = PWP108K First 108K
PWP = PWP104K First 104K
PWP = PWP100K First 100K
PWP = PWP96K First 96K
PWP = PWP92K First 92K
PWP = PWP88K First 88K
PWP = PWP84K First 84K
PWP = PWP80K First 80K
PWP = PWP76K First 76K
PWP = PWP72K First 72K
PWP = PWP68K First 68K
PWP = PWP64K First 64K
PWP = PWP60K First 60K
PWP = PWP56K First 56K
PWP = PWP52K First 52K
PWP = PWP48K First 48K
PWP = PWP44K First 44K
PWP = PWP40K First 40K
PWP = PWP36K First 36K
PWP = PWP32K First 32K
PWP = PWP28K First 28K
PWP = PWP24K First 24K
PWP = PWP20K First 20K
PWP = PWP16K First 16K
PWP = PWP12K First 12K
PWP = PWP8K First 8K
PWP = PWP4K First 4K
PWP = OFF Disable
*************************************/
#pragma config PWP=OFF
/******引导闪存写保护位**************
BWP = ON Protection Enabled
BWP = OFF Protection Disabled
*************************************/
#pragma config BWP=OFF
/******代码保护位********************
CP = ON Protection Enabled
CP = OFF Protection Disabled
*************************************/
#pragma config CP=OFF
#endif
深圳嘉立创PCB现在降价了。做板加Q800058675 |