Two types of compiler macros are used to set device Configuration bits: one type for PIC24F MCUs and one type for dsPIC30F and dsPIC33F/PIC24H devices.
Macros are provided in device header files to set Configuration bits:
_confign(value);
where
n |
Configuration register number. |
value |
Expression representing the value to which the specified Configuration bits will be set. May be literal but usually represented by a macro or macros ANDed together. |
Macros are specified in the device header file (*.h
)
that is located in the Windows OS default directory:
C:\Program Files\Microchip\MPLAB C30\support\PIC24F\h
Macro case should match what is in the relevant header. For example,
_CONFIG1
is correct but _config1
is not.
Example – PIC24F MCUs
#include “p24Fxxxx.h”
//JTAG off, Code Protect off, Write Protect off, COE mode off, WDT off
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF )
//Clock switching/monitor off, Oscillator (RC15) on,
// Oscillator in HS mode, Use primary oscillator (no PLL)
_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_ON & POSCMOD_HS & FNOSC_PRI )
Macros are provided in device header files to set Configuration bits:
_reg(value);
where
_reg |
Configuration register name macro. |
value |
Expression representing the value to which the specified Configuration bits will be set. May be literal but usually represented by a macro or macros ANDed together. |
Macros are specified in the device header file (*.h
)
that is located in the Windows OS default directory:
C:\Program Files\Microchip\MPLAB C30\support\device\h
where device
is the abbreviation of the selected
16-bit device, i.e., PIC24H, dsPIC30F, or dsPIC33F.
Macro case should match what is in the relevant header. For example,
_FOSC
is correct but, _fosc
is not.
In the “MPLAB® C Compiler for PIC24 MCUs and dsPIC® DSCs User’s Guide” (DS50001284), see “Configuration Bits Setup Macros.”
Example – dsPIC30F DSCs
#include “p30fxxxx.h”
//Clock switching and failsafe clock monitoring off,
// Oscillator in HS mode
_FOSC(CSW_FSCM_OFF & HS);
//Watchdog timer off
_FWDT(WDT_OFF);
//Brown-out off, Master clear on
_FBORPOR(PBOR_OFF & MCLR_EN);
Example – dsPIC33F/PIC24H Devices
#include “p33fxxxx.h”
// Use primary oscillator (no PLL)
_FOSCSEL(FNOSC_PRI);
//Oscillator in HS mode
_FOSC(POSCMD_HS);
//Watchdog timer off
_FWDT(FWDTEN_OFF);
//JTAG off
_FICD(JTAGEN_OFF);