Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•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 Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of
patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical
components in life support systems is not authorized except
with express written approval by Microchip. No licenses are
conveyed, implicitly or otherwise, under any intellectual
property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, MXDEV, MXLAB, PICMASTER, SEEVAL,
SmartSensor and The Embedded Control Solutions Company
are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Migratable Memory, MPASM,
MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net,
PICLAB, PICtail, PowerCal, PowerInfo, PowerMate,
PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial,
SmartTel and Total Endurance are trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
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.
®
8-bit MCUs, KEELOQ
®
code hopping
DS39637A-page iiPreliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
28/40/44-Pin Enhanced Flash Microcontrollers with
ECAN™ Technology, 10-Bit A/D and nanoWatt Technology
Power Managed Modes:
• Run: CPU on, peripherals on
• Idle: CPU off, peripherals on
• Sleep: CPU off, peripherals off
• Idle mode currents down to 5.8 µA typical
• Sleep mode current down to 0.1 µA typical
• Timer1 Oscillator: 1.1 µA, 32 kHz, 2V
• Watchdog Timer: 2.1 µA
• Two-Speed Oscillator Start-up
Flexible Oscillator Struc ture:
• Four Crystal modes, up to 40 MHz
• 4X Phase Lock Loop (PLL) – available for crystal
and internal oscillators)
• Two External RC modes, up to 4 MHz
• Two External Clock modes, up to 40 MHz
• Internal oscillator block:
- 8 user selectable frequencies, from 31 kHz to 8 MHz
- Provides a complete range of clock speeds,
from 31 kHz to 32 MHz when used with PLL
- User tunable to compensate for frequency drift
• Secondary oscillator using Timer1 @ 32 kHz
• Fail-Safe Clock Monitor
- Allows for safe shutdown if peripheral clock stops
Special Microcontroller Features:
• C compiler optimized architecture with optional
extended instruction set
• 100,000 erase/write cycle Enhanced Flash
program memory typica l
• 1,000,000 erase/write cycle Data EEPROM
memory typical
• Flash/Data EEPROM Retention: > 40 years
• Self-programmable under software control
• Priority levels for interrupts
• 8 x 8 Single C y cle Hardwa re Multiplier
• Extended Watchdog Timer (WDT):
- Programmable period from 41 ms to 131s
• Single-Supply 5V In-Circuit Serial
Programming™ (ICSP™) via two pins
6.0Flash Program Memory............... ................. ..............................................................................................................................95
17.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 187
24.0 Special Features of the CPU.............. ................ ...................................................................................................................... 343
25.0 Instruction Set Summary..........................................................................................................................................................361
26.0 Development Support............................................................................................................................................................... 411
28.0 DC and AC Characteristics Graphs and Tables....................................................................................................................... 453
29.0 Packaging Informa tio n..... ................. ................................................ ........................................................................................455
Appendix D: Migration from Baseline to Enhanced Devices..............................................................................................................464
Appendix E: Migration From Mid-Range to Enhanced Devices.........................................................................................................465
Appendix F: Migration From High-End to Enhanced Devices................................................... ....... .... .. .... .. .. .................................... 465
Index .................................................................................................................................................................................................. 467
Systems Information and Upgrade Hot Line......................................................................................................................................479
PIC18F2480/2580/4480/4580 Product Identification System ............................................................................................................481
DS39637A-page 4Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include
literature number) you are using.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
DS39637A-page 6Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
1.0DEVICE OVERVIEW
This documen t conta i ns dev ic e spec if i c in for m at i on fo r
the following devices:
• PIC18F2480
• PIC18F2580
• PIC18F4480
• PIC18F4580
This family of devices offers the advantages of all
PIC18 microcontrollers – namely, high computational
performance at an economical price – with the addition
of high-endurance, Enhanced Flash program
memory. In addition to these features, the
PIC18F2480/2580/448 0/4580 family introd uces desig n
enhancements that make these microcontrollers a
logical choice for many high-performance, power
sensitive applications.
1.1New Core Features
1.1.1nanoWatt TECHNOLOGY
All of the devices in the PIC18F2480/2580/4480/4580
family incorporate a range of features that can significantly reduce power consumption during operation.
Key items include:
• Alternate Run Modes: By clocking the controller
from the Timer1 source or the internal oscillator
block, power consumption during code execution
can be reduced by as much as 90%.
• Multiple Idle Modes: The controller can also run
with its CPU core disabled but the peripherals still
active. In these st ates, powe r consumpt ion can be
reduced even further, to as little as 4% of normal
operation requirements.
• On-the-fly Mode Switching: The power
managed modes a re invo ked b y user code durin g
operation, allowing the user to incorporate
power-saving ideas into their application’s
software design.
• Lower Consumption in Key Modules: The
power requirements for both Timer1 and the
Watchdog Timer have been reduced by up to
80%, with typical values of 1.1 and 2. 1 µA,
respectively.
• Extended Instruction Set: In addition to the
standard 75 instructions of the PIC18 instruction
set, PIC18F2480/2580/4480/4580 devices also
provide an optional extension to the core CPU
functionality. The added features include eight
additional instructions that augment indirect and
indexed addressing operations and the
implementation of Indexed Literal Offset
Addressing mode for ma ny of the st and ard PIC18
instructions.
1.1.2MULTIPLE OSCILLATOR OPTIONS
AND FEATURES
All of the devices in the PIC18F2480/2580/4480/4580
family offer ten different oscillator options, allowing
users a wide range o f choices i n develo ping applica tion
hardware. These include:
• Four Crystal modes, using crystals or ceramic
resonators
• Two External Clock modes, offering the option of
using two pins (oscillator input and a divide-by-4
clock output) or one pin (oscillator input, with the
second pin reassigned as general I/O)
• Two External RC Oscillator modes with the same
pin options as the External Clock modes
• An internal oscillator block which provides an
8 MHz clock (±2% accuracy) and an INTRC
source (approximately 31kHz, stable over
temperature and V
6 user selectable clock frequencies, between
125 kHz to 4 MHz, for a total of 8 clock
frequencies. This option frees the two oscillator
pins for use as additional general purpose I/O.
• A Phase Lock Loop (PLL) frequency multiplier,
available to both the high-speed crystal and
internal oscillator modes, which allows clock
speeds of up to 40MHz. Used with the internal
oscillator, the PLL gives users a complete
selection of clock speeds, from 31 kHz to
32 MHz – all without using an external crystal or
clock circuit.
Besides its ava ilability as a cloc k source, the intern al
oscillator block pro vid es a s t ab le re fere nce source that
gives the family additional features for robust
operation:
• Fail-Safe Clock Monitor: This option constantly
monitors the main clock source against a reference signal provi ded by the i nte rnal os ci llator. If a
clock failure occurs, the controller is switched to
the internal oscillato r block, al lowing f or continue d
low-speed operation or a safe application
shutdown.
• Two-Speed Start-up: This option allows the
internal oscillator to serve as the clock source
from Power-on Reset, or wake-up from Sleep
mode, until the primary clock source is available.
• Memory Endurance: The Enhanced Flash cells
for both program memory and data EEPROM are
rated to last for many thousands of erase/write
cycles – up to 100,000 for program memory and
1,000,000 for EEPROM. Data retention without
refresh is conservatively estimated to be greater
than 40 years.
• Self-programmability: These devices can write
to their own program memory spaces under internal software control. By using a bootloader routine located in the protected Boot Block at the top
of program memory, it becomes possible to create
an application that can update itself in the field.
• Extended Instruction Set: The
PIC18F2480/2580/4480/4580 family introduces
an optional extension to th e PIC18 instr uction set,
which adds 8 new instructions and an Indexed
Addressing mode. This extension, enabled as a
device configuration option, has been specifically
designed to optimize re-entrant application code
originally deve loped in high -level la nguages, such
as C.
• Enhanced CCP module: In PWM mode, this
module provides 1, 2 or 4 modulated outputs for
controlling half-bridge and full-bridge drivers.
Other features include Auto-S hutdown, for
disabling PWM output s on interrup t or other selec t
conditions and Auto-Rest art, to re activ ate outpu ts
once the condition has cleared.
• Enhanced Addressable USART: This serial
communication module is capable of standard
RS-232 operation an d provides support for th e LIN
bus protocol. Other enhancements include automatic baud r ate detection and a 16-bit Baud Rate
Generator for improved resolution. When the
microcontroller is using the internal oscillator
block, the EUSART provides stable operation for
applications that talk to the outside world without
using an external crystal (or its accompanying
power requirement).
• 10-bit A/D Converter: This module incorporates
programmable acquisition time, allowing for a
channel to be selected and a conversion to be
initiated withou t wai ting for a sampling period and
thus, reduce code overhead.
• Extended Watchdog Timer (WDT): This
enhanced version in corpora tes a 1 6-bit pre scale r,
allowing a time-out range from 4 ms to over 131
seconds, that is stable across operating voltage
and temperature.
1.3Details on Individual Family
Members
Devices in the PIC18F 2480/2580 /4480/4580 famil y are
available in 28-pin (PIC18F2X80) and 40/44-pin
(PIC18F4X80) packages. Block diagrams for the two
groups are shown in Figure 1-1 and Figure 1-2.
The devices are differentiated from each other in six
ways:
1.Flash program memory (16Kbytes for
PIC18FX480 devices; 32Kbytes for
PIC18FX580).
2.A/D channels (8 for PIC18F2X80 devices; 11 for
PIC18F4X80 devices).
3.I/O ports (3 bidirectional ports and 1 input only
port on PIC18F2X80 devices; 5 bidirectional
ports on PIC18F4X80 devices).
4.CCP and Enhanced CCP implementation
(PIC18F2X80 devices have 1 standard CCP
module; PIC18F4X80 devices have one
standard CCP module and one ECCP module).
5.Parallel Slave Port (present only on
PIC18F4X80 devices).
6.PIC18F4X80 devices provide two comparators.
All other features fo r device s in this family are identi cal.
These are summarized in Ta ble 1-1.
The pinouts for all devices are listed in Table 1-2 and
Table 1-3.
Like all Microchip PIC18 devices, members of the
PIC18F2480/2580/4480/4580 family are available as
both standard and low-voltage devices. Standard
devices with Enhan ced Flas h memory, designated with
an “F” in the part number (such as PIC18F2580),
accommodate an ope rati ng V
Low-voltage parts, designated by “LF” (such as
PIC18LF2580), function over an extended VDD range
of 2.0V to 5.5V.
DD range of 4.2V to 5.5V.
DS39637A-page 8Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 1-1:DEVICE FEATURES
FeaturesPIC18F2480PIC18F2580PIC18F4480PIC18F4580
Operating FrequencyDC – 40 MHzDC – 40 MHzDC – 40 MHzDC – 40 MHz
Program Memory (Bytes)16384327681638432768
Program Memory (Instruction s)819216384819216384
Data Memory (Bytes)76815367681536
Data EEPROM Memory (Bytes)256256256256
Interrupt Sources19192020
I/O PortsPorts A, B, C, (E)Ports A, B, C, (E)Ports A, B, C, D, E Ports A, B, C, D, E
Timers4444
Capture/Compare/PWM Modules1111
Enhanced Capture/
Compare/PWM Modules
ECAN Module1111
Serial CommunicationsMSSP,
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
SPDIP,
SOIC
126
96
107
QFN
Pin
Type
I
P
I
I
I
I/O
O
O
I/O
Buffer
Type
ST
ST
ST
CMOS
TTL
—
—
TTL
Description
Master Clear (input) or programming voltage (input).
Master Clear (Reset) input. This pin is an active-low
Reset to the device.
Programming voltage inpu t.
Digital input.
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source input.
ST buffer when configured in RC mode; CMOS otherwise.
External clock source input. Always associated with pin
function OSC1. (See related OSC1/CLKI, OSC2/CLKO pins.)
General purpose I/O pin.
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or resonator in
Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO which has 1/4 the
frequency of OSC1 and denotes the instruction cycle rate.
General purpose I/O pin.
DS39637A-page 12Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 1-2:PIC18F2480/2580 PINOUT I/O DESCRIPTIONS (CONTINUED)
Pin Number
Pin Name
RA0/AN0
RA0
AN0
RA1/AN1
RA1
AN1
RA2/AN2/VREF-
RA2
AN2
REF-
V
RA3/AN3/V
RA4/T0CKI
RA5/AN4/SS
RA6See the OSC2/CLKO/RA6 pin.
RA7See the OSC1/CLKI/RA7 pin.
Legend: TTL = TTL compatible input CMOS = CMOS compatible input or output
REF+
RA3
AN3
REF+
V
RA4
T0CKI
/HLVDIN
RA5
AN4
SS
HLVDIN
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
SPDIP,
SOIC
227
328
41
52
63
7
QFN
4
Pin
Buffer
Type
Type
I/OITTL
Analog
I/OITTL
Analog
I/O
I/O
I/OITTL
I/O
I
I
I
I
I
I
I
TTL
Analog
Analog
TTL
Analog
Analog
TTL
Analog
TTL
Analog
PORTA is a bidirectional I/O port.
Digital I/O.
Analog input 0.
Digital I/O.
Analog input 1.
Digital I/O.
Analog input 2.
A/D Reference Voltage (Low) input.
Digital I/O.
Analog input 3.
A/D Reference Voltage (High) input.
Digital I/O.
ST
Timer0 external clock input.
Digital I/O.
Analog input 4.
SPI™ Slave Select input.
High/Low-Voltage Detect input.
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
Pin Number
PDIPQFNTQFP
11818
133230
143331
Pin
Type
I
P
I
I
I
I/O
O
O
I/O
Buffer
Type
ST
ST
ST
CMOS
TTL
—
—
TTL
Description
Master Clear (input) or programming voltage (input).
Master Clear (Reset) input. This pin is an
active-low Reset to the device.
Programmin g voltage input.
Digital input.
Oscillator crystal or external clock input.
Oscillator crystal input or external clock source input.
ST buffer when configured in RC mode;
CMOS otherwise.
External clock source input. Always associated with
pin function OSC1. (See related OSC1/CLKI,
OSC2/CLKO pins.)
General purpose I/O pin.
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO which has 1/4
the frequency of OSC1 and denotes the instruction
cycle rate.
General purpose I/O pin.
DS39637A-page 16Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 1-3:PIC18F4480/4580 PINOUT I/O DESCRIPTIONS (CONTINUED)
Pin Name
RA0/AN0/CVREF
RA0
AN0
CVREF
RA1/AN1
RA1
AN1
RA2/AN2/V
RA3/AN3/V
RA4/T0CKI
RA5/AN4/SS
RA6See the OSC2/CLKO/RA6 pin.
RA7See the OSC1/CLKI/RA7 pin.
Legend: TTL = TTL compatible input CMOS = CMOS compatible input or output
REF-
RA2
AN2
REF-
V
REF+
RA3
AN3
REF+
V
RA4
T0CKI
/HLVDIN
RA5
AN4
SS
HLVDIN
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
Pin Number
PDIPQFNTQFP
21919
32020
42121
52222
62323
72424
Pin
Buffer
Type
Type
I/O
TTL
I
Analog
O
Analog
I/OITTL
Analog
I/O
TTL
I
Analog
I
Analog
I/O
TTL
I
Analog
I
Analog
I/OITTL
I/O
TTL
I
Analog
I
TTL
I
Analog
PORTA is a bidirectional I/O port.
Digital I/O.
Analog input 0.
Analog Comparator Reference output.
Digital I/O.
Analog input 1.
Digital I/O.
Analog input 2.
A/D Reference Voltage (Low) input.
Digital I/O.
Analog input 3.
A/D Reference V o lt a ge (H igh ) input .
Digital I/O.
ST
Timer0 external clock input.
Digital I/O.
Analog input 4.
SPI™ Slave Select input.
High/Low-Voltage Detect input.
ST = Schmitt Trigger input with CMOS levels I= Input
O= Output P= Power
Pin Number
PDIPQFNTQFP
193838
203939
214040
224141
2722
2833
2944
3055
Pin
Type
I/O
I/O
I
I/O
I/O
I
I/O
I/O
I
I/O
I/O
I
I/O
I/O
I/O
O
I/O
I/O
O
I/O
I/O
O
I/O
I/O
O
Buffer
Type
ST
TTL
Analog
ST
TTL
Analog
ST
TTL
Analog
ST
TTL
Analog
ST
TTL
ST
TTL
ST
TTL
TTL
ST
TTL
TTL
ST
TTL
TTL
Description
PORTD is a bidirectional I/O port or a Parallel Slave
Port (PSP) for interfacing to a microprocessor port.
These pins have TTL input buffers when PSP modu le
is enabled.
Digital I/O.
Parallel Slave Port data.
Comparator 1 input (+).
Digital I/O.
Parallel Slave Port data.
Comparator 1 input (-)
Digital I/O.
Parallel Slave Port data.
Comparator 2 input (+).
Digital I/O.
Parallel Slave Port data.
Comparator 2 input (-).
Digital I/O.
Parallel Slave Port data.
Capture2 input/Compare 2 output/PWM2 output.
ECCP1 PWM output A.
Digital I/O.
Parallel Slave Port data.
ECCP1 PWM output B.
Digital I/O.
Parallel Slave Port data.
ECCP1 PWM output C.
Digital I/O.
Parallel Slave Port data.
ECCP1 PWM output D.
DS39637A-page 20Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 1-3:PIC18F4480/4580 PINOUT I/O DESCRIPTIONS (CONTINUED)
DS39637A-page 22Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
2.0OSCILLATOR
CONFIGURATIONS
2.1Oscillator Types
PIC18F2480/2580/448 0/4580 devices can be operated
in ten different o scillato r mo des. The user ca n progra m
the configuration bi ts, FOSC3:FOSC 0, in Configuratio n
Register 1H to select one of these ten modes:
1.LPLow-Power Crystal
2.XTCrystal/Resonator
3.HSHigh-Speed Crystal/Resonator
4.HSPLL High-Speed Crystal/Resonator
with PLL enabled
5.RCExternal Resistor/Capacito r with
F
OSC/4 output on RA6
6.RCIOExternal Resistor/C apacitor with I/O
on RA6
7.INTIO1 Internal Oscillator with F
on RA6 and I/O on RA7
8.INTIO2 Internal Oscillator with I/O on RA6
and RA7
9.ECExternal Clock with F
10. ECIOExternal Clock with I/O on RA6
2.2Crystal Oscillator/Ceramic
Resonators
In XT, LP, HS or HSPLL Oscillator modes, a crystal or
ceramic resonator is connected to the OSC1 and
OSC2 pins to establish oscillation. Figure 2-1 shows
the pin connections.
The oscillator design requires the use of a parallel cut
crystal.
Note:Use of a series cut crystal may give a
frequency out of the crystal ma nufacturer’s
specifications.
OSC/4 output
OSC/4 output
FIGURE 2-1:CRYSTAL/CERAMIC
RESONATOR OPERATION
(XT, LP, HS OR HSPLL
CONFIGURATION)
(1)
C1
(1)
C2
Note 1: See T able 2-1 and T able 2-2 for initial values of
C1 and C2.
2: A series resistor (R
strip cut crystals.
3: R
OSC1
To
Internal
XTAL
(2)
RS
OSC2
F varies with the oscillator mode chosen.
(3)
RF
PIC18FXXXX
S) may be required for AT
Logic
Sleep
T ABLE 2-1:CAPACITOR SELECTION FOR
CERAMIC RESONATORS
Typical Capacitor Values Used:
ModeFreqOSC1OSC2
XT455 kHz
2.0 MHz
4.0 MHz
HS8.0 MHz
16.0 MHz
Capacitor values are for design guidance only.
These capacitors were tested with the resonators
listed below for basic start-up and operation. Thesevalues are not optimized.
Different cap acitor values may be required to prod uce
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
DD and temperature range for the application.
V
See the notes on page 24 for additional information.
Resonators Used:
455 kHz4.0 MHz
2.0 MHz8.0 MHz
16.0 MHz
56 pF
47 pF
33 pF
27 pF
22 pF
56 pF
47 pF
33 pF
27 pF
22 pF
Note:When using resonators with frequencies
above 3.5 MHz, the use of HS mode,
rather than XT mode, is recommended.
HS mode may be used at any V
DD for
which the controller is rated. If HS is
selected, it is possible that the gain of the
oscillator will overdrive the resonator.
Therefore, a series resistor should be
placed between the OSC2 pin and the
resonator. As a good starting point, the
recommended value of R
Capacitor values are for design guidance only.
These capacitors were tested with the crystals listed
below for basic start-up and operation . These values
are not optimized.
Different capa citor values may be required to produc e
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
DD and temperature range for the application.
V
See the notes following this table for additional
information.
Note 1: Higher capacitanc e increases th e stabilit y
Crystal
Freq
200 kHz15 pF15 pF
4 MHz27 pF27 pF
8 MHz22 pF22 pF
20 MHz15 pF15 pF
Crystals Used:
32 kHz4 MHz
200 kHz8 MHz
1 MHz20 MHz
of the oscillator but also increases the
start-up time.
2: When operating below 3V V
using certain ceramic resonators at any
voltage, it may be necessary to use the
HS mode or switch to a crystal oscillator.
3: Since each resonator/crystal has its own
characteristics, the user should consult
the resonator/crystal manufacturer for
appropriate values of external
components.
4: Rs may be r equired to av oid overdr iving
crystals with low driv e lev e l spe ci fic ati on.
5: Always verify oscillator perform an ce over
DD and temperature range that is
the V
expected for the application.
T ypical Cap acitor V alues
Tested:
C1C2
DD, or when
An external clock source may also be connected to the
OSC1 pin in the HS mode, as shown in Figure 2-2.
FIGURE 2-2:EXTERNAL CLOCK
INPUT OPERATION
(HS OSCILLATOR
CONFIGURATION)
Clock from
Ext. System
Open
OSC1
OSC2
PIC18FXXXX
(HS Mode)
2.3External Clock Input
The EC and ECIO Oscillator mode s require an externa l
clock source to be conn ected to the OSC1 pi n. There is
no oscillator start-up time required after a Power-on
Reset or after an exit from Sleep mode.
In the EC Oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic. Figure 2-3 shows the pin connections for the EC
Oscillator mode.
FIGURE 2-3:EXTERNAL CLOCK
INPUT OPERATION
(EC CONFIGURATION)
Clock from
Ext. System
F
OSC/4
The ECIO Oscillator mo de func tio ns lik e t he EC mod e,
except that the OSC2 pin becomes an additional
general purpose I/O pin. The I/O pin becomes bit 6 of
PORTA (RA6). Figure 2-4 shows the pin connections
for the ECIO Oscillator mode.
FIGURE 2-4:EXTERNAL CLOCK
Clock from
Ext. System
RA6
OSC1/CLKI
PIC18FXXXX
OSC2/CLKO
INPUT OPERATION
(ECIO CONFIGURATION)
OSC1/CLKI
PIC18FXXXX
I/O (OSC2)
DS39637A-page 24Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
2.4RC Oscillator
For timing insensitive applications, the “RC” and
“RCIO” device options offer additional cost savings.
The actual oscillator frequency is a function of several
factors:
• supply voltage
• values of the external resistor (R
capacitor (C
EXT)
• operating temperature
Given the same device, operating voltage and temperature and component values, there will also be unit-to-unit
frequency variations. These are due to factors such as:
• normal manufacturing variation
• difference in lead frame capacitance between
package types (especially for low C
• variations within the tolerance of limits of REXT
EXT
and C
In the RC Oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic. Figure 2-5 shows how the R/C combination is
connected.
FIGURE 2-5:RC OSCILLATOR MODE
VDD
REXT
OSC1
CEXT
VSS
F
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
OSC/4
OSC2/CLKO
EXT > 20 pF
C
EXT) and
EXT values)
Internal
Clock
PIC18FXXXX
2.5PLL Frequency Multiplier
A Phase Locked Loop (PLL) circuit is provided as an
option for users who wish to use a lower frequency
oscillator circuit or to clock the device up to its highest
rated frequency from a crystal oscillator. This may be
useful for customers who are concerned with EMI due
to high-frequency crystals or users who require higher
clock speeds from an internal oscillator.
2.5.1HSPLL OSCILLATOR MODE
The HSPLL mode make s use of the HS mode osc illator
for frequencies up t o 10 MHz. A PLL then multipl ies the
oscillator output frequency by 4 to produce an internal
clock frequency up to 40 MHz.
The PLL is only available to the crystal oscillator when
the FOSC3:FOSC0 configu r ati on bi t s are prog ram med
for HSPLL mode (= 0110).
FIGURE 2-7:PLL BLOCK DIAGRAM
(HS MODE)
HS Osc Enable
PLL Enable
(from Configuration Register 1H)
OSC2
OSC1
HS Mode
Crystal
Osc
IN
F
FOUT
÷4
Phase
Comparator
Loop
Filter
VCO
SYSCLK
MUX
The RCIO Oscillator mode (Figure 2-6) functions like
the RC mode, except that the OSC2 pin becomes an
additional general purpose I/O pin. The I/O pin
becomes bit 6 of PORTA (RA6).
2.5.2PLL AND INTOSC
The PLL is also ava ilabl e to th e inte rnal os cill ator bl ock
in selected oscillator modes. In this configuration, the
FIGURE 2-6:RCIO OSCILLATOR MODE
VDD
PLL is enabled in software and generates a clock
output of up to 32MHz. The operation of INTOSC with
the PLL is describ ed in Section 2.6.4 “PLL in INTOSC
The PIC18F2480/2580/4480/4580 devices include an
internal oscillator block which generates two different
clock signals; either can be used as the microcontroller’s clock source. This may eliminate the need
for external oscillator circuits on the OSC1 and/or
OSC2 pins.
The main output (INTOSC) is an 8 MHz clock source,
which can be used to directly drive the device clock. It
also drives a postscaler, which can provide a range of
clock frequencies from 31 kHz to 4 MHz. The INTOSC
output is enabled when a clock fre quency from 12 5 kHz
to 8 MHz is selected.
The other clock source is the internal RC oscillator
(INTRC), which provides a nominal 31 kHz output.
INTRC is enabled if it is selected as the device clock
source; it is also ena bled autom atically when an y of the
following are enabled:
• Power-up Timer
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed Sta r t-up
These features are discussed in greater detail in
Section 24.0 “Special Features of the CPU”.
The clock source frequency (INTOSC direct, INTRC
direct or INTOSC postscaler) is selected by configuring
the IRCF bits of the OSCCON register (Register 2-2).
2.6.1INTIO MODES
Using the internal oscillator as the clock source eliminates the need for up to two external oscillator pins,
which can then be used for digital I/O. Two distinct
configurations are available:
• In INTIO1 mode, the OSC2 pin outputs F
while OSC1 functions as RA 7 fo r dig it a l in put a nd
output.
• In INTIO2 mode, OSC1 functions as RA7 and
OSC2 functions as RA6, both for digital input and
output.
2.6.2INTOSC OUTPUT FREQUENCY
The internal oscillator block is calibrated at the factory
to produce an INTOSC output frequency of 8.0MHz.
The INTRC oscillator operates independently of the
INTOSC source. Any changes in INTOSC across voltage and temperature are not necessarily reflected by
changes in INTRC and vice versa.
2.6.3OSCTUNE REGISTER
The internal oscillator’s output has been calibrated at
the factory but can be adjusted in the user’s application. This is do ne by writi ng to the OSC TUNE regi ster
(Register 2-1). The tuning sensitivity is constant
throughout the tuning range.
OSC/4,
When the OSCTUNE regis ter is mo di fied , the IN T O SC
and INTRC frequencies will begin shifting to the new
frequency. The INTRC clock will reach the new
frequency within 8 clock cycles (approximately
8*32µs= 256 µs). The INTOSC clock will stabilize
within 1 ms. Code execution continues du ring this shift.
There is no indication that the shift has occurred.
The OSCTUNE register also implements the INTSRC
and PLLEN bits, which control certain features of the
internal oscillator block. The INTSRC bit allows users
to select which internal oscillator provides the clock
source when the 31 kHz frequency option is selected.
This is covered in greater detail in Section 2.7.1“Oscillator Control Register”.
The PLLEN bit controls the operation of the frequency
multiplier, PLL, in internal oscillator modes.
2.6.4PLL IN INTOSC MODES
The 4x frequency multiplier can be used with the internal oscillator block to produce faster device clock
speeds than are normally possible with an internal
oscillator. When enabled, the PLL produces a clock
speed of up to 32MHz.
Unlike HSPLL mode, the PLL is c ontrolled through so ftware. The control bit, PLLEN (OSCTUNE< 6>), is used
to enable or disable its operation.
The PLL is available when the device is configured to
use the internal oscillator block as its primary clock
source (FOSC3:FOSC0 = 1001 or 1000). Additionally,
the PLL will only function when the selected output frequency is either 4 MHz or 8 MHz (OSCCON<6:4> = 111
or 110). If both of these conditions are not met, the PLL
is disabled.
The PLLEN control bit is only functional in those internal
oscillator modes where the PLL is available. In all other
modes, it is forced to ‘0’ and is effectively u navailable.
2.6.5INTOSC FREQUENCY DRIFT
The factory calibrates the internal oscillator block
output (INTOSC) for 8 MHz. However, this frequency
may drift as VDD or temperature changes, which can
affect the controller operation in a variety of ways. It is
possible to adjust the INTOSC frequency by modifying
the value in the OSCTUNE register. This has no effect
on the INTRC clock source frequency.
Tuning the INTOSC source requires knowing when to
make the adjustment, in which direction it should be
made and in some cases, how large a change is
needed. Three compensation techniques are
discussed in Section 2.6.5.1 “Compensating with
the EUSART”, Section 2.6.5.2 “Compensating with
the Timers” and Section2.6.5.3 “Compensating
with the CCP Module in Capture Mode”, but other
techniques may be used.
DS39637A-page 26Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
REGISTER 2-1:OSCTUNE: OSCILLATOR T UNING REGISTER
R/W-0 R/W-0
INTSRCPLLEN
bit 7bit 0
bit 7INTSRC: Internal Oscillator Low-Frequency Source Select bit
bit 6PLLEN: Frequency Multiplier PLL for INTOSC Enable bit
1 = PLL enabled for INTOSC (4 MHz and 8 MHz only)
0 = PLL disabled
Note 1: Available only in certain oscillator configurations; otherwise, this bit is unavailable
bit 5Unimplemented: Read as ‘0’
bit 4-0TUN4:TUN0: Frequency Tuning bits
01111 = Maximum frequency
• •
• •
00001
00000 = Center frequency. Oscillator module is running at the calibrated frequency.
11111
• •
• •
10000 = Minimum frequency
(1)
and reads as ‘0’. See text for details.
U-0R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
(1)
—TUN4TUN3TUN2TUN1TUN0
(1)
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
2.6.5.1Compensating with the EUSART
An adjustment may be required when the EUSART
begins to generate framing e rrors or recei ves da ta wi th
errors while in Asynchronous mode. Framing errors
indicate that the device clock frequency is too high. To
adjust for this, decrement the value in OSCTUNE to
reduce the clock frequency. On the other hand, errors
in data may sugge st that the clock speed is too low. To
compensate, increment OSCTUNE to increase the
clock frequency.
2.6.5.2Compensating with the Timers
This technique compares device clock speed to some
reference clock. Two timers may be used; one timer is
clocked by the peripheral clock, while the other is
clocked by a fixed reference source, such as the
Timer1 oscillat or.
Both timers are cleared, but the timer clocked by the
reference generates interrupts. When an interrupt
occurs, the internally clocked timer is read and both
timers are cleared. If the internally clocked timer value
is greater than expected, then the internal oscillator
block is ru nning too fast. To adjust for t his, decr ement
the OSCTUNE register.
2.6.5.3Compensating with the CCP Module
in Capture Mode
A CCP module can use free running Timer1 (or
Timer3), cl oc ked by the internal oscillator bl ock and an
external event with a known period (i.e., AC power
frequency). The time of the first event is capt ured in th e
CCPRxH:CCPRxL registers and is recorded for use
later. When the second event causes a capture, the
time of the first event is su btra cte d fro m the tim e of th e
second event. Since the period of the external event is
known, the time difference between events can be
calculated.
If the measured time is much greater than the
calculated time, the i nternal oscillator block is ru nning
too fast. To compensate, decrement the OSCTUNE
register. If the measured time is much less than the
calculated time, the i nternal oscillator block is ru nning
too slow. To compensate, increment the OSCTUNE
register.
Like previous PIC18 devices, the
PIC18F2480/2580/448 0/4580 f amily inclu des a featu re
that allows the devic e clock so urce to be swit ched fro m
the main oscillator to an alternate low-frequency clock
source. PIC18F2480/2580/4480/4580 devices offer
two alternate clock sources. When an alternate clock
source is enabled, the vario us power m anaged oper ating modes are available.
Essentially, there are three clock sources for these
devices:
• Primary oscillators
• Secondary oscillators
• Internal oscillator block
The primary oscillators include the external crystal
and resonator modes, the external RC modes, the
external clock modes and the internal oscillator block.
The particular mode is defined by the FOSC3:FOSC0
configuration bits. The details of these modes are
covered earlier in this chapter.
The s econdary oscillators are those external sources
not connected to the OSC1 or OSC2 pins. These
sources may continue to operate even after the
controller is placed in a power managed mode.
PIC18F2480/2580/448 0/45 80 d ev ic es o f fe r the Timer1
oscillator as a secon dary oscilla tor . This osc illator , in all
power managed modes, is often the time base for
functions such as a real-time cloc k.
Most often, a 32.768 kHz watch crystal is connected
between the RC0/T1OSO/T13CKI and RC1/T1OSI
pins. Like the LP mode oscillator circuit, loading
capacitors are also connected from each pin to ground.
The Timer1 oscillator is discussed in greater detail in
Section 12.3 “Timer1 Oscillator”.
In addition to being a prim ary clock source, the internaloscillator block is available as a power managed
mode clock source. T he IN TR C s ource is also used as
the clock source for several special features, such as
the WDT and Fail-Safe Clock Monitor.
The clock sources for the PIC18F2480/2580/4480/4580
devices are shown in Figure 2-8. See Section 24.0“Special Features of the CPU” for Configuration
DS39637A-page 28Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
2.7.1OSCILLATOR CONTROL REGISTER
The OSCCON register (Register 2-2) controls several
aspects of the device clock’s operation, both in full
power operation and in power managed modes.
The System Clock Select bits, SCS1:SCS0, select the
clock source. The available clock sources are the
primary clock (defined by the FOSC3:FOSC0 configuration bits), the secondary clock (Timer1 oscillator) and
the internal oscillator block. The clock source changes
immediately after one or more of the bits is written to,
following a brief clock transition interval. The SCS bits
are cleared on all forms of Reset.
The Internal Oscillator Frequency Select bits,
IRCF2:IRCF0, select the frequency output of the
internal oscillator block to drive the device clock. The
choices are the INTRC source, the INTOSC source
(8 MHz) or one of the frequencies derived from the
INTOSC postscaler (31kHz to 4 MHz). If the internal
oscillator block is sup ply in g the de vi ce c loc k, changing
the states of these bits will have an immediate change
on the internal oscillator’s output. On device Resets,
the default output frequency of the internal oscillator
block is set at 1 MHz.
When an output frequency of 31 kHz is selected
(IRCF2:IRCF0 = 000), users may choose which internal oscillator acts as the source. This is done with the
INTSRC bit in the OSCTUNE register (OSCTUNE<7>).
Setting this bit selects INTOSC as a 31.25 kHz clock
source by enabling the divide-by-256 output of the
INTOSC postscaler. Clearing INTSRC sel ects INTRC
(nominally 31 kHz) as the clock source.
This option allows users to select the tunable and more
precise INTOSC as a clock source, while maintaining
power savings with a ve ry low clock speed. R egardless
of the setting of INTSRC, INTRC always remains the
clock source for features such as the Watchdog Timer
and the Fail-Safe Clock Monitor.
The OSTS, IOFS and T1RUN bit s ind ic ate wh ich clock
source is currently providing the device clock. The
OSTS bit indicates that the Oscillator Start-up Timer
has timed out and the primary clock is providing the
device clock in primary clock modes. The IOFS bit indicates when t he internal oscillato r block has stabilized
and is providing the device clock in RC Clock modes.
The T1RUN bit (T1CON<6>) indicates when the
Timer1 oscillator is providing the device clock in
secondary clock modes. In power managed modes,
only one of these three bits will be set at any time. If
none of these bits are set, the INTRC is providing the
clock or the internal o scillator bloc k has just s tarted and
is not yet stable.
The IDLEN bit dete rmines if th e dev ice go es in to Slee p
mode or one of the Idle modes when the SLEEP
instruction is executed.
The use of the flag and control bits in the OSCCON
register is discussed in more detail in Section 3.0
“Power Managed Modes”.
Note 1: The Timer1 oscillator must be enabled to
select the secondary clock source. The
Timer1 oscillator is enabled by setting the
T1OSCEN bit in the Timer1 Control register (T1CON<3>). If the Timer1 oscillator is
not enabled, then any attempt to select a
secondary clock source when executing a
SLEEP instruction will be ignored.
2: It is recommended that the Timer1
oscillator be operating and stable before
executing the SLEEP ins truction, or a very
long delay may occur while the Timer1
oscillator starts.
2.7.2OSCILLATOR TRANSITIONS
PIC18F2480/2580/4480/4580 devices contain circuitry
to prevent clock “glitches” when switching between
clock sources. A short p ause in the device cl ock occurs
during the clock switch. The length of this pause is the
sum of two cycles of the old clock source and three to
four cycles of the new clock source. This formula
assumes that the new clock source is stable.
Clock transitions are discussed in greater detail in
Section 3.1.2 “Entering Power Managed Modes”.
bit 3OSTS: Oscillator Start-up Time-out Status bit
1 = Oscillator start-up time-out timer has expired; primary oscillator is running
0 = Oscillator start-up time-out timer is running; primary oscillator is not ready
bit 2IOFS: INTOSC Frequency Stable bit
1 = INTOSC frequency is stable and the frequency is provided by one of the RC modes
0 = INTOSC frequency is not stable
Note 1: Depends on state of the IESO configuration bit.
2: Source selected by the INTSRC bit (OSCTUNE<7>), see text.
3: Default output frequency of INTOSC on Reset.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39637A-page 30Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
2.8Effects of Power Managed Modes
on the Various Clock Sources
When PRI_IDLE mode is selected, the designated
primary oscillator continues to run without interruption.
For all other power managed modes, the oscillator
using the OSC1 pin is disabled. The OSC1 pin (and
OSC2 pin, if used by the o scillat or) will sto p oscillat ing.
In secondary clock modes (SEC_RUN and
SEC_IDLE), the Timer1 oscillator is operating and
providing the device clock. The Timer1 oscillator may
also run in all power managed modes if required to
clock Timer1 or Timer3.
In internal oscillator modes (RC_RUN and RC_IDLE),
the internal oscillator block provides the device clock
source. The 31kHz INTRC output can be used direc tly
to provide the clock and may be enabled to support
various special features, regardless of the power managed mode (see Section 24.2 “Watchdog Timer
(WDT)”, Section 24.3 “Two-Speed Start-up” and
Section 24.4 “Fail-Safe Clock Monitor” for more
information on WDT, T wo-Speed Start-up and Fail-Safe
Clock Monitor. The INTOSC output at 8 MHz may be
used directly to clock the device or may be divided
down by the posts caler . The INTO SC output is disable d
if the clock is provided directly from the INTRC output.
If the Sleep mode is selected, all clock sources are
stopped. Since all the transistor switching currents
have been stopped, Sleep mode achieves the lowest
current consumption of the device (only leakage
currents).
Enabling any on-chip feature that will operate during
Sleep will increas e the current cons umed during S leep.
The INTRC is required to support WDT operation. The
Timer1 oscillator may be operating to support a
real-time clock. Other features may be operating that
do not require a device clock source (i.e., SSP slave,
PSP, INTn pins and others). Peripherals that may add
significant current consumption are listed in
Section 27.2 “DC Characteris tics: Power Dow n and
Supply Current”.
2.9Power-up Delays
Power-up delays are controlled by two timers, so that
no external Rese t circ ui try is re qui red for most applications. The delays ensure that the device is kept in
Reset until the device powe r supply i s stable under normal circumstan ces and the pri mary clock is ope rating
and stable. For additional information on power-up
delays, see Section 4.5 “Device Reset Timers”.
The first timer is the Power-up Timer (PWRT), which
provides a fixed delay on power-up (parameter 33,
Table 27-10). It is enabled by clearing (= 0) the
PWRTEN
The second timer is the Oscillator Start-up Timer
(OST), intended to keep the chip in Reset until the
crystal oscillator is stable (LP, XT and HS modes). The
OST does this by counting 1024 oscillator cycles
before allowing the oscillator to clock the device.
When the HSPLL Oscillator mode is selected, the
device is kept in Res et for an add iti onal 2ms, following
the HS mode OST delay, so the PLL can lock to the
incoming clock frequ enc y.
There is a delay of interval T
Table 27-10), following POR, while the controller
becomes ready to execute instruc tions. This delay runs
concurrently with any other delays. This may be the
only delay that occurs when an y of the EC, RC or INTIO
modes are used as the primary clock source.
configuration bit.
CSD (parameter 38,
TABLE 2-3:OSC1 AND OSC2 PIN STATES IN SLEEP MODE
OSC ModeOSC1 PinOSC2 Pin
RC, INTIO1Floating, external resistor should pull highAt logic low (clock/4 output)
RCIO, INTIO2Floating, external resistor should pull highConfigured as PORTA, bit 6
ECIOFloating, pulled by external clockConfigured as PORTA, bit 6
ECFloating, pulled by external clockAt logic low (clock/4 output)
LP, XT and HSFeedback inverter disabled at quiescent
voltage level
Note:See Table 4-2 in Section 4.0 “Reset”, for time-outs due to Sleep and MCLR
Feedback inverter disabled at quiescent
voltage level
Reset.
PIC18F2480/2580/4480/4580
NOTES:
DS39637A-page 32Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
3.0POWER MANAGED MODES
PIC18F2480/2580/4480/4580 devices offer a total of
seven operating modes for more efficient power management. These modes prov ide a vari ety of options for
selective power conservation in applications where
resources may be limited (i.e., battery-powered
devices).
There are three categories of power managed modes:
• Run modes
• Idle modes
• Sleep mode
These categories define which portions of the device
are clocked and some times , what sp eed. The R un and
Idle modes may use any of the three available clock
sources (primary, secondary or internal oscillator
block); the Sleep mode does not use a clock source.
The power managed modes include several power
saving features offered on previous PICmicro
devices. On e is th e clock switchin g featu re, offer ed in
other PIC18 devices, allowing the controller to use the
Timer1 os cil la tor in pl ac e of the prim ary osc il lato r. Also
included is the Sleep mode, offered by all PICmicro
devices, where all device clocks are stopped.
3.1Selecting Power Managed Modes
Selecting a power managed mode requires two
decisions: if the CPU is to be clocked or not and the
selection of a clock source. The IDLEN bit
(OSCCON<7>) controls CPU clocking, while the
SCS1:SCS0 bits (OSCCON<1:0>) select the clock
source. The individual modes, bit settings, clock sources
and affected modules are summariz ed in Table 3-1.
3.1.1CLOCK SOURCES
The SCS1:SCS0 bits allow the sele ction of one o f three
clock sources for power managed modes. They are:
• the primary clock, as defined by the
FOSC3:FOSC0 configuration bits
• the secondary clock (the Timer1 oscillator)
• the internal oscillator block (for RC modes)
3.1.2ENTERING POWER MANAGED
MODES
Switching from one power managed mode to another
begins by loading the OSCCON register. The
SCS1:SCS0 bits selec t the clock sourc e and determin e
which Run or Idle mode is to be used. Changing these
bits causes an immediate switch to the new clock
source, assuming that it is running. The switch may
also be sub ject to clock tr ansition delays. These are
®
discussed in Section 3.1.3 “Clock Transitions andStatus Indicators” and subsequent sections.
Entry to the Power Managed Idle or Sleep modes is
triggered by the execution of a SLEEP instruction. The
actual mode that results depends on the status of the
IDLEN bit.
Depending on the current mode and the mode being
switched to, a ch ange t o a po wer man aged m ode d oes
not always require setting all of these bits. Many
transitions may be done by changing the oscillator
select bits, or ch angin g the IDLEN b it, pri or to i ssuing a
SLEEP instruction. If the IDLEN bit is already
configured correctly, it may only be necessary to
perform a SLEEP instruction to switch to the desired
mode.
TABLE 3-1:POWER MANAGED MODES
Mode
IDLEN<7>
Sleep0N/AOffOffNone – All clocks are disabled
PRI_RUNN/A00ClockedClockedPrimary – LP , XT, HS, HSPLL, RC, EC, INTRC
The length of the transition between clock sources is
the sum of two cycles o f the old clo ck so urce an d three
to four cycl es of the new clock so urce. This formula
assumes that the new clock source is stable.
Three bits indicate the current clock source and its
status. They are:
• OSTS (OSCCON<3>)
• IOFS (OSCCON<2>)
• T 1RUN (T1CON<6>)
In general, only one of these bits will be set while in a
given power managed mode. When the OSTS bit is
set, the primary clock is providing the device clock.
When the IOFS bit is s et, the I NTOSC output is providing a stable 8 MHz clock source to a divider that
actually drives the device clock. When the T1RUN bit is
set, the Timer1 oscillator is providing the clock. If none
of these bits are set, then either the INTRC clock
source is cloc ki ng t he dev ic e, o r th e INTOSC source is
not yet stable.
If the internal oscillator block is configured as the
primary clock sou rce by the FOSC3:FOSC0 conf igu ration bits, then both the OSTS and IOFS bits ma y be set
when in PRI_RUN or PRI_IDLE modes. This indicates
that the primary clock (INTOSC output) is generatin g a
stable 8 MHz output. Entering another RC power
managed mode at the s am e fre que nc y w ou ld cle ar th e
OSTS bit.
Note 1: Caution should be used when modifying a
single IRCF bit. I f V
possible to select a higher clock speed
than is supported by the low VDD.
Improper device operation may result if
the VDD/FOSC specifications are violated.
2: Executing a SLEEP instruction does not
necessarily place the device into Sleep
mode. It acts as the trigger to place the
controller into either the Sleep mode or
one of the Idle modes, depending on the
setting of the IDLEN bit.
DD is less than 3V, it is
3.1.4MULTIPLE SLEEP COMMANDS
The power managed mode that is invoked with the
SLEEP instruction is determined by the setting of the
IDLEN bit at the time the instruction is executed. If
another SLEEP instruction is executed, the device will
enter the power managed mode specified by IDLEN at
that time. If IDLEN has changed, the device will enter
the new power managed mode specified by the new
setting.
3.2Run Modes
In the Run modes, clocks to both the core and
peripherals are active. The difference between these
modes is the clock source.
3.2.1PRI_RUN MODE
The PRI_RUN mode is the normal, full power execution
mode of the microcontroller. This is also the default
mode upon a device Reset, un less T wo-Speed S tart-up
is enabled (see Section 24.3 “Two-Speed Start-up”
for details). In this m ode, the OSTS bi t is set. Th e IOFS
bit may be set if the internal oscillator block is the
primary clock source (see Section 2.7.1 “OscillatorControl Register”).
3.2.2SEC_RUN MODE
The SEC_RUN mode is the compatible mode to the
“clock switching” feature offered in other PIC18
devices. In this mode, the CPU and peripherals are
clocked from the T imer1 os cillator. This gives users the
option of lower power consumption while still using a
high accuracy clock source.
SEC_RUN mode is en tered by sett ing th e SCS1:SCS 0
bits to ‘01’. The device clock source is switched to the
Timer1 oscillator (see Figure 3-1), the primary oscillator is shut down, the T1RUN bit (T1CON<6>) is set and
the OSTS bit is cleared.
Note:The Timer1 oscillator should already be
running prior to entering SEC_RU N mode.
If the T1OSCEN bit is not set when the
SCS1:SCS0 bits are set to ‘01’, entry to
SEC_RUN mode will not occur. If the
Timer1 oscillator is enabled but not yet
running, devic e cloc ks will be de layed u ntil
the oscillator has started. In such situations, initial oscillator operation is far from
stable and unpredictable operation may
result.
On transitions from SEC_RUN mode to PRI_RUN, the
peripherals and CPU continue to be clocked from the
Timer1 oscillator while the primary clock is started.
When the primary clo ck bec omes r eady, a clock switch
back to the primary clock occurs (see Figure 3-2).
When the clock switch is complete, the T1RUN bit is
cleared, the OSTS bit is set and the primary clock is
providing the clock. The IDLEN and SCS bits are not
affected by the wake-up; the Timer1 oscillator
continues to run.
DS39637A-page 34Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
FIGURE 3-1:TRANSITION TIMING FOR ENTRY TO SEC_RUN MODE
Q4Q3Q2
Q1
Q1
Q4Q3Q2Q1Q3Q2
T1OSI
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter
123
Clock Transition
n-1
n
PC + 2PC
PC + 4
FIGURE 3-2:TRANSITION TIMING FROM SEC_RUN MODE TO PRI_RUN MODE (HSPLL)
T1OSI
OSC1
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program
Counter
Q1Q3 Q4
(1)
TOST
PC
Q3Q4Q1
Q2Q2Q3
(1)
TPLL
12 n-1n
Clock
Transition
PC + 2
Q1
Q2
PC + 4
SCS1:SCS0 bits changed
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
OSTS bit set
3.2.3RC_RUN MODE
In RC_RUN mode, the CPU and peripherals are
clocked from the internal oscillator block using the
INTOSC multiplexer; the primary clock is shut down.
When using the INTRC sourc e, this mo de provides the
best power conservation of all the Run modes, while
still executing code. It works well for user applications
which are not highly timing sensitive or do not require
high-speed clocks at all times.
If the primary clock source is the internal oscillator
block (either INTRC or INTOSC), there are no distinguishable differences between PRI_RUN and
RC_RUN modes during execution. Howeve r, a clock
switch delay will occur during entry to and exit from
RC_RUN mode. Therefore, if the primary clock source
is the internal oscillator block, the use of RC_RUN
mode is not recommended.
This mode is entered by setting SCS1 to ‘1’. Although
it is ignored, it is recommended that SCS0 also be
cleared; this is to maintain software compatibility with
future devices. When the clock source is switched to
the INTOSC multiplexer (see Figure 3-3), the primary
oscillator is shut down and the OSTS bit is cleared. The
IRCF bits may be modified at any time to immediately
change the clock speed.
Note:Cautio n s hou ld be u se d w he n m odi fy ing a
single IRCF bit. If V
DD is less than 3V, it is
possible to select a higher clock speed
than is supported by the low VDD.
Improper device operation may result if
the VDD/FOSC specifications are violated.
If the IRCF bits and the INTSRC bit are all clear, the
INTOSC output is not enabled and the IOFS bit will
remain clear; there will be no indication of the current
clock source. The INTRC source is providing the
device clocks.
If the IRCF bits are changed from all clear (thus,
enabling the INTOSC output) or if INTSRC is set, the
IOFS bit becomes set after the INTOSC output
becomes stable. Clocks to the device continue while
the INTOSC source stabilizes after an interval of
IOBST.
T
On transitions from RC_RUN mode to PRI_RUN mode,
the device continues to be clocked from the INTOSC
multiplexer whil e the prim ary clock is st arted. W hen the
primary clock becomes ready, a clock switch to the
primary clock occurs (see Figure 3-4). When the clock
switch is complete, the IOFS bit is cleared, the OSTS
bit is set and the primary clock is providing the device
clock. The IDLEN and SCS bits are not af fe cte d by the
switch. The INTRC source will continue to run if either
the WDT or the Fail-Safe Clock Monitor is enabled.
If the IRCF b its w ere pr e vi o us ly at a no n - zer o v al u e o r
if INTSRC was set before setting SCS1 and the
INTOSC source was already stable, the IOFS bi t will
remain set.
FIGURE 3-3:TRANSITION TIMING TO RC_RUN MODE
Q4Q3Q2
Q1
123n-1n
Clock Transition
PC + 2PC
INTRC
OSC1
CPU
Clock
Peripheral
Clock
Program
Counter
Q1
Q4Q3Q2Q1Q3Q2
PC + 4
FIGURE 3-4:TRANSITION TIMING FROM RC_RUN MODE TO PRI_RUN MODE
Q2
Q3 Q4
Q1
Q1
INTOSC
Multiplexer
OSC1
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program
Counter
SCS1:SCS0 bits changed
Note 1: TOST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
TOST
(1)
PC
Q2
Q3
TPLL
OSTS bit set
Q4
(1)
12 n-1n
Clock
Transition
PC + 2
Q1
PC + 4
Q2
Q3
DS39637A-page 36Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
3.3Sleep Mode
The Power Managed Sleep mode in the
PIC18F2480/2580/4480/4580 devices is identical to
the legacy Sleep mode offered in all other PICmicro
devices. It is entered by clearing the IDLEN bit (the
default state on device Reset) and executing the
SLEEP instruction. This shuts down the selected
oscillator ( Figure 3-5) . All clock source sta tus bits are
cleared.
Entering the Sleep m ode from any other mo de does not
require a clock switch. This is because no clocks are
needed once the controller has entered Sleep. If the
WDT is selected, the INTRC source will continue to
operate. If the Timer1 oscillator is enabled, it will also
continue to run.
When a wake ev ent occurs i n Sleep mo de (by int errupt,
Reset or WDT time-out), the device wil l not be clocke d
until the clock source selected by the SCS1:SCS0 bits
becomes ready (see Figure 3-6), or it will be clocked
from the internal oscillator block if either the
Two-Speed Start-up or the Fail-Safe Clock Monitor are
enabled (s ee Section 24.0 “Special Features of theCPU”). In either case, the OSTS b it is set when t he primary clock is providing the device clocks. The IDLEN
and SCS bits are not affected by the wake-up.
3.4Idle Modes
The Idle modes allow the controller’s CPU to be
selectively shut down while the peripherals continue to
operate. Selecting a particular Idle mode allows users
to further manage power consumption.
If the IDLEN bit i s set to a ‘1’ when a SLEEP inst ruction is
executed, the periph erals will be cl ocked fro m the cloc k
source selected us ing the SCS1:SCS 0 bits; howev er , the
CPU will not be clocked. The clock source status bits are
not affected. Setting IDLEN and executing a SLEEP
instruction pr ovides a quick method of switchi ng from a
given Run mo de to its correspondi ng Id le m od e.
If the WDT is selected, the INTRC source will continue
to operate. If the T imer1 oscill ator is enable d, it will also
continue to run.
Since the CPU is not executing instructions, the only
exits from any of the Idle modes are by interrupt, WDT
time-out or a Reset. When a wak e even t occur s, CPU
execution is delayed by an interval of T
(parameter 38, Table 27-10) while it becomes ready to
execute code. When the CPU begins executing code,
it resumes with the same clock source for the current
Idle mode. For example, when waking from RC_IDLE
mode, the internal oscillator block will clock the CPU
and peripherals (in other words, RC_RUN mode). The
IDLEN and SCS bits are not affected by the wake-up.
While in any Idle mode or the Sleep mode, a WDT
time-out will resul t i n a WD T wake-up to the Run mode
currently specified by the SCS1:SCS0 bits.
CSD
FIGURE 3-5:TRANSITION TI MING FOR ENTRY TO SLEEP MODE
Q4Q3Q2
Q1Q1
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter
PC + 2PC
FIGURE 3-6:TRANSITION TI MING FOR WAKE FROM SLEEP (HSPLL)
OSC1
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program
Counter
Note 1: T
Q1Q2 Q3 Q4 Q1 Q2
(1)
TOST
Wake Event
OST = 1024 TOSC; TPLL = 2 ms (approx). These intervals are not shown to scale.
This mode is unique among the three Low-Power Idle
modes, in that it does not disable the primary device
clock. For timing sensitive applications, this allows for
the fastest resump tion of devic e operation with its more
accurate pri mary clock source, si nce the cl ock source
does not have to “warm up” or transition from another
oscillator.
PRI_IDLE mode is entered from PRI_RUN mode by
setting the IDLEN bit and executing a SLEEP instruction. If the device is in another Run mode, set IDLEN
first, then clear the SCS bits and execute SLEEP.
Although the CPU is disab led, th e peri pherals c ontinu e
to be clocked from the primary clock source specified
by the FOSC3:FOSC0 config uration bit s. The OSTS bit
remains set (see Figure3-7).
When a wake event occurs, the CPU is clocked from the
primary clock source. A delay of interval T
required between the wake event and when code
execution starts. This is required to allo w the CPU to
become ready to execute instructions. After the
wake-up, the OSTS bit remains set. The IDLEN and
SCS bits are not affected by the wake-up (see
Figure 3-8).
CSD is
3.4.2SEC_IDLE MODE
In SEC_IDLE mode, the CPU is disabled but the
peripherals continue to be clocked from the Timer1
oscillator. This mode is entered from SEC_RUN by setting the IDLEN bit and executi ng a SLEEP instruction. If
the device is in another Run mode, set the IDLEN bit
first, then set the SCS1:SCS0 bits to ‘01’ and execute
SLEEP. When the clock source is switched to the
Timer1 oscillator, the primary oscillator is shut down,
the OSTS bit is cleared and the T1RUN bit is set.
When a wake event occ urs, the pe ripherals continue to
be clocked from the Timer1 oscillator. After an interval
CSD following the wake event, the CPU begi ns ex e-
of T
cuting code being cloc ked by the T im er1 oscil lator . Th e
IDLEN and SCS bits are not affected by the wake-up;
the Timer1 oscillator continues to run (see Figure 3-8).
Note:The Timer1 oscillator should already be
running prior to entering SEC_IDLE mod e.
If the T1OSCEN bit is not set when the
SLEEP instruction is executed, the SLEEP
instruction will be ignored and entry to
SEC_IDLE mode will not occur. If the
Timer1 oscillator is enabled but not yet
running, peripheral clocks will be delayed
until the oscillator has started. In such
situations, initial oscillator operation is far
from stable and unpredictable operation
may result.
FIGURE 3-7:TRANSITION TIMING FOR ENTRY TO IDLE MODE
Q1
OSC1
CPU Clock
Peripheral
Clock
Program
Counter
Q1
Q4
Q2
Q3
PCPC + 2
FIGURE 3-8:TRANSITION TIMING FOR WAKE FROM IDLE TO RUN MODE
OSC1
CPU Clock
Peripheral
Clock
Program
Counter
Q1Q3Q4
TCSD
PC
Q2
Wake Event
DS39637A-page 38Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
3.4.3RC_IDLE MODE
In RC_IDLE mode, t he C PU is d isabled but the peripherals continue to b e c loc ke d fro m t he internal oscillator
block using the INTOSC multiplexer. This mode allows
for controllable power cons ervation during Idl e periods .
From RC_RUN, this mode is entered by setting the
IDLEN bit and executing a SLEEP instruction. If the
device is in a nother Run mode, first s et IDLEN, th en set
the SCS1 bit and execute SLEEP. Although its value is
ignored, it is reco mmended that SCS0 also be cle ared;
this is to maintain software compatibility with future
devices. The INTOSC multiplexer may be used to
select a higher clo ck fr equ enc y, by modifying the IRCF
bits, before executing the SLEEP instruction. When the
clock source is switched to the IN TOSC mult iplexer , the
primary oscillator is shut down and the OSTS bit is
cleared.
If the IRCF bits are set to any non-zero value or the
INTSRC bit is set, the INTOSC output is enabled. The
IOFS bit becomes set, after the INTOSC output
becomes stable, after an interval of T
(parameter 39, Table 27-10). Clocks to the peripherals
continue while the INTOSC source stabilizes. If the
IRCF bits were previously at a non-zero value, or
INTSRC was set before the SLEEP instruction was
executed and the INTOSC source was already stable,
the IOFS bit will remain set. If the IRCF bits and
INTSRC are all clear, the INTOSC output will not be
enabled, the IOF S bit will remain c lear and t here will b e
no indication of the current clock source.
When a wake event occ urs, the pe ripherals co ntinue to
be clocked from the INTOSC multiplexer. After a delay
CSD following the wake event, the CP U begins exe-
of T
cuting code being clocked by the INTOSC multiplexer.
The IDLEN and SCS bits are not affected by the
wake-up. The INTRC source will continue to run if
either the WDT or the Fail-Safe Clock Monitor is
enabled.
IOBST
3.5Exiting Idle and Sleep Modes
An exit from Sleep mode or any of the Idle modes is
triggered b y an interrupt , a Reset or a WDT time-out.
This section discusses the triggers that cause exits
from power managed modes. The clocking subsystem
actions are discussed in each of the power managed
modes (see Section 3.2 “Run Modes”, Section 3.3“Sleep Mode” and Section 3.4 “Idle Modes”).
3.5.1EXIT BY INTERRUPT
Any of the available interrupt sources can cause the
device to exit from an Idle mode or the Sleep mode to
a Run mode. To enable this functionality, an interrupt
source must be enab led by s etti ng i t s en able bit in one
of the INTCON or PIE registers. The exit sequence is
initiated when the c orresponding interrupt flag bit is set.
On all exits from Idl e or Sleep modes by interrupt, code
execution branches to the interrupt vector if the
GIE/GIEH bit (INTCON<7>) is set. Otherwise, code
execution continues or resumes without branching
(see Section 9.0 “Interrupts”).
A fixed delay of inter val T
is required when leaving Sleep and Idle modes. This
delay is required for the CPU to prepare for execution.
Instructio n execution r esumes on th e first clock c ycle
following this delay.
CSD following th e wak e ev en t
3.5.2EXIT BY WDT TIME-OUT
A WDT time-out will cause different actions depending
on which power managed mode the device is in when
the time-out occurs.
If the device i s not exec uti ng code (al l Idle mode s and
Sleep mode), the time-out will res ul t in a n ex it fro m the
power managed mode (see Sec tion 3.2 “Run Modes”
and Section 3.3 “Sleep Mode”). If the device is
executing code (a ll Run mode s), th e time-out will resu lt
in a WDT Reset (se e Section 24.2 “Watchdog Timer(WDT)”).
The WDT timer and postscaler are cleared by executing a SLEEP or CLRWDT instruction, the loss of a
currently selected clock source (if the Fail-Safe Clock
Monitor is enabled) and modifying the IRCF bits in the
OSCCON register if the internal oscillator block is the
device clock source.
3.5.3EXIT BY RESET
Normally, the device is held in Reset by the Oscillator
Start-up Timer (OST) until the primary clock becomes
ready. At that time, the OSTS bit is set and the device
begins executing code. If the internal oscillator block is
the new clock source, the IOFS bit is set instead.
The exit delay time from Reset to the start of code
execution depends on both the clock sources before
and after the wake-up and the type of oscillator if the
new clock source is the primary clock. Exit delays are
summarized in Table 3-2.
Code execution can begin before the primary clock
becomes ready. If either the Two-Speed Start-up (see
Section 24.3 “Two-Speed Start-up”) or Fail-Safe
Clock Monitor (see Section 24.4 “Fail-Safe ClockMonitor”) is enabled, the device may begin execution
as soon as the Reset source ha s cle are d. Execution is
clocked by the INTOSC multiplexer driven by the
internal oscillator block. Execution is clocked by the
internal oscillator block until either the primary clock
becomes ready or a power managed mode is entered
before the primary clock becomes ready; the primary
clock is then shut down.
Certain exits from power managed modes do not
invoke the OST at all. There are two cases:
• PRI_IDLE mode where the primary clock source
is not stopped; and
• the primary clock source is not any of the LP, XT,
HS or HSPLL modes.
In these instances, the primary clock source either
does not require an oscillator start-up delay, since it is
already running (PRI_IDLE), or normally does not
require an oscillator start-up delay (RC, EC and INTIO
Oscillator modes). However, a fixed delay of interval
CSD following the wake event is still required when
T
leaving Sleep and Idle modes to allow the CPU to prepare for execution. Instruction execution resumes on
the first clock cycle following this delay.
TABLE 3-2:EXIT DELAY ON WAKE-UP BY RESET FROM SLEEP MODE OR ANY IDLE MODE
(BY CLOCK SOURCES)
Clock Source
before Wake-up
Primary Device Clo ck
(PRI_IDLE mode)
T1OSC or INTRC
INTOSC
None
(Sleep mode)
Note 1:In this instance, refers specifically to the 31 kHz INTRC clock source.
2:TCSD (parameter 38) is a req uired delay whe n wakin g from Sleep and a ll Idl e mod es an d runs concurr entl y
with any other required delays (see Section 3.4 “Idle Modes”).
3:Includes both the INTOSC 8 MHz source and postscaler derived frequencies.
4:TOST is the Oscillator Start-up Timer (parameter 32). trc is the PLL Lock-out Timer (p aram eter F12); it is
also designated as T
5:Execution continues during T
(1)
(3)
PLL.
Clock Source
After Wake-up
Exit Delay
LP, XT, HS
(2)
EC, RC
(1)
INTRC
INTOSC
(3)
LP, XT, HSTOST
HSPLLT
EC, RC
(1)
INTRC
INTOSC
(2)
LP, XT, HSTOST
HSPLLT
EC, RC
(1)
INTRC
INTOSC
(2)
LP, XT, HST
HSPLLT
EC, RC
(1)
INTRC
INTOSC
IOBST (parameter 39), the INTOSC stabilization period.
(2)
CSD
T
(4)
T
T
CSD
CSD
(2)
(5)
(2)
rc
rc
(4)
(5)
(4)
OST + t
TIOBST
OST + t
NoneIOFS
(4)
OST
T
CSD
(2)
rc
(4)
(5)
OST + t
TIOBST
Clock Ready Status
bit (OSCCON)
OSTSHSPLL
—
IOFS
OSTS
—
IOFS
OSTS
—
OSTS
—
IOFS
DS39637A-page 40Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
4.0RESET
A simplified block di agram of the On-Chip Reset Circu it
is shown in Figure 4-1.
The PIC18F2480/2580/4480/4580 devices differentiate
between various kinds of Reset:
a)Power-on Reset (POR)
b)MCLR
Reset during normal operation
c)MCLR Reset during power managed modes
d)Watchdog Timer (WDT) Reset (during
This section discusses Resets generated by MCLR
POR and BOR and covers the ope rati on o f the various
start-up timers. Stack Reset events are covered in
Section 5.1.2.4 “Stack Full and Underflow Resets”.
WDT Resets are co v ere d i n Section 24.2 “Watchdog
,
4.1RCON Register
Device Reset events are tracked through the RCON
register (Register 4-1). The lower five bits of the register indicate that a specif ic Reset eve nt has occu rred. In
most cases, thes e bits c an only be cl eared by the e vent
and must be set by the app lication after the event. The
state of these flag bits, taken together, can be read to
indicate the type of Reset that just occurred. This is
described in more detail in Sectio n 4.6 “Rese t Stateof Registers”.
The RCON register also has control bits for setting
interrupt priority (IPEN) and software control of the
BOR (SBOREN). Interrupt priority is discussed in
Section 9.0 “Interrupts”. BOR is covered in
Section 4.4 “Brown-out Reset (BOR)”.
Timer (WDT)”.
FIGURE 4-1:SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
RESET
Instruction
Stack
Pointer
Stack Full/Underflow Reset
MCLR
VDD
OSC1
( )_IDLE
Sleep
WDT
Time-out
DD Rise
V
Detect
Brown-out
Reset
OST/PWRT
32 µs
(1)
INTRC
External Reset
MCLRE
POR Pulse
BOREN
OST
PWRT
1024 Cycles
10-bit Ripple Counter
65.5 ms
11-bit Ripple Counter
S
Chip_Reset
R
Q
Enable PWRT
Enable OST
(2)
Note 1: This is the INTRC source from the internal oscillator block and is separate from the RC oscillator of the CLKI pin.
1 = Enable priority levels on interrupts
0 =Disable priority levels on interrupts (16CXXX Compatibility mode)
bit 6SBOREN: BOR Software Enable bit
If BOREN1:BOREN0 = 01:
1 =BOR is enabled
0 =BOR is disabled
If BOREN1:BOREN0 =
Bit is disabled and read as ‘0’.
bit 5Unimplemented: Read as ‘0’
bit 4RI: RESET Instruction Flag bit
1 = The RESET instruction was not executed (set by firmware only)
0 = The RESET instruction was executed causing a device Reset (must be set in software after
a Brown-out Reset occur s )
bit 3TO: Watchdog Time-out Flag bit
1 =Set by power-up, CLRWDT instruction or SLEEP instruction
0 =A WDT time-out occurred
bit 2PD
bit 1POR
bit 0BOR
: Power-down Detection Flag bit
1 =Set by power-up or by the CLRWDT instruction
0 =Set by execution of the SLEEP instruction
: Power-on Reset Status bit
1 =A Power-on Reset has not occurred (set by firmware only)
0 =A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Reset Status bit
1 =A Brown-out Reset has not occurred (set by firmware only)
0 =A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)
Note 1: If SBOREN is enabled, its Reset state is ‘1’; otherwise, it is ‘0’.
2: The actual Reset val ue o f POR
(1)
notes following this register and Section 4.6 “Reset State of Registers” for
additional information.
U-0R/W-1R-1R-1R/W-0
—RITOPDPORBOR
(1)
00, 10 or 11:
(2)
is determined by the t ype of device Reset. See the
(2)
R/W-0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Note 1: It is recommended that the POR bit be set after a Power-on Reset has been
detected so that subsequent Power-on Resets may be detected.
2: Brown-out Reset is said to have occurred when BOR
that POR
DS39637A-page 42Preliminary 2004 Microchip Technology Inc.
was set to ‘1’ by software immediately after POR).
is ‘0’ and POR is ‘1’ (assumin g
PIC18F2480/2580/4480/4580
4.2Master Clear Reset (MCLR)
The MCLR pin provides a method for triggering an
external Reset of the device. A Reset is generated by
holding the pin low. These devices have a noise fi lter in
the MCLR
Reset path which detects and ignores small
pulses.
The MCLR
pin is not drive n low by any inter nal Reset s,
including the WDT.
In PIC18F2480/2580/4480/4580 devices, the MCLR
input can be disabl ed with the MCL RE configuratio n bit.
When MCLR
is disabled, the pin becomes a digital
input. See Section 10.5 “PORTE, TRISE and LATE
Registers” for more information.
4.3Power-on Reset (POR)
A Power-on Reset pulse is generated on-chip
whenever V
allows the device to start in the initialized state when
VDD is adequate for operation.
To take advantage of the POR circuitry, tie the MCLR
pin throug h a resis tor (1 kΩ to 10 kΩ) to VDD. This will
eliminate external RC components usually needed to
create a Power-on Re set delay. A minimum rise rate for
DD is specified (parameter D004). For a slow rise
V
time, see Figure 4-2.
When the device st arts normal operation (i.e., exits the
Reset condition), device operating parameters
(voltage, frequency, temperature, etc.) must be met to
ensure operation. If these conditions are not met, the
device must be held in Reset until the operating
conditions are met.
POR events are captured by the POR
The state of the bit is set to ‘0’ whe never a POR occurs;
it does not change for any other Reset event. POR is
not reset to ‘1’ by any hardware event. To capture
multiple events, the user manually resets the bit to ‘1’
in software following any POR.
DD rises above a certain threshold. This
bit (RCON<1>).
FIGURE 4-2:EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW V
DD
VDD
Note 1: Ex ternal Power-on Reset circuit is required
V
D
R
C
only if the V
The diode D helps discharge the capacitor
quickly when V
2: R < 40 kΩ is recommended to make sure that
the voltage drop across R does not violate
the device’s electrical specification.
3: R1 ≥ 1 kΩ will limit any current flowing into
MCLR
of MCLR
static Discharge (ESD) or Electrical
Overstress (EOS).
PIC18F2480/2580/4480/4580 devices implement a
BOR circuit that provides the user with a number of
configuration and power-saving options. The BOR is
controlled by the BORV1:BORV0 and
BOREN1:BOREN0 configura tion b its . There are a tota l
of four BOR configurations which are summarized in
Table 4-1.
The BOR threshold is set by t he BOR V1:BOR V0 bit s. If
BOR is enabled (any values of BOREN1:BOREN0,
except ‘00’), any drop of V
D005) for greater than T
the device. A Reset may or may not occur if V
below V
Brown-out Reset until V
If the Power-up T imer is enabl ed, it will be inv oked after
V
Reset for an additional time delay, T
(parameter 33). If VDD drops below VBOR while the
Power-up Timer is running, the chip will go back into a
Brown-out Reset and the Power-up Timer will be
initialized. Once V
Timer will execute the additional time delay.
BOR and the Power-on Timer (PWRT) are
independently configured. Enabling BOR Reset does
not automatically enab le the PWRT.
BOR for less than TBOR. The chip will remain in
DD rises above VBOR; it then will keep the chip in
DD rises above VBOR, the Power-up
4.4.1SOFTWARE ENABLED BOR
When BOREN1:BOREN0 = 01, the BOR can be
enabled or disabled by the user in software. This is
done with the control bit, SBOREN (RCON<6>). Setting SBOREN enables the BOR to function as previously described. Clearing SBOREN disables the BOR
entirely. The SBOREN bit operates only in this mode;
otherwise it is read as ‘0’.
DD below VBOR (parameter
BOR (parameter 35 ) will reset
DD falls
DD rises above VBOR.
PWRT
Placing the BOR under software control gives the user
the additional flexibility of tailoring the application to its
environment withou t ha vi ng to reprogram the device to
change BOR configuration. It also allows the user to
tailor device power consumption in software by eliminating the incremental current that the BOR consumes.
While the BOR current is typically very small, it may
have some impact in low-power applications.
Note:Even whe n BOR is u nder softwar e control,
the BOR Reset voltage level is still set by
the BORV1:BORV0 configuration bits. It
cannot be changed in software.
4.4.2DETECTING BOR
When BOR is enab led, the BO R bit always resets to ‘0’
on any BOR or P OR event. This makes it diff icult to
determine if a BOR event has occurre d jus t by rea ding
the state of BOR
simultaneously check the state of both POR
This assumes th at the POR
immediately after any POR event. IF BOR
POR
is ‘1’, it can be reliably assum ed that a BOR event
has occurred.
alone. A more reliable method is to
and BOR.
bit is reset to ‘1’ in softwa re
is ‘0’ while
4.4.3DISABLING BOR IN SLEEP MODE
When BOREN1:BOREN0 = 10, the BOR remains
under hardware control and operates as previously
described. Whenever the device enters Sleep mode,
however , the BOR is au tom ati ca lly dis abl ed . When the
device returns to any other operating mode, BOR is
automatically re-enabled.
This mode allows for applications to recover from
brown-out situations, while actively executing code,
when the device requires BOR protection the most. At
the same time, it save s additional po wer in Sleep mod e
by eliminating the small incremental BOR current.
TABLE 4-1:BOR CONFIGURATIONS
BOR Configuration Status of
BOREN1BOREN0
00Unavailable BOR disabled; must be enabled by reprogramming the configuration bits.
01AvailableBOR enabled in software; operation controlled by SBOREN.
10Unavailable BOR enabled in hardware in Run and Idle modes, disabled during Sleep
11Unavailable BOR enabled in hardware; must be disabled by reprogramming the
DS39637A-page 44Preliminary 2004 Microchip Technology Inc.
SBOREN
(RCON<6>)
mode.
configuration bits.
BOR Operation
PIC18F2480/2580/4480/4580
4.5Device Reset Timers
PIC18F2480/2580/4480/4580 devices incorporate
three separate on-chip timers that help regulate the
Power-on Reset process. Their main function is to
ensure that the device clock is stable before code is
executed. These timers are:
• Power-up Timer (PWRT)
• Oscillator Start-up Timer (OST)
• PLL Lock Time-out
4.5.1POWER-UP TIMER (PWRT)
The Power-up Timer (PWRT) of PIC18F2480/2580/
4480/4580 devices is an 11-bit counter which uses the
INTRC source as the clock input. This yields an
approximate time interval of 2048 x 32 µs=65.6ms.
While the PWRT is counting, the device is held in
Reset.
The power-up time delay depe nd s on the INTRC cl oc k
and will vary from chip-to-chip due to temperature and
process variation. See DC parameter 33 for details.
The PWRT is enabled by clearing the PWRTEN
configuration bit.
4.5.2OSCILLATOR START-UP TIMER
(OST)
The Oscillator Start-up Timer (OST) provides a 1024
oscillator cycle (from OSC1 input) delay after the
PWRT delay is ov er (par a me t er 3 3 ). T h is en su re s t ha t
the crystal oscillator or resonator has started and
stabilized.
The OST time-out is invoked only for XT, LP, HS and
HSPLL modes and only on Power-on Reset or on exit
from most power managed modes.
4.5.3PLL LOCK TIME-OUT
With the PLL enabled in its PLL mode, the time-out
sequence following a Power-on Reset is slightly different from other oscillator modes. A separate timer is
used to provide a fixed time-out that is su fficient for the
PLL to lock to the main oscillator frequency. This PLL
lock time-o ut (T
oscillator start-up time-out.
PLL) is typically 2 ms and follows the
4.5.4TIME-OUT SEQUENCE
On power-up, the time-out sequence is as follows:
1.After the POR pulse has cleared, PWRT
time-out is invoked (if enabled).
2.Then, the OST is activated.
The total time-out will vary based on oscillator configuration and the status of the PWRT. Figure 4-3,
Figure 4-4, Figure 4-5, Figure 4-6 and Figure 4-7 all
depict time-out sequences on power-up, with the
Power-up Timer enabled and the device operating in
HS Oscillator mode. Figure s 4-3 through 4-6 also apply
to devices operating in XT or LP m odes. F or devi ces i n
RC mode and with the PWRT disabled, on the other
hand, there will be no time-out at all.
Since the time-outs occur from the POR pulse, if MC LR
is kept low long e nough, all ti me -out s will e xpire. Brin ging MCLR
(Figure 4-5). This is useful for testing purposes or to
synchronize more than one PIC18FXXXX device
operating in parallel.
high will begin execution immediately
TABLE 4-2:TIME-OUT IN VARIOUS SITUATIONS
Oscillator
Configuration
HSPLL66 ms
HS, XT, LP66 ms
EC, ECIO66 ms
RC, RCIO66 ms
INTIO1, INTIO266 ms
Note 1: 66 ms (65.5 ms) is the nominal Power-up Timer (PWRT) delay.
2: 2 ms is the nominal time required for the PLL to lock.
Most registers are unaffected by a Reset. Their status
is unknown on POR and unchanged by all other
Table 4-4 describes the Reset states for all of the
Special Function Registers. These are categorized by
Power-on and Brown-out Resets, Master Clear and
WDT Resets and WDT wake-ups.
Resets. The other registers are forced to a “Reset
state” depending on the type of Reset that occurred.
Most registers are not affected by a WDT wake-up,
since this is viewed as the resumption of normal operation. Status bits from the RCON register, RI
POR
and BOR, are set or cleare d dif ferently i n differe nt
, TO, PD,
Reset situations, as indicated in Table 4-3. These bits
are used in software to determine the nature of the
Reset.
TABLE 4-3:STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION FOR
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
2480 2580 4480 45800q-1 11q00q-q qquuuq-u qquu
2580 4480 45800-00 00000-00 0000u-uu uuuu
Shaded cells indicate condi tions do not apply for the designated device.
vector (0008h or 0018h).
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
not enabled as PORTA pins, they are disabled and read ‘0’.
Power-on Reset,
Brown-o ut Reset
WDT Reset,
RESET Instruction,
Stack Rese ts
Wake-up via WDT
or Interrupt
DS39637A-page 50Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 4-4:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
WDT Reset,
RESET Instruction,
Stack Rese ts
1111 1111
uuuu uuuu
uu0u 0000
(5)
(5)
(5)
Wake-up via WDT
or Interrupt
uuuu uuuu
uuuu uuuu
uuuu uuuu
(1)
(5)
(5)
(5)
DS39637A-page 52Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 4-4:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Power-on Reset,
Brown-o ut Reset
WDT Reset,
RESET Instruction,
Stack Rese ts
Wake-up via WDT
or Interrupt
DS39637A-page 54Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 4-4:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
2480 2580 4480 4580xxxx xxxxuuuu uuuuuuuu uuuuLegend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
WDT Reset,
RESET Instruction,
Stack Rese ts
Wake-up via WDT
or Interrupt
DS39637A-page 56Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 4-4:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
WDT Reset,
RESET Instruction,
Stack Rese ts
Wake-up via WDT
or Interrupt
DS39637A-page 58Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
TABLE 4-4:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, the T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ‘0’, q = value depends on condition.
Shaded cells indicate condi tions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and t he GIEL or G IEH bit is se t, the PC is lo aded with th e interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is s et, th e T O SU, T O SH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 4-3 for Reset value for specific condition.
5: Bits 6 and 7 of PORTA, LATA and TRISA are enabled, depending on the oscillator mode selected. When
not enabled as PORTA pins, they are disabled and read ‘0’.
6: This register reads all ‘0’s until ECAN™ technology is set up in Mode 1 or Mode 2.
WDT Reset,
RESET Instruction,
Stack Rese ts
Wake-up via WDT
or Interrupt
DS39637A-page 60Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.0MEMORY ORGANIZATION
There are three types of memory in PIC18 Enhanced
microcontroller devices:
• Program Memory
• Data RAM
• Data EEPROM
As Harvard architecture dev ices, the dat a and progra m
memories use separate busses; this allows for concurrent access of the two memory spaces. The data
EEPROM, for practical purposes, can be regarded as
a peripheral device, since it is addresse d and accessed
through a set of control registers.
Additional detailed information on the operation of the
Flash program memory is provided in Section 6.0“Flash Program Memory”. Data EEPROM is discussed separately in Section 7.0 “Data EEPROM
Memory”.
5.1Program Memory Organization
PIC18 microcontrollers implement a 21-bit program
counter, which is capable of addressing a 2-Mbyte
program memory sp ace. Accessi ng a loca tion betwee n
upper boundary of the phys ically im plemente d memor y
and the 2-Mbyte address will return all ‘0’s (a NOP
instruction).
The PIC18F2480 and PIC18F4480 each have
16 Kbytes of Flash memory and can store up to 8,192
single-word instructions. The PIC18F2580 and
PIC18F4580 each have 32 Kbytes of Flash memory
and can store up to 16,384 single-word instructions.
PIC18 devices have two interrupt vectors. The Reset
vector address is at 0000h and the interrupt vector
addresses are at 0008h and 0018h.
The program memory maps for PIC18FX480 and
PIC18FX580 devices are shown in Figure 5-1.
FIGURE 5-1:PROGRAM MEMORY MAP AND STACK FOR
PIC18F2480/2580/4480/4580 DEVICES
PIC18FX480
PC<20:0>
CALL,RCALL,RETURN
RETFIE,RETLW
Stack Level 1
Stack Level 31
Reset Vector
High Priority Interrupt Vector
Low Priori ty Interrupt Vector
The Program Counter (PC) specifies the address of the
instruction to fetch for execu tion. The PC is 21 bits wide
and is contained in three separate 8-bit registers. The
low byte, known as the PCL register, is both readable
and writable. The high byt e, or PCH re gister, contains
the PC<15:8> bits; i t is not directly re adable or writ able.
Updates to the PCH register are perfo rmed through the
PCLATH register. The upper byte is called PCU. This
register contains the PC<20:16> bits; it is also not
directly readable or writable. Updates to the PCU
register are performed through the PCLATU register.
The contents of PCLATH and PCLATU are transferred
to the program counter by any operation that writes
PCL. Similarly, the upper two bytes of the program
counter are transferred to P CLATH and PCLATU by a n
operation that reads PCL. This is useful for computed
offsets to the PC (see Section 5.1.4.1 “ComputedGOTO”).
The PC addresses bytes in the program memory. To
prevent the PC from becoming misaligned with word
instructions, the Least Significant bit of PCL is fixed to
a value of ‘0’. The PC increments by 2 to address
sequential instructions in the program memory.
The CALL, RCALL and GOTO program branch
instructions write to the program counter directly. For
these instructions, the contents of PCLATH and
PCLATU are not transferred to the program counter.
5.1.2RETURN ADDRESS STACK
The return address s tack allows any co mb in atio n of u p
to 31 program calls and interrupts to occur. The PC is
pushed onto th e stac k when a CALL or RCALL instruction is executed or an interrupt is Acknowledged. The
PC value is pulled off the stack on a RETURN, RETLW
or a RETFIE instruction. PCLATU and PCLATH are not
affected by any of the RETURN or CALL instruct ions.
The stack operates as a 31-word by 21-bit RAM and a
5-bit Stack Pointer, STKPTR. The stack space is not
part of either program or da ta sp ace. The Stack Pointer
is readable and writable and the address on the top of
the stack is readable and writable through the
top-of-stack Special File Registers. Data can also be
pushed to, or popped from the stack, using these
registers.
A CALL type instru ctio n caus es a pus h ont o the stac k;
the Stack Pointer is first incremented and the location
pointed to by the Stack Pointer is written with the
contents of the PC (already pointing to the instruction
following the CALL). A RETURN ty pe ins truc ti on c au se s
a pop from the stack; the contents of the location
pointed to by the STKPTR are transferred to the PC
and then the Stack Pointer is decremented.
The Stack Pointer is initialized to ‘00000’ after all
Resets. There is no RAM associated with the location
corresponding to a Stack Pointer value of ‘00000’; this
is only a Reset value. Status bits indicate if the st ac k i s
full or has overflowed or has underflowed.
5.1.2.1Top-of-S tack Access
Only the top of the return address stack (TOS) is
readable and writable. A set of three registers,
TOSU:TOSH:TOSL, hold th e contents of the stack location pointed to by the STKPTR register (Figure 5-2). This
allows users to implement a software stack if necessary.
After a CALL, RCALL or interrupt, the software can read
the pushed value by reading the TOSU:TOSH:TOSL
registers. These values can be placed on a use r defined
software stack. At return time, the software can return
these values to TOSU:TOSH:TOSL and do a return.
The user must disable the global interrupt enable bits
while accessing the stack to prevent inadvertent stack
corruption.
FIGURE 5-2:RETURN ADDRESS STACK AND ASSOCIATED REGISTERS
Return Address Stack <20:0>
11111
T op -of-Stack RegistersStack Pointer
TOSLTOSHTOSU
34h1Ah00h
Top-of-Stack
DS39637A-page 62Preliminary 2004 Microchip Technology Inc.
001A34h
000D58h
11110
11101
STKPTR<4:0>
00010
00011
00010
00001
00000
PIC18F2480/2580/4480/4580
5.1.2.2Return Stack Pointer (STKPTR)
The STKPTR register (Reg ister 5-1) contains the S t ack
Pointer value, the STKFUL (Stack Full) status bit and
the STKUNF (Stack Underflow) status bits. The value
of the Stack Pointer can be 0 through 31. The Stack
Pointer increments before values are pushed onto the
stack and decrements after values are popped off the
stack. On Reset, the Stack Pointer value will be zero.
The user may read and write the Stack Pointer value.
This feature can be used by a Real-Time Operating
System for return stack maintenance.
After the PC is pus hed o nto the st ack 31 times (wi thout
popping any values off the stack), the STKFUL bit is
set. The STKFUL bit is cleared by software or by a
POR.
The action that takes place when the stack becomes
full depends on the state of the STVREN (Stack Overflow Reset Enable) configuration bit. (Refer to
Section 24.1 “Configuration Bits” for a de scription of
the device configuration bits.) If STVREN is set
(default), the 31st push will push the (PC + 2) value
onto the stack, set the STKFUL bit and reset the
device. The STKFUL bit will remain set and the Stack
Pointer will be set to zero.
If STVREN is cleared, the STKFUL bi t will be set on the
31st push and the Stack Pointer will increment to 31.
Any additional pushes will not overwrite the 31st push
and STKPTR will remain at 31.
When the stack has been popped enough times to
unload the stac k, the next pop will ret urn a value of zero
to the PC and sets the STKUNF bit, while the Stack
Pointer remains at zero. The STKUNF bit will remain
set until cleared by software or until a POR occurs.
Note:Returning a value of zero to the PC on an
underflow has the effect of vectoring the
program to the Reset vector, where the
stack conditions can be verified and
appropriate actions can be taken. This is
not the same as a Reset, as the contents
of the SFRs are not affected.
5.1.2.3PU SH and POP Ins tr uctions
Since the Top-of-Stack is readable and writable, the
ability to push value s on to the st ac k an d pul l va lues off
the stack without disturbing normal program execution
is a desirable feature. The PIC18 instruction set
includes two instructions, PUSH and POP, that permit
the TOS to be manipulated under software control.
TOSU, TOSH and T OS L can be m odifie d to plac e dat a
or a return address on the stack.
The PUSH instruction places the current PC value onto
the stack. This increments the Stack Pointer and loads
the current PC value onto the stack.
The POP instruction discards the current TOS by decrementing the Stack Pointer. The previous value pushed
onto the stack then becomes the TOS value.
REGISTER 5-1:STKPTR: STACK POINTER REGISTER
R/C-0R/C-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0
STKFUL
bit 7bit 0
bit 7STKFUL: Stack Full Flag bit
1 = Stack became full or overflowed
0 = Stack has not become full or overflowed
bit 6STKUNF: Stack Underflow Flag bit
1 = Stack underflow occurred
0 = Stack underflow did not occur
bit 5Unimplemented: Read as ‘0’
bit 4-0SP4:SP0: Stack Pointer Location bits
Legend:
R = Readable bitW = Writable bitU = UnimplementedC = Clearable only bit
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
(1)
STKUNF
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
Device Resets on stack overflow and stack underflow
conditions are enabled by setting the STVREN bit in
Configuration Regist er 4L. When STVREN is set, a full
or underflow will set the appropriate STKFUL or
STKUNF bit and then cause a device Reset. When
STVREN is cleared, a full or underflow condi tion will set
the appropriate STKFUL or STKUNF bit but not cause
a device Reset. The STKFUL or STKUNF bits are
cleared by the user software or a Power-on Reset.
5.1.3FAST REGISTER STACK
A fast register stack is provided for the Status, WREG
and BSR registers, to provide a “fast return” option for
interrupts. Each stack is only one level deep and is
neither readable nor writable. It is loaded with the
current value of the corresponding register when the
processor vectors for an interrupt. All interrupt sources
will push val ues into t he s tack re gist ers. The v alue s in
the registers ar e then load ed ba ck i nto th eir a ssoc iated
registers, if the RETFIE, FAST ins truction is used to
return from the interrupt.
If both low and high priority interrupts are enabled, the
stack registers cannot be used reliably to return from
low priority interrupts. If a high priority interrupt occurs
while servicing a low priori ty interrupt, the stack register
values stored by the low priority interrupt will be
overwritten. In these cases, users must save the key
registers in software during a low priority interrupt.
If interrupt priority is not used, all interrupts ma y use the
fast register stack for returns from interrupt. If no interrupts are used, the fast register stack can be used to
restore the S tatus, WREG and BSR registers at th e end
of a subroutine call. To use the fast register stack for a
subroutine call, a CALL label, FAST instruction mus t
be executed to sav e the S t atus, WR EG and BSR re gisters to the fast register stack. A RETURN, FAST
instruction is then executed to restore these registers
from the fast register stack.
Example 5-1 shows a source code example that uses
the fast register stack during a subroutine call and
return.
EXAMPLE 5-1:FAST REGISTER STACK
CODE EXAMPLE
CALL SUB1, FAST;STATUS, WREG, BSR
;SAVED IN FAST REGISTER
;STACK
•
•
SUB1 •
•
RETURN, FAST;RESTORE VALUES SAVED
;IN FAST REGISTER STACK
5.1.4LOOK-UP TABLES IN PROGRAM
MEMORY
There may be programming situations that require the
creation of data structures, or look-up tables, in
program memory. For PIC18 devices, look-up tables
can be implemented in two ways:
• Computed GOTO
• Table Reads
5.1.4.1Computed GOTO
A computed GOTO is accomplished by adding an of fs et
to the program counter. An example is shown in
Example 5-2.
A look-up table can be formed with an ADDWF PCL
instruction and a group of RETLW nn instructions. The
W register is loaded with an of fs et into the table before
executing a call to tha t t a ble . The first instruction of the
called routine is the ADDWF PCL instruction. The next
instruction executed will be one of the RETLW nn
instructions, that returns the value ‘nn’ to the calling
function.
The offset value (in WREG) specifies the number of
bytes that the program counter should advance and
should be multiples of 2 (LSb = 0).
In this method, only one data byte may be stored in
each instruction location and room on the return
address stack is required.
EXAMPLE 5-2:COMPUTED GOTO USING
AN OFFSET VALUE
MOVFOFFSET, W
CALLTABLE
ORG nn00h
TABLEADDWFPCL
RETLWnnh
RETLWnnh
RETLWnnh
.
.
.
5.1.4.2Table Reads and Table Writes
A better method of storing data in program memory
allows two bytes of dat a to be stored in each instruction
location.
Look-up table data may be stored two bytes per
program word by using table reads and writes. The
Table Pointer (TBLPTR) register specifies the byte
address and the Table Latch (TABLAT) register contains the data that is read from or written to program
memory. Data is transferred to or from program
memory one byte at a time.
Table read and table write operations are discussed
further in Section 6.1 “Table Reads and TableWrites”.
DS39637A-page 64Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.2PIC18 Instruction Cycle
5.2.1CLOCKING SCHEME
The microc on t rol l er c l oc k i n pu t, w het h er fro m an i n te rnal or external source, is internally divided by four to
generate four non-overlapping quadrature clocks (Q1,
Q2, Q3 and Q4). Internally, the Program Counter (PC)
is incremen ted on ev ery Q1; t he inst ruction is fetch ed
from the program memory and lat ched int o the Instru ction Register (IR) d uring Q4. The ins truction is d ecoded
and executed during the following Q1 through Q4. The
clocks and instruction execution flow are shown in
Figure 5-3.
FIGURE 5-3:CLOCK/INSTRUCTION CYCLE
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKO
(RC mode)
Q2Q3Q4
Q1
PCPC + 2PC + 4
Execute INST (PC – 2)
Fetch INST (PC)
Q2Q3Q4
Q1
Execute INST (PC)
Fetch INST (PC + 2)
5.2.2INSTRUCTION FLOW/PIPELINING
An “Instruction Cycle” consists of four Q cycles: Q1
through Q4. The instruction fetch and execute are
pipelined in such a manner that a fetch takes one
instruction cycle, while the decode and execute take
another instruction cycle. However, due to the
pipelining, each instruction effectively executes in one
cycle. If a n instruc tion caus es the pro gram coun ter to
change (e.g., GOTO), then two cycles are required to
complete the instruction (Example 5-3 ).
A fetch cycle begins with the program counter
incrementing in Q1.
In the execution cy cle, the fetch ed instruction i s latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3 and Q4 c ycles. Dat a m emory is read during Q2
(operand read) and written during Q4 (destination
write).
Q2Q3Q4
Q1
Internal
Phase
Clock
Execute INST (PC + 2)
Fetch INST (PC + 4)
EXAMPLE 5-3:INSTRUCTION PIPELINE FLOW
TCY0TCY1TCY2TCY3TCY4TCY5
1. MOVLW 55h
2. MOVWF PORTB
3. BRA SUB_1
4. BSF PORTA, BIT3 (Forced NOP)
5. Instruction @ address SUB_1
Note:All instructions are single cycle, except for any program branches. These take two cycles since the
fetch instruction is “flushed” from the pipeline while the new instruction is being fetched and then
executed.
The program memory is addressed in bytes. Instructions are stored as two bytes or four bytes in program
memory. The Least Significant Byte of an instruction
word is always stored in a program memory location
with an even address (LSB = 0). To maintain alignment
with instruction bo undaries , the PC incr ements in step s
of 2 and the LSB will alway s read ‘0’ (see Section 5.1.1“Program Counter”).
Figure 5-4 shows an exam ple of h ow in st ruc tion w ord s
are stored in the program memory.
The CALL and GOTO instructions have the absolute program memory address embedded into the instruction.
Since instructions are always stored on word boundaries, the data contained in the instruction is a word
address. The word address is written to PC<20:1>,
which accesses the desired byte address in program
memory. Instruction #2 in Figure 5-4 shows how the
instruction GOTO 0006h is encoded in the program
memory. Program branch instructions, which encode a
relative address offset, operate in the same ma nner. The
offset value stored in a br anch instruction represent s the
number of single-word instructions that the PC will be
offset by. Section 25.0 “Instruction Set Summary”
provides further details of the instruction set.
The standard PIC18 instruction set has four two-word
instructions: CALL, MOVFF, GOTO and LSFR. In all
cases, the second word of the in struc tion s always has
‘1111’ as its four M ost Si gnifican t bit s; the other 12 bit s
are literal data, usually a data memory address.
The use of ‘1111’ in the 4 MSbs of an instruction specifies a special form of NOP. If the instruction is executed
in proper sequence – immediately after the first wor d –
the data in the s econd word is ac cessed an d used by
the instruction seq ue nce . If th e fi rst word is skipped for
some reason and the se cond word is ex ecuted by itsel f,
a NOP is executed instead. This is necessary for cases
when the two-word instruction is preceded by a conditional instruction that changes the PC. Example 5-4
shows how this works.
Note:See Section 5.5 “Program Memory and
the Extended Instruction Set” for infor-
mation on two-word instructions in the
extended instruction set.
EXAMPLE 5-4:TWO-WORD INSTRUCTIONS
CASE 1:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2 ; No, skip this word
1111 0100 0101 0110; Execute this word as a NOP
0010 0100 0000 0000ADDWFREG3; continue code
CASE 2:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2 ; Yes, execute this word
1111 0100 0101 0110; 2nd word of instruction
0010 0100 0000 0000ADDWFREG3; continue code
DS39637A-page 66Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.3Data Memory Organization
Note:The operation of some aspects of data
memory are changed when the PIC18
extended instruction set is enabled. See
Section 5.6 “Data Memory and the
Extended Instruction Set” for more
information.
The data memory i n P IC 1 8 d ev ic es is imp lem en t ed as
static RAM. Each register in the data memory has a
12-bit address, allowing up to 4096 bytes of data
memory . The m emory sp ace is div ided into as many as
16 banks that contain 256 bytes each;
PIC18F2480/2580/4480/4580 devices implement all
16 banks. Figure 5-6 shows the data memory
organization for the PIC18F2480/2580/4480/4580
devices.
The data memory contains Special Function Registers
(SFRs) and General Purpose Registers (GPRs). The
SFRs are used for control and status of the controller
and peripheral functio ns, while GPRs are us ed for data
storage and scratchpad operations in the user’s application. Any read of an unimpl emented location will read
as ‘0’s.
The instruction set and architecture allow operations
across all banks. The entire data memory may be
accessed by Direct, Indirect or Indexed Addressing
modes. Addressing modes are discussed later in this
subsection.
To ensure that commonly used registers (SFRs and
select GPRs) c an b e ac cess ed i n a si ngle cycle, PI C18
devices impl em ent an Ac ce ss Ba nk . Th is i s a 256-byte
memory space that pr ovid es fa st acces s to SFRs a nd
the lower portion of GPR Bank 0 without using the
BSR. Section 5.3.2 “Access Bank” provides a
detailed description of the Access RAM.
5.3.1BANK SELECT REGISTER (BSR)
Large areas of data memory require an efficient
addressing scheme to make rapid access to any
address possible. Ideally, this means that an entire
address does not need to be provided for each read or
write operation. For PIC18 devices, this is accomplished with a RAM banking scheme. This divides the
memory space into 16 contiguous banks of 256 bytes.
Depending on the instruction, each location can be
addressed directly by its full 12-bit address, or an 8-bit
low-order address and a 4-bit bank pointer.
Most instruct ions in th e PIC18 in struct ion set ma ke use
of the bank poin ter, known as the Bank Select Reg ister
(BSR). This SFR holds the 4 Most Significant bits of a
location’s address; the instruction itself includes the
8 Least Significant bits. Only the four lower bits of the
BSR are implemented (BSR3:BSR0). The upper four
bits are unused; the y will always read ‘ 0’ and cannot be
written to. The BSR can be l oaded direc tly by using the
MOVLB instruction.
The value of the BSR indicates the bank in data memory; the 8 bits in the instru ction s how the lo cation in th e
bank and can be thought of as an of fset from the bank’ s
lower boundary. The relationship between the BSR’s
value and the ban k divis ion in da ta memory i s shown i n
Figure 5-7.
Since up to 16 regis ters m ay share the s ame l ow-order
address, the user must alway s be careful to ensure that
the proper bank is selected before performing a data
read or write. For example, writing what should be
program data to an 8-bit addre ss of F9 h, while the BSR
is 0Fh will end up resetting the Program Counter.
While any bank can be s el ec ted, only those banks that
are actually implemented can be read or written to.
Writes to unimplemented banks are ignored, while
reads from unimplemented banks will return ‘0’s. Even
so, the St atus register will still be affected as if the operation was successful. The data memory map in
Figure 5-6 indicates which banks are implemented.
In the core PIC18 instruction set, only the MOVFF
instruction fully specifies the 12-bit address of the
source and target registers. This i nstruction ig nores the
BSR completely when it ex ecutes. All o ther instruction s
include only the low-order address as an operand and
must use either the BSR or the Access Bank to locate
their target registers.
FIGURE 5-7:USE OF THE BANK SELECT REGISTER (DIRECT ADDRESSING)
Memory
7
BSR
0000
Bank Select
(2)
(1)
0
0011
000h
100h
200h
300h
Data
Bank 0
Bank 1
Bank 2
Bank 3
through
Bank 13
00h
FFh
00h
FFh
00h
FFh
00h
7
From Opcode
11111111
(2)
0
E00h
F00h
FFFh
Note 1:The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to
the registers of the Access Bank.
2:The MOVFF instruction embeds the entire 12-bit address in the instruction.
Bank 14
Bank 15
5.3.2ACCESS BANK
While the use of the BSR with an embedded 8-bit
address allows users to address the entire range of
data memory, it also means th at the user must a lways
ensure that the correct bank is selected. Otherwise,
data may be read from or written to the wrong location.
This can be disastrous if a GPR is the intended target
of an operation, but an SFR is written to instead.
Verifying and/or changing the BSR for each read or
write to data memory can become very inefficient.
T o stre amline acces s for the most commonl y used data
memory locations, the data memory is configured with
an Access Bank, which allows users to access a
mapped block of memory without specifying a BSR.
The Access Bank consists of the first 128 bytes of
memory (00h-7Fh) in Bank 0 and the last 128 bytes of
memory (80h-FFh) in Block 15 . The lower half is known
as the “Access RAM” and is composed of GPRs. The
FFh
00h
FFh
00h
FFh
however, the instruction is forced to use the Access
Bank address map; the current value of the BSR is
ignored entirely.
Using this “forced” addressing allows the instruction to
operate on a data address in a single cycle, without
updating the BSR first. For 8-bit addresses of 80h and
above, this mean s that use rs can ev aluate an d operate
on SFRs more efficiently. The Access RAM below 80h
is a good place for da ta values that the user might need
to access rapidly, such as immediate computational
results or common program variables. Access RAM
also allows for faster and more code efficient context
saving and switching of variab les.
The mapping of the Access Bank is slightly different
when the extended instruction set is enabled (XINST
configuration bit = 1). This is discussed in more detail
in Section 5.6.3 “Mapping the Access Bank inIndexed Literal Offset Mode”.
upper half is where the device’s SFRs are mapped.
These two areas are mapped contiguously in the
Access Bank and can be addressed in a linear fashion
by an 8-bit address (Figure 5-6).
The Access Bank is used by core PIC18 instructions
that inclu de the Acce ss RAM bit ( the ‘a’ parame ter in
the instruction). When ‘a’ is equal to ‘1’, the inst ru ct ion
uses the BSR and the 8-bit address included in the
opcode for the data memory address. When ‘a’ is ‘0’
5.3.3GENERAL PURPOSE
REGISTER FILE
PIC18 devices may have banked memory in the GPR
area. This is dat a RAM, whic h is avai lable for us e by all
instructions. GPRs start at the bottom of Bank 0
(address 000h) and grow upwards towards the bottom
of the SFR area. GPRs are not initialized by a
Power-on Reset and are unchanged on all other
Resets.
DS39637A-page 70Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.3.4SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFRs) are registers
used by the CPU and p eripheral modul es for controllin g
the desired operation of the device. These reg isters are
implemented as static RAM. SFRs start at the top of
data memory (FF Fh) and extend downw ard to oc cupy
the top half of Bank 15 (F80h to FFFh). A list of these
registers is given in Table 5-1 and Table 5-2.
peripheral functions. The reset and interrupt registers
are described in their respective chapters, while the
ALU’s Status register is described later in this section.
Registers related to the operation of a peripheral
feature are described in the c hapter for that perip heral.
The SFRs are typically distributed among the
peripherals whose fun cti ons th ey c ontr ol. U nus ed SFR
locations are unimplemented and read as ‘0’s.
The SFRs can be classified into two sets: those
associated with the “core” device functionality (ALU,
Resets and interrupts) and those related to the
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
DS39637A-page 72Preliminary 2004 Microchip Technology Inc.
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
DS39637A-page 74Preliminary 2004 Microchip Technology Inc.
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
Note 1:RE3 bit only available when MCLRE = 0; otherwise, the bit reads as ‘0’.
2:Bits and registers available only when ENPORTS = 1; otherwise, the registers/bits read as ‘0’.
3:When any TX_ENn bit in RX_TX_SELn is set, then the corresponding bit in this register has transmit properties.
4:This is not a physical register.
DS39637A-page 76Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 5-2:REGISTER FILE SUMMARY (PIC18F2480/2580/4480/4580)
INTCON2RBPU
INTCON3INT2IPINT1IP
INDF0Uses contents of FSR0 to address data memory – value of FSR0 not changed (not a physical register)
POSTINC0Uses contents of FSR0 to address data memory – value of FSR0 post-incremented (not a physical register)
POSTDEC0Uses contents of FSR0 to address data memory – value of FSR0 post-decremented (not a physical register)
PREINC0Uses contents of FSR0 to address data memory – value of FSR0 pre-incremented (not a physical register)
PLUSW0Uses contents of FSR0 to address data memory – value of FSR0 pre-incremented (not a physical register), value
FSR0H
FSR0LIndirect Data Memory Address Pointer 0 Low Bytexxxx xxxx49, 90
WREGWorking Registerxxxx xxxx49
INDF1Uses contents of FSR1 to address data memory – value of FSR1 not changed (not a physical register)
POSTINC1Uses contents of FSR1 to address data memory – value of FSR1 post-incremented (not a physical register)
POSTDEC1Uses contents of FSR1 to address data memory – value of FSR1 post-decremented (not a physical register)
PREINC1Uses contents of FSR1 to address data memory – value of FSR1 pre-incremented (not a physical register)
PLUSW1Uses contents of FSR1 to address data memory – value of FSR1 pre-incremented (not a physical register), value
FSR1H
FSR1LIndirect Data Memory Address Pointer 1 Low Bytexxxx xxxx49, 90
BSR
INDF2Uses contents of FSR2 to address data memory – value of FSR2 not changed (not a physical register)
POSTINC2Uses contents of FSR2 to address data memory – value of FSR2 post-incremented (not a physical register)
POSTDEC2Uses contents of FSR2 to address data memory – value of FSR2 post-decremented (not a physical register)
PREINC2Uses contents of FSR2 to address data memory – value of FSR2 pre-incremented (not a physical register)
PLUSW2Uses contents of FSR2 to address data memory – value of FSR2 pre-incremented (not a physical register), value
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Details
on page:
DS39637A-page 78Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 5-2:REGISTER FILE SUMMARY (PIC18F2480/2580/4480/4580) (CONTINUED)
TRISCData Direction Control Register for PORTC1111 1111 52, 135
TRISBData Direction Control Register for PORTB1111 1111 52, 132
TRISATRISA7
(3)
LATE
LATD
(3)
—————LATE2LATE1LATE0---- -xxx 52, 141
Read PORTD Data Latch, Write PORTD Data Latchxxxx xxxx 52, 138
(6)
TRISA6
(6)
Data Direction Control Register for PORTA1111 1111 52, 129
LATCRead PORTC Data Latch, Write PORTC Data Latchxxxx xxxx 52, 135
LATBRead PORTB Data Latch, Write PORTB Data Latchxxxx xxxx 52, 132
LATALATA7
(6)
LATA6
(6)
Read PORTA Data Latch, Write PORTA Data Latchxxxx xxxx 52, 129
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Details
on page:
DS39637A-page 80Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 5-2:REGISTER FILE SUMMARY (PIC18F2480/2580/4480/4580) (CONTINUED)
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
—TXRTR——DLC3DLC2DLC1DLC0-x-- xxxx 55, 285
—EXIDE —EID17EID16xxxx x-xx 55, 283
—EXIDEN —EID17EID16xxx- x-xx 55, 304
—EXIDEN —EID17EID16xxx- x-xx 55, 304
—EXIDEN —EID17EID16xxx- x-xx 55, 302
—EXIDEN —EID17EID16xxx- x-xx 55, 302
—EXIDEN —EID17EID16xxx- x-xx 55, 302
—EXIDEN —EID17EID16xxx- x-xx 55, 302
—TXPRI1TXPRI00000 0-00 54, 282
—TXPRI1TXPRI00000 0-00 55, 282
Value on
POR, BOR
Details
on page:
DS39637A-page 82Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 5-2:REGISTER FILE SUMMARY (PIC18F2480/2580/4480/4580) (CONTINUED)
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Value on
POR, BOR
Details
on page:
DS39637A-page 84Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
T ABLE 5-2:REGISTER FILE SUMMARY (PIC18F2480/2580/4480/4580) (CONTINUED)
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
Legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 21 of the PC is only available in Test mode and Serial Programming modes.
2: The SBOREN bit is only available when CONFIG2L<1:0> = 01; otherwise it is disabled and reads as ‘0’. See Section 4.4 “Brown-out Reset
(BOR)”.
3: These registers and/or bits are not implemented on PIC18F2X80 devices and are read as ‘0’. Reset values are shown for PIC18F4X80 devices;
individual unimplemented bits should be interpreted as ‘—’.
4: The PLLEN bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ‘0’. See Section 2.6.4 “PLL in INTOSC
Modes”.
5: The RE3 bit is only available when Master Clear Reset is disabled (CONFIG3H<7> = 0); otherwise, RE3 reads as ‘0’. This bit is read-only.
6: RA6/RA7 and their associated latch and direction bits are individually configured as port pins based on various primary oscillator modes. When
disabled, these bits read as ‘0’.
7: CAN bits have multiple functions depending on the selected mode of the CAN module.
8: This register reads all ‘0’s until the ECAN™ technology is set up in Mode 1 or Mode 2.
9: These registers are available on PIC18F4X80 devices only.
The St atus register , s hown in Register5-2, contains the
arithmetic status of the ALU. As with any other SFR, it
can be the operand for any instruction.
If the St atus regis ter is the dest ination for an instructio n
that affect s the Z, DC, C, OV or N bit s, the re sults of the
instruction are not written; instead, the status is
updated according to t he i nstruc tion pe rformed . Therefore, the result of an instru cti on w i th the Status register
as its destinatio n may be dif ferent than intended . As an
example, CLRF STATUS will set the Z bit and leave the
remaining status bits unchanged (‘000u u1uu’).
REGISTER 5-2:STATUS REGISTER
U-0U-0U-0R/W-xR/W-xR/W-xR/W-xR/W-x
———NOVZDCC
bit 7bit 0
bit 7-5Unimplemented: Read as ‘0’
bit 4N: Negative bit
This bit is used for signed arithmetic (2’s complement). It indicates whether the result was
negative (ALU MSB = 1).
1 = Result was negative
0 = Result was positive
bit 3OV: Overflow bit
This bit is used for signed arithmetic (2’s complement). It indicates an overflow of the 7-bit
magnitude which causes the sign bit (bit 7) to change state.
1 = Overflow occurred for signed arithmetic (in this arithmetic operation)
0 = No overflow occurred
bit 2Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1DC: Digit carry/borrow
For ADDWF, ADDLW, SUBLW and SUBWF instructions:
1 = A carry-out from the 4th low-order bit of the result occurred
0 = No carry-out from the 4th low-order bit of the result
Note:For borrow,
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the bit 4 or bit 3 of the source register.
bit 0C: Carry/borrow
For ADDWF, ADDLW, SUBLW and SUBWF instructions:
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note:For borrow,
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low-order bit of the source register.
bit
the polarity is reversed. A subtraction is executed by adding the two’s
bit
the polarity is reversed. A subtraction is executed by adding the two’s
It is recommended that only BCF, BSF, SWAPF, MOVFF
and MOVWF instructions are used to alter the Status
register , b ecaus e thes e ins tructi ons d o not af fect t he Z,
C, DC, OV or N bits in the Status register.
For other instructions that do not affect status bits, see
the instruction set summaries in Table 25-2 and
Table 25-3.
Note:The C and DC bits operate as the borrow
and digit borrow bits respectively in
subtraction.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
DS39637A-page 88Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.4Data Addressing Modes
Note:The execution of s ome inst ructions in the
core PIC18 instruction set are changed
when the PIC18 extended instruction
set is enabled. See Section 5.6 “Data
Memory and the Extended Instruction
Set” for more information.
While the program memory can be addressed in only
one way – through the program counter – information
in the data memory sp ace c an be a ddress ed in severa l
ways. For most instructions, the addressing mode is
fixed. Other instructions may use up to three modes,
depending on whic h operands are used and whe ther or
not the extended instruction set is enabled.
The addressing modes are:
• Inherent
• Literal
•Direct
•Indirect
An additional addressing mode, Indexed Literal Offset,
is available when the extended instruction set is
enabled (XINST configuration bit = 1). Its operation is
discussed in greater detail in Section 5.6.1 “IndexedAddressing with Literal Offset”.
5.4.1INHERENT AND LITERAL
ADDRESSING
Many PIC18 control instructions do not need any
argument at all; they either perform an operation that
globally affects the device or they operate implicitly on
one register. This addressing mode is known as
Inherent Addressing. Exa mp les includ e SLEEP, RESET
and DAW.
Other instructions work in a similar way but require an
additional explicit argument in the opcode. This is
known as Literal Addressing mode because they
require some literal value as an argument. Examples
include ADDLW and MOVLW which, respectively, add or
move a literal value to the W register. Other examples
include CALL and GOTO, which include a 20-bit
program memory address.
5.4.2DIRECT ADDRESSING
Direct addressing specifies all or part of the source
and/or destination address of the operation within the
opcode itself. The options are specified by the
arguments accompanying the instruction.
In the core PIC18 instruction set, bit-oriented and
byte-oriented instructions use some version of direct
addressing by default. All of these instructions include
some 8-bit literal address as their Least Significant
Byte. This address spec ifies either a re gister address in
one of the banks of d ata RAM ( Section 5.3.3 “General
Purpose Register File”) or a location in the Access
Bank (Section 5.3.2 “Access Bank”) as the data
source for the instruction.
The Access RAM bit ‘a’ determines how the address is
interpreted. When ‘a’ is ‘1’, the contents of the BSR
(Section 5.3.1 “Bank Select Register (BSR)”) are
used with the address t o determin e the comple te 12-bit
address of the reg ister. When ‘a’ is ‘0’, the address is
interpreted as being a register in the Access Bank.
Addressing that uses the Access RAM is sometimes
also known as Direct Forced Addressing mode.
A few instructions, such as MOVFF, include the entire
12-bit address (either source or destination) in their
opcodes. In these cases, the BSR is ignored entirely.
The destination of the operati on’s results is determined
by the destination bit ‘d ’. Wh en ‘d’ is ‘1’, the results are
stored back in t he s o ur c e re g is ter, over wr iti n g i ts or i gi nal contents. When ‘d’ is ‘0’, the results are stored in
the W register. Instructions without the ‘d’ argument
have a destin ation tha t is i mplicit in the inst ruction; their
destination is either the target register being operated
on or the W register.
5.4.3INDIRECT ADDRESSING
Indirect addressi ng allows the user to acces s a locatio n
in data memory without giving a fixed address in the
instruction. This is done by using File Select Registers
(FSRs) as pointers to the location s to be read or written
to. Since the FSRs are themselves located in RAM as
Special File Reg isters , they can also be directl y mani pulated under program control. This makes FSRs very
useful in imp lem ent ing data str uct ures , s uch as tabl es
and arrays in data memory.
The registers for indirect addressing are also implemented with Indirect Fi le Operands (INDFs) that perm it
automatic manipulation of the pointer value with
auto-incrementing, auto-decrementing or offsetting
with another va lue . Th is al lo ws f or e fficient code, usin g
loops, such as the example of clearing an entire RAM
bank in Example 5-5.
At the core of indirect addressing are three sets of
registers: FSR0, FSR1 and FSR2. Each represents a
pair of 8-bit registers, FSRnH and FSRnL. The four
upper bits of the FSRnH register are not used, s o each
FSR pair holds a 12-bi t va lue. T his repre sen ts a value
that can address the entire range of the data memory
in a linear fashion. The FSR register pairs, then, serve
as pointers to data memory locations.
Indirect addressing is accomplished with a set of
Indirect File Operands, INDF0 through INDF2. These
can be thought of as “virtual” registers: they are
FIGURE 5-8:INDIRECT ADDRESSING
Using an instruction with one of the
indirect addressing registers as the
operand....
...uses the 12-bit address stored in
the FSR pair associated with that
register....
xxxx1110 11001100
ADDWF, INDF1, 1
mapped in the SFR sp ace, but are not physica lly implemented. Reading or writing to a parti cular INDF register
actually accesses its corresponding FSR register pair.
A read from INDF1, for example, reads the data at the
address indicated by FSR1H:FSR1L. Instructions that
use the INDF registers as operands actually use the
contents of th eir corr espon ding FSR as a poin ter to th e
instruction’s target. The INDF operand is just a convenient way of using the pointer.
Because indirect addres sing uses a full 1 2-bit a ddress ,
data RAM banking is not necessary. Thus, the current
contents of the BSR and the Access RAM bit have no
effect on determining the target address.
FSR1H:FSR1L
07
7
000h
Bank 0
100h
200h
300h
0
Bank 1
Bank 2
Bank 3
through
Bank 13
...to determine the data memory
location to be used in that operation.
In this case, the FSR1 pair contains
ECCh. This means the contents of
location ECCh will be added to that
of the W register and stored back in
ECCh.
E00h
F00h
FFFh
Bank 14
Bank 14
Bank 15
Data Memory
DS39637A-page 90Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
5.4.3.2FSR Regi st er s and PO STIN C,
POSTDEC, PREINC and PLUSW
In addition to the IND F operand, each F SR register p air
also has four additional indirect operands. Like INDF,
these are “virtual” registers that cannot be indirectly
read or written to. Accessing these registers actually
accesses the associated FSR register pair, but also
performs a specif ic action on i ts stored v alue. They a re:
• POSTDEC: accesses the FSR value, then
automatically decrements it by 1 afterwards
• POSTINC: accesses the FSR value, then
automatically increments it by 1 afterwards
• PREINC: increments the FSR value by 1, then
uses it in the operation
• PLUSW: adds the signed value of the W register
(range of -127 to 128) to that of the FSR and uses
the new value in the operation.
In this context, accessing an INDF register uses the
value in the FSR registers without changing them.
Similarly, accessing a PLUSW register gives the FSR
value offset by that in the W register; neither value is
actually changed in the operation. Accessing the other
virtual registers changes the value of the FSR registers.
Operations on the FSRs with POSTDEC, POSTINC
and PREINC affect the entire register pair; that is, rollovers of the FSRnL register from FFh to 00h carry over
to the FSRnH register. On the other hand, results of
these operations do not change the value of any flags
in the Status register (e.g., Z, N, OV, etc.).
The PLUSW register can be used to implement a form
of indexed addressing in t he data memory space. By
manipulating the value in the W register, users can
reach addresses that are fixed offsets from pointer
addresses. In some applications, this can be used to
implement some powerful program control structure,
such as softw are stacks, insi de of data memory.
5.4.3.3Operations by FSRs on FSRs
Indirect addressing operations that target other FSRs
or virtual registers represent special cases. For example, using an FSR to point to one of the virtual regis ters
will not result in successful operations. As a specific
case, assume that FSR0H:FSR0L contains FE7h, the
address of INDF1. Attempts to read the value of the
INDF1 using INDF0 as an operand will return 00h.
Attempts to write to INDF1 using I NDF0 as the operan d
will result in a NOP.
On the other hand, using the virtua l registers to write to
an FSR pair may not occu r as plan ned. I n th ese cas es,
the value will be written to the FSR p air bu t without an y
incrementing or decrementing. Thus, writing to INDF2
or POSTDEC2 will write the same value to the
FSR2H:FSR2L.
Since the FSRs are physical registers mapped in the
SFR space, they can be manipulated through all direct
operations. Users should proceed cautiously when
working on these registers, particularly if their code
uses indirect addressing.
Similarly, operations by indirect addressing are generally permitted on all other SFRs. U sers sho uld exerc ise
the appropriate caution that they do not inadvertently
change settings that might affect the operation of the
device.
5.5Program Memory and the
Extended Instruction Set
The operation of progra m mem ory is un affected by the
use of the extended instruction set.
Enabling the extended instruction set adds eight
additional two-word commands to the existing
PIC18 instruction set: ADDFSR, ADDULNK, CALLW,
MOVSF, MOVSS, PUSHL, SUBFSR and SUBULNK. These
instructions are executed as described in
Section 5.2.4 “Two-Word Instructions”.
5.6Data Memory and the Extended
Instruction Set
Enabling the PIC18 extended instruction set (XINST
configuration bit = 1) significantly changes certain
aspects of data memory and its addressing. Specifically, the use of the Access Bank for many of the core
PIC18 instructions is different; this is due to the introduction of a n ew add ressing mo de fo r the dat a me mory
space. This mode also alters the behavior of indirect
addressing using FSR2 and its associated operands.
What does not change is just as im po rtant. The size of
the data memory space is unchanged, as well as its
linear addressing. The SFR map remains the same.
Core PIC18 instructions can still operate in both Direct
and Indirect Addressing mode; inherent and literal
instructions do not change at all. Indirect addressing
with FSR0 and FSR1 also remains unchanged.
5.6.1INDEXED ADDRESSING WITH
LITERAL OFFSET
Enabling the PIC18 extended instruction set changes
the behavior of indirect addressing using the FSR2
register pair a nd its a ssociated fil e operands. Under the
proper conditions, instructions that use the Access
Bank – that is, most bit-oriented and byte-oriented –
instructions – ca n in voke a form of indexed add r es sin g
using an offse t sp ecified in the instructio n. Thi s special
addressing mode is known as Inde xed A ddressing w ith
Literal Offset or Indexed Literal Offset mode.
When using the extended instruction set, this
addressing mode requires the following:
• The use of the Access Bank is forced (‘a’ = 0);
and
• The file address argument is less th an or e qua l to
5Fh.
Under these conditions, the file address of the instruction is not interpreted as the lower byte of an address
(used with the BSR in direct addre ssing), or as an 8-bit
address in the Access Bank. Instead, the value is
interpreted as an offset value to an address pointer,
specified by FSR2. The offset and the contents of
FSR2 are added to obtain the target address of the
operation.
5.6.2INSTRUCTIONS AFFECTED BY
INDEXED LITERAL OFFSET MODE
Any of the core PIC18 instructions that can use direct
addressing are potentially affected by the Indexed
Literal Offset Addressing mode. This includes all
byte-oriented and bit-oriented instructions, or almost
one-half of the standard PIC18 instruction set. Instructions that only use Inherent or Literal Addressing
modes are unaffecte d.
Additionally, byte-oriented and bit-oriented instructions
are not affected if they use the Access Bank (Access
RAM bit is ‘1’), or include a fi le address of 60h o r above.
Instructions meeting these criteria will continue to
execute as before. A comp aris on of the dif fere nt possible addressing modes when the extended instruction
set is enabled in shown in Figure 5-9.
Those who desire to use byte-oriented or bit-oriented
instructions in the Indexed Literal Offset mode should
note the changes to assembler syntax for this mode.
This is described in more detail in Section 25.2.1“Extended Instruction Syntax”.
DS39637A-page 92Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
FIGURE 5-9:COMPARING ADDRESSING OPTIONS FOR BIT-ORIENTED AND
BYTE-ORIENTED INSTRUCTIONS (EXTENDED INSTRUCTION SET ENABLED)
EXAMPLE INSTRUCTION: ADDWF, f, d, a (Opcode: 0010 01da ffff ffff)
When a = 0 and f ≥ 60h:
The instruction executes in
Direct Forced mode. ‘f’ is interpreted as a location in the
Access RAM between 060h
and 0FFh. This is the same as
the SFRs, or locations F60h to
0FFh (Bank 15) of data
memory.
Locations below 60h are not
available in this addressing
mode.
When a = 0 and f ≤ 5Fh:
The instruction executes in
Indexed Literal Offset mode. ‘f’
is interpreted as an offset to the
address value in FSR2. The
two are added together to
obtain the address of the target
register for the instruction. The
address can be anywhere in
the data memory space.
Note that in this mode, the
correct syntax is now:
ADDWF [k], d
where ‘k’ is the same as ‘f’.
000h
060h
080h
100h
F00h
F60h
FFFh
000h
080h
100h
F00h
F60h
FFFh
Bank 0
Bank 1
through
Bank 14
Bank 15
SFRs
Data Memory
Bank 0
Bank 1
through
Bank 14
Bank 15
SFRs
Data Memory
00h
60h
Access RAM
FSR2HFSR2L
FFh
ffffffff001001da
Valid range
for ‘f’
BSR
00000000
ffffffff001001da
When a = 1 (all values of f):
The instruction executes in
Direct mode (also known as
Direct Long mode). ‘f’ is
interpreted as a location in
one of the 16 banks of the data
memory space. The bank is
designated by the Bank Sel ect
000h
080h
100h
Bank 0
Bank 1
through
Bank 14
Register (BSR). The address
can be in any implemented
bank in the data memory
space.
5.6.3MAPPING THE ACCESS BANK IN
INDEXED LITERAL OFFSET MODE
The use of Indexed Literal Offset Addressing mode
effectively changes how the lower half of Access RAM
(00h to 7Fh) is mapped. R ather th an cont aining just th e
contents of the bottom half of Bank 0, this mode maps
the contents from Bank 0 and a user defined “window”
that can be located anywhere in the data memory
space. The value o f FSR2 establish es the lower boundary of the addresses ma pped into the window , while the
upper boundary is defined by FSR2 plus 95 (5Fh).
Addresses in the Access RA M abo ve 5Fh are mapped
as previou sly described (see Section 5.3.2 “AccessBank”). An example of Access Bank remapping in this
addressing mode is shown in Figure 5-10.
Remapping of the Access Bank applies only to operations using the I ndexed Lite ral Offs et mode. Ope rations
that use the BSR (Access RAM bit is ‘1’) will continue
to use direct addressing as before. Any indirect or
indexed operation tha t explicitly uses an y of the indirect
file operands (including FSR2) will continue to operate
as standard indirect addressing. Any instruction that
uses the Access Bank, but includes a register address
of greater than 05Fh, w ill use di rect address ing and th e
normal Access Bank map.
5.6.4BSR IN INDEXED LITERAL OFFSET
MODE
Although the Access Bank is remapped when the
extended instruct ion set is enable d, the operation o f the
BSR remains unchanged. Direct addressing using the
BSR to select the data memory bank operates in the
same manner as previously described.
FIGURE 5-10:REMAPPING THE ACCESS BANK WITH INDEXED LITERAL
OFFSET ADDRESSING
Example Situation:
ADDWF f, d, a
FSR2H:FSR2L = 120h
Locations in the region
from the FSR2 pointer
(120h) to the pointer plus
05Fh (17Fh) are mapped
to the bottom of the
Access RAM (000h-05Fh).
Special File Registers at
F60h through FFFh are
mapped to 60h through
FFh, as usual.
Bank 0 addresses below
5Fh are not available in
this mode. They can still
be addressed by using the
BSR.
000h
100h
120h
17Fh
200h
F00h
F60h
FFFh
Bank 0
Window
Bank 1
Bank 2
through
Bank 14
Bank 15
SFRs
Data Memory
00h
Bank 1 “Window”
5Fh
60h
SFRs
FFh
Access Bank
DS39637A-page 94Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
6.0FLASH PROGRAM MEMORY
The Flash program memory is readable, writable and
erasable, during normal operation over the entire V
range.
A read from program memory is executed on one byte
at a time. A write to program memory is executed on
blocks of 8 byt es at a time. Program memory is er ase d
in blocks of 32 bytes at a time. A bulk erase operation
may not be issued from user code.
Writing or erasing program memory will cease
instruction fetches until the operation is complete. The
program memory cannot be accessed during the write
or erase, therefore, code cannot execute. An internal
programming timer terminates program memory writes
and erases.
DD
6.1Table Reads and Table Writes
In order to read and write program memory, there are
two operations that allow the processor to move bytes
between the program memory sp ace and the dat a RAM:
• Table Read (TBLRD)
• Table Write (TBLWT)
The program memory space is 16 bits wide, while the
data RAM space is 8 bits wide. Table reads and table
writes move data between these two memory spaces
through an 8-bit register (TABLAT).
Table read operations retrieve data from program
memory and place it into the data RAM space.
Figure 6-1 shows the operation of a table read with
program memory and data RAM.
Table write oper at ions s tore d ata fr om t he data me mor y
space into holding registers in program memory. The
procedure to write the contents of the holding registers
into program memory is detailed in Section 6.5 “Writingto Flash Program Memory”. Figure6-2 shows the
operation of a table write with program memory and data
RAM.
Table operations work with byte entities. A table block
containing data, rather than program instructions, is not
required to be word aligned. Therefore, a table block can
start and end at any byte address. If a t able write is being
used to write executable code into program memory,
program instructions will need to be word aligned.
FIGURE 6-1:TABLE READ OPERATION
Table Pointer
TBLPTRU
Note 1: Table Pointer register points to a byte in program memory.
Note 1: Table pointer actually points to one of 64 holding registers, the address of which is determined by
TBLPTRHTBLPTRL
TBLPTRL<5:0>. The process for physically writing data to the program memory array is discussed in
Section 6.5 “Writing to Flash Program Memory”.
(1)
Program Memory
(TBLPTR)
Holding Registers
Table Latch (8-bit)
TABLAT
6.2Control Registers
Several control registers are used in conjunction with
the TBLRD and TBLWT instructions. These include the:
• EECON1 register
• EECON2 register
• TABLAT register
• TBLPTR registers
6.2.1EECON1 AND EECON2 REGISTERS
The EECON1 register (Register 6-1) is the control
register for memory acce sses. The EECO N2 register is
not a physical register; it is used exclusively in the
memory write and erase sequences. Reading
EECON2 will read all ‘0’s.
The EEPGD control bit determines if th e access will be
a program or data EEPROM memory access. When
clear, any subsequent operations will operate on the
data EEPROM memory. When set, any subsequent
operations will operate on the program memory.
The CFGS control bit determines if the access will be
to the configuration/calibration registers or to program
memory/data EEPROM memory. When set,
subsequent operations will operate on configuration
registers regardless of EEPGD (see Section 24.0“Special Features o f the CPU”). Wh en clear , memory
selection access is determined by EEPGD.
The FREE bit, when set, will allow a program memory
erase operation. When FREE is set, the erase operation is initiated on the n ext WR com mand. Wh en FR EE
is clear, only writes are enabled.
The WREN bit, when set, will allow a write operation.
On power-up, the WREN bit is c lear . T he WRERR bit is
set in hardware when the WREN bit is set and cleared
when the internal programming timer expires and the
write operation is complete.
Note:During normal operation, the WRERR is
read as ‘1’. This can indicate that a write
operation was prematurely terminated by
a Reset, or a write operation was
attempted improperly.
The WR control bit initiates write operations. The bit
cannot be cleared, only set, in software; it is cleared in
hardware at the completion of the write operation.
Note:The EEIF Int errupt flag bit (PIR2<4 >) is set
when the write is complete. It must be
cleared in software.
DS39637A-page 96Preliminary 2004 Microchip Technology Inc.
PIC18F2480/2580/4480/4580
REGISTER 6-1:EECON1: DATA EEPROM CONTROL REGISTER 1
R/W-xR/W-xU-0R/W-0R/W-xR/W-0R/S-0R/S-0
EEPGDCFGS—FREEWRERRWRENWRRD
bit 7bit 0
bit 7EEPGD: Flash Program or Data EEPROM Memory Select bit
1 = Access Flash program memory
0 = Access data EEPROM memory
bit 6CFGS: Flash Program/Data EEPROM or Configuration Select bit
1 = Access configuration registers
0 = Access Flash program or data EEPROM memory
bit 5Unimplemented: Read as ‘0’
bit 4FREE: Flash Row Erase Enable bit
1 = Erase the program memory row addresse d by TBLPTR on the next WR command (cl eared
by completion of erase operation)
0 = Perform write only
bit 3WRERR: Flash Program/Data EEPROM Error Flag bit
1 = A write operation is prematurely terminated (any Reset during self-timed programming in
normal operation or an improper write attempt)
0 = The write operation completed
Note:When a WRERR occurs, the EEPGD and CFGS bits are not cleared.
This allows tracing of the error condition.
bit 2WREN: Flash Program/Data EEPROM Write Enable bit
1 = Allows write cycles to Flash program/data EEPROM
0 = Inhibits write cycles to Flash program/data EEPROM
bit 1WR: Write Control bit
1 = Initiates a data EEPROM erase/write cycle or a program memory erase cycle or write cycle
(The operation is self-timed and the bit is cleared by hardware once write is complete.
The WR bit can only be set (not cleared) in software.)
0 = Write cycle to the EEPROM is complete
bit 0RD: Read Control bit
1 = Initiates an EEPROM read (Read takes one cycle. RD is cleared in hardware. The RD bit can
only be set (not cleared) in software. RD bit cannot be set when EEPGD = 1 or CFGS = 1.)
0 = Does not initiate an EEPROM read
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
The Table Latch (TABLAT) is an 8-bit register mapped
into the SFR space. The Table Latch register is used to
hold 8-bit data during data transfers between program
memory and data RAM.
6.2.3TBLPTR – TABLE POINTER
REGISTER
The Table Pointer (TBLPTR) register addresses a by te
within the program memory. The TBLPTR is comprised
of three SFR registers : Table Pointer Upper Byte, Table
Pointer High Byte and Table Pointer Low Byte
(TBLPTRU:TBLPTRH:TBLPTRL). These three registers join to form a 22-bit wide po inter. The low -order
21 bits allow the device to address up to 2 Mbytes of
program memory sp ace. Th e 22nd b it allow s acce ss to
the device ID, the user ID and the configuration bits.
The Table Pointer, TBLP TR, is use d by the TBLRD an d
TBLWT instructions. These instructions can update the
TBLPTR in one of four ways based on the table operation. These operations are shown in Table 6-1. These
operations on the TBLPTR only affect the low-order
21 bits.
6.2.4 TABLE POINTER BOUNDARIES
TBLPTR is used in reads, writes and erases of the
Flash program memory.
When a TBLRD is executed, all 22 bits of the TBLPTR
determine which byte is read from program memory
into TABL AT.
When a TBLWT is executed, the six LSbs of the Table
Pointer register (TBLP TR<5:0>) determine which of the
64 program memory holding registers is written to.
When the timed write to program memory begins (via
the WR bit), the 16 MSbs of the TBLPTR
(TBLPTR<21:6>) determine which program memory
block of 32 bytes is written to. For more detail, see
Section 6.5 “Writing to Flash Program Memory”.
When an erase of program memory is executed, the
16 MSbs of the Table Pointer register (TBLPTR<21:6>)
point to the 64-byte block that will be erased . The Least
Significant bits (TBLPTR<5:0>) are ignored.
Figure 6-3 describes the relevant boundaries of
TBLPTR based on Flash program memory operations.
TABLE 6-1:TABLE POINTER OPERATIONS WITH TBLRD AND TBLWT INSTRUCTIONS
ExampleOperation on Table Pointer
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*-
TBLRD+*
TBLWT+*
TBLPTR is incremented after the read/write
TBLPTR is decremented after the read/write
TBLPTR is incremented before the read /write
TBLPTR is not modified
FIGURE 6-3:TABLE POINTER BOUNDARIES BASED ON OPERATION
2116 15870
DS39637A-page 98Preliminary 2004 Microchip Technology Inc.
TBLPTRU
TABLE ERASE/WRITE
TABLE READ – TBLPTR<21:0>
TBLPTRLTBLPTRH
TABLE WRITE
TBLPTR<2:0>TBLPTR<21:3>
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.