7.3 Configuration Bit Access

The #pragma config directive specifies the Configuration Words to be programmed into the device running the application. This pragma can be used with either C or C++ programs.

All 32-bit target devices have several Configuration Words. The bits within these words control fundamental device operation, such as the oscillator mode, watchdog timer, programming mode and code protection. Failure to correctly set these bits may result in code failure, or a non-running device.

The config pragma has the following general form:
#pragma config setting = value
where setting is a configuration word bit-field name, e.g., WDT_ENABLE, and value can be either a textual description of the desired state, e.g., CLEAR, or a numerical value, as required by the setting. Multiple pragmas may be used to incrementally specify the complete device state; however, more than one comma-separated setting-value pair may be specified with each pragma.
The following example shows some pragmas relevant for a SAME54P20A device. You can find the configuration word bit-field names used in the setting descriptor from the Configuration Bits view in the MPLAB X IDE.
#pragma config BOD33_DIS = SET
#pragma config BOD33USERLEVEL = 0x1c, BOD33_ACTION = RESET
#pragma config WDT_PER = CYC8192

The #pragma config directives should be specified in only a single translation unit, or module. They should be placed outside of a function definition, as they do not define executable code.

The compiler verifies that the configuration settings specified are valid for the target device. If a given setting in the Configuration word has not been specified in any #pragma config directive, the bits associated with that setting default to the unprogrammed value. It is recommended that all Configuration Words are explicitly programmed to ensure correct device operation.

The config pragma can be used with those devices whose configuration locations must be addressed at the byte level instead of the (4-byte) word level.

In cases where the same configuration word bit-field name is used by more than one configuration setting in different Configuration Words, a more qualified name can be used. The configuration word bit-field (e.g. BOD33_DIS) can be prefixed with the register name (e.g. USER_WORD_0) separated by an underscore character, as in, USER_WORD_0_BOD33_DIS. If further clarification is required, the setting can be additionally prefixed with the register-group address space (e.g. fuses) and an underscore character, as in, fuses_USER_WORD_0_BOD33_DIS. The pragmas in the above example could be rewritten using longer forms of the setting descriptor if desired and as follows (although such names are not necessary when using this device):
#pragma config USER_WORD_0_BOD33_DIS = SET
#pragma config fuses_USER_WORD_0_BOD33USERLEVEL = 0x1c, fuses_USER_WORD_0_BOD33_ACTION = RESET
#pragma config USER_WORD_1_WDT_PER = CYC8192
The compiler will emit an error and make suggestions if a fully qualified name was not used but is required.