Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル
製品コード
SW006021-1
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 135
5.3.5
Configuration Bit Access
The PIC devices have several locations which contain the configuration bits or fuses.
These bits specify fundamental device operation, such as the oscillator mode, watch-
dog timer, programming mode and code protection. Failure to correctly set these bits
may result in code failure, or a non-running device.
These bits specify fundamental device operation, such as the oscillator mode, watch-
dog timer, programming mode and code protection. Failure to correctly set these bits
may result in code failure, or a non-running device.
For PIC18 devices, these bits may be set using a configuration pragma. (Pragmas will
also be introduced for other 8-bit devices in future releases.) The pragma has the
following forms.
also be introduced for other 8-bit devices in future releases.) The pragma has the
following forms.
#pragma config setting = state|value
#pragma config register = value
where setting is a configuration setting descriptor, e.g., WDT, and state is a textual
description of the desired state, e.g., OFF. The value field is a numerical value that can
be used in preference to a descriptor.
description of the desired state, e.g., OFF. The value field is a numerical value that can
be used in preference to a descriptor.
Consider the following PIC18-only examples.
#pragma config WDT = ON // turn on watchdog timer
#pragma config WDT = 1 // an alternate form of the above
#pragma config WDTPS = 0x1A // specify the timer postscale value
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.
pair with a comma. For example, the above could be specified with one pragma, as in
the following.
#pragma config WDT=ON, WDTPS = 0x1A
Rather than specify individual settings, the entire register may be programmed with one
numerical value, for example:
numerical value, for example:
#pragma config CONFIG1L = 0x8F
The upper and lower half of each register must be programmed separately.
The settings and values associated with PIC18 devices can be determined from an
HTML guide. Open the file pic18_chipinfo.html, which is located in the DOCS
directory of your compiler installation. Click on your target device and it will show you
the settings and values that are appropriate with this pragma. Check your device data
sheet for more information.
HTML guide. Open the file pic18_chipinfo.html, which is located in the DOCS
directory of your compiler installation. Click on your target device and it will show you
the settings and values that are appropriate with this pragma. Check your device data
sheet for more information.
The configuration bits for baseline and mid-range devices can be set with the
__CONFIG
__CONFIG
macro which was supported in HI-TECH C, for example:
#include <xc.h>
__CONFIG(WDTDIS & HS & UNPROTECT);
To use this macro, ensure you include <xc.h> in your source file. For devices that
have more than one configuration word, each subsequent invocation of __CONFIG()
will modify the next configuration word in sequence. Typically this might look like:
have more than one configuration word, each subsequent invocation of __CONFIG()
will modify the next configuration word in sequence. Typically this might look like:
#include <xc.h>
__CONFIG(WDTDIS & XT & UNPROTECT); // Program config. word 1
__CONFIG(FCMEN);