7.08 X 8 Hardware Multiplier..................................................................................................................................85
18.0Low Voltage Detect..........................................................................................................................................203
19.0Special Features of the CPU...........................................................................................................................207
20.0Instruction Set Summary .................................................................................................................................215
Appendix D: Migrating from other PICmicro Devices.................................................................................................304
Appendix E: Development Tool Version Requirements.............................................................................................305
Index ...........................................................................................................................................................................307
DS39541A-page 6Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding th is publication, p lease c ontact the M a rketing Communications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include literature number) you are using.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
Legend:TTL = TTL compatible 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
PIC18C601PIC18C801
TQFPPLCCTQFPPLCCDescription
716920
—1, 18,
35, 52
39504962
40515063
—1, 22,
43, 64
Pin
Type
——These pins should be left
Buffer
Type
I
P
IICMOS/ST
O
O
STMaster clear (RESET) input. This pin is
CMOS
—
—
an active low RESET to the device.
Programming voltage in put.
unconnected.
Oscillator crystal inp ut or ex te rnal clock
source input. ST buffer when in RC
mode. Otherwise CMOS.
External clock source inp ut.
Always associated with pi n f unction
OSC1 (see OSC1/CLKI, OSC2/CLKO
pins).
Oscillator crystal outp ut .
Connects to crystal or resonator in
Crystal Oscillator mode.
In RC mode, OSC2 pin ou tp ut s C LKO,
which has 1/4 the
frequency of OSC1 an d den ot es the
instruction cycle rate.
DD)
DS39541A-page 12Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
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/VREF+
RA4/T0CKI
RA5/AN4/SS
Legend:TTL = TTL compatible i nput CMOS = CMOS compatible input or output
REF-
RA2
AN2
REF-
V
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
PIC18C601PIC18C801
TQFPPLCCTQFPPLCCDescription
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) inp ut .
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 .
Legend:TTL = TTL compatible 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
PIC18C601PIC18C801
TQFPPLCCTQFPPLCCDescription
——3952
——4053
——4154
——4255
——5973
——6074
——6175
——6276
41, 56
38, 57
19, 36,
53, 68
2, 20,
37, 49
11,31,
51, 70
12,32,
48, 71
23, 44,
65, 84
2, 24,
45, 61
Pin
Type
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
Buffer
Type
PORTJ is a bi-directional I/O port.
ST
TTL
ST
TTL
ST
TTL
ST
TTL
ST
TTL
ST
TTL
ST
TTL
ST
TTL
P—Ground reference for logic and I/O pins.
P—Positive supply fo r logic and I/O pins.
Digital I/O.
System bus data bit 0.
Digital I/O.
System bus data bit 1.
Digital I/O.
System bus data bit 2.
Digital I/O.
System bus data bit 3.
Digital I/O.
System bus data bit 4.
Digital I/O.
System bus data bit 5.
Digital I/O.
System bus data bit 6.
Digital I/O.
System bus data bit 7.
DD)
DS39541A-page 20Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
2.0OSCILLATOR
CONFIGURATIONS
2.1Oscillator Types
PIC18C601/801 can be operated in one of four o sc ill ator modes, programmable by configuration bits
FOSC1:FOSC0 in CONFIG1H register:
1.LPLow Power Crystal
2.HSHigh Speed Crys tal/Resonator
3.RCExternal Resistor/Capacitor
4.ECExternal Clock
2.2Crystal Oscillator/Ceramic
Resonators
In LP or HS oscillator modes, a crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to
establish oscillation. Figure 2-1 shows the pin connections. An external c lock so urce may also be connecte d
to the OSC1 pin, as shown in Figure 2-3 and Figure 2-4.
PIC18C601/801 oscillator design requires the use of a
parallel cut crystal.
Note:Use of a series cut crystal may give a fre-
quency out of the crystal manufacturer’s
specifications.
of the oscillator, but also increases the
start-up time.
3: Since each resonator/crystal has its own
characteristics, the u ser shoul d consult th e
resonator/crystal manufacturer for appropriate values of external components.
4: Rs may be required in HS mode to avoid
overdriving crystals with low drive level
specification.
2.3RC Oscillator
For timing insensitive applications, the "RC" oscillator
mode offers additional cost savings. The RC oscillator
frequency is a function of the supply volta ge, t he re sis -
EXT) and capacitor (CEXT) values and the operat-
tor (R
ing temperature. In addition to this, the oscillator
frequency will vary from unit to unit due to normal process paramete r variatio n. Further more, the d ifference
in lead frame capacitance between package types will
also affect the oscillation frequency, especially for low
EXT values. The user also needs to take into account
C
variation due t o t ole ranc e of ex ter nal R an d C c om ponents used. Figu re 2-2 shows how the RC comb inatio n
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
OSC/4
F
or I/O
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
OSC2/CLKO
C
EXT > 20pF
PIC18C601/801
Internal
Clock
DS39541A-page 22Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
2.4External Clock Input
The EC oscillator mode requires an external clock
source to be con nected to the OSC1 p in. The fe edback
device between O S C1 a nd OSC2 is turned off in these
modes to save current. There is no oscillator 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 connections for the EC
oscillator mode.
FIGURE 2-3:EXTERNAL CLOCK INPUT
OPERATION (EC OSC
CONFIGURATION)
Clock from
ext. system
OSC/4
F
FIGURE 2-4:PLL BLOCK DIAGRAM
OSC1
PIC18C601/801
OSC2
2.5HS4 (PLL)
A Phase Lock Loop (PLL) circuit is provided as a software programmable optio n for us ers tha t want to m ultiply the frequency of the incoming crystal oscillator
signal by 4. For an input clock frequency of 6 MHz, th e
internal clock frequency will be multiplied to 24 MHz.
This is use ful for custom ers who are conc erned with
EMI due to high frequency crystals.
The PLL is enabled by configuring HS oscillator mode
and setting the PLLEN bit in the OSCON register. If HS
oscillator mode is not selected, or PLLEN bit in
OSCCON register is clear, the PLL is not enabled and
the system clock will come directly from OSC1. HS
oscillator mode i s the d efa ult fo r PIC 1 8C60 1/80 1. In all
other modes, the PLLEN bit and the SCS1 bit are
forced to ‘0’.
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
PIC18C601/801 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 PIC18C601/801 devices, this alternate clock
source is the Timer1 oscillator. If a low frequency crystal (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-5 shows a block diagram of
the system clock sources.
FIGURE 2-5:DEVICE CLOCK SOURCES
PIC18C601/801
OSC2
OSC1
T1OSO
T1OSI
Main Oscillator
SLEEP
Timer 1 Oscillator
T1OSCEN
Enable
Oscillator
2.6.1SYSTEM CLOCK SWITCH BIT
The system clock source switching is performed under
software control. The system clock switch bit, SCS0
(OSCCON register), controls the clock switching. When
the SCS0 bit is ’0’, the system clock source comes from
the main oscillator, selected by the FOSC2:FOSC0 co nfiguration bits in C ONFIG1H registe r . When the SCS0 b it
is set, the system clock source will come from the Timer1
oscillator . The SCS0 bit is cle ared on all forms of RESET.
Note:The Timer1 oscillator must be enabled to
switch the system clock source. The
Timer1 oscillator is enabled by setting the
T1OSCEN bit in the T imer1 c ontrol register
(T1CON). If the Timer1 oscillator is not
enabled, an y write to the SCS0 bi t will be
ignored (SCS0 bit forced cleared) and the
main oscillator will continue to be the system clock source.
OSC/4
4 x PLL
TOSC
TT1P
T
MUX
Clock
Source
TSCLK
Clock Source option
for other modules
Note: I/O pins have diode protection to VDD and VSS.
DS39541A-page 24Advance Information 2001 Microchip Technology Inc.
REGISTER 2-1:OSCCON REGISTER
U-0U-0U-0U-0R/W-0R/W-0R/W-0R/W-0
————LOCKPLLENSCS1SCS0
bit 7bit 0
bit 7-4Unimplemented: Read as '0'
bit 3LOCK: Phase Lock Loop Lock Status bit
1 = Phase Lock Loop output is stable as system clock
0 = Phase Lock Loop output is not stable and cannot be used as system clock
bit 2PLLEN: Phase Lock Loop Enable bit
1 = Enable Phase Lock Loop output as system clock
0 = Disable Phase Lock Loop
bit 1SCS1: System Clock Switch bit 1
When PLLEN and LOCK bit are set:
1 = Use PLL output
0 = Use primary oscillator/clock input pin
When PLLEN bit or LOCK bit is cleared:
Bit is forced clear
bit 0SCS0: System Clock Switch bit 0
When T1OSCEN bit is set:
1 = Switch to Timer1 oscillator/clock pin
0 = Use primary oscillator/clock input pin
When T1OSCEN is cleared:
Bit is forced clear
PIC18C601/801
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2.6.2OSCIL LA T OR TRANSITIONS
PIC18C601/801 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 indicati ng the transition from the main
oscillator to the Timer1 oscillator is shown in Figure 2-6.
The Timer1 oscillator is assumed to be running all the
time. After the SCS0 bit is set, the processor is frozen
at the next occurri ng Q1 c ycle . Af ter eig ht sy nchroniz ation cycles are counted from the T imer1 oscilla tor, operation resumes. No additional delays are required after
the synchronization cycles.
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, LP), the transition will ta ke pl ac e a f ter an oscillator start-up time (T
diagram indicating the transition from the Timer1 oscillator to the main oscillator for HS and LP modes is
shown in Figure 2-7.
FIGURE 2-6:TIMING DIAGRAM FOR TRANSITION FROM OSC1 TO TIMER1 OSCILLATOR
Q1
T1OSI
OSC1
Internal
System
Clock
SCS0
(OSCCON<0>)
Program
Counter
Note: Delay on internal system clock is eight oscillator cycles for synchronization.
TOSC
Q1
TDLY
TT1P
2134 5678
TSCS
PC + 2PC
Q3Q2Q1Q4Q3Q2
Q4Q1
Q2Q3Q4Q1
PC + 4
FIGURE 2-7:TIMING DIAGRAM FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS, LP)
Q3
T1OSI
OSC1
OSC2
Internal System
Clock
SCS0
(OSCCON<0>)
Q3Q4
Q1
12345678
TOST
TOSC
TT1P
TSCS
Q1 Q2 Q3 Q4 Q1 Q2
Program Counter
Note: TOST = 1024TOSC (drawing not to scale).
PC
PC + 2
PC + 4
DS39541A-page 26Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
If the main oscillator is configured for HS4 (PLL) mode
with SCS1 bit set to ‘1’, an oscillator start-up time
(T
OST), plus an additional PLL time-out (TPLL) will
occur . The PLL tim e-out is typica lly 2 ms an d allows the
PLL to lock to the main oscillator frequency. A timing
diagram indicating the transition from the Timer1 oscillator to t he main oscill ator for HS4 m ode is shown in
Figure 2-8.
If the main oscill ator is confi gured for HS4 (PLL) m ode,
with SCS1 bit set to ‘0’, only oscillator start-up time
OST) will occur. Since SCS 1 bi t is se t to ‘0’, PLL out-
(T
put is not used, so the sys te m os ci ll ator w i ll c ome from
OSC1 directly and additional delay of TPLL is not
required. A timing diagram indica ting the transit ion from
the Timer1 oscillator to the main oscillator for HS4
mode is shown in Figure 2-9.
If the main oscillator is configured in the RC or EC
modes, there is no osci llator sta rt-up t ime-out. Operation will resume af ter ei ght cycle s of the m ain osc il lator
have been counted. A timing diagram indicating the
transition from the T ime r1 osci llator to the main os cill ator for RC and EC modes is shown in Figure2-10.
FIGURE 2-8:TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS4 WITH SCS1 = 1)
Q3
PC + 4
Q4
T1OSI
OSC1
OSC2
PLL Clock
Input
Internal System
Program Counter
Clock
SCS0
(OSCCON<0>)
Q4Q1
TOST
PCPC + 2
TPLL
TOSC
TT1P
TSCS
12345678
Q1 Q2 Q3 Q4 Q1 Q2
OST = 1024TOSC (drawing not to scale).
Note: T
FIGURE 2-9:TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS4 WITH SCS = 0)
FIGURE 2-10:TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (RC, EC)
Q3Q4
Q1
TT1P
Q1 Q2 Q3 Q4 Q1 Q2 Q3
Q4
T1OSI
OSC1
OSC2
Internal System
Clock
SCS0
(OSCCON<0>)
Program Counter
Note: RC oscillator mode assumed.
PCPC + 2
2.6.3SCS0, SCS 1 PRIORITY
If both SCS0 and SCS1 are set to ‘1’ simultaneously,
the SCS0 bit has priority over the SCS1 bit. This means
that the low power option will t ake prece dence over the
PLL option. If both bit s are cle ared si mult a neous ly, the
system clock will come from OS C1, after a TOST timeout. If only the SCS0 bit is c leared, the system c lock will
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 the os ci lla tor o f f, 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-chip feature
that will operate during SLEEP, will increase the cur-
TOSC
1
45678
23
TSCS
PC + 4
rent 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 delays are controlled by two timers, so that
no external RESET circuitry is required for most applications. The delays ensure that the device is kept in
RESET until the device power sup ply and clock are st able. For additional information on RESET operation,
see Section 3.0 RESET .
The first timer is the Power-up Ti mer (PWRT), which
optionally provides a fixed delay of T
#33) on power-up only. The second timer is the Oscillator St art-u p T i mer (O ST), in tended to keep the c hip in
RESET until the crystal oscillator is stable.
PIC18C601/801 devices provide a configuration bit,
PWRTEN
in CONFIG2L register, to enable or disable
the Power-up Timer. By default, the Power-up Timer is
enabled.
With the PLL enabled (HS4 osc illator mode), the time-ou t
sequence fol lowing a Power-o n Reset is different fr om
other oscillator modes. The time-out sequence is as follows: the PWRT time-out is invoked after a POR time
delay has expired, then, the Oscillator Start-up Timer
(OST) is i nvoked. However, this is still not a sufficie nt
amount of time to allow the PLL to lock at high frequencies. The PWRT ti mer is used to prov ide an addition al
time-out, called T
PLL (parameter #7), to allow the PLL
ample time to l oc k to the incoming cl oc k frequency.
PWRT (parameter
TABLE 2-4:OSC1 AND OSC2 PIN STATES IN SLEEP MODE
OSC ModeOSC1 PinOSC2 Pin
RCFloating, external resistor should pull highAt logic low
ECFloatingAt logic low
LP and HS Feedback inverter disabled, at quiescent voltage level Feedback inverter disabled, at quiescent voltage level
Note:See Table 3-1 in Section 3.0 RESET, for time-outs due to SLEEP and MCLR Reset.
DS39541A-page 28Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
3.0RESET
Most registers are not affected by a WDT wake-up,
since this is viewed as the resumption of normal oper-
PIC18C601/801 devices differentiate between various
kinds of RESET:
a)Power-on Reset (POR)
b)MCLR
Reset during normal operation
c)MCLR Reset during SLEEP
d)Watchdog Timer (WDT) Reset during normal
operation
e)RESET Instruction
f)Stack Full Reset
g)Stack Underflow Reset
Most registers are una ffected b y a RESET. Their status
is unknown on POR and unchanged by all other
ation. Status bits from the RCON regi ster, RI
and POR, are set or cleared differently in different
RESET situations, as i ndicated in 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.
PIC18C601/801 has a MCLR
noise filter in the MCLR
Reset path. The filter will detect and ignore small
pulses.
A WDT Reset does not drive MCLR
pin low.
RESETS. The other registers are forced to a “RESET”
state on Power-on Reset, MCLR
, WDT Reset, MCLR
Reset during SLEEP, and by the RESET instruction.
FIGURE 3-1:SIMPLIFIED BLOCK DIAGRAM OF THE ON-CHIP RESET CIRCUIT
RESET
Instruction
Stack
Pointer
Stack Full/Underflow Reset
External Reset
, TO, PD
MCLR
WDT
Module
VDD Rise
VDD
OSC1
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
DD rise is detected. To take advantage of the POR cir-
V
cuitry, connect the MCLR
resistor) to V
DD. This will eliminate ext ernal RC compo-
nents usually needed to create a Power-on Reset
delay . A minimum rise rat e for V
eter 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, etc.) must be met to
ensure operation. If these conditions are not met, the
device must be held in RESET until the operating conditions are m et . Po wer - on R e s et ma y b e us ed t o m ee t
the voltage start-up condition.
FIGURE 3-2:EXTERNAL POWER-ON
V
DD
D
R
C
Note 1: External Power-on Reset circuit is required only
2: R < 40 kΩ is recommended to make sure that
3: R1 = 100Ω to 1 kΩ will limit any current flowing
DD power-up slope is too slow. The diode
if the V
D helps discharge the capacitor quickly when
V
DD powers down.
the voltage drop across R does not violate the
device’s electrical specification.
into MCLR
event of MCLR/
Electrostatic Discharge (ESD), or Electrical
Overstress (EOS).
pin directly (or through a
DD is specified (p aram-
RESET CIRCUIT (FOR
SLOW V
from external capacitor C, in the
VPP pin breakdown due to
DD POWER-UP)
R1
MCLR
PIC18C601/801
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 (para meter #32). Th is ensures th at
the crystal oscillator or resonator has started and
stabilized.
The OST time-out is invoked only for 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 1 ms and follows the oscillator start-
(T
up time-out (OST).
3.5Time-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 th e PWRT. For example, in RC mode wi th
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 occur from the POR pulse, if MC LR
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 than one PIC18C601/801 device
operating in parallel.
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
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. Th e PWRT t ime de lay al lows V
acceptable level. PIC18C601/801 devices are available with PWRT enabled or disabled.
The power-up time delay wi ll vary from chip to chi p, due
DD, temperature and process variation. See DC
to V
parameter #33 for details.
DS39541A-page 30Advance Information 2001 Microchip Technology Inc.
DD to rise to an
PIC18C601/801
TABLE 3-1:TIME-OUT IN VARIOUS SITUATIONS
Oscillator
Configuration
HS with PLL enabled
HS, LP72 ms + 1024T
(1)
Power-up
PWRTEN = 0PWRTEN = 1
72 ms + 1024TOSC1024TOSC1024TOSC + 1 ms
OSC1024TOSC1024TOSC
(2)
EC72 ms——
External RC72 ms——
Note 1: 1 ms is the nominal time required for the 4X PLL to lock. Maximum time is 2 ms.
2: 72 ms is the nominal Power-up Timer delay.
REGISTER 3-1:RCON REGISTER BITS AND POSITIONS
R/W-0U-0U-0R/W-1R/W-1R/W-1R/W-1U-0
IPENr
bit 7bit 0
—RITOPDPORr
Wake-up from
SLEEP or
Oscillator Switch
(1)
TABLE 3-2:STATUS BITS, THEIR SIGNIFICANCE, AND THE INITIALIZATION CONDITION FOR
RCON REGISTER
Condition
Power-on Reset
MCLR Reset during normal
Program
Counter
00000h0r-1 110r1110uu
00000h0r-u uuuruuuuuu
operation
Software Reset during normal
00000h0r-0 uuur0uuuuu
operation
Stack Full Reset during normal
00000h0r-u uu1ruuu1u1
operation
Stac k Underfl ow Rese t during normal
00000h0r-u uu1ruuu11u
operation
MCLR Reset during SLEEP
WDT Reset
00000h0r-u 10uru10uuu
00000h0r-u 01uru01uuu
WDT Wake-upPC + 2
Interrupt wake-up from SLEEPPC + 2
(1)
Legend: u = unchanged, x = unknown,- = unimplemented bit, read as '0', r = reserved, maintain ‘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
Legend: u = unchanged, x = unknown, - = unimplem ented b it, read as ’0’, q = value depends on condition,
r = reserved, maintain ‘0’
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL o r GIE H bit is s et, the PC i s load ed with th e interr upt
vector (00008h or 00018h).
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 SKPTR is modified to point to the next location in the
hardware stack.
4: See Table3-2 for RESET value for specific condition.
5: This is not a physical register. It is an indirect pointer that addresses another register. The contents
returned is the value contained in the addressed register.
WDT Reset
Reset Instruction
Wake-up via WDT or
Interrupt
(3)
(3)
(3)
(3)
(2)
(1)
(1)
(1)
DS39541A-page 34Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
TABLE 3-3:INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED)
Legend: u = unchanged, x = unknown, - = unimplem ented b it, read as ’0’, q = value depends on condition,
r = reserved, maintain ‘0’
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIE H bit is s et, the PC i s load ed with th e interru pt
vector (00008h or 00018h).
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 SKPTR is modified to point to the next location in the
hardware stack.
4: See Table3-2 for RESET value for specific condition.
5: This is not a physical register. It is an indirect pointer that addresses another register. The contents
returned is the value contained in the addressed register.
Legend: u = unchanged, x = unknown, - = unimplem ented b it, read as ’0’, q = value depends on condition,
r = reserved, maintain ‘0’
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL o r GIE H bit is s et, the PC i s load ed with th e interr upt
vector (00008h or 00018h).
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 SKPTR is modified to point to the next location in the
hardware stack.
4: See Table3-2 for RESET value for specific condition.
5: This is not a physical register. It is an indirect pointer that addresses another register. The contents
returned is the value contained in the addressed register.
Applicable
Devices
601801-111 1111-111 1111-uuu uuuu
601801-000 0000-000 0000-uuu uuuu
601801-000 0000-000 0000-uuu uuuu
Power-on Reset
Stac k Over/ Unde rflo w Reset
WDT Reset
Reset Instruction
Wake-up via WDT or
Interrupt
(1)
(1)
(1)
DS39541A-page 36Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
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 interrupt and the GIEL or GIE H bit is s et, the PC i s load ed with th e interru pt
vector (00008h or 00018h).
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 SKPTR is modified to point to the next location in the
hardware stack.
4: See Table3-2 for RESET value for specific condition.
5: This is not a physical register. It is an indirect pointer that addresses another register. The contents
returned is the value contained in the addressed register.
DS39541A-page 38Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.0MEMORY ORGANIZATION
There are two memory blocks in PIC18C601/801
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
PIC18C601/801 devices have a 21-bit program
counter that is capable of addressing up to 2 Mbyte of
external program memory space. The PIC18C601 has
an external program memory address space of 256
Kbytes. Any program fetch or TBLRD from a program
location greater than 256K will return all NOPs. The
PIC18C801 has an external program memory address
space of 2Mbytes. Refer to Section 5.0 (“External
Memory Interface”) for additional details.
The RESET vector address is mapped to 000000h and
the interrupt vector addresses are at 000008h and
000018h. PIC18C601/801 devices have a 31-level st ack
to store the program counter values during subroutine
calls and interrupts. Figure 4-1 shows the program
memory map and stack for PIC18C601. Figure 4-2
shows the program memory map and stack for the
PIC18C801.
4.1.1“BOOT RAM” PROGRAM MEMORY
PIC18C601/801 devices have a provision for configuring the last 512 bytes of general purpose user RA M a s
program memory, called “Boot RAM”. This is achieved
by configuring the PGRM bit in the MEMCON register
to ‘1’. (Refer to Section 5.0, “External Memory Interface” for more information.) When the PGRM bit is ‘1’,
the RAM located in data memory locations 400h
through 5FFh (bank 4 throug h 5) is mapped to pro gram
memory locations 1FFE00h to 1FFFFFh.
When configured as program memory, the Boot RAM is
to be used as a te mporary “boot loader” for programming purposes. It can on ly be used for pro gram exec ution. A read from locations 400h to 5FFh in data
memory returns all ‘0’s. Any attempt to write this RAM
as data memo ry when PGRM = 1, d oes no t mod ify an y
of these locations. TBLWT instructions to these locations will cause wr ites to o ccur on the ex ternal memor y
bus. The boot RAM program memory cannot be modified using TBLWT instruction. TBLRD in structions fr om
boot RAM will read memory located on the external
memory bus, not from the on-board RAM. Constants
that are stored in boot RAM are retrieved using the
RETLW instruction.
The default RESET state (power-up) for the PGRM bit
is ‘0’, which configures 1.5K of data RAM and all program memory as external. The PGRM bit can be set
and cleared in the softwar e.
When execution takes place from “Boot RAM”, the
external system bus and all of its control signal s will be
deactivated. If execution takes place from outside of
“Boot RAM”, the external s ystem bu s and all of its co ntrol signals are activated again.
Figure 4-3 and Figure 4-4 show the program memory
map and stack for PIC18C601 and PIC18C801, when
the PGRM bit is set.
FIGURE 4-4:PROGRAM MEMORY MAP AND STACK FOR PIC18C801 (PGRM = 1)
PC<20:0>
Stack Level 1
•
•
•
Stack Level 31
21
RESET Vector
High Priority Interrupt Vector
Low Priority Interrupt Vector
External
Program Memory
0000h
0008h
0018h
User Memory Space
On-Chip
Boot RAM
1FFE00h
1FFFFFh
1FFDFFh
1FFE00h
External
Table Memory
1FFFFFh
EXTERNAL MEMORYINTERNAL MEMORY
DS39541A-page 42Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.1.2BOOT LOADER
When configured as Program Memory, Boot RAM can
be used as a temporary “Boot Loader” for programming
purposes. If an external memory device is used as program memory, any updates performed by the user program will have to be performed in the “Boot RAM”,
because the user program cannot program and fetch
from external memory, simultaneously.
A typical boot loader execution and external memory
programming sequence would be as follows:
• The boot loader program is transferred from the
external program memory to the last 2 banks of
data RAM by TBLRD and MOVWF instructions.
• Once the “boot loader” program is loaded into
internal memory and verified, open combination
lock and set PGRM bit to con figure the data RAM
into program RAM.
• Jump to beginning of Boot code in Boot RAM.
Program execution begins in Boot RAM to begin
programming the external memory. System bus
changes to an inactive state.
• Boot loader program performs the necessary
external TBLWT and TBLWRD instructions to
perform programming functions.
• When the boot loader program is finished programming external memory, jump to known valid
external program memory location and clear
PGRM bit in MEMCON register to set Boot RAM
as data memory, or reset the part.
4.2Return Address St ack
The return address stack allows any combination of up to
31 program call s and interrup ts to occur. The PC (Program Counter) is pushed on to 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 instruction. 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 five-bit stack poin ter, with the stack p ointer i nitia lized to 00000b after all RESETS. There is no RAM associated with stack p oi nte r 00000b. Th is is only a RESE T
value. During a CALL type instruction, causing a push
onto the stack, the stack pointer is first incremented and
the RAM locati on pointed t o by the sta ck pointer i s written
with the contents of the PC. During a RETURN type
instruction, caus ing a pop fr om th e st ack , the c onte nt s of
the RAM location indicated by the STKPTR is transferred
to the PC and th en the stack pointer is decremen ted .
The stack space is not part of either program or data
space. The stac k p oi n ter i s r e adab l e a n d wr i tab le, a nd
the data on the top of the st ack is readable and writable
through SFR registers. Status bits STKOVF and
STKUNF in STKPTR register, indicate whether stack
over/underflow has occurred or not.
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 con tents of the stack loc ation indicated by
the STKPTR register. This allows users to implement a
software stack, if n ece ssary. After a CALL, RCALL or
interrupt, the software can read the pushed value by
reading the TOSU, TOSH and TOSL registers. These
values can be placed on a user defined software stack.
At return time, the software can replace the TOSU,
TOSH and TOSL and do a return.
The user should disable the global interrupt enable bits
during this time to prevent inadvertent stack operations.
4.2.2RETURN STACK POINTER
(STKPTR)
The STKPTR register contains the stack pointer 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 pointer 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 valu e. This featu re can b e used by a Rea l
Time Operating System for return stack maintenance.
After the PC is push ed ont o the s tac k 31 times (w itho ut
popping any values off the stack), the STKFUL bit is
set. The STKFUL bit can o nly be cle ared in sof tware or
by a POR. Any subse quent pus h operatio n that cau ses
stack overflow will be ignored.
The action that takes place when the stack becomes
full, depends on the state of STVREN (stack overflow
RESET enable) configuration bit in CONFIG4L register. Refer to Section 4.2.4 for more information. If
STVREN is set (default), stack over/underflow will set
the STKFUL bit, and reset th e de vi ce. The ST KFU L b it
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 st ack pointer will incr ement to 31. Al l
subsequent push attempts will be ignored and
STKPTR remains at 31.
When the stack has been popped enough times to
unload the stac k, the next pop will ret urn a value of zero
to the PC and sets the STKUNF bit, while the stack
pointer remains at 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 verifi ed and appropriate actions can be taken.
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
FIGURE 4-5:RETURN ADDRESS STACK AND ASSOCIATED REGISTERS
Return Address Stack
11111
11110
TOSLTOSHTOSU
34h1Ah00h
Top-of-Stack
Note 1: No RAM is associated with this address; always maintai ned ‘0’s.
001A34h
000D58h
000000h
11101
00011
00010
00001
00000
STKPTR<4:0>
00010
(1)
DS39541A-page 44Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.2.3PUSH AND POP INSTRUCTIONS
Since the Top-of-Stac k (TOS) is readable and writable,
the ability to push val ues onto the st ack and pop va lues
off the sta ck, withou t disturbi ng normal program ex ecution, is a desirable optio n. To push the current PC value
onto the stack, a PUSH instruction can be executed.
This will i ncrem ent th e stack point er and load the cu rrent 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/dis abled by programmin g
the STVREN configuration bit in CONFIG4L register.
When the STVREN bit is disabled, a full or underflow
condition will set the appropriate STKFUL or STKUNF
bit, but not cause a RESET. When the STVREN bit is
enabled, a full or underflow will set the appropriate
STKFUL or STKUNF bit and then cause a RESET. The
STKFUL or STKUNF bits are only cleared by the user
software or a POR.
4.3Fast Register Stack
A “fast ret urn” option is available for interrupts and calls.
A fast register stack is provided for the STATUS, WREG
and BSR registers, and is only on e layer i n depth . The
stack is not readable or writable and is loaded wit h the
current value of the corresponding register 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 instructi o n is us e d to re tu rn
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 stored by the low priority
interrupt will be overwritten.
If high priority inte rrupts a re not dis abled duri ng low pr iority 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 STATUS, W REG and BSR re gisters
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 show s a source c ode exam ple that us es
the fast register stack.
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 contai ns the PC<20 :16> bi ts an d is not directl 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 the PCL is fix ed 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-6:CLOCK/INSTRUCTION CYCLE
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 OSC 1 or PLL output) is int ernall y
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 fetc hed from the program memor y
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-6.
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(RC mode)
Q2Q3Q4
Q1
PC
Fetch INST (PC)
Execute INST (PC-2)
Q2Q3Q4
Q1
PC+2PC+4
Fetch INST (PC+2)
Execute INST (PC)Fetch INST (PC+4)
Q2Q3Q4
Q1
Execute INST (PC+2)
Internal
Phase
Clock
DS39541A-page 46Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.6Instruction Flow/Pipelining
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. Dat a 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 ins tructions have an absol ute 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 0x06” 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 branch instruction represents the numb er of single word inst ructio ns by w hich
the PC will be offset. Section 20.0 provides further
details of the instruction set.
Fetch 4Flush
Fetch SUB_1 Execute SUB_1
All instructions are s ingle cycle, exce pt for any program br anches. These t ake two cycles , since the fetch in struction
is “flushed” from the pipeline, while the new instruction is being fetched and then executed.
PIC18C601/801 devices have four two-word instructions: MOVFF, CALL, GOTO and LFSR. The second
word of these instructions has the four MSB’s set to 1’s
and is a special kind of NOP instruction. The lower 12
bits of the second word contain data to be used by the
instruction. If the first word of the instruction is executed, the data in the second word is accessed. If the
second word of the in struction is executed by itself (firs t
word was skipped), i t will ex ecute as a NOP. This action
is necessary when the two-word ins truction is prec eded
by a conditional instruction that changes the PC and
skips one instruction. A program example that demonstrates this concept is shown in Example 4-3. Refer to
Section 19.0 for further details of the instruction set.
4.8Lookup Tables
Lookup tables are implemented two ways:
• Computed GOTO
• Table Reads
4.8.1COMPUTED GOTO
A computed GOTO is accomplish ed by adding an offs et
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, before executing a call to that t able. Th e first instruction of the c alled
routine is the ADDWF PCL instruction. The next instruc-
tion executed will be one of t he RETLW 0xnn instructions that returns the value 0xnn to the calling fu nc ti on .
The offset v alue (val ue in WR EG) sp ecifies the numb er
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 the PCL is fixed to a value of ‘0’.
Hence, computed GOTO to an odd add ress
is not possible.
4.8.2TABLE READS/TABLE WRITES
A better method of storing data in program memory
allows 2 bytes of data to be stored in each instruction
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 6.0.
Note:If execution is taking place from Boot RAM
Program Memory, RETLW instructions
must be used to read lookup values from
the Boot RAM itself.
EXAMPLE 4-3:Two-Word Instructions
CASE 1:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2; No, execute 2-word instruction
1111 0100 0101 0110; 2nd operand holds address of REG2
0010 0100 0000 0000ADDWFREG3; continue code
CASE 2:
Object CodeSource Code
0110 0110 0000 0000TSTFSZREG1; is RAM location 0?
1100 0001 0010 0011MOVFFREG1, REG2; Yes
1111 0100 0101 0110; 2nd operand executed as NOP
0010 0100 0000 0000ADDWFREG3; continue code
DS39541A-page 48Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.9Data Memory Organization
The data memory is implemented as static RAM. Each
register in the data memory has a 12-bi t address , all owing up to 4096 bytes of data memory. Figure 4-8 shows
the data memory organization for PIC18C601/801
devices.
The data memory map is divided into banks that contain 256 bytes each. The lower four bits of the Bank
Select Register (BSR<3:0>) select which bank will be
accessed. Th e upp er 4 bits fo r the B SR are no t imp lemented.
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 function s, while 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
(0FFFh) and grow downwards. GPR’s start at the first
location of Bank 0 and grow upwards. Any read of an
unimplemented location will read as ’0’s.
GPR banks 4 and 5 serve a s a Program Memory called
“Boot RAM”, when PGRM bit in M EMCON is set. When
PGRM bit is set, any read from “Boot RAM” returns ‘0’s,
while any write to it is ignored.
The entire data memory may be accessed directly or
indirectly. Direct addressing may require the use of the
BSR register. Indirect addressing requires the use of a
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 the MOVFF instruction. The
MOVFF instruction is a two-word/two-cycle instruction
that moves a value from one register to another.
To ensure that commonly used registers (SFRs and
select GPRs) 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 bank. Section 4.10 provides a detailed description of the Access bank.
4.9.1GENERAL PURPOSE REGISTER
FILE
The register file can b e access ed eithe r dire ctly o r indirectly. Indirect addressing operates through the File
Select Registers (FSR). The operation of indirect
addressing is shown in Section 4.12.
PIC18C601/801 devices have banked memory in the
GPR area. GPRs 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 (0F80h to 0FFFh) 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 (SFRs) are registers
used by the CPU and Peripheral Modules for controlling the desired operation of the device. These registers are implemented as static RAM. 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 SFRs are typica lly d istrib uted a mong the per ipherals whose functions they control.
The unused SFR locations are unimplemented and
read as '0's. See Table 4-2 for addresses for th e SFRs.
4.9.3SECURED ACCESS REGISTERS
PIC18C601/801 devices contain software programming options for safety critical peripherals. Because
these safety critical peripherals can be programmed in
software, registers used to control these peripherals
are given limited access by the user code. This way,
errant code will not accidentally change settings in
peripherals that could cause catastrophic results.
The registers that are considered safety crit ical are the
Watchdog Timer register (WDTCON), the External
Memory Control register (MEMCON), the Oscillator
Control register (OSCCON) and the Chip Select registers (CSSEL2 and CSELIO).
Two b its called Combinati on Lock (CMLK) bits , loc ate d
in the lower two bits of the PSPCON register, must be
set in sequence by user code to gain access to
Secured Access registers.
bit 7-2Unimplemented: Read as '0'
bit 1-0CMLK<1:0>: Combination Lock 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
The Combination Lock bits must be set sequentially,
meaning that as soon as Combinat ion Lock b it CMLK1
is set, the second Combination Lock bit CMLK0 must be
set on the following instruction cycle. If user waits more
than one machine cycle to set the second bit after setting the first, both bits will automatically be cleared in
hardware and the lock will remain closed. T o satisfy this
condition, all interrupts must be disabled before attempting to unlock the Combination Lock. Once secured registers are modified, interrupts may be re-enabled.
Each instruction must only modify one combination lock
bit at a time. This means, user code must use the BSF
instruction to set CMLK bits in the PSPCON register.
Note:The Combination Lock bits are write-only
When the Combination Lock is opened, the user will
have three instruction cycles to modify the safety critical register of choice. After three instruction cycles
have expired, the CMLK bits are cleared, the lock will
close and the user will have to set the CMLK bi ts again,
in order to open the lock. Since there are only three
instruction cyc les allowed af ter the Combina tion Lock is
opened, if a subroutine is used to unlock Combination
Lock bits, user code must preload WREG with the
desired value, call unlock subroutine, and write to the
desired safety critical register itself.
Note:Successive attempts to unlock the Combi-
nation Lock must be separated by at least
three instruction cycles.
bits. These bits will always return ‘0’ when
read.
EXAMPLE 4-4:COMBINATION UNLOCK SUBROUTINE EXAMPLE CODE
BCF INTCON, GIE; Disable all interrupts
; Lock is closed
MOVLW 5Ah ; Preload WREG with data to be stored in a safety critical register
CALL UNLOCK ; Now unlock it
; Write must take place in next instruction cycle
MOVWF OSCCON
BSF INTCON, GIE; Re-enable interrupts
•
•
UNLOCK
BSF PSPCON, CMLK1
BSF PSPCON, CMLK0
RETURN
•
•
DS39541A-page 50Advance Information 2001 Microchip Technology Inc.
When a = 0,
the BSR is ignored and this
Access RAM bank is used.
The first 128 bytes are General
Purpose RAM (from Bank 0).
The next 128 bytes are Special
Function Registers (from
Bank 15).
When a = 1,
the BSR is used to specify
the RAM location that the
instruction uses.
PIC18C601/801
FIGURE 4-8:DATA MEMORY MAP FOR PIC18C601/801 (PGRM = 1)
BSR<3:0>
= 0000b
= 0001b
= 0010b
= 0011b
= 0100b
= 1110b
= 1111b
Bank 0
Bank 1
Bank 2
Bank 3
Bank 4
to
Bank 14
Bank 15
Data Memory Map
00h
Access GPR’s
FFh
00h
FFh
00h
FFh
00h
FFh
00h
FFh
GPR
GPR
GPR
GPR
Unused
Read ’00h’
Unused
Access SFR’s
000h
07Fh
080h
0FFh
100h
1FFh
200h
2FFh
300h
3FFh
EFFh
F00h
F7Fh
F80h
FFFh
Access RAM Bank
Access Bank Low
(GPR’s)
Access Bank High
(SFR’s)
When a = 0,
the BSR is ignored and this
Access RAM bank is used.
The first 128 bytes are General
Purpose RAM (from Bank 0).
The next 128 bytes are Special
Function Re gisters (from
Bank 15).
When a = 1,
the BSR is used to specify
the RAM location that the
instruction uses.
00h
7Fh
80h
FFh
DS39541A-page 52Advance Information 2001 Microchip Technology Inc.
FFFh TOSU———Top-of-Stack Upper Byte (TOS<20:16>)---0 0000 ---0 0000
FFEh TOSHTop-of-Stack High Byte (TOS<15:8>)0000 0000 0000 0000
FFDh TOSLTop-of-Stack Low Byte (TOS<7:0>)0000 0000 0000 0000
FFCh STKPTRSTKOVFSTKUNF—Return Stack Pointer00-0 0000 00-0 0000
FFBh PCLATU———Holding Register for PC<20:16>---0 0000 ---0 0000
FFAh PCLATHHolding Register for PC<15:8>0000 0000 0000 0000
FF9hPCLPC Low Byte (PC<7:0>)0000 0000 0000 0000
FF8hTBLPTRU——rProgram Memory Table Pointer Upper Byte (TBLPTR<20:16>) --r0 0000 --r0 0000
FF7hTBLPTRHProgram Memory Table Pointer High Byte (TBLPTR<15:8>)0000 0000 0000 0000
FF6hTBLPTRLProgram Memory Table Pointer Low Byte (TBLPTR<7:0>)0000 0000 0000 0000
FF5hTABLATProgram Memory Table Latch0000 0000 0000 0000
FF4hPRODHProduct Register High Bytexxxx xxxx uuuu uuuu
FF3hPRODLProduct Register Low Bytexxxx xxxx uuuu uuuu
FF2hINTCONGIE/GIEH PEIE/GIELTMR0IEINT0ERBIETMR0IFINT0FRBIF0000 000x 0000 000u
FF1hINTCON2RBPUINTEDG0INTEDG1INTEDG2—T0IP—RBIP1111 -1-1 1111 -1-1
FF0hINTCON3INT2PINT1P—INT2EINT1E—INT2FINT1F11-0 0-00 11-0 0-00
FEFh INDF0Uses contents of FSR0 to address data memory - value of FSR0 not changed (not a physical register)N/AN/A
FEEh POSTINC0Uses contents of FSR0 to address data memory - value of FSR0 post-incremented (not a physical register)N/AN/A
FEDh POSTDEC0 Uses contents of FSR0 to address data memory - value of FSR0 post-decremented
FECh PREINC0Uses contents of FSR0 to address data memory - value of FSR0 pre-incremented
FEBh PLUSW0Uses contents of FSR0 to address data memory -value of FSR0 offset by WREG
FEAh FSR0H
FE9h FSR0LIndirect Data Memory Addres s Pointer 0 Lo w Bytexxxx xxxx uuuu uuuu
FE8h WREGWorking Registerxxxx xxxx uuuu uuuu
FE7hINDF1Uses contents of FSR1 to address data memory - value of FSR1 not changed (not a physical register)N/AN/A
FE6hPOSTINC1 Uses contents of FSR1 to address data memory - value of FSR1 post-incremented
FE5hPOSTDEC1 Uses contents of FSR1 to address data memory - value of FSR1 post-decremented
FE4hPREINC1Uses contents of FSR1 t o ad dr es s data memory - value of FSR1 pre-incre me nt ed (not a ph ys ic al re gi st er )N/AN/A
FE3hPLUSW1Uses contents of FSR1 to address data memory - value of FSR1 offset by WREG (not a physical register)N/AN/A
FE2hFSR1H
FE1h FSR1LIndirect Data Memory Addres s Pointer 1 Lo w Bytexxxx xxxx uuuu uuuu
FE0hBSR————Bank Select Register---- 0000 ---- 0000
FDFh INDF2Uses contents of FSR2 to address data memory - value of FSR2 not changed (not a physical register)N/AN/A
FDEh POSTINC2 Uses contents of FSR2 to address data memory - value of FSR2 post-incremented (not a physical register)N/AN/A
FDDh POSTDE C2 Uses contents of FSR2 to address data memory - value of FSR2 post-decremented
FDCh PREINC2Uses content s of FSR 2 t o ad dr ess dat a me mo ry - val ue of FSR 2 pre- i nc rem ent ed (n ot a phys i cal re gis t er )N/AN/A
FDBh PLUSW2Uses contents of FSR2 to add res s data memory -v alue of FS R2 of fs et by WR EG (not a ph ysic al re gister )N/AN/A
FDAh FSR2H————Indirect Data Memory Address Pointer 2 High---- xxxx ---- uuuu
FD9h FSR2LIndi rect Data Memory Address Pointer 2 Low Bytexxxx xxxx uuuu uuuu
FD8h STATUS———NOVZDCC---x xxxx ---u uuuu
Legendx = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved
Note 1: Other (non-power-up) RESETS include external RESET through MCLR
2: These registers can only be modified when the Combination Lock is open.
3: These registers are available on PIC18C 801 onl y.
(not a physical register)
(not a physical register)
(not a physical register)
————Indirect Data Memory Address Pointer 0 High---- xxxx ---- uuuu
(not a physical register)
(not a physical register)
————Indirect Data Memory Address Pointer 1 High---- xxxx ---- uuuu
(not a physical register)
and Watchdog Timer Reset.
Value on
POR
N/AN/A
N/AN/A
N/AN/A
N/AN/A
N/AN/A
N/AN/A
Value on
all other
RESETS
(1)
DS39541A-page 54Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
T ABLE 4-2:REGISTER FILE SUMMARY - PIC18C601/801 (CONTINUED)
Data Direction Control Register for PORTJ1111 1111 1111 1111
Data Direction Control Register for PORTH1111 1111 1111 1111
Read PORTJ Data Latch, Write PORTJ Data Latchxxxx xxxx uuuu uuuu
Read PORTH Data Latch, Write PORTH Data Latchxxxx xxxx uuuu uuuu
(3)
Read PORTJ Pins, Write PORTJ Data Latchxxxx xxxx uuuu uuuu
(3)
Read PORTH pins, Write PORTH Data Latchxxxx xxxx uuuu uuuu
and Watchdog Timer Reset.
Value on
POR
Value on
all other
RESETS
(1)
DS39541A-page 56Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
T ABLE 4-2:REGISTER FILE SUMMARY - PIC18C601/801 (CONTINUED)
File NameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
F84hPORTERead PORTE Pins, Write PORTE Data Latchxxxx xxxx uuuu uuuu
F83hPORTDRead PORTD pins, Write PORTD Data Latchxxxx xxxx uuuu uuuu
F82hPORTCRead PORTC pins, Write PORTC Data Latchxxxx xxxx uuuu uuuu
F81hPORTBRead PO RTB pins, Write PO RTB Data Latchxxxx xxxx uuuu uuuu
F80hPORTA——Read PORTA pins, Write PORTA Data Latch--0x 0000 --0u 0000
Legendx = unknown, u = unchanged, - = unimplemented, q = value depends on condition, r = reserved
Note 1: Other (non-power-up) RESETS include external RESET through MCLR
2: These registers can only be modified when the Combination Lock is open.
3: These registers are available on PIC18C 801 onl y.
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 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 128 bytes
in Bank 15 (SFR’s) and the lower 128 bytes in Bank 0.
These two sections will be referred to as Access Bank
High and Access Bank Low, respectively. Figure 4-8
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 Ban k High m aps
all Special Function Registers so that these registers
can be accessed without any software overhead.
4.1 1Bank Select Register (BSR)
The need for a large general purpose memory space
dictates a RAM banking scheme. 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 b e set/c le ared as ap prop ria te
for the instruction performed.
Each Bank extends up to 0FFh (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 o f indirect addr essing, which allows linear addressing of the entire RAM
space.
FIGURE 4-10:DIRECT ADDRESSING
Direct Addressing
BSR<3:0>7
bank select
Note 1: For register file map detail, see Table 4-2.
(2)
2: The access bit of the instruction can be used to force an override of the select ed bank (B SR<3: 0>) to t he
registers of the Access Bank.
MOVFF instruction embeds the entire 12-bit address in the instruction.
3: The
location select
from opcode
Data
Memory
(1)
(3)
(3)
0
00h01h0Eh0Fh
000h
0FFh
Bank 0Bank 1Bank 14Bank 15
100h
1FFh
E00h
EFFh
F00h
FFFh
DS39541A-page 58Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.12Indirect Addressing, INDF and
FSR Registers
Indirect addressing is a mode of addressing dat a memory, 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 i s to be read or written. Since
this pointer is in RAM, the cont en t s c an be mo difi ed by
the program. This can be useful for data tables in the
data memory and for software stacks. Figure 4-11
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
INDFn (0 ≤ n ≤ 2) registers. Any instruction using the
INDFn register actua lly acc esses the regi ster in dicate d
by the File Se le c t R eg ist e r, FSRn (0 ≤ n ≤ 2). Reading
the INDFn register it self indire ctly (FSRn = ’0’), will read
00h. Writing to the INDFn register indirectly, results in a
no-operation. The FSRn register contains a 12-bit
address, which is shown in Figure 4-11.
Example 4-6 shows a simple use of in direct addr essing
to clear the RAM in Bank 1 (locations 100h-1FFh) in a
minimum number of instructions.
EXAMPLE 4-6:HOW TO CLEAR RAM
(BANK 1) USING
INDIRECT ADDRESSING
LFSRFSR0, 100h;
NEXTCLRF POSTINC0; Clear INDF
; register
; & inc pointer
BTFSS FSR0H, 1; All done
; with Bank1?
BRANEXT; 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 addition al register addresses. Perform ing 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-decreme nt features, the effect on the FSR is not reflected in the
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, whe n 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 mem ory.
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 indirect addressing operation is done where the
target address is an FSRnH or FSRnL register, the
write operation will dominate over the pre- or postincrement/decrement functions.
Note 1: For register file map detail, see Table 4-2.
(1)
0FFFh
DS39541A-page 60Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
4.13STATUS Register
The STATUS register, shown in Register 4-3, 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 affect s 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. The r efore, the result of a n ins tructi on with the STATUS re gister as destination may be different than intended.
REGISTER 4-3: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 posit ive
bit 3OV: Overflow bit
This bit is used for signed arithmetic (2’s complement). It indicates an overflow of the 7-bit
magnitude, which causes the sign bit (bit 7) to change state.
1 = Overflow occurred for signed arithmetic (in th is arithmetic operation)
0 = No overflow occurred
bit 2Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1DC: Digi t carry/borrow
For arithmetic addition and subtraction 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, andRLNCF) instructions, this bit is loaded with either the bit 4, or bit 3 of the source
register.
bit 0C: Carry/borrow
For arithmetic addition and subtraction 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 (RRCF, RLCF) instruction s, t h is bi t
is loaded with either the high, or low order bit of the source register.
bit
the polarity is reversed. A subtraction is executed by adding the two’s
bit
the polarity is reversed. A subtraction is executed by adding the two’s
For example, CLRF STATUS will clear all implemented
bits and set the Z bit. This leaves the STATUS register
as ---0 0100 (where - = unimplemented).
It is recommended, therefore, that only BCF, BSF,SWAPF, MOVFF and MOVWF instructions are used to
alter the STATUS regis ter, because t hese i nstruc tions
do not affect the Z, C, DC, OV, or N bits from the
STATUS register. For other instructions which do not
affect the status bits, see Table 20-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, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
The Reset Control (RCON) register contains flag bits
that allow differentiation between the sources of a
device RESET. These flags include the TO
and RI bits. This register is readable and writable.
REGISTER 4-4:RCON REGISTER
R/W-0U-0U-0R/W-1R/W-1R/W-1R/W-0U-0
IPENr
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 6Reserved: Maintain as ‘0’
bit 5Unimplemented: Read as '0 '
bit 4RI
bit 3TO
bit 2PD
bit 1POR
bit 0Reserved: Maintain as ‘0’
: RESET Instruction Flag bit
1 = The RESET instruction was not execu ted
0 = The RESET instruction was executed causing a device RESET
(must be set in software after RESET instruction was executed)
: Watchdog Time-out Flag bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down Detection Flag bit
1 = After power-up or by the CLRWDT instruction
0 = By 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)
, PD, POR
—RITOPDPORr
Note:It is recommended that the POR bit be set
after a Power-on Reset has be en detected,
so that subsequent Power-on Resets may
be detected.
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
r = Reserved
DS39541A-page 62Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
5.0EXTERNAL MEMORY
INTERFACE
The External Memory Interface is a feature of the
PIC18C601/801 that allows the processor to access
external memory devices, such as FLASH, EPROM,
SRAM, etc. Memory mapped peripherals may also be
accessed.
The External Memory Interface physical implementation includes up to 26 pins on the PIC 18C601 and up to
38 pins on the PIC18 C801. These pi ns are reserved for
external address/data bus functions.
1 = External system bus disabled, all external bus drivers are mapped as I/O ports
0 = External system bus enabled, and I/O ports are disabled
bit 6PGRM: Program RAM Enable
1 = 512 bytes of internal RAM enabled as internal program memory from location 1FFE00h to
1FFFFFh, external program memory at these locations is unused. Internal GPR memory
from 400h to 5FFh is disabled and returns 00h.
0 = Internal RAM enabled as internal G PR memor y from 400h to 5 FFh. Program mem ory from
location 1FFE00h to 1FFFFFh is configured as external program memory.
bit 5-4WAIT<1:0>: Table Reads and Writes Bus Cycle Wait Count
11 = Table reads and writes will wait 0 TCY
10 = Table reads and writes will wait 1 TCY
01 = Table reads and writes will wait 2 TCY
00 = Table reads and writes will wait 3 TCY
bit 3-2Unimplemented: Read as '0'
bit 1-0WM<1:0>: TABLWT Operation with 16-bit Bus
1X = Word Write mode: TABLAT0 and T ABLA T1 word output, WRH active when TABLAT1 written
01 = Byte Select mode: TABLAT dat a copied on both MS and LS Byte, WRH and (UB or LB) will
activate
00 = Byte Write mode: T ABLAT data copied on both MS and LS Byte, WRH
These pins are multiplexed with I/O port pins, but the
I/O functions are o nly enabled whe n program execu tion
takes place in internal Boot RAM and the EBDIS bit in
the MEMCON register is set (see Register5-1).
5.1Memory Control Register
(MEMCON)
Register 5-1 shows the Memory Control Register
(MEMCON). This register cont ain s bit s used to contro l
the operation of the External Memory Interface.
——WM1WM0
or WRL will activate
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
The External Memory Interface can operate in 8-bit
mode. The mode sele ction is not so ftware confi gurable,
but is programmable via the configura tion bits.
There are two types of connecti ons in 8-b it mode. They
are referred to as:
• 8-bit Multiplexed
• 8-bit De-Multiplexed
5.2.18-BI T MULTIPLEXED MODE
The 8-bit Multiplexed mode applies only to the
PIC18C601. Data an d address lin es are multiplex ed on
port pins and must be decoded with glue logic.
For 8-bit Multiplexed mode on the PIC18C601, the
instructions will be fetched as two 8-bit bytes on a
Therefore, the designer must choose external memory
devices according to timing calculations based on 1/2
Tcy (2 times instruction rate). For proper memory
speed selection, glue logic propagation delay times
must be considered along with setup and hold times.
The Address Latch Enable (ALE) pin ind icate s that the
address bits A<7:0> are available on the External
Memory Interface bus. Th e OE
enable one byte of prog ram memory for a portion of th e
instruction cycle, then BA0 will change and the sec on d
byte will be enabled to form the 16-bit instruction word.
The least significant bit of the address, BA0, must be
connected to the memory devices in this mode.
Figure 5-1 shows an example of 8-bit Multiplexed
mode on the PIC18C601. The control signals used in
8-bit Multiplexed mode are outlined in Table 5-1.
Register 5-2 describes 8-bit Multiplexed mode timing.
shared data/address bus (PORTD). The two bytes are
sequentially fetched within one instruction cycle (T
CY).
FIGURE 5-1:8-BIT MULTIPLEXED MODE EXAMPLE
AD<7:0>
ALE
PIC18C601
BA0
373
D<7:0>
A<17:0>
output enable signal will
A<x:1>
A0
D<7:0>
(2)
OE
WR
CE
A16, AD<15:8>
CS1
OE
WRL
Note 1: This signal only applies to Table Writes. See Section 6.0, Table Reads and Writes.
TABLE 5-1:8-BIT MULTIPLEXED MODE CONTROL SIGNALS
Name
RG0/ALEALEAddress Latch Enable (ALE) control pin
RG1/OE
RG2/WRL
RG4/BA0BA0Byte address bit 0
RF3/CSIOCSIOChip Select I/O (See Section 5.4)
RF5/CS1
8-bit Mux
Mode
OEOutput Enable (OE) control pin
WRLWrite Low (WRL) control pin
CS1Chip Select 1 (See Section 5.4)
Function
DS39541A-page 64Advance Information 2001 Microchip Technology Inc.
FIGURE 5-2:8-BIT MULTIPLEXED MODE TIMING
PIC18C601/801
Q1
A16, AD<15:8>
AD<7:0>
BA0
ALE
OE
ABh55h
5.2.28-BIT DE-MULTIPLEXED MODE
The 8-bit De-Multiplexed mode applies only to the
PIC18C801. Data an d address lines are availa ble se parately. External components are not nec essary in this
mode.
For 8-bit De-Multiplexed mode on the PIC18C801, the
instructions are fetched as two 8-bit bytes on a dedicated data bus (PORTJ). The address will be presented for the entire duration of the fetch cycle on a
separate address bus. The two instruction bytes are
sequentially fetched within one instruction cycle (T
Therefore, the designer must choose external memory
devices according to timing calculations, based on 1/2
CY (2 times instruction rate). For proper memory speed
T
selection, setup and hold times must be considered.
CY).
Q2
03Ah
Opcode Fetch
MOVLW 55h
from 007556h
The Address Latch Enable (ALE) pin is left unconnected, since glue logic is not necessary. The OE
put enable signal will enable one byte of program
memory for a portion of the instruction cycle, then BA0
will change and the sec ond byte will be enabled to form
the 16-bit i nstruction wo rd. The least sign ificant bit of
the address, BA0, must be connected to the memory
devices in this mode. Figure 5-3 shows an example of
8-bit De-Multiplexed mode on the PIC18C801. The
control signals used in 8-bit De-Multiplexed mode are
outlined in Register 5-2. Register 5-4 describes 8-bit
De-Multiplexed mode timing.
Note 1: This signal only applies to Table Writes. See Section 6.0, Table Reads and Writes.
TABLE 5-2:8-BIT DE-MULTIPLEXED MODE CONTROL SIGNALS
Name8-bit De-Mux ModeFunction
RG0/ALEALEAddress Latch Enable (ALE) control pin
RG1/OE
RG2/WRL
RG4/BA0BA0Byte address bit 0
RF3/CSIO
RF4/CS2
RF5/CS1CS1Chip Select 1 (See Section 5.4)
OEOutput Enab le (OE) control pin
WRLWrite Low (WRL) control pin
CSIOChip Select I/O (See Section 5.4)
CS2Chip Select 2 (See Section 5.4)
A0
A<x:1>
D<7:0>
CE
OE
WR
(1)
FIGURE 5-4:8-BIT DE-MULTIPLEXED MODE TIMING
Q1
A16, AD<15:8>
AD<7:0>
BA0
ALE
OE
Q2
03Ah
Opcode Fetch
MOVLW 55h
from 007556h
Q3
55h
Q4
0Eh
DS39541A-page 66Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
5.316-bit Mode
The External Memory Interface can operate in 16-bit
mode. The mode sele ction is not so ftware confi gurable,
but is programmable via the configura tion bits.
The WM<1:0> bits in the MEMCON register determine
three types of connections in 16-bit mode. They are
referred to as:
• 16-bit Byte Write
• 16-bit Word Write
• 16-bit Byte Select
For all 16-bit modes, the Address Latch Enable (ALE)
pin indicates that the address bits A<15:0> are available on the External Memory Interface bus. Following
the address latch, the output enable signal (OE
enable both bytes of program memory at once to form
a 16-bit instruction word.
In Byte Select mode, JEDEC standard FLASH memories will require BA0 for the byte address line, and one
I/O line, to select between byte and word mode. The
other 16-bit modes do not need BA0. JEDEC st a nda rd
static RAM memo ries will us e the UB
byte selection.
These three different configurations allow the designer
maximum flexibility in using 8-bit and 16-bit memory
devices.
5.3.116-BIT BYTE WRITE MODE
Figure 5-5 shows an example of 16-bit Byte Write
mode for the PIC18C601/801.
FIGURE 5-5:16-BIT BYTE WRITE MODE EXAMPLE
D<7:0>
PIC18C801
AD<15:8>
A<19:16>
AD<7:0>
ALE
373
373
A<19:0>
D<15:8>
or UL signals f o r
(MSB)
A<x:0>
D<7:0>
CE
(1)
WR
OEOE
WR
D<7:0>
A<x:0>
D<7:0>
CE
(LSB)
) will
(1)
CS1
OE
WRH
WRL
Note 1: This signal only applies to Table Writes. See Section 6.0, Table Reads and Writes.
Chip select signals are used to select regions of external memory and I/O devices for access. The
PIC18C801 has th ree chip s elect s and al l are programmable. The chip select signals are CS1
. CS1 and CS2 are general purp os e ch ip s ele cts
CSIO
that are used to en able large portion s of program memory. CSIO
The PIC18C601uses two of these programmable chip
selects: CS1
is used to enable external I/O expansion.
and CSIO.
REGISTER 5-2:CSEL2 REGISTER
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
CSL7CSL6CSL5CSL4CSL3CSL2CSL1CSL0
bit 7bit 0
bit 7-0CSL<7:0>: Chip Select 2 Address Decode bits
XXh = All eight bits are compared to the Most Significant bits PC<20:13> of the program
counter. If PC<20:13> ≥ CSL<7:0> register, then the CS2
If PC<20:13> < CSL<7:0>, CS2
00h =CS2 is inactive
, CS2 and
Two SFRs are used to control the chip select signals.
These are CSEL2 and CSELIO (see Register 5-2 and
Register 5-3). A chip select signal i s asserted low w hen
the CPU makes an access to a dedicated range of
addresses specifie d in the chip select register s, CSEL2
and CSELIO. The 8-bit value found in either of these
registers is decoded as one of 256, 8K banks of pro-
gram memory. If both chip select registers are 00h, all
of the chip select signals are disabled and their corre-
sponding pins are configured as I/O. Since the last 512
bytes of program mem ory are dedicate d to internal p ro-
gram RAM, the chip sele ct signals will not act ivate if the
program memory address falls in this range.
signal is low.
is high.
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
REGISTER 5-3:CSELIO REGISTER
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
CSIO7CSIO6CSIO5CSIO4CSIO3CSIO2CSIO1CSIO0
bit7bit0
bit 7-0CSIO<7:0>: Chip Select IO Address Decode bits
XXh =All eight bits are compared to the Most Significant bits PC<20:13> of the program
counter. If PC<20:13> = CSIO<7:0>, then the CSIO
00h =CSIO is inactive
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
signal is low. If not, CSIO is high.
DS39541A-page 70Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
5.4.1CHIP SELECT 1 (CS1)
CS1 is enabled by writing a value other than 00h into
either the CSEL2 register, or the CSELIO register. If
both of the chip select registers are programmed to
00h, the CS1
signal is not enabled and the RF5 pin is
configured as I/O.
is low for all addresses in which CS2 and CSELIO
CS1
are high. Therefore, if CSEL2 = 20h and CSELIO = 80h,
then the CS1
signal will be low for the address that falls
between 000000h and (2000h x 20h) - 1 = 03FFFFh.
CS1
will always be low for the lower 8K of program
memory . Fi gure 5-9 shows an example a ddress map for
.
CS1
5.4.2CHIP SELECT 2 (CS2)
CS2 is enabled for program memory accesses, starting
at the address derived by the 8-bit value contained in
A 00h value in the CSEL2 register will disable the CS2
signal and will conf ig ure th e RF4 pin as I/O. Figure 5-9
shows an example address map for CS2
.
5.4.3CHIP SELECT I/O (CSIO)
CSIO is enabled fo r a fi xed 8K ad dres s range s tarting
at the address defined by the 8-bit value contained in
CSELIO. If, for instance, the value contained in the
CSELIO register is 80h, then the CSIO
low for the address range between 100000h and
101FFFh.
If the 8K address block overlaps the address range
specified in the C SEL2 re gister, the CSIO
low, and the CS2
signal will be high, for that region.
A 00h value in the CSELIO register will disable the
CSIO
signal and will configure the RF3 pin as I/O.
Figure 5-9 shows an example address map for CSIO
signal will be
signal will be
CSEL2. For example, if the value contained in the
CSEL2 register is 80h, then the CS2
signal will be
asserted low whenever the address is greater than or
equal to 2000h x 80h = 100000h.
FIGURE 5-9: EXAMPLE CONFIGURATION ADDRESS MAP FOR CS1, CS2, AND CSIO
The external memory interface supports wait cycles.
Wait cycles only apply to Table Read and Table Write
operations over the external bus. See Section 6.0 for
more details .
Since the device execut ion is tied to instruc tion fetches,
there is no need t o execut e fast er than t he fet ch rate.
So, if the program needs to be slowed, the processor
speed must be slowed with a different T
CY time.
DS39541A-page 72Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
6.0TABLE READS/TABLE WRITES
PIC18C601/ 801 de vices use two memor y spaces : the
external program me mo ry space and the data memory
space. Table Reads and Table Writes have been provided to move data between thes e two memory space s
through an 8-bit register (TABLAT).
The operations that allow the processor to move data
between the data and external program memory
spaces are:
• Table Read (TBLRD)
• Table Write (TBLWT)
FIGURE 6-1:TABLE READ OPER ATION
(1)
TBLPTRU
Table Pointer
TBLPTRHTBLPTRL
Table Read operations retrieve data from external program memory and place it into the da ta memo ry space.
Figure 6-1 shows the operation of a Table Read with
program and data memory.
Table Write operations store data from the data memory space into external program memory. Figure 6-2
shows the operation of a Table Write with external program and data memory.
Table operations work with byte entities. A table block
containing dat a is not requ ired to be word a ligned , 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 must
be word aligned.
Table Latch (8-bit)
TABLAT
External Program Memory
Program Memory
Instruction: TBLRD*
Note 1: Table Pointer points to a byte in external program memory.
(TBLPTR)
FIGURE 6-2:TABLE WRITE OPERATION
(1)
External
Program Memory
(TBLPTR)
TBLPTRU
Instruction: TBLWT*
Table Pointer
TBLPTRHTBLPTRL
Table Latch (8-bit)
TABLAT
External Program Memory
Note 1: Table Pointer points to a byte in external program memory.
Several control registers are used in conjunction with
the TBLRD and TBLWT instructions. These include:
• TABLAT register
• TBLPTR register s
6.1.1TABLAT - TABLE LATCH REGISTER
The Table Latch (TABLAT) is an 8-bit register mapped
into the SFR space. The Table Latch is used to hold
8-bit data during data transf ers between program memory and data memory.
6.1.2TBLPTR - 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 21-bit
wide pointer . The 21-bi ts allow the de vice to address u p
to 2 Mbytes of program memory space.
The table pointer T BLPTR is used by the TBLRD and
TBLWRT instructions. These inst ructions can update
the TBLPTR in one of four ways, bas ed on the table
operation. These oper ations are shown in Table 6-1.
These operations o n the TBL PTR only affect the l ow
order 21-bits.
TABLE 6-1:TABLE POINTER OPERATIONS WITH TBLRD AND TBLWT INSTRUCTIONS
ExampleOperation on Table Pointer
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*-
TBLRD+*
TBLWT+*
TBLPTR is not modified
TBLPTR is incremented after the read/write
TBLPTR is decremented after the read/write
TBLPTR is incremented bef ore the read /write
DS39541A-page 74Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
6.2Table Read
The TBLRD instruction is used to retrieve data from
external program memory and place it into data
memory.
TBLPTR points to a byte a ddress i n exter nal prog ram
memory space. Executing TBLRD places the byte into
TABLAT. In addition, TBLPTR can be modified automatically for the next Table Read operation.
Table Reads from external program memory are
performed one byte at a ti me. If the external interface is
8-bit, the bus interface ci rcu itry in TABLAT will load the
external value into TABLAT. If the external interface is
16-bit, interface circui try in T ABLAT will select either the
high or low byte of the data from the 16-bit bus, based
on the least significant bit of the address.
Example 6-1describes how to use TBLRD. Figure 6-3
and Figure 6-4 show Table Read timings for an 8-bit
external interface, and Figure 6-5 describes Table
Read timing for a 16-bit interface.
EXAMPLE 6-1:TABLE READ CODE EXAMPLE
; Read a byte from location 0020h
CLRFTBLPTRU; clear upper 5 bits of TBLPTR
CLRFTBLPTRH; clear higher 8 bits of TBLPTR
MOVLW20h; Load 20h into
MOVWFTBLPTRL; TBLPTRL
TBLRD*; Data is in TABLAT
DS39541A-page 76Advance Information 2001 Microchip Technology Inc.
6.3Table Write
Table Write operations store data from the data memory space into external program memory.
PIC18C601/801devices perform Table Writes one byte
at a time. T able Writes to external memory are two-cycle
instructions, unless wait states are enabled. The last
cycle writes the data to the external memory location.
16-bit interface Table Writes depend on the type of
external device that is connected and the WM<1:0>
bits in the MEM CON register (See Figure 5- 2).
Example 6-2 describes how to use TBLWT.
EXAMPLE 6-2: TABLE WRITE CODE EXAMPLE
; Write a byte to location 0020h
CLRFTBLPTRU; clear upper 5 bits of TBLPTR
CLRFTBLPTRH; clear higher 8 bits of TBLPTR
MOVLW20h; Load 20h into
MOVWFTBLPTRL; TBLPTRL
MOVLW55h; Load 55h into
MOVWFTBLAT; TBLAT
TBLWT*; Write it
When the external bus is 8-bit, the byte-wide Table
Write exactl y corr espon ds to t he bu s leng th and there
are no special considerations required.
The WRL
Figure 6-6 and Figure 6-7 show the timings assoc iate d
This mode allows Table Writes to byte-wide external
memories. During a TBLWT cycle, the TABLAT data is
presented on the upper and lower byte of the
AD<15:0> bus. The appropriate WRH
strobed based on the LSb of the TBLPTR. Figure 6-8
shows the timing associated with this mode.
DS39541A-page 80Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
6.3.3EXTERNAL TABLE WRITE IN 16-BIT
WORD WRITE MODE
During a TBLWT cycle to an odd address, where
TBLPTR<0> = 1, the TABLAT data is pres ent ed on the
upper byte of the AD<15:0> bus. The contents of the
This mode allows Table Writes to any type of wordwide external memories.
This method makes a distinction between TBLWT
cycles to even or odd addresses.
During a TBLWT cycle to an even address, where
TBLPTR<0> = 0, the TABLAT data is transferred to a
holding latch and the external address data bus is tristated for the data portion of the bus cycle. No write
signals are activated.
holding latch are presented on the lower byte of the
AD<15:0> bus. The WRH
write cycle and the WRL
line is strobed for each
line is unused. The BA0 line
indicates the LSb of TBLPTR, but it is unnecessary.
The UB
and LB lines are active to select both bytes.
The obvious limitation to this method is th at th e TBLWT
must be done in pairs on a specific word boundary to
correctly write a word location.
Figure 6-9 shows the timing associated with this mode.
FIGURE 6-9:TBLWT EXTERNAL INTERFACE TIMING (16-BIT WORD WRITE MODE)
This mode allows Table Writes to word-wide external
memories that have byte selection capabilities. This
generally includes word-wide FLASH devices and
word-wide static RAM devices.
During a TBLWT cycle, the TABLAT data is presen ted
on the upper and lower byte of the AD<15:0> bus.
The WRH
line is unused. The BA0 or UB or UL lines are
used to select the byte to be written, based on the LS b
of the TBLPTR.
JEDEC standard flash memories will require a I/O port
line to become a BYTE/WORD input signal and will
use the BA0 signal as a byte address. JEDEC standard static RAM memories will use the UB
nals to select the byte.
Figure 6-10 shows the timing associated with this mode.
or UL sig-
A<19:16>
AD<15:0>
BA0
ALE
OE
WRH
WRL
UB
LB
Memory
Cycle
Instruction
Execution
Q2Q1Q3 Q4Q2Q1Q3 Q4
0h
3AAAh
’1’
Opcode FetchOpcode FetchOpcode Fetch
from 007554h
000Dh
TBLWT*+
INST(PC-2)
0h
3AABh
MOVWF TABLAT
from 007556h
TBLWT*+ Cycle1
6FF4h
Q2Q1Q3 Q4
Ch
CF33h
TBLWT 56h
to 199E66h
TBLWT*+ Cycle2
5656h
Q2Q1Q3 Q4
0h0h
3AACh
Opcode Fetch
from 007558h
000Ch
TBLWT*
MOVWF
3AADh
MOVLW 55h
from 00755Ah
TBLWT* Cycle1
0E55h
Q2Q1Q3 Q4Q2Q1Q3 Q4
Ch
CF33h
TBLWT 92h
to 199E67h
TBLWT* Cycle2
9292h
DS39541A-page 82Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
6.4Long Writes
Long writes wi ll not be supp orted on t he PIC18 C601/ 801
to program FL ASH config uration memo ry. The configuration location s c an on ly b e p ro gra m med in ICSP mode.
6.5External Wait Cycles
The Table Reads and Writes have the capability to
insert wait states when accessing external memory.
These wait states on ly apply to the ex ecution of a Table
Read or Write to externa l memory and not to instruc tion
The WAIT<1:0> bits in the MEMCON register will select
0, 1, 2, or 3 extra T
The wait will occur on Q4.
The default setting of the wait on power-up is to assert
a maximum wait of 3T
memories will work in Microprocessor mode immediately after RESET.
Figure 6-11 shows 8-bit external bus timing for a Table
Read with 2 wait cycles. Figure 6-12 shows 16-bit
external bus timing for a Table Read with 1 wait cycle.
fetches out of external memory. The guidelines presented in Section 5.0must be followed to select the
proper memory speed grade for the device operating
frequency.
FIGURE 6-11:EXTERNAL INTERFACE T IMING (8-BIT MODE)
DS39541A-page 84Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
7.08 X 8 HARDWARE MULTIPLIER
An 8 x 8 hardware multiplier is included in the ALU of
PIC18C601/801 devices. By making the multiply a
hardware operatio n, i t co mp letes in a single instruc tion
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:
The performance incre ase allows the device to be used
in some applications previously reserved for Digital
Signal Processors.
Tab le 7-1 shows a performance compar ison between
enhanced devic es using the sin gle cycle hard ware multiply, and performing the same function without the
hardware multiply.
Example 7-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 al rea dy lo aded in
the WREG register.
Example 7-2 shows the sequence t o do an 8 x 8 signed
multiply. To ac count for the si gn bi ts of the ar gum ents,
each argument’s most significant bit (MSb) is tested
and the appropriate subtractions are done.
Example 7-3 shows the sequence to perfo rm a 16 x 16
unsigned multiply. Equation 7-1 shows the algorithm
that is used. The 32-bit result is stored in 4 registers
RES3:RES0.
EQUATION 7-1:16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
RES3:RES0=ARG1H:ARG1L
=(ARG1H
(ARG1H
(ARG1L
(ARG1L
• ARG2H:ARG2L
• ARG2H • 2
• ARG2L • 2
• ARG2H • 2
• ARG2L)
16
)+
8
)+
8
)+
Example 7-4 shows the sequence to perfo rm a 16 x 16
signed multiply. Equation 7-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 argu me nt p a irs ’ m ost sig nif ic ant b it (M Sb)
is tested and the appropriate subtractions are done.
EQUATION 7-2:16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
RES3:RES0
=ARG1H:ARG1L
=(ARG1H
(ARG1H
(ARG1L
(ARG1L
(-1
• ARG2H<7> • ARG1H:ARG1L • 2
• ARG1H<7> • ARG2H:ARG2L • 2
(-1
• ARG2H:ARG2L
• ARG2H • 2
• ARG2L • 2
• ARG2H • 2
• ARG2L)+
16
)+
8
)+
8
)+
16
)+
16
)
DS39541A-page 86Advance Information 2001 Microchip Technology Inc.
DS39541A-page 88Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
8.0INTERRUPTS
PIC18C601/801 dev ices have 15 inte rrupt sourc es and
an interrupt priority feature that allows each interrupt
source to be ass ign ed a hi gh prio rity level, or a low priority level. The high priority interrupt vector is at
000008h and the low priority interrupt vector is at
000018h. High priorit y interrupt event s will overrid e any
low priority interrupts that may be in progress.
There are 10 registers that are use d to c ontrol interru pt
operation. These registers are:
• RCON
• INTCON
• INTCON2
• INTCON3
• PIR1, PIR2
• PIE1, PIE2
• IPR1, IPR2
It is recommended that the Microchip header files supplied with MPLAB
names in these registers. This allows the assembler/
compiler to automatical ly ta ke care of the pla ceme nt of
these bits within the specified register.
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 high priority or low priority
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.
®
IDE be used for the symbolic bit
When the IPEN bit is cleared (default state), the interrupt priority feature is disabled and interrupts are
compatible with PICmicro
patibility mode, th e interrupt priority bits for each sourc e
have no effect. The PEIE bit (INTCON register)
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 mode.
When an interrupt is responded to, the Glob al Interrupt
Enable bit is cleared to disable further interrupts. 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 cleared in software b efore re-e nabling
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.
1 = Enables all unmasked 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
When IPEN = 0:
1 = Enables all unmasked 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 interrupt
bit 2TMR0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 regi ster has overflowed (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)
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
8.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:In ter ru pt f la g bi ts ge t se t wh e n an i nt e rr up t cond i ti o n oc c urs , r e gar d le ss of t he stat e
of its correspondi ng enable bi t, or the globa l enable bit . User soft ware shou ld ensure
the appropriate interr upt fla g bit s are clear prior to enabl ing an interru pt. This featu re
allows software polling.
bit 6INTEDG0: External Interrupt 0 Edge Select bit
bit 5INTEDG1: External Interrupt 1 Edge Select bit
bit 4INTEDG2: External Interrupt 2 Edge Select bit
bit 3Unimplemented: Read as ’0’
bit 2TMR0IP: TMR0 Overflow Interrupt Priority bit
bit 1Unimplemented: Read as ’0’
bit 0RBIP: RB Port Change Interrupt Priority bit
: PORTB Pull-up Enable bit
1 = All PORTB pull-ups are disabled
0 = PORTB pull-ups are enabled by individual port latch values
1 = Interrupt on rising edge
0 = Interrupt on falling edge
1 = Interrupt on rising edge
0 = Interrupt on falling edge
1 = Interrupt on rising edge
0 = Interrupt on falling edge
1 = High priority
0 = Low priority
1 = High priority
0 = Low priority
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 correspondi ng enable bi t, or the globa l enable bit . User soft ware shou ld ensure
the appropriate interr upt fla g bit s are clear prior to enabl ing an interru pt. This featu re
allows software polling.
DS39541A-page 92Advance Information 2001 Microchip Technology Inc.
REGISTER 8-3:INTCON3 REGISTER
R/W-1R/W-1U-0R/W-0R/W-0U-0R/W-0R/W-0
INT2IPINT1IP
bit 7bit 0
bit 7INT2IP: INT2 External Interrupt Priority bit
1 = High priority
0 = Low priority
bit 6INT1IP: INT1 External Interrupt Priority bit
1 = High priority
0 = Low priority
bit 5Unimplemented: Read as ’0’
bit 4INT2IE: INT2 External Interrupt Enable bit
1 = Enables the INT2 external interrupt
0 = Disables the INT2 external interrupt
bit 3INT1IE: INT1 External Interrupt Enable bit
1 = Enables the INT1 external interrupt
0 = Disables the INT1 external interrupt
bit 2Unimplemented: Read as ’0’
bit 1INT2IF: INT2 External Interrupt Flag bit
1 = The INT2 external interrupt occurred (must be cleared in software)
0 = The INT2 external interrupt did not occur
bit 0INT1IF: INT1 External Interrupt Flag bit
1 = The INT1 external interrupt occurred (must be cleared in software)
0 = The INT1 external interrupt did not occur
—INT2IEINT1IE—INT2IFINT1IF
PIC18C601/801
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:In ter ru pt f la g bi ts ge t se t wh e n an i nt e rr up t cond i ti o n oc c urs , r e gar d le ss of t he stat e
of its correspondi ng enable bi t, or the globa l enable bit . User soft ware shou ld ensure
the appropriate interr upt fla g bit s are clear prior to enabl ing an interru pt. This featu re
allows software polling.
The Peripheral Interrupt Request (PIR) registers contain the individual flag bits for the peripheral interrupts
(Register 8-5). There are two Peripheral Interrupt
Request (Flag) registers (PIR1, PIR2).
Note 1: Interrupt flag bits are set when an interru pt
condition occurs, regardl ess of the s tate of
its corresponding enable bit, or the global
enable bit, GIE (INTCON register).
2: User software sho uld ensure the appropri-
ate interrupt flag bits are cleared prior to
enabling an interrupt, and after servicing
that interrupt.
REGISTER 8-4:RCON REGISTER
R/W-0U-0U-0R/W-1R/W-1R/W-1R/W-0U-0
IPENr
bit 7bit 0
—RITOPDPORr
8.1.3PIE REGISTERS
The Peripheral Interrupt En abl e (PIE) regi ste rs c on t ai n
the individual enable bits for the peripheral interrupts
(Register 8-6). There are two two Peripheral Interrupt
Enable registers (PIE1, PIE2). Whe n IPEN is clear, the
PEIE bit must be set to enable any of these peripheral
interrupts.
8.1.4IPR REGISTERS
The Interrupt Priority (IPR) registers contain the individual priority bi ts for th e peripheral i nterrupts (Re gister 8-9).
There are two Peripheral Interrupt Priority registers
(IPR1, IPR2). T he operation of th e priority bits requ ires
that the Interr upt Pri or ity E na ble b it (IP E N) b e se t.
8.1.5RCON REGISTER
The Reset Control (RCON ) register cont ains the bit that
is used to enable prioritized interrupts (IPEN).
bit 7IPEN: Interrupt Priority Enable bit
1 =Enable priority levels on interrupts
0 =Disable priority levels on interrupts (16CXXX compatibility mode)
bit 6Reserved: Maintain as '0'
bit 5Unimplemented: Read as '0 '
bit 4RI
bit 3TO
bit 2PD
bit 1POR
bit 0Reserved: Maintain as '0'
: RESET Instruction Flag bit
For details of bit operation, see Register 4-4
: Watchdog Time-out Flag bit
For details of bit operation, see Register 4-4
: Power-down Detection Flag bit
For details of bit operation, see Register 4-4
: Power-on Reset Status bit
For details of bit operation, see Register 4-4
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
DS39541A-page 94Advance Information 2001 Microchip Technology Inc.
PIC18C601/801
REGISTER 8-5:PIR1 REGISTER
U-0R/W-0R-0R-0R/W-0R/W-0R/W-0R/W-0
—ADIFRCIFTXIFSSPIFCCP1IFTMR2IFTMR1IF
bit 7bit 0
bit 7Unimplemented: Read as ’0’
bit 6ADIF: A/D Converter Interrupt Flag bit
1 = An A/D conversion completed
(must be cleared in software)
0 = The A/D conversion is not complete
bit 5RCIF: USART Receive Interrupt Flag bit
1 = The USART receive buffer, RCREG, is full
(cleared when RCREG is read)
0 = The USART receive buffer is empty
bit 4TXIF: USART Transmit Interrupt Flag bit
1 = The USART transmit buffer, TXREG, is empty
(cleared when TXREG is written)
0 = The USART transmit buffer is full
bit 3SSPIF: Master Synchronous Serial Port Interrupt Flag bit
1 = The transmission/reception is complete
(must be cleared in software)
0 = Waiting to transmit/receive
bit 2CCP1IF: CCP1 Interrupt Flag bit
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
bit 1TMR2IF: TMR2 to PR2 Match Interrupt Flag bit
1 = TMR2 to PR2 match occurred
(must be cleared in software)
0 = No TMR2 to PR2 match occurred
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = TMR1 register overflowed
(must be cleared in software)
0 = TMR1 register did not overflow
:
:
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