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 Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, KEELOQ logo, MPLAB, PIC, PICmicro,
PICSTART, PRO MATE, rfPIC and SmartShunt are registered
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB,
SEEVAL, SmartSensor and The Embedded Control Solutions
Company are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
logo, PowerCal, PowerInfo,
PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total
Endurance, UNI/O, WiperLock and ZENA 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 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC
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.
6.0Flash Program Memory.............................................................................................................................................................. 97
7.0External Memory Bus ............................................................................................................................................................... 107
8.08 x 8 Hardware Multiplier.......................................................................................................................................................... 119
19.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 257
23.0 Comparator Voltage Reference Module ................................................................................................................................... 343
24.0 Special Features of the CPU.................................................................................................................................................... 347
25.0 Instruction Set Summary.......................................................................................................................................................... 361
26.0 Development Support............................................................................................................................................................... 411
Index .................................................................................................................................................................................................. 463
The Microchip Web Site..................................................................................................................................................................... 475
Customer Change Notification Service .............................................................................................................................................. 475
Customer Support .............................................................................................................................................................................. 475
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 comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@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)
When contacting a sales office, 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 to receive the most current information on all of our products.
This document contains device-specific information for
the following devices:
• PIC18F66J60• PIC18F87J60
• PIC18F66J65• PIC18F96J60
• PIC18F67J60• PIC18F96J65
• PIC18F86J60• PIC18F97J60
• PIC18F86J65
This family introduces a new line of low-voltage devices
with the foremost traditional advantage of all PIC18
microcontrollers – namely, high computational performance and a rich feature set at an extremely
competitive price point. These features make the
PIC18F97J60 family a logical choice for many
high-performance applications where cost is a primary
consideration.
1.1Core Features
1.1.1OSCILLATOR OPTIONS AND
FEATURES
All of the devices in the PIC18F97J60 family offer five
different oscillator options, allowing users a range of
choices in developing application hardware. These
options include:
• Two Crystal modes, using crystals or ceramic
resonators.
• Two External Clock modes, offering the option of
a divide-by-4 clock output.
• A Phase Lock Loop (PLL) frequency multiplier,
available to the external oscillator modes, which
allows clock speeds of up to 41.667 MHz.
• An internal RC oscillator with a fixed 31 kHz
output which provides an extremely low-power
option for timing-insensitive applications.
The internal oscillator block provides a stable reference
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 provided by the internal oscillator. If a clock
failure occurs, the controller is switched to the
internal oscillator, allowing for continued 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.
1.1.2EXPANDED MEMORY
The PIC18F97J60 family provides ample room for
application code, from 64 Kbytes to 128 Kbytes of code
space. The Flash cells for program memory are rated
to last 100 erase/write cycles. Data retention without
refresh is conservatively estimated to be greater than
20 years.
The PIC18F97J60 family also provides plenty of room
for dynamic application data with 3808 bytes of data
RAM.
1.1.3EXTERNAL MEMORY BUS
In the unlikely event that 128 Kbytes of memory are
inadequate for an application, the 100-pin members of
the PIC18F97J60 family also implement an External
Memory Bus (EMB). This allows the controller’s internal program counter to address a memory space of up
to 2 Mbytes, permitting a level of data access that few
8-bit devices can claim. This allows additional memory
options, including:
• Using combinations of on-chip and external
memory up to the 2-Mbyte limit
• Using external Flash memory for reprogrammable
application code or large data tables
• Using external RAM devices for storing large
amounts of variable data
1.1.4EXTENDED INSTRUCTION SET
The PIC18F97J60 family implements the optional
extension to the PIC18 instruction set, adding eight
new instructions and an Indexed Addressing mode.
Enabled as a device configuration option, the extension
has been specifically designed to optimize reentrant
application code originally developed in high-level
languages, such as C.
1.1.5EASY MIGRATION
Regardless of the memory size, all devices share the
same rich set of peripherals, allowing for a smooth
migration path as applications grow and evolve.
• Communications: The PIC18F97J60 family
incorporates a range of serial communication
peripherals, including up to two independent
Enhanced USARTs and up to two Master SSP
modules, capable of both SPI and I
and Slave) modes of operation. In addition, one of
the general purpose I/O ports can be reconfigured
as an 8-bit Parallel Slave Port for direct
processor-to-processor communications.
• CCP Modules: All devices in the family incorporate
two Capture/Compare/PWM (CCP) modules and
three Enhanced CCP (ECCP) modules to maximize
flexibility in control applications. Up to four different
time bases may be used to perform several
different operations at once. Each of the three
ECCP modules offers up to four PWM outputs,
allowing for a total of twelve PWMs. The ECCP
modules also offer many beneficial features,
including polarity selection, programmable dead
time, auto-shutdown and restart and Half-Bridge
and Full-Bridge Output modes.
• 10-Bit A/D Converter: This module incorporates
programmable acquisition time, allowing for a
channel to be selected and a conversion to be
initiated without waiting for a sampling period and
thus, reducing code overhead.
• Extended Watchdog Timer (WDT): This
enhanced version incorporates a 16-bit prescaler,
allowing an extended time-out range. See
Section 27.0 “Electrical Characteristics” for
time-out periods.
2
C™ (Master
1.3Details on Individual Family
Members
Devices in the PIC18F97J60 family are available in
64-pin, 80-pin and 100-pin packages. Block diagrams
for the three groups are shown in Figure 1-1,
Figure 1-2 and Figure 1-3.
The devices are differentiated from each other in four
ways:
1.Flash program memory (three sizes, ranging
from 64 Kbytes for PIC18FX6J60 devices to
128 Kbytes for PIC18FX7J60 devices).
2.A/D channels (eleven for 64-pin devices, fifteen
for 80-pin pin devices and sixteen for 100-pin
devices).
3.Serial communication modules (one EUSART
module and one MSSP module on 64-pin
devices, two EUSART modules and one MSSP
module on 80-pin devices and two EUSART
modules and two MSSP modules on 100-pin
devices).
4.I/O pins (39 on 64-pin devices, 55 on 80-pin
devices and 70 on 100-pin devices).
All other features for devices in this family are identical.
These are summarized in Table 1-1, Table 1-2 and
Table 1-3.
The pinouts for all devices are listed in Table 1-4,
Table 1-5 and Table 1-6.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
7ISTMaster Clear (Reset) input. This pin is an active-low Reset
to the device.
39
40
24
23
22
21
28
27
O
O
I/O
O
I/O
O
I/O
I/O
I/O
I/O
I
I
CMOS
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
I
Analog
Oscillator crystal or external clock input.
ST
—
—
TTL
—
TTL
—
TTL
TTL
ST
ST
TTL
Oscillator crystal input or external clock source input.
ST buffer when configured in internal RC mode; CMOS
otherwise.
External clock source input. Always associated
with pin function OSC1. (See related OSC2/CLKO pin.)
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator mode.
In Internal RC mode, OSC2 pin outputs CLKO which has
1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
PORTA is a bidirectional I/O port.
Digital I/O.
Ethernet LEDA indicator output.
Analog input 0.
Digital I/O.
Ethernet LEDB indicator output.
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.
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
REF-
RA2
AN2
REF-
V
REF+
RA3
AN3
REF+
V
RA4
T0CKI
RA5
AN4
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
9ISTMaster Clear (Reset) input. This pin is an active-low Reset to
the device.
49
50
30
29
28
27
34
33
O
O
I/O
O
I/O
O
I/O
I/O
I/O
I/O
I
I
CMOS
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
I
Analog
Oscillator crystal or external clock input.
ST
—
—
TTL
—
TTL
—
TTL
TTL
ST
ST
TTL
Oscillator crystal input or external clock source input.
ST buffer when configured in internal RC mode; CMOS
otherwise.
External clock source input. Always associated with
pin function OSC1. (See related OSC2/CLKO pin.)
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or
resonator in Crystal Oscillator mode.
In Internal RC mode, OSC2 pin outputs CLKO which has
1/4 the frequency of OSC1 and denotes the
instruction cycle rate.
PORTA is a bidirectional I/O port.
Digital I/O.
Ethernet LEDA indicator output.
Analog input 0.
Digital I/O.
Ethernet LEDB indicator output.
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.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
5
6
7
8
54
53
52
47
Pin
Typ e
I/O
I
I
I/O
I
I/O
I
I/O
I
I/O
I
I/O
I
I/O
I
I/O
I/O
I
I/O
Buffer
Type
TTL
ST
ST
TTL
ST
TTL
ST
TTL
ST
TTL
TTL
TTL
TTL
TTL
TTL
ST
TTL
TTL
ST
Description
PORTB is a bidirectional I/O port. PORTB can be software
programmed for internal weak pull-ups on all inputs.
Digital I/O.
External interrupt 0.
Enhanced PWM Fault input (ECCP modules); enabled
in software.
Digital I/O.
External interrupt 1.
Digital I/O.
External interrupt 2.
Digital I/O.
External interrupt 3.
Digital I/O.
Interrupt-on-change pin.
Digital I/O.
Interrupt-on-change pin.
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP™ programming clock pin.
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP programming data pin.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
36
35
43
44
45
46
37
38
Pin
Typ e
I/O
O
I
I/O
I
I/O
O
I/O
I/O
O
I/O
I/O
I/O
I/O
I
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
Buffer
Type
ST
—
ST
ST
CMOS
ST
—
ST
ST
—
ST
ST
ST
ST
ST
ST
ST
—
ST
—
ST
ST
ST
ST
Description
PORTC is a bidirectional I/O port.
Digital I/O.
Timer1 oscillator output.
Timer1/Timer3 external clock input.
Digital I/O.
Timer1 oscillator input.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM output A.
Digital I/O.
Capture 1 input/Compare 1 output/PWM1 output.
ECCP1 PWM output A.
Digital I/O.
Synchronous serial clock input/output for SPI mode.
Synchronous serial clock input/output for I
Digital I/O.
SPI data in.
I2C data I/O.
Digital I/O.
SPI data out.
Digital I/O.
EUSART1 asynchronous transmit.
EUSART1 synchronous clock (see related RX1/DT1 pin).
Digital I/O.
EUSART1 asynchronous receive.
EUSART1 synchronous data (see related TX1/CK1 pin).
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
4
3
78
77
76
75
74
73
Pin
Typ e
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
I/O
O
Buffer
Type
ST
—
ST
—
ST
—
ST
—
ST
—
ST
—
ST
—
ST
ST
—
Description
PORTD is a bidirectional I/O port.
PORTE is a bidirectional I/O port.
Digital I/O.
ECCP2 PWM output D.
Digital I/O.
ECCP2 PWM output C.
Digital I/O.
ECCP2 PWM output B.
Digital I/O.
ECCP3 PWM output C.
Digital I/O.
ECCP3 PWM output B.
Digital I/O.
ECCP1 PWM output C.
Digital I/O.
ECCP1 PWM output B.
Digital I/O.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM output A.
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
REF
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to VDD)
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
23
18
17
16
15
14
13
Pin
Typ e
I/O
I
O
I/O
I
O
I/O
I
I/O
I
I/O
I
O
I/O
I
I/O
I
Buffer
Type
ST
Analog
—
ST
Analog
—
ST
Analog
ST
Analog
ST
Analog
—
ST
Analog
ST
TTL
Description
PORTF is a bidirectional I/O port.
Digital I/O.
Analog input 6.
Comparator 2 output.
Digital I/O.
Analog input 7.
Comparator 1 output.
Digital I/O.
Analog input 8.
Digital I/O.
Analog input 9.
Digital I/O.
Analog input 10.
Comparator reference voltage output.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
56
55
42
41
10
Pin
Typ e
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
I/O
I/O
O
I/O
I/O
O
Buffer
Type
ST
ST
—
ST
—
ST
ST
ST
ST
ST
ST
—
ST
ST
—
Description
PORTG is a bidirectional I/O port.
Digital I/O.
Capture 3 input/Compare 3 output/PWM3 output.
ECCP3 PWM output A.
Digital I/O.
EUSART2 asynchronous transmit.
EUSART2 synchronous clock (see related RX2/DT2 pin).
Digital I/O.
EUSART2 asynchronous receive.
EUSART2 synchronous data (see related TX2/CK2 pin).
Digital I/O.
Capture 4 input/Compare 4 output/PWM4 output.
ECCP3 PWM output D.
Digital I/O.
Capture 5 input/Compare 5 output/PWM5 output.
ECCP1 PWM output D.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to VDD)
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Default assignment for ECCP2/P2A when CCP2MX Configuration bit is set.
2:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
3:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared.
4:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin
Typ e
P
P
Buffer
Type
—
—
Description
PORTJ is a bidirectional I/O port.
Core logic power or external filter capacitor connection.
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
REF-
RA2
AN2
REF-
V
REF+
RA3
AN3
REF+
V
RA4
T0CKI
RA5
AN4
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
13ISTMaster Clear (Reset) input. This pin is an active-low Reset to
the device.
63
64
35
34
33
32
42
41
O
O
I/O
O
I/O
O
I/O
I/O
I/O
I/O
I
I
CMOS
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
Analog
I
I
Analog
Oscillator crystal or external clock input.
ST
—
—
TTL
—
TTL
—
TTL
TTL
ST
ST
TTL
Oscillator crystal input or external clock source input.
ST buffer when configured in internal RC mode; CMOS
otherwise.
External clock source input. Always associated with
pin function OSC1. (See related OSC2/CLKO pin.)
Oscillator crystal or clock output.
Oscillator crystal output. Connects to crystal or resonator
in Crystal Oscillator mode.
In Internal RC mode, OSC2 pin outputs CLKO which has 1/4
the frequency of OSC1 and denotes the instruction cycle rate.
PORTA is a bidirectional I/O port.
Digital I/O.
Ethernet LEDA indicator output.
Analog input 0.
Digital I/O.
Ethernet LEDB indicator output.
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.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
5
6
7
8
69
68
67
57
Pin
Typ e
I/O
I
I
I/O
I
I/O
I
I/O
I
I/O
O
I/O
I
I/O
I
I/O
I
I/O
I/O
I
I/O
Buffer
Type
TTL
ST
ST
TTL
ST
TTL
ST
TTL
ST
ST
—
TTL
TTL
TTL
TTL
TTL
TTL
ST
TTL
TTL
ST
Description
PORTB is a bidirectional I/O port. PORTB can be software
programmed for internal weak pull-ups on all inputs.
Digital I/O.
External interrupt 0.
Enhanced PWM Fault input (ECCP modules); enabled
in software.
Digital I/O.
External interrupt 1.
Digital I/O.
External interrupt 2.
Digital I/O.
External interrupt 3.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM output A.
Digital I/O.
Interrupt-on-change pin.
Digital I/O.
Interrupt-on-change pin.
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP™ programming clock pin.
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and ICSP programming data pin.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
44
43
53
54
55
56
45
46
Pin
Typ e
I/O
O
I
I/O
I
I/O
O
I/O
I/O
O
I/O
I/O
I/O
I/O
I
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
Buffer
Type
ST
—
ST
ST
CMOS
ST
—
ST
ST
—
ST
ST
ST
ST
ST
ST
ST
—
ST
—
ST
ST
ST
ST
Description
PORTC is a bidirectional I/O port.
Digital I/O.
Timer1 oscillator output.
Timer1/Timer3 external clock input.
Digital I/O.
Timer1 oscillator input.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM output A.
Digital I/O.
Capture 1 input/Compare 1 output/PWM1 output.
ECCP1 PWM output A.
Digital I/O.
Synchronous serial clock input/output for SPI mode.
Synchronous serial clock input/output for I
Digital I/O.
SPI data in.
I2C data I/O.
Digital I/O.
SPI data out.
Digital I/O.
EUSART1 asynchronous transmit.
EUSART1 synchronous clock (see related RX1/DT1 pin).
Digital I/O.
EUSART1 asynchronous receive.
EUSART1 synchronous data (see related TX1/CK1 pin).
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
92
91
90
89
88
87
84
83
Pin
Typ e
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
O
I/O
I/O
I/O
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
Buffer
Type
ST
TTL
TTL
ST
TTL
TTL
ST
TTL
TTL
ST
TTL
TTL
ST
TTL
TTL
—
ST
TTL
TTL
ST
ST
ST
TTL
TTL
ST
ST
ST
TTL
TTL
TTL
Description
PORTD is a bidirectional I/O port.
Digital I/O.
External memory address/data 0.
Parallel Slave Port data.
Digital I/O.
External memory address/data 1.
Parallel Slave Port data.
Digital I/O.
External memory address/data 2.
Parallel Slave Port data.
Digital I/O.
External memory address/data 3.
Parallel Slave Port data.
Digital I/O.
External memory address/data 4.
Parallel Slave Port data.
SPI data out.
Digital I/O.
External memory address/data 5.
Parallel Slave Port data.
SPI data in.
2
C™ data I/O.
I
Digital I/O.
External memory address/data 6.
Parallel Slave Port data.
Synchronous serial clock input/output for SPI mode.
Synchronous serial clock input/output for I
Digital I/O.
External memory address/data 7.
Parallel Slave Port data.
SPI slave select input.
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
/P2C
/P2B
(3)
(3)
(3)
(3)
(4)
(4)
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
4
3
98
97
96
95
94
93
Pin
Typ e
I/O
I/O
I
O
I/O
I/O
I
O
I/O
I/O
I
O
I/O
I/O
O
I/O
I/O
O
I/O
I/O
O
I/O
I/O
O
I/O
I/O
I/O
O
Buffer
Type
ST
TTL
TTL
—
ST
TTL
TTL
—
ST
TTL
TTL
—
ST
TTL
—
ST
TTL
—
ST
TTL
—
ST
TTL
—
ST
TTL
ST
—
Description
PORTE is a bidirectional I/O port.
Digital I/O.
External memory address/data 8.
Read control for Parallel Slave Port.
ECCP2 PWM output D.
Digital I/O.
External memory address/data 9.
Write control for Parallel Slave Port.
ECCP2 PWM output C.
Digital I/O.
External memory address/data 10.
Chip select control for Parallel Slave Port.
ECCP2 PWM output B.
Digital I/O.
External memory address/data 11.
ECCP3 PWM output C.
Digital I/O.
External memory address/data 12.
ECCP3 PWM output B.
Digital I/O.
External memory address/data 13.
ECCP1 PWM output C.
Digital I/O.
External memory address/data 14.
ECCP1 PWM output B.
Digital I/O.
External memory address/data 15.
Capture 2 input/Compare 2 output/PWM2 output.
ECCP2 PWM output A.
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
REF
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
12
28
23
22
21
20
19
18
Pin
Typ e
I/O
ISTAnalog
I/O
I
Analog
O
I/O
I
Analog
O
I/O
ISTAnalog
I/O
ISTAnalog
I/O
I
Analog
O
I/O
ISTAnalog
I/O
I
Buffer
Type
ST
—
ST
—
ST
—
ST
TTL
Description
PORTF is a bidirectional I/O port.
Digital I/O.
Analog input 5.
Digital I/O.
Analog input 6.
Comparator 2 output.
Digital I/O.
Analog input 7.
Comparator 1 output.
Digital I/O.
Analog input 8.
Digital I/O.
Analog input 9.
Digital I/O.
Analog input 10.
Comparator reference voltage output.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
71
70
52
51
14
Pin
Typ e
I/O
I/O
O
I/O
O
I/O
I/O
I
I/O
I/O
I/O
O
I/O
I/O
O
Buffer
Type
ST
ST
—
ST
—
ST
ST
ST
ST
ST
ST
—
ST
ST
—
Description
PORTG is a bidirectional I/O port.
Digital I/O.
Capture 3 input/Compare 3 output/PWM3 output.
ECCP3 PWM output A.
Digital I/O.
EUSART2 asynchronous transmit.
EUSART2 synchronous clock (see related RX2/DT2 pin).
Digital I/O.
EUSART2 asynchronous receive.
EUSART2 synchronous data (see related TX2/CK2 pin).
Digital I/O.
Capture 4 input/Compare 4 output/PWM4 output.
ECCP3 PWM output D.
Digital I/O.
Capture 5 input/Compare 5 output/PWM5 output.
ECCP1 PWM output D.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to VDD)
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin Number
TQFP
49
50
66
61
47
48
58
39
Pin
Typ e
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
I/O
O
Buffer
Type
ST
—
ST
—
ST
—
ST
—
ST
—
ST
—
ST
—
ST
—
Description
PORTJ is a bidirectional I/O port.
Digital I/O.
External memory address latch enable.
Digital I/O.
External memory output enable.
Digital I/O.
External memory write low control.
Digital I/O.
External memory write high control.
Digital I/O.
External memory byte address 0 control.
ST= Schmitt Trigger input with CMOS levels Analog= Analog input
I= Input O= Output
P= Power OD= Open-Drain (no P diode to V
Note 1:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Extended Microcontroller mode).
2:Default assignment for ECCP2/P2A for all devices in all operating modes (CCP2MX Configuration bit is set).
3:Default assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is set).
4:Alternate assignment for ECCP2/P2A when CCP2MX Configuration bit is cleared (Microcontroller mode).
5:Alternate assignments for P1B/P1C/P3B/P3C (ECCPMX Configuration bit is cleared).
Pin
Typ e
Buffer
Type
Description
P—Ground reference for logic and I/O pins.
P—Positive supply for peripheral digital logic and I/O pins.
Core logic power or external filter capacitor connection.
P
—
Positive supply for microcontroller core logic
(regulator disabled).
Devices in the PIC18F97J60 family incorporate an
oscillator and microcontroller clock system that differs
from standard PIC18FXXJXX devices. The addition of
the Ethernet module, with its requirement for a stable
25 MHz clock source, makes it necessary to provide a
primary oscillator that can provide this frequency as
well as a range of different microcontroller clock
speeds. An overview of the oscillator structure is shown
in Figure 2-1.
Other oscillator features used in PIC18FXXJXX
enhanced microcontrollers, such as the internal RC
oscillator and clock switching, remain the same. They
are discussed later in this chapter.
2.2Oscillator Types
The PIC18F97J60 family of devices can be operated in
five different oscillator modes:
1.HSHigh-Speed Crystal/Resonator
2.HSPLLHigh-Speed Crystal/Resonator
with Software PLL Control
3.ECExternal Clock with F
4.ECPLLExternal Clock with Software PLL
Control
5.INTRCInternal 31 kHz Oscillator
2.2.1OSCILLATOR CONTROL
The oscillator mode is selected by programming the
FOSC2:FOSC0 Configuration bits. FOSC1:FOSC0
bits select the default primary oscillator modes, while
FOSC2 selects when INTRC may be invoked.
The OSCCON register (Register 2-2) selects the Active
Clock mode. It is primarily used in controlling clock
switching in power-managed modes. Its use is discussed
in Section 2.7.1 “Oscillator Control Register”.
The OSCTUNE register (Register 2-1) is used to select
the system clock frequency from the primary oscillator
source by selecting combinations of prescaler/postscaler
settings and enabling the PLL. Its use is described in
Section 2.6.1 “PLL Block”.
OSC/4 Output
FIGURE 2-1:PIC18F97J60 FAMILY CLOCK DIAGRAM
PIC18F97J60 Family
PLL/Prescaler/Postscaler
5x PLL
EC, HS, ECPLL, HSPLL
INTRC
Source
OSC2
OSC1
T1OSO
T1OSI
Primary Oscillator
Sleep
PLL
Prescaler
Secondary Oscillator
T1OSCEN
Enable
Oscillator
PLL
Postscaler
T1OSC
Internal Oscillator
Ethernet Clock
OSCTUNE<7:5>
Clock
Control
WDT, PWRT, FSCM
and Two-Speed Start-up
Clock Source Option
for Other Modules
FOSC2:FOSC0
OSCCON<1:0>
Peripherals
MUX
IDLEN
(1)
CPU
Note 1: See Table 2-2 for OSCTUNE register configurations and their corresponding frequencies.
In HS or HSPLL Oscillator modes, a crystal is
connected to the OSC1 and OSC2 pins to establish
oscillation. Figure 2-2 shows the pin connections.
The oscillator design requires the use of a crystal that
is rated for parallel resonant operation.
Note:Use of a crystal rated for series resonant
operation may give a frequency out of the
crystal manufacturer’s specifications.
FIGURE 2-2:CRYSTAL OSCILLATOR
OPERATION (HS OR
HSPLL CONFIGURATION)
(1)
C1
(1)
C2
Note 1: See Table 2-1 for initial values of C1 and C2.
2: A series resistor (R
crystals with a low drive specification.
F varies with the oscillator mode chosen.
3: R
XTAL
RS
OSC1
OSC2
(2)
To
Internal
RF
(3)
Logic
Sleep
PIC18FXXJ6X
S) may be required for
Note 1: Higher capacitance increases the stability
of the oscillator but also increases the
start-up time.
2: Since each crystal has its own character-
istics, the user should consult the crystal
manufacturer for appropriate values of
external components.
3: Rs may be required to avoid overdriving
crystals with low drive level specifications.
4: Always verify oscillator performance over
DD and temperature range that is
the V
expected for the application.
2.4External Clock Input (EC Modes)
The EC and ECPLL Oscillator modes require an external clock source to be connected to the OSC1 pin.
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 for test purposes or to synchronize other
logic. Figure 2-3 shows the pin connections for the EC
Oscillator mode.
FIGURE 2-3:EXTERNAL CLOCK
INPUT OPERATION
(EC CONFIGURATION)
TABLE 2-1:CAPACITOR SELECTION FOR
CRYSTAL OSCILLATOR
Osc Type
Crystal
Freq.
HS25 MHz33 pF33 pF
Capacitor values are for design guidance only.
Different capacitor values may be required to produce
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
DD and temperature range for the application. Refer
V
to the following application notes for oscillator specific
information:
®
• AN588, “PIC
Microcontroller Oscillator Design
Guide”
• AN826, “Crystal Oscillator Basics and Crystal
Selection for rfPIC
• AN849, “Basic PIC
• AN943, “Practical PIC
Design”
• AN949, “Making Your Oscillator Work”
See the notes following this table for additional
information.
Typical Capacitor Values
Tested:
C1C2
®
and PIC® Devices”
®
Oscillator Design”
®
Oscillator Analysis and
Clock from
Ext. System
OSC/4
F
OSC1/CLKI
PIC18FXXJ6X
OSC2/CLKO
An external clock source may also be connected to the
OSC1 pin in the HS mode, as shown in Figure 2-4. In
this configuration, the OSC2 pin is left open. Current
consumption in this configuration will be somewhat
higher than EC mode, as the internal oscillator’s
feedback circuitry will be enabled (in EC mode, the
feedback circuit is disabled).
The PIC18F97J60 family of devices includes an internal
oscillator source (INTRC) which provides a nominal
31 kHz output. The INTRC is enabled on device
power-up and clocks the device during its configuration
cycle until it enters operating mode. INTRC is also
enabled if it is selected as the device clock source or if
any of the following are enabled:
• Fail-Safe Clock Monitor
• Watchdog Timer
• Two-Speed Start-up
These features are discussed in greater detail in
Section 24.0 “Special Features of the CPU”.
The INTRC can also be optionally configured as the
default clock source on device start-up by setting the
FOSC2 Configuration bit. This is discussed in
Section 2.7.1 “Oscillator Control Register”.
2.6Ethernet Operation and the
Microcontroller Clock
Although devices of the PIC18F97J60 family can accept
a wide range of crystals and external oscillator inputs,
they must always have a 25 MHz clock source when
used for Ethernet applications. No provision is made for
internally generating the required Ethernet clock from a
primary oscillator source of a different frequency. A
frequency tolerance is specified, likely excluding the use
of ceramic resonators. See Section 27.0 “ElectricalCharacteristics”, Table 27-6, parameter 5, for more
details.
2.6.1PLL BLOCK
To accommodate a range of applications and microcontroller clock speeds, a separate PLL block is
incorporated into the clock system. It consists of three
components:
• A configurable prescaler (1:2 or 1:3)
• A 5x PLL frequency multiplier
• A configurable postscaler (1:1, 1:2, or 1:3)
The operation of the PLL block’s components is
controlled by the OSCTUNE register (Register 2-1).
The use of the PLL block’s prescaler and postscaler,
with or without the PLL itself, provides a range of system clock frequencies to choose from, including the
unaltered 25 MHz of the primary oscillator. The full
range of possible oscillator configurations compatible
with Ethernet operation is shown in Table 2-2.
REGISTER 2-1:OSCTUNE: PLL BLOCK CONTROL REGISTER
R/W-0 R/W-0R/W-0R/W-0 U-0U-0U-0U-0
PPST1PLLEN
bit 7bit 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
bit 7PPST1: PLL Postscaler Configuration bit
1 = Divide-by-2
0 = Divide-by-3
bit 6PLLEN: 5x Frequency Multiplier PLL Enable bit
1 = PLL enabled
0 = PLL disabled
bit 5PPST0: PLL Postscaler Enable bit
1 = Postscaler enabled
0 = Postscaler disabled
bit 4PPRE: PLL Prescaler Configuration bit
1 = Divide-by-2
0 = Divide-by-3
bit 3-0Unimplemented: Read as ‘0’
(1)
PPST0PPRE————
(1)
Note 1:Available only for ECPLL and HSPLL oscillator configurations; otherwise, this bit is unavailable and is read
The PIC18F97J60 family of devices includes a feature
that allows the device clock source to be switched from
the main oscillator to an alternate clock source. These
devices also offer two alternate clock sources. When
an alternate clock source is enabled, the various
power-managed operating 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 and the External Clock modes.
The particular mode is defined by the FOSC2:FOSC0
Configuration bits. The details of these modes are
covered earlier in this chapter.
The secondary 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. The PIC18F97J60
family of devices offers the Timer1 oscillator as a secondary oscillator. In all power-managed modes, this oscillator
is often the time base for functions such as a Real-Time
Clock (RTC).
Most often, a 32.768 kHz watch crystal is connected
between the RC0/T1OSO/T13CKI and RC1/T1OSI
pins. 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 primary clock source, the internaloscillator is available as a power-managed mode
clock source. The INTRC source 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 PIC18F97J60 family devices
are shown in Figure 2-1. See Section 24.0 “SpecialFeatures of the CPU” for Configuration register details.
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 FOSC2:FOSC0 Configuration bits), the secondary clock (Timer1 oscillator) and
the internal oscillator. The clock source changes after
one or more of the bits are changed, following a brief
clock transition interval.
The OSTS (OSCCON<3>) and T1RUN (T1CON<6>)
bits indicate which clock source is currently providing
the device clock. The T1RUN bit indicates when the
Timer1 oscillator is providing the device clock in
secondary clock modes. In power-managed modes,
only one of these bits will be set at any time. If neither
bit is set, the INTRC source is providing the clock, or
the internal oscillator has just started and is not yet
stable.
The IDLEN bit determines if the device goes into Sleep
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 will be ignored.
2: It is recommended that the Timer1
oscillator be operating and stable before
executing the SLEEP instruction or a very
long delay may occur while the Timer1
oscillator starts.
REGISTER 2-2:OSCCON: OSCILLATOR CONTROL REGISTER
R/W-0U-0U-0U-0R-qU-0R/W-0R/W-0
IDLEN———OSTS
bit 7bit 0
(1)
—SCS1SCS0
Legend:q = Value determined by configuration
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
bit 7IDLEN: Idle Enable bit
1 = Device enters Idle mode on SLEEP instruction
0 = Device enters Sleep mode on SLEEP instruction
bit 6-4Unimplemented: Read as ‘0’
bit 3OSTS: Oscillator Status bit
1 = Device is running from oscillator source defined when SCS1:SCS0 = 00
0 = Device is running from oscillator source defined when SCS1:SCS0 = 01, 10 or 11
The SCS bits are cleared on all forms of Reset. In the
device’s default configuration, this means the primary
oscillator defined by FOSC1:FOSC0 (that is, one of the
HC or EC modes) is used as the primary clock source
on device Resets.
The default clock configuration on Reset can be changed
with the FOSC2 Configuration bit. This bit affects the
clock source selection setting when SCS1:SCS0 = 00.
When FOSC2 = 1 (default), the oscillator source
defined by FOSC1:FOSC0 is selected whenever
SCS1:SCS0 = 00. When FOSC2 = 0, the INTRC oscillator is selected whenever SCS1:SCS2 = 00. Because the
SCS bits are cleared on Reset, the FOSC2 setting also
changes the default oscillator mode on Reset.
Regardless of the setting of FOSC2, INTRC will always
be enabled on device power-up. It will serve as the
clock source until the device has loaded its configuration values from memory. It is at this point that the
FOSC Configuration bits are read and the oscillator
selection of operational mode is made.
Note that either the primary clock or the internal
oscillator will have two bit setting options, at any given
time, depending on the setting of FOSC2.
2.7.2OSCILLATOR TRANSITIONS
PIC18F97J60 family devices contain circuitry to
prevent clock “glitches” when switching between clock
sources. A short pause in the device clock 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”.
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 oscillator) will stop oscillating.
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 RC_RUN and RC_IDLE modes, the internal oscillator provides the device clock source. The 31 kHz
INTRC output can be used directly 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)” through
Section 24.5 “Fail-Safe Clock Monitor” for more
information on WDT, Fail-Safe Clock Monitor and
Two-Speed Start-up).
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 increase the current consumed during Sleep.
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., MSSP slave,
PSP, INTx pins and others). Peripherals that may add
significant current consumption are listed in
Section 27.2 “DC Characteristics: Power-Down and
Supply Current”.
2.9Power-up Delays
Power-up delays are controlled by two timers, so that
no external Reset circuitry is required for most applications. The delays ensure that the device is kept in
Reset until the device power supply is stable under normal circumstances and the primary clock is operating
and stable. For additional information on power-up
delays, see Section 4.6 “Power-up Timer (PWRT)”.
The first timer is the Power-up Timer (PWRT), which
provides a fixed delay on power-up (parameter 33,
Table 27-12); it is always enabled.
The second timer is the Oscillator Start-up Timer
(OST), intended to keep the chip in Reset until the
crystal oscillator is stable (HS modes). The OST does
this by counting 1024 oscillator cycles before allowing
the oscillator to clock the device.
There is a delay of interval T
Table 27-12), following POR, while the controller
becomes ready to execute instructions.
CSD (parameter 38,
TABLE 2-3:OSC1 AND OSC2 PIN STATES IN SLEEP MODE
Oscillator ModeOSC1 PinOSC2 Pin
EC, ECPLLFloating, pulled by external clockAt logic low (clock/4 output)
HS, HSPLLFeedback 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.
PIC18F97J60 FAMILY
3.0POWER-MANAGED MODES
The PIC18F97J60 family devices provide the ability to
manage power consumption by simply managing clocking to the CPU and the peripherals. In general, a lower
clock frequency and a reduction in the number of circuits
being clocked constitutes lower consumed power. For
the sake of managing power in an application, there are
three primary modes of operation:
• Run mode
• Idle mode
• Sleep mode
These modes define which portions of the device are
clocked and at what speed. The Run 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 PIC
devices. One is the clock switching feature, offered in
other PIC18 devices, allowing the controller to use the
Timer1 oscillator in place of the primary oscillator. Also
included is the Sleep mode, offered by all PIC MCU
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 which
clock source is to be used. 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 summarized in Table 3-1.
®
MCU
3.1.1CLOCK SOURCES
The SCS1:SCS0 bits allow the selection of one of three
clock sources for power-managed modes. They are:
• The primary clock, as defined by the
FOSC2:FOSC0 Configuration bits
• The secondary clock (Timer1 oscillator)
• The internal oscillator
3.1.2ENTERING POWER-MANAGED
MODES
Switching from one power-managed mode to another
begins by loading the OSCCON register. The
SCS1:SCS0 bits select the clock source and determine
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 subject to clock transition 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 change to a power-managed mode does
not always require setting all of these bits. Many
transitions may be done by changing the oscillator
select bits, or changing the IDLEN bit, prior to issuing 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.
The length of the transition between clock sources 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.
Two bits indicate the current clock source and its
status: OSTS (OSCCON<3>) and T1RUN
(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 T1RUN bit is set, the Timer1
oscillator is providing the clock. If neither of these bits
is set, INTRC is clocking the device.
Note: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.
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.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 Timer1 oscillator. This gives users the
option of lower power consumption while still using a
high accuracy clock source.
SEC_RUN mode is entered by setting the SCS1:SCS0
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_RUN 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, device clocks will be delayed until
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 clock becomes ready, 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.
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 unless Two-Speed Start-up
is enabled (see Section 24.4 “Two-Speed Start-up”
for details). In this mode, the OSTS bit is set. (see
Section 2.7.1 “Oscillator Control Register”).
In RC_RUN mode, the CPU and peripherals are
clocked from the internal oscillator; the primary clock is
shut down. This mode 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.
This mode is entered by setting SCS<1:0> to ‘11’.
On transitions from RC_RUN mode to PRI_RUN mode,
the device continues to be clocked from the INTRC
while the primary clock is started. When the primary
clock becomes ready, a clock switch to the primary
clock occurs (see Figure 3-4). When the clock switch is
complete, the OSTS bit is set and the primary clock is
providing the device clock. The IDLEN and SCS bits
are not affected by the switch. The INTRC source will
continue to run if either the WDT or Fail-Safe Clock
Monitor is enabled.
When the clock source is switched to the INTRC (see
Figure 3-3), the primary oscillator is shut down and the
OSTS bit is cleared.
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
INTRC
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.
The power-managed Sleep mode is identical to the
legacy Sleep mode offered in all other PIC MCU
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 status bits are
cleared.
Entering the Sleep mode from any other mode 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 event occurs in Sleep mode (by interrupt,
Reset or WDT time-out), the device will not be clocked
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 if either the Two-Speed
Start-up or the Fail-Safe Clock Monitor is enabled (see
Section 24.0 “Special Features of the CPU”). In
either case, the OSTS bit is set when the 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 is set to ‘1’ when a SLEEP instruction is
executed, the peripherals will be clocked from the clock
source selected using the SCS1:SCS0 bits; however, the
CPU will not be clocked. The clock source status bits are
not affected. Setting IDLEN and executing a SLEEP
instruction provides a quick method of switching from a
given Run mode to its corresponding Idle mode.
If the WDT is selected, the INTRC source will continue
to operate. If the Timer1 oscillator is enabled, 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 wake event occurs, CPU
execution is delayed by an interval of T
(parameter 38, Table 27-12) 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 result in a WDT wake-up to the Run mode
currently specified by the SCS1:SCS0 bits.
CSD
FIGURE 3-5:TRANSITION TIMING FOR ENTRY TO SLEEP MODE
Q4Q3Q2
Q1Q1
OSC1
CPU
Clock
Peripheral
Clock
Sleep
Program
Counter
PC + 2PC
FIGURE 3-6:TRANSITION TIMING FOR WAKE FROM SLEEP MODE (HSPLL)
OSC1
PLL Clock
Output
CPU Clock
Peripheral
Clock
Program
Counter
Note1: 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 resumption of device operation with its more
accurate primary clock source, since the clock 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 set the SCS<1:0> bits to ‘10’ and execute
SLEEP. Although the CPU is disabled, the peripherals
continue to be clocked from the primary clock source
specified by the FOSC1:FOSC0 Configuration bits.
The OSTS bit remains set (see Figure 3-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 allow 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 executing a SLEEP instruction. If
the device is in another Run mode, set IDLEN first, then
set SCS<1:0> 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 occurs, the peripherals continue to
be clocked from the Timer1 oscillator. After an interval
CSD following the wake event, the CPU begins exe-
of T
cuting code being clocked by the Timer1 oscillator. The
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 mode.
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
Q2
Q3
PCPC + 2
Q4
FIGURE 3-8:TRANSITION TIMING FOR WAKE FROM IDLE TO RUN MODE
In RC_IDLE mode, the CPU is disabled but the peripherals continue to be clocked from the internal oscillator.
This mode allows for controllable power conservation
during Idle periods.
From RC_RUN mode, RC_IDLE mode is entered by
setting the IDLEN bit and executing a SLEEP instruction.
If the device is in another Run mode, first set IDLEN,
then clear the SCS bits and execute SLEEP. When the
clock source is switched to the INTRC, the primary
oscillator is shut down and the OSTS bit is cleared.
When a wake event occurs, the peripherals continue to
be clocked from the INTRC. After a delay of T
following the wake event, the CPU begins executing
code being clocked by the INTRC. 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.
CSD
3.5Exiting Idle and Sleep Modes
An exit from Sleep mode, or any of the Idle modes, is
triggered by 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 sections (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 enabled by setting its enable bit in one
of the INTCON or PIE registers. The exit sequence is
initiated when the corresponding interrupt flag bit is set.
On all exits from Idle 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 interval T
is required when leaving the Sleep and Idle modes.
This delay is required for the CPU to prepare for execution. Instruction execution resumes on the first clock
cycle following this delay.
CSD following the wake event
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 is not executing code (all Idle modes and
Sleep mode), the time-out will result in an exit from the
power-managed mode (see Section 3.2 “RunModes” and Section 3.3 “Sleep Mode”). If the device
is executing code (all Run modes), the time-out will
result in a WDT Reset (see Section 24.2 “WatchdogTimer (WDT)”).
The WDT timer and postscaler are cleared by one of
the following events:
• Executing a SLEEP or CLRWDT instruction
• The loss of a currently selected clock source (if
the Fail-Safe Clock Monitor is enabled)
3.5.3EXIT BY RESET
Exiting an Idle or Sleep mode by Reset automatically
forces the device to run from the INTRC.
3.5.4EXIT WITHOUT AN OSCILLATOR
START-UP TIMER DELAY
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
• The primary clock source is either the EC or
ECPLL mode
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 (EC). However, a
fixed delay of interval T
still required when leaving the Sleep and Idle modes to
allow the CPU to prepare for execution. Instruction
execution resumes on the first clock cycle following this
delay.
This section discusses Resets generated by hard
events (MCLR), power events (POR and BOR) and
4.1RCON Register
Device Reset events are tracked through the RCON
register (Register 4-1). The lower six bits of the register
indicate that a specific Reset event has occurred. In
most cases, these bits can only be set by the event and
must be cleared by the application 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 Section 4.7 “Reset Stateof Registers”.
The RCON register also has a control bit for setting
interrupt priority (IPEN). Interrupt priority is discussed
in Section 9.0 “Interrupts”.
Configuration Mismatches (CM). It also covers the
operation of the various start-up timers. Stack Reset
events are covered in Section 5.1.6.4 “Stack Full and
Underflow Resets”. WDT Resets are covered in
Section 24.2 “Watchdog Timer (WDT)”.
FIGURE 4-1:SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
RESET Instruction
MCLR
VDD
Configuration Word Mismatch
Stack
Pointer
Stack Full/Underflow Reset
External Reset
( )_IDLE
Sleep
WDT
Time-out
DD Rise
V
Detect
Brown-out
Reset
PWRT
32 μs
INTRC
POR Pulse
(1)
PWRT
11-Bit Ripple Counter
66 ms
S
Chip_Reset
R
Q
Note 1: The ENVREG pin must be tied high to enable Brown-out Reset. The Brown-out Reset is provided by the on-chip
voltage regulator when there is insufficient source voltage to maintain regulation.
PIC18F97J60 FAMILY
REGISTER 4-1:RCON: RESET CONTROL REGISTER
R/W-0U-0R/W-1R/W-1R-1R-1R/W-0R/W-0
IPEN
bit 7bit 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
bit 7IPEN: Interrupt Priority Enable bit
bit 6Unimplemented: Read as ‘0’
bit 5CM
bit 4RI
bit 3TO
bit 2PD
bit 1POR
bit 0BOR
—CMRITOPDPORBOR
1 =Enable priority levels on interrupts
0 =Disable priority levels on interrupts (PIC16CXXX Compatibility mode)
: Configuration Mismatch Flag bit
1 = A Configuration Mismatch Reset has not occurred
0 = A Configuration Mismatch Reset has occurred (must be set in software after a Configuration
Mismatch Reset occurs)
: 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 occurs)
: Watchdog Timer Time-out Flag bit
1 = Set by power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
: 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: 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: If the on-chip voltage regulator is disabled, BOR
BOR” for more information.
3: Brown-out Reset is said to have occurred when BOR
‘1’ by software immediately after a Power-on Reset).
remains ‘0’ at all times. See Section 4.4.1 “Detecting
is ‘0’ and POR is ‘1’ (assuming that POR was set to
PIC18F97J60 FAMILY
4.2Master Clear (MCLR)
The MCLR pin provides a method for triggering a hard
external Reset of the device. A Reset is generated by
holding the pin low. PIC18 extended microcontroller
devices have a noise filter in the MCLR
Reset path
which detects and ignores small pulses.
The MCLR
pin is not driven low by any internal Resets,
including the WDT.
4.3Power-on Reset (POR)
A Power-on Reset condition is generated on-chip
whenever V
DD rises above a certain threshold. This
allows the device to start in the initialized state when
DD is adequate for operation.
V
To take advantage of the POR circuitry, tie the MCLR
pin through a resistor (1 kΩ to 10 kΩ) to VDD. This will
eliminate external RC components usually needed to
create a Power-on Reset delay. A minimum rise rate for
DD is specified (parameter D004). For a slow rise
V
time, see Figure 4-2.
When the device starts 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
bit (RCON<1>).
The state of the bit is set to ‘0’ whenever a Power-on
Reset 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 Power-on Reset.
4.4Brown-out Reset (BOR)
The PIC18F97J60 family of devices incorporates a
simple BOR function when the internal regulator is
enabled (ENVREG pin is tied to V
below VBOR (parameter D005), for greater than time
T
BOR (parameter 35), will reset the device. A Reset
may or may not occur if V
BOR. The chip will remain in Brown-out Reset
than T
until V
DD rises above VBOR.
Once a BOR has occurred, the Power-up Timer will
keep the chip in Reset for T
DD drops below VBOR while the Power-up Timer is
V
running, the chip will go back into a Brown-out Reset
and the Power-up Timer will be initialized. Once V
rises above VBOR, the Power-up Timer will execute the
additional time delay.
DD). Any drop of VDD
DD falls below VBOR for less
PWRT (parameter 33). If
DD
FIGURE 4-2:EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW V
VDD
Note 1: External Power-on Reset circuit is required
VDD
(1)
D
2: R < 40 kΩ is recommended to make sure that
3: R1 ≥ 1 kΩ will limit any current flowing into
(2)
R
R1
C
only if the V
The diode D helps discharge the capacitor
quickly when V
the voltage drop across R does not violate
the device’s electrical specification.
MCLR
of MCLR
Electrostatic Discharge (ESD), or Electrical
Overstress (EOS).
DD power-up slope is too slow.
from external capacitor C in the event
/VPP pin breakdown, due to
DD POWER-UP)
(3)
MCLR
PIC18FXXJ6X
DD powers down.
4.4.1DETECTING BOR
The BOR bit always resets to ‘0’ on any Brown-out
Reset or Power-on Reset event. This makes it difficult
to determine if a Brown-out Reset event has occurred
just by reading the state of BOR
alone. A more reliable
method is to simultaneously check the state of both
POR and BOR. This assumes that the POR bit is reset
to ‘1’ in software immediately after any Power-on Reset
event. If BOR
is ‘0’ while POR is ‘1’, it can be reliably
assumed that a Brown-out Reset event has occurred.
If the voltage regulator is disabled, Brown-out Reset
functionality is disabled. In this case, the BOR
bit
cannot be used to determine a Brown-out Reset event.
The BOR bit is still cleared by a Power-on Reset event.
4.5Configuration Mismatch (CM)
The Configuration Mismatch (CM) Reset is designed to
detect and attempt to recover from random, memory
corrupting events. These include Electrostatic
Discharge (ESD) events which can cause widespread
single-bit changes throughout the device and result in
catastrophic failure.
In PIC18FXXJ Flash devices, the device Configuration
registers (located in the configuration memory space)
are continuously monitored during operation by comparing their values to complimentary shadow registers.
If a mismatch is detected between the two sets of
registers, a CM Reset automatically occurs. These
events are captured by the CM
state of the bit is set to ‘0’ whenever a CM event occurs;
it does not change for any other Reset event.
A CM Reset behaves similarly to a Master Clear Reset,
RESET instruction, WDT time-out or Stack Event Reset.
As with all hard and power Reset events, the device
Configuration Words are reloaded from the Flash Configuration Words in program memory as the device
restarts.
4.6Power-up Timer (PWRT)
PIC18F97J60 family of devices incorporates an
on-chip Power-up Timer (PWRT) to help regulate the
Power-on Reset process. The PWRT is always
enabled. The main function is to ensure that the device
voltage is stable before code is executed.
The Power-up Timer (PWRT) of the PIC18F97J60 family 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 = 66 ms. While the PWRT
is counting, the device is held in Reset.
The power-up time delay depends on the INTRC clock
and will vary from chip-to-chip due to temperature and
process variation. See DC parameter 33 for details.
4.6.1TIME-OUT SEQUENCE
The PWRT time-out is invoked after the POR pulse has
cleared. The total time-out will vary based on the status
of the PWRT. Figure 4-3, Figure 4-4, Figure 4-5 and
Figure 4-6 all depict time-out sequences on power-up.
Since the time-outs occur from the POR pulse, if MCLR
is kept low long enough, the PWRT will expire. Bringing
high will begin execution immediately
MCLR
(Figure 4-5). This is useful for testing purposes or to
synchronize more than one PIC18FXXJ6X device
operating in parallel.
FIGURE 4-3:TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD, VDD RISE < TPWRT)
, PD, POR and BOR) are set or cleared differently in
4.7Reset State of Registers
Most registers are unaffected by a Reset. Their status
is unknown on POR and unchanged by all other
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 (CM
TABLE 4-1:STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION FOR
RCON REGISTER
Condition
Power-on Reset0000h111100 00
RESET Instruction0000hu0uuuu uu
Brown-out Reset0000h1111u0 uu
Configuration Mismatch Reset0000h0uuuuu uu
during power-managed
MCLR
Run modes
MCLR
during power-managed
Idle modes and Sleep mode
MCLR
during full-power
execution
Stack Full Reset (STVREN = 1)0000huuuuuu 1u
Stack Underflow Reset
(STVREN = 1)
Stack Underflow Error (not an
actual Reset, STVREN = 0)
WDT time-out during full power
or power-managed Run modes
WDT time-out during
power-managed Idle or Sleep
modes
Interrupt exit from
power-managed modes
Legend: u = unchanged
Note 1: When the wake-up is due to an interrupt, and the GIEH or GIEL bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
Program
Counter
(1)
0000huu1uuu uu
0000huu10uu uu
0000huuuuuu uu
0000huuuuuu u1
0000huuuuuu u1
0000huu0uuu uu
PC + 2uu00uu uu
PC + 2uuu0uu uu
, RI,
CM
TO
different Reset situations, as indicated in Table 4-1.
These bits are used in software to determine the nature
of the Reset.
Table 4-2 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.
There are two types of memory in PIC18 Flash
microcontroller devices:
• Program Memory
• Data RAM
As Harvard architecture devices, the data and program
memories use separate busses. This allows for
concurrent access of the two memory spaces.
Additional detailed information on the operation of the
Flash program memory is provided in Section 6.0
“Flash Program Memory”.
5.1Program Memory Organization
PIC18 microcontrollers implement a 21-bit program
counter which is capable of addressing a 2-Mbyte
program memory space. Accessing a location between
the upper boundary of the physically implemented
memory and the 2-Mbyte address will return all ‘0’s (a
NOP instruction).
The entire PIC18F97J60 family offers three sizes of
on-chip Flash program memory, from 64 Kbytes (up
to 32,764 single-word instructions) to 128 Kbytes
(65,532 single-word instructions). The program memory maps for individual family members are shown in
Figure 5-1.
FIGURE 5-1:MEMORY MAPS FOR PIC18F97J60 FAMILY DEVICES
All PIC18 devices have a total of three hard-coded
return vectors in their program memory space. The
Reset vector address is the default value to which the
program counter returns on all device Resets; it is
located at 0000h.
PIC18 devices also have two interrupt vector
addresses for the handling of high-priority and
low-priority interrupts. The high-priority interrupt vector
is located at 0008h and the low-priority interrupt vector
is at 0018h. Their locations in relation to the program
memory map are shown in Figure 5-2.
FIGURE 5-2:HARD VECTOR AND
CONFIGURATION WORD
LOCATIONS FOR
PIC18F97J60 FAMILY
DEVICES
Reset Vector
High-Priority Interrupt Vector
Low-Priority Interrupt Vector
0000h
0008h
0018h
5.1.2FLASH CONFIGURATION WORDS
Because the PIC18F97J60 family devices do not have
persistent configuration memory, the top four words of
on-chip program memory are reserved for configuration
information. On Reset, the configuration information is
copied into the Configuration registers.
The Configuration Words are stored in their program
memory location in numerical order, starting with the
lower byte of CONFIG1 at the lowest address and ending with the upper byte of CONFIG4. For these devices,
only Configuration Words, CONFIG1 through
CONFIG3, are used; CONFIG4 is reserved. The actual
addresses of the Flash Configuration Words for
devices in the PIC18F97J60 family are shown in
Table 5-1. Their location in the memory map is shown
with the other memory vectors in Figure 5-2.
Additional details on the device Configuration Words
are provided in Section 24.1 “Configuration Bits”.
TABLE 5-1:FLASH CONFIGURATION
WORDS FOR PIC18F97J60
FAMILY DEVICES
Device
Program
Memory
(Kbytes)
Configuration
Word Addresses
On-Chip
Program Memory
Flash Configuration Words
Read as ‘
Legend:(Top of Memory) represents upper boundary
of on-chip program memory space (see
Figure 5-1 for device-specific values).
Shaded area represents unimplemented
memory. Areas are not shown to scale.
•The Extended Microcontroller Mode allows
access to both internal and external program
memories as a single block. The device can
The 100-pin devices in this family can address up to a
total of 2 Mbytes of program memory. This is achieved
through the external memory bus. There are two
distinct operating modes available to the controllers:
• Microcontroller (MC)
• Extended Microcontroller (EMC)
The program memory mode is determined by setting
the EMB Configuration bits (CONFIG3L<5:4>), as
shown in Register 5-1. (See also Section 24.1“Configuration Bits” for additional details on the
device Configuration bits.)
The program memory modes operate as follows:
•The Microcontroller Mode accesses only on-chip
Flash memory. Attempts to read above the top of
on-chip memory causes a read of all ‘0’s (a NOP
access its entire on-chip program memory. Above
this, the device accesses external program
memory up to the 2-Mbyte program space limit.
Execution automatically switches between the
two memories as required.
The setting of the EMB Configuration bits also controls
the address bus width of the external memory bus. This
is covered in more detail in Section 7.0 “ExternalMemory Bus”.
In all modes, the microcontroller has complete access
to data RAM.
Figure 5-3 compares the memory maps of the different
program memory modes. The differences between
on-chip and external memory access limitations are
more fully explained in Table 5-2.
instruction).
The Microcontroller mode is also the only operating
R = Readable bitWO = Write-Once bitU = Unimplemented bit, read as ‘0’
-n = Value when device is unprogrammed‘1’ = Bit is set‘0’ = Bit is cleared
bit 7WAIT: External Bus Wait Enable bit
(1)
1 = Wait states for operations on external memory bus disabled
0 = Wait states for operations on external memory bus enabled and selected by MEMCON<5:4>
bit 6BW: Data Bus Width Select bit
(1)
1 = 16-Bit Data Width mode
0 = 8-Bit Data Width mode
bit 5-4EMB1:EMB0: External Memory Bus Configuration bits
bit 3EASHFT: External Address Bus Shift Enable bit
(1)
1 = Address shifting enabled; address on external bus is offset to start at 000000h
0 = Address shifting disabled; address on external bus reflects the PC value
5.1.4EXTENDED MICROCONTROLLER
MODE AND ADDRESS SHIFTING
By default, devices in Extended Microcontroller mode
directly present the program counter value on the
external address bus for those addresses in the range
of the external memory space. In practical terms, this
means addresses in the external memory device below
To avoid this, the Extended Microcontroller mode
implements an address shifting option to enable automatic address translation. In this mode, addresses
presented on the external bus are shifted down by the
size of the on-chip program memory and are remapped
to start at 0000h. This allows the complete use of the
external memory device’s memory space.
the top of on-chip memory are unavailable.
FIGURE 5-3:MEMORY MAPS FOR PIC18F97J60 FAMILY PROGRAM MEMORY MODES
Microcontroller Mode
On-Chip
Memory
Space
000000h
On-Chip
Program
Memory
(Top of Memory)
(Top of Memory) + 1
Reads
‘0’s
(1)
Extended Microcontroller Mode
External
Memory
Space
No
Access
External
Memory
On-Chip
Memory
Space
000000h
On-Chip
Program
Memory
(Top of Memory)
(Top of Memory) + 1
Mapped
to
External
Memory
Space
(2)
Extended Microcontroller Mode
with Address Shifting
External
Memory
Space
External
Memory
On-Chip
Memory
Space
On-Chip
Program
Memory
Mapped
to
External
Memory
Space
000000h
(Top of Memory)
(Top of Memory) + 1
1FFFFFh –
(Top of Memory)
(2)
1FFFFFh
Legend:(Top of Memory) represents upper boundary of on-chip program memory space (see Figure 5-1 for device-specific
values). Shaded areas represent unimplemented or inaccessible areas depending on the mode.
Note 1:This mode is the only available mode on 64-pin and 80-pin devices and the default on 100-pin devices.
2:These modes are only available on 100-pin devices.
1FFFFFh
1FFFFFh
TABLE 5-2:MEMORY ACCESS FOR PIC18F9XJ60/9XJ65 PROGRAM MEMORY MODES
The Program Counter (PC) specifies the address of the
instruction to fetch for execution. 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 byte, or PCH register, contains
the PC<15:8> bits; it is not directly readable or writable.
Updates to the PCH register are performed 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 to
the PCL. Similarly, the upper two bytes of the program
counter are transferred to PCLATH and PCLATU by an
operation that reads PCL. This is useful for computed
offsets to the PC (see Section 5.1.8.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, GOTO and 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.6RETURN ADDRESS STACK
The return address stack allows any combination of up to
31 program calls and interrupts to occur. The PC is
pushed onto the stack 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 (and on ADDULNK and SUBULNK
instructions if the extended instruction set is enabled).
PCLATU and PCLATH are not affected by any of the
RETURN or CALL instructions.
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 data space. 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 Function Registers. Data can also
be pushed to, or popped from the stack, using these
registers.
A CALL type instruction causes a push onto the stack.
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 type instruction causes
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 stack is
full, has overflowed or has underflowed.
5.1.6.1Top-of-Stack Access
Only the top of the return address stack (TOS) is readable and writable. A set of three registers,
TOSU:TOSH:TOSL, holds the contents of the stack
location pointed to by the STKPTR register
(Figure 5-4). This allows users to implement a software
stack if necessary. After a CALL, RCALL or interrupt
(and ADDULNK and SUBULNK instructions if the
extended instruction set is enabled), the software can
read the pushed value by reading the
TOSU:TOSH:TOSL registers. These values can be
placed on a user-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-4:RETURN ADDRESS STACK AND ASSOCIATED REGISTERS
The STKPTR register (Register 5-2) contains the Stack
Pointer value, the STKFUL (Stack Full) status bit and
the STKUNF (Stack Underflow) status bit. 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 (RTOS) for return stack maintenance.
After the PC is pushed onto the stack 31 times (without
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 description 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 bit 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 the STKPTR will remain at 31.
When the stack has been popped enough times to
unload the stack, the next pop returns 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.6.3PUSH and POP Instructions
Since the Top-of-Stack is readable and writable, the
ability to push values onto the stack and pull values 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 TOSL can be modified to place data
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-2:STKPTR: STACK POINTER REGISTER
R/C-0R/C-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0
STKFUL
bit 7bit 0
Legend:C = Clearable bit
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
bit 7STKFUL: Stack Full Flag bit
bit 6STKUNF: Stack Underflow Flag bit
bit 5Unimplemented: Read as ‘0’
bit 4-0SP4:SP0: Stack Pointer Location bits
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
(1)
STKUNF
1 = Stack became full or overflowed
0 = Stack has not become full or overflowed
1 = Stack underflow occurred
0 = Stack underflow did not occur
Device Resets on stack overflow and stack underflow
conditions are enabled by setting the STVREN bit in
Configuration Register 1L. When STVREN is set, a full
or underflow condition will set the appropriate STKFUL
or STKUNF bit and then cause a device Reset. When
STVREN is cleared, a full or underflow condition will set
the appropriate STKFUL or STKUNF bit, but not cause
a device Reset. The STKFUL or STKUNF bit is cleared
by user software or a Power-on Reset.
5.1.7FAST REGISTER STACK
A Fast Register Stack is provided for the STATUS,
WREG and BSR registers to provide a “fast return”
option for interrupts. This 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 values into the Stack registers. The values in
the registers are then loaded back into the working
registers if the RETFIE, FAST instruction 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-priority 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 may use the
Fast Register Stack for returns from interrupt. If no
interrupts are used, the Fast Register Stack can be
used to restore the STATUS, WREG and BSR registers
at the end of a subroutine call. To use the Fast Register
Stack for a subroutine call, a CALL label, FAST
instruction must be executed to save the STATUS,
WREG and BSR registers 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.8LOOK-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.8.1Computed GOTO
A computed GOTO is accomplished by adding an offset
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 offset into the table before
executing a call to that table. 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.8.2Table Reads
A better method of storing data in program memory
allows two bytes of data to be stored in each instruction
location.
Look-up table data may be stored two bytes per
program word while programming. The Table Pointer
(TBLPTR) specifies the byte address and the Table
Latch (TABLAT) contains the data that is read from the
program memory. Data is transferred from program
memory one byte at a time.
Table read operation is discussed further in
Section 6.1 “Table Reads and Table Writes”.
The microcontroller clock input, whether from an
internal or external source, is internally divided by four
to generate four non-overlapping quadrature clocks
(Q1, Q2, Q3 and Q4). Internally, the program counter is
incremented on every Q1. The instruction is fetched
from the program memory and latched into the
Instruction Register (IR) during Q4. The instruction is
decoded and executed during the following Q1 through
Q4. The clocks and instruction execution flow are
shown in Figure 5-5.
FIGURE 5-5: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 an
instruction causes the program counter 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 (PC)
incrementing in Q1.
In the execution cycle, the fetched instruction is latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then decoded and executed during the Q2,
Q3 and Q4 cycles. Data memory 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
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 boundaries, the PC increments in steps
of 2 and the LSb will always read ‘0’ (see Section 5.1.5“Program Counter”).
Figure 5-6 shows an example of how instruction words
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-6 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 manner. The offset
value stored in a branch instruction represents 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.
FIGURE 5-6:INSTRUCTIONS IN PROGRAM MEMORY
LSB = 1LSB = 0↓
F0h00h00000Ch
F4h56h000010h
Instruction 1:
Instruction 2:
Instruction 3:
Program Memory
Byte Locations
MOVLW055h0Fh55h000008h
GOTO0006hEFh03h00000Ah
MOVFF123h, 456hC1h23h00000Eh
→
Word Address
000000h
000002h
000004h
000006h
000012h
000014h
5.2.4TWO-WORD INSTRUCTIONS
The standard PIC18 instruction set has four, two-word
instructions: CALL, MOVFF, GOTO and LSFR. In all
cases, the second word of the instructions always has
‘1111’ as its four Most Significant bits; the other 12 bits
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 word – the data in the second word is accessed
and used by the instruction sequence. If the first word
is skipped for some reason and the second word is
executed by itself, 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
information 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
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 in PIC18 devices is implemented as
static RAM. Each register in the data memory has a
12-bit address, allowing up to 4096 bytes of addressable
memory. The memory space is divided into 16 banks
that contain 256 bytes each. All of the PIC18F97J60
family devices implement all available banks and provide 3808 bytes of data memory available to the user.
Figure 5-7 shows the data memory organization for the
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 functions, while GPRs are used for data
storage and scratchpad operations in the user’s
application. Any read of an unimplemented 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
section.
To ensure that commonly used registers (most SFRs
and select GPRs) can be accessed in a single cycle,
PIC18 devices implement an Access Bank. This is a
256-byte memory space that provides fast access to
the majority of SFRs and the lower portion of GPR
Bank 0 without using the BSR. Section 5.3.2 “AccessBank” provides a detailed description of the Access
RAM.
5.3.1BANK SELECT REGISTER
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 instructions in the PIC18 instruction set make use
of the Bank Pointer, known as the Bank Select Register
(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; they will always read ‘0’ and cannot be
written to. The BSR can be loaded directly by using the
MOVLB instruction.
The value of the BSR indicates the bank in data memory.
The 8 bits in the instruction show the location in the bank
and can be thought of as an offset from the bank’s lower
boundary. The relationship between the BSR’s value
and the bank division in data memory is shown in
Figure 5-8.
Since up to 16 registers may share the same low-order
address, the user must always 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 address of F9h, while the BSR
is 0Fh, will end up resetting the program counter.
While any bank can be selected, 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 STATUS register will still be affected as if the
operation was successful. The data memory map in
Figure 5-7 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 instruction ignores the
BSR completely when it executes. All other instructions
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-8:USE OF THE BANK SELECT REGISTER (DIRECT ADDRESSING)
(1)
7
0000
Bank Select
Note 1:The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to
BSR
0010
(2)
the registers of the Access Bank.
2:The MOVFF instruction embeds the entire 12-bit address in the instruction.
000h
0
100h
200h
300h
E00h
F00h
FFFh
Data Memory
Bank 0
Bank 1
Bank 2
Bank 3
through
Bank 13
Bank 14
Bank 15
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
From Opcode
7
11111111
11111111
(2)
0
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 that the user must always
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.
To streamline access for the most commonly 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 96 bytes of
memory (00h-5Fh) in Bank 0 and the last 160 bytes of
memory (60h-FFh) in Bank 15. The lower block is
known as the “Access RAM” and is composed of
GPRs. The upper block 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-7).
The Access Bank is used by core PIC18 instructions
that include the Access RAM bit (the ‘a’ parameter in
the instruction). When ‘a’ is equal to ‘1’, the instruction
uses the BSR and the 8-bit address included in the
opcode for the data memory address. When ‘a’ is ‘0’,
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 60h and
above, this means that users can evaluate and operate
on SFRs more efficiently. The Access RAM below 60h
is a good place for data 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 variables.
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”.
5.3.3GENERAL PURPOSE
REGISTER FILE
PIC18 devices may have banked memory in the GPR
area. This is data RAM which is available for use 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.
The Special Function Registers (SFRs) are registers
used by the CPU and peripheral modules for controlling
the desired operation of the device. These registers are
implemented as static RAM.
The main group of SFRs start at the top of data memory
(FFFh) and extend downward to occupy more than the
top half of Bank 15 (F60h to FFFh). These SFRs can
be classified into two sets: those associated with the
“core” device functionality (ALU, Resets and interrupts)
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 the peripheral features are described
in the chapter for that peripheral.
The SFRs are typically distributed among the
peripherals whose functions they control. Unused SFR
locations are unimplemented and read as ‘0’s. A list of
SFRs is given in Table 5-3; a full description is provided
in Table 5-5.
and those related to the peripheral functions. The
TABLE 5-3:SPECIAL FUNCTION REGISTER MAP FOR PIC18F97J60 FAMILY DEVICES
2:Unimplemented registers are read as ‘0’.
3:This register is not available on 64-pin devices.
4:This register is not available on 64 and 80-pin devices.
In addition to the standard SFR set in Bank 15,
members of the PIC18F97J60 family have a second
set of SFRs. This group, associated exclusively with
the Ethernet module, occupies the top half of Bank 14
(E80h to EFFh).
Note:To improve performance, frequently
accessed Ethernet registers are located in
the standard SFR bank (F60h through
FFFh).
A complete list of Ethernet SFRs is given in Table 5-4.
All SFRs are fully described in Table 5-5
TABLE 5-4:ETHERNET SFR MAP FOR PIC18F97J60 FAMILY DEVICES
INDF0Uses contents of FSR0 to address data memory – value of FSR0 not changed (not a physical register)N/A61, 91
POSTINC0Uses contents of FSR0 to address data memory – value of FSR0 post-incremented (not a physical register)N/A61, 92
POSTDEC0 Uses contents of FSR0 to address data memory – value of FSR0 post-decremented (not a physical register)N/A61, 92
PREINC0Uses contents of FSR0 to address data memory – value of FSR0 pre-incremented (not a physical register)N/A61, 92
PLUSW0Uses contents of FSR0 to address data memory – value of FSR0 pre-incremented (not a physical register) –
FSR0H
FSR0LIndirect Data Memory Address Pointer 0 Low Bytexxxx xxxx61, 92
WREGWorking Registerxxxx xxxx61
INDF1Uses contents of FSR1 to address data memory – value of FSR1 not changed (not a physical register)N/A61, 91
POSTINC1Uses contents of FSR1 to address data memory – value of FSR1 post-incremented (not a physical register)N/A61, 92
POSTDEC1 Uses contents of FSR1 to address data memory – value of FSR1 post-decremented (not a physical register)N/A61, 92
PREINC1Uses contents of FSR1 to address data memory – value of FSR1 pre-incremented (not a physical register)N/A61, 92
PLUSW1Uses contents of FSR1 to address data memory – value of FSR1 pre-incremented (not a physical register) –
FSR1H
FSR1LIndirect Data Memory Address Pointer 1 Low Bytexxxx xxxx61, 91
BSR
INDF2Uses contents of FSR2 to address data memory – value of FSR2 not changed (not a physical register)N/A61, 91
POSTINC2Uses contents of FSR2 to address data memory – value of FSR2 post-incremented (not a physical register)N/A61, 92
POSTDEC2 Uses contents of FSR2 to address data memory – value of FSR2 post-decremented (not a physical register)N/A61, 92
PREINC2Uses contents of FSR2 to address data memory – value of FSR2 pre-incremented (not a physical register)N/A61, 92
PLUSW2Uses contents of FSR2 to address data memory – value of FSR2 pre-incremented (not a physical register) –
FSR2H
FSR2LIndirect Data Memory Address Pointer 2 Low Bytexxxx xxxx61, 91
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
are unimplemented, read as ‘0’.
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
2
C™ Slave mode.
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
apply only to 100-pin devices.
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
values are shown for 100-pin devices.
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
are unimplemented, read as ‘0’.
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
2
C™ Slave mode.
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
apply only to 100-pin devices.
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
values are shown for 100-pin devices.
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
EPMOLPattern Match Offset Register Low Byte0000 0000 66, 251
EPMCSHPattern Match Checksum Register High Byte0000 0000 66, 251
EPMCSLPattern Match Checksum Register Low Byte0000 0000 66, 251
EPMM7Pattern Match Mask Register Byte 70000 0000 66, 251
EPMM6Pattern Match Mask Register Byte 60000 0000 66, 251
EPMM5Pattern Match Mask Register Byte 50000 0000 66, 251
EPMM4Pattern Match Mask Register Byte 40000 0000 66, 251
EPMM3Pattern Match Mask Register Byte 30000 0000 66, 251
EPMM2Pattern Match Mask Register Byte 20000 0000 66, 251
EPMM1Pattern Match Mask Register Byte 10000 0000 66, 251
EPMM0Pattern Match Mask Register Byte 00000 0000 66, 251
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
Legend: x = unknown, u = unchanged, - = unimplemented, read as ‘0’, q = value depends on condition, r = reserved bit, do not modify. Shaded cells
Note 1: Bit 7 and bit 6 are cleared by user software or by a POR.
2: Bit 21 of the PC is only available in Serial Programming modes.
3: Reset value is ‘0’ when Two-Speed Start-up is enabled and ‘1’ if disabled.
4: Alternate names and definitions for these bits when the MSSP module is operating in I
5: These bits and/or registers are only available in 100-pin devices; otherwise, they are unimplemented and read as ‘0’. Reset values shown
6: These bits and/or registers are only available in 80-pin and 100-pin devices; in 64-pin devices, they are unimplemented and read as ‘0’. Reset
7: In Microcontroller mode, the bits in this register are unwritable and read as ‘0’.
8: PLLEN is only available when either ECPLL or HSPLL Oscillator mode is selected; otherwise, read as ‘0’.
9: Implemented in 100-pin devices in Microcontroller mode only.
———MII Address Register---0 0000 66, 220
——————MIISCANMIIRD---- --00 66, 219
—MAC Non Back-to-Back Inter-Packet Gap Register High Byte-000 0000 67, 233
—MAC Non Back-to-Back Inter-Packet Gap Register Low Byte-000 0000 67, 233
The STATUS register, shown in Register 5-3, contains
the arithmetic status of the ALU. The STATUS register
can be the operand for any instruction, as with any
other register. If the STATUS register is the destination
for an instruction that affects the Z, DC, C, OV or N bits,
then the write to these five bits is disabled.
These bits are set or cleared according to the device
logic. Therefore, the result of an instruction with the
STATUS register as destination may be different than
intended. For example, CLRF STATUS will set the Z bit
but leave the other bits unchanged. The STATUS
register then reads back as ‘000u u1uu’. It is recom-
mended, therefore, that only BCF, BSF, SWAPF, MOVFF
and MOVWF instructions are used to alter the STATUS
register because these instructions do not affect the Z,
C, DC, OV or N bits in the STATUS register.
For other instructions not affecting any Status bits, see
the instruction set summaries in Table 25-2 and
Table 25-3.
Note:The C and DC bits operate as a Borrow
and Digit Borrow bit respectively, in
subtraction.
REGISTER 5-3:STATUS REGISTER
U-0U-0U-0R/W-xR/W-xR/W-xR/W-xR/W-x
———NOVZDC
bit 7bit 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
(1)
(2)
C
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 of the result) 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 non-zero
(1)
bit
(2)
bit
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
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 1: For Borrow
operand. For rotate (RRF, RLF) instructions, this bit is loaded with either bit 4 or bit 3 of the source register.
2: For Borrow
operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low-order bit of the
source register.
, the polarity is reversed. A subtraction is executed by adding the 2’s complement of the second
, the polarity is reversed. A subtraction is executed by adding the 2’s complement of the second
core PIC18 instruction set are changed
when the PIC18 extended instruction set is
enabled. See Section 5.6 “Data Memoryand 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 space can be addressed in several
ways. For most instructions, the addressing mode is
fixed. Other instructions may use up to three modes,
depending on which operands are used and whether 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. Examples include 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 mode 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 specifies either a register address in
one of the banks of data RAM (Section 5.3.3 “GeneralPurpose 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”) are used with
the address to determine the complete 12-bit address
of the register. 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 operation’s results is determined
by the destination bit, ‘d’. When ‘d’ is ‘1’, the results are
stored back in the source register, overwriting its original contents. When ‘d’ is ‘0’, the results are stored in
the W register. Instructions without the ‘d’ argument
have a destination that is implicit in the instruction.
Their destination is either the target register being
operated on or the W register.
5.4.3INDIRECT ADDRESSING
Indirect Addressing mode allows the user to access a
location in data memory without giving a fixed address
in the instruction. This is done by using File Select
Registers (FSRs) as pointers to the locations to be read
or written to. Since the FSRs are themselves located in
RAM as Special Function Registers, they can also be
directly manipulated under program control. This
makes FSRs very useful in implementing data
structures, such as tables and arrays in data memory.
The registers for Indirect Addressing are also
implemented with Indirect File Operands (INDFs) that
permit automatic manipulation of the pointer value with
auto-incrementing, auto-decrementing or offsetting
with another value. This allows for efficient code using
loops, such as the example of clearing an entire RAM
bank in Example 5-5. It also enables users to perform
indexed addressing and other Stack Pointer operations
for program memory in data memory.
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, so each
FSR pair holds a 12-bit value. This represents 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 mapped in the
FIGURE 5-9: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....
xxxx1111 11001100
ADDWF, INDF1, 1
FSR1H:FSR1L
SFR space but are not physically implemented. Reading
or writing to a particular 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 their
corresponding FSR as a pointer to the instruction’s
target. The INDF operand is just a convenient way of
using the pointer.
Because Indirect Addressing uses a full 12-bit address,
data RAM banking is not necessary. Thus, the current
contents of the BSR and Access RAM bit have no effect
on determining the target address.
000h
Bank 0
100h
Bank 1
200h
300h
07
7
0
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
FCCh. This means the contents of
location FCCh will be added to that
of the W register and stored back in
FCCh.
5.4.3.2FSR Registers and POSTINC,
POSTDEC, PREINC and PLUSW
In addition to the INDF operand, each FSR register pair
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 specific action on its stored value. They are:
• 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 -128 to 127) 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 the value 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 the 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 software stacks, inside 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 registers will
not result in successful operation. As a specific case,
assume that the FSR0H:FSR0L pair 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 INDF0 as the operand,
will result in a NOP.
On the other hand, using the virtual registers to write to
an FSR pair may not occur as planned. In these cases,
the value will be written to the FSR pair but without any
incrementing or decrementing. Thus, writing to INDF2
or POSTDEC2 will write the same value to the
FSR2H:FSR2L pair.
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. Users should exercise
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 program memory is unaffected by the
use of the extended instruction set.
Enabling the extended instruction set adds five
additional two-word commands to the existing PIC18
instruction set: ADDFSR, CALLW, MOVSF, MOVSS andSUBFSR. 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 new addressing mode for the data memory space.
This mode also alters the behavior of Indirect
Addressing using FSR2 and its associated operands.
What does not change is just as important. 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.
Enabling the PIC18 extended instruction set changes
the behavior of Indirect Addressing using the FSR2
register pair and its associated file operands. Under the
proper conditions, instructions that use the Access
Bank – that is, most bit-oriented and byte-oriented
instructions – can invoke a form of Indexed Addressing
using an offset specified in the instruction. This special
addressing mode is known as Indexed Addressing with
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 than or equal 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 Addressing) 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 half of the
standard PIC18 instruction set. Instructions that only use
Inherent or Literal Addressing modes are unaffected.
Additionally, byte-oriented and bit-oriented instructions
are not affected if they use the Access Bank (Access
RAM bit is ‘1’) or include a file address of 60h or above.
Instructions meeting these criteria will continue to
execute as before. A comparison of the different possible
addressing modes when the extended instruction set is
enabled is shown in Figure 5-10.
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”.
FIGURE 5-10: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 FFFh. This is the same as
locations F60h to FFFh
(Bank 15) of data memory.
Locations below 060h 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
100h
F00h
F40h
FFFh
000h
060h
100h
F00h
F40h
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
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 Select
000h
060h
100h
Bank 0
Bank 1
through
Bank 14
00000000
ffffffff001001da
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 part of Access RAM
(00h to 5Fh) is mapped. Rather than containing just the
contents of the bottom part 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 of FSR2 establishes the lower
boundary of the addresses mapped into the window,
while the upper boundary is defined by FSR2 plus 95
(5Fh). Addresses in the Access RAM above 5Fh are
mapped as previously described (see Section 5.3.2“Access Bank”). An example of Access Bank
remapping in this addressing mode is shown in
Figure 5-11.
Remapping of the Access Bank applies only to operations using the Indexed Literal Offset mode. Operations
that use the BSR (Access RAM bit is ‘1’) will continue
to use Direct Addressing as before. Any indirect or
indexed operation that explicitly uses any 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, will use Direct Addressing and
the normal Access Bank map.
5.6.4BSR IN INDEXED LITERAL
OFFSET MODE
Although the Access Bank is remapped when the
extended instruction set is enabled, the operation of 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-11: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 Function 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.
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 64 bytes at a time. Program memory is
erased in blocks of 1024 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.
A value written to program memory does not need to be
a valid instruction. Executing a program memory
location that forms an invalid instruction results in a
NOP.
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 space and the data 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 operations store data from the data memory
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”. Figure 6-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 table 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
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”.
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 accesses. The EECON2 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 FREE bit, when set, will allow a program memory
erase operation. When FREE is set, the erase
operation is initiated on the next WR command. When
FREE is clear, only writes are enabled.
The WREN bit, when set, will allow a write operation.
On power-up, the WREN bit is clear. The WRERR bit is
set in hardware when the WR 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.