# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 108
- 109
- 110
- 111
- 112
…
- 365
- 366

MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 110  2012-2013 Microchip Technology Inc.
The SFR variable identifiers are predefined in header files and are accessible once you
have included the <xc.h> header file (see Section 6.3 Device Header Files) into
your source code. Structures with bit-fields are also defined so you may access bits
within a register in your source code.
A linker script file for the appropriate device must be linked into your project to ensure
the SFR variable identifiers are linked to the correct address. MPLAB IDE will link in a
default linker script, but a linker script file must be explicitly specified if you are driving
the command-line toolchain. Linker scripts have a .gld extension (e.g.
p30F6014.gld) and basic files are provided with the compiler.
The convention in the processor header files is that each SFR is named, using the
same name that appears in the data sheet for the part  for example, CORCON for the
Core Control register. If the register has individual bits that might be of interest, then
there will also be a structure defined for that SFR, and the name of the structure will be
the same as the SFR name, with bits appended. For example, CORCONbits for the
Core Control register. The individual bits (or bit-fields) are named in the structure using
the names in the data sheet  for example PSV for the PSV bit of the CORCON
register.
Here is the complete definition of CORCON (subject to change):
/* CORCON: CPU Mode control Register */
extern volatile unsigned int CORCON __attribute__((__sfr__));
typedef struct tagCORCONBITS {
unsigned IF :1; /* Integer/Fractional mode */
unsigned RND :1; /* Rounding mode */
unsigned PSV :1; /* Program Space Visibility enable */
unsigned IPL3 :1;
unsigned ACCSAT :1; /* Acc saturation mode */
unsigned SATDW :1; /* Data space write saturation enable */
unsigned SATB :1; /* Acc B saturation enable */
unsigned SATA :1; /* Acc A saturation enable */
unsigned DL :3; /* DO loop nesting level status */
unsigned :4;
} CORCONBITS;
extern volatile CORCONBITS CORCONbits __attribute__((__sfr__));
See MPLAB XC16 Assembler, Linker and Utilities Users Guide (DS52106) for more
information on using linker scripts.
For example, the following is a sample real-time clock. It uses an SFR, e.g. TMR1, as
well as bits within an SFR, e.g. T1CONbits.TCS. Descriptions for these SFRs are
found in the p30F6014.h file (this file will automatically be included by <xc.h> so you
do not need to include this into your source code). This file would be linked with the
device specific linker script which is p30F6014.gld.
EXAMPLE 6-1: SAMPLE REAL-TIME CLOCK
/*
** Sample Real Time Clock for dsPIC
**
** Uses Timer1, TCY clock timer mode
** and interrupt on period match
*/
#include <xc.h>
Note: The symbols CORCON and CORCONbits refer to the same register and will
resolve to the same address at link time.

- 1
- 2
…
- 108
- 109
- 110
- 111
- 112
…
- 365
- 366