Two types of assembler directives are used to set device configuration
bits: __config
and config
. DO NOT mix
__config
and config
in the same code.
The directive __config
is used for PIC10/12/16 MCUs.
It may be used for PIC18 MCUs (excluding PIC18FXXJ devices) but the
config
directive is recommended. The syntax is as follows:
__config expr ;For a single configuration word
or
__config addr, expr ;For multiple configuration word
where:
addr |
Address of the
Configuration Word. May be literal but usually represented by a
macro. Note: Macros must be listed in ascending register
order.
|
expr |
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 include file
(*.inc
) that is located in the Windows operating system (OS) default
directory:
C:\Program Files\Microchip\MPLABX\mpasmx
Directive case does not matter; __CONFIG
or
__config
is acceptable. Macro case should match what is in the
header.
In the “MPASM Assembler, MPLINK Object Linker, MPLIB Object Librarian User’s Guide” (DS30003014), see “__config - Set Processor Configuration Bits.”
Example – PIC10/12/16 MCUs
#include p16f877a.inc
;Set oscillator to HS, watchdog time off, low-voltage prog. off
__CONFIG _HS_OSC & _WDT_OFF & _LVP_OFF
Example – PIC18 MCUs
#include p18f452.inc
;Oscillator switch enabled, RC oscillator with OSC2 as I/O pin.
__CONFIG _CONFIG1, _OSCS_OFF_1 & _RCIO_OSC_1
;Watch Dog Timer enable, Watch Dog Timer PostScaler count - 1:128
__CONFIG _CONFIG3, _WDT_ON_3 & _WDTPS_128_3
The directive config
is used for PIC18 MCUs (including
PIC18FXXJ devices). The syntax is as follows:
config setting=value [, setting=value]
where:
setting |
Macro representing a Configuration bit or bits. |
value |
Macro representing the value to which the specified Configuration bit(s) will be set. Multiple settings may be defined on a single line, separated by commas. Settings for a single configuration byte may also be defined on separate lines. |
Macros are specified in the device include file (*.inc) that is located in the Windows OS default directory:
C:\Program Files\Microchip\MPLABX\mpasmx
Directive case does not matter; __CONFIG or __config is acceptable. Macro case should match what is in the header.
In the “MPASM Assembler, MPLINK Object Linker, MPLIB Object Librarian User’s Guide” (DS30003014), see “config - Set Processor Configuration Bits (PIC18 MCUs).”
Example – PIC18 MCUs
#include p18f452.inc
;Oscillator switch enabled, RC oscillator with OSC2 as I/O pin.
CONFIG OSCS=ON, OSC=LP
;Watch Dog Timer enable, Watch Dog Timer PostScaler count - 1:128
CONFIG WDT=ON, WDTPS=128