24.4.14 Specifying Configuration Bits
The #pragma config
directive can be used to program the Configuration
bits for a device. The pragma has the form:
#pragma config setting =
state|value
where setting
is a configuration setting descriptor
(for example, WDT
), state
is a
descriptive value (for example, ON
) and
value
is a numerical value.
Use the native keywords discussed in the Differences section to look up information on the semantics of this directive.
Example
The following shows Configuration bits being specified using this pragma.
#pragma config WDT=ON, WDTPS = 0x1A
Differences
When targeting PIC MCUs, MPLAB XC8 has provided a legacy __CONFIG()
macro, but more recently has accepted #pragma config
. When targeting
AVR devices, it has used a predefined FUSES
structure to allow the
configuration bits to be specified.
The MPLAB XC16 and XC-DSC compilers have used a number of macros to specify the configuration settings.
The MPLAB XC32 compiler has supported the use of #pragma config
.
Migration to the CCI
When building for PIC MCUs with MPLAB XC8, change any occurrence of the
__CONFIG()
macro, for example,
__CONFIG(WDTEN & XT & DPROT)
to the #pragma config
directive, for example:
#pragma config WDTE=ON, FOSC=XT, CPD=ON
FUSES
structure, for
example:#include <avr/io.h>
FUSES = {
.high = (FUSE_SPIEN)
};
to:#pragma config SPIEN=SET
For the MPLAB XC16 and XC-DSC compilers, change any occurrence of the
_FOSC()
or _FBORPOR()
macros attribute, for
example, from:
_FOSC(CSW_FSCM_ON & EC_PLL16);
to:
#pragma config FCKSMEM = CSW_ON_FSCM_ON, FPR = ECIO_PLL16
No migration is required for 32-bit code.
Caveats
None.