4.2.4 Configuration Bit Access
Configuration bits or fuses are used to set up fundamental device operation, such as the oscillator mode, watchdog timer, programming mode, and lockbit code protection. These bits must be correctly set to ensure your program executes correctly.
Use the configuration pragma, which has the following form, to set up your device.
#pragma config setting = state|value
Here, setting
is a configuration setting
descriptor, e.g., WDT
, and state
is a textual
description of the desired state, e.g., SET
. Those states other than
SET
and CLEAR
are prefixed with the setting
descriptor, as in BODLEVEL_4V3
, as shown in the following examples.
#pragma config WDTON = SET
#pragma config EESAVE = CLEAR
#pragma config BODLEVEL = BODLEVEL_4V3
#pragma config LB = LB_NO_LOCK
The settings and states associated with each device can be determined from
an HTML guide. Open the avr_chipinfo.html
file that is located in the
docs directory of your compiler installation. Click the link to
your target device and the page will show you the settings and values that are appropriate
with this pragma. Review your device data sheet for more information.
One pragma can be used to program several settings by separating each setting-value pair with a comma. For example, the above could be specified with one pragma, as in the following.
#pragma config WDTON=SET, EESAVE=CLEAR, BODLEVEL=BODLEVEL_4V3, LB=LB_NO_LOCK
The value
field is a constant that can be used in
preference to a descriptor, as in the following.
#pragma config SUT_CKSEL = 0x10
Setting-value pairs are not scanned by the preprocessor and they are not subject to macro substitution. The setting-value pairs must not be placed in quotes.
The config
pragma does not produce executable code, and
ideally it should be placed outside function definitions.
Those bits not specified by a pragma are assigned a default value. Rather than rely on this default value, all the bits in the Configuration Words should be programmed to prevent erratic program behavior.