Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 139
5.3.7
ID Locations
The 8-bit PIC devices have locations outside the addressable memory area that can be 
used for storing program information, such as an ID number. For PIC18 devices, the 
config
 pragma is also used to place data into these locations by using a special 
register name. The pragma is used as follows.
#pragma config IDLOCx = value
where x is the number (position) of the ID location, and value is the nibble or byte 
which is to be positioned into that ID location. If value is larger than the maximum 
value allowable for each location on the target device, the value will be truncated and 
a warning message issued. The size of each ID location varies from device to device. 
See your device data sheet for more information.
For example:
#pragma config IDLOC0 = 1
#pragma config IDLOC1 = 4
will attempt fill the first two ID locations with 1 and 4. One pragma can be used to pro-
gram several locations by separating each register-value pair with a comma. For 
example, the above could also be specified as shown below.
#pragma config IDLOC0 = 1, IDLOC1 = 4
The config pragma does not produce executable code and so should ideally be placed 
outside function definitions.
The compiler also has legacy support for the __IDLOC macro. This macro must be 
used for baseline and mid-range devices. The macro is used in a manner similar to:
#include <xc.h>
__IDLOC(x);
where x is a list of nibbles which are positioned into the ID locations. Only the lower 
four bits of each ID location is programmed, so the following:
__IDLOC(15F0);
will attempt to fill ID locations with the values: 1, 5, F and 0.
To use this macro, ensure you include <xc.h> in your source file.
The __IDLOC macro does not produce executable code and so should ideally be 
placed outside function definitions.
Some devices permit programming up to seven bits within each ID location. The 
__IDLOC()
 macro is not suitable for such devices and the __IDLOC7(a,b,c,d
macro should be used instead. The parameters a to d are the values to be pro-
grammed. The values can be entered in either decimal or hexadecimal format, such as:
__IDLOC7(0x7f,1,70,0x5a);
It is not appropriate to use the __IDLOC7() macro on a device that does not permit 
seven-bit programming of ID locations.