50002184 b
50002184 b
Migration Guide
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
CERTIFIED BY DNV headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
== ISO/TS 16949 == are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
Table of Contents
Preface ........................................................................................................................... 4
Chapter 1. Migration Overview
1.1 Introduction ..................................................................................................... 8
1.2 Using C18 Compatibility Mode ..................................................................... 10
1.3 Migrating Projects to MPLAB XC8 ............................................................... 11
Chapter 2. Invoking the Compiler
2.1 Introduction ................................................................................................... 13
2.2 General Compiler Usage .............................................................................. 13
2.3 Driver Options .............................................................................................. 16
2.4 MPLINK Options ........................................................................................... 20
Chapter 3. Language Features
3.1 Introduction ................................................................................................... 21
3.2 Operating Modes .......................................................................................... 22
3.3 Memory Models ............................................................................................ 22
3.4 Integer Promotions ....................................................................................... 22
3.5 Device-Specific Information .......................................................................... 23
3.6 Data Types and Limits .................................................................................. 25
3.7 Size Limitations ............................................................................................ 26
3.8 Storage Classes ........................................................................................... 26
3.9 Storage Qualifiers ......................................................................................... 27
3.10 Pointer Storage Qualifiers .......................................................................... 28
3.11 Function Variants ....................................................................................... 29
3.12 Structures and Unions ................................................................................ 30
3.13 Interrupts .................................................................................................... 30
3.14 Locating Objects ......................................................................................... 32
3.15 Function Reentrancy and Calling Conventions .......................................... 34
3.16 The Runtime Startup Code ......................................................................... 37
3.17 Register Usage ........................................................................................... 38
3.18 Preprocessing ............................................................................................ 39
3.19 C and Assembly ......................................................................................... 41
3.20 Linking ........................................................................................................ 44
Glossary ....................................................................................................................... 45
Worldwide Sales and Service .................................................................................... 66
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXXXXA”, where “XXXXXXXX” is the document number and “A” is the revision level
of the document.
For the most up-to-date information on development tools, see the MPLAB® IDE online help.
Select the Help menu, and then Topics to open a list of available online help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
MPLAB® C18 to XC8 C Compiler Migration Guide. Items discussed in this chapter
include:
• Document Layout
• Conventions Used in this Guide
• Recommended Reading
• The Microchip Web Site
• Development Systems Customer Change Notification Service
• Customer Support
• Document Revision History
DOCUMENT LAYOUT
This document describes how to migrate C source code from the MPLAB C18 Compiler
to the MPLAB XC8 C Compiler. This guide is organized as follows:
• Chapter 1. Migration Overview
• Chapter 2. Invoking the Compiler
• Chapter 3. Language Features
• Glossary
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB® IDE User’s Guide
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog
A menu selection select Enable Programmer
Quotes A field name in a window or “Save project before build”
dialog
Underlined, italic text with A menu path File>Save
right angle bracket
Bold characters A dialog button Click OK
A tab Click the Power tab
N‘Rnnnn A number in verilog format, 4‘b0010, 2‘hF1
where N is the total number of
digits, R is the radix and n is a
digit.
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Filenames autoexec.bat
File paths c:\mcc18\h
Keywords _asm, _endasm, static
Command-line options -Opa+, -Opa-
Bit values 0, 1
Constants 0xFF, ‘A’
Italic Courier New A variable argument file.o, where file can be
any valid filename
Square brackets [ ] Optional arguments mcc18 [options] file
[options]
Curly brackets and pipe Choice of mutually exclusive errorlevel {0|1}
character: { | } arguments; an OR selection
Ellipses... Replaces repeated text var_name [,
var_name...]
Represents code supplied by void main (void)
user { ...
}
RECOMMENDED READING
This user’s guide describes migrating MPLAB C18 C projects to the XC8 C compiler.
Other useful documents are listed below. The following Microchip documents are
available and recommended as supplemental reference resources.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in
the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files
contain update information and known issues that may not be included in this migration
guide.
MPLAB X IDE User’s Guide (DS52027)
A guide to using the MPLAB X Integrated Development Environment (IDE).
MPLAB XC8 C Compiler User’s Guide (DS50002053)
A guide to using the MPLAB XC8 C Compiler.
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
1.See the note box in Section 1.2 “Using C18 Compatibility Mode” concerning the avail-
ability of this mode.
Note: 1. This guide assumes you are familiar with MPLAB C18 syntax and features.
This guide is primarily aimed at introducing the equivalent or nearest
MPLAB XC8 syntax or feature, but does not attempt to explain every
aspect of these features. It is important to check the MPLAB XC8 user’s
guide for full information about the features offered by this compiler.
2. The MPLAB C18 compiler can compile functions as being reentrant.
Ensure that you are using a version of MPLAB XC8 that supports
reentrancy, if your project requires this functionality.
3. In addition to PIC18 devices, MPLAB XC8 can compile for all Microchip
8-bit devices, including devices in the baseline and mid-range families.
This guide deals only with PIC18 projects. The features described in this
guide may not be relevant for other devices.
Note: Not all MPLAB C18 assembly language features are available in C18
compatibility mode.
Microchip recommends using compatibility mode to quickly rebuild code with the
MPLAB XC8 compiler or to experiment with this tool. You may also use compatibility
mode as you gain familiarity with the MPLAB XC8 language and environment.
To use compatibility mode, follow these steps:
• Open your existing MPLAB C18 project in MPLAB IDE1.
• Do not change the project toolsuite; continue to use the MPLAB C18 toolsuite.
• Change the path for the MPLAB C18 driver application from being the
mcc18.exe application installed by MPLAB C18 to the identically named replace-
ment application found in your MPLAB XC8 compiler’s bin directory. Also change
the path to the mplink.exe and mplib.exe applications in the same way.
(There is no support for code built with the mpasmwin.exe application).
• Rebuild your code in the usual way.
When you build the project, the IDE will think it is using MPLAB C18, but it will instead be
using the replacement applications provided by MPLAB XC8. When run, these applica-
tions will transcribe the MPLAB C18 options specified in your project to equivalent MPLAB
XC8 options, run the MPLAB XC8 compiler and ensure that the compiler is running in
compatibility mode.
If you are using batch or make files to build your MPLAB C18 projects instead of
MPLAB IDE, you can edit these files so that they execute the replacement applications
provided by MPLAB XC8.
Note: Do not attempt to explicitly run the MPLAB XC8 compiler (xc8) when
compiling MPLAB C18 projects.
Do not manually set any option to indicate C18 compatibility mode.
Only use the replacement applications provided by MPLAB XC8; invoked
from the command line, batch or make files; or from MPLAB IDE.
1.At the time of writing, only MPLAB IDE version 8 can be used to compile legacy projects in C18
compatibility mode.
Not only can the xc8 driver invoke all the compilation steps, it can usually do so in one
command. For example, to compile and link a trivial source file using MPLAB C18, you
might use the commands:
mcc18.exe -p=18F4410 test.c
mplink.exe /p18F4410 /u_CRUNTIME test.o
This can be performed using just one command with MPLAB XC8:
xc8 --chip=18f4410 test.c
If you are using MPLAB X IDE, it is aware of how both compilers operate and always
uses the appropriate command lines.
2.3.6 Diagnostics
Messages are issued by compilers to indicate invalid or suspicious code. A complete
list of all messages is shown in the Error and Warning Messages Appendix of the
MPLAB XC8 C Compiler User’s Guide (DS500002053).
The generation of the assembly list file and output files, such as the COD and HEX files,
is independently controlled using MPLAB XC8, and is an attribute of different internal
applications. Thus, there is no direct counterpart to the MPLAB C18 options such as
/i, /w and /x. However you may control list file generation with the MPLAB XC8
option --ASMIST, and the output file type with --OUTPUT.
Note: Do not be tempted to believe that changing from a smaller to a larger type will
not change the numerical result of an expression. Look especially for cases
where a smaller unsigned type would be promoted to signed int. A change
in operand signedness can lead to a very different expression results.
1.An accurate means of determining the MPLAB XC8 SFR symbol names for the device you are
using is to open the preprocessed file (.pre extension) of any module in your project which in-
cludes the <xc.h> header.
This preprocessed file will contain the C definitions for most device-specific information.
Note 1: The compiler looks for expressions such as c = (c << 1) | (c >> 7); and
encodes these using a rotate instruction.
2: An expression such as (c >> 4) | (c << 4) can swap nibbles in a value.
TIPS: MPLAB XC8 also implements _delay(), _delaywdt(), __delay_us() etc.,
built-in routines associated with delay loops; interrupt enable macros, such as ei()
and di(); and __EEPROM_DATA() for preloading data to EEPROM and
__BUILTIN_SOFTWARE_BREAKPOINT() for inserting software breakpoints.
Note: For each C function, the size, location and the actual instructions
themselves will be different in the assembly generated by MPLAB XC8.
Note: This means that if you never assign an address to a pointer, or only ever
assign a NULL pointer, the MPLAB XC8 compiler will be aware of this fact
as well. In such a case, the compiler could radically optimize the size of the
pointer and how it is dereferenced.
A generic MPLAB XC8 pointer can access any object (of the correct type) regardless
of in which memory space it resides. The same pointer can be used to access both data
and program memory targets.
Use the const and volatile qualifier when defining pointers to indicate their usual
meaning (read-only and do-not-optimize-access, respectively), but all other
non-standard qualifiers should not be used and have no effect. For example, the above
pointer example would be defined as follows when using MPLAB XC8:
char * npsp;
MPLAB C18 pointers will be either 16 or 24 bits wide, based on the qualifiers used
when the pointer is defined. Pointers defined when using MPLAB XC8 will be either 8,
16, or 24 bits wide, based on the addresses assigned to them in the code. Their size is
fixed for the duration of the program, but might change from one build to the next as
source code is developed. Your source code should not be making assumptions as to
the size of a pointer.
3.13 INTERRUPTS
The definitions of interrupt vectors and service routines when using MPLAB XC8 are
different to those applicable for MPLAB C18. Encoding of the service routines also dif-
fers between the two compilers.
The MPLAB C18 compiler expects two functions to be written for each interrupt priority:
one to define the interrupt service routine (ISR), and the other to be linked at the inter-
rupt vector and which will transfer control to the ISR. This is shown in the following
MPLAB C18 example.
#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{
_asm GOTO low_isr _endasm
}
Note: The MPLAB XC8 user’s guide refers to sections as “psect”. This term is
short for “program section”, but is an identical concept to sections used by
MPLAB C18 and other compilers.
If you want to force a function to use the software stack for its auto and parameter vari-
ables, even though it is not reentrantly called in the C program, use the MPLAB XC8
reentrant function specifier.
If a function must use the compiled stack, you can use the nonreentrant function
specifier to indicate this. If such a function is then called from multiple call graphs in the
program (and so needs to be reentrant), the function will be duplicated. This makes
these functions appear to be reentrant. (See the MPLAB XC8 C Compiler User’s Guide
for more information on function duplication.) An error will result if a function specified
nonreentrant is called recursively in your source code.
The MPLAB XC8 option --STACK=compiled (nonreentrant model—you can also use
the alias --STACK=nonreentrant) explicitly states the default stack behavior and
forces all functions to be encoded using the compiled stack, regardless of how they are
called in the program; the option --STACK=software (reentrant model—you can also
use the alias --STACK=reentrant) forces all functions to use the software stack. The
--STACK=hybrid option will encode functions based on how they are called in the
program: functions that are called reentrantly will use the software stack; other func-
tions will use the compiled stack. If the --STACK=compiled option is used and a func-
tion (which does not use the reentrant specifier) is reentrantly called from multiple
call graphs in the program, the function output will be duplicated and both functions will
use the compiled stack. An error will result if a function is called recursively in the pro-
gram and this option is used.
The MPLAB XC8 specifiers described above have precedence over the --STACK
option settings where there is conflict. Thus, you might specify all functions to be non-
reentrant, using the --STACK=compiled option, but allow one function reentrancy by
using the reentrant specifier where you define that function.
You can find out how a function has been encoded, i.e., which stack has been used,
but looking at the function information shown in the assembly list file or in the map file.
The MPLAB XC8 C Compiler User’s Guide has complete information on the layout of
these files.
MPLAB XC8 ensures that these registers will be saved and restored by an ISR if they
are used by C code in that function, or any of the functions called by the ISR. Note that
in-line assembly code is not scanned for register usage.
3.18 PREPROCESSING
There are slight differences in preprocessing and predefined macros between the
MPLAB C18 and XC8 compilers.
Use the __18CXX macro and either the __XC or __XC8 macros to allow code to
compile under both compilers during development. For example:
#ifdef __18CXX
signed int input; // to ensure no integral promotion issues
#elif defined (__XC8)
signed char input;
#elif
#error “What exactly are we using to compile this code?”
#endif
TIPS: There are many more predefined preprocessor macros created by MPLAB XC8.
These are shown in the MPLAB XC8 C Compiler User’s Guide (DS500002053).
The assembler directives used by both assemblers differ. A full list of directives and
controls, and their functions, are given in the Macro Assembler chapter of the MPLAB
XC8 user’s guide. The most common MPLAB XC8 directives needed are the GLOBAL
directive, which allows a symbol to be linked global with other symbols having the same
name, and the PSECT directive (akin to the MPLAB C18 CODE, IDATA and UDATA
directives, for example) which defines a section (or psect as they are referred to in
MPLAB XC8 nomenclature).
Since assembly code must conform to the operation of the assembly code generated
by the C compiler, some restructuring of the assembly will almost certainly be required.
The assembly symbols assigned to C objects and their location in memory can be dif-
ferent. All assembly code for MPLAB XC8 must be contained within a psect (see the
PSECT directive in the MPLAB XC8 user’s guide) and the flags used with these psects
must be appropriate for the information they hold. The most common flags that are nec-
essary for correct operation are reloc, delta and space, all of which are described
in the assembly section of the MPLAB XC8 C Compiler User’s Guide (DS500002053).
Writing code in assembly should be a last resort, as it is far less portable than C code.
Ensure your task is not possible in C code before including assembly code in your proj-
ect. If assembly code is unavoidable, the Macro Assembler chapter of the MPLAB XC8
user’s guide has information on writing in assembly. Also consider looking at the
assembly output of the compiler using the assembly list file to see the assembly code
that the compiler generates. An assembly list file is automatically produced if you are
using MPLAB X IDE. See the --ASMLIST option in the MPLAB XC8 user’s guide if you
are building outside of the IDE.
3.20 LINKING
The MPLAB C18 compiler (specifically, the MPLINK application) uses linker scripts to
indicate how sections should be placed in memory. MPLAB C18 linker scripts are not
compatible with the MPLAB XC8 compiler. Indeed, MPLAB XC8 does not use any type
of file to specify linker settings.
A set of linker options is generated by the MPLAB XC8 driver with each build. These
options are based on the device you select, as well as the other driver options you use
in your project.
These generated linker options control how memory is defined and where psects (sec-
tions) are allocated in that memory. These linker options work in conjunction with flags
specified with the psect definition in the assembly code. The flags indicate special
linking requirements of that psect.
The default linker options generated by the MPLAB XC8 compiler are suitable for the
vast majority of projects. If the application has special requirements, additional linker
options can be added, or the default linker options can be modified using the -L- driver
option. This driver option allows direct control over the linker options without you having
to run the linker directly. (Do not confuse this option with the -L driver option, or the -L
linker option).
If you have not modified the default linker script in your MPLAB C18 project, then the
default linker options in MPLAB XC8 should work for the migrated project. Note that
these are different compilers producing different output, and that the location of objects
and code will change.
If you have modified your MPLAB C18 project so as to specifically locate objects or sec-
tions, then you will need to review your code and MPLAB XC8 project settings. See
Section 3.14 “Locating Objects” for information on making objects absolute, or to
place them in user-defined sections with MPLAB XC8.
Simple modifications made to the MPLAB C18 linker scripts can be transcribed to an
equivalent MPLAB XC8 linker option. As described above, use the -L- driver option to
pass these to the linker, as shown using the following general forms.
The MPLAB C18 SECTION directive (found in a linker script), which has a general form:
SECTION NAME=sectionName ROM=memoryName
would be implemented using the MPLAB XC8 driver option:
-L-psectionName=linkerClass
assuming that sectionName has been defined in C code via the __section() direc-
tive, or in assembly code using the PSECT directive. If linkerClass is not an existing,
compiler-generated linker class, it can be defined with the following driver option:
-L-AlinkerCLass=start-end[,start-end]
If you wish the section to be placed at a specific address (rather than anywhere in an
address range), you can alternatively use:
-L-psectionName=address
See the Linker chapter in the MPLAB XC8 user’s guide for more information on the
linker options which you can control using the -L- driver option. This chapter also has
more information on the linking process and on psects in general.
Glossary
A
Absolute Section
A GCC compiler section with a fixed (absolute) address that cannot be changed by the
linker.
Absolute Variable/Function
A variable or function placed at an absolute address using the OCG compiler’s @ address
syntax.
Access Memory
PIC18 Only – Special registers on PIC18 devices that allow access regardless of the
setting of the Bank Select Register (BSR).
Access Entry Points
Access entry points provide a way to transfer control across segments to a function
which may not be defined at link time. They support the separate linking of boot and
secure application segments.
Address
Value that identifies a location in memory.
Alphabetic Character
Alphabetic characters are those characters that are letters of the arabic alphabet
(a, b, …, z, A, B, …, Z).
Alphanumeric
Alphanumeric characters are comprised of alphabetic characters and decimal digits
(0,1, …, 9).
ANDed Breakpoints
Set up an ANDed condition for breaking, i.e., breakpoint 1 AND breakpoint 2 must
occur at the same time before a program halt. This can only be accomplished if a data
breakpoint and a program memory breakpoint occur at the same time.
Anonymous Structure
16-bit C Compiler – An unnamed structure.
PIC18 C Compiler – An unnamed structure that is a member of a C union. The mem-
bers of an anonymous structure may be accessed as if they were members of the
enclosing union. For example, in the following code, hi and lo are members of an
anonymous structure inside the union caster.
union castaway {
int intval;
struct {
char lo; //accessible as caster.lo
char hi; //accessible as caster.hi
};
} caster;
ANSI
American National Standards Institute is an organization responsible for formulating
and approving standards in the United States.
Application
A set of software and hardware that may be controlled by a PIC microcontroller.
Archive/Archiver
An archive/library is a collection of relocatable object modules. It is created by assem-
bling multiple source files to object files, and then using the archiver/librarian to com-
bine the object files into one archive/library file. An archive/library can be linked with
object modules and other archives/libraries to create executable code.
ASCII
American Standard Code for Information Interchange is a character set encoding that
uses 7 binary digits to represent each character. It includes upper and lower case
letters, digits, symbols and control characters.
Assembly/Assembler
Assembly is a programming language that describes binary machine code in a sym-
bolic form. An assembler is a language tool that translates assembly language source
code into machine code.
Assigned Section
A GCC compiler section which has been assigned to a target memory block in the linker
command file.
Asynchronously
Multiple events that do not occur at the same time. This is generally used to refer to
interrupts that may occur at any time during processor execution.
Asynchronous Stimulus
Data generated to simulate external inputs to a simulator device.
Attribute
GCC characteristics of variables or functions in a C program which are used to describe
machine-specific properties.
Attribute, Section
GCC characteristics of sections, such as “executable”, “readonly”, or “data” that can be
specified as flags in the assembler .section directive.
B
Binary
The base two numbering system that uses the digits 0-1. The rightmost digit counts
ones, the next counts multiples of 2, then 22 = 4, etc.
Breakpoint
Hardware Breakpoint: An event whose execution will cause a halt.
Software Breakpoint: An address where execution of the firmware will halt. Usually
achieved by a special break instruction.
Build
Compile and link all the source files for an application.
C
C\C++
C is a general-purpose programming language which features economy of expression,
modern control flow and data structures, and a rich set of operators. C++ is the
object-oriented version of C.
Calibration Memory
A special function register or registers used to hold values for calibration of a PIC micro-
controller on-board RC oscillator or other device peripherals.
Central Processing Unit
The part of a device that is responsible for fetching the correct instruction for execution,
decoding that instruction, and then executing that instruction. When necessary, it works
in conjunction with the arithmetic logic unit (ALU) to complete the execution of the
instruction. It controls the program memory address bus, the data memory address
bus, and accesses to the stack.
Clean
Clean removes all intermediary project files such as object, hex and debug files for the
active project. These files are recreated from other files when a project is built.
COFF
Common Object File Format. An object file of this format contains machine code,
debugging and other information.
Command Line Interface
A means of communication between a program and its user based solely on textual
input and output.
Compiled Stack
A region of memory managed by the compiler in which variables are statically allocated
space. It replaces a software or hardware stack when such mechanisms cannot be effi-
ciently implemented on the target device.
Compiler
A program that translates a source file written in a high-level language into machine
code.
Conditional Assembly
Assembly language code that is included or omitted based on the assembly-time value
of a specified expression.
Conditional Compilation
The act of compiling a program fragment only if a certain constant expression, specified
by a preprocessor directive, is true.
Configuration Bits
Special-purpose bits programmed to set PIC microcontroller modes of operation. A
Configuration bit may or may not be preprogrammed.
Control Directives
Directives in assembly language code that cause code to be included or omitted based
on the assembly-time value of a specified expression.
CPU
See Central Processing Unit.
E
EEPROM
Electrically Erasable Programmable Read Only Memory. A special type of PROM that
can be erased electrically. Data is written or erased one byte at a time. EEPROM
retains its contents even when power is turned off.
ELF
Executable and Linking Format. An object file of this format contains machine code.
Debugging and other information is specified in with DWARF. ELF/DWARF provide
better debugging of optimized code than COFF.
Emulation/Emulator
See ICE/ICD.
Endianness
The ordering of bytes in a multi-byte object.
Environment
MPLAB PM3 – A folder containing files on how to program a device. This folder can be
transferred to a SD/MMC card.
Epilogue
A portion of compiler-generated code that is responsible for deallocating stack space,
restoring registers and performing any other machine-specific requirement specified in
the runtime model. This code executes after any user code for a given function,
immediately prior to the function return.
EPROM
Erasable Programmable Read Only Memory. A programmable read-only memory that
can be erased usually by exposure to ultraviolet radiation.
Error/Error File
An error reports a problem that makes it impossible to continue processing your pro-
gram. When possible, an error identifies the source file name and line number where
the problem is apparent. An error file contains error messages and diagnostics gener-
ated by a language tool.
Event
A description of a bus cycle which may include address, data, pass count, external
input, cycle type (fetch, R/W), and time stamp. Events are used to describe triggers,
breakpoints and interrupts.
Executable Code
Software that is ready to be loaded for execution.
Export
Send data out of the MPLAB IDE in a standardized format.
Expressions
Combinations of constants and/or symbols separated by arithmetic or logical
operators.
Extended Microcontroller Mode
In extended microcontroller mode, on-chip program memory as well as external mem-
ory is available. Execution automatically switches to external if the program memory
address is greater than the internal memory space of the PIC18 device.
Import
Bring data into the MPLAB IDE from an outside source, such as from a hex file.
Initialized Data
Data which is defined with an initial value. In C,
int myVar=5;
defines a variable which will reside in an initialized data section.
Instruction Set
The collection of machine language instructions that a particular processor
understands.
Instructions
A sequence of bits that tells a central processing unit to perform a particular operation
and can contain data to be used in the operation.
Internal Linkage
A function or variable has internal linkage if it can not be accessed from outside the
module in which it is defined.
International Organization for Standardization
An organization that sets standards in many businesses and technologies, including
computing and communications. Also known as ISO.
Interrupt
A signal to the CPU that suspends the execution of a running application and transfers
control to an Interrupt Service Routine (ISR) so that the event may be processed. Upon
completion of the ISR, normal execution of the application resumes.
Interrupt Handler
A routine that processes special code when an interrupt occurs.
Interrupt Service Request (IRQ)
An event which causes the processor to temporarily suspend normal instruction exe-
cution and to start executing an interrupt handler routine. Some processors have
several interrupt request events allowing different priority interrupts.
Interrupt Service Routine (ISR)
Language tools – A function that handles an interrupt.
MPLAB IDE – User-generated code that is entered when an interrupt occurs. The
location of the code in program memory will usually depend on the type of interrupt that
has occurred.
Interrupt Vector
Address of an interrupt service routine or interrupt handler.
L
L-value
An expression that refers to an object that can be examined and/or modified. An l-value
expression is used on the left-hand side of an assignment.
Latency
The time between an event and its response.
Library/Librarian
See Archive/Archiver.
Macro
Macro instruction. An instruction that represents a sequence of instructions in
abbreviated form.
Macro Directives
Directives that control the execution and data allocation within macro body definitions.
Makefile
Export to a file the instructions to Make the project. Use this file to Make your project
outside of MPLAB IDE, i.e., with a make.
Make Project
A command that rebuilds an application, recompiling only those source files that have
changed since the last complete compilation.
MCU
Microcontroller Unit. An abbreviation for microcontroller. Also uC.
Memory Model
For C compilers, a representation of the memory available to the application. For the
PIC18 C compiler, a description that specifies the size of pointers that point to program
memory.
Message
Text displayed to alert you to potential problems in language tool operation. A message
will not stop operation.
Microcontroller
A highly integrated chip that contains a CPU, RAM, program memory, I/O ports and
timers.
Microcontroller Mode
One of the possible program memory configurations of PIC18 microcontrollers. In
microcontroller mode, only internal execution is allowed. Thus, only the on-chip pro-
gram memory is available in microcontroller mode.
Microprocessor Mode
One of the possible program memory configurations of PIC18 microcontrollers. In
microprocessor mode, the on-chip program memory is not used. The entire program
memory is mapped externally.
Mnemonics
Text instructions that can be translated directly into machine code. Also referred to as
opcodes.
Module
The preprocessed output of a source file after preprocessor directives have been
executed. Also known as a translation unit.
MPASM™ Assembler
Microchip Technology’s relocatable macro assembler for PIC microcontroller devices,
KeeLoq® devices and Microchip memory devices.
MPLAB Language Tool for Device
Microchip’s C compilers, assemblers and linkers for specified devices. Select the type
of language tool based on the device you will be using for your application, e.g., if you
will be creating C code on a PIC18 MCU, select the MPLAB C Compiler for PIC18
MCUs.
NOP
No Operation. An instruction that has no effect when executed except to advance the
program counter.
O
Object Code/Object File
Object code is the machine code generated by an assembler or compiler. An object file
is a file containing machine code and possibly debug information. It may be immediately
executable or it may be relocatable, requiring linking with other object files, e.g., libraries,
to produce a complete executable program.
Object File Directives
Directives that are used only when creating an object file.
Octal
The base 8 number system that only uses the digits 0-7. The rightmost digit counts
ones, the next digit counts multiples of 8, then 82 = 64, etc.
Off-Chip Memory
Off-chip memory refers to the memory selection option for the PIC18 device where
memory may reside on the target board, or where all program memory may be supplied
by the emulator. The Memory tab accessed from Options>Development Mode provides
the Off-Chip Memory selection dialog box.
Opcodes
Operational Codes. See Mnemonics.
Operators
Symbols, like the plus sign ‘+’ and the minus sign ‘-’, that are used when forming
well-defined expressions. Each operator has an assigned precedence that is used to
determine order of evaluation.
OTP
One Time Programmable. EPROM devices that are not in windowed packages. Since
EPROM needs ultraviolet light to erase its memory, only windowed devices are erasable.
P
Pass Counter
A counter that decrements each time an event (such as the execution of an instruction
at a particular address) occurs. When the pass count value reaches zero, the event is
satisfied. You can assign the Pass Counter to break and trace logic, and to any
sequential event in the complex trigger dialog.
PC
Personal Computer or Program Counter.
PC Host
Any PC running a supported Windows operating system.
Persistent Data
Data that is never cleared or initialized. Its intended use is so that an application can
preserve data across a device reset.
Phantom Byte
An unimplemented byte in the dsPIC architecture that is used when treating the 24-bit
instruction word as if it were a 32-bit instruction word. Phantom bytes appear in dsPIC
hex files.
Prologue
A portion of compiler-generated code that is responsible for allocating stack space, pre-
serving registers and performing any other machine-specific requirement specified in
the runtime model. This code executes before any user code for a given function.
Prototype System
A term referring to a user’s target application, or target board.
Psect
The OCG equivalent of a GCC section, short for program section. A block of code or
data which is treated as a whole by the linker.
PWM Signals
Pulse Width Modulation Signals. Certain PIC MCU devices have a PWM peripheral.
Q
Qualifier
An address or an address range used by the Pass Counter or as an event before
another operation in a complex trigger.
R
Radix
The number base, hex, or decimal, used in specifying an address.
RAM
Random Access Memory (Data Memory). Memory in which information can be
accessed in any order.
Raw Data
The binary representation of code or data associated with a section.
Read-Only Memory
Memory hardware that allows fast access to permanently stored data but prevents
addition to or modification of the data.
Real Time
When an in-circuit emulator or debugger is released from the halt state, the processor
runs in Real Time mode and behaves exactly as the normal chip would behave. In Real
Time mode, the real-time trace buffer of an emulator is enabled and constantly cap-
tures all selected cycles, and all break logic is enabled. In an in-circuit emulator or
debugger, the processor executes in real time until a valid breakpoint causes a halt, or
until the user halts the execution.
In the simulator, real time simply means execution of the microcontroller instructions as
fast as they can be simulated by the host CPU.
Recursive Calls
A function that calls itself, either directly or indirectly.
Recursion
The concept that a function or macro, having been defined, can call itself. Great care
should be taken when writing recursive macros; it is easy to get caught in an infinite
loop where there will be no exit from the recursion.
Reentrant
A function that may have multiple, simultaneously active instances. This may happen
due to either direct or indirect recursion or through execution during interrupt
processing.
Simulator
A software program that models the operation of devices.
Single Step
This command steps though code, one instruction at a time. After each instruction,
MPLAB IDE updates register windows, watch variables, and status displays so you can
analyze and debug instruction execution. You can also single step C compiler source
code, but instead of executing single instructions, MPLAB IDE will execute all assembly
level instructions generated by the line of the high level C statement.
Skew
The information associated with the execution of an instruction appears on the proces-
sor bus at different times. For example, the executed opcodes appears on the bus as
a fetch during the execution of the previous instruction, the source data address and
value and the destination data address appear when the opcodes is actually executed,
and the destination data value appears when the next instruction is executed. The trace
buffer captures the information that is on the bus at one instance. Therefore, one trace
buffer entry will contain execution information for three instructions. The number of cap-
tured cycles from one piece of information to another for a single instruction execution
is referred to as the skew.
Skid
When a hardware breakpoint is used to halt the processor, one or more additional
instructions may be executed before the processor halts. The number of extra
instructions executed after the intended breakpoint is referred to as the skid.
Source Code
The form in which a computer program is written by the programmer. Source code is
written in a formal programming language which can be translated into machine code
or executed by an interpreter.
Source File
An ASCII text file containing source code.
Special Function Registers (SFRs)
The portion of data memory (RAM) dedicated to registers that control I/O processor
functions, I/O status, timers or other modes or peripherals.
SQTP
See Serialized Quick Turn Programming.
Stack, Hardware
Locations in PIC microcontrollers where the return address is stored when a function
call is made.
Stack, Software
Memory used by an application for storing return addresses, function parameters, and
local variables. This memory is dynamically allocated at runtime by instructions in the
program. It allows for reentrant function calls.
Stack, Compiled
A region of memory managed and allocated by the compiler in which variables are stat-
ically assigned space. It replaces a software stack when such mechanisms cannot be
efficiently implemented on the target device. It precludes reentrancy.
MPLAB Starter Kit for Device
Microchip’s starter kits contains everything needed to begin exploring the specified
device. View a working application and then debug and program your own changes.
Target Application
Software residing on the target board.
Target Board
The circuitry and programmable device that makes up the target application.
Target Processor
The microcontroller device on the target application board.
Template
Lines of text that you build for inserting into your files at a later time. The MPLAB Editor
stores templates in template files.
Tool Bar
A row or column of icons that you can click on to execute MPLAB IDE functions.
Trace
An emulator or simulator function that logs program execution. The emulator logs program
execution into its trace buffer which is uploaded to MPLAB IDE’s trace window.
Trace Memory
Trace memory contained within the emulator. Trace memory is sometimes called the
trace buffer.
Trace Macro
A macro that will provide trace information from emulator data. Since this is a software
trace, the macro must be added to code, the code must be recompiled or reassembled,
and the target device must be programmed with this code before trace will work.
Trigger Output
Trigger output refers to an emulator output signal that can be generated at any address
or address range, and is independent of the trace and breakpoint settings. Any number
of trigger output points can be set.
Trigraphs
Three-character sequences, all starting with ??, that are defined by ISO C as
replacements for single characters.
U
Unassigned Section
A section which has not been assigned to a specific target memory block in the linker
command file. The linker must find a target memory block in which to allocate an
unassigned section.
Uninitialized Data
Data which is defined without an initial value. In C,
int myVar;
defines a variable which will reside in an uninitialized data section.
Upload
The Upload function transfers data from a tool, such as an emulator or programmer, to
the host PC or from the target board to the emulator.
USB
Universal Serial Bus. An external peripheral interface standard for communication
between a computer and external peripherals over a cable using bi-serial transmission.
USB 1.0/1.1 supports data transfer rates of 12 Mbps. Also referred to as high-speed
USB, USB 2.0 supports data rates up to 480 Mbps.
V
Vector
The memory locations that an application will jump to when either a reset or interrupt
occurs.
Volatile
A variable qualifier which prevents the compiler applying optimizations that affect how
the variable is accessed in memory.
W
Warning
MPLAB IDE – An alert that is provided to warn you of a situation that would cause physical
damage to a device, software file, or equipment.
16-bit assembler/compiler – Warnings report conditions that may indicate a problem,
but do not halt processing. In MPLAB C30, warning messages report the source file
name and line number, but include the text ‘warning:’ to distinguish them from error
messages.
Watch Variable
A variable that you may monitor during a debugging session in a Watch window.
Watch Window
Watch windows contain a list of watch variables that are updated at each breakpoint.
Watchdog Timer (WDT)
A timer on a PIC microcontroller that resets the processor after a selectable length of
time. The WDT is enabled or disabled and set up using Configuration bits.
Workbook
For MPLAB SIM stimulator, a setup for generation of SCL stimulus.
Index
Symbols E
__section() specifier ............................................................ 32 ELF files.............................................................................. 14
_asm directive ..................................................................... 42 entry function ...................................................................... 37
#asm directive ..................................................................... 42 errors ............................................................................ 18, 19
extended instruction set................................................ 17, 41
A extended mode ................................................................... 22
absolute functions ............................................................... 32 external memory ................................................................. 18
absolute variables ............................................................... 32
anonymous structures......................................................... 30 F
asm statement .................................................................... 42 fake mcc18 driver ............................................................... 10
aspic18 application ............................................................. 41 far qualifier (MPLAB C18)................................................... 27
assembler applications ....................................................... 41 far qualifier (MPLAB XC8) .................................................. 18
assembly code .............................................................. 12, 41 FCALL instruction ............................................................... 41
assembly instruction destination specifier........................... 41 floating-point data types ..................................................... 25
assembly symbols............................................................... 41 function calling convention.................................................. 36
auto specifier................................................................. 26, 34 function parameters ............................................................ 36
function return values ......................................................... 36
B function variants ................................................................. 29
bankx qualifiers ................................................................... 32
bit data type ........................................................................ 25 G
bit-fields............................................................................... 30 GLOBAL assembler directive ............................................. 42
bootloaders ......................................................................... 18
H
C header files ......................................................................... 23
C and assembly .................................................................. 41 hybrid stack model.............................................................. 34
C18 compatibility mode................................................... 8, 10
CCI ...................................................................................... 12 I
char data type ..................................................................... 25 IDATA assembler directive ................................................. 42
clearing static objects.......................................................... 37 idata pragma....................................................................... 32
ClrWdt macro ...................................................................... 24 implementation defined behavior........................................ 11
code pragma ................................................................. 30, 32 indicating object locations................................................... 33
CODEassembler directive................................................... 42 in-line assembly .................................................................. 42
COFF files ........................................................................... 14 instruction set ..................................................................... 22
command-line applications ................................................. 13 integer promotions ........................................................ 11, 22
command-line format .......................................................... 14 intermediate files................................................................. 14
command-line options ......................................................... 16 Internet Address ................................................................... 6
common C interface ............................................................ 12 interrupt specifier ................................................................ 30
compiled stack .................................................................... 34 interrupts............................................................................. 30
compiler messages ............................................................. 18
compiler-managed resources ............................................. 38
L
config pragma ..................................................................... 23 library files..................................................................... 12, 14
configuration bits ................................................................. 23 linker options to position sections ....................................... 32
const qualifier ...................................................................... 27 linker scripts............................................................ 12, 18, 44
Customer Notification Service............................................... 7 linking ................................................................................. 44
Customer Support ................................................................. 7 LJMP instruction ................................................................. 41
locating objects ................................................................... 32
D low_priority specifier ........................................................... 30
data stack...................................................................... 17, 34
data types ........................................................................... 25
M
delay built-ins, EEPROM data ............................................ 24 macros .......................................................................... 24, 39
Documentation macros with variable argument lists.................................... 40
Conventions .................................................................. 5 maximum function size ....................................................... 26
Layout ........................................................................... 4 maximum object size .......................................................... 26
driver applications ............................................................... 13 mcc18 application ............................................................... 13
driver options ...................................................................... 16 mcc18 driver ....................................................................... 10
memory
external....................................................................... 18
O U
object files ........................................................................... 12 UDATA assembler directive................................................ 42
operating modes ................................................................. 22 udata pragma ..................................................................... 32
optimizations ....................................................................... 18 union types ......................................................................... 30
options ................................................................................ 16 unused memory .................................................................. 18
overlay specifier ............................................................ 26, 34 USB .................................................................................... 62
P V
parameters .......................................................................... 36 varlocate pragma ................................................................ 33
p-code files.......................................................................... 14
p-code libraries ................................................................... 14 W
placing objects at an address ............................................. 32 warnings ....................................................................... 18, 19
placing objects in a bank..................................................... 32 Watchdog Timer ................................................................. 63
pointer sizes ........................................................................ 28 WWW Address ..................................................................... 6
pointer storage qualifiers..................................................... 28
pointer variables.................................................................. 22
X
powerup routine .................................................................. 37 xc.h header ......................................................................... 23
predefined macros ........................................................ 24, 39 xc.inc header ...................................................................... 23
preprocessing ..................................................................... 39
preprocessor commands .................................................... 18
preprocessor macros .......................................................... 39
project migration ................................................................... 8
PSECT assembler directive ................................................ 42
R
ram qualifier ........................................................................ 27
Reading, Recommended ...................................................... 6
reentrancy ........................................................................... 34
reentrant specifier ............................................................... 35
register usage ..................................................................... 38
registers .............................................................................. 23
regsused pragma ................................................................ 31
reserving memory ............................................................... 18
RETFIE instruction .............................................................. 41
return values ....................................................................... 36
Rlcf macro ........................................................................... 24
rom qualifier ........................................................................ 27
romdata pragma.................................................................. 32
RUNTIME driver option ....................................................... 37
runtime startup code ........................................................... 37
S
SECTION linker script directive .......................................... 44
sectiontype pragma............................................................. 32
SFRs ................................................................................... 23
short long int type................................................................ 25
size limitations..................................................................... 26
size of data types ................................................................ 25