15.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 135
17.0 CAN Module.............................................................................................................................................................................183
21.0 Low Voltage Detect .................................................................................................................................................................. 247
22.0 Special Features of the CPU......................................................................................... ...........................................................251
23.0 Instruction Set Summary.......................................................................................................................................................... 261
24.0 Development Support. .............................................................................................................................................................. 305
26.0 DC and AC Characteristics Graphs and Tables.......................................................................................................................341
Appendix D: Migrating from other PICmicro Devices................................... .... .. ......... .... .. .... ....... .... .... .. .. ......................................350
Appendix E:Development Tool Version Requirements.................................................................................................................351
Index ..................................................................................................................................................................................................353
PIC18CXX8 Product Identification System ........................................................................................................................................363
DS30475A-page 6Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers wit h the best docume ntation possible to ensure successf ul use of your Mic rochip 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@mail.m ic rochip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-
4150. We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include literature number) you are using.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
DS30475A-page 8Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
1.0DEVICE OVERVIEW
This document contains device specific information for
the following three devices:
1. PIC18C658
2. PIC18C858
The PIC18C658 is ava ilable in 64- pin TQFP and 6 8-pin
PLCC packages. The PIC18C858 is available in 80-pin
TQFP and 84-pin PLCC packages.
An overview of features is shown in Table 1-1.
The following two figures are device block diagrams
sorted by pin count; 64/68-pin for Figure 1-1 and
80/84-pin for Figure 1-2. The 64/68-pin and 80/84-pin
pinouts are listed in Table 1-2.
TABLE 1-1:DEVICE FEATURES
FeaturesPIC18C658PIC18C858
Operating FrequencyDC - 40 MHzDC - 40 MHz
Bytes32 K32 K
Program Memory Internal
Data Memory (Bytes)15361536
Interrupt sources2121
I/O PortsPorts A – GPorts A – H, J, K
Timers44
Capture/Compare/PWM modules22
Serial Communications
Parallel CommunicationsPSPPSP
10-bit Analog-to-Digital Module12 input channels16 input channels
Analog Comparators22
RESETS (and Delays)
Programmable Low Voltage DetectYesYes
Programmable Brown-out ResetYesYes
CAN ModuleY esYes
In-Circuit Serial Programming (ICSP™)YesYes
Instruction Set75 Instructions75 Instructions
Legend:TTL = TTL com pat ibl e i nput CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open Drain (no P diode to VDD)
PIC18C658PIC18C85 8
TQFP PLCC TQFP PLCCDescription
716920
—1, 22,
35, 52
39504962
40515063
43, 64
Pin
Type
I/O
Buffer
Type
I
P
——These pins should be left
IICMOS/ST
O
O
STMaster clear (RESET) input. This pin is
an active low RESET to th e device.
Programming voltage i nput
unconnected
Oscillator crystal input or external
clock source input. ST buffer when
configured in RC mode. O th er w i se
CMOS.
CMOS
—
—
TTL
External clock source input. Always
associated with pin function OSC1
(see OSC1/CLKI, OSC2/CLKO pins).
Oscillator crystal output.
Connects to crystal or resonator in
Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO,
which has 1/4 the freque ncy of OSC1
and denotes the instruct i on cycle rate
General purpose I/O pin
DS30475A-page 12Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
TABLE 1-2: PINOUT I/O DESCRIPTIONS (CONTINUED)
Pin Number
Pin Name
RA0/AN0
RA0
AN0
RA1/AN1
RA1
AN1
RA2/AN2/V
RA3/AN3/V
RA4/T0CKI
RA5/AN4/SS
RA6See the OSC2/CLKO/RA6 pin
Legend:TTL = TTL com pat ibl e i nput CMOS = CMOS compatible input or output
REF-
RA2
AN2
V
REF-
REF+
RA3
AN3
REF+
V
RA4
T0CKI
/LVDIN
RA5
AN4
SS
LVDIN
ST = Schmitt Trigger input with CMOS levels Analog = Analog input
I= Input O= Output
P= Power OD= Open Drain (no P diode to V
PIC18C658PIC18C85 8
TQFP PLCC TQFP PLCCDescription
24343042
23332941
22322840
21312739
28393447
27383346
Pin
Type
I/O
I/O
I/O
I/O
I/O
I/O
Buffer
Type
PORTA is a bi-directional I/O port
TTL
I
Analog
TTL
I
Analog
TTL
I
Analog
I
Analog
TTL
I
Analog
I
Analog
ST/OD
I
I
I
I
ST
TTL
Analog
ST
Analog
Digital I/O
Analog input 0
Digital I/O
Analog input 1
Digital I/O
Analog input 2
A/D reference voltage (L ow) in put
Digital I/O
Analog input 3
A/D reference voltage (High) input
Digital I/O – Open drain when
configured as output
Timer0 external clock input
Digital I/O
Analog input 4
SPI slave select input
Low voltage detect input
RK0——3952I/OSTDigital I/O
RK1——4053I/OSTDigital I/O
RK2——4154I/OSTDigital I/O
RK3——4255I/OSTDigital I/O
V
SS9, 25,
DD10, 26,
V
VSS20302638P—Gro und reference for analog mod ul es
A
AVDD19292537P—Positive supply for analog modules
Legend:TTL = TTL com pat ibl e i nput CMOS = CMOS compatible input or 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
PIC18C658PIC18C85 8
TQFP PLCC TQFP PLCCDescription
—
—
—
—
—
—
—
—
41, 56
38, 57
—
—
—
—
—
—
—
—
19, 36,
53, 68
2, 20,
37, 49
62
—
61
—
60
—
59
—
11, 31,
51, 70
12, 32,
48, 71
23, 44,
65, 84
2, 24,
45, 61
Pin
Type
76
—
I/OSTDigital I/O
75
—
I/OSTDigital I/O
74
—
I/OSTDigital I/O
73
—
I/OSTDigital I/O
Buffer
Type
PORTJ is a bi-directional I/O port
PORTK is a bi-directional I/O p ort
P—Ground re fe re nce for logic and I/O pins
P—Positive supply for logic and I/O pins
DD)
DS30475A-page 20Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
2.0OSCILLATOR
CONFIGURATIONS
2.1Oscillator Types
The PIC18CXX8 can be operated in one of eight oscillator modes, programmable by three configuration bits
(FOSC2, FOSC1, and FOSC0).
1. LPLow Power Crystal
2. XTCrystal/Resonator
3. HSHigh Speed Crystal/Resonator
4. HS4High Speed Crystal/Resonator with
PLL enabled
5. RCExternal Resistor/Capac ito r
6. R CIOExternal Resisto r/Capac itor wi th I/O
pin enabled
7. ECExternal Clock
8. ECIOExternal Clock with I/O pin enabled
2.2Crystal Oscillator/Ceramic
Resonators
In XT, LP, HS or HS4 (PLL) oscillator modes, a crystal
or ceramic resonator is connected to the OSC1 and
OSC2 pins to establish oscillation. Figure2-1 shows
the pin connections . An external cloc k source may also
be connected to the OSC1 pin, as shown in Figure 2-3
and Figure 2-4.
The PIC18CXX8 oscillat or desi gn requ ires th e use o f a
parallel cut crystal.
Note:Use of a series cut crystal may give a fre-
quency out of the crystal manufacturer’s
specifications.
FIGURE 2-1:CRYSTAL/CERAMIC
RESONATOR OPERATION
(HS, XT OR LP
OSC CONFIGURATION)
These values are for design guidance only. See
notes on this page.
68 - 100 pF
15 - 68 pF
15 - 68 pF
10 - 68 pF
10 - 22 pF
TBD
TBD
TBD
10 - 68 pF
TBD
68 - 100 pF
15 - 68 pF
15 - 68 pF
10 - 68 pF
10 - 22 pF
TBD
TBD
TBD
10 - 68 pF
TBD
Resonators Used:
455 kHzPanasonic EFO-A455K04B± 0.3%
2.0 MHzMurata Erie CSA2.00MG
4.0 MHzMurata Erie CSA4.00MG
8.0 MHzMurata Erie CSA8.00MT
16.0 MHzMurata Erie CSA16.00MX
All resonators used did not have built-in capacitors.
± 0.5%
± 0.5%
± 0.5%
± 0.5%
TABLE 2-2:CAPACITOR SELECTION FOR
Osc Type
CRYSTAL OSCILLATOR
Crystal
Freq
DS30475A-page 22Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
2.3RC Oscillator
For timing insensitive applications, the “RC” and
"RCIO" device options offer additional cost savings.
The RC oscillator frequency is a function of the supply
voltage, the resistor (R
EXT) and capacitor (CEXT) v al-
ues and the operating temperature. In addition to this,
the oscillator frequency will vary from unit to unit due
to normal process parameter variation. Furthermore,
the difference in lead frame capacitance between
package types will also affect the oscillation frequency ,
especially for low C
EXT values. The user also needs to
take into account variation due to tolerance of external
R and C components used. Figure 2-2 shows how the
R/C combination is connected.
In the RC oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic.
FIGURE 2-2:RC OSCILLATOR MODE
VDD
REXT
OSC1
CEXT
VSS
F
OSC/4
or I/O
Recommended values: 3 kΩ ≤ REXT≤ 100 kΩ
OSC2/CLKO/RA6
CEXT > 20pF
Internal
clock
PIC18CXX8
2.4External Clock Input
The EC and ECIO os c ill ato r m ode s req uire a n e xt erna l
clock source to be connected to the OSC1 pin. The
feedback device between OSC1 and OSC2 is turned
off in these mode s to save c urrent. The re is no os cill ator start-up time required after a Power-on Reset or
after a recovery from SLEEP mode.
In the EC oscillator mode, the oscillator frequency
divided by 4 is available on the OSC2 pin. This signal
may be used f or t e st pu r pos es or t o sy nc hr o n iz e ot he r
logic. Figure 2-3 shows the pin connecti ons for the EC
oscillator mode.
FIGURE 2-3:EXTERNAL CLOCK INPUT
OPERATION
(EC OSC CONFIGURATION)
Clock from
ext. system
F
OSC/4
The ECIO oscillator mode functions like the EC mode,
except that the OSC2 pin becomes an additional general purpose I/O pin. The I/O pin becomes bit 6 of
PORTA (RA6). Figure 2-4 shows the pin connections
for the ECIO oscillator mode.
OSC1
PIC18CXX8
OSC2
FIGURE 2-4:EXTERNAL CLOCK INPUT
OPERATION
(ECIO CONFIGURATION)
The RCIO oscillator mode functions like the RC mode,
except that the OSC2 pin becomes an additional general purpose I/O pin. The I/O pin becomes bit 6 of
PORTA (RA6).
A Phase Locked Loop circuit is provided as a programmable option for users that want to multiply the
frequency of the i nc om ing c rys tal o sc ill ato r s ig nal b y 4.
For an input clock frequency of 10 MHz, the internal
clock frequency will be multiplied to 40 MHz. This is
useful for customers who are concerned with EMI due
to high frequency crystals.
FIGURE 2-5:PLL BLOCK DIAGRAM
OSC2
Crystal
Osc
Phase
Comparator
IN
F
FOUT
The PLL can only be enabled when the oscillator configuration bits are programmed for HS mode. If they
are programmed for any other mode, the PLL is not
enabled and the system clock will come directly from
OSC1.
The PLL is one of the modes of the FOSC2:FOSC0
configuration bits . Th e o sc ill ato r mode is specified during device programming.
A PLL lock timer is used to ensure that the PLL has
locked before device execution starts. The PLL lock
timer has a time-out referred to as T
FOSC2:FOSC0 = ‘110’
Loop
Filter
PLL.
VCO
SYSCLK
OSC1
Divide by 4
MUX
DS30475A-page 24Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
2.6Oscillator Switching Feature
The PIC18CXX8 devices include a feature that allows
the system clock source to be switched from the main
oscillator t o an alternate lo w frequency clock s ource.
For the PIC18CXX8 devices, this alternate clock
source is the Timer1 oscillator. If a l ow freque ncy c rystal (32 kHz, for example) has been attached to the
Timer1 oscillator pins and the Timer1 oscillator has
been enabled, the device can switch to a low power
execution mode. Figure 2-6 shows a block diagram of
the system clock so urc es. The clock switching feature
is enabled by programming the Oscillator Switching
Enable (OSCSEN
CONFIG1H to a ’0’. Clock switching is disabled in an
erased device. See Section 9 for further details of the
Timer1 oscillator. See Section 22.0 for Configuration
Register details.
) bit in Configuration register
FIGURE 2-6:DEVICE CLOCK SOURCES
2.6.1SYSTEM CLOCK SWITCH BIT
The system clock source switching is performed under
software control. The system clock switch bit, SCS
(OSCCON register), controls the clock switching. When
the SCS bit is ’0’, the system clock source comes from
the main oscillator selected by the FOSC2:FOSC0 configuration bits. When the SCS bit is set, the system clock
source will come from the T imer1 oscilla tor . The SCS bit
is cleared on all forms of RESET.
Note:The Timer 1 oscillator mu st be enabl ed to
switch the system clock source. The
Timer1 oscillator is enabled by setting the
T1OSCEN bit in the T imer1 cont rol register
(T1CON). If the Timer1 oscillator is not
enabled, any write to the SCS bit will be
ignored (SCS bit forced cleared) and the
main oscillator will continue to be the system clock source.
REGISTER 2-1:OSCCON REGISTER
U-0U-0U-0U-0U-0U-0U-0R/W-1
———————SCS
bit 7bit 0
bit 7-1Unimplemented: Read a s '0'
bit 0SCS: System Clock Switch bit
OSCSEN configuration bit = ’0’ and T1OSCEN bit is set:
when
1 = Switch to Timer1 Oscillator/Clock pin
0 = Use primary Oscillator/Clock input pin
2.6.2OSCILLATOR TRANSITIONS
The PIC18CXX8 devices contain circuitry to prevent
"glitches" when switching between oscillator sources.
Essentially, the circuitry waits for eight rising edges of
the clock source that the processor is switching to.
This ensures that the new clock source is stable and
that its pulse width will not be less than the shortest
pulse width of the two clock sources.
A timing diagram indicating the transition from the
main oscillator to the Timer1 oscillator is shown in
The sequence of events that takes place when switching from the Timer1 oscillator to the main oscillator will
depend on the mode of the main oscillator. In addition
to eight clock cycles of the main oscillator, additional
delays may take place.
If the main oscillator is configured for an external crystal (HS, XT, LP), the transition will take place after an
oscillator start-up time (T
OST) has occurred. A timing
diagram indicating the transition from the Timer1 oscillator to the main oscillator for HS, XT and LP modes is
shown in Figure 2-8.
Figure 2-7. The Timer1 oscillator is assumed to be
running all the time. After the SCS bit is set, the processor is frozen at the next occurring Q1 cycle. After
eight synchronization cycles are counted from the
Timer1 oscillator, operation resumes. No additional
delays are required after the synchronization cycles.
FIGURE 2-7:TIMING DIAGRAM FOR TRANSITION FROM OSC1 TO TIMER1 OSCILLATOR
Q1
T1OSI
OSC1
Internal
System
Clock
SCS
(OSCCON<0>)
Program
Counter
TOSC
Q1
TDLY
TT1P
21345678
Tscs
PC + 2PC
Q3Q2Q1Q4Q3Q2
Q4Q1
Q2Q3Q4Q1
PC + 4
Note 1:Delay on internal system clock is eight oscillator cycles for synchronization.
FIGURE 2-8:TIMING DIAGRAM FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS,XT,LP)
Q3Q4
T1OSI
OSC1
OSC2
Internal System
Clock
SCS
(OSCCON<0>)
Program Counter
Note 1:TOST = 1024TOSC (drawing not to scale).
PCPC + 2
Q1
TOST
TOSC
TT1P
12345678
TSCS
Q1 Q2 Q3 Q4 Q1 Q2
Q3
PC + 4
DS30475A-page 26Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
If the main oscill ator is confi gured for HS4 (PLL) m ode,
an oscillator start-up tim e (T
time-out (T
PLL) will occur. The PLL time-out is typicall y
OST) plus an additional PLL
2 ms and allows the PLL to lock to the main oscillator
frequency. A timing diagram indicating the transition
from the Timer1 oscilla tor to the main os cillator f or HS4
mode is shown in Figure 2-9.
If the main oscillato r is co nfigure d in th e RC, R CIO, EC
or ECIO modes, t here i s no os ci lla tor st art-u p time-out.
Operation will resume after eight cycles of the main
oscillator have been counted. A t iming diagram ind icating the transition from the Timer1 oscillator to the main
oscillator for RC, RCIO, EC and ECIO modes is shown
in Figure 2-10.
FIGURE 2-9:TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS WITH PLL)
Q4Q1
T1OSI
OSC1
TOST
Internal System
Clock
(OSCCON<0>)
Program Counter
Note 1:TOST = 1024TOSC (drawing not to scale).
SCS
PCPC + 2
Q1 Q2 Q3 Q4 Q1 Q2
FIGURE 2-10: TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (RC, EC)
2.7Effects of SLEEP Mode on the
On-chip Oscillator
When the device executes a SLEEP instruction, the
on-chip clocks and oscillator are turned off and the
device is held at the beginning of an instruction cycle
(Q1 state). With th e o scill ato r off, the OSC1 and OSC2
signals will stop oscillating. Since all the transistor
switching currents have been removed, SLEEP mode
achieves the lowest current consumption of the device
(only leakage currents). Enabling any on-chi p feature
that will operate duri ng SLEEP will i ncrease th e current
consumed during SLEEP. The user can wake from
SLEEP through external RESET, Watchdog Timer
Reset or through an interrupt.
2.8Power-up Delays
Power up del ays are contr olled by t wo 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 powe r supply and clock ar e stable. For additional information on RESET operation,
see Section 3.0 RESET .
The first timer is the Power-up Timer (PWRT), which
optionally provides a fixed delay of T
#33) on power-up only (POR and BOR). The second
timer is the Osci llator Start-up T ime r (OST), intended to
keep the chip in RESET until the crystal oscillator is
stable.
With the PLL enabled (HS4 oscillator mode), the
time-out sequenc e following a Power-on Reset is diff erent from other oscil lator modes. The time-out se quence
is as follows: th e PWRT time-ou t is invoked a fter a POR
time delay has expired, then the Oscillator Start-up
Timer (OST) is invoked. However, this is still not a sufficient amount of time to allow the PLL to lock at high
frequencies. The PWRT timer is used to provide an
additional time -out. Th is ti me is called T
#7) to allow the PLL ample time to lo ck to the incom ing
clock frequency.
PWRT (parameter
PLL (parameter
TABLE 2-3:OSC1 AND OSC2 PIN STATES IN SLEEP MODE
OSC ModeOSC1 PinOSC2 Pin
RCFloating, external resistor should pull high At logic low
RCIOFloating, external resistor should pull high Configured as PORTA, bit 6
ECIOFloatingConfigured as PORTA, bit 6
ECFloatingAt logic low
LP, XT, and HSFeedback inverter disabled, at quiescent
voltage level
Note:See Table 3-1 in Section 3.0 RESET, for time-outs due to SLEEP and MCLR
Feedback inverter disabled, at quiescent
voltage level
Reset.
DS30475A-page 28Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
3.0RESET
The PIC18CXX8 differentiates between various kinds
of RESET:
a) Power-on Reset (POR)
b) MCLR
c) MCLR
d) Watchdog Timer (WDT) Reset (during normal
Most registers are unaff ected by a RESET. Their status
is unknown on POR and unchanged by all other
RESETs. The other registers are forced to a “RESET”
Reset during normal operation
Reset during SLEEP
operation)
state on Power-on Reset, MCLR
Brown-out Reset, MCLR
Reset during SLEEP and by
the RESET instruction.
Most registers are not affected by a WDT wake-up,
since this is viewed as the resumption of normal operation. Status bits from the RCON register, RI
and BOR are set or cleared differently in different
POR
RESET situations, as indicated i n Table 3-2. These bits
are used in software to determine the nature of the
RESET. See Table 3-3 for a full description of the
RESET states of all registers.
A simplified block diagram of the on-chip RESET circuit
is shown in Figure 3-1.
The Enhanced MCU devices have a MCLR
in the MCLR
Reset path. The filter will detect and
ignore small pulses.
A WDT Reset does not drive MCLR
FIGURE 3-1:SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
RESET
Instruction
Stack
Pointer
Stack Full/Underflow Reset
External Reset
, WDT Reset,
, TO, PD,
noise filter
pin low.
MCLR
WDT
Module
DD Rise
V
Detect
VDD
Brown-out
Reset
OST/PWRT
OST
OSC1
On-chip
RC OSC
Note 1: This is a separate oscillator from the RC oscillator of the CLKI pin.
A Power-on Reset pulse is generated on-chip when a
V
DD rise is detected. To take advan tage of th e POR cir-
cuitry, connect the MCLR
resistor) to V
DD. This will eliminate ext ernal RC compo-
pin directly (or through a
nents usually needed to create a Power-on Reset
delay . A minimum ris e rate for VDD is specified (parameter D004). For a slow rise time, see Figure 3-2.
When the device starts normal operation (exits the
RESET condition), device operating parameters (voltage, frequency, temperature,...) must be m et to en su re
operation. If these cond itions are not met, the d evice
must be held in RESET until the operating conditions
are met. Brown-out Reset may be used to meet the
voltage start-up condition.
FIGURE 3-2:EXTERNAL POWER-ON
RESET CIRCUIT (FOR SLOW
DD POWER-UP)
V
DD
V
D
R
R1
MCLR
C
Note 1: External Power-on Reset circuit is required
only if the V
DD power-up slope is too slow.
The diode D hel ps d isch arge th e ca pacito r
quickly when V
DD powers down.
2: R < 40 kΩ is recommended to make sure
that the voltage drop across R does not
violate the device’s electrical specification.
3: R1 = 100Ω to 1 kΩ will limit any current
flowing into MCLR
C in the even t of MCLR/
down due to Electrostatic Discharge
(ESD) or Electrical Overstress (EOS).
PIC18CXX8
from external capacitor
VPP pin break-
3.2Power-up Timer (PWRT)
The Power-up Timer provides a fixed nominal time-out
(parameter #33), only on power-up from the POR. The
Power-up Timer operates on an internal RC oscillator.
The chip is kept in RESET as long as the PWRT is
active. The PWRT ’s time delay allows V
acceptable level. A configuration bit (PWRTEN
DD to rise to an
in
CONFIG2L register) is provided to enable/disable the
PWRT.
The power-up time dela y will vary f rom chip to c hip due
DD, temperature and process variation. See DC
to V
parameter #33 for details.
3.3Oscillator Start-up Timer (OST)
The Oscillator Start-up Timer (OST) provides 1024
oscillator cycle (from OSC1 input) delay after the
PWRT delay is over (parameter #32). This ensures that
the crystal oscilla tor or res onator has started an d stabilized.
The OST time-out is invoked only for XT, LP, HS and
HS4 modes and only on Power-on Reset or wake-up
from SLEEP.
3.4PLL Lock Time-out
With the PLL enabled, the time-ou t sequen ce foll owin g
a Power-on Reset is different from other oscillator
modes. A portion of the Pow er-up T imer is used to provide a fixed time-out th at is suff icient for the PLL to lock
to the main oscillato r frequency. This PLL lock time-out
PLL) is typically 2 ms and follows the oscillator
(T
start-up time-out (OST).
3.5Brown-out Reset (BOR)
A configuration bit, BOREN, can disable (if
clear/programmed) or enable (if set) the Brown-out
Reset circuitry. If VDD falls below parameter D005 for
greater than parameter #35, the brown-out situation
resets the chip. A RESET may not occur if VDD falls
below parameter D005 for less than parameter #35.
The chip will remain in Bro wn-out Re set unt il V
above BV
DD. The Power-up T im er w ill th en be invoked
and will keep the chip in RESET an additional time
delay (parameter #33). If V
DD drops below BVDD while
the Power-up Timer is running, the chip will go back
into a Brown-out Reset and the Power-up Timer will be
initialized . Once V
DD rises above BVDD, the Power-up
Timer will execute the additional time delay.
DD rises
DS30475A-page 30Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
3.6Time-out Sequence
On power-up, the time-out sequence is as follows:
First, PWRT time-out is invoked after the POR time
delay has expired, then OST is activated. The total
time-out will vary based on oscillator configuration and
the status of the PWRT. For example, in RC mode with
the PWRT disabled, there will be no time-out at all.
Figure 3-3, Figure 3-4, Figure 3-5, Figure 3-6 and
Figure 3-7 depict time-out sequences on power-up.
Since the time-outs oc cur from the POR pulse, if MCLR
is kept low long enough, the time-outs will expire.
Bringing MCLR
(Figure 3-5). This is useful for testing purposes or to
synchronize more th an one PIC18C XX8 device opera ting in para llel.
Table 3-2 shows the RESET conditions for some Special Function Registers, while Table 3-3 shows the
RESET conditions for all registers.
high will begin execution immediately
TABLE 3-1:TIME-OUT IN VARIOUS SITUATIONS
Oscillator
Configuration
HS with PLL enabled
HS, XT, LP72 ms + 1024Tosc1024Tosc72 ms + 1024Tosc1024Tosc
EC72 ms—72 ms—
External RC72 ms—72 ms—
Note 1: 2 ms = Nominal time required for the 4X PLL to lock.
2: 72 ms is the nominal power-up timer delay.
(1)
PWRTE
72 ms + 1024Tosc + 2 ms 1024Tosc + 2 ms 72 ms + 1024Tosc + 2 ms 1 02 4Tosc + 2 ms
Power-up
N = 0PWRTEN = 1
(2)
Brown-out
(2)
Wake-up from
SLEEP or
Oscillator Switch
REGISTER 3-1:RCON REGISTER BITS AND POSITIONS
R/W-0R/W-0U-0R/W-1R/W-1R/W-1R/W-1R/W-1
IPENLWRT
bit 7bit 0
—RITOPDPORBOR
TABLE 3-2:STATUS BITS, THEIR SIGNIFICANCE AND THE INITIALIZATION CONDITION FOR
RCON REGISTER
Condition
Power-on Reset0000h00-1 110011100uu
Reset during normal
MCLR
operation
Software Reset during normal
operation
Stack Full Reset during normal
operation
Stack Underflow Reset during
normal operation
MCLR
Reset during SLEEP0000h00-u 10uuu10uuuu
WDT Reset0000h0u-u 01uuu01uuuu
WDT Wake-upPC + 2uu-u 00uuu00uuuu
Brown-out Reset0000h0u-1 11u0111u0uu
Interrupt wake-up from SLEEPPC + 2
Legend: u = unchanged, x = unknown,- = unimplemented bit, read as '0'
Note 1: When the wake-up is due to an interrupt and the GIEH or GIEL bits are set, the PC is loaded with the
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Power-on Reset,
Brown-out Reset
WDT Reset
RESET Instruction
Stack Resets
.
Wake-up via WDT
or Interrupt
(3)
(3)
(3)
(3)
(2)
(1)
(1)
(1)
DS30475A-page 34Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
TABLE 3-3:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as ’0’, q = value depends on condition
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Applicable
Devices
658858-111 1111-111 1111-uuu uuuu
658858-000 0000-000 0000-uuu uuuu
658858-000 0000-000 0000-uuu uuuu
Power-on Reset,
Brown-out Reset
WDT Reset
RESET Instruction
Stack Resets
.
Wake-up via WDT
or Interrupt
(1)
(1)
(1)
DS30475A-page 36Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
TABLE 3-3:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Applicable
Devices
Power-on Reset,
Brown-out Reset
WDT Reset
RESET Instruction
Stack Resets
.
Wake-up via WDT
or Interrupt
DS30475A-page 38Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
TABLE 3-3:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an inte rrup t and th e GIEL or GIEH bit is set, the PC is loaded with the interrupt
vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the hardware
stack.
4: See Table 3-2 for RESET value for specific condition.
5: Bit 6 of PORTA, LATA, and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other
oscillator modes, they are disabled and read ’0’.
6: The long write enable is only reset on a POR or MCLR
7: Available on PIC18C858 only.
Applicable
Devices
Power-on Reset,
Brown-out Reset
WDT Reset
RESET Instruction
Stack Resets
.
Wake-up via WDT
or Interrupt
DS30475A-page 40Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
4.0MEMORY ORGANIZATION
There are two memory blocks in Enhanced MCU
devices. These memory blocks are:
• Program Memory
• Data Memory
Each block has its own bus so that concurrent access
can occur.
4.1Program Memory Organization
The PIC18CXX8 devices have a 21-bit program
counter that is capable of addressing the 2 Mbyte
program memory space.
The reset vector address is at 0000h and the interrupt
vector addresses are at 0008h and 0018h. Figure 4-1
shows the diag ram for program memory map and stack
for the PIC18C658 and PIC18C858.
4.1.1INTERNAL PROGRAM MEMORY
OPERATION
All devices have 32 Kbytes of internal EPROM program
memory. This means that the PIC18CXX 8 de vi ces ca n
store up to 16 K of si ngle wo rd ins tructi ons. Ac cessi ng
a location between the physically implemented memory and the 2 Mbyt e addre ss will c ause a rea d of all '0' s
(a NOP instruction) .
FIGURE 4-1:PROGRAM MEMORY MAP
AND STACK FOR
PIC18C658/858
PC<20:0>
Stack Level 1
Stack Level 31
RESET Vector
High Priority Interrupt Vector
Low Priori ty Interrupt Vector
The return address stack allows any combination of up
to 31 program calls and interrupts to occur. The PC
(Program Counter) is pu shed onto the stack when a
PUSH, 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 instruc-
tion. PCLATU and PCLATH are not affected by any of
the return instructions.
The stack operates as a 31 word by 21-bit stack memory and a 5-bit stack pointer, with the stack pointer initialized to 00000b after all RESETs. There is no RAM
associated with stack pointer 00000b. This is only a
RESET value. During a CALL type instruction caus ing
a push onto the stack, the stack pointer is first incremented and the RAM location pointed to by the stack
pointer is written with the contents of the PC. During a
RETURN type instruction causing a pop from the stack,
the contents of the RAM location indicated by the
STKPTR is transferred to the PC and then the stack
pointer is decremented.
The stack space is not part of either program or data
space. The stack pointer is readable and writable, and
the data on the top of the s tack is readab le and writabl e
through SFR registers. Status bits indicate if the stack
pointer is at or beyond the 31 levels provided.
4.2.1TOP-OF-STACK ACCESS
The top of the stack is readable and writable. Three
register locations, TOSU, TOSH and TOSL allow
access to the contents of the stack lo cation indi cated
by the STKPTR register. This allows users to implement a software stack if necessary. After a CALL,RCALL or interrupt, the software can read the pushed
value by reading the TOSU, TO SH and TOSL regis ters.
These values can b e placed on a user define d software
stack. At return time, the software can replace the
TOSU, TOSH and TOSL and do a return.
The user should disable the global interru pt enable bit s
during this time to prevent inadvertent stack operations.
4.2.2RETURN STACK POINTER (STKPTR)
The STKPTR register c onta in s th e st ack po inter value,
the STKFUL (stack full) status bit, and the STKUNF
(stack underflow) status bits. Register 4-1 shows the
STKPTR register . The value of the stack point er can be
0 through 31. The stack pointer increments when values are pushed onto the stack and decrements when
values are popped off the stack. At RESET, the stack
pointer value will be 0. The user may read and write the
stack pointer value. T his feature can be u sed by a Rea l
Time Operating Sy stem for return stack maintenance.
After the PC is pushed onto the stack 31 times (witho ut
popping any values off the stack), the STKFUL bit is
set. The STKFUL bit can on ly be cleared in so ftware 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
18 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, an d
reset the device. The STKFUL bit will remain set and
the stack pointer will be set to 0.
If STVREN is cleared, the STKFUL bit will be set on the
31st push and the stack pointer will increment to 31.
The 32nd push will overwrite th e 31st push (and so on),
while STKPTR remains at 31.
When the stack has been popped enough times to
unload the stack, t he next pop will retu rn a value of zero
to the PC and sets the STKUNF bit, while the stack
pointer remains at 0. The STKUNF bit will remain set
until cleared in software or 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 condition s can be ve rified and app ropriate actions can be taken.
DS30475A-page 42Advanced Information 2000 Microchip Technology Inc.
REGISTER 4-1:STKPTR - STACK POINTER REGISTER
R/C-0R/C-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0
STKFULSTKUNF—SP4SP3SP2SP1SP0
bit 7bit 0
bit 7STKFUL: Stack Full Flag bit
1 = Stack became full or overflowed
0 = Stack has not become full or overflowed
bit 6STKUNF: Stack Underflow Flag bit
1 = Stack underflow occurred
0 = Stack underflow did not occur
bit 5Unimplemented: Read as '0'
bit 4-0SP4:SP0: Stack Pointer Location bits
Note:Bit 7 and bit 6 can only be cleared in user software or by a POR.
Legend
= Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
R
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedC = Clearable bit
PIC18CXX8
FIGURE 4-2:RETURN ADDRESS STACK AND ASSOCIATED REGISTERS
Return Address Stack
11111
11110
TOSLTOSHTOSU
0x340x1A0x00
Top-of-Stack
Note 1: No RAM associated with this address; always maintained ‘0’s.
4.2.3PUSH AND POP INSTRUCTIONS
Since the Top-of-Stack (TOS) is readable and writ able,
the ability to push values on to the stac k and pull values
off the stack without disturbing normal program execution is a desirable opt ion. To push the curren t PC value
onto the stack, a PUSH instruction can be executed.
This will increment the stack pointer and load the current PC value onto the stack. TOSU, TOSH and TOSL
can then be modified to place a return address on 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.
4.2.4STACK FULL/UNDERFLOW RESETS
These RESETs are enabled by programming the
STVREN configuration bit. When the STVREN bit is
disabled, a full or underf low condition will set the appropriate STKFUL or STKUNF bit, but not cause a device
RESET. When the STVREN bit is enabled, a full or
underflow will set the appro priate STKF UL or STKUNF
bit and then cause a device RESET. The STKFUL or
STKUNF bits are only cleared by the user software or
a POR.
4.3Fast Register Stack
A “fast return” option is available for interrupts and
calls. A fast register stack is provided for the STATUS,
WREG and BSR registers and is only one layer in
depth. The stack is not readable or writable and is
loaded with the curre nt value o f the co rrespon ding re gister when the processor vectors for an interrupt. The
values in the fast register stack are then loaded back
into the working registers if the fast return instruction is used to return from the interrupt.
A low or high priority interrupt source will push values
into the stack registers. If both low and high priority
interrupts are enabled, the stack registers cannot be
used reliably for low priority interrupts. If a high priority
interrupt occurs while servicing a low priority interrupt,
the stack register values sto red by the low priority interrupt will be overwritten.
If high priority interrupts are not disabled during low priority interrupts, users must save the key registers in
software during a low priority interrupt.
If no interrupts are used, the fast register stack can be
used to restore the STATU S, WREG and BSR registers
at the end of a subroutine call. To use the fast register
stack for a subroutine call, a fast call instruction
must be executed.
Example 4-1 sho ws a source code exam ple that uses
the fast register stack.
EXAMPLE 4-1:FAST REGISTER STACK
CODE EXAMPLE
CALL SUB1, FAST;STATUS, WREG, BSR
;SAVED IN FAST REGISTER
•
•
SUB1•
•
•
RETURN FAST;RESTORE VALUES SAVED
;STACK
;IN FAST REGISTER STACK
DS30475A-page 44Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
4.4PCL, PCLATH and PCLATU
The program counter (PC) specifies the address of the
instruction to fetch for execution. The PC is 21-bits
wide. The low byte is called the PCL register. This register is readable and writable. The high byte is called
the PCH register. This register contains the PC<15:8>
bits and is not directly readable or writable. Updates to
the PCH register may be performed through the
PCLATH register. The upper byte is called PCU. This
register contains the PC<20 :16> bi ts and i s not d irectl y
readable or writable. Updates to the PCU register may
be performed through the PCLATU register.
The PC addresses bytes in the program memory. To
prevent the PC from becoming misaligned with word
instructions, the LSb 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.
FIGURE 4-3:CLOCK/INSTRUCTION CYCLE
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(RC mode)
Q1
PC
Fetch INST (PC)
Execute INST (PC-2)Fetch INS T (PC +2)
Q1
Execute INST (PC)Fetch INST (PC+4)
The contents of PCLATH and PCLATU will be transferred to the program counter by an operation that
writes PCL. Similarly, the upper two bytes of the program counter will be transferred to PCLATH and
PCLATU by an operation that reads PCL. This is useful
for computed offsets to the PC (See Section 4.8.1).
4.5Clocking Scheme/Instruction Cycle
The clock input (from OSC1) is internally divided by
four to generate four non-overlapping quadrature
clocks, namely Q1, Q2, Q3 and Q4. Internally, the program counter (PC) is incremented every Q1, the
instruction is fetched from the program memory and
latched into the instruction register in Q4. The instruction is decoded and executed during the following Q1
through Q4. The clocks and instruction execution flow
are shown in Figure 4-3.
An “Instruction Cycle” consists of four Q cycles (Q1,
Q2, Q3 and Q4). The instruc ti on fe tch and execute are
pipelined such that fetch takes one instruction cycle
while decode and execute takes 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),
two cycles are required to complete the instruction
(Example 4-2).
A fetch cycle begins with the program counter (PC)
incrementing in Q1.
In the execution cy cle, the fetc hed instructi on is latche d
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).
EXAMPLE 4-2: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
Fetch 1Execute 1
Fetch 2Execute 2
Fetch 3Execute 3
4.7Instructions in Program Memory
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’). Figure 4-1 shows an
example of how instruct ion words are stored in the p rogram memory. To maintain alignment with instruction
boundaries, the PC increments in steps of 2 and the
LSB will always read ’0’ (See Section 4.4).
The CALL and GOTO instructions have an 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 4-1 shows how the
instruction “GOTO 000006h” is encoded in the program
memory . Program branch instructions that encode a relative address offset operate in the same manner. The
offset value stored in a b ranch instruction represents the
number of single word instructions by which the PC will
be offset. Section 23.0 provides further details of the
instruction set.
Fetch 4Flush
Fetch SUB_1 Execute 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.
TABLE 4-1:INSTRUCTIONS IN PROGRAM MEMORY
InstructionOpcodeMemoryAddress
—000007h
MOVLW 055h0E55h55h000008h
0Eh000009h
GOTO 000006hEF03h, F000h03h00000Ah
EFh00000Bh
00h00000Ch
F0h00000Dh
MOVFF 123h, 456hC123h, F456h23h00000Eh
C1h00000Fh
56h000010h
F4h000011h
—000012h
DS30475A-page 46Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
4.7.1TWO WORD INSTRUCTIONS
The PIC18CXX8 devi ces h ave 4 two word ins tructi ons:
MOVFF, CALL, GOTO and LFSR. The second w ord of
these instructions has the 4 MSB’s set to 1’s and is a
special kind of NOP instruction. The lower 12 bits of the
second word contain da ta to be used by the ins truction.
If the first word of the instruction is executed, the data
in the second word is accessed. If the second word of
the instruction is executed by itself (first word was
skipped), it will execute as a NOP. This action is neces-
sary when the two word instruction is preceded by a
conditional instruct ion that changes the PC. A program
example that demonstrates this concept is shown in
Example 4-3. Refer to Section 19.0 for further de tails of
the instruction set.
4.8Lookup Tables
Lookup tables are implemented two ways. These are:
• Computed GOTO
• Table Reads
4.8.1COMPUTED GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL).
A lookup table can be formed with an ADDWF PCL
instruction and a group of RETLW 0xnn instructions.
WREG is loaded with an offset into the table befor e 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 0xnn instructions that returns the value 0xnn to the calling fun ction .
The offset v alue (val ue in WR EG) speci fies the number
of bytes that the program counter should advance.
In this method, only one data byte may be stored in
each instruction location and room on the return
address stack is required.
Warning:The LSb of PCL is fixed to a value of ‘0’.
Hence, computed GOTO to an odd
address is not possible.
4.8.2TABLE READS/TABLE WRITES
A better method of storing data in program memory
allows 2 byte s of data to be stored in each inst ruction
location.
Lookup table data may be stored as 2 bytes per program word by using table reads and writes. The table
pointer (TBLPTR) specifies the byte address and the
table latch (TABLAT) contains the data that is read
from, or written to, program memory. Data is transferred to/from program memory one byte at a time.
A description of the Table Read/Table Write operation
is shown in Section 5.0.
The data memory is impl eme nted as static RAM. Each
register in the data memory has a 12-bit address,
allowing up to 4096 bytes of data memory. Figure 4-4
shows the data memory organization for the
PIC18CXX8 devices.
The data memory map is divided into as many as 16
banks that contain 256 bytes each. The lower 4 bits of
the Bank Select Register (BSR<3:0>) select which
bank will be accessed. The upper 4 bits for the BSR are
not implemented.
The data memory contains Special Function Registers
(SFR) and General Purpose Registers (GPR). The
SFR’s are used for control and status of the controller
and peripheral fu nctions, whi le GPR’s are used for data
storage and scratch pad operations in the user’s application. The SFR’s start at the last location of Bank 15
(0xFFF) and grow downwards. GPR’s start at the first
location of Bank 0 and grow up wards. Any read of an
unimplemented location will read as ’0’s.
The entire data memory may be accessed directly or
indirectly. Direct addressing may require the use of th e
BSR register. Indirect addressing requires the use of
the File Select Register (FSR). Each FSR holds a
12-bit address value that can be used to access any
location in the Data Memory map without banking.
The instruction set and architecture allow operations
across all banks. This m ay be accompli shed by indirec t
addressing or by the use of th e MOVFF instruction. The
MOVFF instruction is a two word/two cycl e instruction
that moves a value from one register to another.
To ensure that commonly used registers (SFR’s and
select GPR’s) can be accessed in a single cycle,
regardless of the current BSR values, an Access Bank
is implemented. A s egment of Ban k 0 and a segm ent of
Bank 15 comprise the Access RAM. Section 4.10 provides a detailed description of the Access RAM.
4.9.1GENERAL PURPOSE REGISTER FILE
The register file can b e access ed eithe r dire ctly o r indi-
rectly. Indirect addressing operates through the File
Select Registers (FSR). The operation of indirect
addressing is shown in Section 4.12.
Enhanced MCU devices may have banked memory in
the GPR area. GPR’s are not initialized by a Power-on
Reset and are unchanged on all other RESETS.
Data RAM is available for use as GPR registers by all
instructions. Bank 15 (0xF00 to 0xFFF) contains
SFR’s. All other banks of data memory contain GPR
registers starting with bank 0.
4.9.2SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFR’s) are registers
used by the CPU and Peripheral Modules for controlling the desired operation of the device. These registers are implemented as static RAM. A list of these
registers is given in Table 4-2.
The SFR’s can be classified into two sets: those associated with the “core” function and those related to the
peripheral functions. Those registers related to the
“core” are described in this s ec tio n, w hil e tho se rel ate d
to the operation of the peripheral features are
described in the section of that periphe ral feature.
The SFR’s are typically di stributed among the per ipherals whose functions they control.
The unused SFR locations will be unimplemented and
read as '0's. See Table 4-2 for addresses for the SFR’s.
DS30475A-page 48Advanced Information 2000 Microchip Technology Inc.
FIGURE 4-4:DATA MEMORY MAP FOR PIC18C658/858
PIC18CXX8
BSR<3:0>
= 0000b
= 0001b
= 0010b
= 0011b
= 0100b
= 0101b
= 0110b
= 1110b
= 1111b
Bank 0
Bank 1
Bank 2
Bank 3
Bank 4
Bank 5
Bank 6
to
Bank 14
Bank 15
Data Memory Map
00h
Access GPR’s
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
GPR’s
GPR’s
GPR’s
GPR’s
GPR’s
GPR’s
Unused
Read ’00h’
SFR’s
Access SFR’s
000h
05Fh
060h
0FFh
100h
1FFh
200h
2FFh
300h
3FFh
400h
4FFh
500h
5FFh
600h
EFFh
F00h
F5Fh
F60h
FFFh
Access Bank
Access Bank low
(GPR’s)
Access Bank high
(SFR’s)
When a = 0,
the BSR is ignored and the
Access Bank is used.
The first 96 bytes are General Purpose RAM (from
Bank 0).
The next 160 bytes are
Special Function R egisters
(from Bank 15).
00h
5Fh
60h
FFh
When a = 1,
the BSR is used to specify
the RAM location that the
instruction uses.
2: This is not a physical register.
3: Contents of register is dependent on WIN2:WIN0 bits in CANCON register.
4: CANSTAT regi ste r is repeated in these locations t o si mplify application firmware. Uniqu e nam es are given
for each instance of the CANSTAT register due to the Microchip Header file requirement.
5: Available on PIC18C858 only.
DS30475A-page 50Advanced Information 2000 Microchip Technology Inc.
Note:Shaded registers are available in Bank 15, while the rest are in Access Bank low.
Note 1: Unimplemented registers are read as ’0’.
2: This is not a physical register.
3: Contents of register is dependent on WIN2:WIN0 bits in CANCON register.
4: CANSTAT registe r is repea ted in the se loc ations to simp lify app licat ion firm ware. Un ique nam es are g iven
for each instance of the CANSTAT register due to the Microchip Header file requirement.
TBLPTRHProgram Memory Table Pointer High Byte (TBLPTR<15:8>)0000 0000 0000 0000
TBLPTRLProgram Memory Table Pointer Low Byte (TBLPTR<7:0>)0000 0000 0000 0000
TABLATProgram Memory Table Latch0000 0000 0000 0000
PRODHProduct Register High Bytexxxx xxxx uuuu uuuu
PRODLProduct Register Low Bytexxxx xxxx uuuu uuuu
INTCONGIE/GIEHPEIE/GIELTMR0IEINT0IERBIETMR0IFINT0IFRBIF0000 000x 0000 000u
INTCON2RBPU
INTCON3INT2IPINT1IPINT3IEINT2IEINT1IEINT3IFINT2IFINT1IF1100 0000 1100 0000
INDF0Uses contents of FSR0 to address data memory - value of FSR0 not changed (not a physical register)n/an/a
POSTINC0 Uses contents of FSR0 to address data memory - value of FSR0 post-incremented (not a physical register)n/an/a
POSTDEC0 Uses contents of FSR0 to address data memory - value of FSR0 post-decremented (not a physical register)n/an/a
PREINC0Uses contents of FSR0 to address data memory - value of FSR0 pre-incremented (not a physical register)n/an/a
PLUSW0Uses contents of FSR0 to address data memory - value of FSR0 pre-incremented (not a physical register) - value
WREGWorking Registerxxxx xxxx uuuu uuuu
INDF1Uses contents of FSR1 to address data memory - value of FSR1 not changed (not a physical register)n/an/a
POSTINC1 Uses contents of FSR1 to address data memory - value of FSR1 post-incremented (not a physical register)n/an/a
POSTDEC1 Uses contents of FSR1 to address data memory - value of FSR1 post-decremented (not a physical register)n/an/a
PREINC1Uses contents of FSR1 to address data memory - value of FSR1 pre-incremented (not a physical register)n/an/a
PLUSW1Uses contents of FSR1 to address data memory - value of FSR1 pre-incremented (not a physical register) - value
BSR
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
Holding Register for PC<20: 16>--00 0000 --00 0000
(2)
Program Memory Table Pointer Upper Byte (TBLPTR<20:16>)---0 0000 ---0 0000
Indirect Data Memory Address Pointer 0 High---- 0000 ---- 0000
Indirect Data Memory Address Pointer 1 High---- 0000 ---- 0000
Bank Select Register---- 0000 ---- 0000
and Watchdog Timer Reset.
Value on
POR,
BOR
n/an/a
n/an/a
Value on
all other
RESETS
(3)
DS30475A-page 52Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
FilenameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
INDF2Uses contents of FSR2 to address data memory - value of FSR2 not changed (not a physical register)n/an/a
POSTINC2 Uses contents of FSR2 to address data memory - value of FSR2 post-incremented (not a physical register)n/an/a
POSTDEC2 Uses contents of FSR2 to address data memory - value of FSR2 post-decremented (not a physical register)n/an/a
PREINC2Uses contents of FSR2 to address data memory - value of FSR2 pre-incremented (not a physical register)n/an/a
PLUSW2Uses contents of FSR2 to address data memory - value of FSR2 pre-incremented (not a physical register) - value
SSPBUFSSP Receive Buffer/Transmit Registerxxxx xxxx uuuu uuuu
SSPADDSSP Address Register in I
SSPSTATSMPCKED/A
SSPCON1WCOLSSPOVSSPENCKPSSPM3SSPM2SSPM1SSPM00000 0000 0000 0000
SSPCON2GCENACKSTATACKDTACKENRCENPENRSENSEN0000 0000 0000 0000
ADRESHA/D Result Register High Bytexxxx xxxx uuuu uuuu
ADRESLA/D Result Register Low Bytexxxx xxxx uuuu uuuu
ADCON0
ADCON1
ADCON2ADFM
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
of FSR2 offset by WREG
————
———
Indirect Data Memory Address Pointer 2 High---- 0000 ---- 0000
C Slave mode. SSP Baud Rate Reload Register in I2C Master mode.0000 0000 0000 0000
CHS3CHS2CHS1CHS0GO/DONEADON--00 0000 --00 0000
VCFG1VCFG0PCFG3PCFG2PCFG1PCFG0-000 0000 -000 0000
————
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
TRISFData Direction Control Register for PORTF1111 1111 1111 1111
TRISEData Direction Control Register for PORTE1111 1111 1111 1111
TRISDData Direction Control Register for PORTD1111 1111 1111 1111
TRISCData Direction Control Register for PORTC1111 1111 1111 1111
TRISBData Direction Control Register for PORTB1111 1111 1111 1111
TRISA
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
——
——
—
—
—
Data Direction Control Register for PORTJ1111 1111 1111 1111
Data Direction Control Register for PORTH1111 1111 1111 1111
DS30475A-page 54Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
(4)
LATJ
LATH
LATG
LATFRead PORTF Data Latch, Write PORTF Data Latchxxxx xxxx uuuu uuuu
LATERead PORTE Data Latch, Write PORTE Data Latchxxxx xxxx uuuu uuuu
LATDRead PORTD Data Latch, Write PORTD Data Latchxxxx xxxx uuuu uuuu
LATCRead PORTC Data Latch, Write PORTC Data Latchxxxx xxxx uuuu uuuu
LATBRead PORTB Data Latch, Write PORTB Data Latchxxxx xxxx uuuu uuuu
LATA
PORTJ
PORTH
PORTG
PORTFRead PORTF pins, Write PORTF Data Latch0000 0000 0000 0000
PORTERead PORTE pins, Write PORTE Data Latchxxxx xxxx uuuu uuuu
PORTDRead PORTD pins, Write PORTD Data Latchxxxx xxxx uuuu uuuu
PORTCRead PORTC pins, Write PORTC Data Latchxxxx xxxx uuuu uuuu
PORTBRead PORTB pins, Write PORTB Data Latchxxxx xxxx uuuu uuuu
PORTA
TRISK
LATK
PORTK
Read PORTJ Data Latch, Write PORTJ Data Latchxxxx xxxx uuuu uuuu
(4)
Read PORTH Data Latch, Write PORTH Data Latchxxxx xxxx uuuu uuuu
———
(1)
—
(4)
Read PORTJ pins, Write PORTJ Data Latchxxxx xxxx uuuu uuuu
(4)
Read PORTH pins, Write PORTH Data Latchxxxx xxxx uuuu uuuu
Bit 6
Read PORTA Data Latch, Write PORTA Data Latch--xx xxxx --uu uuuu
———
(1)
—Bit 6
(4)
Data Direction Control Register for PORTK1111 1111 1111 1111
(4)
Read PORTK Data Latch, Write PORTK Data Latchxxxx xxxx uuuu uuuu
(4)
Read PORTK pins, Write PORTK Data Latchxxxx xxxx uuuu uuuu
Read PORTA pins, Write PORTA Data Latch--0x 0000 --0u 0000
Read PORTG Data Latch, Write PORTG Data Latch---x xxxx ---u uuuu
Read PORTG pins, Write PORTG Data Latch---x xxxx uuuu uuuu
CANSTATOPMODE2 OPMODE1OPMODE0
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
CANSTATOPMODE2 OPMODE1OPMODE0
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
RXF3SIDH
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
TXRTR
——
—
TXABTTXLARBTXERRTXREQ
———
———
—
—
—
DLC3DLC2DLC1DLC0
EXIDEN
—
—
EXIDEN
EXIDEN
EXIDEN
—
—
—
and Watchdog Timer Reset.
EID17EID16
TXPRI1TXPRI0
EID17EID16
EID17EID16
EID17EID16
EID17EID16
EID17EID16
Value on
POR,
BOR
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
0x00 xxxx 0u00 uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx0 x0xx uuu0 u0uu
xxxx xxxx uuuu uuuu
0000 0000 0000 0000
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx- --xx uuu- --uu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx- --xx uuu- --uu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx- x-xx uuu- u-uu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx- x-xx uuu- u-uu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxx- x-xx uuu- u-uu
xxxx xxxx uuuu uuuu
Value on
all other
RESETS
(3)
DS30475A-page 58Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
FilenameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
RXF2EID0
RXF2EID8
RXF2SIDL
RXF2SIDH
RXF1EIDL
RXF1EIDH
RXF1SIDL
RXF1SIDH
RXF0EIDL
RXF0EIDH
RXF0SIDL
RXF0SIDH
Legend:x = unknown, u = unchanged, - = unimplemented, q = value depends on condition
Note 1: Bit 6 of PORTA, L ATA and TRISA are enabled in ECIO and RCIO oscillator modes only. In all other oscillator modes, they are disabled and read ‘0’.
2: Bit 21 of the TBLPTRU allows access to the device configuration bits.
3: Other (non-power-up) RESETs include external RESET through MCLR
4: These registers are reserved on PIC18C658.
The Access Bank is an arch itectural e nhanc ement th at
is very useful for C compiler code optimization. The
techniques used by the C compiler are also be useful
for programs written in assembly.
This data memory region can be used for:
• Intermediate computational values
• Local variables of subroutines
• Faster context saving/switching of variables
• Common variables
• Faster evaluation/control of SFR’s (no banking)
The Access Bank is comprised of the upper 160 bytes
in Bank 15 ( SFR’s) and the lower 96 bytes in Bank 0.
These two sections will be referred to as Access Bank
High and Access Bank Low, respectively. Figure 4-4
indicates the Access Bank areas.
A bit in the instruction word spec ifie s if the opera tion is
to occur in the bank s pecified by t he BSR register, or in
the Access Bank.
When forced in the Access Bank (a = ’0’), the last
address in Access Bank Low is followed by the first
address in Access Bank High. Access Bank High maps
most of the Special Function Registers so that these
registers can be accessed without any software overhead.
4.11Bank Select Register (BSR)
The need for a large general purpose memory space
dictates a RAM banking scheme. The data memory is
partitioned into sixteen banks. When using direct
addressing, the BSR should be configured for the
desired bank.
BSR<3:0> holds the upper 4 bits of the 12-bit RAM
address. The BSR<7:4> bits will always read ’0’s, and
writes will have no effect.
A MOVLB instruction has been provided in the instruction set to assist in selecting banks.
If the currently selected bank is not implemented, any
read will return all '0's and all writes are ignored. The
ST ATUS register bits will be set/cleared as approp riate
for the instruction p erformed.
Each Bank extends up to FFh (256 bytes). All data
memory is implemented as static RAM.
A MOVFF instr uctio n igno res t he BSR, sinc e the 12-bit
addresses are embedded into the instruction word.
Section 4.12 provides a description of ind irect addr essing, which allows linear addressing of the entire RAM
space.
FIGURE 4-5:DIRECT ADDRESSING
Direct Addressing
BSR<3:0>7
bank select
(2)
location select
Note 1: For register file map detail, see Table 4-2.
2: The access bit of the instruction can be used to force an override of the selected bank
(BSR<3:0>) to the registers of the Access Bank.
3: The MOVFF instruction embeds the entire 12-bit address in the instruction.
from opcode
Data
Memory
(3)
(1)
(3)
0
00h01h0Eh0Fh
000h
0FFh
100h
1FFh
E00h
EFFh
Bank 0Bank 1Bank 14 Bank 15
F00h
FFFh
DS30475A-page 60Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
4.12Indirect Addressing, INDF and FSR
Registers
Indirect addressin g is a mode of addr essing data mem ory, where the data memory address in the instruction
is not fixed. A SFR register is used as a pointer to the
data memory location that is to be read or written.
Since this pointer is in RAM, the contents can be modified by the program. This ca n be use ful for data tables
in the data memory and for sof tware sta cks. Figu re 4-6
shows the operation of indirect addressing. This shows
the moving of the value to the data memory address
specified b y the value of the FSR register.
Indirect addressing is possible by using one of the
INDF registers. Any ins tru cti on u si ng the IN DF reg ist er
actually accesses the register indicated by the File
Select Register, FSR. Reading the INDF register itself
indirectly (FSR = ’0’) will read 00h. Writing to the INDF
register indirectly results in a no-operation. The FSR
register contains a 12-bit address, which is shown in
Figure 4-6.
The INDFn (0 ≤ n ≤ 2) register is not a physical registe r .
Addressing INDFn actually addresses the register
whose address is contained in the FSRn register
(FSRn is a pointer). This is indirect addressing.
Example 4-4 shows a simple use of in direct addres sing
to clear the RAM in Bank 1 (locations 100h-1FFh) in a
minimum number of instructions.
EXAMPLE 4-4:HOW TO CLEAR RAM
(BANK 1) USING INDIRECT
ADDRESSING
LFSRFSR0, 0x100 ;
NEXT CLRFPOSTINC0; Clear INDF
; register
; & inc pointer
BTFSSFSR0H, 1; All done
; w/ Bank1?
GOTONEXT; NO, clear next
CONTINUE;
: ; YES, continue
There are three indirect addressing registers. To
address the entire data memory space (4096 bytes),
these registers are 12-bit wide. To store the 12-bits of
addressing information, two 8-bit registers are
required. These indirect addres si ng regi ste r s are:
1. FSR0: composed of FSR0H:FSR0L
2. FSR1: composed of FSR1H:FSR1L
3. FSR2: composed of FSR2H:FSR2L
In addition, there are registers INDF0, INDF1 and
INDF2, which are not physically implemented. Reading
or writing to these registers activates indirect addressing, with the value in the corresponding FSR register
being the address of the data.
If an instruction writes a value to INDF0, the value will
be written to the address indicated by FSR0H:FSR0L.
A read from INDF1 reads the data from the address
indicated by FSR1H:FSR1L. INDFn can be used in
code anywhere an operand can be used.
If INDF0, INDF1 or INDF2 are read indirectly via an
FSR, all ’0’s are read (zero bit is set). Similarly, if
INDF0, INDF1 or INDF2 are written to indirectly, the
operation will be equivale nt to a NOP instruction and the
ST ATUS bits are not affected.
4.12.1INDIRECT ADDRESSING OPERATION
Each FSR register has an INDF register associated with
it, plus four additional register addresses. Performing an
operation on one of these five registers determines how
the FSR will be modified during indirect addressing.
When data access is done to one of the five INDFn
locations, the address selected will configure the FSRn
register to:
• Do nothing to FSRn after an indirect access (no
change) - INDFn
• Auto-decrement FSRn after an indirect access
(post-decrement) - POSTDECn
• Auto-increment FSRn after an indirect access
(post-increment) - POSTINCn
• Auto-increment FSRn before an indirect access
(pre-increment) - PREINCn
• Use the value in the WREG register as an offset
to FSRn. Do not mo dify the va lue of the WREG or
the FSRn register after an indirect access (no
change) - PLUSWn
When using the auto-increment or auto-decrement
features, the e ffect on t he FSR i s not r eflecte d in th e
STATUS register. For example, if the indirect address
causes the FSR to equal '0', the Z bit will not be set.
Incrementing or decrementing an FSR affects all 12
bits. That is, when FSRnL overflows from an increment,
FSRnH will be incremented automatically.
Adding these features allows the FSRn to be used as a
software stack pointer in addition to its uses for table
operations in data memory.
Each FSR has an address associated with it that performs an indexed indirect access. When a data access
to this INDFn location (PLUSWn) occurs, the FSRn is
configured to add the 2’s complement value in the
WREG register and the value in FSR to form the
address before an indirect access. The FSR value is
not changed.
If an FSR register con tains a value t hat indicate s one of
the INDFn, an indirect read will read 00h (zero bit is
set), while an indirect write will be equivalent to a NOP
(ST ATUS bits are not affected).
If an indirect addressing operation is done where the
target address is an FSRnH or FSRnL register, the
write operation will dominate over the pre- or
post-increment/decrement functions.
Note 1: For register file map detail, see Table 4-2.
(1)
0FFFh
DS30475A-page 62Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
4.13STATUS Register
The STATUS register, shown in Register 4-2, contains
the arithmetic status of the ALU. The STATUS register
can be the destination for any instruction, as with any
other register. If the STATUS register is the destination
for an instruction t hat affec ts the Z, DC, C , OV or N bits,
then the write to these five bits is disabled. These bits
are set or cleare d a cc ord ing to th e d ev ice l ogi c. Therefore, the result of a n ins tructi on with the STATUS re gister as destination may be different than intended.
REGISTER 4-2:STATUS REGISTER
U-0U-0U-0R/W-xR/W-xR/W-xR/W-xR/W-x
———NOVZDCC
bit 7bit 0
bit 7-5Unimplemented: Read as '0'
bit 4N: Negative bit
This bit is used for signed arithmetic (2 ’s comp lement). It indicates w hether the result of the ALU
operation was negative, (ALU MSb = 1)
1 = Result was negative
0 = Result was positive
bit 3OV: Overflow bit
This bit is used for signed a rithmetic (2’s complement). It indicates an overflow of the 7-bit magnitude, which causes the sign bit (bit 7) to change state.
1 = Overflow occurred for signed arithmetic (in this arithmet ic operation)
0 = No overflow occurred
bit 2Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1DC: Digit carry/borrow
For ADDWF, ADDLW, SUBLW, and SUBWF instructions
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
Note:For borrow,
complement of the second operand. For rotate (RRCF, RRNCF, RLCF, and
RLNCF) instructions, this bit is loaded with either the bit 4 or bit 3 of the source
register.
bit 0C: Carry/borrow
For ADDWF, ADDLW, SUBLW, and SUBWF instructions
1 = A carry-out from the most significant bit of the result occurred
0 = No carry-out from the most significant bit of the result occurred
Note:For borrow,
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low order bit of the source register.
bit
the polarity is reversed. A subtraction is executed by adding the tw o’s
bit
the polarity is reversed. A subtraction is executed by adding the tw o’s
For example, CLRF STATUS will clear the upper three
bits and set the Z bit. This leaves the STATUS register
as 000u u1uu (where u = unchanged).
It is recommended, 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 o r N bits from the
STATUS register. For other instructions which do not
affect the status bits, see Table 23-2.
Note:The C and DC bits operate as a borrow and
digit borrow
bit respectively, in subtraction.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, r ead as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
4.13.1RCON REGISTER
The Reset Control (RCON) regi ster contains flag bits
that allow differentiation between the sources of a
device RESET. These flags include the TO
BOR
and RI bits. This regis ter is rea dable and writabl e.
, PD, POR,
REGISTER 4-3:RCON REGISTER
R/W-0R/W-0U-0R/W-1R/W-1R/W-1R/W-0R/W-0
IPENLWRT
bit 7bit 0
bit 7IPEN: Interrupt Priority Enable bit
1 = Enable priority levels on interrupts
0 = Disable priority levels on interrupts (16CXXX compatibility mode)
bit 6LWRT: Long Write Enable bit
1 = Enable TBLWT to internal program memory
Once this bit is set, it can only be cleared by a POR or MCLR
0 = Disable TBLWT to internal program memory; TBLWT only to external program memory
bit 5Unimplemented: Read as '0'
bit 4RI
bit 3TO
bit 2PD
bit 1POR
bit 0BOR
: RESET Instruction Flag bit
1 = The RESET instruction was not executed
0 = The RESET instruction was executed causing a device RESET
(must be set in software after a Brown-out Reset occurs)
: Watchdog Time-out Flag bit
1 = After power-up, CLRWDT instru ction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down Detection Flag bit
1 = After power-up or by the CLRWDT instruction
0 = B y execution of the SLEEP instruction
: Power-on Reset Status bit
1 = A Power-on Reset has not occurred
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
0 = A Brown-out Reset occurred
(must be set in software after a Brown-out Reset occurs)
—RITOPDPORBOR
Note 1: If the BOREN configuration bit is set, BOR
is ’1’ on Power-on Reset. If the BOREN
configuration bit is c lear, BOR
on Power-on Reset.
The BOR
not necessarily predictable if the
brown-out circuit is disabled (the BOREN
configuration bit is clear). BOR
be set by the user and ch ecke d on su bsequent RESETs to see if it is clear, indicating a brown-out has occurred.
2: It is recommended that the POR
after a Power-on Reset has been
detected, so that subsequent Power-on
Resets may be detected.
status bit is a “don't care” and is
Reset
is unknown
must then
bit be set
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
DS30475A-page 64Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
5.0TABLE READS/TABLE WRITES
All PICmicro® devices have two memory spaces: the
program memory space and the data memory space.
Table Reads and Table Writes have been provided to
move data between these two memory spa ces through
an 8-bit register (TABLAT).
The operations that allow the processor to move data
between the data and program memory spaces are:
• Table Read (TBLRD)
• Table Write (TBLWT)
FIGURE 5-1:TABLE READ OPERATION
TABLE POINTER
TBLPTRHTBLPTRL
(1)
PROGRAM MEMORY
Table Read operations retrieve data from program
memory and place it into the data memory space.
Figure 5-1 shows the operation of a Table Read with
program and data memory.
Table Write operations store data from the data memory space into program memory. Figure 5-2 shows the
operation of a Table Write with program and data
memory.
Table operations work with byte entities. A table block
containing data is n ot requi red to b e word align ed, so a
table block can start and end at any byte address. If a
table write is being used to write an executable program to program memory, program instructions will
need to be word aligned.
Several control registers are used in conjunction with
the TBLRD and TBLWT instructions. These include:
• RCON register
• TABLAT register
• TBLPTR registers
5.1.1RCON REGISTER
The L WRT bit specifi es the opera tion of Table Writes to
internal memory when the V
pin. When the LWRT bit is set, the controller
MCLR
continues to execute user code, but long table writes
are allowed (for programming internal program memory) from user mo de. The LWRT bit can be cl eared only
by performing either a POR or MCLR
REGISTER 5-1: RCON REGISTER (ADDRESS: 0xFD0h)
R/W-0R/W-0U-0R/W-1R/W-1R/W-1R/W-0R/W-0
IPENLWRT
bit 7bit 0
bit 7IPEN: Interrupt Priority Enable
1 = Enable priority levels on interrupts
0 = Disable priority levels on interrupts (16CXXX compatibility mode)
bit 6LWRT: Long Write Enable
1 = Enable TBLWT to internal program memory
0 = Disable TBLWT to internal program memory.
Note 1: Only cleared on a POR or MCLR reset.
This bit has no effect on TBLWTs to external program memory.
bit 5Unimplemented: Read as '0'
bit 4RI
bit 3TO: Time-out bit
bit 2PD: Power-down bit
bit 1POR: Power-on Reset Status bit
bit 0BOR: Brown-out Reset Status bit
: RESET Instruction Flag bit
1 = No RESET instruction occurred
0 = A RESET instruction occurred
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
1 = After power-up or by t he CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
1 = No Brown-out Reset nor POR Reset occurred
0 = A Brown-out Reset or POR Reset occurred
(must be set in software after a Brown-out Reset occurs)
—RITOPDPORBOR
PP voltage is applied to th e
Reset.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS30475A-page 66Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
5.1.2TABLAT - TABLE LATCH REGISTER
The T a ble Latch (TABLAT) is an 8-bi t register mapped
into the SFR space. The Table Latch is used to hold
8-bit data during data transfers between program
memory and data memory.
5.1.3TBLPTR - TABLE POINTER REGISTER
The Table Pointer (TBLPTR) addresses a byte within
the program memory. The TBLPTR is comprised of
three SFR registers (Table Pointer Upper byte, High
byte and Low byte). These three registers
(TBLPTRU:TBLPTRH:TBLPTRL) join to form a 22-bit
wide pointer. The low order 21-bits allow the device to
address up to 2 Mbytes o f program memory spac e. The
22nd bit allows read only access to the Device ID, the
User ID and the Configuration bits.
The table pointer TBLPTR is used by t he TBLRD and
TBLWT instructions. These instructions can update the
TBLPTR in one of four ways based on the t a ble operation. These operations are shown in Table5-1.
These operations o n the TBL PTR only affect the l ow
order 21-bits.
TABLE 5-1:TABLE POINTER OPERATIONS WITH TBLRD AND TBLWT INSTRUCTIONS
5.2.1TABLE READ OVERVIEW (TBLRD)
The TBLRD in structions are used to read data from pr o-
gram memory to data memory.
TBLPTR points to a byte address in program space.
Executing TBLRD places the byte pointed to into
TABLAT. In addition, TBLPTR can be modified automatically for the next Table Read operation.
Table Reads from program memory are perform ed on e
byte at a time. The instruction will load T ABLAT with the
one byte from program memory poi nted to by TBLPTR .
5.2.2PROGRAM MEMORY WRITE BLOCK SIZE
The program memory of PIC18CXX8 devices is written
in blocks. For PIC18CXX8 devices , the write block size
is 2 bytes. Consequently, Table Write operations to
program memory are performed in pairs, one byte at a
time.
When a Table Write occurs to an even program memory address (TBLP TR<0> = 0), the co ntents of TABLAT
are transferred to an internal holding register. This is
performed as a short write and the program memory
block is not actually programmed at this time. The
holding register is not accessible by the user.
When a Table Write occurs to a n odd p rogram memor y
address (TBLPTR <0> = 1), a long wri te is s tarted. During the long write, the contents of TABLAT are written
to the high byte of t he progr am m emory blo ck and t he
contents of the holding register are transferred to the
low byte of the program memory block.
Figure 5-3 shows the holding register and the program
memory write blocks.
If a single byte is to be programmed, the low (even)
byte of the destination program word should be read
using TBLRD*, modified or changed, if required, and
written back to the same address using TBLWT*+. The
high (odd) byte should be read using TBLRD*, modified
or changed if required, and written back to the same
address using TBLWT. The write to an odd address will
cause a long write to begin. This process ensures that
existing data in either byte will not be changed unless
desired.
FIGURE 5-3:HOLDING REGISTER AND THE WRITE
Program MemoryHolding RegisterInstruction Execution
; TABLPTR points to address n
MOVLW DataLow; Load low data
MSBLSBMOVWF TABLAT; byte to TABLAT
DataLowTBLWT*+; Write it to LSB
; of Holding register
MOVLW DataHigh; Load high data
n - 1MSBLSBMOVWF TABLAT; byte to TABLAT
nDataLowDataHighDataLowTBLWT*; Write it to MSB
n + 1DataHigh; of Holding
n + 2; register and
; begin long
; write
EXAMPLE 5-1:TABLE READ CODE EXAMPLE
; Read a byte from location 0x0020
CLRFTBLPTRU; Load upper 5 bits of
; 0x0020
CLRFTBLPTRH; Load higher 8 bits of
; 0x0020
MOVLW 0x20; Load 0x20 into
MOVWF TBLPTRL; TBLPTRL
MOVWF TBLRD*; Data is in TABLAT
DS30475A-page 68Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
5.2.2.1Long Write Operation
The long write is what actually programs words of data
into the internal me mory. When a TBLWT to the MSB of
the write block occurs, instruction execution is halted.
During this time, programming voltage and the data
stored in internal latche s is applied to program memory .
For a long write to occur:
1. MCLR
2. LWRT bit must be set
3. TBLWT to the address of the MSB of the write
If the LWRT bit is clear , a short write will oc cur an d program memory will not be changed. If the TBLWT is not
to the MSB of th e write block, t hen the program ming
phase is not initiated.
Setting the LWRT bit enables long writes when the
MCLR
is set, it can be cleared only by performing a POR or
MCLR Reset.
To ensure that the memory location has been well programmed, a minimum programming time is required.
The long write can be terminated after the programming time has expired by a RESET or an interrupt.
Having only one int errupt source en able d to ter minat e
the long write, ensures that no unintended interrupts
will prematurely terminate the long write.
/VPP pin must be at the programming
voltage
block
pin is taken to VPP voltage. Once the LWRT bit
5.2.2.2Sequence of Events
The sequence of events for programming an internal
program memory location should be:
1. Enable the interrupt that terminates the long
write. Disable all other interrupts.
2. Clear the source interrupt flag.
3. If Interrupt Service Routine execution is desired
when the device wakes, enable global
interrupts.
4. Set LWRT bit in the RCON register.
5. Raise MCLR
voltage, V
6. Clear the WDT (if enabled).
7. Set the interrupt source to interrupt at the
required time.
8. Execute the Table Write for the lower (even)
byte. This will be a short write.
9. Execute the T able Wr ite for the upper (odd) b yte.
This will be a lo ng write. The con troller will HA L T
while programming. The interrupt wakes the
controller.
10. If GIE was set, service the interrupt request.
5.2.3LONG WRITE INTERRUPTS
The long write must be terminated by a RESET or any
interrupt.
The interrupt source must have its interrupt enable bit
set. When the source sets its interrupt flag, programming will terminate. This will occur regardless of the
settings of interrupt priori ty bits, the GIE/GIEH bit o r the
PIE/GIEL bit.
Depending on the states of interrupt priority bits, the
GIE/GIEH bit or the PIE/GIEL bit, program execution
can either be vectored to the high or low priority Interrupt Service Routine (ISR), or continue execution from
where programming commenced.
In either case, the interrupt flag will not be cleared
when programming is terminated and will need to be
cleared by the software.
5.3Unexpected Termination of Write
Operations
If a write is terminated by an unplanned event such as
loss of power, an unexpected RESET, or an interrupt
that was not disabled, the memory location just programmed should be verified and reprogrammed if
needed.
TABLE 5-2:SLEEP MODE, INTERRUPT ENABLE BITS AND INTERRUPT RESULTS
GIE/
GIEH
XX X 0
XXX10Long write continues, will wake when
0
(default)0(default)
0
(default)
10
0
(default)
10
PIE/
GIEL
11
(default)
10
(default)1high priority
Priority
X11Terminates long write, executes next instruction.
high priority
(default)
0
low
low
(default)
Interrupt
Enable
(default)
11Terminates long write, executes next instruction.
11Terminates long write, executes next instruction.
11Terminates long write, branches to low priority
11Terminates long write, branches to high priority
Interrupt
Flag
XLong write continues even if interrupt flag
becomes set during SLEEP.
the interrupt flag is set.
Interrupt flag not cleared.
Interrupt flag not cleared.
Interrupt flag not cleared.
interrupt vector.
Interrupt flag can be cleared by ISR.
interrupt vector.
Interrupt flag can be cleared by ISR.
Action
DS30475A-page 70Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
6.08 X 8 HARDWARE MULTIPLIER
An 8 x 8 hardware multiplier is included in the ALU of
the PIC18CXX8 devices. By making the multiply a
hardware operatio n, i t co mp letes in a single instruction
cycle. This is an unsign ed multiply that gives a 16-bit
result. The result is store d into th e 16-bit produ ct regi ster pair (PRODH:PRODL). The multiplier does not
affect any flags in the STATUS register.
Making the 8 x 8 multiplier execute in a single cycle
gives the following advantages:
• Higher computational throughput
• Reduces code size requirements for multiply algo-
rithms
The performance incre ase allows the device to be used
in applications previously reserved for Digital Signal
Processors.
Table 6-1 shows a performance comparison between
enhanced devic es using the sin gle cycle hard ware multiply, and performing the same function without the
hardware multiply.
TABLE 6-1:PERFORMANCE COMPARISON
Program
RoutineMultiply Method
8 x 8 unsignedWithout hardware multiply13696.9 µs27.6 µs69 µs
Hardware multiply11100 ns400 ns1 µs
8 x 8 signedWithout hardware multiply33919.1 µs36.4 µs91 µs
Hardware multiply66600 ns2.4 µs6 µs
16 x 16 unsigned Without hardware multiply2124224.2 µs96.8 µs242 µs
Hardware multiply24242.4 µs9.6 µs24 µs
16 x 16 signedWithout hardware multiply5225425.4 µs102.6 µs254 µs
Example 6-1 shows the sequence to perform an 8 x 8
unsigned multiply. Only one instruction is required
when one argumen t of the multiply is already loaded in
the WREG register.
Example 6-2 shows the sequence to do an 8 x 8 signed
multiply. To account for the sign bits of the arguments,
each argument’s most significant bit (MSb) is tested
and the appropriate subtractions are done.
MOVFF ARG1, WREG
MULWF ARG2 ; ARG1 * ARG2 ->
; PRODH:PRODL
BTFSC ARG2, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH
; - ARG1
MOVFF ARG2, WREG
BTFSC ARG1, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH
; - ARG2
Example 6-3 shows the sequence to perform a 16 x 16
unsigned multiply. Equation 6-1 shows the algorithm
that is used. The 32-bit result is stored in 4 registers
RES3:RES0.
DS30475A-page 72Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
Example 6-4 shows the sequence to perform an 16 x
16 signed multiply. Equation 6-2 shows the algorithm
used. The 32-bit result is stored in four registers
RES3:RES0. To account for the sign bits of the arguments, each argument pairs most significant bit (MSb)
is tested and the appropriate subtractions are done.
DS30475A-page 74Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
7.0INTERRUPTS
The PIC18CXX8 devices have multiple interrupt
sources and an interrupt priority feature that allows
each interrupt source to be assigned a high priority
level or a low priority level. The high priority interrupt
vector is at 000008h and the low prio rity interrupt vector
is at 000018h. High priority interrupt events will override any low priority interrupts that may be in progress.
There are 13 registers that are use d to c ontrol interru pt
operation. These registers are:
• RCON
• INTCON
• INTCON2
• INTCON3
• PIR1, PIR2, PIR3
• PIE1, PIE2, PIE3
• IPR1, IPR2, IPR3
It is recommended that the Microchip header files supplied with MPLAB be used for the symbolic bit names
in these registers. This allows the assembler/compiler
to automatically take care of the placement of these
bits within the specified regis te r.
Each interrupt source has three bits to control its operation. The functions of these bits are:
• Flag bit to indicate that an interrupt event
occurred
• Enable bit that allows program execution to
branch to the interrupt vector address when
the flag bit is set
• Priority bit to select hi gh p rio rity or l ow pri orit y
The interrupt priority feature is enabled by setting the
IPEN bit (RCON register). When interrupt priority is
enabled, there are two bits that enable interrupts globally. Setting the GI EH bit (IN TCON regi ster) enab les
all interrupts that have the priority bit set. Setting the
GIEL bit (INTCON register) enables all interrupts that
have the pr iority bit cleared. When the interrup t flag,
enable bit and appropriate global interrupt enable bit
are set, the interrupt will v ector im media tely to add ress
000008h or 000018h, depending on the priority level.
Individual interrupts can be disabled through their corresponding enable bits.
When the IPEN bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with PICmicro
Compatibility mode, the interrupt priority bits for each
source have no effe ct. T he PEIE b it (IN TCO N regi st er)
enables/disables all peripheral interrupt sources. The
GIE bit (INTCON register) enab les/disables all in terrupt
sources. All interrupts branch to address 000008h in
Compatibility mo de.
When an interrupt is responded to, the Global Interrupt
Enable bit is cleared to d isable furth er interru pts. If the
IPEN bit is cleared, this is the GIE bit. If in terrupt pri ority levels are used, this will be eith er the GIEH or GIEL
bit. High priority interrupt sources can interrupt a low
priority interrupt.
The return address is pushed onto the stack and the
PC is loaded with the interrupt vector address
(000008h or 000018h). Once in the interrupt service
routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. The interrupt
flag bits must be cl eared in so ftware be fore re-enab ling
interrupts to avoid recursive interrupts.
The "return from interrupt" instruction, RETFIE, exits
the interrupt routine and set s the GIE bit (GIEH or GI EL
if priority levels are used), which re-enables interrupts.
For external interrupt events, such as the INT pins or
the PORTB input chang e interrupt, the i nterrupt latenc y
will be three to four instruction cycles. The exact
latency is the same for one or two cycle instructions.
Individual interrupt flag bits are set, regardless of the
status of their corresponding enable bit or the GIE bit.
Peripheral Interrupt Flag bit
Peripheral Interrupt Enable bit
Peripheral Interrupt Priority bit
TMR1IF
TMR1IE
TMR1IP
XXXXIF
XXXXIE
XXXXIP
Additional Peripheral Interrupts
High Priority Interrupt Generation
Low Priority Interrupt Generation
IPEN
TMR0IF
TMR0IE
TMR0IP
INT0IF
INT0IE
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
INT3IF
INT3IE
INT3IP
IPEN
GIEL/PEIE
RBIF
RBIE
RBIP
IPEN
Wake-up if in SLEEP mode
Interrupt to CPU
Vector to location
0008h
GIE/GIEH
Peripheral Interrupt Flag bit
Peripheral Interrupt Enable bit
Peripheral Interrupt Priority bit
TMR1IF
TMR1IE
TMR1IP
XXXXIF
XXXXIE
XXXXIP
Additional Peripheral Interrupts
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
INT3IF
INT3IE
INT3IP
PEIE/GIEL
Interrupt to CPU
Vector to Location
0018h
DS30475A-page 76Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
7.1Control Registers
This section contains the control and status registers.
REGISTER 7-1:INTCON REGISTER
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIE/GIEH PEIE/GIELTMR0IEINT0IERBIETMR0IFINT0IFRBIF
bit 7bit 0
bit 7GIE/GIEH: Global Interrupt Enable bit
When IPEN = 0:
1 = Enables all un-masked interrupts
0 = Disables all interrupts
When IPEN = 1
1 = Enables all high priority interrupts
0 = Disables all high priority interrupts
bit 6PEIE/GIEL: Peripheral Interrupt Enable bit
hen IPEN = 0:
W
1 = Enables all un-masked peripheral interrupts
0 = Disables all peripheral interrupts
When IPEN = 1
1 = Enables all low priority peripheral interrupts
0 = Disables all priority peripheral interrupts
bit 5TMR0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 overflow interrupt
0 = Disables the TMR0 overflow interrupt
bit 4INT0IE: INT0 External Interrupt Enable bit
1 = Enables the INT0 external interrupt
0 = Disables the INT0 external interrupt
bit 3RBIE: RB Port Change Interrupt Enable bit
1 = Enables the RB port change interrupt
0 = Disables the RB port change inte rrupt
bit 2TMR0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 register has ov erflowed (must be clear ed in software)
0 = TMR0 register did not overflow
bit 1INT0IF: INT0 External Interrupt Flag bit
1 = The INT0 external interrupt occurred (must be cleared in software by reading PORTB)
0 = The INT0 external interrupt did not occur
bit 0RBIF: RB Port Change Interrupt Flag bit
1 = At least one of the RB7:RB4 pins changed state (must be cleared in software)
0 = None of the RB7:RB4 pins have changed state
:
:
7.1.1INTCON REGISTERS
The INTCON Registers are readable and writable
registers, which contain various enable, priority, and
flag bits.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
Note:Interrupt flag bits get set when an interrupt condition occurs, regardless of the state
of its corresponding enable bit or the global enable bit. Use r s oftwa re s ho uld ensure
the appropriate inte rrupt fla g bits ar e clea r pr ior to enabli ng an interrup t. This featu re
allows software polling.
7.1.2PIR REGISTERS
The Peripheral Interrupt Request (PIR) registers con-
tain the individual flag bits for the peripheral interrupts
(Register 7-5). Due to the number of peripheral interrupt sources, there are three Peripheral Interrupt
Request (Flag) registers (PIR1, PIR2, PIR3).
Note 1: Interrupt flag bits are set when an interrupt
condition occurs, re gardless of th e state of
its corresponding enable bit or the global
enable bit, GIE (INTCON register).
2: User software sh ould en sure th e approp ri-
ate interru pt flag bits are clea red prior to
enabling an interrupt, and after servicing
that interrupt.
REGISTER 7-4:RCON REGISTER
R/W-0R/W-0U-0R/W-1R/W-1R/W-1R/W-0R/W-0
7.1.3PIE REGISTERS
The Peripheral Interrupt Enable (PIE) registers contain
the individual enable bits for the peripheral interrupts
(Register 7-5). Due to the number of peripheral interrupt sources, there are three Peripheral Interrupt
Enable registers (PIE1, PIE2, PIE3). When IPEN is
clear, the PEIE bit must be set to enable any of these
peripheral interrupts.
7.1.4IPR REGISTERS
The Interrupt Priority (IPR) regis ters contain the indivi d-
ual priority bits for the peripheral interrupts
(Register 7-7). Due to the number of peripheral interrupt sources, there are three Peri pheral Interrupt Pri ority registers (IPR1, IPR2, IPR3). The operation of the
priority bits requires that the Interrup t Priority Enable b it
(IPEN) be set.
7.1.5RCON REGISTER
The Reset Control ( RCON) register contains the bit th at
is used to enable prioritized interrupts (IPEN).
IPENLWRT
bit 7bit 0
bit 7IPEN: Interrupt Priority Enable bit
1 = Enable priority levels on interrupts
0 = Disable priority levels on interrupts (16CXXX compatibility mode)
bit 6LWRT: Long Write Enable
For details of bit operation see Register 4-3
bit 5Unimplemented: Read as '0'
bit 4RI
bit 3TO
bit 2PD
bit 1POR
bit 0BOR
: RESET Instruction Flag bit
For details of bit operation see Register 4-3
: Watchdog Time-out Flag bit
For details of bit operation see Register 4-3
: Power-down Detection Flag bit
For details of bit operation see Register 4-3
: Power-on Reset Status bit
For details of bit operation see Register 4-3
: Brown-out Reset Status bit
For details of bit operation see Register 4-3
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
—RITOPDPORBOR
DS30475A-page 80Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
REGISTER 7-5:PIR REGISTERS
R/W-0R/W-0R-0R-0R/W-0R/W-0R/W-0R/W-0
PIR1PSPIFADIFRCIFTXIFSSPIFCCP1IF TMR2IFTMR1IF
bit 7bit 0
U-0R/W-0U-0U-0R/W-0R/W-0R/W-0R/W-0
PIR2
bit 7bit 0
PIR3IRXIFWAKIFERRIFTXB2IFTXB1IFTXB0IFRXB1IFRXB0IF
bit 7bit 0
PIR1 bit 7PSPIF: Parallel Slave Port Read/Write Interrupt Flag bit
bit 6ADIF: A/D Converter Interrupt Flag bit
bit 5RCIF: USART Receive Interrupt Flag bit
bit 4TXIF: USART Transmit Interrupt Flag bit
bit 3SSPIF: Master Synchronous Serial Port Interrupt Flag bit
bit 2CCP1IF: CCP1 Interrupt Flag bit
bit 1TMR2IF: TMR2 to PR2 Match Interrupt Flag bit
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
—CMIF——BCLIFLVDIFTMR3IFCCP2IF
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
1 = A read or a write operation has taken place
(must be cleared in software)
0 = No read or write has occurred
1 = An A/D conversion completed
(must be cleared in software)
0 = The A/D conversion is not complete
1 = The USART receive buffer, RCREG, is full
(cleared when RCREG is read)
0 = The USART receive buffer is empty
1 = The USART transmit buffer, TXREG, is empty
(cleared when TXREG is written)
0 = The USART transmit buffer is full
1 = The transmission/reception is complete
(must be cleared in software)
0 = Waiting to transmit/receive
Capture Mode
1 = A TMR1 register capture occurred
(must be cleared in software)
0 = No TMR1 register capture occurred
Compare Mode
1 = A TMR1 register compare match occurred
(must be cleared in software)
0 = No TMR1 register compare match occurred
PWM Mode
Unused in this mode
7.1.6INT INTERRUPTS
External interrupts on the RB0/INT0, RB1/INT1,
RB2/INT2, and RB3/INT3 pins are edge triggered:
either risi ng if the c orre spon din g INT EDG x bit is se t in
the INTCON2 register, or falling, if the INTEDGx bit is
clear . When a val id edge appe ars on the RBx/IN Tx pin,
the corresponding flag bit INTxIF is set. This interrupt
can be disabled by clearing the corresponding enable
bit INTxIE. Flag bit INTxIF must be cleared in software
in the Interrupt Service Routine before re-enabling the
interrupt. All external interrupts (INT0, INT1, INT2, and
INT3) can wake-up the processor from SLEEP, if bit
INTxIE was set prior to going into SLEEP. If the global
interrupt enable bi t GIE is set, the processor wil l branch
to the interrupt vector following wake-up.
Interrupt priority for INT1, INT 2 and INT3 is determine d
by the value contained in the interrupt priority bits
INT1IP (INTCON3 register), INT3IP (INTCON3 register), and INT2IP (INTCON2 register). There i s no priority bit associated with INT0; it is always a high priority
interrupt source.
7.1.7TMR0 INTERRUPT
In 8-bit mode (wh ich is the de fault), an ov erflow (FFh →
00h) in the TMR0 register will set flag bit TMR0IF. In
16-bit mode, an overflow (FFFFh → 0000h) in the
TMR0H:TMR0L registers will set flag bit TMR0IF. The
interrupt can be enabled/disabled by setting/clearing
enable bit TMR0IE (INTCON register). Interrupt pri ority
for Timer0 is determined by the value contained in the
interrupt priority bit TMR0IP (INTCON2 register). See
Section 10.0 for further details on the Timer0 module.
7.1.8PORTB INTERRUPT-ON-CHANGE
An input change on PORTB<7:4> sets flag bit RBIF
(INTCON register). The interrupt can be enabled/
disabled by setting/clearing enable bit RBIE (INTCON
register). Interrupt priority for PORTB interrupton-change is determined by the value contained in the
interrupt priority bit RBIP (INTCON2 register).
7.2Context Saving During Interrupts
During an interrupt, the return PC v alue is sa ved on the
stack. Additionally, the WREG, STATUS and BSR registers are saved on the fast return stack. I f a fast return
from interrupt is not used (See Section 4.3), the user
may need to save the WREG, STATUS and BSR registers in software. Depending on the user’s application,
other registers may also need to be saved.
Example 7-1 saves and restores the WREG, STATUS
and BSR registers during an In terrupt Serv ice Rou tine.
EXAMPLE 7-1:SAVING STATUS, WREG AND BSR REGISTERS IN RAM
MOVWF W_TEMP ; W_TEMP is in Low Access bank
MOVFF STATUS, STATUS_TEMP ; STATUS_TEMP located anywhere
MOVFF BSR, BSR_TEMP ; BSR located anywhere
;
; USER ISR CODE
;
MOVFF BSR_TEMP, BSR ; Restore BSR
MOVF W_TEMP, W ; Restore WREG
MOVFF STATUS_TEMP, STATUS ; Restore STATUS
DS30475A-page 88Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.0I/O PORTS
Depending on the device selected, there are up to
eleven ports available. Some pins of the I/O ports are
multiplexe d wi th an a lter nat e fu nct ion from th e pe ri pheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general
purpose I/ O pin.
Each port has three registers for its operation. These
registers are:
• TRIS register (Data Direction register)
• PORT register (reads the level s on the pins of the
device)
• LAT register (output latch)
The data latch (LAT register) is useful for
read-modify-write operations on the value that the I/O
pins are driving.
8.1PORTA, TRISA and LATA Registers
PORTA is a 6-bit wide, bi-directional port. The corresponding Data Direction register is TRISA. Setting a
TRISA bit (=1) will make t he co rrespon ding POR TA pin
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISA bit (=0) will
make the correspondin g POR TA pin an output (i.e., put
the contents of the output latch on the selected pin).
On a Power-on Reset, these pins are configured as
inputs and read as '0'.
Reading the PORTA register reads the status of the
pins, whereas writing to it will write to the port latch.
Read-modify-write operations on the LATA register,
reads and writes the latched output value for PORTA.
The RA4 pin is multiplexed with the Timer0 module
clock input to become the RA4/T0CKI pin. The
RA4/T0CKI pin is a Schmitt Trigger input and an open
drain output. All other R A po rt pin s h ave TTL inpu t le vels and full CMOS output drivers.
The other PORTA pins are multiplexed with analog
inputs and the analog V
operation of each p in is se lected by clearing /settin g the
control bits in the ADCON1 register (A/D Control
Register1). On a Power-on Reset, these pins are configured as analog inputs and read as '0'.
The TRISA register controls the direction of the RA
pins, even when they are bei ng u se d as ana lo g inputs.
The user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs.
REF+ and VREF- inputs. The
EXAMPLE 8-1:INITIALIZING PORTA
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
CLRF LATA ; Alternate method
; to clear output
; data latches
MOVLW 0x07 ; Configure A/D
MOVWF ADCON1 ; for digital inputs
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISA ; Set RA3:RA0 as inputs
; RA5:RA4 as outputs
FIGURE 8-1:RA3:RA0 AND RA5 PINS
BLOCK DIAGRAM
RD LATA
Data
Bus
WR LATA
or
WR PORTA
WR TRISA
RD PORTA
SS Input (RA5 only)
To A/D Converter and LVD Modules
Note 1:I/O pins have diode protection to VDD and VSS.
Note 1:I/O pins have diode protection to VDD and VSS.
TABLE 8-1:PORTA FUNCTIONS
NameBit#Buffer Function
RA0/AN0bit0TTLInput/output or analog input.
RA1/AN1bit1TTLInput/output or analog input.
RA2/AN2/V
RA3/AN3/VREF+bit3TTLInput/output or analog input or VREF+.
RA4/T0CKIbit4ST/OD Input/output or external clock input for Timer0 output is open drain type.
RA5/SS/
OSC2/CLKO/RA6bit6TTLOSC2 or clock output or I/O pin.
Legend: TTL = TTL input, ST = Schmitt Trigger input, OD = Open Drain
TABLE 8-2:SUMMARY OF REGISTERS ASSOCIATED WITH PORTA
NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
REF-bit2TTLInput/output or analog input or VREF-.
AN4/LVDINbit5TTLInput/output or slave select input for synchronous serial port or analog
input, or low voltage detect input.
Valu e on
POR,
BOR
Value on all
other
RESETS
PORTA
—RA6RA5RA4RA3RA2RA1RA0-x0x 0000 -uuu uuuu
LATA—Latch A Data Output Register-xxx xxxx -uuu uuuu
TRISA—PORTA Data Direction Register-111 1111 -111 1111
ADCON1
——VCFG1 VCFG0 PCFG3 PCFG2PCFG1PCFG0 --00 0000 --uu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'.
Shaded cells are not used by PORTA.
DS30475A-page 90Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.2PORTB, TRISB and LATB Registers
PORTB is an 8-bit wide bi-directional port. The corresponding Data Direction register is TRISB. Setting a
TRISB bit (=1) will make the corres ponding POR TB pi n
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISB bit (=0) will
make the corresponding PORTB pin an output ( i.e.,
put the contents of the output latch on the selected pin).
Read-modify-write operations on the LATB register
read and write the latched output value for PORTB.
EXAMPLE 8-2:INITIALIZING PORTB
CLRF PORTB ; Initialize PORTB by
; clearing output
; data latches
CLRF LATB ; Alternate method
; to clear output
; data latches
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB3:RB0 as inputs
; RB5:RB4 as outputs
; RB7:RB6 as inputs
FIGURE 8-4:RB7:RB4 PINS BLOCK
DIAGRAM
V
TTL
Input
Buffer
DD
P
Weak
Pull-up
I/O pin
(1)
(2)
RBPU
Data Bus
WR LATB
WR TRISB
Data Latch
QD
CK
TRIS Latch
QD
CK
Each of the PORTB pi ns has a wea k inte rnal pul l-up. A
single control bit can turn on all the pull- ups. This is performed by cl eari ng b it RB PU
(INTCON2 register). The
weak pull -up is au tomati cally t urned off when th e port
pin is configured as an output. The pull-ups are disabled on a Power-on Reset.
Four of PORTB’s pins, RB7:RB4, have an
interrupt-on-change feature. Only pins configured as
inputs can cause this interrupt to occur (i.e., any
RB7:RB4 pin configured as an output is excluded from
the interrupt-on-change comparison). The input pins
(of RB7:RB4) are compared with the old value latched
on the last r e ad of P ORTB. Th e “mismatch” outputs of
RB7:RB4 are OR’d together to generate the RB Port
Change Interrupt w ith f lag bit RBIF (INTC ON reg ister).
This interrupt can wake the device from SLEEP. The
user, in the Interrupt Service Routine, can clear the
interrupt in the following manner:
a) Any read or write of PORTB (except with the
MOVFF instruction) . This will end the mismatch
condition.
b) Clear flag bit RBIF.
A mismatch c ond it i on wi ll cont i n ue to s et f lag bi t RB IF.
Reading PORTB will end the mismatch condition and
allow flag bit RBIF to be cleared.
The interrupt-on-change feature is recommended for
wake-up on key depression operation and operations
where PORTB is only used for the interrupt on change
feature. Polling of PORTB is not recommended while
using the interrupt-on-change feature.
Input/output pin (with in terrupt-on-change). Internal softw are programmable
weak pull-up. Serial programming clock.
(2)
Input/output pin (with in terrupt-on-change). Internal softw are programmable
weak pull-up. Serial programming data.
TABLE 8-4:SUMMARY OF REGISTERS ASSOCIATED WITH PORTB
NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
PORTBRB7RB6RB5RB4RB3RB2RB1RB0xxxx xxxx uuuu uuuu
LATBLATB Data Output Registerxxxx xxxx uuuu uuuu
TRISBPORTB Data Direction Register1111 1111 1111 1111
INTCON
INTCON2RBPU INTEDG0 INTEDG1 INTEDG2INTEDG3
INTCON3INT2IPINT1IPINT3IEINT2IEINT1IEINT3IFINT2IF INT1IF 1100 0000 1100 0000
Legend: x = unknown, u = unchanged. Shaded cells are not used by PORTB.
DS30475A-page 92Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.3PORTC, TRISC and LATC Registers
put, while other peripherals override th e TRIS bit to make
a pin an input. The user should refer to the correspond-
PORTC is an 8-bit wide, bi-directional port. The corresponding Data Direction regi ster is TRISC. Setting a
TRISC bit (=1) will make the corres ponding POR TC pin
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISC bit (=0) will
make the correspondi ng PORTC pin an output (i.e., p ut
the contents of the output latch on the selected pin).
Read-modify-write operations on the LATC register,
read and write the latched output value for PORTC.
PORTC is mul tiplexed with s everal peri pheral function s
(Table 8-5). PORTC pins have Schmitt Trigger input
buffers.
When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTC pin. Some
peripherals override the TRIS bit to make a pin an out-
ing peripheral section fo r the c orrec t TRIS bit s etti ngs .
The pin override value is not loaded into the TRIS reg-
ister. Th is allows read-mod ify-write of the TRIS regi ster ,
without concern due to peripheral overrides.
EXAMPLE 8-3:INITIALIZING PORTC
CLRF PORTC ; Initialize PORTC by
; clearing output
; data latches
CLRF LATC ; Alternate method
; to clear output
; data latches
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISC ; Set RC3:RC0 as inputs
; RC5:RC4 as outputs
; RC7:RC6 as inputs
RC0Y esTimer1 OSC for Timer1/Timer3
RC1Y esTimer1 OSC for Timer1/Timer3
RC2No—
RC3Yes
RC4Yes
RC5YesSPI Data Out
RC6YesUSART Async Xmit, Sync Clock
RC7YesUSART Sync Data Out
2
C Master Clock
SPI/I
2
I
C Data Out
DD and VSS.
Schmitt
Trigger
EN
PIC18CXX8
TABLE 8-5:PORTC FUNCTIONS
NameBit#Buffer TypeFunction
RC0/T1OSO/T13CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
Legend: ST = Schmitt Trigg er input
bit0
bit1
bit2
bit3
bit4
bit5
bit6
bit7
STInput/output port pin or T imer1 oscillato r output or Timer1/Timer3 clock
STInput/output port pin or Timer1 oscillator input.
STInput/output port pin or Capture1 input/Compare1 output/PWM1
STInput/output port pin or Synchronous Serial clock for SPI/I
STInput/output port pin or SPI Data in (SPI mode) or Data I/O
STInput/output port pin or Synchronous Serial Port data output.
STInput/output port pin Addressable USART Asynchronous Transmit or
STInput/output port pin Addressable USART Asynchronous Receive or
input.
output.
2
(I
C mode).
Addressable USART Synchronous Clock.
Addressable USART Synchronous Data.
2
C.
TABLE 8-6:SUMMARY OF REGISTERS ASSOCIATED WITH PORTC
NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
PORTCRC7RC6RC5RC4RC3RC2RC1RC0xxxx xxxx uuuu uuuu
LATCLATC Data Output Registerxxxx xxxxuuuu uuuu
TRISCPORTC Data Direction Register1111 11111111 1111
Legend: x = unknown, u = unchanged
Value on
POR,
BOR
Value on all
other
RESETS
DS30475A-page 94Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.4PORTD, TRISD and LATD Registers
PORTD is an 8-bit wide, bi-directional port. The corresponding Data Direction regi ster is TRISD. Setting a
TRISD bit (=1) will make the corres ponding POR TD pin
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISD bit (=0) will
make the correspondi ng PORTD pin an output (i.e., p ut
the contents of the output latch on the selected pin).
Read-modify-write operations on the LATD register
reads and writes the latched output value for PORTD.
PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individu all y co nfig ura ble as an inp ut or
output.
PORTD can be configured as an 8-bit wide microprocessor port (parallel slave port), by setting control
bit PSPMODE (PSPCON register). In this mode, the
input buffers are TTL. See Section 9.0 for additional
information on the Parallel Slave Port (PSP).
EXAMPLE 8-4:INITIALIZING PORTD
CLRF PORTD ; Initialize PORTD by
; clearing output
; data latches
CLRF LATD ; Alternate method
; to clear output
; data latches
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISD ; Set RD3:RD0 as inputs
; RD5:RD4 as outputs
; RD7:RD6 as inputs
Input/output port pin or parallel slave port bit0.
Input/output port pin or parallel slave port bit1.
Input/output port pin or parallel slave port bit2.
Input/output port pin or parallel slave port bit3.
Input/output port pin or parallel slave port bit4.
Input/output port pin or parallel slave port bit5.
Input/output port pin or parallel slave port bit6.
Input/output port pin or parallel slave port bit7.
TABLE 8-8:SUMMARY OF REGISTERS ASSOCIATED WITH PORTD
NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
PORTDRD7RD6RD5RD4RD3RD2RD1RD0xxxx xxxxuuuu uuuu
LATDLATD Data Output Registerxxxx xxxxuuuu uuuu
TRISDPORTD Data Direction Register1111 11111111 1111
PSPCON
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTD.
IBFOBFIBOVPSPMODE————0000 ----0000 ----
Valu e on
POR,
BOR
Value on all
other
RESETS
DS30475A-page 96Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.5PORTE, TRISE and LATE Registers
PORTE is an 8-bit wide, bi-directional port. The corresponding Data Direction register is TRISE. Setting a
TRISE bit (=1) will make the corres ponding POR TE pi n
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISE bit (=0) will
make the corresponding POR TE pin an output (i.e., put
the contents of the output latch on the selected pin).
Read-modify-write operations on the LATE register
reads and writes the latched output value for PORTE.
PORTE is an 8- b it po r t w i t h S c hm it t Trigge r i npu t b u ffers. Each pin is individu all y co nfig ura ble as an inp ut or
output. PORT E is multiplexed w ith several per ipheral
functions (T able 8-9).
FIGURE 8-8:PORTE BLOCK DIAGRAM
Peripheral Out Select
Peripheral Data Out
Data Bus
WR LATE
or
WR PORTE
WR TRISE
RD LATE
QD
Q
CK
Data Latch
QD
Q
CK
TRIS Latch
EXAMPLE 8-5:INITIALIZING PORTE
CLRF PORTE ; Initialize PORTE by
; clearing output
; data latches
CLRF LATE ; Alternate method
; to clear output
; data latches
MOVLW 0x03 ; Value used to
; initialize data
; direction
MOVWF TRISE ; Set RE1:RE0 as inputs
; RE7:RE2 as outputs
RE3bit3STInput/output port pin.
RE4bit4STInput/output port pin.
RE5bit5STInput/output port pin.
RE6bit6STInput/output port pin.
RE7/CCP2bit7STInput/output port pin or Capture 2 input/Compare 2 output.
Legend: ST = Schmitt Trigger input, TTL = TTL input
Note 1: Input buffers are Schmitt Triggers when in I/O mode and TTL buffer when in Parallel Slave Port mode.
bit0ST/TTL
bit1ST/TTL
bit2ST/TTL
(1)
Input/output port pin or Re ad contr ol inpu t in Par allel Slav e Port mod e.
(1)
Input/output port pin or Write control input in Parallel Slave Port mode.
(1)
Input/output port pin or Chip Select control input in Parallel Slave Port
mode.
TABLE 8-10:SUMMARY OF REGISTERS ASSOCIATED WITH PORTE
NameBit 7 Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
TRISEPORTE Data Direction Control Register1111 1111 1111 1111
PORTERead PORTE pin/Write PORTE Data Latchxxxx xxxx uuuu uuuu
LATERead PORTE Data Latch/Write PORTE Data Latchxxxx xxxx uuuu uuuu
PSPCONIBFOBF IBOV PSPMODE————0000 ----0000 ----
Legend: x = unknown, u = unchanged
Valu e on:
POR,
BOR
Value on all
other
RESETS
DS30475A-page 98Advanced Information 2000 Microchip Technology Inc.
PIC18CXX8
8.6PORTF, LATF, and TRISF Registers
PORTF is an 8-bit wide, bi-directional port. The corresponding Data Direction register is TRISF. Setting a
TRISF bit (=1) will m ake the corres pondi ng POR TF pi n
an input (i.e., put the corresponding output driver in a
hi-impedance mode). Clearing a TRISF bit (=0) will
make the correspondi ng PORTF pin an outp ut (i.e., put
the contents of the output latch on the selected pin).
Read-modify-write operations on the LATF register
reads and writes the latched output value for PORTF.
PORTF is multiplexed with several analog peripheral
functions incl uding t he A/ D co nverte r inpu ts a nd co mparator inputs, outputs, and voltage reference.
Note 1: On a Power- on Reset , the R F6:RF0 pi ns
EXAMPLE 8-6:INITIALIZING PORTF
CLRF PORTF ; Initialize PORTF by
; clearing output
; data latches
CLRF LATF ; Alternate method
; to clear output
; data latches
MOVLW 0x07 ;
MOVWF CMCON ; Turn off comparators
MOVLW 0x0F ;
MOVWF ADCON1 ; Set PORTF as digital I/O
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISF ; Set RF3:RF0 as inputs
; RF5:RF4 as outputs
; RF7:RF6 as inputs
RF0/AN5bit0STInput/output port pin or analog input.
RF1/AN6/C2OUTbit1STInput/output port pin or analog input or comparator 2 output.
RF2/AN7/C1OUTbit2STInput/output port pin or analog input or comparator 1 output.
RF3/AN8bit3STInput/output port pin or analog input or comparator input.
RF4/AN9bit4STInput/output port pin or analog input or comparator input.
RF5/AN10/
CVREF
bit5STInput/output port pin or analog input or comparator input or comparator
reference output.
RF6/AN11bit6STInput/output port pin or analog input or comp arator inpu t.
RF7bit7STInput/output port pin.
Legend: ST = Schmitt Trigger input
TABLE 8-12:SUMMARY OF REGISTERS ASSOCIATED WITH PORTF
Value on:
NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
POR,
BOR
TRISFPORTF Data Direction Control Register1111 11111111 1111
PORTFRead PORTF pin / Write PORTF Data Latchxxxx xxxxuuuu uuuu
LATFRead PORTF Data Latch/Write PORTF Data Latch0000 0000uuuu uuuu
ADCON1
CMCON