Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 56
 2012 Microchip Technology Inc.
3.5
GETTING MY APPLICATION TO DO WHAT I WANT
This section provides programming techniques, applications and examples. It also 
examines questions that relate to making an application perform a specific task.
3.5.1
What Can Cause Glitches on Output Ports?
In most cases, this is caused by using ordinary variables to access port bits or the entire 
port itself. These variables should be qualified volatile.
The value stored in a variable mapped over a port (hence the actual value written to 
the port) directly translates to an electrical signal. It is vital that the values held by these 
variables only change when the code intends them to, and that they change from their 
current state to their new value in a single transition. See Section 5.4.7.2 “Volatile 
Type Qualifier”
. The compiler attempts to write to volatile variables in one operation.
3.5.2
How Do I Link Bootloaders and Downloadable Applications?
Exactly how this is done depends on the device you are using and your project require-
ments, but the general approach when compiling applications that use a bootloader is 
to allocate discrete program memory space to the bootloader and application so they 
have their own dedicated memory. In this way the operation of one cannot affect the 
other. This will require that either the bootloader or the application is offset in memory. 
That is, the Reset and interrupt location are offset from address 0 and all program code 
is offset by the same amount. 
On PIC18 devices, typically the application code is offset, and the bootloader is linked 
with no offset so that it populates the Reset and interrupt code locations. The boot-
loader Reset and interrupt code merely contains code which redirects control to the real 
Reset and interrupt code defined by the application and which is offset.
On mid-range devices, this is not normally possible to perform when interrupts are 
being used. Consider offsetting all of the bootloader with the exception of the code 
associated with Reset, which must always be defined by the bootloader. The applica-
tion code can define the code linked at the interrupt location. The bootloader will need 
to remap any application code that attempts to overwrite the Reset code defined by the 
bootloader.
The option --CODEOFFSET, see Section 4.8.22 “--CODEOFFSET: Offset Program 
Code to Address”
, al
lows the program code (Reset and vectors included) to be 
moved by a specified amount. The option also restricts the program from using any pro-
gram memory from address 0 (Reset vector) to the offset address. Always check the 
map file, see Section 7.4.2 “Contents”, to ensure that nothing remains in reserved 
areas.