Confuguration bits 可以直接用程式設定,範例如下:
// Setup configuration bits
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & FNOSC_PRI )
以上的設定是摘自 204 ADV 的練習的設定,使用 Explorer-16 的實驗版,使用 HS Mode without x4 PLL 電路,使用第二組除錯腳位。
每一項的說明要參考 PIC24FJ128GA010 的 H 檔說明。
/* -------------------------------------------------------- */
/* Macros for setting device configuration registers */
/* -------------------------------------------------------- */
/* Register CONFIG2 (0x157fc) */
#define _CONFIG2(x) __attribute__((section("__CONFIG2.sec,code"))) int _CONFIG2 = (x);
/*
** Only one invocation of CONFIG2 should appear in a project,
** at the top of a C source file (outside of any function).
**
** The following constants can be used to set CONFIG2.
** Multiple options may be combined, as shown:
**
** _CONFIG2( OPT1_ON & OPT2_OFF & OPT3_PLL )
**
** Two Speed Start-up:
** IESO_OFF Disabled
** IESO_ON Enabled
**
** Oscillator Selection:
** FNOSC_FRC Fast RC oscillator
** FNOSC_FRCPLL Fast RC oscillator w/ divide and PLL
** FNOSC_PRI Primary oscillator (XT, HS, EC)
** FNOSC_PRIPLL Primary oscillator (XT, HS, EC) w/ PLL
** FNOSC_SOSC Secondary oscillator
** FNOSC_LPRC Low power RC oscillator
** FNOSC_LPRCDIV Fast RC oscillator with divide
**
** Clock switching and clock monitor:
** FCKSM_CSECME Both enabled
** FCKSM_CSECMD Only clock switching enabled
** FCKSM_CSDCMD Both disabled
**
** OSCO/RC15 function:
** OSCIOFNC_ON RC15
** OSCIOFNC_OFF OSCO or Fosc/2
**
** Oscillator Selection:
** POSCMOD_EC External clock
** POSCMOD_XT XT oscillator
** POSCMOD_HS HS oscillator
** POSCMOD_NONE Primary disabled
**
*/
#define IESO_OFF 0x7FFF
#define IESO_ON 0xFFFF
#define FNOSC_FRC 0xF8FF
#define FNOSC_FRCPLL 0xF9FF
#define FNOSC_PRI 0xFAFF
#define FNOSC_PRIPLL 0xFBFF
#define FNOSC_SOSC 0xFCFF
#define FNOSC_LPRC 0xFDFF
#define FNOSC_LPRCDIV 0xFFFF
#define FCKSM_CSECME 0xFF3F
#define FCKSM_CSECMD 0xFF7F
#define FCKSM_CSDCMD 0xFFBF
#define OSCIOFNC_ON 0xFFDF
#define OSCIOFNC_OFF 0xFFFF
#define POSCMOD_EC 0xFFFC
#define POSCMOD_XT 0xFFFD
#define POSCMOD_HS 0xFFFE
#define POSCMOD_NONE 0xFFFF
/* Register CONFIG1 (0x157fe) */
#define _CONFIG1(x) __attribute__((section("__CONFIG1.sec,code"))) int _CONFIG1 = (x);
/*
** Only one invocation of CONFIG1 should appear in a project,
** at the top of a C source file (outside of any function).
**
** The following constants can be used to set CONFIG1.
** Multiple options may be combined, as shown:
**
** _CONFIG1( OPT1_ON & OPT2_OFF & OPT3_PLL )
**
** JTAG:
** JTAGEN_OFF Disabled
** JTAGEN_ON Enabled
**
** Code Protect:
** GCP_ON Enabled
** GCP_OFF Disabled
**
** Write Protect:
** GWRP_ON Enabled
** GWRP_OFF Disabled
**
** Background Debugger:
** BKBUG_ON Enabled
** BKBUG_OFF Disabled
**
** Clip-on Emulation mode:
** COE_ON Enabled
** COE_OFF Disabled
**
** ICD pins select:
** ICS_PGx1 EMUC/EMUD share PGC1/PGD1
** ICS_PGx2 EMUC/EMUD share PGC2/PGD2
**
** Watchdog Timer:
** FWDTEN_OFF Disabled
** FWDTEN_ON Enabled
**
** Windowed WDT:
** WINDIS_ON Enabled
** WINDIS_OFF Disabled
**
** Watchdog prescaler:
** FWPSA_PR32 1:32
** FWPSA_PR128 1:128
**
** Watchdog postscale:
** 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:1,024
** WDTPS_PS2048 1:2,048
** WDTPS_PS4096 1:4,096
** WDTPS_PS8192 1:8,192
** WDTPS_PS16384 1:16,384
** WDTPS_PS32768 1:32,768
**
*/
#define JTAGEN_OFF 0xBFFF
#define JTAGEN_ON 0xFFFF
#define GCP_ON 0xDFFF
#define GCP_OFF 0xFFFF
#define GWRP_ON 0xEFFF
#define GWRP_OFF 0xFFFF
#define BKBUG_ON 0xF7FF
#define BKBUG_OFF 0xFFFF
#define COE_ON 0xFBFF
#define COE_OFF 0xFFFF
#define ICS_PGx1 0xFEFF
#define ICS_PGx2 0xFFFF
#define FWDTEN_OFF 0xFF7F
#define FWDTEN_ON 0xFFFF
#define WINDIS_ON 0xFFBF
#define WINDIS_OFF 0xFFFF
#define FWPSA_PR32 0xFFEF
#define FWPSA_PR128 0xFFFF
#define WDTPS_PS1 0xFFF0
#define WDTPS_PS2 0xFFF1
#define WDTPS_PS4 0xFFF2
#define WDTPS_PS8 0xFFF3
#define WDTPS_PS16 0xFFF4
#define WDTPS_PS32 0xFFF5
#define WDTPS_PS64 0xFFF6
#define WDTPS_PS128 0xFFF7
#define WDTPS_PS256 0xFFF8
#define WDTPS_PS512 0xFFF9
#define WDTPS_PS1024 0xFFFA
#define WDTPS_PS2048 0xFFFB
#define WDTPS_PS4096 0xFFFC
#define WDTPS_PS8192 0xFFFD
#define WDTPS_PS16384 0xFFFE
#define WDTPS_PS32768 0xFFFF
Edited by Ryang on 2008年09月18日 14:37:39