Professional Documents
Culture Documents
PIC18F6520/8520/6620/8620/6720/8720 Data Sheet
PIC18F6520/8520/6620/8620/6720/8720 Data Sheet
Data Sheet
64/80-Pin High-Performance,
256 Kbit to 1 Mbit Enhanced Flash
Microcontrollers with A/D
DS39609B
Note the following details of the code protection feature on Microchip devices:
Microchip products meet the specification contained in their particular Microchip Data Sheet.
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE and PowerSmart are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
AmpLab, FilterLab, microID, MXDEV, MXLAB, PICMASTER,
SEEVAL, SmartShunt and The Embedded Control Solutions
Company are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Application Maestro, dsPICDEM, dsPICDEM.net,
dsPICworks, ECAN, ECONOMONITOR, FanSense,
FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP,
ICEPIC, microPort, Migratable Memory, MPASM, MPLIB,
MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICtail,
PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB, rfPIC,
Select Mode, SmartSensor, SmartTel and Total Endurance
are trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
Serialized Quick Turn Programming (SQTP) is a service mark
of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
2004, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
DS39609B-page ii
PIC18F6520/8520/6620/
8620/6720/8720
64/80-Pin High-Performance, 256 Kbit to 1 Mbit
Enhanced Flash Microcontrollers with A/D
High-Performance RISC CPU:
Analog Features:
Peripheral Features:
CMOS Technology:
Data Memory
10-bit
CCP
A/D
(PWM)
(ch)
MSSP
Max
Timers
Ext
OSC
USART
F
Master
8-bit/16-bit Bus
SPI
(MHz)
I2C
PIC18F6520
32K
16384
2048
1024
52
12
2/3
PIC18F6620
64K
32768
3840
1024
52
12
2/3
25
PIC18F6720 128K
65536
3840
1024
52
12
2/3
25
PIC18F8520
32K
16384
2048
1024
68
16
2/3
40
PIC18F8620
64K
32768
3840
1024
68
16
2/3
25
PIC18F8720 128K
65536
3840
1024
68
16
2/3
25
40
DS39609B-page 1
PIC18F6520/8520/6620/8620/6720/8720
Pin Diagrams
Note 1:
RE5
RE6
RE7/CCP2(1)
RD0/PSP0
VDD
VSS
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
61
60
58
56
55
54
53
52
51
50
49
RD6/PSP6
RD7/PSP7
RE4
57
RE3
62
59
RE2/CS
64
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
PIC18F6520
PIC18F6620
PIC18F6720
RB2/INT2
RB3/INT3
RB4/KBI0
RB5/KBI1/PGM
RB6/KBI2/PGC
VSS
OSC2/CLKO/RA6
OSC1/CLKI
VDD
RB7/KBI3/PGD
RC5/SDO
RC4/SDI/SDA
RC3/SCK/SCL
RC2/CCP1
32
RA5/AN4/LVDIN
31
27
28
VDD
30
26
VSS
RB0/INT0
RB1/INT1
RC0/T1OSO/T13CKI
RC6/TX1/CK1
RC7/RX1/DT1
25
RA0/AN0
29
24
RA4/T0CKI
RC1/T1OSI/CCP2(1)
23
RA2/AN2/VREF-
RA1/AN1
20
AVSS
RA3/AN3/VREF+
21
22
19
AVDD
15
16
RF1/AN6/C2OUT
VSS
VDD
RF7/SS
RF6/AN11
RF5/AN10/CVREF
RF4/AN9
RF3/AN8
RF2/AN7/C1OUT
48
2
3
4
5
6
7
8
9
10
11
12
13
14
17
18
RG2/RX2/DT2
RG3/CCP4
MCLR/VPP
RG4/CCP5
RF0/AN5
RE1/WR
RE0/RD
RG0/CCP3
RG1/TX2/CK2
63
64-Pin TQFP
DS39609B-page 2
PIC18F6520/8520/6620/8620/6720/8720
Pin Diagrams (Continued)
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
RH1/A17
RH0/A16
RE2/CS/AD10(3)
RE3/AD11
RE4/AD12
RE5/AD13
RE6/AD14
RE7/CCP2/AD15(2)
RD0/PSP0/AD0(3)
VDD
VSS
RD1/PSP1/AD1(3)
RD2/PSP2/AD2(3)
RD3/PSP3/AD3(3)
RD4/PSP4/AD4(3)
RD5/PSP5/AD5(3)
RD6/PSP6/AD6(3)
RD7/PSP7/AD7(3)
RJ0/ALE
RJ1/OE
80-Pin TQFP
RH2/A18
RH3/A19
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PIC18F8520
PIC18F8620
PIC18F8720
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
RJ2/WRL
RJ3/WRH
RB0/INT0
RB1/INT1
RB2/INT2
RB3/INT3/CCP2(1)
RB4/KBI0
RB5/KBI1/PGM
RB6/KBI2/PGC
VSS
OSC2/CLKO/RA6
OSC1/CLKI
VDD
RB7/KBI3/PGD
RC5/SDO
RC4/SDI/SDA
RC3/SCK/SCL
RC2/CCP1
RJ7/UB
RJ6/LB
RH5/AN13
RH4/AN12
RF1/AN6/C2OUT
RF0/AN5
AVDD
AVSS
RA3/AN3/VREF+
RA2/AN2/VREFRA1/AN1
RA0/AN0
VSS
VDD
RA5/AN4/LVDIN
RA4/T0CKI
RC1/T1OSI/CCP2(1)
RC0/T1OSO/T13CKI
RC6/TX1/CK1
RC7/RX1/DT1
RJ4/BA0
RJ5/CE
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
RE1/WR/AD9(3)
RE0/RD/AD8(3)
RG0/CCP3
RG1/TX2/CK2
RG2/RX2/DT2
RG3/CCP4
MCLR/VPP
RG4/CCP5
VSS
VDD
RF7/SS
RF6/AN11
RF5/AN10/CVREF
RF4/AN9
RF3/AN8
RF2/AN7/C1OUT
RH7/AN15
RH6/AN14
1
2
Note 1:
2:
3:
DS39609B-page 3
PIC18F6520/8520/6620/8620/6720/8720
Table of Contents
1.0 Device Overview .......................................................................................................................................................................... 7
2.0 Oscillator Configurations ............................................................................................................................................................ 21
3.0 Reset .......................................................................................................................................................................................... 29
4.0 Memory Organization ................................................................................................................................................................. 39
5.0 Flash Program Memory .............................................................................................................................................................. 61
6.0 External Memory Interface ......................................................................................................................................................... 71
7.0 Data EEPROM Memory ............................................................................................................................................................. 79
8.0 8 X 8 Hardware Multiplier ........................................................................................................................................................... 85
9.0 Interrupts .................................................................................................................................................................................... 87
10.0 I/O Ports ................................................................................................................................................................................... 103
11.0 Timer0 Module ......................................................................................................................................................................... 131
12.0 Timer1 Module ......................................................................................................................................................................... 135
13.0 Timer2 Module ......................................................................................................................................................................... 141
14.0 Timer3 Module ......................................................................................................................................................................... 143
15.0 Timer4 Module ......................................................................................................................................................................... 147
16.0 Capture/Compare/PWM (CCP) Modules ................................................................................................................................. 149
17.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 157
18.0 Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART).............................................................. 197
19.0 10-Bit Analog-to-Digital Converter (A/D) Module ..................................................................................................................... 213
20.0 Comparator Module.................................................................................................................................................................. 223
21.0 Comparator Voltage Reference Module ................................................................................................................................... 229
22.0 Low-Voltage Detect .................................................................................................................................................................. 233
23.0 Special Features of the CPU .................................................................................................................................................... 239
24.0 Instruction Set Summary .......................................................................................................................................................... 259
25.0 Development Support............................................................................................................................................................... 301
26.0 Electrical Characteristics .......................................................................................................................................................... 307
27.0 DC and AC Characteristics Graphs and Tables ....................................................................................................................... 343
28.0 Packaging Information.............................................................................................................................................................. 357
Appendix A: Revision History............................................................................................................................................................. 361
Appendix B: Device Differences......................................................................................................................................................... 361
Appendix C: Conversion Considerations ........................................................................................................................................... 362
Appendix D: Migration from Mid-Range to Enhanced Devices .......................................................................................................... 362
Appendix E: Migration from High-End to Enhanced Devices............................................................................................................. 363
Index .................................................................................................................................................................................................. 365
On-Line Support................................................................................................................................................................................. 375
Systems Information and Upgrade Hot Line ...................................................................................................................................... 375
Reader Response .............................................................................................................................................................................. 376
PIC18F6520/8520/6620/8620/6720/8720 Product Identification System .......................................................................................... 377
DS39609B-page 4
PIC18F6520/8520/6620/8620/6720/8720
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 comments regarding this publication, please contact the Marketing 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.
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:
Microchips 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.
DS39609B-page 5
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 6
PIC18F6520/8520/6620/8620/6720/8720
1.0
DEVICE OVERVIEW
PIC18F8520
PIC18F6620
PIC18F8620
PIC18F6720
PIC18F8720
1.1
1.1.1
Key Features
EXPANDED MEMORY
1.1.2
1.1.3
EASY MIGRATION
1.1.4
DS39609B-page 7
PIC18F6520/8520/6620/8620/6720/8720
1.2
3.
4.
2.
5.
TABLE 1-1:
Features
Operating Frequency
PIC18F6520
PIC18F6620
PIC18F6720
PIC18F8520
PIC18F8620
PIC18F8720
DC 40 MHz
DC 25 MHz
DC 25 MHz
DC 40 MHz
DC 25 MHz
DC 25 MHz
Program Memory
(Bytes)
32K
64K
128K
32K
64K
128K
Program Memory
(Instructions)
16384
32768
65536
16384
32768
65536
Data Memory
(Bytes)
2048
3840
3840
2048
3840
3840
Data EEPROM
Memory (Bytes)
1024
1024
1024
1024
1024
1024
External Memory
Interface
No
No
No
Yes
Yes
Yes
17
17
Interrupt Sources
I/O Ports
17
Ports A, B, C,
D, E, F, G
Ports A, B, C, D, Ports A, B, C, D,
E, F, G
E, F, G
18
18
18
Ports A, B, C,
D, E, F, G, H, J
Ports A, B, C,
D, E, F, G, H, J
Ports A, B, C,
D, E, F, G, H, J
Timers
Capture/Compare/
PWM Modules
MSSP,
Addressable
USART (2)
MSSP,
Addressable
USART (2)
MSSP,
Addressable
USART (2)
MSSP,
Addressable
USART (2)
MSSP,
Addressable
USART (2)
MSSP,
Addressable
USART (2)
Serial Communications
Parallel Communications
10-bit Analog-to-Digital
Module
Resets (and Delays)
PSP
PSP
PSP
PSP
PSP
PSP
12 input
channels
12 input
channels
12 input
channels
16 input
channels
16 input
channels
16 input
channels
POR, BOR,
POR, BOR,
RESET
RESET
Instruction,
Instruction,
Stack Full,
Stack Full,
Stack Underflow Stack Underflow
(PWRT, OST)
(PWRT, OST)
POR, BOR,
POR, BOR,
POR, BOR,
POR, BOR,
RESET
RESET
RESET
RESET
Instruction,
Instruction,
Instruction,
Instruction,
Stack Full,
Stack Full,
Stack Full,
Stack Full,
Stack Underflow Stack Underflow Stack Underflow Stack Underflow
(PWRT, OST)
(PWRT, OST)
(PWRT, OST)
(PWRT, OST)
Programmable
Low-Voltage Detect
Yes
Yes
Yes
Yes
Yes
Yes
Programmable
Brown-out Reset
Yes
Yes
Yes
Yes
Yes
Yes
77 Instructions
77 Instructions
77 Instructions
77 Instructions
77 Instructions
77 Instructions
64-pin TQFP
64-pin TQFP
64-pin TQFP
80-pin TQFP
80-pin TQFP
80-pin TQFP
Instruction Set
Package
DS39609B-page 8
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 1-1:
21
Table Pointer<21>
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/LVDIN
RA6
Data Latch
8
21
PORTA
8
Data RAM
inc/dec logic
Address Latch
21
PCLATU PCLATH
12
4
Bank0, F
FSR0
FSR1
FSR2
31 Level Stack
Program Memory
RB0/INT0
RB1/INT1
RB2/INT2
RB3/INT3
RB4/KBI0
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
Address<12>
BSR
Address Latch
PORTB
12
12
Data Latch
inc/dec
logic
Decode
Table Latch
PORTC
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX1/CK1
RC7/RX1/DT1
16
ROM Latch
IR
8
PORTD
PRODH PRODL
Instruction
Decode &
Control
OSC2/CLKO
OSC1/CLKI
RD7/PSP7:RD0/PSP0
8 x 8 Multiply
8
3
WREG
8
BITOP
8
Power-up
Timer
Timing
Generation
Oscillator
Start-up Timer
Precision
Band Gap
Reference
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
PORTE
8
ALU<8>
8
RE0/RD
RE1/WR
RE2/CS
RE3
RE4
RE5
RE6
RE7/CCP2
PORTF
RF0/AN5
RF1/AN6/C2OUT
RF2/AN7/C1OUT
RF3/AN8
RF4/AN9
RF5/AN10/CVREF
RF6/AN11
RF7/SS
PORTG
Synchronous
Serial Port
USART2
USART1
BOR
LVD
Timer0
Timer1
Timer2
Timer3
Timer4
Comparator
CCP1
CCP2
CCP3
CCP4
CCP5
RG0/CCP3
RG1/TX2/CK2
RG2/RX2/DT2
RG3/CCP4
RG4/CCP5
Data
EEPROM
10-bit
A/D
DS39609B-page 9
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 1-2:
21
Table Pointer<21>
RA0/AN0
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/LVDIN
RA6
Data Latch
8
21
PORTA
Data RAM
inc/dec logic
Address Latch
21
PCLATU PCLATH
12
4
Bank0, F
FSR0
FSR1
FSR2
31 Level Stack
Program Memory
RB0/INT0
RB1/INT1
RB2/INT2
RB3/INT3/CCP2
RB4/KBI0
RB5/KBI1/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
Address<12>
BSR
Address Latch
PORTB
12
12
PORTC
Data Latch
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX1/CK1
RC7/RX1/DT1
inc/dec
logic
Decode
Table Latch
16
ROM Latch
IR
AD15:AD0, A19:A16(1)
PORTD
RD7/PSP7/AD7:
RD0/PSP0/AD0
8
PORTE
PRODH PRODL
Instruction
Decode &
Control
OSC2/CLKO
OSC1/CLKI
RE0/RD/AD8
RE1/WR/AD9
RE2/CS/AD10
RE3/AD11
RE4/AD12
RE5/AD13
RE6/AD14
RE7/CCP2/AD15
8 x 8 Multiply
8
3
WREG
8
BITOP
8
Power-up
Timer
Timing
Generation
Oscillator
Start-up Timer
Precision
Band Gap
Reference
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
PORTF
RF0/AN5
RF1/AN6/C2OUT
RF2/AN7/C1OUT
RF3/AN8
RF4/AN9
RF5/AN10/CVREF
RF6/AN11
RF7/SS
ALU<8>
8
PORTG
RG0/CCP3
RG1/TX2/CK2
RG2/RX2/DT2
RG3/CCP4
RG4/CCP5
PORTH
Synchronous
Serial Port
USART2
USART1
RH3/AD19:RH0/AD16
Data
EEPROM
RH7/AN15:RH4/AN12
PORTJ
BOR
LVD
Timer0
Timer1
Timer2
Timer3
Timer4
Comparator
CCP1
CCP2
CCP3
CCP4
CCP5
RJ0/ALE
RJ1/OE
RJ2/WRL
RJ3/WRH
RJ4/BA0
RJ5/CE
RJ6/LB
RJ7/UB
10-bit
A/D
Note 1: External memory interface pins are physically multiplexed with PORTD (AD7:AD0), PORTE (AD15:AD8) and PORTH (A19:A16).
DS39609B-page 10
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
PIC18F6X20 PIC18F8X20 Type
7
MCLR/VPP
9
I
MCLR
ST
VPP
OSC1/CLKI
OSC1
Buffer
Type
39
49
I
CMOS/ST
CMOS
CLKO
RA6
I/O
TTL
CLKI
OSC2/CLKO/RA6
OSC2
40
50
Description
Master Clear (input) or programming
voltage (output).
Master Clear (Reset) input. This pin is
an active-low Reset to the device.
Programming voltage input.
Oscillator crystal or external clock input.
Oscillator crystal input or external clock
source input. ST buffer when configured
in RC mode; otherwise CMOS.
External clock source input. Always
associated with pin function OSC1
(see OSC1/CLKI, OSC2/CLKO pins).
Oscillator crystal or clock output.
Oscillator crystal output.
Connects to crystal or resonator in
Crystal Oscillator mode.
In RC mode, OSC2 pin outputs CLKO,
which has 1/4 the frequency of OSC1
and denotes the instruction cycle rate.
General purpose I/O pin.
DS39609B-page 11
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTA is a bidirectional I/O port.
RA0/AN0
RA0
AN0
24
RA1/AN1
RA1
AN1
23
RA2/AN2/VREFRA2
AN2
VREF-
22
RA3/AN3/VREF+
RA3
AN3
VREF+
21
RA4/T0CKI
RA4
28
30
RA6
27
TTL
Analog
Digital I/O.
Analog input 0.
I/O
I
TTL
Analog
Digital I/O.
Analog input 1.
I/O
I
I
TTL
Analog
Analog
Digital I/O.
Analog input 2.
A/D reference voltage (Low) input.
I/O
I
I
TTL
Analog
Analog
Digital I/O.
Analog input 3.
A/D reference voltage (High) input.
I/O
ST/OD
ST
I/O
I
I
TTL
Analog
Analog
29
28
27
34
T0CKI
RA5/AN4/LVDIN
RA5
AN4
LVDIN
I/O
I
33
Digital I/O.
Analog input 4.
Low-Voltage Detect input.
See the OSC2/CLKO/RA6 pin.
DS39609B-page 12
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTB is a bidirectional I/O port. PORTB
can be software programmed for internal
weak pull-ups on all inputs.
RB0/INT0
RB0
INT0
48
RB1/INT1
RB1
INT1
47
RB2/INT2
RB2
INT2
46
RB3/INT3/CCP2
RB3
INT3
CCP2(1)
45
RB4/KBI0
RB4
KBI0
44
RB5/KBI1/PGM
RB5
KBI1
PGM
43
RB6/KBI2/PGC
RB6
KBI2
PGC
42
RB7/KBI3/PGD
RB7
KBI3
PGD
37
58
I/O
I
TTL
ST
Digital I/O.
External interrupt 0.
I/O
I
TTL
ST
Digital I/O.
External interrupt 1.
I/O
I
TTL
ST
Digital I/O.
External interrupt 2.
I/O
I/O
I/O
TTL
ST
ST
Digital I/O.
External interrupt 3.
Capture2 input, Compare2 output,
PWM2 output.
I/O
I
TTL
ST
Digital I/O.
Interrupt-on-change pin.
I/O
I
I/O
TTL
ST
ST
Digital I/O.
Interrupt-on-change pin.
Low-Voltage ICSP Programming enable
pin.
I/O
I
I/O
TTL
ST
ST
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and
ICSP programming clock.
I/O
I/O
TTL
ST
Digital I/O.
Interrupt-on-change pin.
In-Circuit Debugger and
ICSP programming data.
57
56
55
54
53
52
47
DS39609B-page 13
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTC is a bidirectional I/O port.
RC0/T1OSO/T13CKI
RC0
T1OSO
T13CKI
30
RC1/T1OSI/CCP2
RC1
T1OSI
CCP2(2)
29
RC2/CCP1
RC2
CCP1
33
RC3/SCK/SCL
RC3
SCK
34
36
35
RC5/SDO
RC5
SDO
36
RC6/TX1/CK1
RC6
TX1
CK1
31
RC7/RX1/DT1
RC7
RX1
DT1
32
ST
ST
Digital I/O.
Timer1 oscillator output.
Timer1/Timer3 external clock input.
I/O
I
I/O
ST
CMOS
ST
Digital I/O.
Timer1 oscillator input.
Capture2 input/Compare2 output/
PWM2 output.
I/O
I/O
ST
ST
Digital I/O.
Capture1 input/Compare1 output/
PWM1 output.
I/O
I/O
ST
ST
I/O
ST
Digital I/O.
Synchronous serial clock input/output
for SPI mode.
Synchronous serial clock input/output
for I2C mode.
I/O
I
I/O
ST
ST
ST
Digital I/O.
SPI data in.
I2C data I/O.
I/O
O
ST
Digital I/O.
SPI data out.
I/O
O
I/O
ST
ST
Digital I/O.
USART 1 asynchronous transmit.
USART 1 synchronous clock
(see RX1/DT1).
I/O
I
I/O
ST
ST
ST
Digital I/O.
USART 1 asynchronous receive.
USART 1 synchronous data
(see TX1/CK1).
35
43
44
SCL
RC4/SDI/SDA
RC4
SDI
SDA
I/O
O
I
45
46
37
38
DS39609B-page 14
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTD is a bidirectional I/O port. These
pins have TTL input buffers when external
memory is enabled.
RD0/PSP0/AD0
RD0
PSP0
AD0(3)
58
RD1/PSP1/AD1
RD1
PSP1
AD1(3)
55
RD2/PSP2/AD2
RD2
PSP2
AD2(3)
54
RD3/PSP3/AD3
RD3
PSP3
AD3(3)
53
RD4/PSP4/AD4
RD4
PSP4
AD4(3)
52
RD5/PSP5/AD5
RD5
PSP5
AD5(3)
51
RD6/PSP6/AD6
RD6
PSP6
AD6(3)
50
RD7/PSP7/AD7
RD7
PSP7
AD7(3)
49
72
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 0.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 1.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 2.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 3.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 4.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 5.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 6.
I/O
I/O
I/O
ST
TTL
TTL
Digital I/O.
Parallel Slave Port data.
External memory address/data 7.
69
68
67
66
65
64
63
DS39609B-page 15
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTE is a bidirectional I/O port.
RE0/RD/AD8
RE0
RD
AD8(3)
RE1/WR/AD9
RE1
WR
64
RE3/AD11
RE3
AD11(3)
RE4/AD12
RE4
AD12
62
RE5/AD13
RE5
AD13(3)
61
RE6/AD14
RE6
AD14(3)
60
RE7/CCP2/AD15
RE7
CCP2(1,4)
59
AD15(3)
Digital I/O.
Read control for Parallel Slave Port
(see WR and CS pins).
External memory address/data 8.
I/O
TTL
I/O
I
ST
TTL
I/O
TTL
I/O
I
ST
TTL
I/O
TTL
Digital I/O.
Chip select control for Parallel Slave
Port (see RD and WR).
External memory address/data 10.
I/O
I/O
ST
TTL
Digital I/O.
External memory address/data 11.
I/O
I/O
ST
TTL
Digital I/O.
External memory address/data 12.
I/O
I/O
ST
TTL
Digital I/O.
External memory address/data 13.
I/O
I/O
ST
TTL
Digital I/O.
External memory address/data 14.
I/O
I/O
ST
ST
I/O
TTL
Digital I/O.
Capture2 input/Compare2 output/
PWM2 output.
External memory address/data 15.
Digital I/O.
Write control for Parallel Slave Port
(see CS and RD pins).
External memory address/data 9.
78
AD10(3)
63
ST
TTL
AD9(3)
RE2/CS/AD10
RE2
CS
I/O
I
77
76
75
74
73
DS39609B-page 16
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTF is a bidirectional I/O port.
RF0/AN5
RF0
AN5
18
RF1/AN6/C2OUT
RF1
AN6
C2OUT
17
RF2/AN7/C1OUT
RF2
AN7
C1OUT
16
RF3/AN8
RF1
AN8
15
RF4/AN9
RF1
AN9
14
RF5/AN10/CVREF
RF1
AN10
CVREF
13
RF6/AN11
RF6
AN11
12
RF7/SS
RF7
SS
11
24
I/O
I
ST
Analog
Digital I/O.
Analog input 5.
I/O
I
O
ST
Analog
ST
Digital I/O.
Analog input 6.
Comparator 2 output.
I/O
I
O
ST
Analog
ST
Digital I/O.
Analog input 7.
Comparator 1 output.
I/O
I
ST
Analog
Digital I/O.
Analog input 8.
I/O
I
ST
Analog
Digital I/O.
Analog input 9.
I/O
I
O
ST
Analog
Analog
Digital I/O.
Analog input 10.
Comparator VREF output.
I/O
I
ST
Analog
Digital I/O.
Analog input 11.
I/O
I
ST
TTL
23
18
17
16
15
14
13
Digital I/O.
SPI slave select input.
DS39609B-page 17
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTG is a bidirectional I/O port.
RG0/CCP3
RG0
CCP3
RG1/TX2/CK2
RG1
TX2
CK2
RG2/RX2/DT2
RG2
RX2
DT2
RG3/CCP4
RG3
CCP4
RG4/CCP5
RG4
CCP5
5
I/O
I/O
ST
ST
Digital I/O.
Capture3 input/Compare3 output/
PWM3 output.
I/O
O
I/O
ST
ST
Digital I/O.
USART 2 asynchronous transmit.
USART 2 synchronous clock
(see RX2/DT2).
I/O
I
I/O
ST
ST
ST
Digital I/O.
USART 2 asynchronous receive.
USART 2 synchronous data
(see TX2/CK2).
I/O
I/O
ST
ST
Digital I/O.
Capture4 input/Compare4 output/
PWM4 output.
I/O
I/O
ST
ST
Digital I/O.
Capture5 input/Compare5 output/
PWM5 output.
10
DS39609B-page 18
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTH is a bidirectional I/O port(5).
RH0/A16
RH0
A16
RH1/A17
RH1
A17
RH2/A18
RH2
A18
RH3/A19
RH3
A19
RH4/AN12
RH4
AN12
RH5/AN13
RH5
AN13
RH6/AN14
RH6
AN14
RH7/AN15
RH7
AN15
79
I/O
O
ST
TTL
Digital I/O.
External memory address 16.
I/O
O
ST
TTL
Digital I/O.
External memory address 17.
I/O
O
ST
TTL
Digital I/O.
External memory address 18.
I/O
O
ST
TTL
Digital I/O.
External memory address 19.
I/O
I
ST
Analog
Digital I/O.
Analog input 12.
I/O
I
ST
Analog
Digital I/O.
Analog input 13.
I/O
I
ST
Analog
Digital I/O.
Analog input 14.
I/O
I
ST
Analog
Digital I/O.
Analog input 15.
80
22
21
20
19
DS39609B-page 19
PIC18F6520/8520/6620/8620/6720/8720
TABLE 1-2:
Pin Name
Pin
Type
PIC18F6X20 PIC18F8X20
Buffer
Type
Description
PORTJ is a bidirectional I/O port(5).
RJ0/ALE
RJ0
ALE
RJ1/OE
RJ1
OE
RJ2/WRL
RJ2
WRL
RJ3/WRH
RJ3
WRH
RJ4/BA0
RJ4
BA0
RJ5/CE
RJ5
CE
RJ6/LB
RJ6
LB
RJ7/UB
RJ7
UB
62
I/O
O
ST
TTL
Digital I/O.
External memory address latch enable.
I/O
O
ST
TTL
Digital I/O.
External memory output enable.
I/O
O
ST
TTL
Digital I/O.
External memory write low control.
I/O
O
ST
TTL
Digital I/O.
External memory write high control.
I/O
O
ST
TTL
Digital I/O.
External memory Byte Address 0 control.
I/O
O
ST
TTL
Digital I/O.
External memory chip enable control.
I/O
O
ST
TTL
Digital I/O.
External memory low byte select.
I/O
O
ST
TTL
Digital I/O.
External memory high byte select.
61
60
59
39
40
41
42
VSS
9, 25,
41, 56
11, 31,
51, 70
VDD
10, 26,
38, 57
12, 32,
48, 71
AVSS(6)
20
26
AVDD(6)
19
25
DS39609B-page 20
PIC18F6520/8520/6620/8620/6720/8720
2.0
OSCILLATOR
CONFIGURATIONS
2.1
Oscillator Types
TABLE 2-1:
Mode
LP
XT
HS
HS+PLL
5.
6.
RC
RCIO
7.
8.
EC
ECIO
2.2
Low-Power Crystal
Crystal/Resonator
High-Speed Crystal/Resonator
High-Speed Crystal/Resonator
with PLL enabled
External Resistor/Capacitor
External Resistor/Capacitor with
I/O pin enabled
External Clock
External Clock with I/O pin
enabled
FIGURE 2-1:
C1(1)
C2
XT
455 kHz
68-100 pF
68-100 pF
2.0 MHz
15-68 pF
15-68 pF
4.0 MHz
15-68 pF
15-68 pF
HS
8.0 MHz
10-68 pF
10-68 pF
16.0 MHz
10-22 pF
10-22 pF
These values are for design guidance only.
See notes following this table.
Resonators Used:
2.0 MHz Murata Erie CSA2.00MG
0.5%
4.0 MHz Murata Erie CSA4.00MG
0.5%
8.0 MHz Murata Erie CSA8.00MT
0.5%
16.0 MHz Murata Erie CSA16.00MX
0.5%
All resonators used did not have built-in capacitors.
CRYSTAL/CERAMIC
RESONATOR OPERATION
(HS, XT OR LP
CONFIGURATION)
OSC1
XTAL
RS(2)
C2(1)
C1
Crystal Oscillator/Ceramic
Resonators
Note:
Freq
OSC2
To
Internal
Logic
RF(3)
Sleep
PIC18FXX20
Note 1:
2:
3:
DS39609B-page 21
PIC18F6520/8520/6620/8620/6720/8720
TABLE 2-2:
FIGURE 2-2:
Ranges Tested:
Mode
Freq
LP
32 kHz
200 kHz
XT
1 MHz
4 MHz
HS
C1
C2
15-22 pF
15-22 pF
15-22 pF
15-22 pF
8 MHz
15-22 pF
15-22 pF
PIC18FXX20
OSC2
Open
2.3
4 MHz
OSC1
Clock from
Ext. System
RC Oscillator
20 MHz
Capacitor values are for design guidance only.
These capacitors were tested with the above crystal
frequencies for basic start-up and operation. These
values are not optimized.
Different capacitor values may be required to produce
acceptable oscillator operation. The user should test
the performance of the oscillator over the expected
VDD and temperature range for the application.
DS39609B-page 22
FIGURE 2-3:
RC OSCILLATOR MODE
VDD
REXT
OSC1
Internal
Clock
CEXT
PIC18FXX20
VSS
FOSC/4
Recommended values:
OSC2/CLKO
3 k REXT 100 k
CEXT > 20 pF
PIC18F6520/8520/6620/8620/6720/8720
2.4
FIGURE 2-5:
FIGURE 2-4:
Clock from
Ext. System
PIC18FXX20
OSC2
FOSC/4
Clock from
Ext. System
PIC18FXX20
RA6
2.5
I/O (OSC2)
HS/PLL
FIGURE 2-6:
(from Configuration
bit Register)
HS Osc
PLL Enable
Phase
Comparator
OSC2
Crystal
Osc
FIN
FOUT
Loop
Filter
VCO
OSC1
Divide by 4
MUX
SYSCLK
DS39609B-page 23
PIC18F6520/8520/6620/8620/6720/8720
2.6
FIGURE 2-7:
Sleep
Timer1 Oscillator
TSCLK
TT1P
T1OSO
T1OSI
MUX
TOSC
OSC1
TOSC/4
T1OSCEN
Enable
Oscillator
Clock
Source
DS39609B-page 24
PIC18F6520/8520/6620/8620/6720/8720
2.6.1
Note:
REGISTER 2-1:
OSCCON REGISTER
U-0
bit 7
U-0
U-0
U-0
U-0
U-0
U-0
R/W-1
SCS
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 25
PIC18F6520/8520/6620/8620/6720/8720
2.6.2
OSCILLATOR TRANSITIONS
FIGURE 2-8:
Q1 Q2
Q3 Q4
Q1
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
TT1P
1
T1OSI
TSCS
OSC1
Internal
System
Clock
TOSC
TDLY
SCS
(OSCCON<0>)
Program
Counter
PC
PC + 2
PC + 4
Note 1: Delay on internal system clock is eight oscillator cycles for synchronization.
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.
FIGURE 2-9:
TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS, XT, LP)
Q3
Q4
Q1
Q1
TT1P
Q2 Q3
Q4
Q1
Q2
Q3
T1OSI
OSC1
1
TOST
TSCS
OSC2
TOSC
Internal
System Clock
SCS
(OSCCON<0>)
Program
Counter
PC
PC + 2
PC + 6
DS39609B-page 26
PIC18F6520/8520/6620/8620/6720/8720
frequency. A timing diagram, indicating the transition
from the Timer1 oscillator to the main oscillator for
HS-PLL mode, is shown in Figure 2-10.
FIGURE 2-10:
TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS WITH PLL)
Q4
Q1 Q2 Q3 Q4
TT1P
Q1
Q1 Q2 Q3 Q4
T1OSI
OSC1
TOST
TPLL
OSC2
TSCS
TOSC
PLL Clock
Input
Internal System
Clock
SCS
(OSCCON<0>)
Program Counter
PC
PC + 2
PC + 4
FIGURE 2-11:
Q4
T1OSI
Q1
Q1 Q2 Q3
TT1P
Q4 Q1 Q2
Q3 Q4
TOSC
OSC1
OSC2
Internal System
Clock
SCS
(OSCCON<0>)
TSCS
Program
Counter
PC
PC + 2
PC + 4
DS39609B-page 27
PIC18F6520/8520/6620/8620/6720/8720
2.7
When the device executes a SLEEP instruction, the onchip clocks and oscillator are turned off and the device
is held at the beginning of an instruction cycle (Q1
state). With the oscillator off, the OSC1 and OSC2
signals will stop oscillating. Since all the transistor
switching currents have been removed, Sleep mode
achieves the lowest current consumption of the device
(only leakage currents). Enabling any on-chip feature
that will operate during Sleep will increase the current
consumed during Sleep. The user can wake from
Sleep through external Reset, Watchdog Timer Reset
or through an interrupt.
TABLE 2-3:
OSC Mode
2.8
Power-up Delays
OSC2 Pin
RC
At logic low
RCIO
ECIO
Floating
EC
Floating
At logic low
LP, XT and HS
Note:
See Table 3-1 in Section 3.0 Reset for time-outs due to Sleep and MCLR Reset.
DS39609B-page 28
PIC18F6520/8520/6620/8620/6720/8720
3.0
RESET
differentiate
between
FIGURE 3-1:
Stack
Pointer
External Reset
WDT
Time-out
Reset
MCLR
WDT
Module
Sleep
VDD Rise Power-on Reset
Detect
VDD
Brown-out
Reset
BOREN
OST/PWRT
OST
10-bit Ripple Counter
Chip_Reset
R
OSC1
PWRT
On-chip
RC OSC(1)
Enable PWRT
Enable OST(2)
Note 1:
2:
DS39609B-page 29
PIC18F6520/8520/6620/8620/6720/8720
3.1
FIGURE 3-2:
EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW VDD POWER-UP)
R
R1
MCLR
C
PIC18FXX20
Note 1:
2:
3:
R1 = 1 k to 10 k will limit any current flowing into MCLR from external capacitor C, in
the event of MCLR/VPP pin breakdown due to
Electrostatic Discharge (ESD) or Electrical
Overstress (EOS).
3.2
DS39609B-page 30
3.4
3.5
VDD
D
3.3
3.6
Time-out Sequence
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-1:
Oscillator
Configuration
Brown-out
Wake-up from
Sleep or
Oscillator Switch
PWRTE = 0
PWRTE = 1
72 ms + 1024 TOSC
+ 2ms
1024 TOSC
+ 2 ms
1024 TOSC + 2 ms
HS, XT, LP
72 ms + 1024 TOSC
1024 TOSC
1024 TOSC
EC
External RC
Note 1:
2:
3:
1.5 s
72 ms
72 ms
72 ms
(2)
1.5 s(3)
72 ms
(2)
REGISTER 3-1:
U-0
U-0
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
IPEN
RI
TO
PD
POR
BOR
bit 7
bit 0
TABLE 3-2:
RCON
Register
RI
TO
PD
POR
BOR
STKFUL
STKUNF
Power-on Reset
0000h
0--1 1100
0000h
0--u uuuu
0000h
0--0 uuuu
0000h
0--u uu11
0000h
0--u uu11
0000h
0--u 10uu
WDT Reset
0000h
0--u 01uu
WDT Wake-up
PC + 2
u--u 00uu
Brown-out Reset
0000h
0--1 11u0
u--u 00uu
Condition
PC + 2
(1)
DS39609B-page 31
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Resets
WDT Reset
RESET Instruction
Stack Resets
---0 0000
---0 uuuu(3)
TOSH
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu(3)
TOSL
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu(3)
STKPTR
PIC18F6X20 PIC18F8X20
00-0 0000
uu-0 0000
uu-u uuuu(3)
PCLATU
PIC18F6X20 PIC18F8X20
---0 0000
---0 0000
---u uuuu
PCLATH
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
PCL
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
PC + 2(2)
TBLPTRU
PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
TBLPTRH
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TBLPTRL
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TABLAT
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
PRODH
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PRODL
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
INTCON
PIC18F6X20 PIC18F8X20
0000 000x
0000 000u
uuuu uuuu(1)
INTCON2
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu(1)
INTCON3
PIC18F6X20 PIC18F8X20
1100 0000
1100 0000
uuuu uuuu(1)
INDF0
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTINC0 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTDEC0 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PREINC0
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PLUSW0
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
FSR0H
PIC18F6X20 PIC18F8X20
---- xxxx
---- uuuu
---- uuuu
FSR0L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
WREG
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
INDF1
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTINC1 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTDEC1 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PREINC1
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PLUSW1
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as 0, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 3-2 for Reset value for specific condition.
5: Bit 6 of PORTA, LATA and TRISA are enabled in ECIO and RCIO Oscillator modes only. In all other
oscillator modes, they are disabled and read 0.
6: Bit 6 of PORTA, LATA and TRISA are not available on all devices. When unimplemented, they are read 0.
TOSU
PIC18F6X20 PIC18F8X20
DS39609B-page 32
---0 0000
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-3:
Register
Power-on Reset,
Brown-out Reset
MCLR Resets
WDT Reset
RESET Instruction
Stack Resets
FSR1H
PIC18F6X20 PIC18F8X20
---- xxxx
---- uuuu
---- uuuu
FSR1L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
BSR
PIC18F6X20 PIC18F8X20
---- 0000
---- 0000
---- uuuu
INDF2
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTINC2 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
POSTDEC2 PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PREINC2
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
PLUSW2
PIC18F6X20 PIC18F8X20
N/A
N/A
N/A
FSR2H
PIC18F6X20 PIC18F8X20
---- xxxx
---- uuuu
---- uuuu
FSR2L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
STATUS
PIC18F6X20 PIC18F8X20
---x xxxx
---u uuuu
---u uuuu
TMR0H
PIC18F6X20 PIC18F8X20
0000 0000
uuuu uuuu
uuuu uuuu
TMR0L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T0CON
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
OSCCON
PIC18F6X20 PIC18F8X20
---- ---0
---- ---0
---- ---u
LVDCON
PIC18F6X20 PIC18F8X20
--00 0101
--00 0101
--uu uuuu
WDTCON
PIC18F6X20 PIC18F8X20
---- ---0
---- ---0
---- ---u
RCON(4)
PIC18F6X20 PIC18F8X20
0--q 11qq
0--q qquu
u--u qquu
TMR1H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR1L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T1CON
PIC18F6X20 PIC18F8X20
0-00 0000
u-uu uuuu
u-uu uuuu
TMR2
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
PR2
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
1111 1111
T2CON
PIC18F6X20 PIC18F8X20
-000 0000
-000 0000
-uuu uuuu
SSPBUF
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
SSPADD
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
SSPSTAT
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
SSPCON1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
SSPCON2
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as 0, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 3-2 for Reset value for specific condition.
5: Bit 6 of PORTA, LATA and TRISA are enabled in ECIO and RCIO Oscillator modes only. In all other
oscillator modes, they are disabled and read 0.
6: Bit 6 of PORTA, LATA and TRISA are not available on all devices. When unimplemented, they are read 0.
DS39609B-page 33
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-3:
Register
Power-on Reset,
Brown-out Reset
MCLR Resets
WDT Reset
RESET Instruction
Stack Resets
ADRESH
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADRESL
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADCON0
PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
ADCON1
PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
ADCON2
PIC18F6X20 PIC18F8X20
0--- -000
0--- -000
u--- -uuu
CCPR1H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR1L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP1CON PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
CCPR2H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR2L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP2CON PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
CCPR3H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR3L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP3CON PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
CVRCON
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
CMCON
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TMR3H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR3L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
T3CON
PIC18F6X20 PIC18F8X20
0000 0000
uuuu uuuu
uuuu uuuu
PSPCON
PIC18F6X20 PIC18F8X20
0000 ---0000 ---uuuu ---SPBRG1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
RCREG1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TXREG1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TXSTA1
PIC18F6X20 PIC18F8X20
0000 -010
0000 -010
uuuu -uuu
RCSTA1
PIC18F6X20 PIC18F8X20
0000 000x
0000 000x
uuuu uuuu
EEADRH
PIC18F6X20 PIC18F8X20
---- --00
---- --00
---- --uu
EEADR
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
EEDATA
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
EECON2
PIC18F6X20 PIC18F8X20
---- ------- ------- ---EECON1
PIC18F6X20 PIC18F8X20
xx-0 x000
uu-0 u000
uu-0 u000
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as 0, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 3-2 for Reset value for specific condition.
5: Bit 6 of PORTA, LATA and TRISA are enabled in ECIO and RCIO Oscillator modes only. In all other
oscillator modes, they are disabled and read 0.
6: Bit 6 of PORTA, LATA and TRISA are not available on all devices. When unimplemented, they are read 0.
DS39609B-page 34
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-3:
Register
Power-on Reset,
Brown-out Reset
MCLR Resets
WDT Reset
RESET Instruction
Stack Resets
IPR3
PIC18F6X20 PIC18F8X20
--11 1111
--11 1111
--uu uuuu
PIR3
PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
PIE3
PIC18F6X20 PIC18F8X20
--00 0000
--00 0000
--uu uuuu
IPR2
PIC18F6X20 PIC18F8X20
-1-1 1111
-1-1 1111
-u-u uuuu
PIR2
PIC18F6X20 PIC18F8X20
-0-0 0000
-0-0 0000
-u-u uuuu(1)
PIE2
PIC18F6X20 PIC18F8X20
-0-0 0000
-0-0 0000
-u-u uuuu
IPR1
PIC18F6X20 PIC18F8X20
0111 1111
0111 1111
uuuu uuuu
PIR1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu(1)
PIE1
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
MEMCON
PIC18F6X20 PIC18F8X20
0-00 --00
0-00 --00
u-uu --uu
TRISJ
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISH
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISG
PIC18F6X20 PIC18F8X20
---1 1111
---1 1111
---u uuuu
TRISF
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISE
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISD
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISC
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
TRISB
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
(5,6)
(5)
(5)
TRISA
PIC18F6X20 PIC18F8X20
-111 1111
-111 1111
-uuu uuuu(5)
LATJ
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATH
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATG
PIC18F6X20 PIC18F8X20
---x xxxx
---u uuuu
---u uuuu
LATF
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATE
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATD
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATC
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATB
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATA(5,6)
PIC18F6X20 PIC18F8X20
-xxx xxxx(5)
-uuu uuuu(5)
-uuu uuuu(5)
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as 0, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 3-2 for Reset value for specific condition.
5: Bit 6 of PORTA, LATA and TRISA are enabled in ECIO and RCIO Oscillator modes only. In all other
oscillator modes, they are disabled and read 0.
6: Bit 6 of PORTA, LATA and TRISA are not available on all devices. When unimplemented, they are read 0.
DS39609B-page 35
PIC18F6520/8520/6620/8620/6720/8720
TABLE 3-3:
Register
Power-on Reset,
Brown-out Reset
MCLR Resets
WDT Reset
RESET Instruction
Stack Resets
PORTJ
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTH
PIC18F6X20 PIC18F8X20
0000 xxxx
0000 uuuu
uuuu uuuu
PORTG
PIC18F6X20 PIC18F8X20
---x xxxx
uuuu uuuu
---u uuuu
PORTF
PIC18F6X20 PIC18F8X20
x000 0000
u000 0000
u000 0000
PORTE
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTD
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTC
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTB
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTA(5,6) PIC18F6X20 PIC18F8X20
-x0x 0000(5)
-u0u 0000(5)
-uuu uuuu(5)
TMR4
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
PR4
PIC18F6X20 PIC18F8X20
1111 1111
1111 1111
uuuu uuuu
T4CON
PIC18F6X20 PIC18F8X20
-000 0000
-000 0000
-uuu uuuu
CCPR4H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR4L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP4CON PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
CCPR5H
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR5L
PIC18F6X20 PIC18F8X20
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP5CON PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
SPBRG2
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
RCREG2
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TXREG2
PIC18F6X20 PIC18F8X20
0000 0000
0000 0000
uuuu uuuu
TXSTA2
PIC18F6X20 PIC18F8X20
0000 -010
0000 -010
uuuu -uuu
RCSTA2
PIC18F6X20 PIC18F8X20
0000 000x
0000 000x
uuuu uuuu
Legend: u = unchanged, x = unknown, - = unimplemented bit, read as 0, q = value depends on condition.
Shaded cells indicate conditions do not apply for the designated device.
Note 1: One or more bits in the INTCONx or PIRx registers will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the PC is loaded with the
interrupt vector (0008h or 0018h).
3: When the wake-up is due to an interrupt and the GIEL or GIEH bit is set, the TOSU, TOSH and TOSL are
updated with the current value of the PC. The STKPTR is modified to point to the next location in the
hardware stack.
4: See Table 3-2 for Reset value for specific condition.
5: Bit 6 of PORTA, LATA and TRISA are enabled in ECIO and RCIO Oscillator modes only. In all other
oscillator modes, they are disabled and read 0.
6: Bit 6 of PORTA, LATA and TRISA are not available on all devices. When unimplemented, they are read 0.
DS39609B-page 36
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 3-3:
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 3-4:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 3-5:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
DS39609B-page 37
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 3-6:
0V
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 3-7:
VDD
MCLR
IINTERNAL POR
TPWRT
PWRT TIME-OUT
OST TIME-OUT
TOST
TPLL
PLL TIME-OUT
INTERNAL RESET
Note:
DS39609B-page 38
PIC18F6520/8520/6620/8620/6720/8720
4.0
MEMORY ORGANIZATION
4.1
4.1.1
Microprocessor (MP)
Microprocessor with Boot Block (MPBB)
Extended Microcontroller (EMC)
Microcontroller (MC)
DS39609B-page 39
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 4-1:
21
Stack Level 31
000000h
000000h
000000h
Reset Vector
000008h
000008h
000008h
High Priority
Interrupt Vector
000018h
000018h
000018h
Low Priority
Interrupt Vector
On-Chip Flash
Program Memory
On-Chip Flash
Program Memory
00FFFFh
010000h
On-Chip Flash
Program Memory
007FFFh
008000h
01FFFFh
020000h
Read 0
1FFFFFh
200000h
1FFFFFh
200000h
PIC18FX520
(32 Kbyte)
Note:
Read 0
Read 0
PIC18FX620
(64 Kbyte)
1FFFFFh
200000h
PIC18FX720
(128 Kbyte)
TABLE 4-1:
Operating Mode
Execution
From
Table Read
From
Table Write To
Microprocessor
No Access
No Access
No Access
Microprocessor
with Boot Block
Yes
Yes
Yes
Microcontroller
Yes
Yes
Yes
Extended
Microcontroller
Yes
Yes
Yes
DS39609B-page 40
Execution
From
Table Read
From
Table Write To
Yes
Yes
Yes
Yes
Yes
Yes
No Access
No Access
No Access
Yes
Yes
Yes
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 4-1:
U-0
U-0
U-0
U-0
U-0
R/P-1
R/P-1
WAIT
PM1
PM0
bit 7
bit 0
bit 7
bit 6-2
Unimplemented: Read as 0
bit 1-0
FIGURE 4-2:
R = Readable bit
1 = Bit is set
x = Bit is unknown
Microprocessor
Mode (MP)
000000h
On-Chip
Program
Memory
(No
access)
Program Space Execution
0 = Bit is cleared
000000h
Boot
Boot+1
On-Chip
Flash
Boundary
Boundary+1
Boundary
Boundary+1
Reads
0s
1FFFFFh
External
Memory
1FFFFFh
External
Memory
On-Chip
Program
Memory
On-Chip
Program
Memory
External
Program
Memory
1FFFFFh
000000h
000000h
On-Chip
Program
Memory
External
Program
Memory
Extended
Microcontroller
Mode (EMC)
Microcontroller
Mode (MC)
On-Chip
Flash
External
Program
Memory
1FFFFFh
External
Memory
On-Chip
Flash
On-Chip
Flash
Boundary Values for Microprocessor with Boot Block, Microcontroller and Extended Microcontroller modes(1)
Device
Boot
Boot+1
Boundary
Boundary+1
Available
Memory Mode(s)
PIC18F6520
0007FFh
000800h
007FFFh
008000h
MC
PIC18F6620
0001FFh
000200h
00FFFFh
010000h
MC
PIC18F6720
0001FFh
000200h
01FFFFh
020000h
MC
PIC18F8520
0007FFh
000800h
007FFFh
008000h
PIC18F8620
0001FFh
000200h
00FFFFh
010000h
PIC18F8720
0001FFh
000200h
01FFFFh
020000h
Note 1:
PIC18F6X20 devices are included here for completeness, to show the boundaries of their Boot Blocks and program memory spaces.
DS39609B-page 41
PIC18F6520/8520/6620/8620/6720/8720
4.2
4.2.1
TOP-OF-STACK ACCESS
DS39609B-page 42
4.2.2
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 4-2:
STKPTR REGISTER
R/C-0
R/C-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
SP4
SP3
SP2
SP1
SP0
STKFUL(1) STKUNF(1)
bit 7
bit 0
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4-0
FIGURE 4-3:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
TOSH
0x1A
STKPTR<4:0>
00010
TOSL
0x34
00011
Top-of-Stack 0x001A34 00010
0x000D58 00001
00000
4.2.3
4.2.4
The ability to pull the TOS value off of the stack and
replace it with the value that was previously pushed
onto the stack, without disturbing normal execution, is
achieved by using the POP instruction. The POP
instruction discards the current TOS by decrementing
the stack pointer. The previous value pushed onto the
stack then becomes the TOS value.
DS39609B-page 43
PIC18F6520/8520/6620/8620/6720/8720
4.3
4.4
The contents of PCLATH and PCLATU will be transferred to the program counter by an operation that
writes PCL. Similarly, the upper two bytes of the
program counter will be transferred to PCLATH and
PCLATU by an operation that reads PCL. This is useful
for computed offsets to the PC (see Section 4.8.1
Computed GOTO).
EXAMPLE 4-1:
4.5
SUB1
FIGURE 4-4:
Clocking Scheme/Instruction
Cycle
RETURN FAST
CLOCK/INSTRUCTION CYCLE
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
OSC1
Q1
Q2
Internal
Phase
Clock
Q3
Q4
PC
OSC2/CLKO
(RC mode)
DS39609B-page 44
PC
PC+2
PC+4
PIC18F6520/8520/6620/8620/6720/8720
4.6
Instruction Flow/Pipelining
EXAMPLE 4-2:
1. MOVLW 55h
TCY0
TCY1
Fetch 1
Execute 1
Fetch 2
2. MOVWF PORTB
3. BRA
4. BSF
TCY2
TCY4
TCY5
Execute 2
Fetch 3
SUB_1
TCY3
Execute 3
Fetch 4
Flush (NOP)
Fetch SUB_1 Execute SUB_1
All instructions are single cycle, except for any program branches. These take two cycles since the fetch instruction is flushed
from the pipeline, while the new instruction is being fetched and then executed.
4.7
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-5 shows an
example of how instruction words are stored in the program 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 PCL,
PCLATH and PCLATU).
FIGURE 4-5:
LSB = 0
0Fh
EFh
F0h
C1h
F4h
55h
03h
00h
23h
56h
Program Memory
Byte Locations
Instruction 1:
Instruction 2:
MOVLW
GOTO
055h
000006h
Instruction 3:
MOVFF
123h, 456h
Word Address
000000h
000002h
000004h
000006h
000008h
00000Ah
00000Ch
00000Eh
000010h
000012h
000014h
DS39609B-page 45
PIC18F6520/8520/6620/8620/6720/8720
4.7.1
TWO-WORD INSTRUCTIONS
The PIC18FXX20 devices have four two-word instructions: MOVFF, CALL, GOTO and LFSR. The second word
of these instructions has the 4 MSBs set to 1s 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
EXAMPLE 4-3:
TWO-WORD INSTRUCTIONS
CASE 1:
Object Code
Source Code
TSTFSZ
REG1
MOVFF
; is RAM location 0?
REG3
; continue code
CASE 2:
Object Code
Source Code
TSTFSZ
REG1
MOVFF
ADDWF
REG3
4.8
Look-up Tables
4.8.1
; is RAM location 0?
COMPUTED GOTO
; continue code
4.8.2
DS39609B-page 46
PIC18F6520/8520/6620/8620/6720/8720
4.9
4.9.1
GENERAL PURPOSE
REGISTER FILE
The register file can be accessed either directly or indirectly. Indirect addressing operates using a File Select
Register and corresponding Indirect File Operand. The
operation of indirect addressing is shown in
Section 4.12 Indirect Addressing, INDF and FSR
Registers.
Enhanced MCU devices may 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 General Purpose
Registers by all instructions. The top section of Bank 15
(F60h to FFFh) contains SFRs. All other banks of data
memory contain GPR registers, starting with Bank 0.
4.9.2
DS39609B-page 47
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 4-6:
BSR<3:0>
= 0000
= 0001
= 0010
= 0110
= 0111
Access RAM
FFh
00h
GPRs
000h
05Fh
060h
0FFh
100h
GPRs
Bank 1
FFh
00h
Bank 2
1FFh
200h
GPRs
2FFh
300h
FFh
00h
= 0011
00h
Bank 0
Bank 3
to
Bank 6
GPRs
Access Bank
FFh
00h
Bank 7
6FFh
700h
GPRs
FFh
7FFh
800h
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
Access RAM Low
= 1000
Unused,
Read as 0
Bank 8
to
Bank 14
= 1110
= 1111
00h
Unused
FFh
SFRs
Bank 15
EFFh
F00h
F5Fh
F60h
FFFh
When a = 0,
the BSR is ignored and the
Access Bank is used.
The first 96 bytes are General
Purpose RAM (from Bank 0).
The second 160 bytes are
Special Function Registers
(from Bank 15).
When a = 1,
the BSR is used to specify the
RAM location that the instruction
uses.
DS39609B-page 48
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 4-7:
BSR<3:0>
= 0000
= 0001
= 0010
= 0011
Access RAM
FFh
00h
GPRs
Bank 0
GPRs
Bank 1
FFh
00h
Bank 2
1FFh
200h
GPRs
2FFh
300h
FFh
00h
Bank 3
GPRs
FFh
= 0100
Bank 4
3FFh
400h
GPRs
Access Bank
4FFh
500h
= 0101
000h
05Fh
060h
0FFh
100h
Bank 5
to
Bank 13
GPRs
= 1101
= 1110
= 1111
00h
5Fh
Access RAM High 60h
(SFRs)
FFh
Access RAM Low
DFFh
E00h
00h
Bank 14
GPRs
FFh
00h
Unused
FFh
SFRs
Bank 15
EFFh
F00h
F5Fh
F60h
FFFh
When a = 0,
the BSR is ignored and the
Access Bank is used.
The first 96 bytes are General
Purpose RAM (from Bank 0).
The second 160 bytes are
Special Function Registers
(from Bank 15).
When a = 1,
the BSR is used to specify the
RAM location that the instruction
uses.
DS39609B-page 49
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-2:
Address
Name
FFFh
Address
TOSU
FFEh
FDFh
TOSH
FDEh
Name
Address
(3)
Name
Address
Name
FBFh
CCPR1H
F9Fh
IPR1
POSTINC2(3)
FBEh
CCPR1L
F9Eh
PIR1
(3)
F9Dh
PIE1
INDF2
FFDh
TOSL
FBDh
CCP1CON
FFCh
STKPTR
FDCh
FDDh POSTDEC2
PREINC2(3)
FBCh
CCPR2H
F9Ch MEMCON(2)
FFBh
PCLATU
FDBh
PLUSW2(3)
FBBh
CCPR2L
F9Bh
(1)
FFAh
PCLATH
FDAh
FSR2H
FBAh
CCP2CON
F9Ah
TRISJ
FF9h
PCL
FD9h
FSR2L
FB9h
CCPR3H
F99h
TRISH
FF8h
TBLPTRU
FD8h
STATUS
FB8h
CCPR3L
F98h
TRISG
FF7h
TBLPTRH
FD7h
TMR0H
FB7h
CCP3CON
F97h
TRISF
FF6h
TBLPTRL
FD6h
TMR0L
FB6h
(1)
F96h
TRISE
FF5h
TABLAT
FD5h
T0CON
FB5h
CVRCON
F95h
TRISD
FF4h
PRODH
FD4h
(1)
FB4h
CMCON
F94h
TRISC
FF3h
PRODL
FD3h
OSCCON
FB3h
TMR3H
F93h
TRISB
FF2h
INTCON
FD2h
LVDCON
FB2h
TMR3L
F92h
TRISA
FF1h
INTCON2
FD1h
WDTCON
FB1h
T3CON
F91h
LATJ
FF0h
INTCON3
FD0h
RCON
FB0h
PSPCON
F90h
LATH
FEFh
INDF0(3)
LATG
FCFh
TMR1H
FAFh
SPBRG1
F8Fh
FEEh POSTINC0(3)
FCEh
TMR1L
FAEh
RCREG1
F8Eh
LATF
(3)
FCDh
T1CON
FADh
TXREG1
F8Dh
LATE
FCCh
TMR2
FACh
TXSTA1
F8Ch
LATD
FEDh POSTDEC0
FECh
PREINC0(3)
FEBh
PLUSW0(3)
FCBh
PR2
FABh
RCSTA1
F8Bh
LATC
FEAh
FSR0H
FCAh
T2CON
FAAh
EEADRH
F8Ah
LATB
FE9h
FSR0L
FC9h
SSPBUF
FA9h
EEADR
F89h
LATA
FE8h
WREG
FC8h
SSPADD
FA8h
EEDATA
F88h
PORTJ
FE7h
INDF1(3)
FC7h
SSPSTAT
FA7h
EECON2
F87h
PORTH
FE6h
POSTINC1(3)
FC6h
SSPCON1
FA6h
EECON1
F86h
PORTG
FE5h
POSTDEC1(3)
FC5h
SSPCON2
FA5h
IPR3
F85h
PORTF
FE4h
PREINC1(3)
FC4h
ADRESH
FA4h
PIR3
F84h
PORTE
FE3h
PLUSW1(3)
FC3h
ADRESL
FA3h
PIE3
F83h
PORTD
FE2h
FSR1H
FC2h
ADCON0
FA2h
IPR2
F82h
PORTC
FE1h
FSR1L
FC1h
ADCON1
FA1h
PIR2
F81h
PORTB
FE0h
BSR
FC0h
ADCON2
FA0h
PIE2
F80h
PORTA
Note 1:
2:
3:
DS39609B-page 50
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-2:
Address
Address
Name
F5Fh
(1)
F7Eh
(1)
F7Dh
(1)
F7Ch
(1)
F7Bh
(1)
F7Ah
(1)
F79h
F7Fh
Address
Name
Address
Name
F3Fh
(1)
F1Fh
(1)
F5Eh
(1)
F3Eh
(1)
F1Eh
(1)
F5Dh
(1)
F3Dh
(1)
F1Dh
(1)
F5Ch
(1)
F3Ch
(1)
F1Ch
(1)
F5Bh
(1)
F3Bh
(1)
F1Bh
(1)
F5Ah
(1)
F3Ah
(1)
F1Ah
(1)
(1)
F59h
(1)
F39h
(1)
F19h
(1)
(1)
(1)
(1)
F78h
TMR4
F58h
F38h
F18h
(1)
F77h
PR4
F57h
(1)
F37h
(1)
F17h
(1)
(1)
(1)
F76h
T4CON
F56h
F36h
F16h
(1)
F75h
CCPR4H
F55h
(1)
F35h
(1)
F15h
(1)
F34h
(1)
F14h
(1)
F74h
CCPR4L
F54h
(1)
F73h
CCP4CON
F53h
(1)
F33h
(1)
F13h
(1)
F32h
(1)
F12h
(1)
F72h
CCPR5H
F52h
(1)
F71h
CCPR5L
F51h
(1)
F31h
(1)
F11h
(1)
F30h
(1)
F10h
(1)
F70h
CCP5CON
F50h
(1)
F6Fh
SPBRG2
F4Fh
(1)
F2Fh
(1)
F0Fh
(1)
F2Eh
(1)
F0Eh
(1)
F6Eh
RCREG2
F4Eh
(1)
F6Dh
TXREG2
F4Dh
(1)
F2Dh
(1)
F0Dh
(1)
F2Ch
(1)
F0Ch
(1)
F6Ch
TXSTA2
F4Ch
(1)
F6Bh
RCSTA2
F4Bh
(1)
F2Bh
(1)
F0Bh
(1)
F6Ah
(1)
F4Ah
(1)
F2Ah
(1)
F0Ah
(1)
F69h
(1)
F49h
(1)
F29h
(1)
F09h
(1)
F68h
(1)
F48h
(1)
F28h
(1)
F08h
(1)
F67h
(1)
F47h
(1)
F27h
(1)
F07h
(1)
F66h
(1)
F46h
(1)
F26h
(1)
F06h
(1)
F65h
(1)
F45h
(1)
F25h
(1)
F05h
(1)
F64h
(1)
F44h
(1)
F24h
(1)
F04h
(1)
F63h
(1)
F43h
(1)
F23h
(1)
F03h
(1)
F62h
(1)
F42h
(1)
F22h
(1)
F02h
(1)
F61h
(1)
F41h
(1)
F21h
(1)
F01h
(1)
F60h
(1)
F40h
(1)
F20h
(1)
F00h
(1)
Note 1:
2:
3:
DS39609B-page 51
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-3:
File Name
TOSU
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
Details
POR, BOR on page:
---0 0000
32, 42
TOSH
0000 0000
32, 42
TOSL
0000 0000
32, 42
00-0 0000
32, 43
--10 0000
32, 44
STKPTR
STKFUL
STKUNF
PCLATU
bit 21
PCLATH
0000 0000
32, 44
PCL
0000 0000
32, 44
TBLPTRU
TBLPTRH
bit 21(2)
--00 0000
32, 64
0000 0000
32, 64
TBLPTRL
0000 0000
32, 64
TABLAT
0000 0000
32, 64
PRODH
xxxx xxxx
32, 85
PRODL
xxxx xxxx
32, 85
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
32, 89
INTCON2
RBPU
INTEDG0
INTEDG1
INTEDG2
INTEDG3
TMR0IP
INT3IP
RBIP
1111 1111
32, 90
INT2IP
INT1IP
INT3IE
INT2IE
INT1IE
INT3IF
INT2IF
INT1IF
1100 0000
32, 91
INTCON3
INDF0
Uses contents of FSR0 to address data memory value of FSR0 not changed (not a physical register)
n/a
57
POSTINC0 Uses contents of FSR0 to address data memory value of FSR0 post-incremented
(not a physical register)
n/a
57
POSTDEC0 Uses contents of FSR0 to address data memory value of FSR0 post-decremented
(not a physical register)
n/a
57
PREINC0
Uses contents of FSR0 to address data memory value of FSR0 pre-incremented (not a physical register)
n/a
57
PLUSW0
n/a
57
FSR0H
---- 0000
32, 57
FSR0L
xxxx xxxx
32, 57
WREG
Working Register
xxxx xxxx
32
INDF1
Uses contents of FSR1 to address data memory value of FSR1 not changed (not a physical register)
n/a
57
POSTINC1 Uses contents of FSR1 to address data memory value of FSR1 post-incremented
(not a physical register)
n/a
57
POSTDEC1 Uses contents of FSR1 to address data memory value of FSR1 post-decremented
(not a physical register)
n/a
57
PREINC1
n/a
57
PLUSW1
n/a
57
---- 0000
33, 57
xxxx xxxx
33, 57
---- 0000
33, 56
FSR1H
FSR1L
BSR
INDF2
Uses contents of FSR2 to address data memory value of FSR2 not changed (not a physical register)
n/a
57
POSTINC2 Uses contents of FSR2 to address data memory value of FSR2 post-incremented
(not a physical register)
n/a
57
POSTDEC2 Uses contents of FSR2 to address data memory value of FSR2 post-decremented
(not a physical register)
n/a
57
Legend:
Note 1:
2:
3:
DS39609B-page 52
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-3:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
Details
POR, BOR on page:
PREINC2
n/a
57
PLUSW2
n/a
57
---- 0000
33, 57
FSR2H
FSR2L
STATUS
TMR0H
TMR0L
T0CON
OV
DC
xxxx xxxx
33, 57
---x xxxx
33, 59
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
OSCCON
SCS
LVDCON
IRVST
LVDEN
LVDL3
LVDL2
LVDL1
LVDL0
SWDTE
IPEN
RI
TO
PD
POR
BOR
WDTCON
RCON
TMR1H
TMR1L
T1CON
RD16
TMR2
Timer2 Register
PR2
T2CON
0--1 11qq
25, 33
33, 60,
101
T1CKPS0
T1OSCEN
T1SYNC
TMR1CS
TMR2ON
T2CKPS1
SSPBUF
SSPADD
SSP Address Register in I2C Slave mode. SSP Baud Rate Reload Register in I2C Master mode.
SSPSTAT
SMP
CKE
D/A
R/W
UA
BF
SSPCON1
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
SSPCON2
GCEN
ACKSTAT
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
ADRESH
ADRESL
ADCON0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
ADCON1
VCFG1
VCFG0
PCFG3
PCFG2
PCFG1
PCFG0
ADCON2
ADFM
ADCS2
ADCS1
ADCS0
CCPR1H
CCPR1L
CCP1CON
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
CCPR2H
CCPR2L
CCP2CON
Legend:
Note 1:
2:
3:
DC2B1
DC2B0
CCP2M3
CCP2M2
CCP2M1
CCP2M0
DS39609B-page 53
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-3:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
Details
POR, BOR on page:
CCPR3H
CCPR3L
CCP3CON
DC3B1
DC3B0
CCP3M3
CCP3M2
CCP3M1
CCP3M0
CVRCON
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
C2OUT
C1OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
CMCON
TMR3H
TMR3L
T3CON
PSPCON
RD16
T3CCP2
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
IBF
OBF
IBOV
PSPMODE
SPBRG1
RCREG1
TXREG1
TXSTA1
CSRC
TX9
TXEN
SYNC
BRGH
RCSTA1
SPEN
RX9
SREN
CREN
ADDEN
FERR
EEADRH
TRMT
TX9D
OERR
RX9D
34, 79
EEADR
0000 0000
34, 79
EEDATA
0000 0000
34, 79
EECON2
---- ----
34, 79
xx-0 x000
34, 80
EECON1
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
IPR3
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
35, 97
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
-1-1 1111
35, 99
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
-0-0 0000
35, 93
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
-0-0 0000
35, 96
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
35, 98
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
35, 92
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
35, 95
MEMCON(3)
EBDIS
WAIT1
WAIT0
WM1
WM0
0-00 --00
35, 71
TRISJ(3)
TRISH(3)
TRISG
35, 94
TRISF
1111 1111
35, 117
TRISE
1111 1111
35, 114
TRISD
1111 1111
35, 111
TRISC
TRISB
TRISA
Legend:
Note 1:
2:
3:
TRISA6(1)
DS39609B-page 54
PIC18F6520/8520/6620/8620/6720/8720
TABLE 4-3:
File Name
Bit 6
Bit 5
Bit 4
LATJ(3)
LATH(3)
LATG
Bit 3
Bit 2
Bit 1
Bit 0
Value on
Details
POR, BOR on page:
xxxx xxxx 35, 125
xxxx xxxx 35, 122
LATF
xxxx xxxx
35, 117
LATE
xxxx xxxx
35, 114
LATD
xxxx xxxx
35, 111
LATC
LATB
LATA
LATA6(1)
PORTJ(3)
PORTH(3)
PORTG
PORTF
xxxx xxxx
36, 117
PORTE
xxxx xxxx
36, 114
PORTD
xxxx xxxx
36, 111
PORTC
PORTB
PORTA
RA6(1)
TMR4
Timer4 Register
PR4
T4CON
TMR4ON
T4CKPS1
CCPR4H
CCPR4L
CCP4CON
DC4B1
DC4B0
CCP4M3
CCP4M2
CCP4M1
CCP4M0
CCPR5H
CCPR5L
CCP5CON
DC5B1
DC5B0
CCP5M3
CCP5M2
CCP5M1
CCP5M0
SPBRG2
RCREG2
TXREG2
TXSTA2
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
RCSTA2
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
Legend:
Note 1:
2:
3:
DS39609B-page 55
PIC18F6520/8520/6620/8620/6720/8720
4.10
Access Bank
4.11
FIGURE 4-8:
DIRECT ADDRESSING
Direct Addressing
BSR<3:0>
Bank Select(2)
From Opcode(3)
Location Select(3)
00h
01h
0Eh
0Fh
000h
100h
E00h
F00h
0FFh
1FFh
EFFh
FFFh
Bank 14
Bank 15
Data
Memory(1)
Bank 0
Note 1:
Bank 1
2:
The access bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to the
registers of the Access Bank.
3:
The MOVFF instruction embeds the entire 12-bit address in the instruction.
DS39609B-page 56
PIC18F6520/8520/6620/8620/6720/8720
4.12
Indirect addressing is a mode of addressing data memory, where the data memory address in the instruction
is not fixed. An FSR register is used as a pointer to the
data memory location that is to be read or written. Since
this pointer is in RAM, the contents can be modified by
the program. This can be useful for data tables in the
data memory and for software stacks. Figure 4-9
shows the operation of indirect addressing. This shows
the moving of the value to the data memory address,
specified by the value of the FSR register.
Indirect addressing is possible by using one of the
INDF registers. Any instruction using the INDF register
actually accesses the register pointed to by the File
Select Register, FSR. Reading the INDF register itself,
indirectly (FSR = 0), will read 00h. Writing to the INDF
register indirectly, results in a no operation. The FSR
register contains a 12-bit address, which is shown in
Figure 4-10.
The INDFn register is not a physical register. Addressing INDFn actually addresses the register whose
address is contained in the FSRn register (FSRn is a
pointer). This is indirect addressing.
Example 4-4 shows a simple use of indirect addressing
to clear the RAM in Bank 1 (locations 100h-1FFh) in a
minimum number of instructions.
EXAMPLE 4-4:
FSR0 ,0x100 ;
POSTINC0
; Clear INDF
; register and
; inc pointer
BTFSS FSR0H, 1
; All done with
; Bank 1?
GOTO NEXT
; NO, clear next
CONTINUE
; YES, continue
NEXT
LFSR
CLRF
4.12.1
INDIRECT ADDRESSING
OPERATION
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 4-9:
0h
Instruction
Executed
Opcode
Address
FFFh
12
File Address = Access of an Indirect Addressing Register
BSR<3:0>
Instruction
Fetched
Opcode
FIGURE 4-10:
12
12
8
FSR
File
INDIRECT ADDRESSING
Indirect Addressing
11
FSR Register
Location Select
0000h
Data
Memory(1)
0FFFh
Note 1:
DS39609B-page 58
PIC18F6520/8520/6620/8620/6720/8720
4.13
Status Register
REGISTER 4-3:
STATUS REGISTER
U-0
U-0
U-0
R/W-x
R/W-x
R/W-x
R/W-x
R/W-x
OV
DC
bit 7
bit 0
bit 7-5
Unimplemented: Read as 0
bit 4
N: Negative bit
This bit is used for signed arithmetic (2s complement). It indicates whether the result was
negative (ALU MSB = 1).
1 = Result was negative
0 = Result was positive
bit 3
bit 2
Z: 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 1
bit 0
C: Carry/borrow bit
For ADDWF, ADDLW, SUBLW and SUBWF instructions:
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note:
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 59
PIC18F6520/8520/6620/8620/6720/8720
4.14
RCON Register
REGISTER 4-4:
RCON REGISTER
R/W-0
U-0
U-0
R/W-1
R/W-1
R/W-1
R/W-0
R/W-0
IPEN
RI
TO
PD
POR
BOR
bit 7
bit 0
bit 7
bit 6-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
DS39609B-page 60
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
5.0
Table read operations retrieve data from program memory and place it into the data RAM space. Figure 5-1
shows the operation of a table read with program
memory and data RAM.
5.1
FIGURE 5-1:
Program Memory
Table Pointer(1)
TBLPTRU
TBLPTRH
Program Memory
(TBLPTR)
Note 1:
DS39609B-page 61
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 5-2:
Program Memory
Holding Registers
Table Pointer(1)
TBLPTRU
TBLPTRH
TABLAT
Program Memory
(TBLPTR)
Note 1:
5.2
Table Pointer actually points to one of eight holding registers, the address of which is determined by
TBLPTRL<2:0>. The process for physically writing data to the Program Memory Array is discussed in
Section 5.5 Writing to Flash Program Memory.
Control Registers
EECON1 register
EECON2 register
TABLAT register
TBLPTR registers
5.2.1
DS39609B-page 62
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 5-1:
R/W-x
CFGS
U-0
R/W-0
FREE
R/W-x
WRERR
R/W-0
WREN
R/S-0
WR
R/S-0
RD
bit 0
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows
tracing of the error condition.
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 63
PIC18F6520/8520/6620/8620/6720/8720
5.2.2
5.2.4
5.2.3
TABLE 5-1:
Example
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*-
TBLRD+*
TBLWT+*
FIGURE 5-3:
21
16
15
TBLPTRH
TBLPTRL
ERASE TBLPTR<20:6>
WRITE TBLPTR<21:3>
READ TBLPTR<21:0>
DS39609B-page 64
PIC18F6520/8520/6620/8620/6720/8720
5.3
FIGURE 5-4:
Program Memory
TBLPTR = xxxxx1
Instruction Register
(IR)
EXAMPLE 5-1:
FETCH
TBLRD
TBLPTR = xxxxx0
TABLAT
Read Register
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
READ_WORD
TBLRD*+
MOVF
MOVWF
TBLRD*+
MOVFW
MOVWF
TABLAT, W
WORD_EVEN
TABLAT, W
WORD_ODD
DS39609B-page 65
PIC18F6520/8520/6620/8620/6720/8720
5.4
5.4.1
When initiating an erase sequence from the microcontroller itself, a block of 64 bytes of program memory
is erased. The Most Significant 16 bits of the
TBLPTR<21:6> point to the block being erased.
TBLPTR<5:0> are ignored.
2.
3.
4.
5.
6.
EXAMPLE 5-2:
7.
8.
9.
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
BSF
EECON1,
EECON1,
EECON1,
EECON1,
INTCON,
55h
EECON2
AAh
EECON2
EECON1,
;
;
;
;
;
ERASE_ROW
Required
Sequence
DS39609B-page 66
EEPGD
CFGS
WREN
FREE
GIE
; write 55H
WR
INTCON, GIE
; write AAH
; start erase (CPU stall)
; re-enable interrupts
PIC18F6520/8520/6620/8620/6720/8720
5.5
FIGURE 5-5:
8
TBLPTR = xxxxx0
TBLPTR = xxxxx1
Holding Register
TBLPTR = xxxxx2
Holding Register
8
TBLPTR = xxxxx7
Holding Register
Holding Register
Program Memory
5.5.1
8.
9.
10.
11.
12.
13.
14.
15.
16.
DS39609B-page 67
PIC18F6520/8520/6620/8620/6720/8720
EXAMPLE 5-3:
D64
COUNTER
BUFFER_ADDR_HIGH
FSR0H
BUFFER_ADDR_LOW
FSR0L
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
TBLRD*+
MOVF
MOVWF
DECFSZ
BRA
TABLAT, W
POSTINC0
COUNTER
READ_BLOCK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
DATA_ADDR_HIGH
FSR0H
DATA_ADDR_LOW
FSR0L
NEW_DATA_LOW
POSTINC0
NEW_DATA_HIGH
INDF0
READ_BLOCK
;
;
;
;
;
MODIFY_WORD
; point to buffer
ERASE_BLOCK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
Required
MOVLW
Sequence
MOVWF
BSF
NOP
BSF
TBLRD*WRITE_BUFFER_BACK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
PROGRAM_LOOP
MOVLW
MOVWF
WRITE_WORD_TO_HREGS
MOVFF
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
TBLPTRL
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
EECON1, FREE
INTCON, GIE
55h
EECON2
AAh
EECON2
EECON1, WR
;
;
;
;
;
; write 55H
; write AAH
; start erase (CPU stall)
INTCON, GIE
; re-enable interrupts
; dummy read decrement
8
COUNTER_HI
BUFFER_ADDR_HIGH
FSR0H
BUFFER_ADDR_LOW
FSR0L
8
COUNTER
POSTINC0, WREG
;
;
;
;
;
TBLWT+*
DECFSZ COUNTER
BRA
WRITE_WORD_TO_HREGS
DS39609B-page 68
; point to buffer
PIC18F6520/8520/6620/8620/6720/8720
EXAMPLE 5-3:
PROGRAM_MEMORY
BSF
BCF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
BSF
DECFSZ
BRA
BCF
Required
Sequence
5.5.2
EECON1,
EECON1,
EECON1,
INTCON,
55h
EECON2
AAh
EECON2
EECON1,
EEPGD
CFGS
WREN
GIE
;
;
;
;
; write 55H
; write AAH
; start program (CPU stall)
WR
INTCON, GIE
COUNTER_HI
PROGRAM_LOOP
EECON1, WREN
; re-enable interrupts
; loop until done
; disable write to memory
WRITE VERIFY
5.5.4
5.5.3
UNEXPECTED TERMINATION OF
WRITE OPERATION
TABLE 5-2:
Name
TBLPTRU
5.6
PROTECTION AGAINST
SPURIOUS WRITES
Bit 6
Bit 5
bit 21
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
--00 0000
--00 0000
TBPLTRH
0000 0000
0000 0000
TBLPTRL
0000 0000
0000 0000
TABLAT
0000 0000
0000 0000
0000 0000
0000 0000
INTCON
EECON2
INTE
RBIE
TMR0IF
INTF
RBIF
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
xx-0 x000
uu-0 u000
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
---1 1111
---1 1111
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
---0 0000
---0 0000
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
---0 0000
---0 0000
EECON1
Legend:
DS39609B-page 69
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 70
PIC18F6520/8520/6620/8620/6720/8720
6.0
Note:
EXTERNAL MEMORY
INTERFACE
6.1
REGISTER 6-1:
Note:
MEMCON REGISTER
R/W-0
U-0
R/W-0
R/W-0
U-0
U-0
R/W-0
R/W-0
EBDIS
WAIT1
WAIT0
WM1
WM0
bit7
bit0
bit 7
bit 6
Unimplemented: Read as 0
bit 5-4
WAIT<1:0>: Table Reads and Writes Bus Cycle Wait Count bits
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-2
Unimplemented: Read as 0
bit 1-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 71
PIC18F6520/8520/6620/8620/6720/8720
If the device fetches or accesses external memory
while EBDIS = 1, the pins will switch to external bus. If
the EBDIS bit is set by a program executing from
external memory, the action of setting the bit will be
delayed until the program branches into the internal
memory. At that time, the pins will change from
external bus to I/O ports.
TABLE 6-1:
Name
Port
Bit
Function
RD0/AD0
PORTD
bit 0
RD1/AD1
PORTD
bit 1
RD2/AD2
PORTD
bit 2
RD3/AD3
PORTD
bit 3
RD4/AD4
PORTD
bit 4
RD5/AD5
PORTD
bit 5
RD6/AD6
PORTD
bit 6
RD7/AD7
PORTD
bit 7
RE0/AD8
PORTE
bit 0
RE1/AD9
PORTE
bit 1
RE2/AD10
PORTE
bit 2
RE3/AD11
PORTE
bit 3
RE4/AD12
PORTE
bit 4
RE5/AD13
PORTE
bit 5
RE6/AD14
PORTE
bit 6
RE7/AD15
PORTE
bit 7
RH0/A16
PORTH
bit 0
RH1/A17
PORTH
bit 1
RH2/A18
PORTH
bit 2
RH3/A19
PORTH
bit 3
RJ0/ALE
PORTJ
bit 0
RJ1/OE
PORTJ
bit 1
RJ2/WRL
PORTJ
bit 2
RJ3/WRH
PORTJ
bit 3
RJ4/BA0
PORTJ
bit 4
RJ5/CE
PORTJ
bit 5
RJ6/LB
PORTJ
bit 6
RJ7/UB
PORTJ
bit 7
DS39609B-page 72
PIC18F6520/8520/6620/8620/6720/8720
6.2
16-bit Mode
FIGURE 6-1:
6.2.1
PIC18F8X20
AD<7:0>
(MSB)
373
(LSB)
A<19:0>
A<x:0>
A<x:0>
D<15:8>
D<7:0>
D<7:0>
CE
AD<15:8>
373
OE
D<7:0>
CE
WR(1)
OE
WR(1)
ALE
A<19:16>
CE
OE
WRH
WRL
Address Bus
Data Bus
Control Lines
Note 1:
This signal only applies to table writes. See Section 5.1 Table Reads and Table Writes.
DS39609B-page 73
PIC18F6520/8520/6620/8620/6720/8720
6.2.2
FIGURE 6-2:
PIC18F8X20
AD<7:0>
373
A<20:1>
D<15:0>
A<x:0>
D<15:0>
CE
AD<15:8>
JEDEC Word
EPROM Memory
OE
WR(1)
373
ALE
A<19:16>
CE
OE
WRH
Address Bus
Data Bus
Control Lines
Note 1:
DS39609B-page 74
This signal only applies to table writes. See Section 5.1 Table Reads and Table Writes.
PIC18F6520/8520/6620/8620/6720/8720
6.2.3
FIGURE 6-3:
PIC18F8X20
AD<7:0>
373
A<20:1>
A<x:1>
JEDEC Word
Flash Memory
D<15:0>
D<15:0>
138
AD<15:8>
373
CE
A0
ALE
BYTE/WORD
OE WR(1)
A<19:16>
OE
WRH
WRL
A<20:1>
A<x:1>
BA0
JEDEC Word
SRAM Memory
I/O
D<15:0>
D<15:0>
CE
LB
LB
UB
UB
OE
WR(1)
Address Bus
Data Bus
Control Lines
Note 1:
This signal only applies to table writes. See Section 5.1 Table Reads and Table Writes.
DS39609B-page 75
PIC18F6520/8520/6620/8620/6720/8720
6.2.4
FIGURE 6-4:
Apparent Q
Actual Q
Q2
Q2
Q3
Q3
Q4
Q4
Q1
Q1
Q2
Q2
Q3
Q3
Q4
Q4
00h
A<19:16>
3AABh
AD<15:0>
Q4
Q1
Q4
Q2
Q4
Q3
Q4
Q4
0Ch
0E55h
9256h
CF33h
BA0
ALE
OE
WRH
WRL
CE
0
1 TCY Wait
Memory
Cycle
Instruction
Execution
FIGURE 6-5:
Opcode Fetch
MOVLW 55h
from 007556h
Table Read
of 92h
from 199E67h
TBLRD Cycle 1
TBLRD Cycle 2
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
0Ch
A<19:16>
CF33h
AD<15:0>
9256h
CE
ALE
OE
Memory
Cycle
Opcode Fetch
TBLRD *
from 000100h
Opcode Fetch
MOVLW 55h
from 000102h
TBLRD 92h
from 199E67h
Instruction
Execution
INST(PC-2)
TBLRD Cycle 1
TBLRD Cycle 2
DS39609B-page 76
Opcode Fetch
ADDLW 55h
from 000104h
MOVLW
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 6-6:
Q2
Q4
Q1
Q2
3AAAh
Q3
Q4
Q1
00h
00h
A<19:16>
AD<15:0>
Q3
0003h
3AABh
0E55h
CE
ALE
OE
Memory
Cycle
Instruction
Execution
Opcode Fetch
SLEEP
from 007554h
Opcode Fetch
MOVLW 55h
from 007556h
INST(PC-2)
SLEEP
DS39609B-page 77
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 78
PIC18F6520/8520/6620/8620/6720/8720
7.0
EECON1
EECON2
EEDATA
EEADRH
EEADR
7.1
The address register pair can address up to a maximum of 1024 bytes of data EEPROM. The two Most
Significant bits of the address are stored in EEADRH,
while the remaining eight Least Significant bits are
stored in EEADR. The six Most Significant bits of
EEADRH are unused and are read as 0.
7.2
DS39609B-page 79
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 7-1:
R/W-x
U-0
R/W-0
R/W-x
R/W-0
R/S-0
R/S-0
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
bit 7
bit 0
bit 7
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
When a WRERR occurs, the EEPGD or FREE bits are not cleared. This allows
tracing of the error condition.
bit 2
bit 1
bit 0
DS39609B-page 80
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
7.3
EXAMPLE 7-1:
MOVLW
MOVWF
MOVLW
MOVWF
BCF
BCF
BSF
MOVF
7.4
DATA_EE_ADDRH
EEADRH
DATA_EE_ADDR
EEADR
EECON1, EEPGD
EECON1, CFGS
EECON1, RD
EEDATA, W
;
;
;
;
;
;
;
;
EXAMPLE 7-2:
Required
Sequence
DATA_EE_ADDRH
EEADRH
DATA_EE_ADDR
EEADR
DATA_EE_DATA
EEDATA
EECON1, EEPGD
EECON1, CFGS
EECON1, WREN
;
;
;
;
;
;
;
;
;
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BSF
INTCON, GIE
55h
EECON2
AAh
EECON2
EECON1, WR
INTCON, GIE
;
;
;
;
;
;
;
BCF
EECON1, WREN
DS39609B-page 81
PIC18F6520/8520/6620/8620/6720/8720
7.5
Write Verify
7.8
7.6
The data EEPROM is a high endurance, byte addressable array that has been optimized for the storage of
frequently changing information (e.g., program variables or other data that are updated often). Frequently
changing values will typically be updated more often
than specification D124. If this is not the case, an array
refresh must be performed. For this reason, variables
that change infrequently (such as constants, IDs,
calibration, etc.) should be stored in Flash program
memory.
A simple data EEPROM refresh routine is shown in
Example 7-3.
Note:
7.7
EXAMPLE 7-3:
CLRF
CLRF
BCF
BCF
BCF
BSF
EEADR
EEADRH
EECON1,
EECON1,
INTCON,
EECON1,
BSF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BTFSC
BRA
INCFSZ
BRA
INCFSZ
BRA
EECON1, RD
55h
EECON2
AAh
EECON2
EECON1, WR
EECON1, WR
$-2
EEADR, F
Loop
EEADRH, F
Loop
BCF
BSF
EECON1, WREN
INTCON, GIE
CFGS
EEPGD
GIE
WREN
Loop
DS39609B-page 82
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
Start at address 0
Set for memory
Set for Data EEPROM
Disable interrupts
Enable writes
Loop to refresh array
Read current address
Write 55h
Write AAh
Set WR bit to begin write
Wait for write to complete
Increment
Not zero,
Increment
Not zero,
address
do it again
the high address
do it again
; Disable writes
; Enable interrupts
PIC18F6520/8520/6620/8620/6720/8720
TABLE 7-1:
Name
INTCON
EEADRH
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
RBIE
TMR0IF
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INT0IF
RBIF
0000 0000
0000 0000
---- --00
---- --00
EEADR
0000 0000
0000 0000
EEDATA
0000 0000
0000 0000
EECON2
---- ----
---- ----
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
xx-0 x000
uu-0 u000
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
---1 1111
---1 1111
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
---0 0000
---0 0000
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
---0 0000
---0 0000
EECON1
Legend:
DS39609B-page 83
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 84
PIC18F6520/8520/6620/8620/6720/8720
8.0
8 X 8 HARDWARE MULTIPLIER
8.1
Introduction
8.2
EXAMPLE 8-1:
MOVF
MULWF
ARG1, W
ARG2
;
; ARG1 * ARG2 ->
; PRODH:PRODL
8 x 8 SIGNED MULTIPLY
ROUTINE
MOVF
MULWF
ARG1, W
ARG2
BTFSC
SUBWF
ARG2, SB
PRODH, F
MOVF
BTFSC
SUBWF
ARG2, W
ARG1, SB
PRODH, F
;
;
;
;
;
;
;
;
;
;
PERFORMANCE COMPARISON
Routine
8 x 8 unsigned
8 x 8 signed
16 x 16 unsigned
16 x 16 signed
8 x 8 UNSIGNED
MULTIPLY ROUTINE
EXAMPLE 8-2:
TABLE 8-1:
Operation
Multiply Method
Without hardware multiply
Time
Program
Memory
(Words)
Cycles
(Max)
@ 40 MHz
@ 10 MHz
@ 4 MHz
13
69
6.9 s
27.6 s
69 s
Hardware multiply
100 ns
400 ns
1 s
33
91
9.1 s
36.4 s
91 s
Hardware multiply
600 ns
2.4 s
6 s
21
242
24.2 s
96.8 s
242 s
Hardware multiply
28
28
2.8 s
11.2 s
28 s
52
254
25.4 s
102.6 s
254 s
Hardware multiply
35
40
4.0 s
16.0 s
40 s
DS39609B-page 85
PIC18F6520/8520/6620/8620/6720/8720
Example 8-3 shows the sequence to do a 16 x 16
unsigned multiply. Equation 8-1 shows the algorithm
that is used. The 32-bit result is stored in four registers,
RES3:RES0.
EQUATION 8-1:
RES3:RES0
=
=
EXAMPLE 8-3:
16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
ARG1H:ARG1L ARG2H:ARG2L
(ARG1H ARG2H 216) +
(ARG1H ARG2L 28) +
(ARG1L ARG2H 28) +
(ARG1L ARG2L)
EQUATION 8-2:
RES3:RES0
=
ARG1H:ARG1L ARG2H:ARG2L
=
(ARG1H ARG2H 216) +
(ARG1H ARG2L 28) +
(ARG1L ARG2H 28) +
(ARG1L ARG2L) +
(-1 ARG2H<7> ARG1H:ARG1L 216) +
(-1 ARG1H<7> ARG2H:ARG2L 216)
EXAMPLE 8-4:
16 x 16 UNSIGNED
MULTIPLY ROUTINE
MOVF
MULWF
ARG1L, W
ARG2L
MOVFF
MOVFF
PRODH, RES1
PRODL, RES0
MOVF
MULWF
ARG1H, W
ARG2H
MOVFF
MOVFF
PRODH, RES3
PRODL, RES2
MOVF
MULWF
ARG1L, W
ARG2H
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
16 x 16 SIGNED
MULTIPLY ROUTINE
MOVF
MULWF
ARG1L, W
ARG2L
MOVFF
MOVFF
PRODH, RES1
PRODL, RES0
MOVF
MULWF
ARG1H, W
ARG2H
MOVFF
MOVFF
PRODH, RES3
PRODL, RES2
MOVF
MULWF
ARG1L, W
ARG2H
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1, F
PRODH, W
RES2, F
WREG
RES3, F
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
ARG2H, 7
SIGN_ARG1
ARG1L, W
RES2
ARG1H, W
RES3
; ARG2H:ARG2L neg?
; no, check ARG1
;
;
;
ARG1H, 7
CONT_CODE
ARG2L, W
RES2
ARG2H, W
RES3
; ARG1H:ARG1L neg?
; no, done
;
;
;
;
; ARG1H * ARG2H ->
; PRODH:PRODL
;
;
DS39609B-page 86
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
SIGN_ARG1
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
;
CONT_CODE
:
PIC18F6520/8520/6620/8620/6720/8720
9.0
INTERRUPTS
RCON
INTCON
INTCON2
INTCON3
PIR1, PIR2, PIR3
PIE1, PIE2, PIE3
IPR1, IPR2, IPR3
DS39609B-page 87
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 9-1:
INTERRUPT LOGIC
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
Interrupt to CPU
Vector to Location
0008h
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
GIEH/GIE
TMR1IF
TMR1IE
TMR1IP
IPEN
IPEN
XXXXIF
XXXXIE
XXXXIP
GIEL/PEIE
IPEN
Additional Peripheral Interrupts
TMR1IF
TMR1IE
TMR1IP
RBIF
RBIE
RBIP
XXXXIF
XXXXIE
XXXXIP
DS39609B-page 88
Interrupt to CPU
Vector to Location
0018h
TMR0IF
TMR0IE
TMR0IP
GIEL/PEIE
GIE/GEIH
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
PIC18F6520/8520/6620/8620/6720/8720
9.1
INTCON Registers
Note:
REGISTER 9-1:
INTCON REGISTER
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-x
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
A mismatch condition will continue to set this bit. Reading PORTB will end the
mismatch condition and allow the bit to be cleared.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 89
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-2:
INTCON2 REGISTER
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
RBPU
INTEDG0
INTEDG1
INTEDG2
INTEDG3
TMR0IP
INT3IP
RBIP
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Note:
DS39609B-page 90
x = Bit is unknown
Interrupt flag bits are set when an interrupt condition occurs, regardless of the state
of its corresponding enable bit or the global enable bit. User software should ensure
the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature
allows for software polling.
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-3:
INTCON3 REGISTER
R/W-1
R/W-1
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
INT2IP
INT1IP
INT3IE
INT2IE
INT1IE
INT3IF
INT2IF
INT1IF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Note:
x = Bit is unknown
Interrupt flag bits are set when an interrupt condition occurs, regardless of the state
of its corresponding enable bit or the global enable bit. User software should ensure
the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature
allows for software polling.
DS39609B-page 91
PIC18F6520/8520/6620/8620/6720/8720
9.2
PIR Registers
The PIR registers contain the individual flag bits for the
peripheral interrupts. Due to the number of peripheral
interrupt sources, there are three Peripheral Interrupt
Flag Registers (PIR1, PIR2 and PIR3).
REGISTER 9-4:
2: User software should ensure the appropriate interrupt flag bits are cleared prior to
enabling an interrupt and after servicing
that interrupt.
(1)
R/W-0
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
ADIF
RC1IF
TX1IF
SSPIF
CCP1IF
TMR2IF
TMR1IF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS39609B-page 92
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-5:
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 93
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-6:
U-0
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
bit 7
bit 0
bit 7- 6
Unimplemented: Read as 0
bit 5
bit 4
bit 3
bit 2-0
DS39609B-page 94
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
9.3
PIE Registers
REGISTER 9-7:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
PSPIE(1)
ADIE
RC1IE
TX1IE
SSPIE
CCP1IE
TMR2IE
TMR1IE
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 95
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-8:
R/W-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
DS39609B-page 96
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-9:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4
bit 3
bit 2-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 97
PIC18F6520/8520/6620/8620/6720/8720
9.4
IPR Registers
REGISTER 9-10:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
PSPIP(1)
ADIP
RC1IP
TX1IP
SSPIP
CCP1IP
TMR2IP
TMR1IP
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS39609B-page 98
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-11:
R/W-1
U-0
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 99
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 9-12:
U-0
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4
bit 3
bit 2-0
DS39609B-page 100
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
9.5
RCON Register
REGISTER 9-13:
RCON REGISTER
R/W-0
U-0
U-0
R/W-1
R-1
R-1
R/W-0
R/W-0
IPEN
RI
TO
PD
POR
BOR
bit 7
bit 0
bit 7
bit 6-5
Unimplemented: Read as 0
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 101
PIC18F6520/8520/6620/8620/6720/8720
9.6
INT0 Interrupt
9.7
TMR0 Interrupt
9.8
PORTB Interrupt-on-Change
9.9
EXAMPLE 9-1:
MOVWF
MOVFF
MOVFF
;
; USER
;
MOVFF
MOVF
MOVFF
W_TEMP
STATUS, STATUS_TEMP
BSR, BSR_TEMP
ISR CODE
BSR_TEMP, BSR
W_TEMP, W
STATUS_TEMP, STATUS
DS39609B-page 102
; Restore BSR
; Restore WREG
; Restore STATUS
PIC18F6520/8520/6620/8620/6720/8720
10.0
I/O PORTS
10.1
FIGURE 10-1:
SIMPLIFIED BLOCK
DIAGRAM OF PORT/LAT/
TRIS OPERATION
RD LAT
TRIS
PORTA is a 7-bit wide, bidirectional port. The corresponding data direction register is TRISA. Setting a
TRISA bit (= 1) will make the corresponding PORTA pin
an input (i.e., put the corresponding output driver in a
high-impedance mode). Clearing a TRISA bit (= 0) will
make the corresponding PORTA pin an output (i.e., put
the contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the
pins, whereas writing to it will write to the port latch.
The Data Latch register (LATA) is also memory
mapped. Read-modify-write operations on the LATA
register, read and write the latched output value for
PORTA.
The RA4 pin is multiplexed with the Timer0 module
clock input to become the RA4/T0CKI pin. The RA4/
T0CKI pin is a Schmitt Trigger input and an open-drain
output. All other RA port pins have TTL input levels and
full CMOS output drivers.
The RA6 pin is only enabled as a general I/O pin in
ECIO and RCIO Oscillator modes.
The other PORTA pins are multiplexed with analog
inputs and the analog VREF+ and VREF- inputs. The
operation of each pin is selected by clearing/setting the
control bits in the ADCON1 register (A/D Control
Register 1).
Note:
D
WR LAT +
WR Port
CK
Data Latch
Data Bus
RD Port
I/O pin
EXAMPLE 10-1:
CLRF
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
PORTA
;
;
;
LATA
;
;
;
0x0F
;
ADCON1 ;
0xCF
;
;
;
TRISA ;
;
INITIALIZING PORTA
Initialize PORTA by
clearing output
data latches
Alternate method
to clear output
data latches
Configure A/D
for digital inputs
Value used to
initialize data
direction
Set RA<3:0> as inputs
RA<5:4> as outputs
DS39609B-page 103
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-2:
BLOCK DIAGRAM OF
RA3:RA0 AND RA5 PINS
FIGURE 10-3:
BLOCK DIAGRAM OF
RA4/T0CKI PIN
RD LATA
RD LATA
Data
Bus
WR LATA
or
PORTA
Data
Bus
WR LATA
or
PORTA
Q
VDD
CK
WR TRISA
I/O
pin(1)
WR TRISA
CK
CK
Q
N
Data Latch
Data Latch
D
VSS
Analog
Input
Mode
TRIS Latch
CK
I/O pin(1)
VSS
Schmitt
Trigger
Input
Buffer
TRIS Latch
RD TRISA
RD TRISA
Q
TTL
Input
Buffer
D
ENEN
EN
RD PORTA
RD PORTA
Note 1:
FIGURE 10-4:
WR LATA or PORTA
CK
VDD
P
Data Latch
WR TRISA
CK
I/O pin(1)
VSS
TRIS Latch
TTL
Input
Buffer
RD TRISA
ECRA6 or RCRA6 Enable
D
EN
RD PORTA
Note 1:
DS39609B-page 104
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-1:
PORTA FUNCTIONS
Name
RA0/AN0
Bit#
Buffer
bit 0
TTL
Function
Input/output or analog input.
RA1/AN1
bit 1
TTL
RA2/AN2/VREF-
bit 2
TTL
RA3/AN3/VREF+
bit 3
TTL
RA4/T0CKI
bit 4
ST
RA5/AN4/LVDIN
bit 5
TTL
OSC2/CLKO/RA6
bit 6
TTL
TABLE 10-2:
Name
Bit 7
Value on
all other
Resets
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
RA6
RA5
RA4
RA3
RA2
RA1
RA0
PORTA
LATA
TRISA
ADCON1
PCFG1
PCFG0
DS39609B-page 105
PIC18F6520/8520/6620/8620/6720/8720
10.2
PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB. Setting a
TRISB bit (= 1) will make the corresponding PORTB
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISB bit (= 0)
will make the corresponding PORTB pin an output (i.e.,
put the contents of the output latch on the selected pin).
The Data Latch register (LATB) is also memory
mapped. Read-modify-write operations on the LATB
register, read and write the latched output value for
PORTB.
EXAMPLE 10-2:
CLRF
PORTB
CLRF
LATB
MOVLW
0xCF
MOVWF
TRISB
INITIALIZING PORTB
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTB by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RB<3:0> as inputs
RB<5:4> as outputs
RB<7:6> as inputs
The other four PORTB pins (RB7:RB4) have an interrupt-on-change feature. Only pins configured as inputs
can cause this interrupt to occur (i.e., any RB7:RB4 pin
configured as an output is excluded from the interrupton-change comparison). The input pins (of RB7:RB4)
are compared with the old value latched on the last
read of PORTB. The mismatch outputs of RB7:RB4
are ORed together to generate the RB Port Change
Interrupt with Flag bit, RBIF (INTCON<0>).
This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, can clear the
interrupt in the following manner:
b)
FIGURE 10-5:
BLOCK DIAGRAM OF
RB7:RB4 PINS
VDD
RBPU(2)
Weak
P Pull-up
Data Bus
WR LATB
or PORTB
Data Latch
D
Q
I/O pin(1)
CK
TRIS Latch
D
WR TRISB
a)
Q
TTL
Input
Buffer
CK
ST
Buffer
RD TRISB
RD LATB
Latch
Q
RD PORTB
EN
Q1
Set RBIF
D
RD PORTB
From other
RB7:RB4 pins
EN
Q3
DS39609B-page 106
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-6:
Weak
P Pull-up
Data Latch
D
Q
Data Bus
I/O pin(1)
WR Port
CK
TRIS Latch
D
WR TRIS
TTL
Input
Buffer
CK
RD TRIS
Q
RD Port
EN
INTx
RD Port
Schmitt Trigger
Buffer
Note
FIGURE 10-7:
1:
2:
Weak
P Pull-up
CCP Output(3)
VDD
P
Enable(3)
CCP Output
Data Bus
WR LATB or
WR PORTB
0
Data Latch
D
I/O pin(1)
Q
N
CK
TRIS Latch
D
WR TRISB
CK
VSS
TTL
Input
Buffer
RD TRISB
RD LATB
Q
RD PORTB
EN
RD PORTB
CCP2 or INT3
Schmitt Trigger
Buffer
Note
CCP2MX = 0
1:
2:
To enable weak pull-ups, set the appropriate TRIS bit(s) and clear the RBPU bit (INTCON2<7>).
3:
The CCP2 input/output is multiplexed with RB3 if the CCP2MX bit is enabled (= 0) in the Configuration register and the device
is operating in Microprocessor, Microprocessor with Boot Block or Extended Microcontroller mode.
DS39609B-page 107
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-3:
PORTB FUNCTIONS
Name
Bit#
Buffer
RB0/INT0
bit 0
TTL/ST(1)
RB1/INT1
bit 1
TTL/ST(1)
RB2/INT2
bit 2
TTL/ST(1)
RB3/INT3/CCP2(3)
bit 3
TTL/ST(4)
RB4/KBI0
bit 4
TTL
RB5/KBI1/PGM
bit 5
TTL/ST(2)
RB6/KBI2/PGC
bit 6
TTL/ST(2)
RB7/KBI3/PGD
bit 7
TTL/ST(2)
Legend:
Note 1:
2:
3:
4:
TABLE 10-4:
Name
PORTB
Function
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
xxxx xxxx
uuuu uuuu
LATB
xxxx xxxx
uuuu uuuu
TRISB
1111 1111
1111 1111
RBIF
0000 0000
0000 0000
INTCON
GIE/
GIEH
INTCON2
RBPU
INTCON3
INT2IP
Legend:
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
INT3IE
INT2IE
INT1IE
TMR0IF
INT0IF
TMR0IP
INT3IP
RBIP
1111 1111
1111 1111
INT3IF
INT2IF
INT1IF
1100 0000
1100 0000
DS39609B-page 108
PIC18F6520/8520/6620/8620/6720/8720
10.3
PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISC. Setting a
TRISC bit (= 1) will make the corresponding PORTC
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISC bit (= 0)
will make the corresponding PORTC pin an output (i.e.,
put the contents of the output latch on the selected pin).
EXAMPLE 10-3:
CLRF
PORTC
CLRF
LATC
MOVLW
0xCF
MOVWF
TRISC
INITIALIZING PORTC
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTC by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RC<3:0> as inputs
RC<5:4> as outputs
RC<7:6> as inputs
FIGURE 10-8:
P
1
RD LATC
Data Bus
WR LATC or
WR PORTC
CK
I/O pin(1)
Data Latch
D
WR TRISC
CK
TRIS Latch
TRIS OVERRIDE
VSS
TRIS
Override
Logic
Pin
Override
Peripheral
RC0
Yes
RC1
Yes
RC2
Yes
CCP1 I/O
RC3
Yes
SPI/I2C
Master Clock
RC4
Yes
RD TRISC
Schmitt
Trigger
Peripheral Output
Enable(2)
D
EN
RD PORTC
Peripheral Data In
Note 1:
2:
RC5
Yes
RC6
Yes
USART1 Async
Xmit, Sync Clock
RC7
Yes
USART1 Sync
Data Out
DS39609B-page 109
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-5:
PORTC FUNCTIONS
Name
Bit#
Buffer Type
Function
RC0/T1OSO/T13CKI
bit 0
ST
RC1/T1OSI/CCP2(1)
bit 1
ST
RC2/CCP1
bit 2
ST
RC3/SCK/SCL
bit 3
ST
RC3 can also be the synchronous serial clock for both SPI and I2C
modes.
RC4/SDI/SDA
bit 4
ST
RC4 can also be the SPI data in (SPI mode) or data I/O (I2C mode).
RC5/SDO
bit 5
ST
RC6/TX1/CK1
bit 6
ST
RC7/RX1/DT1
bit 7
ST
TABLE 10-6:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
PORTC
RC7
RC6
RC5
RC4
RC3
RC2
RC1
RC0
xxxx xxxx
uuuu uuuu
LATC
xxxx xxxx
uuuu uuuu
TRISC
1111 1111
1111 1111
DS39609B-page 110
PIC18F6520/8520/6620/8620/6720/8720
10.4
PORTD can also be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting control
bit PSPMODE (TRISE<4>). In this mode, the input
buffers are TTL. See Section 10.10 Parallel Slave
Port for additional information on the Parallel Slave
Port (PSP).
PORTD is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISD. Setting a
TRISD bit (= 1) will make the corresponding PORTD
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISD bit (= 0)
will make the corresponding PORTD pin an output (i.e.,
put the contents of the output latch on the selected pin).
EXAMPLE 10-4:
CLRF
PORTD
CLRF
LATD
MOVLW
0xCF
MOVWF
TRISD
INITIALIZING PORTD
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTD by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RD<3:0> as inputs
RD<5:4> as outputs
RD<7:6> as inputs
FIGURE 10-9:
PORTD/CCP1 Select
PSPMODE
RD LATD
Data Bus
WR LATD
or PORTD
CK
VDD
Data Latch
WR TRISD
CK
I/O pin(1)
0
VSS
TRIS Latch
PSP Write
TTL Buffer
RD TRISD
1
Q
D
0
RD PORTD
PSP Read
Note 1:
ENEN
Schmitt Trigger
Input Buffer
DS39609B-page 111
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-10:
D
EN
EN
RD PORTD
RD LATD
Data Bus
WR LATD
or PORTD
CK
Port
Data
I/O pin(1)
0
1
Data Latch
D
WR TRISD
CK
TRIS Latch
TTL
Input
Buffer
RD TRISD
Bus Enable
System Bus Data/TRIS Out
Control
Drive Bus
Instruction Register
Instruction Read
Note 1: I/O pins have protection diodes to VDD and VSS.
DS39609B-page 112
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-7:
PORTD FUNCTIONS
Name
Bit#
Buffer Type
Function
RD0/PSP0/AD0
bit 0
ST/TTL(1)
Input/output port pin, Parallel Slave Port bit 0 or address/data bus bit 0.
bit 1
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 1 or address/data bus bit 1.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 2 or address/data bus bit 2.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 3 or address/data bus bit 3.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 4 or address/data bus bit 4.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 5 or address/data bus bit 5.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 6 or address/data bus bit 6.
ST/TTL
(1)
Input/output port pin, Parallel Slave Port bit 7 or address/data bus bit 7.
RD1/PSP1/AD1
RD2/PSP2/AD2
bit 2
RD3/PSP3/AD3
bit 3
RD4/PSP4/AD4
bit 4
RD5/PSP5/AD5
bit 5
RD6/PSP6/AD6
bit 6
RD7/PSP7/AD7
bit 7
TABLE 10-8:
Name
PORTD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
xxxx xxxx
uuuu uuuu
xxxx xxxx
uuuu uuuu
LATD
TRISD
1111 1111
1111 1111
PSPCON
IBF
OBF
IBOV
PSPMODE
0000 ----
0000 ----
MEMCON
EBDIS
WAIT1
WAIT0
WM1
WM0
0-00 --00
0-00 --00
Legend: x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by PORTD.
DS39609B-page 113
PIC18F6520/8520/6620/8620/6720/8720
10.5
PORTE is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISE. Setting a
TRISE bit (= 1) will make the corresponding PORTE
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISE bit (= 0)
will make the corresponding PORTE pin an output (i.e.,
put the contents of the output latch on the selected pin).
Read-modify-write operations on the LATE register,
read and write the latched output value for PORTE.
PORTE is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input or
output. PORTE is multiplexed with the CCP module
(Table 10-9).
On PIC18F8X20 devices, PORTE is also multiplexed
with the system bus as the external memory interface;
the I/O bus is available only when the system bus is
disabled, by setting the EBDIS bit in the MEMCON
register (MEMCON<7>). If the device is configured in
Microprocessor or Extended Microcontroller mode,
then the PORTE<7:0> becomes the high byte of the
address/data bus for the external program memory
interface. In Microcontroller mode, the PORTE<2:0>
pins become the control inputs for the Parallel Slave
Port when bit PSPMODE (PSPCON<4>) is set. (Refer
to Section 4.1.1 PIC18F8X20 Program Memory
Modes for more information on program memory
modes.)
DS39609B-page 114
EXAMPLE 10-5:
CLRF
PORTE
CLRF
LATE
MOVLW
0x03
MOVWF
TRISE
INITIALIZING PORTE
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTE by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RE1:RE0 as inputs
RE7:RE2 as outputs
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-11:
VDD
P
RD LATE
Data Bus
WR LATE
or WR PORTE
CK
Data Latch
WR TRISE
CK
I/O pin(1)
N
TRIS OVERRIDE
VSS
TRIS
Override
TRIS Latch
RD TRISE
Schmitt
Trigger
Peripheral Enable
Q
D
EN
RD PORTE
Peripheral Data In
Pin
Override
Peripheral
RE0
Yes
External Bus
RE1
Yes
External Bus
RE2
Yes
External Bus
RE3
Yes
External Bus
RE4
Yes
External Bus
RE5
Yes
External Bus
RE6
Yes
External Bus
RE7
Yes
External Bus
FIGURE 10-12:
D
EN
EN
RD PORTE
RD LATE
Data Bus
WR LATE
or PORTE
CK
Port 0
Data
1
I/O pin(1)
Data Latch
D
WR TRISE
CK
TRIS Latch
TTL
Input
Buffer
RD TRISE
Bus Enable
System Bus Data/TRIS Out
Control
Drive Bus
Instruction Register
Instruction Read
Note 1: I/O pins have protection diodes to VDD and VSS.
DS39609B-page 115
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-9:
PORTE FUNCTIONS
Name
Bit#
Buffer Type
RE0/RD/AD8
bit 0
ST/TTL(1)
RE1/WR/AD9
bit 1
ST/TTL(1)
RE2/CS/AD10
bit 2
ST/TTL(1)
Input/output port pin, chip select control for Parallel Slave Port or
address/data bit 10
For CS (PSP Control mode):
1 = Device is not selected
0 = Device is selected
RE3/AD11
bit 3
ST/TTL(1)
RE4/AD12
bit 4
ST/TTL(1)
bit 5
(1)
ST/TTL
bit 6
ST/TTL(1)
bit 7
ST/TTL(1)
RE5/AD13
RE6/AD14
RE7/CCP2/AD15
Function
Value on
all other
Resets
1111 1111
1111 1111
PORTE
xxxx xxxx
uuuu uuuu
LATE
xxxx xxxx
uuuu uuuu
MEMCON
EBDIS
WAIT1
WAIT0
WM1
WM0
0-00 --00
0000 --00
PSPCON
IBF
OBF
IBOV
PSPMODE
0000 ----
0000 ----
Name
TRISE
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
DS39609B-page 116
PIC18F6520/8520/6620/8620/6720/8720
10.6
EXAMPLE 10-6:
PORTF is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISF. Setting a
TRISF bit (= 1) will make the corresponding PORTF pin
an input (i.e., put the corresponding output driver in a
high-impedance mode). Clearing a TRISF bit (= 0) will
make the corresponding PORTF pin an output (i.e., put
the contents of the output latch on the selected pin).
Read-modify-write operations on the LATF register,
read and write the latched output value for PORTF.
PORTF is multiplexed with several analog peripheral
functions, including the A/D converter inputs and
comparator inputs, outputs and voltage reference.
CLRF
PORTF
CLRF
LATF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
0x07
CMCON
0x0F
ADCON1
0xCF
MOVWF
TRISF
INITIALIZING PORTF
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTF by
clearing output
data latches
Alternate method
to clear output
data latches
Turn off comparators
Set PORTF as digital I/O
Value used to
initialize data
direction
Set RF3:RF0 as inputs
RF5:RF4 as outputs
RF7:RF6 as inputs
FIGURE 10-13:
Port/Comparator Select
Comparator Data Out
VDD
P
RD LATF
Data Bus
WR LATF
or
WR PORTF
D
CK
Q
I/O pin
Data Latch
D
WR TRISF
CK
Q
VSS
TRIS Latch
Analog
Input
Mode
RD TRISF
Schmitt
Trigger
Q
D
EN
RD PORTF
To A/D Converter
DS39609B-page 117
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-14:
WR LATF
or
WR PORTF
WR LATF or
WR PORTF
CK
Q
VDD
CK
Data
Bus
VSS
Analog
Input
Mode
TRIS Latch
Q
Schmitt
Trigger
Input
Buffer
I/O pin
WR TRISF
CK
I/O pin
D
N
Data Latch
Data Latch
WR TRISF
RD LATF
RD LATF
Data
Bus
FIGURE 10-15:
CK
TRIS Latch
TTL
Input
Buffer
RD TRISF
RD TRISF
ST
Input
Buffer
Q
D
ENEN
EN
RD PORTF
RD PORTF
SS Input
To A/D Converter or Comparator Input
Note
1:
DS39609B-page 118
Note:
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-11: PORTF FUNCTIONS
Name
Bit#
Buffer Type
Function
RF0/AN5
bit 0
ST
RF1/AN6/C2OUT
bit 1
ST
RF2/AN7/C1OUT
bit 2
ST
RF3/AN8
bit 3
ST
RF4/AN9
bit 4
ST
RF5/AN10/CVREF
bit 5
ST
RF6/AN11
bit 6
ST
RF7/SS
bit 7
ST/TTL
Input/output port pin or slave select pin for synchronous serial port.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
TRISF
1111 1111
1111 1111
PORTF
xxxx xxxx
uuuu uuuu
LATF
ADCON1
CMCON
C1INV
0000 0000
uuuu uuuu
--00 0000
--00 0000
CIS
CM2
CM1
CM0
0000 0000
0000 0000
CVR3
CVR2
CVR1
CVR0
0000 0000
0000 0000
DS39609B-page 119
PIC18F6520/8520/6620/8620/6720/8720
10.7
PORTG is a 5-bit wide, bidirectional port. The corresponding data direction register is TRISG. Setting a
TRISG bit (= 1) will make the corresponding PORTG
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISG bit (= 0)
will make the corresponding PORTC pin an output (i.e.,
put the contents of the output latch on the selected pin).
Note:
The pin override value is not loaded into the TRIS register. This allows read-modify-write of the TRIS register,
without concern due to peripheral overrides.
EXAMPLE 10-7:
FIGURE 10-16:
CLRF
PORTG
CLRF
LATG
MOVLW
0x04
MOVWF
TRISG
INITIALIZING PORTG
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTG by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RG1:RG0 as outputs
RG2 as input
RG4:RG3 as inputs
P
1
RD LATG
Data Bus
WR LATG or
WR PORTG
CK
I/O pin(1)
Data Latch
D
WR TRISG
CK
Q
Q
TRIS Latch
VSS
TRIS
Override
Logic
RD TRISG
Schmitt
Trigger
Peripheral Output
Enable(2)
D
EN
RD PORTG
Peripheral Data In
Note 1:
DS39609B-page 120
TRIS OVERRIDE
Pin
Override
Peripheral
RG0
Yes
CCP3 I/O
RG1
Yes
USART1 Async
Xmit, Sync Clock
RG2
Yes
USART1 Async
Rcv, Sync Data
Out
RG3
Yes
CCP4 I/O
RG4
Yes
CCP5 I/O
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-13: PORTG FUNCTIONS
Name
Bit#
Buffer Type
Function
RG0/CCP3
bit 0
ST
RG1/TX2/CK2
bit 1
ST
RG2/RX2/DT2
bit 2
ST
RG3/CCP4
bit 3
ST
RG4/CCP5
bit 4
ST
Bit 7
Bit 6
Bit 5
PORTG
LATG
TRISG
Value on
POR, BOR
Value on
all other
Resets
---x xxxx
---u uuuu
---x xxxx
---u uuuu
---1 1111
---1 1111
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
DS39609B-page 121
PIC18F6520/8520/6620/8620/6720/8720
10.8
Note:
FIGURE 10-17:
RD LATH
PORTH is an 8-bit wide, bidirectional I/O port. The corresponding data direction register is TRISH. Setting a
TRISH bit (= 1) will make the corresponding PORTH
pin an input (i.e., put the corresponding output driver in
a high-impedance mode). Clearing a TRISH bit (= 0)
will make the corresponding PORTH pin an output (i.e.,
put the contents of the output latch on the selected pin).
Data
Bus
WR TRISH
EXAMPLE 10-8:
CLRF
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
PORTH
LATH
0Fh
ADCON1
0CFh
TRISH
INITIALIZING PORTH
;
;
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTH by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RH3:RH0 as inputs
RH5:RH4 as outputs
RH7:RH6 as inputs
WR LATH
or
PORTH
I/O pin(1)
CK
Data Latch
D
Schmitt
Trigger
Input
Buffer
CK
TRIS Latch
RD TRISH
ENEN
RD PORTH
Note 1: I/O pins have diode protection to VDD and VSS.
FIGURE 10-18:
RD LATH
Data
Bus
WR LATH
or
PORTH
I/O pin(1)
CK
Data Latch
D
WR TRISH
Schmitt
Trigger
Input
Buffer
CK
TRIS Latch
RD TRISH
D
EN
EN
RD PORTH
To A/D Converter
Note 1: I/O pins have diode protection to VDD and VSS.
DS39609B-page 122
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-19:
D
EN
EN
RD PORTH
RD LATD
Data Bus
WR LATH
or
PORTH
Port
I/O pin(1)
0
Data 1
CK
Data Latch
WR TRISH
CK
TRIS Latch
TTL
Input
Buffer
RD TRISH
External Enable
System Bus
Control
Address Out
Drive System
To Instruction Register
Instruction Read
DS39609B-page 123
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-15: PORTH FUNCTIONS
Name
Bit#
Buffer Type
bit 0
ST/TTL(1)
bit 1
ST/TTL(1)
RH2/A18
bit 2
ST/TTL
(1)
RH3/A19
bit 3
ST/TTL(1)
RH4/AN12
bit 4
ST
RH5/AN13
bit 5
ST
RH6/AN14
bit 6
ST
RH7/AN15
bit 7
ST
RH0/A16
RH1/A17
Function
Value on
all other
Resets
1111 1111
1111 1111
PORTH
xxxx xxxx
uuuu uuuu
LATH
xxxx xxxx
uuuu uuuu
Name
TRISH
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
ADCON1
--00 0000
MEMCON
EBDIS
WAIT1
0-00 --00
WAIT0
WM1
WM0
0-00 --00
Legend: x = unknown, u = unchanged, = unimplemented. Shaded cells are not used by PORTH.
DS39609B-page 124
PIC18F6520/8520/6620/8620/6720/8720
10.9
Note:
FIGURE 10-20:
RD LATJ
PORTJ is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISJ. Setting a
TRISJ bit (= 1) will make the corresponding PORTJ pin
an input (i.e., put the corresponding output driver in a
high-impedance mode). Clearing a TRISJ bit (= 0) will
make the corresponding PORTJ pin an output (i.e., put
the contents of the output latch on the selected pin).
Data
Bus
WR TRISJ
PORTJ is multiplexed with the system bus as the external memory interface; I/O port functions are only available when the system bus is disabled. When operating
as the external memory interface, PORTJ provides the
control signal to external memory devices. The RJ5 pin
is not multiplexed with any system bus functions.
When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTJ pin. Some
peripherals override the TRIS bit to make a pin an
output, while other peripherals override the TRIS bit to
make a pin an input. The user should refer to the corresponding peripheral section for the correct TRIS bit
settings.
Note:
WR LATJ
or
PORTJ
I/O pin(1)
CK
Data Latch
D
Schmitt
Trigger
Input
Buffer
CK
TRIS Latch
RD TRISJ
ENEN
RD PORTJ
Note 1: I/O pins have diode protection to VDD and VSS.
The pin override value is not loaded into the TRIS register. This allows read-modify-write of the TRIS register,
without concern due to peripheral overrides.
EXAMPLE 10-9:
CLRF
PORTJ
CLRF
LATJ
MOVLW
0xCF
MOVWF
TRISJ
INITIALIZING PORTJ
;
;
;
;
;
;
;
;
;
;
;
;
Initialize PORTG by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RJ3:RJ0 as inputs
RJ5:RJ4 as output
RJ7:RJ6 as inputs
DS39609B-page 125
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-21:
ENEN
RD PORTJ
RD LATJ
Data Bus
Data
WR LATJ
or
PORTJ
I/O pin(1)
Port 0
CK
Data Latch
D
WR TRISJ
CK
TRIS Latch
RD TRISJ
Control Out
System Bus
Control
External Enable
Drive System
FIGURE 10-22:
ENEN
RD PORTJ
RD LATJ
Data Bus
WR LATJ
or
PORTJ
Port
I/O pin(1)
0
Data 1
CK
Data Latch
D
WR TRISJ
CK
TRIS Latch
RD TRISJ
UB/LB Out
System Bus
Control
Note 1:
DS39609B-page 126
WM = 01
Drive System
I/O pins have diode protection to VDD and VSS.
PIC18F6520/8520/6620/8620/6720/8720
TABLE 10-17: PORTJ FUNCTIONS
Name
Bit#
Buffer Type
Function
RJ0/ALE
bit 0
ST
Input/output port pin or address latch enable control for external memory
interface.
RJ1/OE
bit 1
ST
Input/output port pin or output enable control for external memory interface.
RJ2/WRL
bit 2
ST
Input/output port pin or write low byte control for external memory interface.
RJ3/WRH
bit 3
ST
Input/output port pin or write high byte control for external memory interface.
RJ4/BA0
bit 4
ST
Input/output port pin or byte address 0 control for external memory interface.
RJ5/CE
bit 5
ST
Input/output port pin or chip enable control for external memory interface.
RJ6/LB
bit 6
ST
Input/output port pin or lower byte select control for external memory
interface.
RJ7/UB
bit 7
ST
Input/output port pin or upper byte select control for external memory
interface.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
PORTJ
xxxx xxxx
uuuu uuuu
LATJ
xxxx xxxx
uuuu uuuu
TRISJ
1111 1111
1111 1111
DS39609B-page 127
PIC18F6520/8520/6620/8620/6720/8720
10.10 Parallel Slave Port
PORTD also operates as an 8-bit wide Parallel Slave
Port, or microprocessor port, when control bit
PSPMODE (PSPCON<4>) is set. It is asynchronously
readable and writable by the external world through the
RD control input pin, RE0/RD/AD8 and the WR control
input pin, RE1/WR/AD9.
Note:
The PSP can directly interface to an 8-bit microprocessor data bus. The external microprocessor can
read or write the PORTD latch as an 8-bit latch. Setting
bit PSPMODE enables port pin RE0/RD/AD8 to be the
RD input, RE1/WR/AD9 to be the WR input and RE2/
CS/AD10 to be the CS (Chip Select) input. For this
functionality, the corresponding data direction bits of
the TRISE register (TRISE<2:0>) must be configured
as inputs (set). The A/D port configuration bits,
PCFG2:PCFG0 (ADCON1<2:0>), must be set which
will configure pins RE2:RE0 as digital I/O.
A write to the PSP occurs when both the CS and WR
lines are first detected low. A read from the PSP occurs
when both the CS and RD lines are first detected low.
The PORTE I/O pins become control inputs for the
microprocessor
port
when
bit
PSPMODE
(PSPCON<4>) is set. In this mode, the user must make
sure that the TRISE<2:0> bits are set (pins are configured as digital inputs) and the ADCON1 is configured
for digital I/O. In this mode, the input buffers are TTL.
FIGURE 10-23:
Data Bus
D
WR LATD
or
PORTD
RDx
pin
CK
TTL
Data Latch
Q
RD PORTD
D
ENEN
TRIS Latch
RD LATD
Read
TTL
RD
Chip Select
TTL
CS
Write
TTL
WR
DS39609B-page 128
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 10-1:
PSPCON REGISTER
R-0
R-0
R/W-0
R/W-0
U-0
U-0
U-0
U-0
IBF
OBF
IBOV
PSPMODE
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3-0
Unimplemented: Read as 0
Legend:
FIGURE 10-24:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
DS39609B-page 129
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 10-25:
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
PORTD
xxxx xxxx
uuuu uuuu
LATD
xxxx xxxx
uuuu uuuu
TRISD
1111 1111
1111 1111
PORTE
0000 0000
0000 0000
LATE
xxxx xxxx
uuuu uuuu
TRISE
1111 1111
1111 1111
PSPCON
IBF
OBF
IBOV
PSPMODE
0000 ----
0000 ----
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IF
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
Legend:
Note 1:
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the Parallel Slave Port.
Enabled only in Microcontroller mode for PIC18F8X20 devices.
DS39609B-page 130
PIC18F6520/8520/6620/8620/6720/8720
11.0
TIMER0 MODULE
REGISTER 11-1:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 131
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 11-1:
0
8
0
1
RA4/T0CKI pin
Programmable
Prescaler
Sync with
Internal
Clocks
TMR0
(2 TCY delay)
T0SE
PSA
Set Interrupt
Flag bit TMR0IF
on Overflow
Note:
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
FIGURE 11-2:
FOSC/4
0
0
1
RA4/T0CKI
pin
Programmable
Prescaler
Sync with
Internal
Clocks
TMR0L
TMR0
High Byte
8
(2 TCY delay)
T0SE
3
Set Interrupt
Flag bit TMR0IF
on Overflow
Read TMR0L
PSA
T0PS2, T0PS1, T0PS0
Write TMR0L
T0CS
8
8
TMR0H
8
Data Bus<7:0>
Note:
Upon Reset, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
DS39609B-page 132
PIC18F6520/8520/6620/8620/6720/8720
11.1
11.2.1
Timer0 Operation
11.3
11.4
TABLE 11-1:
Name
Prescaler
Note:
Timer0 Interrupt
11.2
SWITCHING PRESCALER
ASSIGNMENT
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
TMR0L
TMR0H
INTCON
RBIE
TMR0IF INT0IF
T0CON
TMR0ON
PSA
T0PS2
TRISA
T08BIT
T0CS
Bit 0
Value on
POR, BOR
Value on
all other
Resets
T0PS1
RBIF
DS39609B-page 133
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 134
PIC18F6520/8520/6620/8620/6720/8720
12.0
TIMER1 MODULE
REGISTER 12-1:
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RD16
T1CKPS1
T1CKPS0
T1OSCEN
T1SYNC
TMR1CS
TMR1ON
bit 7
bit 0
bit 7
bit 6
Unimplemented: Read as 0
bit 5-4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 135
PIC18F6520/8520/6620/8620/6720/8720
12.1
Timer1 Operation
When TMR1CS = 0, Timer1 increments every instruction cycle. When TMR1CS = 1, Timer1 increments on
every rising edge of the external clock input or the
Timer1 oscillator, if enabled.
FIGURE 12-1:
TMR1IF
Overflow
Interrupt
Flag Bit
TMR1
TMR1H
1
TMR1ON
On/Off
T1OSC
T1OSO/T13CKI
T1OSCEN
Enable
Oscillator(1)
T1OSI
Synchronized
Clock Input
CLR
TMR1L
T1SYNC
1
FOSC/4
Internal
Clock
Synchronize
Prescaler
1, 2, 4, 8
det
0
2
T1CKPS1:T1CKPS0
Sleep Input
TMR1CS
Note 1: When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
FIGURE 12-2:
Data Bus<7:0>
8
TMR1H
8
Write TMR1L
Read TMR1L
TMR1IF
Overflow
Interrupt
Flag bit
TMR1
8
Timer 1
High Byte
CLR
TMR1L
1
TMR1ON
On/Off
T1OSC
T1OSO/T13CKI
T1OSI
Synchronized
Clock Input
T1SYNC
1
T1OSCEN
Enable
Oscillator(1)
FOSC/4
Internal
Clock
Prescaler
1, 2, 4, 8
Synchronize
det
0
2
Sleep Input
TMR1CS
T1CKPS1:T1CKPS0
Note 1: When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
DS39609B-page 136
PIC18F6520/8520/6620/8620/6720/8720
12.2
12.2.1
Timer1 Oscillator
FIGURE 12-3:
EXTERNAL
COMPONENTS FOR THE
TIMER1 LP OSCILLATOR
C1
33 pF
PIC18FXX20
T1OSI
XTAL
32.768 kHz
The Timer1 oscillator for PIC18LFX520 devices incorporates a low-power feature, which allows the oscillator
to automatically reduce its power consumption when
the microcontroller is in Sleep mode.
As high noise environments may cause excessive
oscillator instability in Sleep mode, this option is best
suited for low noise applications where power
conservation is an important design consideration. Due
to the low-power nature of the oscillator, it may also be
sensitive to rapidly changing signals in close proximity.
The oscillator circuit, shown in Figure 12-3, should be
located as close as possible to the microcontroller.
There should be no circuits passing within the oscillator
circuit boundaries other than VSS or VDD.
If a high-speed circuit must be located near the oscillator (such as the CCP1 pin in output compare or PWM
mode, or the primary oscillator using the OSC2 pin), a
grounded guard ring around the oscillator circuit, as
shown in Figure 12-4, may be helpful when used on a
single-sided PCB or in addition to a ground plane.
T1OSO
C2
33 pF
Note:
FIGURE 12-4:
OSCILLATOR CIRCUIT
WITH GROUNDED
GUARD RING
VDD
TABLE 12-1:
CAPACITOR SELECTION
FOR THE ALTERNATE
OSCILLATOR
OSC1
Osc Type
Freq
C1
C2
OSC2
LP
32 kHz
TBD(1)
TBD(1)
VSS
Crystal to be Tested:
32.768 kHz Epson C-001R32.768K-A
RC0
20 PPM
RC1
RC2
Note:
Note:
DS39609B-page 137
PIC18F6520/8520/6620/8620/6720/8720
12.3
Timer1 Interrupt
12.4
Timer1 must be configured for either Timer or Synchronized Counter mode to take advantage of this feature.
If Timer1 is running in Asynchronous Counter mode,
this Reset operation may not work.
In the event that a write to Timer1 coincides with a
special event trigger from CCP1, the write will take
precedence.
In this mode of operation, the CCPR1H:CCPR1L
register pair effectively becomes the period register for
Timer1.
12.5
12.6
Using Timer1 as a
Real-Time Clock
DS39609B-page 138
PIC18F6520/8520/6620/8620/6720/8720
EXAMPLE 12-1:
RTCinit
MOVLW
MOVWF
CLRF
MOVLW
MOVWF
CLRF
CLRF
MOVLW
MOVWF
BSF
RETURN
0x80
TMR1H
TMR1L
b00001111
T1OSC
secs
mins
.12
hours
PIE1, TMR1IE
BSF
BCF
INCF
MOVLW
CPFSGT
RETURN
CLRF
INCF
MOVLW
CPFSGT
RETURN
CLRF
INCF
MOVLW
CPFSGT
RETURN
MOVLW
MOVWF
RETURN
TMR1H, 7
PIR1, TMR1IF
secs, F
.59
secs
RTCisr
TABLE 12-2:
Name
INTCON
Bit 7
secs
mins, F
.59
mins
mins
hours, F
.23
hours
;
;
;
;
;
;
;
;
No, done
Clear seconds
Increment minutes
60 minutes elapsed?
;
;
;
;
No, done
clear minutes
Increment hours
24 hours elapsed?
; No, done
; Reset hours to 1
.01
hours
; Done
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
TMR1L
Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
TMR1H
Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
T1CON
Legend:
RD16
T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON 0-00 0000 u-uu uuuu
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the Timer1 module.
DS39609B-page 139
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 140
PIC18F6520/8520/6620/8620/6720/8720
13.0
TIMER2 MODULE
13.1
REGISTER 13-1:
Timer2 Operation
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6-3
bit 2
bit 1-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 141
PIC18F6520/8520/6620/8620/6720/8720
13.2
Timer2 Interrupt
13.3
FIGURE 13-1:
Output of TMR2
TMR2
Output(1)
Prescaler
1:1, 1:4, 1:16
FOSC/4
TMR2
Reset
Comparator
EQ
Postscaler
1:1 to 1:16
T2CKPS1:T2CKPS0
4
PR2
T2OUTPS3:T2OUTPS0
Note 1:
TABLE 13-1:
Name
TMR2 register output can be software selected by the SSP module as a baud clock.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Value on
all other
Resets
Bit 0
Value on
POR, BOR
RBIF
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR2
T2CON
PR2
Legend:
T2OUTPS3 T2OUTPS2 T2OUTPS1 T2OUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the Timer2 module.
DS39609B-page 142
PIC18F6520/8520/6620/8620/6720/8720
14.0
TIMER3 MODULE
REGISTER 14-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
RD16
T3CCP2
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
TMR3ON
bit 7
bit 0
bit 7
bit 6, 3
bit 5-4
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 143
PIC18F6520/8520/6620/8620/6720/8720
14.1
Timer3 Operation
When TMR3CS = 0, Timer3 increments every instruction cycle. When TMR3CS = 1, Timer3 increments on
every rising edge of the Timer1 external clock input or
the Timer1 oscillator, if enabled.
FIGURE 14-1:
TMR3IF
Overflow
Interrupt
Flag bit
TMR3H
Synchronized
Clock Input
CLR
TMR3L
1
TMR3ON
On/Off
T1OSC
T1OSO/
T13CKI
T3SYNC
(3)
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
T1OSCEN FOSC/4
Enable
Internal
Oscillator(1) Clock
det
0
2
Sleep Input
TMR3CS
T3CKPS1:T3CKPS0
Note 1:
When enable bit T1OSCEN is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
FIGURE 14-2:
Data Bus<7:0>
8
TMR3H
8
8
Write TMR3L
Read TMR3L
Set TMR3IF Flag bit
on Overflow
TMR3
Timer3
High Byte
TMR3L
CLR
Synchronized
Clock Input
1
To Timer1 Clock Input
T1OSC
T1OSO/
T13CKI
T3SYNC
1
T1OSCEN
Enable
Oscillator(1)
T1OSI
Note 1:
TMR3ON
On/Off
FOSC/4
Internal
Clock
Synchronize
Prescaler
1, 2, 4, 8
det
0
2
T3CKPS1:T3CKPS0
TMR3CS
Sleep Input
When the T1OSCEN bit is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
DS39609B-page 144
PIC18F6520/8520/6620/8620/6720/8720
14.2
Timer1 Oscillator
14.4
14.3
Timer3 Interrupt
TABLE 14-1:
Name
INTCON
Bit 7
Timer3 must be configured for either Timer or Synchronized Counter mode to take advantage of this feature.
If Timer3 is running in Asynchronous Counter mode,
this Reset operation may not work. In the event that a
write to Timer3 coincides with a special event trigger
from CCP1, the write will take precedence. In this mode
of operation, the CCPR1H:CCPR1L register pair
effectively becomes the period register for Timer3.
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR2
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
---0 0000
---0 0000
PIE2
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
---0 0000
---0 0000
IPR2
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
---1 1111
---1 1111
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
xxxx xxxx
uuuu uuuu
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
xxxx xxxx
uuuu uuuu
u-uu uuuu
T3CKPS1 T3CKPS0
uuuu uuuu
T1CON
T3CON
Legend:
RD16
RD16
T3CCP2
T3CCP1
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the Timer3 module.
DS39609B-page 145
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 146
PIC18F6520/8520/6620/8620/6720/8720
15.0
TIMER4 MODULE
15.1
Timer4 Operation
REGISTER 15-1:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
T4CKPS0
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6-3
bit 2
bit 1-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 147
PIC18F6520/8520/6620/8620/6720/8720
15.2
Timer4 Interrupt
15.3
FIGURE 15-1:
Output of TMR4
TMR4
Output(1)
Prescaler
1:1, 1:4, 1:16
FOSC/4
TMR4
Reset
Comparator
EQ
Postscaler
1:1 to 1:16
T4CKPS1:T4CKPS0
4
PR4
T4OUTPS3:T4OUTPS0
TABLE 15-1:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
TMR0IE
RC2IP
Bit 1
INT0IE
RBIE
TMR0IF
INT0IF
TX2IP
TMR4IP
CCP5IP
CCP4IP
Value on
all other
Resets
Bit 0
Value on
POR, BOR
RBIF
IPR3
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
TMR4
T4CON
PR4
Legend:
T4OUTPS3 T4OUTPS2 T4OUTPS1 T4OUTPS0 TMR4ON T4CKPS1 T4CKPS0 -000 0000 -000 0000
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the Timer4 module.
DS39609B-page 148
PIC18F6520/8520/6620/8620/6720/8720
16.0
CAPTURE/COMPARE/PWM
(CCP) MODULES
REGISTER 16-1:
CCPxCON REGISTER
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
DCxB1
DCxB0
CCPxM3
CCPxM2
R/W-0
R/W-0
CCPxM1 CCPxM0
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5-4
DCxB1:DCxB0: PWM Duty Cycle bit 1 and bit 0 for CCP Module x
Capture mode:
Unused.
Compare mode:
Unused.
PWM mode:
These bits are the two Least Significant bits (bit 1 and bit 0) of the 10-bit PWM duty cycle. The
eight Most Significant bits (DCx9:DCx2) of the duty cycle are found in CCPRxL.
bit 3-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 149
PIC18F6520/8520/6620/8620/6720/8720
16.1
TABLE 16-1:
16.1.1
FIGURE 16-1:
CCP Mode
Timer Resource
Capture
Compare
PWM
Timer1 or Timer3
Timer1 or Timer3
Timer2 or Timer4
T3CCP<2:1> = 00
TMR1
TMR3
CCP1
T3CCP<2:1> = 01
TMR1
TMR3
CCP1
T3CCP<2:1> = 10
TMR1
TMR3
T3CCP<2:1> = 11
TMR1
TMR3
CCP1
CCP1
CCP2
CCP2
CCP2
CCP2
CCP3
CCP3
CCP3
CCP3
CCP4
CCP4
CCP4
CCP4
CCP5
CCP5
CCP5
CCP5
TMR2
TMR4
DS39609B-page 150
TMR2
TMR4
TMR2
TMR4
TMR2
TMR4
PIC18F6520/8520/6620/8620/6720/8720
16.2
16.2.3
Capture Mode
16.2.1
16.2.2
If the RC2/CCP1 is configured as an output, a write to the port can cause a capture
condition.
FIGURE 16-2:
16.2.4
SOFTWARE INTERRUPT
CCP PRESCALER
EXAMPLE 16-1:
CLRF
MOVLW
MOVWF
CHANGING BETWEEN
CAPTURE PRESCALERS
TMR3L
TMR3
Enable
CCPR1H
and
Edge Detect
T3CCP2
CCPR1L
TMR1
Enable
TMR1H
TMR1L
CCP1CON<3:0>
Qs
DS39609B-page 151
PIC18F6520/8520/6620/8620/6720/8720
16.3
16.3.2
Compare Mode
16.3.3
is driven High
is driven Low
toggles output (high-to-low or low-to-high)
remains unchanged
16.3.1
16.3.4
FIGURE 16-3:
For CCP1 and CCP2 only, the Special Event Trigger will:
Reset Timer1 or Timer3, but not set Timer1 or Timer3 interrupt flag bit
and set bit GO/DONE (ADCON0<2>),
which starts an A/D conversion (CCP2 only)
Special Event Trigger
Set Flag bit CCP1IF
CCPR1H CCPR1L
Q
RC2/CCP1 pin
TRISC<2>
Output Enable
S
R
Output
Logic
CCP1CON<3:0>
Mode Select
Comparator
Match
T3CCP2
TMR1H
DS39609B-page 152
TMR1L
TMR3H
TMR3L
PIC18F6520/8520/6620/8620/6720/8720
TABLE 16-2:
Name
INTCON
Bit 6
GIE/GIEH PEIE/GIEL
RCON
IPEN
Value on
POR, BOR
Value on
all other
Resets
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
RI
TO
PD
POR
BOR
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
PIR2
CMIE
EEIE
BCLIF
LVDIF
TMR3IF
CCP2IF
PIE2
CMIF
EEIF
BCLIE
LVDIE
TMR3IE
CCP2IE
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
IPR3
TRISC
TMR1L
Holding Register for the Least Significant Byte of the 16-bit TMR1 Register
TMR1H
Holding Register for the Most Significant Byte of the 16-bit TMR1 Register
T1CON
RD16
T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON 0-00 0000 u-uu uuuu
TMR3H
TMR3L
T3CON
RD16
T3CCP2
T3CKPS1 T3CKPS0
T3CCP1
CCPRxL(1)
CCPRxH(1)
CCPxCON(1)
Legend:
Note 1:
DCxB1
DCxB0
CCPxM3
DS39609B-page 153
PIC18F6520/8520/6620/8620/6720/8720
16.4
16.4.1
PWM Mode
PWM PERIOD
EQUATION 16-1:
PWM Period = (PR2) + 1] 4 TOSC
(TMR2 Prescale Value)
PWM frequency is defined as 1/[PWM period].
TMR2 is cleared
The CCP1 pin is set (exception: if PWM duty
cycle = 0%, the CCP1 pin will not be set)
The PWM duty cycle is latched from CCPR1L into
CCPR1H
FIGURE 16-4:
Note:
CCP1CON<5:4>
CCPR1H (Slave)
16.4.2
R
Comparator
Q
RC2/CCP1
(Note 1)
TMR2
S
TRISC<2>
Comparator
Clear Timer,
CCP1 pin and
latch D.C.
PR2
Note
1:
EQUATION 16-2:
PWM Duty Cycle = (CCPR1L:CCP1CON<5:4>)
TOSC (TMR2 Prescale Value)
FIGURE 16-5:
PWM OUTPUT
Period
When the CCPR1H and 2-bit latch match TMR2, concatenated with an internal 2-bit Q clock or 2 bits of the
TMR2 prescaler, the CCP1 pin is cleared.
Duty Cycle
TMR2 = PR2
TMR2 = Duty Cycle
TMR2 = PR2
DS39609B-page 154
PIC18F6520/8520/6620/8620/6720/8720
16.4.3
EQUATION 16-3:
1.
F OSC
log ---------------
F PWM
PWM Resolution (max) = -----------------------------bits
log ( 2 )
2.
3.
Note:
TABLE 16-3:
Name
INTCON
5.
2.44 kHz
9.77 kHz
39.06 kHz
156.25 kHz
312.50 kHz
416.67 kHz
16
FFh
FFh
FFh
3Fh
1Fh
17h
14 10
12 10
10
6.58
Bit 6
GIE/GIEH PEIE/GIEL
RCON
4.
PWM Frequency
TABLE 16-4:
IPEN
Value on
all other
Resets
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
RI
TO
PD
POR
BOR
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
PIR2
CMIE
EEIE
BCLIF
LVDIF
TMR3IF
CCP2IF
PIE2
CMIF
EEIF
BCLIE
LVDIE
TMR3IE
CCP2IE
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
IPR3
TMR2
PR2
T2CON
T3CON
RD16
T2OUTPS3 T2OUTPS2 T2OUTPS1 T2OUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
T3CCP2
T3CKPS1
T3CKPS0
T3CCP1
TMR4
Timer4 Register
PR4
T4CON
T4OUTPS3 T4OUTPS2 T4OUTPS1 T4OUTPS0 TMR4ON T4CKPS1 T4CKPS0 -000 0000 uuuu uuuu
CCPRxL(1)
CCPRxH(1)
CCPxCON(1)
Legend:
Note 1:
DCxB1
DCxB0
CCPxM2 CCPxM1
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by PWM, Timer2, or Timer4.
Generic term for all of the identical registers of this name for all CCP modules, where x identifies the individual module
(CCP1 through CCP5). Bit assignments and Reset values for all registers of the same generic name are identical.
DS39609B-page 155
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 156
PIC18F6520/8520/6620/8620/6720/8720
17.0
17.1
MASTER SYNCHRONOUS
SERIAL PORT (MSSP)
MODULE
Master SSP (MSSP) Module
Overview
17.3
SPI Mode
FIGURE 17-1:
Internal
Data Bus
Read
Master mode
Multi-Master mode
Slave mode
17.2
Control Registers
Write
SSPBUF reg
RC4/SDI/SDA
SSPSR reg
Shift
Clock
RC5/SDO
bit0
RF7/SS
SS Control
Enable
Edge
Select
2
Clock Select
RC3/SCK/
SCL
SSPM3:SSPM0
SMP:CKE 4
TMR2 Output
2
2
Edge
Select
Prescaler TOSC
4, 16, 64
DS39609B-page 157
PIC18F6520/8520/6620/8620/6720/8720
17.3.1
REGISTERS
REGISTER 17-1:
During transmission, the SSPBUF is not doublebuffered. A write to SSPBUF will write to both SSPBUF
and SSPSR.
R/W-0
R-0
R-0
R-0
R-0
R-0
R-0
SMP
CKE
D/A
R/W
UA
BF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
P: Stop bit
Used in I2C mode only. This bit is cleared when the MSSP module is disabled,
SSPEN is cleared.
bit 3
S: Start bit
Used in I2C mode only.
bit 2
bit 1
bit 0
DS39609B-page 158
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 17-2:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
bit 7
bit 0
bit 7
bit 6
bit 5
In Master mode, the overflow bit is not set, since each new reception (and
transmission) is initiated by writing to the SSPBUF register.
bit 4
bit 3-0
Bit combinations not specifically listed here are either reserved, or implemented in
I2C mode only.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 159
PIC18F6520/8520/6620/8620/6720/8720
17.3.2
OPERATION
EQUATION 17-1:
reading the data that was just received. Any write to the
SSPBUF register during transmission/reception of data
will be ignored and the Write Collision detect bit, WCOL
(SSPCON1<7>), will be set. User software must clear
the WCOL bit so that it can be determined if the following write(s) to the SSPBUF register completed
successfully.
When the application software is expecting to receive
valid data, the SSPBUF should be read before the next
byte of data to transfer is written to the SSPBUF. Buffer
Full bit, BF (SSPSTAT<0>), indicates when SSPBUF
has been loaded with the received data (transmission
is complete). When the SSPBUF is read, the BF bit is
cleared. This data may be irrelevant if the SPI is only a
transmitter. Generally, the MSSP interrupt is used to
determine when the transmission/reception has completed. The SSPBUF must be read and/or written. If the
interrupt method is not going to be used, then software
polling can be done to ensure that a write collision does
not occur. Example 17-1 shows the loading of the
SSPBUF (SSPSR) for data transmission.
The SSPSR is not directly readable or writable and can
only be accessed by addressing the SSPBUF register.
Additionally, the MSSP Status register (SSPSTAT)
indicates the various status conditions.
MOVWF RXDATA
MOVF TXDATA, W
MOVWF SSPBUF
DS39609B-page 160
PIC18F6520/8520/6620/8620/6720/8720
17.3.3
17.3.4
TYPICAL CONNECTION
FIGURE 17-2:
SDI
SDI
Shift Register
(SSPSR)
MSb
LSb
Shift Register
(SSPSR)
MSb
SCK
PROCESSOR 1
SDO
Serial Clock
LSb
SCK
PROCESSOR 2
DS39609B-page 161
PIC18F6520/8520/6620/8620/6720/8720
17.3.5
MASTER MODE
The clock polarity is selected by appropriately programming the CKP bit (SSPCON1<4>). This then, would
give waveforms for SPI communication, as shown in
FIGURE 17-3:
Write to
SSPBUF
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
4 Clock
Modes
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
SDO
(CKE = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDO
(CKE = 1)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
SDI
(SMP = 0)
bit 0
bit 7
Input
Sample
(SMP = 0)
SDI
(SMP = 1)
bit 7
bit 0
Input
Sample
(SMP = 1)
SSPIF
SSPSR to
SSPBUF
DS39609B-page 162
Next Q4 cycle
after Q2
PIC18F6520/8520/6620/8620/6720/8720
17.3.6
SLAVE MODE
17.3.7
SLAVE SELECT
SYNCHRONIZATION
FIGURE 17-4:
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDO
SDI
(SMP = 0)
bit 7
bit 6
bit 7
bit 0
bit 0
bit 7
bit 7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
SSPSR to
SSPBUF
Next Q4 cycle
after Q2
DS39609B-page 163
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 17-5:
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDO
SDI
(SMP = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
bit 0
bit 7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
after Q2
SSPSR to
SSPBUF
FIGURE 17-6:
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPBUF
SDO
bit 7
SDI
(SMP = 0)
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
bit 0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
SSPSR to
SSPBUF
DS39609B-page 164
Next Q4 cycle
after Q2
PIC18F6520/8520/6620/8620/6720/8720
17.3.8
SLEEP OPERATION
17.3.10
TABLE 17-1:
17.3.9
EFFECTS OF A RESET
Name
INTCON
CKP
CKE
0, 0
0, 1
1, 0
1, 1
TABLE 17-2:
Bit 6
GIE/GIEH PEIE/GIEL
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
all other
Resets
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TRISF4
TRISF3
TRISF2
TRISF1
TRISC
TRISF
SSPBUF
RBIF
Value on
POR, BOR
TRISF6
TRISF5
SSPCON
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
SSPSTAT
SMP
CKE
D/A
R/W
UA
BF
Legend:
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used by the MSSP in SPI mode.
DS39609B-page 165
PIC18F6520/8520/6620/8620/6720/8720
17.4
I2C Mode
17.4.1
FIGURE 17-7:
Write
Shift
Clock
LSb
MSb
Match Detect
Addr Match
SSPADD reg
Start and
Stop bit Detect
DS39609B-page 166
SSPSR reg
RC4/
SDI/
SDA
SSPBUF reg
RC3/SCK/SCL
REGISTERS
During transmission, the SSPBUF is not doublebuffered. A write to SSPBUF will write to both SSPBUF
and SSPSR.
Set, Reset
S, P bits
(SSPSTAT reg)
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 17-3:
R/W-0
R-0
R-0
R-0
R-0
R-0
R-0
SMP
CKE
D/A
R/W
UA
BF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
P: Stop bit
1 = Indicates that a Stop bit has been detected last
0 = Stop bit was not detected last
Note:
bit 3
S: Start bit
1 = Indicates that a Start bit has been detected last
0 = Start bit was not detected last
Note:
bit 2
This bit holds the R/W bit information following the last address match. This bit is only
valid from the address match to the next Start bit, Stop bit, or not ACK bit.
In Master mode:
1 = Transmit is in progress
0 = Transmit is not in progress
Note:
ORing this bit with SEN, RSEN, PEN, RCEN or ACKEN will indicate if the MSSP is
in active mode.
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 167
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 17-4:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
WCOL
SSPOV
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
bit 7
bit 0
bit 7
bit 6
bit 5
When enabled, the SDA and SCL pins must be properly configured as input or output.
bit 4
bit 3-0
Bit combinations not specifically listed here are either reserved or implemented in
SPI mode only.
Legend:
DS39609B-page 168
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 17-5:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
GCEN
ACKSTAT
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
bit 7
bit 0
bit 7
bit 6
bit 5
Value that will be transmitted when the user initiates an Acknowledge sequence at
the end of a receive.
bit 4
bit 3
bit 2
bit 1
bit 0
For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle mode,
this bit may not be set (no spooling) and the SSPBUF may not be written (or writes
to the SSPBUF are disabled).
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 169
PIC18F6520/8520/6620/8620/6720/8720
17.4.2
OPERATION
17.4.3
SLAVE MODE
In Slave mode, the SCL and SDA pins must be configured as inputs (TRISC<4:3> set). The MSSP module
will override the input state with the output data when
required (slave-transmitter).
The I 2C Slave mode hardware will always generate an
interrupt on an address match. Through the mode
select bits, the user can also choose to interrupt on
Start and Stop bits
When an address is matched or the data transfer after
an address match is received, the hardware automatically will generate the Acknowledge (ACK) pulse and
load the SSPBUF register with the received value
currently in the SSPSR register.
17.4.3.1
3.
4.
5.
Addressing
6.
7.
8.
9.
DS39609B-page 170
PIC18F6520/8520/6620/8620/6720/8720
17.4.3.2
Reception
17.4.3.3
Transmission
DS39609B-page 171
DS39609B-page 172
CKP
A6
A4
A3
Receiving Address
A5
A2
SSPOV (SSPCON<6>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A7
A1
ACK
R/W = 0
D7
D4
D3
Receiving Data
D5
Cleared in software
SSPBUF is read
D6
D2
D1
D0
ACK
D7
D6
D4
D3
Receiving Data
D5
D2
D1
D0
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-8:
SDA
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 7-BIT ADDRESS)
CKP
A6
Data in
sampled
BF (SSPSTAT<0>)
SSPIF (PIR1<3>)
A7
A5
A4
A3
A2
Receiving Address
A1
R/W = 1
ACK
D7
D5
D4
D3
D2
Cleared in software
D6
Transmitting Data
D0
ACK
D1
D7
D4
D3
D2
D0
ACK
D1
Transmitting Data
Cleared in software
D5
D6
FIGURE 17-9:
SCL
SDA
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING (TRANSMISSION, 7-BIT ADDRESS)
DS39609B-page 173
DS39609B-page 174
A9 A8
UA (SSPSTAT<1>)
SSPOV (SSPCON<6>)
CKP
Cleared in software
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
ACK
R/W = 0
A7
A4
A3
A0 ACK
Cleared by hardware
when SSPADD is updated
with low byte of address
A2 A1
Cleared in software
A5
A6
D7
Cleared in software
9
1
Cleared in software
D3 D2
D3 D2 D1 D0 ACK D7 D6 D5 D4
D1 D0
P
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-10:
SDA
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 10-BIT ADDRESS)
CKP (SSPCON<4>)
UA (SSPSTAT<1>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A9 A8
ACK
Cleared in software
A6 A5 A4 A3 A2 A1
A0
A7
ACK
Cleared in software
ACK
R/W = 1
Completion of
data transmission
clears BF flag
ACK
Bus master
terminates
transfer
D4 D3 D2 D1 D0
Cleared in software
D7 D6 D5
Write of SSPBUF
BF flag is clear
initiates transmit
at the end of the
third address sequence
A9 A8
Sr
FIGURE 17-11:
SDA
R/W = 0
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING (TRANSMISSION, 10-BIT ADDRESS)
DS39609B-page 175
PIC18F6520/8520/6620/8620/6720/8720
17.4.4
CLOCK STRETCHING
17.4.4.1
17.4.4.2
17.4.4.3
17.4.4.4
In 10-bit Slave Transmit mode, clock stretching is controlled during the first two address sequences by the
state of the UA bit, just as it is in 10-bit Slave Receive
mode. The first two addresses are followed by a third
address sequence, which contains the high-order bits
of the 10-bit address and the R/W bit set to 1. After
the third address sequence is performed, the UA bit is
not set, the module is now configured in Transmit
mode and clock stretching is controlled as in 7-bit
Slave Transmit mode (see Figure 17-11).
DS39609B-page 176
PIC18F6520/8520/6620/8620/6720/8720
17.4.4.5
FIGURE 17-12:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
SDA
DX
DX-1
SCL
CKP
Master device
asserts clock
Master device
deasserts clock
WR
SSPCON
DS39609B-page 177
DS39609B-page 178
CKP
SSPOV (SSPCON<6>)
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
A7
A6
A4
A3
Receiving Address
A5
A2
A1
ACK
R/W = 0
D4
D3
Receiving Data
D5
Cleared in software
D6
If BF is cleared
prior to the falling
edge of the 9th clock,
CKP will not be reset
to 0 and no clock
stretching will occur
SSPBUF is read
D7
D2
D1
ACK
D7
D0
CKP
written
to 1 in
software
D6
D4
D3
Receiving Data
D5
D2
D1
D0
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-13:
SDA
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESS)
UA (SSPSTAT<1>)
SSPOV (SSPCON<6>)
CKP
A9 A8
Cleared in software
BF (SSPSTAT<0>)
(PIR1<3>)
SSPIF
SCL
ACK
R/W = 0
A7
A4
A3
A0
Note:
A2 A1
Cleared in software
A5
A6
ACK
Cleared in software
D3 D2
D1
Note:
ACK
Cleared in software
CKP written to 1
in software
D3 D2
D0
D7 D6 D5 D4
Bus master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
D1 D0
ACK
FIGURE 17-14:
SDA
PIC18F6520/8520/6620/8620/6720/8720
I2C SLAVE MODE TIMING SEN = 1 (RECEPTION, 10-BIT ADDRESS)
DS39609B-page 179
PIC18F6520/8520/6620/8620/6720/8720
17.4.5
When the interrupt is serviced, the source for the interrupt can be checked by reading the contents of the
SSPBUF. The value can be used to determine if the
address was device specific or a general call address.
In 10-bit mode, the SSPADD is required to be updated
for the second half of the address to match and the UA
bit is set (SSPSTAT<1>). If the general call address is
sampled when the GCEN bit is set, while the slave is
configured in 10-bit Address mode, then the second
half of the address is not necessary, the UA bit will not
be set and the slave will begin receiving data after the
Acknowledge (Figure 17-15).
FIGURE 17-15:
SDA
Receiving Data
ACK
D6
D5
D4
D3
D2
D1
D0
SCL
S
SSPIF
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON1<6>)
GCEN (SSPCON2<7>)
DS39609B-page 180
PIC18F6520/8520/6620/8620/6720/8720
MASTER MODE
Note:
FIGURE 17-16:
Start Condition
Stop Condition
Data Transfer Byte Transmitted/received
Acknowledge Transmit
Repeated Start
SSPM3:SSPM0
SSPADD<6:0>
Write
SSPBUF
Baud
Rate
Generator
Shift
Clock
SDA
SDA In
SCL In
Bus Collision
LSb
Clock Cntl
SCL
Receive Enable
SSPSR
MSb
17.4.6
DS39609B-page 181
PIC18F6520/8520/6620/8620/6720/8720
17.4.6.1
DS39609B-page 182
PIC18F6520/8520/6620/8620/6720/8720
17.4.7
FIGURE 17-17:
Once the given operation is complete (i.e., transmission of the last data bit is followed by ACK), the internal
clock will automatically stop counting and the SCL pin
will remain in its last state.
Table 15-3 demonstrates clock rates based on
instruction cycles and the BRG value loaded into
SSPADD.
SSPM3:SSPM0
Reload
SCL
Control
CLKO
Reload
FOSC/4
TABLE 17-3:
Note 1:
SSPADD<6:0>
FCY
FCY*2
BRG VALUE
FSCL
(2 rollovers of BRG)
10 MHz
20 MHz
19h
400 kHz(1)
10 MHz
20 MHz
20h
312.5 kHz
10 MHz
20 MHz
3Fh
100 kHz
4 MHz
8 MHz
0Ah
400 kHz(1)
4 MHz
8 MHz
0Dh
308 kHz
4 MHz
8 MHz
28h
100 kHz
1 MHz
2 MHz
03h
333 kHz(1)
1 MHz
2 MHz
0Ah
100 kHz
1 MHz
2 MHz
00h
1 MHz(1)
I2C
I2C
The
interface does not conform to the 400 kHz
specification (which applies to rates greater than
100 kHz) in all details, but may be used with care where higher rates are required by the application.
DS39609B-page 183
PIC18F6520/8520/6620/8620/6720/8720
17.4.7.1
Clock Arbitration
FIGURE 17-18:
SDA
DX
DX-1
SCL
BRG decrements on
Q2 and Q4 cycles
BRG
Value
03h
02h
01h
03h
02h
DS39609B-page 184
PIC18F6520/8520/6620/8620/6720/8720
17.4.8
17.4.8.1
To initiate a Start condition, the user sets the Start Condition Enable bit, SEN (SSPCON2<0>). If the SDA and
SCL pins are sampled high, the Baud Rate Generator
is reloaded with the contents of SSPADD<6:0> and
starts its count. If SCL and SDA are both sampled high
when the Baud Rate Generator times out (TBRG), the
SDA pin is driven low. The action of the SDA being
driven low, while SCL is high, is the Start condition and
causes the S bit (SSPSTAT<3>) to be set. Following
this, the Baud Rate Generator is reloaded with the contents of SSPADD<6:0> and resumes its count. When
the Baud Rate Generator times out (TBRG), the SEN bit
(SSPCON2<0>) will be automatically cleared by
hardware, the Baud Rate Generator is suspended,
leaving the SDA line held low and the Start condition is
complete.
Note:
Note:
FIGURE 17-19:
TBRG
SDA
2nd bit
TBRG
SCL
TBRG
S
DS39609B-page 185
PIC18F6520/8520/6620/8620/6720/8720
17.4.9
17.4.9.1
FIGURE 17-20:
SDA = 1,
SCL = 1
TBRG
TBRG
SDA
Write to SSPBUF occurs here
TBRG
SCL
TBRG
RSEN bit set
DS39609B-page 186
Sr = Repeated Start
PIC18F6520/8520/6620/8620/6720/8720
17.4.10
17.4.10.1
BF Status Flag
17.4.10.3
17.4.11
17.4.11.1
BF Status Flag
17.4.11.2
17.4.11.3
17.4.10.2
DS39609B-page 187
DS39609B-page 188
S
R/W
PEN
SEN
BF (SSPSTAT<0>)
SSPIF
SCL
SDA
A6
A5
A4
A3
A2
A1
Cleared in software
SSPBUF written
D7
1
SCL held low
while CPU
responds to SSPIF
ACK = 0
R/W = 0
A7
D5
D4
D3
D2
D1
D0
D6
Cleared in software
ACK
ACKSTAT in
SSPCON2 = 1
FIGURE 17-21:
SEN = 0
PIC18F6520/8520/6620/8620/6720/8720
I 2C MASTER MODE WAVEFORM (TRANSMISSION, 7 OR 10-BIT ADDRESS)
ACKEN
SSPOV
BF
(SSPSTAT<0>)
SDA = 0, SCL = 1
while CPU
responds to SSPIF
SSPIF
SCL
SDA
A7
4
5
Cleared in software
A6 A5 A4 A3 A2
A1
R/W = 1
ACK
D0
ACK
Cleared in software
D7 D6 D5 D4 D3 D2 D1
Cleared in
software
ACK
P
Set SSPIF interrupt
at end of Acknowledge sequence
Bus master
terminates
transfer
Set P bit
(SSPSTAT<4>)
and SSPIF
PEN bit = 1
written here
D0
RCEN cleared
automatically
RCEN = 1
Start next receive
Cleared in software
Cleared in software
D7 D6 D5 D4 D3 D2 D1
RCEN cleared
automatically
FIGURE 17-22:
SEN = 0
Write to SSPBUF occurs here
Start XMIT
Write to SSPCON2<4>
to start Acknowledge sequence
SDA = ACKDT (SSPCON2<5>) = 0
PIC18F6520/8520/6620/8620/6720/8720
I 2C MASTER MODE WAVEFORM (RECEPTION, 7-BIT ADDRESS)
DS39609B-page 189
PIC18F6520/8520/6620/8620/6720/8720
17.4.12
ACKNOWLEDGE SEQUENCE
TIMING
17.4.13
17.4.12.1
17.4.13.1
FIGURE 17-23:
TBRG
SDA
ACK
D0
SCL
SSPIF
SSPIF set at the end
of receive
Note:
FIGURE 17-24:
Cleared in
software
Cleared in
software
SSPIF set at the end
of Acknowledge sequence
Write to SSPCON2
Set PEN
Falling edge of
9th clock
TBRG
SCL
SDA
ACK
P
TBRG
TBRG
TBRG
DS39609B-page 190
PIC18F6520/8520/6620/8620/6720/8720
17.4.14
SLEEP OPERATION
17.4.17
17.4.15
EFFECT OF A RESET
17.4.16
MULTI-MASTER MODE
Address Transfer
Data Transfer
A Start Condition
A Repeated Start Condition
An Acknowledge Condition
Multi-Master mode support is achieved by bus arbitration. When the master outputs address/data bits onto
the SDA pin, arbitration takes place when the master
outputs a 1 on SDA, by letting SDA float high and
another master asserts a 0. When the SCL pin floats
high, data should be stable. If the expected data on
SDA is a 1 and the data sampled on the SDA pin = 0,
then a bus collision has taken place. The master will set
the Bus Collision Interrupt Flag, BCLIF and reset the
I2C port to its Idle state (Figure 17-25).
If a transmit was in progress when the bus collision
occurred, the transmission is halted, the BF flag is
cleared, the SDA and SCL lines are deasserted and the
SSPBUF can be written to. When the user services the
bus collision Interrupt Service Routine and if the I2C
bus is free, the user can resume communication by
asserting a Start condition.
If a Start, Repeated Start, Stop, or Acknowledge condition was in progress when the bus collision occurred,
the condition is aborted, the SDA and SCL lines are
deasserted and the respective control bits in the
SSPCON2 register are cleared. When the user services the bus collision Interrupt Service Routine and if
the I2C bus is free, the user can resume communication
by asserting a Start condition.
The master will continue to monitor the SDA and SCL
pins. If a Stop condition occurs, the SSPIF bit will be set.
A write to the SSPBUF will start the transmission of
data at the first data bit, regardless of where the
transmitter left off when the bus collision occurred.
In Multi-Master mode, the interrupt generation on the
detection of Start and Stop conditions allows the determination of when the bus is free. Control of the I2C bus can
be taken when the P bit is set in the SSPSTAT register, or
the bus is Idle and the S and P bits are cleared.
FIGURE 17-25:
SDA
SCL
BCLIF
DS39609B-page 191
PIC18F6520/8520/6620/8620/6720/8720
17.4.17.1
b)
FIGURE 17-26:
SDA
SCL
Set SEN, enable Start
condition if SDA = 1, SCL = 1
SEN
BCLIF
SSPIF
DS39609B-page 192
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 17-27:
TBRG
SDA
SCL
SEN
SCL = 0 before BRG time-out,
bus collision occurs. Set BCLIF.
BCLIF
Interrupt cleared
in software
S
SSPIF
FIGURE 17-28:
SDA
Set SSPIF
TBRG
SCL
S
SCL pulled low after BRG
Time-out
SEN
BCLIF
SSPIF
SDA = 0, SCL = 1
Set SSPIF
Interrupts cleared
in software
DS39609B-page 193
PIC18F6520/8520/6620/8620/6720/8720
17.4.17.2
FIGURE 17-29:
If, at the end of the BRG time-out, both SCL and SDA
are still high, the SDA pin is driven low and the BRG is
reloaded and begins counting. At the end of the count,
regardless of the status of the SCL pin, the SCL pin is
driven low and the Repeated Start condition is complete.
SDA
SCL
BCLIF
Cleared in software
S
SSPIF
FIGURE 17-30:
TBRG
SDA
SCL
BCLIF
RSEN
S
SSPIF
DS39609B-page 194
PIC18F6520/8520/6620/8620/6720/8720
17.4.17.3
b)
FIGURE 17-31:
TBRG
SDA sampled
low after TBRG,
set BCLIF
TBRG
SDA
SDA asserted low
SCL
PEN
BCLIF
P
SSPIF
FIGURE 17-32:
TBRG
TBRG
SDA
Assert SDA
SCL
PEN
BCLIF
P
SSPIF
DS39609B-page 195
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 196
PIC18F6520/8520/6620/8620/6720/8720
18.0
ADDRESSABLE UNIVERSAL
SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (USART)
DS39609B-page 197
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 18-1:
R/W-0
TX9
R/W-0
TXEN
R/W-0
SYNC
U-0
bit 7
bit 6
bit 5
R/W-0
BRGH
R-1
TRMT
R/W-0
TX9D
bit 0
bit 4
bit 3
Unimplemented: Read as 0
bit 2
bit 1
bit 0
DS39609B-page 198
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 18-2:
R/W-0
RX9
R/W-0
SREN
R/W-0
CREN
R/W-0
ADDEN
R-0
FERR
R-0
OERR
R-x
RX9D
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 199
PIC18F6520/8520/6620/8620/6720/8720
18.1
FOSC = 16 MHz
Desired Baud Rate = 9600
BRGH = 0
SYNC = 0
18.1.1
SAMPLING
EXAMPLE 18-1:
= FOSC/(64 (X + 1))
Solving for X:
= ((FOSC/Desired Baud Rate)/64 ) 1
= ((16000000/9600)/64) 1
= [25.042] = 25
X
X
X
Calculated Baud Rate
=
=
Error
=
=
TABLE 18-1:
SYNC
0
1
TABLE 18-2:
Name
TXSTAx
RCSTAx
SPBRGx
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
0000 -010
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
Legend: x = unknown, = unimplemented, read as 0. Shaded cells are not used by the BRG.
Note 1: Register names generically refer to both of the identically named registers for the two USART modules,
where x indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 200
PIC18F6520/8520/6620/8620/6720/8720
TABLE 18-3:
33 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
1.2
NA
2.4
NA
9.6
25 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
NA
19.2
NA
76.8
76.92
20 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
NA
NA
+0.16
129
77.10
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
NA
NA
NA
NA
+0.39
106
77.16
+0.47
80
76.92
+0.16
64
96
96.15
+0.16
103
95.93
-0.07
85
96.15
+0.16
64
96.15
+0.16
51
300
303.03
+1.01
32
294.64
-1.79
27
297.62
-0.79
20
294.12
-1.96
16
500
500
19
485.30
-2.94
16
480.77
-3.85
12
500
HIGH
10000
8250
6250
5000
LOW
39.06
255
32.23
255
24.41
255
19.53
255
FOSC = 16 MHz
10 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
1.2
NA
2.4
NA
9.6
NA
7.15909 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
5.0688 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
NA
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
9.62
+0.23
185
9.60
131
19.2
19.23
+0.16
207
19.23
+0.16
129
19.24
+0.23
92
19.20
65
76.8
76.92
+0.16
51
75.76
-1.36
32
77.82
+1.32
22
74.54
-2.94
16
96
95.24
-0.79
41
96.15
+0.16
25
94.20
-1.88
18
97.48
+1.54
12
300
307.70
+2.56
12
312.50
+4.17
298.35
-0.57
316.80
+5.60
500
500
500
447.44
-10.51
422.40
-15.52
HIGH
4000
2500
1789.80
1267.20
LOW
15.63
255
9.77
255
6.99
255
4.95
255
FOSC = 4 MHz
3.579545 MHz
BAUD
RATE
(Kbps)
KBAUD
0.3
NA
1.2
NA
2.4
NA
%
ERROR
SPBRG
value
(decimal)
1 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
1.20
+0.16
NA
2.40
+0.16
KBAUD
%
ERROR
32.768 kHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.30
+1.14
26
207
1.17
-2.48
103
2.73
+13.78
2
0
9.6
9.62
+0.16
103
9.62
+0.23
92
9.62
+0.16
25
8.20
-14.67
19.2
19.23
+0.16
51
19.04
-0.83
46
19.23
+0.16
12
NA
76.8
76.92
+0.16
12
74.57
-2.90
11
83.33
+8.51
NA
96
1000
+4.17
99.43
+3.57
83.33
-13.19
NA
300
333.33
+11.11
298.30
-0.57
250
-16.67
NA
500
500
447.44
-10.51
NA
NA
HIGH
1000
894.89
250
8.20
LOW
3.91
255
3.50
255
0.98
255
0.03
255
DS39609B-page 201
PIC18F6520/8520/6620/8620/6720/8720
TABLE 18-4:
33 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
1.2
NA
2.4
NA
25 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
2.40
-0.07
20 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
214
2.40
-0.15
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
162
2.40
+0.16
129
9.6
9.62
+0.16
64
9.55
-0.54
53
9.53
-0.76
40
9.47
-1.36
32
19.2
18.94
-1.36
32
19.10
-0.54
26
19.53
+1.73
19
19.53
+1.73
15
76.8
78.13
+1.73
73.66
-4.09
78.13
+1.73
78.13
+1.73
96
89.29
-6.99
103.13
+7.42
97.66
+1.73
104.17
+8.51
300
312.50
+4.17
257.81
-14.06
NA
312.50
+4.17
500
625
+25.00
NA
NA
NA
HIGH
625
515.63
390.63
312.50
LOW
2.44
255
2.01
255
1.53
255
1.22
255
FOSC = 16 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
10 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
7.15909 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
5.0688 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
NA
NA
NA
1.2
1.20
+0.16
207
1.20
+0.16
129
1.20
+0.23
92
1.20
65
2.4
2.40
+0.16
103
2.40
+0.16
64
2.38
-0.83
46
2.40
32
9.6
9.62
+0.16
25
9.77
+1.73
15
9.32
-2.90
11
9.90
+3.13
19.2
19.23
+0.16
12
19.53
+1.73
18.64
-2.90
19.80
+3.13
76.8
83.33
+8.51
78.13
+1.73
111.86
+45.65
79.20
+3.13
96
83.33
-13.19
78.13
-18.62
NA
NA
300
250
-16.67
156.25
-47.92
NA
NA
500
NA
NA
NA
NA
HIGH
250
156.25
111.86
79.20
LOW
0.98
255
0.61
255
0.44
255
0.31
255
FOSC = 4 MHz
BAUD
RATE
(Kbps)
KBAUD
0.3
1.2
2.4
3.579545 MHz
%
ERROR
SPBRG
value
(decimal)
0.30
-0.16
1.20
+1.67
2.40
1 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
207
0.30
+0.23
51
1.19
-0.83
+1.67
25
2.43
+1.32
32.768 kHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
KBAUD
%
ERROR
SPBRG
value
(decimal)
185
0.30
+0.16
46
1.20
+0.16
51
0.26
-14.67
12
NA
22
2.23
-6.99
NA
9.6
8.93
-6.99
9.32
-2.90
7.81
-18.62
NA
19.2
20.83
+8.51
18.64
-2.90
15.63
-18.62
NA
76.8
62.50
-18.62
55.93
-27.17
NA
NA
96
NA
NA
NA
NA
300
NA
NA
NA
NA
500
NA
NA
NA
NA
HIGH
62.50
55.93
15.63
0.51
LOW
0.24
255
0.22
255
0.06
255
0.002
255
DS39609B-page 202
PIC18F6520/8520/6620/8620/6720/8720
TABLE 18-5:
33 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
1.2
NA
2.4
NA
9.6
25 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
NA
19.2
19.23
+0.16
76.8
75.76
-1.36
96
96.15
+0.16
300
312.50
+4.17
500
500
HIGH
2500
LOW
9.77
255
20 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
9.60
-0.07
214
129
19.28
+0.39
32
76.39
-0.54
25
98.21
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
9.59
-0.15
162
9.62
+0.16
129
106
19.30
+0.47
80
19.23
+0.16
64
26
78.13
+1.73
19
78.13
+1.73
15
+2.31
20
97.66
+1.73
15
96.15
+0.16
12
294.64
-1.79
312.50
+4.17
312.50
+4.17
515.63
+3.13
520.83
+4.17
416.67
-16.67
2062.50
1562.50
1250
8,06
255
6.10
255
4.88
255
FOSC = 16 MHz
10 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
1.2
NA
2.4
NA
7.15909 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
5.0688 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
2.41
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
+0.23
185
2.40
131
9.6
9.62
+0.16
103
9.62
+0.16
64
9.52
-0.83
46
9.60
32
19.2
19.23
+0.16
51
18.94
-1.36
32
19.45
+1.32
22
18.64
-2.94
16
76.8
76.92
+0.16
12
78.13
+1.73
74.57
-2.90
79.20
+3.13
96
100
+4.17
89.29
-6.99
89.49
-6.78
105.60
+10.00
300
333.33
+11.11
312.50
+4.17
447.44
+49.15
316.80
+5.60
500
500
625
+25.00
447.44
-10.51
NA
HIGH
1000
625
447.44
316.80
LOW
3.91
255
2.44
255
1.75
255
1.24
255
FOSC = 4 MHz
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
3.579545 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
1 MHz
SPBRG
value
(decimal)
KBAUD
32.768 kHz
%
ERROR
SPBRG
value
(decimal)
KBAUD
%
ERROR
SPBRG
value
(decimal)
0.3
NA
NA
0.30
+0.16
207
0.29
-2.48
1.2
1.20
+0.16
207
1.20
+0.23
185
1.20
+0.16
51
1.02
-14.67
2.4
2.40
+0.16
103
2.41
+0.23
92
2.40
+0.16
25
2.05
-14.67
9.6
9.62
+0.16
25
9.73
+1.32
22
8.93
-6.99
NA
19.2
19.23
+0.16
12
18.64
-2.90
11
20.83
+8.51
NA
76.8
NA
74.57
-2.90
62.50
-18.62
NA
96
NA
111.86
+16.52
NA
NA
300
NA
223.72
-25.43
NA
NA
500
NA
NA
NA
NA
HIGH
250
55.93
62.50
2.05
LOW
0.98
255
0.22
255
0.24
255
0.008
255
DS39609B-page 203
PIC18F6520/8520/6620/8620/6720/8720
18.2
In this mode, the USARTs use standard Non-Return-toZero (NRZ) format (one Start bit, eight or nine data bits
and one Stop bit). The most common data format is
8 bits. An on-chip dedicated 8-bit Baud Rate Generator
can be used to derive standard baud rate frequencies
from the oscillator. The USART transmits and receives
the LSb first. The USARTs transmitter and receiver are
functionally independent, but use the same data format
and baud rate. The Baud Rate Generator produces a
clock, either 16 or 64 times the bit shift rate, depending
on bit BRGH (TXSTAx<2>). Parity is not supported by
the hardware, but can be implemented in software (and
stored as the ninth data bit). Asynchronous mode is
stopped during Sleep.
1.
2.
18.2.1
3.
USART ASYNCHRONOUS
TRANSMITTER
4.
FIGURE 18-1:
Initialize the SPBRGx register for the appropriate baud rate. If a high-speed baud rate is
desired, set bit BRGH (Section 18.1 USART
Baud Rate Generator (BRG)).
Enable the asynchronous serial port by clearing
bit SYNC and setting bit SPEN.
If interrupts are desired, set enable bit TXxIE in
the appropriate PIE register.
If 9-bit transmission is desired, set transmit bit
TX9. Can be used as address/data bit.
Enable the transmission by setting bit TXEN,
which will also set bit TXxIF.
If 9-bit transmission is selected, the ninth bit
should be loaded in bit TX9D.
Load data to the TXREGx register (starts
transmission).
5.
6.
7.
Note:
TXREG Register
TXIE
8
MSb
LSb
(8)
Pin Buffer
and Control
TSR Register
TX pin
Interrupt
TXEN
SPEN
SPBRG
Baud Rate Generator
TX9
TX9D
DS39609B-page 204
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 18-2:
ASYNCHRONOUS TRANSMISSION
Write to TXREG
BRG Output
(Shift Clock)
Word 1
RC6/TX1/CK1 (pin)
Start bit
bit 0
bit 1
TXIF bit
(Transmit Buffer
Reg. Empty Flag)
TRMT bit
(Transmit Shift
Reg. Empty Flag)
FIGURE 18-3:
bit 7/8
Stop bit
Word 1
Word 1
Transmit Shift Reg
Write to TXREG
Word 1
BRG Output
(Shift Clock)
RC6/TX1/CK1 (pin)
TXIF bit
(Interrupt Reg. Flag)
Start bit
TRMT bit
(Transmit Shift
Reg. Empty Flag)
Note:
bit 1
Word 1
bit 7/8
Stop bit
Start bit
bit 0
Word 2
Word 1
Transmit Shift Reg.
Word 2
Transmit Shift Reg.
INTCON
bit 0
TABLE 18-6:
Name
Word 2
GIE/GIEH
Bit 6
Bit 5
PEIE/GIEL TMR0IE
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RC1IF
TX1IF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RC1IE
TX1IE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RC1IP
TX1IP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
IPR3
RCSTAx(1)
CSRC
TX9
SPBRGx
Legend:
Note 1:
x = unknown, = unimplemented locations read as 0. Shaded cells are not used for asynchronous transmission.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 205
PIC18F6520/8520/6620/8620/6720/8720
18.2.2
USART ASYNCHRONOUS
RECEIVER
18.2.3
FIGURE 18-4:
Initialize the SPBRGx register for the appropriate baud rate. If a high-speed baud rate is
required, set the BRGH bit.
2. Enable the asynchronous serial port by clearing
the SYNC bit and setting the SPEN bit.
3. If interrupts are required, set the RCEN bit and
select the desired priority level with the RCIP bit.
4. Set the RX9 bit to enable 9-bit reception.
5. Set the ADDEN bit to enable address detect.
6. Enable reception by setting the CREN bit.
7. The RCxIF bit will be set when reception is
complete. The interrupt will be Acknowledged if
the RCxIE and GIE bits are set.
8. Read the RCSTAx register to determine if any
error occurred during reception, as well as read
bit 9 of data (if applicable).
9. Read RCREGx to determine if the device is
being addressed.
10. If any error occurred, clear the CREN bit.
11. If the device has been addressed, clear the
ADDEN bit to allow all received data into the
receive buffer and interrupt the CPU.
FERR
OERR
SPBRG
64
or
16
RSR Register
MSb
Stop
(8)
LSb
0
Start
Data
Recovery
RX9D
RCREG Register
FIFO
SPEN
8
Interrupt
RCIF
Data Bus
RCIE
DS39609B-page 206
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 18-5:
ASYNCHRONOUS RECEPTION
Start
bit
bit 0
RX (pin)
bit 1
Start
bit
Rcv Shift
Reg
Rcv Buffer Reg
bit 0
Stop
bit
Start
bit
bit 7/8
Stop
bit
Word 2
RCREG
Word 1
RCREG
Read Rcv
Buffer Reg
RCREG
bit 7/8
RCIF
(Interrupt Flag)
OERR bit
CREN
Note:
This timing diagram shows three words appearing on the RX input. The RCREG (receive buffer) is read after the third word,
causing the OERR (overrun) bit to be set.
TABLE 18-7:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RC1IF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RC1IE
TXIE
SSPIE
CCP1IE TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RC1IP
TXIP
SSPIP
CCP1IP TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
IPR3
RC2IP
TX2IP
TMR4IP CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
RCSTAx(1)
FERR
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
x = unknown, = unimplemented locations read as 0. Shaded cells are not used for asynchronous reception.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 207
PIC18F6520/8520/6620/8620/6720/8720
18.3
18.3.1
2.
TABLE 18-8:
set, regardless of the state of enable bit TXxIE and cannot be cleared in software. It will reset only when new
data is loaded into the TXREGx register. While flag bit
TXxIF indicates the status of the TXREGx register,
another bit TRMT (TXSTAx<1>) shows the status of the
TSR register. TRMT is a read-only bit, which is set
when the TSR is empty. No interrupt logic is tied to this
bit, so the user has to poll this bit in order to determine
if the TSR register is empty. The TSR is not mapped in
data memory, so it is not available to the user.
3.
4.
5.
6.
7.
Note:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
IPR3
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
SYNC
BRGH
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
RCSTAx(1)
SPBRGx
Legend:
Note 1:
CSRC
TX9
TXEN
x = unknown, = unimplemented, read as 0. Shaded cells are not used for synchronous master transmission.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 208
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 18-6:
SYNCHRONOUS TRANSMISSION
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
RC7/RX1/DT1
pin
bit 0
bit 1
Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
bit 2
bit 7
Word 1
bit 0
bit 1
Word 2
bit 7
RC6/TX1/CK1
pin
Write to
TXREG Reg
Write Word 1
Write Word 2
TXIF bit
(Interrupt Flag)
TRMT
TRMT
bit
TXEN bit
Note:
FIGURE 18-7:
RC7/RX1/DT1 pin
bit 0
bit 1
bit 2
bit 6
bit 7
RC6/TX1/CK1 pin
Write to
TXREG reg
TXIF bit
TRMT bit
TXEN bit
DS39609B-page 209
PIC18F6520/8520/6620/8620/6720/8720
18.3.2
4.
2.
3.
Initialize the SPBRGx register for the appropriate baud rate (Section 18.1 USART Baud
Rate Generator (BRG)).
Enable the synchronous master serial port by
setting bits SYNC, SPEN and CSRC.
Ensure bits CREN and SREN are clear.
TABLE 18-9:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
0000 0000
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
PIR1
PSPIF
ADIF
RC1IF
TX1IF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RC1IE
TX1IE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RC1IP
TX1IP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
IPR3
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
INTCON
GIE/GIEH PEIE/GIEL
(1)
RCSTAx
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 0000
0000 0000
0000 -010
0000 -010
0000 0000
0000 0000
x = unknown, = unimplemented, read as 0. Shaded cells are not used for synchronous master reception.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
FIGURE 18-8:
RC7/RX1/DT1 pin
bit 0
bit 1
bit 2
bit 3
bit 4
bit 5
bit 6
bit 7
RC6/TX1/CK1 pin
Write to
bit SREN
SREN bit
CREN bit
RCIF bit
(Interrupt)
Read
RXREG
Note:
Timing diagram demonstrates Sync Master mode with bit SREN = 1 and bit BRGH = 0.
DS39609B-page 210
PIC18F6520/8520/6620/8620/6720/8720
18.4
18.4.1
1.
2.
3.
4.
5.
6.
7.
8.
e)
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RC1IF
TX1IF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RC1IE
TX1IE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RC1IP
TX1IP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
IPR3
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
RCSTAx(1)
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000
x = unknown, = unimplemented, read as 0. Shaded cells are not used for synchronous slave transmission.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 211
PIC18F6520/8520/6620/8620/6720/8720
18.4.2
2.
3.
4.
5.
6.
7.
8.
9.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RC1IF
TX1IF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RC1IE
TX1IE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RC1IP
TX1IP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR3
RC2IF
TX2IF
TMR4IF
CCP5IF
CCP4IF
CCP3IF
--00 0000
--00 0000
PIE3
RC2IE
TX2IE
TMR4IE
CCP5IE
CCP4IE
CCP3IE
--00 0000
--00 0000
IPR3
RC2IP
TX2IP
TMR4IP
CCP5IP
CCP4IP
CCP3IP
--11 1111
--11 1111
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
RCSTAx(1)
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 000x
0000 000x
0000 0000
0000 0000
0000 -010
0000 -010
0000 0000
0000 0000
x = unknown, = unimplemented, read as 0. Shaded cells are not used for synchronous slave reception.
Register names generically refer to both of the identically named registers for the two USART modules, where x
indicates the particular module. Bit names and Reset values are identical between modules.
DS39609B-page 212
PIC18F6520/8520/6620/8620/6720/8720
19.0
10-BIT ANALOG-TO-DIGITAL
CONVERTER (A/D) MODULE
REGISTER 19-1:
The ADCON0 register, shown in Register 19-1, controls the operation of the A/D module. The ADCON1
register, shown in Register 19-2, configures the functions of the port pins. The ADCON2 register, shown in
Register 19-3, configures the A/D clock source and
justification.
ADCON0 REGISTER
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5-2
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 213
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 19-2:
ADCON1 REGISTER
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
VCFG1
VCFG0
PCFG3
PCFG2
PCFG1
PCFG0
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5-4
A/D VREF-
00
AVDD
AVSS
01
External VREF+
AVSS
10
AVDD
External VREF-
11
External VREF+
External VREF-
PCFG3
PCFG0
AN14
AN13
AN12
AN11
AN10
AN9
AN8
AN7
AN6
AN5
AN4
AN3
AN2
AN1
AN0
bit 3-0
A/D VREF+
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
A
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
A
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
A
A
D
D
D
D
D
D
D
D
D
D
D
D
D
D
A
A
A
D
D
D
D
D
D
D
D
D
D
D
D
D
A
A
A
A
D
D
D
D
D
D
D
D
D
D
D
D
A
A
A
A
A
D
D
D
D
D
D
D
D
D
D
D
A
A
A
A
A
A
D
D
D
D
D
D
D
D
D
D
A
A
A
A
A
A
A
D
D
D
D
D
D
D
D
D
A
A
A
A
A
A
A
A
D
D
D
D
D
D
D
D
A
A
A
A
A
A
A
A
A
D
D
D
D
D
D
D
A
A
A
A
A
A
A
A
A
A
D
D
D
D
D
D
A
A
A
A
A
A
A
A
A
A
A
D
D
D
D
D
A
A
A
A
A
A
A
A
A
A
A
A
D
D
D
D
A
A
A
A
A
A
A
A
A
A
A
A
A
D
D
D
A
A
A
A
A
A
A
A
A
A
A
A
A
A
D
D
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
D
A = Analog input
Note:
D = Digital I/O
Legend:
DS39609B-page 214
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 19-3:
ADCON2 REGISTER
R/W-0
U-0
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
ADFM
ADCS2
ADCS1
ADCS0
bit 7
bit 0
bit 7
bit 6-3
Unimplemented: Read as 0
bit 2-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 215
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 19-1:
AN15(1)
1110
AN14(1)
1101
AN13(1)
1100
AN12(1)
1011
1010
1001
1000
0111
0110
0101
0100
VAIN
0011
(Input Voltage)
10-bit
Converter
A/D
0010
0001
VCFG1:VCFG0
0000
VDD
AN11
AN10
AN9
AN8
AN7
AN6
AN5
AN4
AN3
AN2
AN1
AN0
VREF+
Reference
Voltage
VREFVSS
Note 1: Channels AN15 through AN12 are not available on PIC18F6X20 devices.
2: I/O pins have diode protection to VDD and VSS.
DS39609B-page 216
PIC18F6520/8520/6620/8620/6720/8720
The value in the ADRESH/ADRESL registers is not
modified for a Power-on Reset. The ADRESH/
ADRESL registers will contain unknown data after a
Power-on Reset.
2.
3.
4.
6.
1.
7.
5.
FIGURE 19-2:
VT = 0.6V
Rs
VAIN
RIC 1k
ANx
CPIN
5 pF
VT = 0.6V
SS
RSS
ILEAKAGE
500 nA
CHOLD = 120 pF
VSS
Legend: CPIN
= input capacitance
= threshold voltage
VT
ILEAKAGE = leakage current at the pin due to
various junctions
= interconnect resistance
RIC
= sampling switch
SS
= sample/hold capacitance (from DAC)
CHOLD
RSS
= sampling switch resistance
VDD
6V
5V
4V
3V
2V
5 6 7 8 9 10 11
Sampling Switch (k)
DS39609B-page 217
PIC18F6520/8520/6620/8620/6720/8720
19.1
=
=
=
=
=
120 pF
2.5 k
1/2 LSb
5V Rss = 7 k
50C (system max.)
0V @ time = 0
EQUATION 19-1:
TACQ
TAMP + TC + TCOFF
EQUATION 19-2:
VHOLD =
or
TC
=
EXAMPLE 19-1:
TACQ
ACQUISITION TIME
TAMP + TC + TCOFF
TC
TACQ
DS39609B-page 218
PIC18F6520/8520/6620/8620/6720/8720
19.2
19.3
2 TOSC
4 TOSC
8 TOSC
16 TOSC
32 TOSC
64 TOSC
Internal RC oscillator
TABLE 19-1:
Operation
ADCS2:ADCS0
PIC18FXX20
2 TOSC
000
1.25 MHz
666 kHz
TOSC
100
2.50 MHz
1.33 MHz
8 TOSC
001
5.00 MHz
2.67 MHz
16 TOSC
101
10.0 MHz
5.33 MHz
32 TOSC
010
20.0 MHz
10.67 MHz
64 TOSC
110
40.0 MHz
21.33 MHz
RC
x11
PIC18LFXX20
DS39609B-page 219
PIC18F6520/8520/6620/8620/6720/8720
19.4
A/D Conversions
19.5
FIGURE 19-3:
TCY - TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11
b0
b1
b3
b0
b4
b2
b5
b7
b6
b8
b9
Conversion starts
Holding capacitor is disconnected from analog input (typically 100 ns)
Set GO bit
Next Q4: ADRESH/ADRESL is loaded, GO bit is cleared,
ADIF bit is set, holding capacitor is connected to analog input.
DS39609B-page 220
PIC18F6520/8520/6620/8620/6720/8720
TABLE 19-2:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
Resets
INTCON
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 0000
0000 0000
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
0111 1111
0111 1111
PIR2
CMIF
BCLIF
LVDIF
TMR3IF
CCP2IF
-0-- 0000
-0-- 0000
PIE2
CMIE
BCLIE
LVDIE
TMR3IE
CCP2IE
-0-- 0000
-0-- 0000
IPR2
CMIP
BCLIP
LVDIP
TMR3IP
CCP2IP
-0-- 0000
-0-- 0000
ADRESH
xxxx xxxx
uuuu uuuu
ADRESL
xxxx xxxx
uuuu uuuu
ADCON0
CHS3
CHS3
CHS1
CHS0
GO/DONE
ADON
--00 0000
--00 0000
ADCON1
VCFG1
VCFG0
PCFG3
PCFG2
PCFG1
PCFG0
--00 0000
--00 0000
ADCON2
ADFM
ADCS2
ADCS1
ADCS0
0--- -000
0--- -000
RA6
RA5
RA4
RA3
RA2
RA1
RA0
PORTA
TRISA
PORTF
LATF
TRISF
PORTH(1)
LATH(1)
--0x 0000
--0u 0000
--11 1111
--11 1111
RF7
RF6
RF5
RF4
RF3
RF2
RF1
RF0
x000 0000
u000 0000
LATF7
LATF6
LATF5
LATF4
LATF3
LATF2
LATF1
LATF0
xxxx xxxx
uuuu uuuu
1111 1111
1111 1111
RH6
RH5
RH4
RH3
RH2
RH1
RH0
0000 xxxx
0000 xxxx
LATH7
LATH6
LATH5
LATH4
LATH3
LATH2
LATH1
LATH0
xxxx xxxx
uuuu uuuu
1111 1111
1111 1111
TRISH(1)
Legend:
Note 1:
x = unknown, u = unchanged, = unimplemented, read as 0. Shaded cells are not used for A/D conversion.
Only available on PIC18F8X20 devices.
DS39609B-page 221
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 222
PIC18F6520/8520/6620/8620/6720/8720
20.0
COMPARATOR MODULE
The comparator module contains two analog comparators. The inputs to the comparators are multiplexed
with the RF1 through RF6 pins. The on-chip voltage reference (Section 21.0 Comparator Voltage Reference
Module) can also be an input to the comparators.
REGISTER 20-1:
The CMCON register, shown as Register 20-1, controls the comparator input and output multiplexers. A
block diagram of the various comparator configurations
is shown in Figure 20-1.
CMCON REGISTER
R-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
C2OUT
C1OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 223
PIC18F6520/8520/6620/8620/6720/8720
20.1
Comparator Configuration
There are eight modes of operation for the comparators. The CMCON register is used to select these
modes. Figure 20-1 shows the eight possible modes.
The TRISF register controls the data direction of the
comparator pins for each mode. If the Comparator
mode is changed, the comparator output level may not
FIGURE 20-1:
VIN+
VIN-
RF3/AN8
VIN+
VIN-
RF5/AN10 A
VIN+
VIN-
RF5/AN10 D
VIN+
VIN-
VIN+
RF6/AN11
C1
Off (Read as 0)
C2
Off (Read as 0)
RF4/AN9
RF3/AN8
VIN-
RF5/AN10 A
VIN+
RF6/AN11
C1
C1
Off (Read as 0)
C2
Off (Read as 0)
Comparators Off
CM2:CM0 = 111
VIN-
RF5/AN10 A
RF4/AN9
Note:
C1OUT
C1
C1OUT
C2
C2OUT
RF2/AN7/C1OUT
RF4/AN9
RF3/AN8
VIN-
VIN+
C2
RF4/AN9
C2OUT
RF3/AN8
VIN-
VIN+
RF1/AN6/C2OUT
Two Common Reference Comparators
CM2:CM0 = 100
RF6/AN11
RF5/AN10 A
VINVIN+
VIN-
RF5/AN10 A
VIN+
RF6/AN11
C1
C1OUT
C1
C1OUT
C2
C2OUT
RF2/AN7/C1OUT
RF4/AN9
RF3/AN8
VIN-
VIN+
C2
C2OUT
RF4/AN9
RF3/AN8
VIN-
VIN+
RF1/AN6/C2OUT
Four Inputs Multiplexed to Two Comparators
CM2:CM0 = 110
VIN-
VIN+
RF6/AN11
C1
C1OUT
RF5/AN10 A
RF2/AN7/C1OUT
RF4/AN9
RF3/AN8
RF4/AN9
VIN-
VIN+
RF3/AN8
C2
CIS = 0
CIS = 1
VINVIN+
C1
C1OUT
C2
C2OUT
A
A
CIS = 0
CIS = 1
VINVIN+
Off (Read as 0)
DS39609B-page 224
CVREF
D = Digital Input
PIC18F6520/8520/6620/8620/6720/8720
20.2
20.3.2
Comparator Operation
20.3
20.4
Comparator Reference
FIGURE 20-2:
VIN+
VIN-
SINGLE COMPARATOR
20.5
Output
VIN
VIN
VIN
+
VIN+
Comparator Outputs
Output
Output
20.3.1
DS39609B-page 225
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 20-3:
MULTIPLEX
+
CxINV
To RF1 or
RF2 pin
Bus
Data
Q
Read CMCON
Set
CMIF
bit
D
EN
Q
From
Other
Comparator
D
EN
CL
Read CMCON
Reset
20.6
Comparator Interrupts
DS39609B-page 226
Note:
PIC18F6520/8520/6620/8620/6720/8720
20.7
Comparator Operation
During Sleep
20.9
20.8
Effects of a Reset
FIGURE 20-4:
RS < 10k
RIC
Comparator
Input
AIN
CPIN
5 pF
VA
VT = 0.6V
ILEAKAGE
500 nA
VSS
Legend:
CPIN
VT
ILEAKAGE
RIC
RS
VA
=
=
=
=
=
=
Input Capacitance
Threshold Voltage
Leakage Current at the pin due to various junctions
Interconnect Resistance
Source Impedance
Analog Voltage
DS39609B-page 227
PIC18F6520/8520/6620/8620/6720/8720
TABLE 20-1:
Name
C2OUT
C1OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
TMR0IE INT0IE
RBIE
TMR0IF
INT0IF
RBIF
INTCON
Bit 3
Bit 2
Bit 1
Bit 0
Value on
all other
Resets
Bit 6
CMCON
Bit 4
Value on
POR
Bit 7
GIE/
GIEH
PEIE/
GIEL
PIR2
CMIF
BCLIF
LVDIF
PIE2
CMIE
BCLIE
LVDIE
IPR2
CMIP
BCLIP
LVDIP
PORTF
RF7
RF6
RF5
RF4
RF3
RF2
RF1
RF0
LATF
LATF7
LATF6
LATF5
LATF4
LATF3
LATF2
LATF1
LATF0
TRISF
TRISF7 TRISF6 TRISF5 TRISF4 TRISF3 TRISF2 TRISF1 TRISF0 1111 1111 1111 1111
DS39609B-page 228
PIC18F6520/8520/6620/8620/6720/8720
21.0
COMPARATOR VOLTAGE
REFERENCE MODULE
21.1
If CVRR = 1:
CVREF = (CVR<3:0>/24) x CVRSRC
If CVRR = 0:
CVREF = (CVRSRC x 1/4) + (CVR<3:0>/32) x CVRSRC
Note: In order to select external VREF+ and VREFsupply voltages, the Voltage Reference Configuration bits (VCFG1:VCFG0) of the
ADCON1 register must be set appropriately.
REGISTER 21-1:
CVRCON REGISTER
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 229
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 21-1:
CVRSS = 0
16 Stages
CVRSS = 1
CVREN
8R
R
CVRR
8R
CVRSS = 0
CVRSS = 1
CVREF
VREFCVR3
(From CVRCON<3:0>)
CVR0
21.2
21.4
Effects of a Reset
21.3
21.5
Connection Considerations
DS39609B-page 230
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 21-2:
R(1)
CVREF
Module
RF5
CVREF Output
Voltage
Reference
Output
Impedance
Note 1:
TABLE 21-1:
Name
R is dependent upon the Comparator Voltage Reference Configuration bits CVRCON<3:0> and CVRCON<5>.
Bit 7
Bit 6
Value on
POR
Value on
all other
Resets
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
CMCON
C2OUT
C1OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
TRISF
TRISF7
TRISF2
TRISF1
DS39609B-page 231
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 232
PIC18F6520/8520/6620/8620/6720/8720
22.0
LOW-VOLTAGE DETECT
Voltage
FIGURE 22-1:
VA
VB
Legend:
VA = LVD trip point
VB = Minimum valid device
operating voltage
Time
TA
TB
DS39609B-page 233
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 22-2:
LVD3:LVD0
LVDCON
Register
16 to 1 MUX
VDD
Internally Generated
Reference Voltage
(Parameter #D423)
LVDEN
FIGURE 22-3:
LVDIF
16 to 1 MUX
LVD3:LVD0
LVDIN
Externally Generated
Trip Point
LVDEN
LVD
VxEN
BODEN
EN
BGAP
DS39609B-page 234
PIC18F6520/8520/6620/8620/6720/8720
22.1
Control Register
REGISTER 22-1:
LVDCON REGISTER
U-0
U-0
R-0
R/W-0
R/W-0
R/W-1
R/W-0
R/W-1
IRVST
LVDEN
LVDL3
LVDL2
LVDL1
LVDL0
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4
bit 3-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
DS39609B-page 235
PIC18F6520/8520/6620/8620/6720/8720
22.2
Operation
1.
2.
3.
4.
5.
6.
FIGURE 22-4:
CASE 1:
Enable LVD
Internally Generated
Reference Stable
TIVRST
LVDIF cleared in software
CASE 2:
VDD
VLVD
LVDIF
Enable LVD
Internally Generated
Reference Stable
TIVRST
DS39609B-page 236
PIC18F6520/8520/6620/8620/6720/8720
22.2.1
22.2.2
22.3
22.4
Effects of a Reset
CURRENT CONSUMPTION
DS39609B-page 237
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 238
PIC18F6520/8520/6620/8620/6720/8720
23.0
There are several features intended to maximize system reliability, minimize cost through elimination of
external components, provide power saving operating
modes and offer code protection. These are:
Oscillator Selection
Reset
- Power-on Reset (POR)
- Power-up Timer (PWRT)
- Oscillator Start-up Timer (OST)
- Brown-out Reset (BOR)
Interrupts
Watchdog Timer (WDT)
Sleep
Code Protection
ID Locations
In-Circuit Serial Programming
All PIC18FXX20 devices have a Watchdog Timer,
which is permanently enabled via the configuration bits,
or software controlled. It runs off its own RC oscillator
for added reliability. There are two timers that offer
necessary delays on power-up. One is the Oscillator
Start-up Timer (OST), intended to keep the chip in
Reset until the crystal oscillator is stable. The other is
the Power-up Timer (PWRT), which provides a fixed
delay on power-up only, designed to keep the part in
Reset while the power supply stabilizes. With these two
timers on-chip, most applications need no external
Reset circuitry.
23.1
Configuration Bits
DS39609B-page 239
PIC18F6520/8520/6620/8620/6720/8720
TABLE 23-1:
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Default/
Unprogrammed
Value
300001h
CONFIG1H
OSCSEN
FOSC2
FOSC1
FOSC0
--1- -111
300002h
CONFIG2L
BORV1
BORV0
BODEN
PWRTEN
---- 1111
300003h
CONFIG2H
WDTPS2
WDTPS1
WDTPS0
WDTEN
---- 1111
WAIT
PM1
PM0
1--- --11
300004h(1) CONFIG3L
r(3)
CCP2MX
---- --11
LVP
STVREN
1--- -1-1
CP7(2)
CP6(2)
CP5(2)
CP4(2)
CP3
CP2
CP1
CP0
1111 1111
CPD
CPB
11-- ----
WRT5(2)
WRT4(2)
WRT3
WRT2
WRT1
WRT0
1111 1111
WRTB
WRTC
111- ----
CONFIG7L
EBTR7(2)
EBTR6(2)
EBTR5(2)
EBTR4(2)
EBTR3
EBTR2
EBTR1
EBTR0
1111 1111
CONFIG7H
EBTRB
-1-- ----
DEVID1
DEV2
DEV1
DEV0
REV4
REV3
REV2
REV1
REV0
(4)
3FFFFFh
DEVID2
DEV10
DEV9
DEV8
DEV7
DEV6
DEV5
DEV4
DEV3
0000 0110
Legend:
300005h
CONFIG3H
300006h
CONFIG4L DEBUG
300008h
CONFIG5L
300009h
CONFIG5H
30000Ah
30000Bh
CONFIG6H
WRTD
30000Ch
30000Dh
3FFFFEh
Note 1:
2:
3:
4:
REGISTER 23-1:
U-0
R/P-1
U-0
U-0
R/P-1
R/P-1
R/P-1
OSCSEN
FOSC2
FOSC1
FOSC0
bit 7
bit 0
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4-3
Unimplemented: Read as 0
bit 2-0
P = Programmable bit
DS39609B-page 240
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-2:
U-0
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
BORV1
BORV0
BOREN
PWRTEN
bit 7
bit 0
bit 7-4
Unimplemented: Read as 0
bit 3-2
bit 1
bit 0
P = Programmable bit
REGISTER 23-3:
U-0
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
WDTPS2
WDTPS1
WDTPS0
WDTEN
bit 7
bit 0
bit 7-4
Unimplemented: Read as 0
bit 3-1
bit 0
P = Programmable bit
DS39609B-page 241
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-4:
U-0
U-0
U-0
U-0
U-0
R/P-1
R/P-1
WAIT
PM1
PM0
bit 7
bit 0
bit 7
bit 6-2
Unimplemented: Read as 0
bit 1-0
P = Programmable bit
REGISTER 23-5:
U-0
U-0
U-0
U-0
U-0
R/P-1
R/P-1
r(1)
CCP2MX
bit 7
bit 0
bit 7-2
Unimplemented: Read as 0
bit 1
bit 0
P = Programmable bit
DS39609B-page 242
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-6:
U-0
U-0
U-0
U-0
R/P-1
U-0
R/P-1
DEBUG
LVP
STVREN
bit 7
bit 0
bit 7
bit 6-3
Unimplemented: Read as 0
bit 2
bit 1
Unimplemented: Read as 0
bit 0
P = Programmable bit
DS39609B-page 243
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-7:
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
CP7(1)
CP6(1)
CP5(1)
CP4(1)
CP3
CP2
CP1
CP0
bit 7
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
bit 0
DS39609B-page 244
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-8:
bit 7
bit 6
bit 5-0
R/C-1
CPB
U-0
U-0
U-0
U-0
U-0
U-0
bit 0
DS39609B-page 245
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-9:
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
WRT7(1)
WRT6(1)
WRT5(1)
WRT4(1)
WRT3
WRT2
WRT1
WRT0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
P = Programmable bit
DS39609B-page 246
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-10: CONFIG6H: CONFIGURATION REGISTER 6 HIGH (BYTE ADDRESS 30000Bh)
R/P-1
R/P-1
R-1
U-0
U-0
U-0
U-0
U-0
WRTD
WRTB
WRTC(1)
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4-0
Unimplemented: Read as 0
Legend:
R = Readable bit
P = Programmable bit
DS39609B-page 247
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-11: CONFIG7L: CONFIGURATION REGISTER 7 LOW (BYTE ADDRESS 30000Ch)
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
R/P-1
EBTR7(1)
EBTR6(1)
EBTR5(1)
EBTR4(1)
EBTR3
EBTR2
EBTR1
EBTR0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
P = Programmable bit
DS39609B-page 248
PIC18F6520/8520/6620/8620/6720/8720
REGISTER 23-12: CONFIG7H: CONFIGURATION REGISTER 7 HIGH (BYTE ADDRESS 30000Dh)
U-0
R/P-1
U-0
U-0
U-0
U-0
U-0
U-0
EBTRB
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5-0
Unimplemented: Read as 0
Legend:
R = Readable bit
P = Programmable bit
DEV2
DEV1
DEV0
REV4
REV3
REV2
REV1
REV0
bit 7
bit 0
bit 7-5
bit 4-0
P = Programmable bit
DEV10
DEV9
DEV8
DEV7
DEV6
DEV5
DEV4
DEV3
bit 7
bit 7-0
bit 0
P = Programmable bit
DS39609B-page 249
PIC18F6520/8520/6620/8620/6720/8720
23.2
23.2.1
CONTROL REGISTER
U-0
U-0
U-0
U-0
U-0
U-0
R/W-0
SWDTEN
bit 7
bit 0
bit 7-1
Unimplemented: Read as 0
bit 0
DS39609B-page 250
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PIC18F6520/8520/6620/8620/6720/8720
23.2.2
WDT POSTSCALER
FIGURE 23-1:
WDT Timer
Postscaler
8
WDTPS2:WDTPS0
8-to-1 MUX
WDTEN
Configuration bit
SWDTEN bit
WDT
Time-out
Note:
TABLE 23-2:
Name
CONFIG2H
RCON
WDTCON
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
WDTPS2
WDTPS2
WDTPS0
WDTEN
IPEN
RI
TO
PD
POR
BOR
SWDTEN
DS39609B-page 251
PIC18F6520/8520/6620/8620/6720/8720
23.3
23.3.1
23.3.2
DS39609B-page 252
PIC18F6520/8520/6620/8620/6720/8720
WAKE-UP FROM SLEEP THROUGH INTERRUPT(1,2)
FIGURE 23-2:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
TOST(2)
CLKO(4)
INT pin
INTF flag
(INTCON<1>)
Interrupt Latency(3)
GIEH bit
(INTCON<7>)
Processor in
Sleep
INSTRUCTION FLOW
PC
Instruction
Fetched
Instruction
Executed
Note
23.4
1:
2:
3:
4:
PC
PC+2
Inst(PC) = Sleep
Inst(PC + 2)
PC+4
Inst(PC + 2)
Sleep
Inst(PC - 1)
PC + 4
PC+4
0008h
000Ah
Inst(0008h)
Inst(000Ah)
Dummy Cycle
Inst(0008h)
Inst(PC + 4)
Dummy Cycle
TABLE 23-3:
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CP6(1)
CP5(1)
CP4(1)
CP3
CP2
CP1
CP0
CPB
WRT6(1)
WRT5(1)
WRT4(1)
300008h
CONFIG5L
CP7(1)
300009h
CONFIG5H
CPD
(1)
30000Ah
CONFIG6L
WRT3
WRT2
WRT1
WRT0
30000Bh
CONFIG6H
WRTD
WRTB
WRTC
30000Ch
CONFIG7L
EBTR7(1)
EBTR6(1)
EBTR5(1)
EBTR4(1)
EBTR3
EBTR2
EBTR1
EBTR0
30000Dh
CONFIG7H
EBTRB
WRT7
DS39609B-page 253
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 23-3:
32 Kbytes
Boot Block
000000h
0007FFh
Block 0
000800h
001FFFh
002000h
Block 1
Block 2
005FFFh
006000h
Block 3
Unimplemented
Read 0s
1FFFFFh
FIGURE 23-4:
64 Kbytes
(PIC18FX620)
128 Kbytes
(PIC18FX720)
Boot Block
Boot Block
000000h
0001FFh
Block 0
Block 0
000200h
003FFFh
Block 1
Block 1
004000h
CP1, WRT1, EBTR1
007FFFh
008000h
Block 2
Block 2
Block 3
Block 3
Block 4
Block 5
Unimplemented
Read 0s
018000h
Block 6
Block 7
DS39609B-page 254
PIC18F6520/8520/6620/8620/6720/8720
23.4.1
PROGRAM MEMORY
CODE PROTECTION
FIGURE 23-5:
Register Values
Program Memory
TBLPTR = 000FFFh
WRTB, EBTRB = 11
WRT0, EBTR0 = 01
PC = 003FFEh
TBLWT *
003FFFh
004000h
WRT1, EBTR1 = 11
007FFFh
008000h
PC = 008FFEh
WRT2, EBTR2 = 11
TBLWT *
00BFFFh
00C000h
WRT3, EBTR3 = 11
00FFFFh
DS39609B-page 255
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 23-6:
Register Values
Program Memory
TBLPTR = 000FFFh
WRTB, EBTRB = 11
WRT0, EBTR0 = 10
003FFFh
004000h
PC = 004FFEh
TBLRD *
WRT1, EBTR1 = 11
007FFFh
008000h
WRT2, EBTR2 = 11
00BFFFh
00C000h
WRT3, EBTR3 = 11
00FFFFh
Results: All table reads from external blocks to Block n are disabled whenever EBTRn = 0.
TABLAT register returns a value of 0.
FIGURE 23-7:
Register Values
Program Memory
TBLPTR = 000FFFh
PC = 003FFEh
WRTB, EBTRB = 11
WRT0, EBTR0 = 10
TBLRD *
003FFFh
004000h
WRT1, EBTR1 = 11
007FFFh
008000h
WRT2, EBTR2 = 11
00BFFFh
00C000h
WRT3, EBTR3 = 11
00FFFFh
DS39609B-page 256
PIC18F6520/8520/6620/8620/6720/8720
23.4.2
DATA EEPROM
CODE PROTECTION
23.4.3
CONFIGURATION REGISTER
PROTECTION
23.5
ID Locations
23.6
PIC18FX520/X620/X720 microcontrollers can be serially programmed while in the end application circuit.
This is simply done with two lines for clock and data
and three other lines for power, ground and the
programming voltage. This allows customers to manufacture boards with unprogrammed devices and then
program the microcontroller just before shipping the
product. This also allows the most recent firmware or a
custom firmware to be programmed.
Note:
23.7
When
performing
In-Circuit
Serial
Programming, verify that power is connected to all VDD and AVDD pins of the
microcontroller and that all VSS and AVSS
pins are grounded.
In-Circuit Debugger
TABLE 23-4:
DEBUGGER RESOURCES
I/O pins
Stack
Program Memory
Data Memory
RB6, RB7
2 levels
Last 576 bytes
Last 10 bytes
To use the In-Circuit Debugger function of the microcontroller, the design must implement In-Circuit Serial
Programming connections to MCLR/VPP, VDD, GND,
RB7 and RB6. This will interface to the In-Circuit
Debugger module available from Microchip or one of
the third party development tool companies.
23.8
DS39609B-page 257
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 258
PIC18F6520/8520/6620/8620/6720/8720
24.0
Byte-oriented operations
Bit-oriented operations
Literal operations
Control operations
1.
2.
3.
All examples use the format nnh to represent a hexadecimal number, where h signifies a hexadecimal
digit.
The Instruction Set Summary, shown in Table 24-1,
lists the instructions recognized by the Microchip
Assembler (MPASMTM).
Section 24.1 Instruction Set provides a description
of each instruction.
DS39609B-page 259
PIC18F6520/8520/6620/8620/6720/8720
TABLE 24-1:
Field
Description
bbb
BSR
dest
Destination either the WREG register or the specified register file location.
fs
12-bit Register file address (0x000 to 0xFFF). This is the source address.
fd
12-bit Register file address (0x000 to 0xFFF). This is the destination address.
Literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value).
label
Label name.
mm
The mode of the TBLPTR register for the table read and table write instructions.
Only used with table read and table write instructions:
No Change to register (such as TBLPTR with table reads and writes)
Post-Increment register (such as TBLPTR with table reads and writes)
Post-Decrement register (such as TBLPTR with table reads and writes)
Pre-Increment register (such as TBLPTR with table reads and writes)
*
*+
*+*
n
The relative address (2s complement number) for relative branch instructions, or the direct address for Call/
Branch and Return instructions.
PRODH
PRODL
Unused or Unchanged.
WREG
TBLPTR
TABLAT
TOS
Top-of-Stack.
PC
Program Counter.
PCL
PCH
PCLATH
PCLATU
GIE
WDT
Watchdog Timer.
TO
Time-out bit.
PD
Power-down bit.
C, DC, Z, OV, N
Optional.
Contents.
Assigned to.
< >
italics
DS39609B-page 260
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 24-1:
10
9 8 7
OPCODE d
a
Example Instruction
0
f (FILE #)
ADDWF MYREG, W, B
0
f (Source FILE #)
12 11
f (Destination FILE #)
1111
12 11
9 8 7
OPCODE b (BIT #) a
0
f (FILE #)
OPCODE
0
k (literal)
MOVLW 0x7F
8 7
OPCODE
15
0
n<7:0> (literal)
12 11
GOTO Label
0
n<19:8> (literal)
1111
8 7
OPCODE
15
0
CALL MYFUNC
n<7:0> (literal)
12 11
0
n<19:8> (literal)
S = Fast bit
15
OPCODE
15
OPCODE
11 10
0
BRA MYFUNC
n<10:0> (literal)
8 7
n<7:0> (literal)
0
BC MYFUNC
DS39609B-page 261
PIC18F6520/8520/6620/8620/6720/8720
TABLE 24-1:
Mnemonic,
Operands
Cycles
MSb
LSb
Status
Affected
Notes
f, d, a
f, d, a
f, d, a
f, a
f, d, a
f, a
f, a
f, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
f, d, a
fs, fd
MOVWF
MULWF
NEGF
RLCF
RLNCF
RRCF
RRNCF
SETF
SUBFWB
f, a
f, a
f, a
f, d, a
f, d, a
f, d, a
f, d, a
f, a
f, d, a
SUBWF
SUBWFB
f, d, a
f, d, a
SWAPF
TSTFSZ
XORWF
f, d, a
f, a
f, d, a
1
1
1
1
1
1 (2 or 3)
1 (2 or 3)
1 (2 or 3)
1
1 (2 or 3)
1 (2 or 3)
1
1 (2 or 3)
1 (2 or 3)
1
1
2
C, DC, Z, OV, N
C, DC, Z, OV, N
Z, N
Z
Z, N
None
None
None
C, DC, Z, OV, N
None
None
C, DC, Z, OV, N
None
None
Z, N
Z, N
None
1, 2
1, 2
1,2
2
1, 2
4
4
1, 2
1, 2, 3, 4
1, 2, 3, 4
1, 2
1, 2, 3, 4
4
1, 2
1, 2
1
1
1
1
1
1
1
1
1
1
0010
0010
0001
0110
0001
0110
0110
0110
0000
0010
0100
0010
0011
0100
0001
0101
1100
1111
0110
0000
0110
0011
0100
0011
0100
0110
0101
01da
00da
01da
101a
11da
001a
010a
000a
01da
11da
11da
10da
11da
10da
00da
00da
ffff
ffff
111a
001a
110a
01da
01da
00da
00da
100a
01da
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
1
1
0101
0101
11da
10da
ffff
ffff
1
1 (2 or 3)
1
0011
0110
0001
10da
011a
10da
ffff
ffff
ffff
ffff None
ffff None
ffff Z, N
4
1, 2
1
1
1 (2 or 3)
1 (2 or 3)
1
1001
1000
1011
1010
0111
bbba
bbba
bbba
bbba
bbba
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
ffff
None
None
None
None
None
1, 2
1, 2
3, 4
3, 4
1, 2
None
None
C, DC, Z, OV, N 1, 2
C, Z, N
Z, N
1, 2
C, Z, N
Z, N
None
C, DC, Z, OV, N 1, 2
f, b, a
f, b, a
f, b, a
f, b, a
f, d, a
Bit Clear f
Bit Set f
Bit Test f, Skip if Clear
Bit Test f, Skip if Set
Bit Toggle f
Note 1: When a Port register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
2: If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
4: Some instructions are 2-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
5: If the table write starts the write cycle to internal memory, the write will continue until terminated.
DS39609B-page 262
PIC18F6520/8520/6620/8620/6720/8720
TABLE 24-1:
Mnemonic,
Operands
Description
Cycles
MSb
LSb
Status
Affected
Notes
CONTROL OPERATIONS
BC
BN
BNC
BNN
BNOV
BNZ
BOV
BRA
BZ
CALL
n
n
n
n
n
n
n
n
n
n, s
CLRWDT
DAW
GOTO
NOP
NOP
POP
PUSH
RCALL
RESET
RETFIE
RETLW
RETURN
SLEEP
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
2
1 (2)
2
Branch if Carry
Branch if Negative
Branch if Not Carry
Branch if Not Negative
Branch if Not Overflow
Branch if Not Zero
Branch if Overflow
Branch Unconditionally
Branch if Zero
Call subroutine 1st word
2nd word
Clear Watchdog Timer
Decimal Adjust WREG
Go to address 1st word
2nd word
No Operation
No Operation
Pop top of return stack (TOS)
Push top of return stack (TOS)
Relative Call
Software device Reset
Return from interrupt enable
k
s
1
1
1
1
2
1
2
1110
1110
1110
1110
1110
1110
1110
1101
1110
1110
1111
0000
0000
1110
1111
0000
1111
0000
0000
1101
0000
0000
0010
0110
0011
0111
0101
0001
0100
0nnn
0000
110s
kkkk
0000
0000
1111
kkkk
0000
xxxx
0000
0000
1nnn
0000
0000
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
kkkk
kkkk
0000
0000
kkkk
kkkk
0000
xxxx
0000
0000
nnnn
1111
0001
2
2
1
0000
0000
0000
1100
0000
0000
kkkk
0001
0000
1
1
2
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
kkkk
kkkk
0100
0111
kkkk
kkkk
0000
xxxx
0110
0101
nnnn
1111
000s
None
None
None
None
None
None
None
None
None
None
TO, PD
C
None
None
None
None
None
None
All
GIE/GIEH,
PEIE/GIEL
kkkk None
001s None
0011 TO, PD
Note 1: When a Port register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
2: If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
4: Some instructions are 2-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
5: If the table write starts the write cycle to internal memory, the write will continue until terminated.
DS39609B-page 263
PIC18F6520/8520/6620/8620/6720/8720
TABLE 24-1:
Mnemonic,
Operands
Description
Cycles
MSb
LSb
Status
Affected
Notes
LITERAL OPERATIONS
ADDLW
ANDLW
IORLW
LFSR
k
k
k
f, k
MOVLB
MOVLW
MULLW
RETLW
SUBLW
XORLW
k
k
k
k
k
k
1
1
1
2
1
1
1
2
1
1
0000
0000
0000
1110
1111
0000
0000
0000
0000
0000
0000
1111
1011
1001
1110
0000
0001
1110
1101
1100
1000
1010
kkkk
kkkk
kkkk
00ff
kkkk
0000
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
kkkk
C, DC, Z, OV, N
Z, N
Z, N
None
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
0000
1000
1001
1010
1011
1100
1101
1110
1111
None
None
None
None
None
None
None
None
None
None
None
None
C, DC, Z, OV, N
Z, N
Table Read
Table Read with post-increment
Table Read with post-decrement
Table Read with pre-increment
Table Write
Table Write with post-increment
Table Write with post-decrement
Table Write with pre-increment
2 (5)
Note 1: When a Port register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value
present on the pins themselves. For example, if the data latch is 1 for a pin configured as input and is driven low by an
external device, the data will be written back with a 0.
2: If this instruction is executed on the TMR0 register (and where applicable, d = 1), the prescaler will be cleared if
assigned.
3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is
executed as a NOP.
4: Some instructions are 2-word instructions. The second word of these instructions will be executed as a NOP unless the
first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory
locations have a valid instruction.
5: If the table write starts the write cycle to internal memory, the write will continue until terminated.
DS39609B-page 264
PIC18F6520/8520/6620/8620/6720/8720
24.1
Instruction Set
ADDLW
ADD literal to W
Syntax:
[ label ] ADDLW
Operands:
0 k 255
Operation:
(W) + k W
Status Affected:
N, OV, C, DC, Z
Encoding:
0000
Description:
1111
kkkk
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
ADDLW
0x15
Before Instruction
W
0x10
ADDWF
ADD W to f
Syntax:
[ label ] ADDWF
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Encoding:
0010
01da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
After Instruction
W
0x25
Example:
ADDWF
REG, 0, 0
Before Instruction
W
REG
=
=
0x17
0xC2
After Instruction
W
REG
=
=
0xD9
0xC2
DS39609B-page 265
PIC18F6520/8520/6620/8620/6720/8720
ADDWFC
ANDLW
Syntax:
[ label ] ADDWFC
Syntax:
[ label ] ANDLW
Operands:
0 f 255
d [0,1]
a [0,1]
f [,d [,a]
Operation:
Status Affected:
N, OV, C, DC, Z
Encoding:
0010
Description:
Cycles:
0 k 255
Operation:
(W) .AND. k W
Status Affected:
N, Z
Encoding:
ffff
ffff
Words:
0000
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
ADDWFC
kkkk
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read literal
k
Process
Data
Write to W
ANDLW
0x5F
Before Instruction
W
0xA3
After Instruction
W
Example:
1011
Description:
Example:
Q Cycle Activity:
Q1
Decode
00da
Operands:
0x03
REG, 0, 1
Before Instruction
Carry bit =
REG
=
W
=
1
0x02
0x4D
After Instruction
Carry bit =
REG
=
W
=
DS39609B-page 266
0
0x02
0x50
PIC18F6520/8520/6620/8620/6720/8720
ANDWF
AND W with f
Syntax:
[ label ] ANDWF
Operands:
0 f 255
d [0,1]
a [0,1]
f [,d [,a]
Operation:
Status Affected:
N, Z
Encoding:
0001
ffff
ffff
Operands:
-128 n 127
Operation:
if Carry bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
1110
0010
nnnn
nnnn
Words:
Cycles:
1(2)
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
ANDWF
REG, 0, 0
Before Instruction
=
=
0x17
0xC2
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
If No Jump:
Q1
Decode
After Instruction
=
=
Cycles:
W
REG
[ label ] BC
Words:
W
REG
Syntax:
Description:
Example:
Branch if Carry
Encoding:
01da
Description:
Decode
BC
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
0x02
0xC2
Example:
HERE
BC
Before Instruction
PC
address (HERE)
=
=
=
=
1;
address (HERE+12)
0;
address (HERE+2)
After Instruction
If Carry
PC
If Carry
PC
DS39609B-page 267
PIC18F6520/8520/6620/8620/6720/8720
BCF
Bit Clear f
Syntax:
[ label ] BCF
Operands:
0 f 255
0b7
a [0,1]
Operation:
0 f<b>
Status Affected:
None
Encoding:
1001
Description:
Branch if Negative
Syntax:
[ label ] BN
Operands:
-128 n 127
Operation:
if Negative bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
Encoding:
bbba
ffff
ffff
1110
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
BCF
Before Instruction
FLAG_REG = 0xC7
After Instruction
FLAG_REG = 0x47
FLAG_REG,
0110
nnnn
nnnn
Description:
Words:
Cycles:
1(2)
Words:
Decode
f,b[,a]
BN
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
7, 0
If No Jump:
Q1
Decode
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
Example:
HERE
BN
Jump
Before Instruction
PC
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE+2)
After Instruction
If Negative
PC
If Negative
PC
DS39609B-page 268
PIC18F6520/8520/6620/8620/6720/8720
BNC
BNN
Syntax:
[ label ] BNC
Syntax:
[ label ] BNN
Operands:
-128 n 127
Operands:
-128 n 127
Operation:
if Carry bit is 0
(PC) + 2 + 2n PC
Operation:
if Negative bit is 0
(PC) + 2 + 2n PC
Status Affected:
None
Status Affected:
None
Encoding:
1110
0011
nnnn
nnnn
Encoding:
1110
0111
nnnn
nnnn
Description:
Description:
Words:
Words:
Cycles:
1(2)
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
If No Jump:
Q1
Decode
Example:
HERE
BNC
Jump
Before Instruction
PC
Decode
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
Example:
HERE
BNN
Jump
Before Instruction
=
address (HERE)
After Instruction
If Carry
PC
If Carry
PC
If No Jump:
Q1
PC
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE+2)
After Instruction
=
=
=
=
0;
address (Jump)
1;
address (HERE+2)
If Negative
PC
If Negative
PC
DS39609B-page 269
PIC18F6520/8520/6620/8620/6720/8720
BNOV
BNZ
Syntax:
[ label ] BNOV
Syntax:
[ label ] BNZ
Operands:
-128 n 127
Operands:
-128 n 127
Operation:
if Overflow bit is 0
(PC) + 2 + 2n PC
Operation:
if Zero bit is 0
(PC) + 2 + 2n PC
Status Affected:
None
Status Affected:
None
Encoding:
1110
0101
nnnn
nnnn
Encoding:
1110
0001
nnnn
nnnn
Description:
Description:
Words:
Words:
Cycles:
1(2)
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
If No Jump:
Q1
Decode
Example:
HERE
BNOV Jump
Before Instruction
PC
DS39609B-page 270
Decode
Example:
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
HERE
BNZ
Jump
Before Instruction
=
address (HERE)
After Instruction
If Overflow
PC
If Overflow
PC
If No Jump:
Q1
PC
address (HERE)
=
=
=
=
0;
address (Jump)
1;
address (HERE+2)
After Instruction
=
=
=
=
0;
address (Jump)
1;
address (HERE+2)
If Zero
PC
If Zero
PC
PIC18F6520/8520/6620/8620/6720/8720
BRA
Unconditional Branch
BSF
Bit Set f
Syntax:
[ label ] BRA
Syntax:
[ label ] BSF
Operands:
-1024 n 1023
Operands:
Operation:
(PC) + 2 + 2n PC
Status Affected:
None
0 f 255
0b7
a [0,1]
Operation:
1 f<b>
Status Affected:
None
Encoding:
Description:
1101
Cycles:
Q Cycle Activity:
Q1
No
operation
0nnn
nnnn
nnnn
Words:
Decode
Q2
Q3
Q4
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
Encoding:
HERE
BRA
Jump
PC
address (HERE)
address (Jump)
After Instruction
PC
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
BSF
FLAG_REG, 7, 1
Before Instruction
FLAG_REG
Before Instruction
bbba
Description:
Example:
Example:
1000
f,b[,a]
0x0A
0x8A
After Instruction
FLAG_REG
DS39609B-page 271
PIC18F6520/8520/6620/8620/6720/8720
BTFSC
BTFSS
Syntax:
Syntax:
Operands:
0 f 255
0b7
a [0,1]
Operands:
0 f 255
0b<7
a [0,1]
Operation:
skip if (f<b>) = 0
Operation:
skip if (f<b>) = 1
Status Affected:
None
Status Affected:
None
Encoding:
1011
bbba
ffff
ffff
Encoding:
1010
bbba
ffff
ffff
Description:
Description:
Words:
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Cycles:
1(2)
Note:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
No
operation
If skip:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
Process
Data
No
operation
If skip:
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Q4
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
FALSE
TRUE
BTFSC
:
:
FLAG, 1, 0
Before Instruction
PC
DS39609B-page 272
HERE
FALSE
TRUE
BTFSS
:
:
FLAG, 1, 0
Before Instruction
=
address (HERE)
After Instruction
If FLAG<1>
PC
If FLAG<1>
PC
Example:
PC
address (HERE)
=
=
=
=
0;
address (FALSE)
1;
address (TRUE)
After Instruction
=
=
=
=
0;
address (TRUE)
1;
address (FALSE)
If FLAG<1>
PC
If FLAG<1>
PC
PIC18F6520/8520/6620/8620/6720/8720
BTG
Bit Toggle f
BOV
Branch if Overflow
Syntax:
Syntax:
[ label ] BOV
Operands:
0 f 255
0b<7
a [0,1]
Operands:
-128 n 127
Operation:
if Overflow bit is 1
(PC) + 2 + 2n PC
Status Affected:
None
Operation:
(f<b>) f<b>
Status Affected:
None
Encoding:
Description:
bbba
ffff
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
BTG
PORTC,
After Instruction:
PORTC
1110
0100
nnnn
nnnn
Description:
Words:
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
4, 0
Before Instruction:
PORTC
ffff
Words:
Decode
Encoding:
0111
If No Jump:
Q1
Decode
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
Example:
HERE
BOV
Jump
Before Instruction
PC
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE+2)
After Instruction
If Overflow
PC
If Overflow
PC
DS39609B-page 273
PIC18F6520/8520/6620/8620/6720/8720
BZ
Branch if Zero
CALL
Subroutine Call
Syntax:
[ label ] BZ
Syntax:
Operands:
-128 n 127
Operands:
Operation:
if Zero bit is 1
(PC) + 2 + 2n PC
0 k 1048575
s [0,1]
Operation:
(PC) + 4 TOS,
k PC<20:1>,
if s = 1
(W) WS,
(STATUS) STATUSS,
(BSR) BSRS
Status Affected:
None
Status Affected:
None
Encoding:
1110
Description:
0000
nnnn
nnnn
Words:
Cycles:
1(2)
Q Cycle Activity:
If Jump:
Q1
Q2
Q3
Q4
Decode
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
No
operation
No
operation
Q2
Q3
Q4
Read literal
n
Process
Data
No
operation
If No Jump:
Q1
Decode
Example:
HERE
BZ
Jump
Encoding:
1st word (k<7:0>)
2nd word(k<19:8>)
1110
1111
110s
k19kkk
k7kkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read literal
k<7:0>
Push PC to
stack
Read literal
k<19:8>,
Write to PC
No
operation
No
operation
No
operation
No
operation
Before Instruction
PC
address (HERE)
=
=
=
=
1;
address (Jump)
0;
address (HERE+2)
After Instruction
If Zero
PC
If Zero
PC
kkkk0
kkkk8
Example:
HERE
CALL
THERE,1
Before Instruction
PC
address (HERE)
After Instruction
PC
TOS
WS
BSRS
STATUSS
DS39609B-page 274
=
=
=
=
=
address (THERE)
address (HERE + 4)
W
BSR
STATUS
PIC18F6520/8520/6620/8620/6720/8720
CLRF
Clear f
Syntax:
[ label ] CLRF
Operands:
0 f 255
a [0,1]
Operation:
000h f
1Z
Status Affected:
Encoding:
Description:
0110
f [,a]
101a
ffff
ffff
CLRWDT
Syntax:
[ label ] CLRWDT
Operands:
None
Operation:
000h WDT,
000h WDT postscaler,
1 TO,
1 PD
Status Affected:
TO, PD
Encoding:
0000
0000
0000
0100
Description:
Words:
Words:
Cycles:
Cycles:
Q Cycle Activity:
Q1
Decode
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Decode
Example:
Example:
CLRF
FLAG_REG,1
Before Instruction
FLAG_REG
Q3
Q4
Process
Data
No
operation
CLRWDT
Before Instruction
WDT Counter
0x5A
0x00
After Instruction
FLAG_REG
Q2
No
operation
WDT Counter
WDT Postscaler
TO
PD
=
=
=
=
0x00
0
1
1
After Instruction
DS39609B-page 275
PIC18F6520/8520/6620/8620/6720/8720
COMF
Complement f
Syntax:
[ label ] COMF
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
( f ) dest
Status Affected:
N, Z
Encoding:
0001
Description:
Cycles:
Q Cycle Activity:
Q1
Syntax:
[ label ] CPFSEQ
Operands:
0 f 255
a [0,1]
Operation:
(f) (W),
skip if (f) = (W)
(unsigned comparison)
Status Affected:
None
Encoding:
0110
001a
f [,a]
ffff
ffff
Description:
Q2
Q3
Q4
Words:
Process
Data
Write to
destination
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
COMF
Before Instruction
=
0x13
After Instruction
REG
W
ffff
Read
register f
Example:
REG
ffff
Words:
Decode
11da
f [,d [,a]
CPFSEQ
=
=
0x13
0xEC
REG, 0, 0
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
No
operation
If skip:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
NEQUAL
EQUAL
CPFSEQ REG, 0
:
:
Before Instruction
PC Address
W
REG
=
=
=
HERE
?
?
=
=
W;
Address (EQUAL)
W;
Address (NEQUAL)
After Instruction
If REG
PC
If REG
PC
DS39609B-page 276
PIC18F6520/8520/6620/8620/6720/8720
CPFSGT
CPFSLT
Syntax:
[ label ] CPFSGT
Syntax:
[ label ] CPFSLT
Operands:
0 f 255
a [0,1]
Operands:
0 f 255
a [0,1]
Operation:
(f) (W),
skip if (f) > (W)
(unsigned comparison)
Operation:
(f) (W),
skip if (f) < (W)
(unsigned comparison)
Status Affected:
None
Status Affected:
None
Encoding:
Description:
0110
010a
f [,a]
ffff
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
No
operation
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
No
operation
If skip:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Q4
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
NGREATER
GREATER
CPFSGT REG, 0
:
:
Before Instruction
=
=
Address (HERE)
?
>
=
W;
Address (GREATER)
W;
Address (NGREATER)
After Instruction
ffff
No
operation
No
operation
If REG
PC
If REG
PC
000a
No
operation
No
operation
PC
W
0110
Description:
Decode
If skip:
Example:
Encoding:
f [,a]
Example:
HERE
NLESS
LESS
CPFSLT REG, 1
:
:
Before Instruction
PC
W
=
=
Address (HERE)
?
<
=
W;
Address (LESS)
W;
Address (NLESS)
After Instruction
If REG
PC
If REG
PC
DS39609B-page 277
PIC18F6520/8520/6620/8620/6720/8720
DAW
DECF
Decrement f
Syntax:
[ label ] DAW
Syntax:
Operands:
None
Operands:
Operation:
0 f 255
d [0,1]
a [0,1]
Operation:
(f) 1 dest
Status Affected:
C, DC, N, OV, Z
0000
0000
0000
Cycles:
Q Cycle Activity:
Q1
Q3
Q4
Process
Data
Write
W
Example1:
DAW
Cycles:
1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
DECF
CNT,
1, 0
Before Instruction
CNT
Z
=
=
0x01
0
After Instruction
Before Instruction
=
=
=
ffff
Words:
Decode
Q2
ffff
Decrement register f. If d is 0,
the result is stored in W. If d is 1,
the result is stored back in register
f (default). If a is 0, the Access
Bank will be selected, overriding
the BSR value. If a = 1, then the
bank will be selected as per the
BSR value (default).
Q Cycle Activity:
Q1
Read
register W
01da
Description:
0111
Words:
W
C
DC
0000
Description:
Decode
Encoding:
0xA5
0
0
CNT
Z
=
=
0x00
1
After Instruction
W
C
DC
=
=
=
0x05
1
0
Example 2:
Before Instruction
W
C
DC
=
=
=
0xCE
0
0
After Instruction
W
C
DC
=
=
=
DS39609B-page 278
0x34
1
0
PIC18F6520/8520/6620/8620/6720/8720
DECFSZ
Decrement f, skip if 0
DCFSNZ
Syntax:
Syntax:
[ label ] DCFSNZ
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
(f) 1 dest,
skip if result = 0
Operation:
(f) 1 dest,
skip if result 0
Status Affected:
None
Status Affected:
None
Encoding:
0010
11da
ffff
ffff
Encoding:
0100
11da
f [,d [,a]
ffff
ffff
Description:
Description:
Words:
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Q4
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
DECFSZ
GOTO
CNT, 1, 1
LOOP
Example:
HERE
Example:
CONTINUE
Before Instruction
PC
=
=
=
=
DCFSNZ
:
:
TEMP, 1, 0
Before Instruction
Address (HERE)
After Instruction
CNT
If CNT
PC
If CNT
PC
HERE
ZERO
NZERO
TEMP
=
=
=
TEMP - 1,
0;
Address (ZERO)
0;
Address (NZERO)
After Instruction
CNT - 1
0;
Address (CONTINUE)
0;
Address (HERE+2)
TEMP
If TEMP
PC
If TEMP
PC
DS39609B-page 279
PIC18F6520/8520/6620/8620/6720/8720
GOTO
Unconditional Branch
INCF
Increment f
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 k 1048575
Operands:
Operation:
k PC<20:1>
Status Affected:
None
0 f 255
d [0,1]
a [0,1]
Operation:
(f) + 1 dest
Status Affected:
C, DC, N, OV, Z
Encoding:
1st word (k<7:0>)
2nd word(k<19:8>)
Description:
1110
1111
GOTO k
1111
k19kkk
k7kkk
kkkk
kkkk0
kkkk8
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read literal
k<7:0>
No
operation
Read literal
k<19:8>,
Write to PC
No
operation
No
operation
No
operation
No
operation
Example:
GOTO THERE
After Instruction
PC =
Address (THERE)
Encoding:
0010
INCF
f [,d [,a]
10da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
INCF
CNT, 1, 0
Before Instruction
CNT
Z
C
DC
=
=
=
=
0xFF
0
?
?
After Instruction
CNT
Z
C
DC
DS39609B-page 280
=
=
=
=
0x00
1
1
1
PIC18F6520/8520/6620/8620/6720/8720
INCFSZ
Increment f, skip if 0
INFSNZ
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
(f) + 1 dest,
skip if result = 0
Operation:
(f) + 1 dest,
skip if result 0
Status Affected:
None
Status Affected:
None
Encoding:
0011
INCFSZ
11da
f [,d [,a]
ffff
ffff
Encoding:
0100
INFSNZ
10da
f [,d [,a]
ffff
ffff
Description:
Description:
Words:
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Q4
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
NZERO
ZERO
INCFSZ
:
:
Before Instruction
PC
=
=
=
=
Example:
HERE
ZERO
NZERO
INFSNZ
REG, 1, 0
Before Instruction
Address (HERE)
After Instruction
CNT
If CNT
PC
If CNT
PC
CNT, 1, 0
PC
Address (HERE)
After Instruction
CNT + 1
0;
Address (ZERO)
0;
Address (NZERO)
REG
If REG
PC
If REG
PC
=
=
=
REG + 1
0;
Address (NZERO)
0;
Address (ZERO)
DS39609B-page 281
PIC18F6520/8520/6620/8620/6720/8720
IORLW
IORWF
Inclusive OR W with f
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, Z
IORLW k
Operands:
0 k 255
Operation:
(W) .OR. k W
Status Affected:
N, Z
Encoding:
0000
Description:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
kkkk
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
IORLW
Before Instruction
=
0x9A
After Instruction
W
kkkk
Words:
1001
0x35
Encoding:
0001
IORWF
00da
f [,d [,a]
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
0xBF
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
IORWF
RESULT, 0, 1
Before Instruction
RESULT =
W
=
0x13
0x91
After Instruction
RESULT =
W
=
DS39609B-page 282
0x13
0x93
PIC18F6520/8520/6620/8620/6720/8720
LFSR
Load FSR
MOVF
Move f
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0f2
0 k 4095
Operands:
Operation:
k FSRf
0 f 255
d [0,1]
a [0,1]
Status Affected:
None
Operation:
f dest
Status Affected:
N, Z
Encoding:
LFSR f,k
1110
1111
1110
0000
00ff
k7kkk
k11kkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read literal
k MSB
Process
Data
Write literal
k MSB to
FSRfH
Decode
Read literal
k LSB
Process
Data
Write literal
k to FSRfL
Example:
LFSR 2, 0x3AB
After Instruction
FSR2H
FSR2L
=
=
0x03
0xAB
Encoding:
MOVF
0101
f [,d [,a]
00da
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
register f
Process
Data
Write W
MOVF
REG, 0, 0
Before Instruction
REG
W
=
=
0x22
0xFF
=
=
0x22
0x22
After Instruction
REG
W
DS39609B-page 283
PIC18F6520/8520/6620/8620/6720/8720
MOVFF
Move f to f
MOVLB
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 fs 4095
0 fd 4095
Operands:
0 k 255
Operation:
k BSR
None
MOVFF fs,fd
Operation:
(fs) fd
Status Affected:
Status Affected:
None
Encoding:
Encoding:
1st word (source)
2nd word (destin.)
1100
1111
Description:
ffff
ffff
ffff
ffff
ffffs
ffffd
Words:
Cycles:
2 (3)
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register f
(src)
Process
Data
No
operation
Decode
No
operation,
No
operation
Write
register f
(dest)
No dummy
read
Example:
MOVFF
MOVLB k
0000
0001
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read literal
k
Process
Data
Write
literal k to
BSR
MOVLB
Before Instruction
BSR register
0x02
0x05
After Instruction
BSR register
REG1, REG2
Before Instruction
REG1
REG2
=
=
0x33
0x11
=
=
0x33,
0x33
After Instruction
REG1
REG2
DS39609B-page 284
PIC18F6520/8520/6620/8620/6720/8720
MOVLW
Move literal to W
MOVWF
Move W to f
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 k 255
Operands:
Operation:
kW
0 f 255
a [0,1]
Status Affected:
None
Operation:
(W) f
Status Affected:
None
Encoding:
0000
Description:
MOVLW k
1110
kkkk
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
MOVLW
0x5A
After Instruction
W
kkkk
0x5A
Encoding:
0110
Description:
111a
f [,a]
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
MOVWF
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
MOVWF
REG, 0
Before Instruction
W
REG
=
=
0x4F
0xFF
After Instruction
W
REG
=
=
0x4F
0x4F
DS39609B-page 285
PIC18F6520/8520/6620/8620/6720/8720
MULLW
MULWF
Multiply W with f
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 f 255
a [0,1]
Operation:
Status Affected:
None
MULLW
Operands:
0 k 255
Operation:
(W) x k PRODH:PRODL
Status Affected:
None
Encoding:
Description:
0000
Cycles:
Q Cycle Activity:
Q1
Example:
kkkk
kkkk
An unsigned multiplication is
carried out between the contents
of W and the 8-bit literal k. The
16-bit result is placed in
PRODH:PRODL register pair.
PRODH contains the high byte.
W is unchanged.
None of the status flags are
affected.
Note that neither overflow nor
carry is possible in this
operation. A zero result is
possible but not detected.
Words:
Decode
1101
Q2
Q3
Q4
Read
literal k
Process
Data
Write
registers
PRODH:
PRODL
MULLW
0xC4
Before Instruction
W
PRODH
PRODL
=
=
=
0xE2
?
?
=
=
=
0xE2
0xAD
0x08
Encoding:
Description
0000
001a
Cycles:
Q Cycle Activity:
Q1
Example:
ffff
ffff
Q2
Q3
Q4
Read
register f
Process
Data
Write
registers
PRODH:
PRODL
After Instruction
W
PRODH
PRODL
f [,a]
An unsigned multiplication is
carried out between the contents
of W and the register file location
f. The 16-bit result is stored in
the PRODH:PRODL register
pair. PRODH contains the high
byte.
Both W and f are unchanged.
None of the status flags are
affected.
Note that neither overflow nor
carry is possible in this
operation. A zero result is
possible but not detected. If a is
0, the Access Bank will be
selected, overriding the BSR
value. If a= 1, then the bank will
be selected as per the BSR
value (default).
Words:
Decode
MULWF
MULWF
REG, 1
Before Instruction
W
REG
PRODH
PRODL
=
=
=
=
0xC4
0xB5
?
?
=
=
=
=
0xC4
0xB5
0x8A
0x94
After Instruction
W
REG
PRODH
PRODL
DS39609B-page 286
PIC18F6520/8520/6620/8620/6720/8720
NEGF
Negate f
Syntax:
[ label ]
Operands:
0 f 255
a [0,1]
NEGF
Operation:
(f)+1f
Status Affected:
N, OV, C, DC, Z
Encoding:
0110
Description:
Cycles:
Q Cycle Activity:
Q1
Syntax:
[ label ]
NOP
Operands:
None
Operation:
No operation
Status Affected:
None
0000
1111
ffff
Description:
Cycles:
Decode
0000
xxxx
0000
xxxx
No operation.
Words:
Q Cycle Activity:
Q1
0000
xxxx
Q2
Q3
Q4
No
operation
No
operation
No
operation
Example:
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
Example:
No Operation
Encoding:
ffff
Words:
Decode
110a
f [,a]
NOP
NEGF
None.
REG, 1
Before Instruction
REG
After Instruction
REG
DS39609B-page 287
PIC18F6520/8520/6620/8620/6720/8720
POP
PUSH
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
None
Operands:
None
Operation:
Operation:
(PC+2) TOS
Status Affected:
None
Status Affected:
None
Encoding:
0000
Description:
0000
0000
0110
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
POP
Encoding:
Q2
Q3
Q4
POP TOS
value
No
operation
Cycles:
=
=
DS39609B-page 288
=
=
Q3
Q4
No
operation
No
operation
PUSH
TOS
PC
0031A2h
014332h
After Instruction
TOS
PC
Q2
PUSH PC+2
onto return
stack
Before Instruction
NEW
Before Instruction
TOS
Stack (1 level down)
0101
Words:
Example:
POP
GOTO
0000
Q Cycle Activity:
Q1
No
operation
0000
Description:
Decode
Example:
0000
PUSH
014332h
NEW
=
=
00345Ah
000124h
=
=
=
000126h
000126h
00345Ah
After Instruction
PC
TOS
Stack (1 level down)
PIC18F6520/8520/6620/8620/6720/8720
RCALL
Relative Call
RESET
Reset
Syntax:
[ label ] RCALL
Syntax:
[ label ]
Operands:
Operation:
-1024 n 1023
Operands:
None
(PC) + 2 TOS,
(PC) + 2 + 2n PC
Operation:
Status Affected:
None
Status Affected:
All
Encoding:
Description:
1101
nnnn
nnnn
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
1nnn
Encoding:
0000
RESET
0000
1111
1111
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Start
Reset
No
operation
No
operation
RESET
After Instruction
Q2
Q3
Q4
Read literal
n
Process
Data
Write to PC
No
operation
No
operation
Registers =
Flags*
=
Reset Value
Reset Value
Push PC to
stack
No
operation
Example:
No
operation
HERE
RCALL Jump
Before Instruction
PC =
Address (HERE)
After Instruction
PC =
TOS =
Address (Jump)
Address (HERE+2)
DS39609B-page 289
PIC18F6520/8520/6620/8620/6720/8720
RETFIE
RETLW
Return Literal to W
Syntax:
[ label ]
Syntax:
[ label ]
RETFIE [s]
RETLW k
Operands:
s [0,1]
Operands:
0 k 255
Operation:
(TOS) PC,
1 GIE/GIEH or PEIE/GIEL,
if s = 1
(WS) W,
(STATUSS) STATUS,
(BSRS) BSR,
PCLATU, PCLATH are unchanged
Operation:
k W,
(TOS) PC,
PCLATU, PCLATH are unchanged
Status Affected:
None
Status Affected:
0000
0000
0000
0001
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
literal k
Process
Data
Pop PC
from stack,
Write to W
No
operation
No
operation
No
operation
No
operation
Example:
Cycles:
CALL TABLE ;
;
;
;
:
TABLE
ADDWF PCL ;
RETLW k0
;
RETLW k1
;
:
:
RETLW kn
;
Decode
Q2
Q3
Q4
No
operation
No
operation
Pop PC
from stack
Set GIEH or
GIEL
No
operation
Example:
No
operation
RETFIE
No
operation
No
operation
DS39609B-page 290
W contains table
offset value
W now has
table value
W = offset
Begin table
End of table
Before Instruction
After Interrupt
PC
W
BSR
STATUS
GIE/GIEH, PEIE/GIEL
kkkk
Words:
Words:
Q Cycle Activity:
Q1
kkkk
000s
1100
Description:
GIE/GIEH, PEIE/GIEL.
Encoding:
Description:
Encoding:
W
=
=
=
=
=
TOS
WS
BSRS
STATUSS
1
0x07
After Instruction
W
value of kn
PIC18F6520/8520/6620/8620/6720/8720
RETURN
RLCF
Syntax:
[ label ]
Syntax:
[ label ]
RETURN [s]
RLCF
f [,d [,a]
Operands:
s [0,1]
Operands:
Operation:
(TOS) PC,
if s = 1
(WS) W,
(STATUSS) STATUS,
(BSRS) BSR,
PCLATU, PCLATH are unchanged
0 f 255
d [0,1]
a [0,1]
Operation:
(f<n>) dest<n+1>,
(f<7>) C,
(C) dest<0>
Status Affected:
C, N, Z
None
Encoding:
Status Affected:
Encoding:
0000
0000
0001
001s
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
No
operation
Q2
Q3
Q4
No
operation
Process
Data
Pop PC
from stack
No
operation
No
operation
No
operation
0011
Description:
ffff
register f
C
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
ffff
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
Example:
01da
RLCF
REG, 0, 0
Before Instruction
RETURN
After Interrupt
PC = TOS
REG
C
1110 0110
0
After Instruction
REG
W
C
=
=
=
=
=
1110 0110
1100 1100
1
DS39609B-page 291
PIC18F6520/8520/6620/8620/6720/8720
RLNCF
RRCF
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
(f<n>) dest<n+1>,
(f<7>) dest<0>
Operation:
Status Affected:
N, Z
(f<n>) dest<n-1>,
(f<0>) C,
(C) dest<7>
Status Affected:
C, N, Z
Encoding:
0100
Description:
RLNCF
01da
f [,d [,a]
ffff
ffff
Encoding:
0011
Description:
Cycles:
Q Cycle Activity:
Q1
Decode
Q3
Q4
Read
register f
Process
Data
Write to
destination
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
RLNCF
REG, 1, 0
ffff
ffff
register f
Q2
Example:
00da
f [,d [,a]
register f
Words:
RRCF
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Before Instruction
REG
1010 1011
After Instruction
REG
Example:
RRCF
REG, 0, 0
Before Instruction
0101 0111
REG
C
=
=
1110 0110
0
After Instruction
REG
W
C
DS39609B-page 292
=
=
=
1110 0110
0111 0011
0
PIC18F6520/8520/6620/8620/6720/8720
RRNCF
SETF
Set f
Syntax:
[ label ]
Syntax:
[ label ] SETF
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
a [0,1]
Operation:
(f<n>) dest<n-1>,
(f<0>) dest<7>
FFh f
Operation:
Status Affected:
None
Status Affected:
N, Z
Encoding:
0100
Description:
RRNCF
00da
f [,d [,a]
Encoding:
ffff
ffff
Words:
Cycles:
100a
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
register f
Process
Data
Write
register f
SETF
REG,1
Before Instruction
Q Cycle Activity:
Q1
Decode
0110
f [,a]
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
RRNCF
REG
0x5A
0xFF
After Instruction
REG
REG, 1, 0
Before Instruction
REG
1101 0111
After Instruction
REG
Example 2:
1110 1011
RRNCF
REG, 0, 0
Before Instruction
W
REG
=
=
?
1101 0111
After Instruction
W
REG
=
=
1110 1011
1101 0111
DS39609B-page 293
PIC18F6520/8520/6620/8620/6720/8720
SLEEP
SUBFWB
Syntax:
[ label ] SLEEP
Syntax:
[ label ] SUBFWB
Operands:
None
Operands:
Operation:
00h WDT,
0 WDT postscaler,
1 TO,
0 PD
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Status Affected:
TO, PD
Encoding:
0000
Description:
Encoding:
0000
0000
0011
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
No
operation
Process
Data
Go to
Sleep
Example:
SLEEP
After Instruction
TO =
PD =
1
0
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Before Instruction
?
?
01da
Description:
Words:
TO =
PD =
0101
f [,d [,a]
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
SUBFWB
REG, 1, 0
Before Instruction
REG
W
C
=
=
=
3
2
1
After Instruction
REG
W
C
Z
N
=
=
=
=
=
Example 2:
FF
2
0
0
1 ; result is negative
SUBFWB
REG, 0, 0
Before Instruction
REG
W
C
=
=
=
2
5
1
After Instruction
REG
W
C
Z
N
=
=
=
=
=
Example 3:
2
3
1
0
0
; result is positive
SUBFWB
REG, 1, 0
Before Instruction
REG
W
C
=
=
=
1
2
0
After Instruction
REG
W
C
Z
N
DS39609B-page 294
=
=
=
=
=
0
2
1
1
0
; result is zero
PIC18F6520/8520/6620/8620/6720/8720
SUBLW
SUBWF
Subtract W from f
Syntax:
[ label ] SUBLW k
Syntax:
[ label ] SUBWF
Operands:
0 k 255
Operands:
Operation:
k (W) W
Status Affected:
N, OV, C, DC, Z
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, OV, C, DC, Z
Encoding:
0000
1000
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
Example 1:
SUBLW
0x02
Before Instruction
W
C
=
=
1
?
=
=
=
=
Example 2:
1
1
0
0
SUBLW
; result is positive
0x02
=
=
0
1
1
0
SUBLW
; result is zero
0x02
Before Instruction
W
C
=
=
=
=
=
=
Words:
Cycles:
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
SUBWF
REG, 1, 0
Example 1:
=
=
=
3
2
?
FF
0
0
1
REG
W
C
Z
N
=
=
=
=
=
Example 2:
1
2
1
0
0
; result is positive
SUBWF
REG, 0, 0
Before Instruction
3
?
REG
W
C
After Instruction
W
C
Z
N
ffff
After Instruction
=
=
=
=
Example 3:
ffff
Description:
REG
W
C
2
?
After Instruction
W
C
Z
N
11da
Before Instruction
Before Instruction
W
C
0101
Q Cycle Activity:
Q1
After Instruction
W
C
Z
N
Encoding:
f [,d [,a]
; (2s complement)
; result is negative
=
=
=
2
2
?
After Instruction
REG
W
C
Z
N
=
=
=
=
=
Example 3:
2
0
1
1
0
SUBWF
; result is zero
REG, 1, 0
Before Instruction
REG
W
C
=
=
=
1
2
?
After Instruction
REG
W
C
Z
N
=
=
=
=
=
DS39609B-page 295
PIC18F6520/8520/6620/8620/6720/8720
SUBWFB
SWAPF
Swap f
Syntax:
[ label ] SUBWFB
Syntax:
Operands:
0 f 255
d [0,1]
a [0,1]
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Operation:
Status Affected:
N, OV, C, DC, Z
(f<3:0>) dest<7:4>,
(f<7:4>) dest<3:0>
Status Affected:
None
Encoding:
Description:
0101
10da
f [,d [,a]
ffff
ffff
Encoding:
0011
Words:
Cycles:
Cycles:
Decode
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
SUBWFB
REG, 1, 0
Before Instruction
REG
W
C
=
=
=
0x19
0x0D
1
(0001 1001)
(0000 1101)
0x0C
0x0D
1
0
0
(0000 1011)
(0000 1101)
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
SWAPF
REG, 1, 0
Before Instruction
REG
REG
=
=
=
=
=
Example 2:
Q Cycle Activity:
Q1
0x53
After Instruction
After Instruction
REG
W
C
Z
N
ffff
Q2
ffff
Description:
Words:
Q Cycle Activity:
Q1
10da
0x35
; result is positive
SUBWFB REG, 0, 0
Before Instruction
REG
W
C
=
=
=
0x1B
0x1A
0
(0001 1011)
(0001 1010)
0x1B
0x00
1
1
0
(0001 1011)
After Instruction
REG
W
C
Z
N
=
=
=
=
=
Example 3:
SUBWFB
; result is zero
REG, 1, 0
Before Instruction
REG
W
C
=
=
=
0x03
0x0E
1
(0000 0011)
(0000 1101)
(1111 0100)
; [2s comp]
(0000 1101)
After Instruction
REG
0xF5
W
C
Z
N
=
=
=
=
0x0E
0
0
1
DS39609B-page 296
; result is negative
PIC18F6520/8520/6620/8620/6720/8720
TBLRD
Table Read
TBLRD
Syntax:
[ label ]
Example 1:
TBLRD
Operands:
None
Operation:
if TBLRD *,
(Prog Mem (TBLPTR)) TABLAT;
TBLPTR No Change;
if TBLRD *+,
(Prog Mem (TBLPTR)) TABLAT;
(TBLPTR) + 1 TBLPTR;
if TBLRD *-,
(Prog Mem (TBLPTR)) TABLAT;
(TBLPTR) 1 TBLPTR;
if TBLRD +*,
(TBLPTR) + 1 TBLPTR;
(Prog Mem (TBLPTR)) TABLAT;
Before Instruction
Status Affected:None
Encoding:
Description:
0000
*+ ;
0000
0000
10nn
nn=0 *
=1 *+
=2 *=3 +*
TABLAT
TBLPTR
MEMORY(0x00A356)
=
=
=
0x55
0x00A356
0x34
=
=
0x34
0x00A357
After Instruction
TABLAT
TBLPTR
Example 2:
TBLRD
+* ;
Before Instruction
TABLAT
TBLPTR
MEMORY(0x01A357)
MEMORY(0x01A358)
=
=
=
=
0xAA
0x01A357
0x12
0x34
=
=
0x34
0x01A358
After Instruction
TABLAT
TBLPTR
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
No
operation
No operation
(Read Program
Memory)
No
No operation
operation (Write TABLAT)
DS39609B-page 297
PIC18F6520/8520/6620/8620/6720/8720
TBLWT
Table Write
Syntax:
Words: 1
Operands:
None
Cycles: 2
Operation:
if TBLWT*,
(TABLAT) Holding Register;
TBLPTR No Change;
if TBLWT*+,
(TABLAT) Holding Register;
(TBLPTR) + 1 TBLPTR;
if TBLWT*-,
(TABLAT) Holding Register;
(TBLPTR) 1 TBLPTR;
if TBLWT+*,
(TBLPTR) + 1 TBLPTR;
(TABLAT) Holding Register;
Q Cycle Activity:
Description:
0000
0000
0000
11nn
nn=0 *
=1 *+
=2 *=3 +*
DS39609B-page 298
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
No
operation
No
operation
(Read
TABLAT)
No
operation
No
operation
(Write to
Holding
Register )
Example 1:
Q1
TBLWT
*+;
Before Instruction
TABLAT
TBLPTR
HOLDING REGISTER
(0x00A356)
=
=
0x55
0x00A356
0xFF
Example 2:
TBLWT
=
=
0x55
0x00A357
0x55
+*;
Before Instruction
TABLAT
TBLPTR
HOLDING REGISTER
(0x01389A)
HOLDING REGISTER
(0x01389B)
=
=
0x34
0x01389A
0xFF
0xFF
=
=
0x34
0x01389B
0xFF
0x34
PIC18F6520/8520/6620/8620/6720/8720
TSTFSZ
Test f, skip if 0
XORLW
Syntax:
Syntax:
[ label ] XORLW k
Operands:
0 f 255
a [0,1]
Operands:
0 k 255
Operation:
Operation:
skip if f = 0
(W) .XOR. k W
Status Affected:
N, Z
Status Affected:
None
Encoding:
Description:
Encoding:
0110
011a
ffff
ffff
Words:
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
No
operation
0000
1010
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
Example:
XORLW 0xAF
Before Instruction
W
0xB5
After Instruction
W
0x1A
If skip:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Example:
HERE
NZERO
ZERO
TSTFSZ
:
:
CNT, 1
Before Instruction
PC
Address (HERE)
=
=
0x00,
Address (ZERO)
0x00,
Address (NZERO)
After Instruction
If CNT
PC
If CNT
PC
DS39609B-page 299
PIC18F6520/8520/6620/8620/6720/8720
XORWF
Exclusive OR W with f
Syntax:
[ label ] XORWF
Operands:
0 f 255
d [0,1]
a [0,1]
Operation:
Status Affected:
N, Z
Encoding:
0001
10da
f [,d [,a]
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
XORWF
REG, 1, 0
Before Instruction
REG
W
=
=
0xAF
0xB5
After Instruction
REG
W
=
=
DS39609B-page 300
0x1A
0xB5
PIC18F6520/8520/6620/8620/6720/8720
25.0
DEVELOPMENT SUPPORT
25.1
25.2
MPASM Assembler
DS39609B-page 301
PIC18F6520/8520/6620/8620/6720/8720
25.3
25.4
25.5
DS39609B-page 302
25.6
25.7
The MPLAB SIM software simulator allows code development in a PC hosted environment by simulating the
PICmicro series microcontrollers on an instruction
level. On any given instruction, the data areas can be
examined or modified and stimuli can be applied from
a file, or user defined key press, to any pin. The execution can be performed in Single-Step, Execute Until
Break or Trace mode.
The MPLAB SIM simulator fully supports symbolic
debugging using the MPLAB C17 and MPLAB C18
C Compilers, as well as the MPASM assembler. The
software simulator offers the flexibility to develop and
debug code outside of the laboratory environment,
making it an excellent, economical software
development tool.
25.8
PIC18F6520/8520/6620/8620/6720/8720
25.9
DS39609B-page 303
PIC18F6520/8520/6620/8620/6720/8720
25.14 PICSTART Plus Development
Programmer
DS39609B-page 304
PIC18F6520/8520/6620/8620/6720/8720
25.20 PICDEM 17 Demonstration Board
The PICDEM 17 demonstration board is an evaluation
board that demonstrates the capabilities of several
Microchip microcontrollers, including PIC17C752,
PIC17C756A, PIC17C762 and PIC17C766. A programmed sample is included. The PRO MATE II device
programmer, or the PICSTART Plus development programmer, can be used to reprogram the device for user
tailored application development. The PICDEM 17
demonstration board supports program download and
execution from external on-board Flash memory. A
generous prototype area is available for user hardware
expansion.
DS39609B-page 305
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 306
PIC18F6520/8520/6620/8620/6720/8720
26.0
ELECTRICAL CHARACTERISTICS
NOTICE: Stresses above those listed under Absolute Maximum Ratings may cause permanent damage to the
device. This is a stress rating only and functional operation of the device at those or any other conditions above those
indicated in the operation listings of this specification is not implied. Exposure to maximum rating conditions for
extended periods may affect device reliability.
DS39609B-page 307
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-1:
Voltage
5.0V
PIC18FX520
4.5V
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
FMAX (Extended)
FMAX
Frequency
FMAX = 40 MHz for PIC18F6520/8520 in Microcontroller mode.
FMAX (Extended) = 25 MHz for PIC18F6520/8520 in modes other than Microcontroller mode.
FIGURE 26-2:
Voltage
5.0V
PIC18LFX520
4.5V
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
FMAX
4 MHz
Frequency
For PIC18F6520/8520 in Microcontroller mode:
FMAX = (16.36 MHz/V) (VDDAPPMIN 2.0V) + 4 MHz, if VDDAPPMIN 4.2V;
FMAX = 40 MHz, if VDDAPPMIN > 4.2V.
For PIC18F8X8X in modes other than Microcontroller mode:
FMAX = (9.55 MHz/V) (VDDAPPMIN 2.0V) + 4 MHz, if VDDAPPMIN 4.2V;
FMAX = 25 MHz, if VDDAPPMIN > 4.2V.
Note: VDDAPPMIN is the minimum voltage of the Picmicro device in the application.
DS39609B-page 308
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-3:
Voltage
5.0V
PIC18FX620/X720
4.5V
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
FMAX (Extended)
FMAX
Frequency
FMAX = 25 MHz in Microcontroller mode.
FMAX (Extended) = 16 MHz for PIC18F6520/8520 in modes other than Microcontroller mode.
FIGURE 26-4:
Voltage
5.0V
4.5V
PIC18LFX620/X720
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
FMAX
4 MHz
Frequency
In Microcontroller mode:
FMAX = (9.55 MHz/V) (VDDAPPMIN 2.0V) + 4 MHz, if VDDAPPMIN 4.2V;
FMAX = 25 MHz, if VDDAPPMIN > 4.2V.
In modes other than Microcontroller mode:
FMAX = (5.45 MHz/V) (VDDAPPMIN 2.0V) + 4 MHz, if VDDAPPMIN 4.2V;
FMAX = 16 MHz, if VDDAPPMIN > 4.2V.
Note: VDDAPPMIN is the minimum voltage of the Picmicro device in the application.
DS39609B-page 309
PIC18F6520/8520/6620/8620/6720/8720
26.1
PIC18LF6520/8520/6620/8620/6720/8720
(Industrial)
PIC18F6520/8520/6620/8620/6720/8720
(Industrial, Extended)
Param
Symbol
No.
D001
VDD
Characteristic
Min
Typ
Max
Units
PIC18LFXX20
2.0
5.5
PIC18FXX20
4.2
5.5
Supply Voltage
D001A AVDD
VDD 0.3
VDD + 0.3
D002
VDR
1.5
D003
VPOR
0.7
D004
SVDD
0.05
D005
VBOR
N/A
N/A
Legend:
Note 1:
Conditions
BORV1:BORV0 = 10
2.64
2.92
BORV1:BORV0 = 01
4.11
4.55
BORV1:BORV0 = 00
4.41
4.87
Reserved
DS39609B-page 310
PIC18F6520/8520/6620/8620/6720/8720
26.2
Device
Max
Units
Conditions
0.2
-40C
0.2
+25C
+85C
PIC18LFXX20
All devices
Legend:
Note 1:
2:
3:
1.2
0.4
-40C
0.4
+25C
1.8
+85C
0.7
-40C
0.7
+25C
3.0
15
+85C
VDD = 2.0V,
(Sleep mode)
VDD = 3.0V,
(Sleep mode)
VDD = 5.0V,
(Sleep mode)
DS39609B-page 311
PIC18F6520/8520/6620/8620/6720/8720
26.2
Device
Max
Units
Conditions
PIC18LFXX20
All devices
PIC18LFXX20
2:
3:
350
-40C
165
350
+25C
+85C
170
350
360
750
-40C
340
750
+25C
300
750
+85C
800
1700
-40C
730
1700
+25C
700
1700
+85C
600
1200
-40C
600
1200
+25C
640
1300
+85C
PIC18LFXX20 1000
2500
-40C
1000
2500
+25C
1000
2500
+85C
2.2
5.0
mA
-40C
2.1
5.0
mA
+25C
2.0
5.0
mA
+85C
All devices
Legend:
Note 1:
165
VDD = 2.0V
VDD = 3.0V
FOSC = 1 MHZ,
EC oscillator
VDD = 5.0V
VDD = 2.0V
VDD = 3.0V
FOSC = 4 MHz,
EC oscillator
VDD = 5.0V
DS39609B-page 312
PIC18F6520/8520/6620/8620/6720/8720
26.2
Device
Max
Units
Conditions
9.3
15
mA
-40C
9.5
15
mA
+25C
10
15
mA
+85C
11.8
20
mA
-40C
12
20
mA
+25C
12
20
mA
+85C
16
20
mA
-40C
16
20
mA
+25C
16
20
mA
+85C
19
25
mA
-40C
19
25
mA
+25C
19
25
mA
+85C
PIC18FX620/X720
15
55
-40C to +85C
VDD = 2.0V
PIC18LF8520
13
18
-40C to +85C
VDD = 2.0V
20
35
-40C to +85C
VDD = 3.0V
50
85
-40C to +85C
VDD = 5.0V
200
-40C to +85C
VDD = 4.2V
250
-40C to +125C
VDD = 4.2V
PIC18FX620, PIC18FX720
PIC18FX520
PIC18FX520
D014
PIC18FXX20
Legend:
Note 1:
2:
3:
VDD = 4.2V
FOSC = 25 MHZ,
EC oscillator
VDD = 5.0V
VDD = 4.2V
FOSC = 40 MHZ,
EC oscillator
VDD = 5.0V
FOSC = 32 kHz,
Timer1 as clock
FOSC = 32 kHz,
Timer1 as clock
FOSC = 32 kHz,
Timer1 as clock
DS39609B-page 313
PIC18F6520/8520/6620/8620/6720/8720
26.2
Device
Max
Units
Conditions
D022
(IWDT)
<1
+85C
VDD = 2.0V
-40C
+25C
15
+85C
15
25
-40C
12
20
+25C
12
40
+85C
35
50
-40C to +85C
VDD = 3.0V
45
65
-40C to +85C
VDD = 5.0V
33
45
-40C to +85C
VDD = 2.0V
35
50
-40C to +85C
VDD = 3.0V
45
65
-40C to +85C
Timer1 Oscillator
5.2
30
+25C
VDD = 2.0V
PIC18LF8720/8620
5.2
40
-40C to +85C
VDD = 2.0V
6.5
50
-40C to +125C
VDD = 4.2V
6.5
40
+25C
6.5
50
-40C to +85C
-40C to +125C
PIC18F8520/8620/8720
PIC18LF8520
A/D Converter
3:
+25C
Low-Voltage Detect
2:
-40C
10
D022B
(ILVD)
Legend:
Note 1:
1.5
Brown-out Reset
D026
(IAD)
2.0
<1
2.5
D022A
(IBOR)
D025
(IOSCB)
<1
VDD = 3.0V
VDD = 5.0V
VDD = 5.0V
VDD = 4.2V
6.5
65
1.8
2.2
+25C
VDD = 2.0V
2.9
3.8
-40C to +85C
VDD = 3.0V
3.4
7.0
-40C to +125C
VDD = 5.0V
<1
+25C
VDD = 2.0V
<1
+25C
VDD = 3.0V
<1
+25C
VDD = 5.0V
32 kHz on Timer1
32 kHz on Timer1
32 kHz on Timer1
DS39609B-page 314
PIC18F6520/8520/6620/8620/6720/8720
26.3
DC CHARACTERISTICS
Param
Sym
No.
VIL
Characteristic
Min
Max
Units
Conditions
VSS
0.15 VDD
0.8
VSS
VSS
0.2 VDD
0.3 VDD
V
V
D030
D030A
D031
D032
MCLR
VSS
0.2 VDD
D032A
VSS
0.2 VDD
D033
VSS
0.2 VDD
VDD
VIH
D040
D040A
D041
D042
D042A
D043
IIL
2.0
VDD
0.8 VDD
0.7 VDD
VDD
VDD
V
V
0.8 VDD
VDD
1.6
VDD
0.9 VDD
VDD
Current(2,3)
VSS VPIN VDD,
Pin at high-impedance
D060
I/O ports
D061
MCLR
D063
OSC1
50
400
IPU
D070
Note 1:
2:
3:
4:
In RC oscillator configuration, the OSC1/CLKI pin is a Schmitt Trigger input. It is not recommended that the
PICmicro device be driven with an external clock while in RC mode.
The leakage current on the MCLR pin is strongly dependent on the applied voltage level. The specified
levels represent normal operating conditions. Higher leakage current may be measured at different input
voltages.
Negative current is defined as current sourced by the pin.
Parameter is characterized but not tested.
DS39609B-page 315
PIC18F6520/8520/6620/8620/6720/8720
26.3
DC CHARACTERISTICS
Param
Sym
No.
Min
Max
Units
0.6
0.6
0.6
0.6
VDD 0.7
VDD 0.7
VDD 0.7
VDD 0.7
8.5
RA4 pin
15
pF
D101
CIO
50
pF
D102
CB
SCL, SDA
400
pF
In I2C mode
VOL
D080
Characteristic
Output Low Voltage
I/O ports
D080A
D083
OSC2/CLKO
(RC mode)
D083A
VOH
D090
D090A
D092
OSC2/CLKO
(RC mode)
D092A
D150
VOD
Conditions
Note 1:
2:
3:
4:
In RC oscillator configuration, the OSC1/CLKI pin is a Schmitt Trigger input. It is not recommended that the
PICmicro device be driven with an external clock while in RC mode.
The leakage current on the MCLR pin is strongly dependent on the applied voltage level. The specified
levels represent normal operating conditions. Higher leakage current may be measured at different input
voltages.
Negative current is defined as current sourced by the pin.
Parameter is characterized but not tested.
DS39609B-page 316
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-1:
COMPARATOR SPECIFICATIONS
Operating Conditions: 3.0V < VDD < 5.5V, -40C < TA < +125C (unless otherwise stated).
Param
No.
Sym
Characteristics
Min
Typ
Max
Units
D300
VIOFF
5.0
10
mV
D301
VICM
VDD 1.5
D302
CMRR
55
dB
300
300A
TRESP
Response Time(1)
150
400
600
ns
ns
301
TMC2OV
10
Note 1:
Comments
PIC18FXX20
PIC18LFXX20
Response time measured with one comparator input at (VDD 1.5)/2, while the other input transitions from
VSS to VDD.
TABLE 26-2:
Operating Conditions: 3.0V < VDD < 5.5V, -40C < TA < +125C (unless otherwise stated).
Param
No.
Sym
Characteristics
Min
Typ
Max
Units
D310
VRES
Resolution
VDD/24
VDD/32
LSb
D311
VRAA
Absolute Accuracy
1/4
1/2
LSb
LSb
D312
VRUR
2k
TSET
Time(1)
10
310
Note 1:
Settling
Comments
Settling time measured while VRR = 1 and VR<3:0> transitions from 0000 to 1111.
DS39609B-page 317
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-5:
VLVD
(LVDIF set by hardware)
LVDIF
TABLE 26-3:
D423
Characteristic
LVD Voltage on VDD
Transition high-to-low
VBG
Min
Typ
Max
Units
LVV = 0001
1.96
2.06
2.16
LVV = 0010
2.16
2.27
2.38
LVV = 0011
2.35
2.47
2.59
LVV = 0100
2.45
2.58
2.71
LVV = 0101
2.64
2.78
2.92
LVV = 0110
2.75
2.89
3.03
LVV = 0111
2.95
3.1
3.26
LVV = 1000
3.24
3.41
3.58
LVV = 1001
3.43
3.61
3.79
LVV = 1010
3.53
3.72
3.91
LVV = 1011
3.72
3.92
4.12
LVV = 1100
3.92
4.13
4.34
LVV = 1101
4.11
4.33
4.55
LVV = 1110
4.41
4.64
4.87
1.22
Conditions
Production tested at TAMB = 25C. Specifications over temperature limits ensured by characterization.
DS39609B-page 318
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-4:
DC Characteristics
Param
No.
Sym
Characteristic
Min
Typ
Max
Units
13.25
Conditions
9.00
D112
IPP
D113
IDDP
10
mA
D110
(Note 2)
Cell Endurance
100K
1M
D120A ED
Cell Endurance
10K
100K
D121
VDRW
VMIN
5.5
D122
TDEW
D123
40
100
D120
ms
Cell Endurance
10K
100K
D130A EP
Cell Endurance
1000
10K
D131
VPR
VMIN
5.5
D132
VIE
4.5
5.5
D132A VIW
4.5
5.5
D132B VPEW
VMIN
5.5
D133
ms
D133A TIW
ms
D133A TIW
D130
TIE
2.5
40
100
D134
ms
Data in Typ column is at 5.0V, 25C unless otherwise stated. These parameters are for design guidance
only and are not tested.
Note 1: These specifications are for programming the on-chip program memory through the use of table write
instructions.
2: The pin may be kept in this range at times other than programming, but it is not recommended.
3: Retention time is valid, provided no other specifications are violated.
DS39609B-page 319
PIC18F6520/8520/6620/8620/6720/8720
26.4
26.4.1
AC (Timing) Characteristics
TIMING PARAMETER SYMBOLOGY
DS39609B-page 320
3. TCC:ST
4. Ts
Time
osc
rd
rw
sc
ss
t0
t1
wr
OSC1
RD
RD or WR
SCK
SS
T0CKI
T1CKI
WR
P
R
V
Z
Period
Rise
Valid
High-Impedance
High
Low
High
Low
SU
Setup
STO
Stop condition
PIC18F6520/8520/6620/8620/6720/8720
26.4.2
TIMING CONDITIONS
TABLE 26-5:
AC CHARACTERISTICS
FIGURE 26-6:
Load condition 2
VDD/2
RL
CL
Pin
VSS
CL
Pin
RL = 464
VSS
CL = 50 pF
DS39609B-page 321
PIC18F6520/8520/6620/8620/6720/8720
26.4.3
FIGURE 26-7:
Q1
Q2
Q3
Q4
Q1
OSC1
1
2
CLKO
TABLE 26-6:
Param
No.
1A
Symbol
FOSC
Characteristic
Min
Max
Units
DC
25
MHz
DC
40
MHz
DC
25
MHz
DC
MHz
RC oscillator
0.1
MHz
XT oscillator
25
MHz
HS oscillator
10
MHz
6.25
MHz
6.25
MHz
33
kHz
LP Oscillator mode
40
ns
25
ns
40
ns
250
ns
RC oscillator
250
10,000
ns
XT oscillator
40
250
ns
HS oscillator
100
250
ns
160
250
ns
30
200
LP oscillator
100
ns
TCY = 4/FOSC
30
ns
XT oscillator
2.5
LP oscillator
10
ns
HS oscillator
20
ns
XT oscillator
50
ns
LP oscillator
7.5
ns
HS oscillator
Oscillator Frequency(1)
TOSC
Oscillator Period(1)
(1)
TCY
TOSL,
TOSH
TOSR,
TOSF
Note 1:
Conditions
Instruction cycle period (TCY) equals four times the input oscillator time base period for all configurations except PLL. All
specified values are based on characterization data for that particular oscillator type under standard operating conditions
with the device executing code. Exceeding these specified limits may result in an unstable oscillator operation and/or
higher than expected current consumption. All devices are tested to operate at min. values with an external clock applied
to the OSC1/CLKI pin. When an external clock input is used, the max. cycle time limit is DC (no clock) for all devices.
DS39609B-page 322
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-7:
Param
No.
Sym
Min
Typ
Max
Units
Conditions
FOSC
10
MHz
HS mode
FSYS
16
40
MHz
HS mode
trc
ms
CLK
-2
+2
Data in Typ column is at 5V, 25C, unless otherwise stated. These parameters are for design guidance
only and are not tested.
FIGURE 26-8:
Q4
Q2
Q3
OSC1
11
10
CLKO
13
12
14
19
18
16
I/O pin
(Input)
15
17
I/O pin
(Output)
New Value
Old Value
20, 21
Note:
DS39609B-page 323
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-8:
Param
No.
Symbol
Characteristic
Min
Typ
Max
Units
Conditions
(Note 1)
10
TOSH2CKL
OSC1 to CLKO
75
200
ns
11
TOSH2CKH
OSC1 to CLKO
75
200
ns
(Note 1)
12
TCKR
35
100
ns
(Note 1)
13
TCKF
35
100
ns
(Note 1)
14
TCKL2IOV
0.5 TCY + 20
ns
(Note 1)
15
TIOV2CKH
0.25 TCY + 25
ns
(Note 1)
16
TCKH2IOI
ns
(Note 1)
17
TOSH2IOV
50
150
ns
18
TOSH2IOI
100
ns
200
ns
18A
19
TIOV2OSH
ns
20
TIOR
PIC18FXX20
10
25
ns
PIC18LFXX20
60
ns
TIOF
PIC18FXX20
10
25
ns
60
ns
22
TINP
TCY
ns
23
TRBP
TCY
ns
24
TRCP
20
ns
20A
21
21A
PIC18LFXX20
Note 1:
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
These parameters are asynchronous events not related to any internal clock edges.
Measurements are taken in RC mode, where CLKO output is 4 x TOSC.
FIGURE 26-9:
Q2
Q3
Q4
Q1
Q2
OSC1(1)
A<19:16>
BA0
Address
AD<15:0>
Address
150
151
Address
Data from External
Address
163
160
162
161
155
166
167
168
ALE
164
169
171
CE
171A
OE
165
Operating Conditions: 2.0V < VCC < 5.5V, -40C < TA < +125C unless otherwise stated.
Note 1: Maximum speed of FOSC is 25 MHz for external program memory read.
DS39609B-page 324
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-9:
Param
No.
Symbol
Characteristics
Min
Typ
Max
Units
0.25 TCY 10
ns
ns
150
151
TALL2ADL
155
TALL2OEL ALE to OE
10
0.125 TCY
ns
160
ns
161
TOEH2ADD OE to AD Driven
0.125 TCY 5
ns
162
20
ns
163
ns
164
0.25 TCY
ns
165
0.5 TCY 5
0.5 TCY
ns
166
TCY
ns
167
TACC
0.75 TCY 25
ns
168
TOE
OE to Data Valid
0.5 TCY 25
ns
0.625 TCY 10
0.625 TCY + 10
ns
10
ns
0.25 TCY 20
ns
169
TALL2OEH ALE to OE
171
171A
FIGURE 26-10:
Q2
Q3
Q4
Q1
Q2
OSC1(1)
A<19:16>
BA0
Address
Address
166
Data
Address
AD<15:0>
Address
153
150
156
151
ALE
171
CE
171A
154
WRH or
WRL
UB or
LB
157
157A
Operating Conditions: 2.0V < VCC < 5.5V, -40C < TA < +125C unless otherwise stated.
Note 1: Maximum speed of FOSC is 25 MHz for external program memory read.
DS39609B-page 325
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-10: PROGRAM MEMORY WRITE TIMING REQUIREMENTS
Param
No.
Symbol
Characteristics
Min
Typ
Max
Units
150
TADV2ALL
0.25 TCY 10
ns
151
TALL2ADL
ns
153
ns
154
TWRL
156
157
0.5 TCY 5
0.5 TCY
ns
0.5 TCY 10
ns
0.25 TCY
ns
157A
TWRH2BSI
WRn to Byte Select Invalid (byte select hold time) 0.125 TCY 5
166
TALH2ALH
171
171A
TUBL2OEH
FIGURE 26-11:
ns
TCY
ns
10
ns
0.25 TCY 20
ns
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
34
31
34
I/O Pins
Note:
DS39609B-page 326
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-12:
VDD
35
VBGAP = 1.2V
VIRVST
Enable Internal
Reference Voltage
Internal Reference
Voltage Stable
36
TABLE 26-11: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER
AND BROWN-OUT RESET REQUIREMENTS
Param
Symbol
No.
Characteristic
Min
Typ
Max
Units
30
TMCL
31
TWDT
18
33
ms
32
TOST
1024 TOSC
1024 TOSC
33
TPWRT
28
72
132
ms
34
TIOZ
35
TBOR
200
36
TIVRST
20
50
37
TLVD
200
FIGURE 26-13:
Conditions
VDD VLVD
T0CKI
41
40
42
T1OSO/T13CKI
46
45
47
48
TMR0 or
TMR1
Note:
DS39609B-page 327
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-12: TIMER0 AND TIMER1 EXTERNAL CLOCK REQUIREMENTS
Param
Symbol
No.
Characteristic
40
TT0H
No prescaler
41
TT0L
No prescaler
42
TT0P
T0CKI Period
Min
Max
Units
0.5 TCY + 20
ns
With prescaler
10
ns
0.5 TCY + 20
ns
With prescaler
No prescaler
With prescaler
45
TT1H
T13CKI
High Time
Synchronous, no prescaler
10
ns
TCY + 10
ns
Greater of:
20 ns or TCY + 40
N
ns
0.5 TCY + 20
ns
Synchronous, PIC18FXX20
with prescaler PIC18LFXX20
10
ns
25
ns
Asynchronous PIC18FXX20
30
ns
PIC18LFXX20
46
TT1L
T13CKI
Low Time
Synchronous, no prescaler
50
ns
0.5 TCY + 5
ns
10
ns
25
ns
Synchronous, PIC18FXX20
with prescaler PIC18LFXX20
Asynchronous PIC18FXX20
30
ns
TBD
TBD
ns
Greater of:
20 ns or TCY + 40
N
ns
PIC18LFXX20
47
48
TT1P
T13CKI
Synchronous
Input Period
Asynchronous
60
ns
FT1
DC
50
kHz
2 TOSC
7 TOSC
FIGURE 26-14:
Conditions
N = prescale
value
(1, 2, 4,..., 256)
N = prescale
value (1, 2, 4, 8)
50
51
52
CCPx
(Compare or PWM Mode)
53
Note:
54
DS39609B-page 328
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-13: CAPTURE/COMPARE/PWM REQUIREMENTS (ALL CCP MODULES)
Param
Symbol
No.
50
51
TCCL
Characteristic
CCPx Input Low
Time
TCCH
No prescaler
With
prescaler
Max
Units
0.5 TCY + 20
ns
PIC18FXX20
10
ns
PIC18LFXX20
20
ns
0.5 TCY + 20
ns
10
ns
No prescaler
With
prescaler
Min
PIC18FXX20
PIC18LFXX20
20
ns
3 TCY + 40
N
ns
25
ns
52
TCCP
53
TCCR
PIC18FXX20
PIC18LFXX20
45
ns
54
TCCF
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
FIGURE 26-15:
Conditions
N = prescale
value (1, 4 or 16)
VDD = 2.0V
VDD = 2.0V
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
64
62
63
Note:
DS39609B-page 329
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-14: PARALLEL SLAVE PORT REQUIREMENTS (PIC18F8X20)
Param
No.
62
Symbol
TDTV2WRH
TWRH2DTI
63
64
TRDL2DTV
Characteristic
Min
Max
Units
Conditions
20
25
ns
ns
WR or CS to DataIn
Invalid (hold time)
PIC18FXX20
20
ns
PIC18LFXX20
35
ns
VDD = 2.0V
80
90
ns
ns
ns
65
TRDH2DTI
RD or CS to DataOut Invalid
10
30
66
TIBFINH
3 TCY
FIGURE 26-16:
SS
70
SCK
(CKP = 0)
71
72
78
79
79
78
SCK
(CKP = 1)
80
bit 6 - - - - - -1
MSb
SDO
LSb
75, 76
SDI
MSb In
bit 6 - - - -1
LSb In
74
73
Note:
DS39609B-page 330
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-15: EXAMPLE SPI MODE REQUIREMENTS (MASTER MODE, CKE = 0)
Param
No.
Symbol
Characteristic
70
71
TSCH
71A
TSCL
72
72A
Min
TCY
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
100
ns
1.5 TCY + 40
ns
100
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
25
ns
25
ns
73
73A
TB2B
74
TSCH2DIL,
(Note 1)
(Note 1)
(Note 2)
TSCL2DIL
75
TDOR
76
TDOF
78
TSCR
79
TSCF
80
Note 1:
2:
PIC18FXX20
PIC18LFXX20
45
ns
25
ns
PIC18FXX20
50
ns
PIC18LFXX20
100
ns
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
FIGURE 26-17:
SS
81
SCK
(CKP = 0)
71
72
79
73
SCK
(CKP = 1)
80
78
SDO
bit 6 - - - - - -1
MSb
LSb
75, 76
SDI
MSb In
bit 6 - - - -1
LSb In
74
Note:
DS39609B-page 331
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-16: EXAMPLE SPI MODE REQUIREMENTS (MASTER MODE, CKE = 1)
Param
No.
71
Symbol
TSCH
TSCL
71A
72
Characteristic
72A
Min
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
40
ns
100
ns
ns
100
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
25
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
Single Byte
73
73A
TB2B
74
75
TDOR
Last Clock Edge of Byte 1 to the 1st Clock Edge of Byte 2 1.5 TCY + 40
76
TDOF
78
TSCR
79
TSCF
25
ns
80
50
ns
100
ns
TCY
ns
81
Note 1:
2:
(Note 1)
(Note 1)
(Note 2)
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
FIGURE 26-18:
SS
70
SCK
(CKP = 0)
83
71
72
78
79
79
78
SCK
(CKP = 1)
80
MSb
SDO
bit 6 - - - - - -1
LSb
77
75, 76
SDI
MSb In
bit 6 - - - -1
LSb In
74
73
Note:
DS39609B-page 332
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-17: EXAMPLE SPI MODE REQUIREMENTS (SLAVE MODE TIMING, CKE = 0)
Param
No.
Symbol
Characteristic
70
71
TSCH
71A
TSCL
72
72A
Min
TCY
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
100
ns
73
73A
TB2B
Last Clock Edge of Byte 1 to the First Clock Edge of Byte 2 1.5 TCY + 40
ns
74
TSCH2DIL,
100
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
25
ns
(Note 1)
(Note 1)
(Note 2)
TSCL2DIL
75
TDOR
76
TDOF
77
78
TSCR
10
50
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
25
ns
79
TSCF
80
83
50
ns
100
ns
1.5 TCY + 40
ns
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
FIGURE 26-19:
SS
SCK
(CKP = 0)
70
83
71
72
SCK
(CKP = 1)
80
MSb
SDO
bit 6 - - - - - -1
LSb
75, 76
SDI
MSb In
77
bit 6 - - - -1
LSb In
74
Note:
DS39609B-page 333
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-18: EXAMPLE SPI SLAVE MODE REQUIREMENTS (CKE = 1)
Param
No.
Symbol
Characteristic
70
71
TSCH
71A
TSCL
72
72A
Min
TCY
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
40
ns
(Note 1)
(Note 2)
73A
TB2B
74
Last Clock Edge of Byte 1 to the First Clock Edge of Byte 2 1.5 TCY + 40
75
TDOR
ns
100
ns
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
25
ns
10
50
ns
76
TDOF
77
78
TSCR
PIC18FXX20
25
ns
PIC18LFXX20
45
ns
79
TSCF
25
ns
80
PIC18FXX20
50
ns
PIC18LFXX20
100
ns
PIC18FXX20
50
ns
PIC18LFXX20
100
ns
1.5 TCY + 40
ns
82
83
(Note 1)
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
FIGURE 26-20:
SCL
91
90
93
92
SDA
Start
Condition
Note:
Stop
Condition
DS39609B-page 334
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-19: I2C BUS START/STOP BITS REQUIREMENTS (SLAVE MODE)
Param
No.
Symbol
90
TSU:STA
Characteristic
Max
Units
ns
ns
Start Condition
4700
Setup Time
600
Start Condition
4000
Hold Time
600
Stop Condition
4700
91
THD:STA
92
TSU:STO
93
Setup Time
Hold Time
FIGURE 26-21:
Min
600
4000
600
Conditions
ns
ns
102
100
101
SCL
90
106
107
91
92
SDA
In
110
109
109
SDA
Out
Note:
DS39609B-page 335
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-20: I2C BUS DATA REQUIREMENTS (SLAVE MODE)
Param
No.
100
Symbol
THIGH
Characteristic
Clock High Time
TLOW
TR
103
TF
Units
4.0
s
s
4.7
1.3
1.5 TCY
1000
ns
20 + 0.1 CB
300
ns
300
ns
20 + 0.1 CB
300
ns
CB is specified to be from
10 to 400 pF
Only relevant for Repeated
Start condition
TSU:STA
Start Condition
Setup Time
4.7
0.6
91
THD:STA
Start Condition
Hold Time
4.0
0.6
106
THD:DAT
ns
0.9
107
TSU:DAT
250
ns
100
ns
92
TSU:STO
Stop Condition
Setup Time
4.7
0.6
109
TAA
3500
ns
ns
110
TBUF
4.7
1.3
400
pF
CB
Note 1:
2:
CB is specified to be from
10 to 400 pF
90
D102
Conditions
0.6
SSP module
102
Max
1.5 TCY
SSP module
101
Min
(Note 2)
(Note 1)
Time the bus must be free
before a new transmission
can start
As a transmitter, the device must provide this internal minimum delay time to bridge the undefined region
(min. 300 ns) of the falling edge of SCL to avoid unintended generation of Start or Stop conditions.
A fast mode I2C bus device can be used in a standard mode I2C bus system but the requirement,
TSU:DAT 250 ns, must then be met. This will automatically be the case if the device does not stretch the
LOW period of the SCL signal. If such a device does stretch the LOW period of the SCL signal, it must
output the next data bit to the SDA line, TR max. + TSU:DAT = 1000 + 250 = 1250 ns (according to the
standard mode I2C bus specification), before the SCL line is released.
DS39609B-page 336
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-22:
SCL
93
91
90
92
SDA
Stop
Condition
Start
Condition
Note:
91
92
93
TSU:STA
Characteristic
Start Condition
Setup Time
Note 1:
Min
Units
Conditions
ns
ns
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
2(TOSC)(BRG + 1)
1 MHz mode(1)
2(TOSC)(BRG + 1)
FIGURE 26-23:
Max
I2C
ns
ns
pins.
102
100
101
SCL
90
106
91
107
92
SDA
In
109
109
110
SDA
Out
Note:
DS39609B-page 337
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-22: MASTER SSP I2C BUS DATA REQUIREMENTS
Param
Symbol
No.
100
THIGH
Characteristic
Min
Max
Units
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG
+ 1)
ms
mode(1)
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
mode(1)
ms
TLOW
1 MHz
102
103
90
91
106
107
92
TR
TF
TSU:STA
Start Condition
Setup Time
TSU:DAT
Data Input
Setup Time
2(TOSC)(BRG + 1)
1000
ns
20 + 0.1 CB
300
ns
1 MHz mode(1)
300
ns
300
ns
20 + 0.1 CB
300
ns
1 MHz mode(1)
100
ns
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
ns
0.9
ms
1 MHz mode(1)
TBD
ns
250
ns
100
ns
1 MHz mode(1)
TBD
ns
2(TOSC)(BRG + 1)
ms
2(TOSC)(BRG + 1)
ms
mode(1)
2(TOSC)(BRG + 1)
ms
3500
ns
1000
ns
(1)
ns
4.7
ms
1 MHz
109
TAA
Output Valid
from Clock
1 MHz mode
110
D102
Note 1:
2:
TBUF
CB
1.3
ms
1 MHz mode(1)
TBD
ms
400
pF
Conditions
CB is specified to be from
10 to 400 pF
CB is specified to be from
10 to 400 pF
(Note 2)
DS39609B-page 338
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 26-24:
RC6/TX1/CK1
pin
121
121
RC7/RX1/DT1
pin
120
Note:
122
Symbol
Characteristic
120
121
TCKRF
122
TDTRF
FIGURE 26-25:
Min
Max
Units
PIC18FXX20
40
ns
PIC18LFXX20
100
ns
PIC18FXX20
20
ns
PIC18LFXX20
50
ns
PIC18FXX20
20
ns
PIC18LFXX20
50
ns
Conditions
VDD = 2.0V
VDD = 2.0V
VDD = 2.0V
RC6/TX1/CK1
pin
125
RC7/RX1/DT1
pin
126
Note:
Symbol
Characteristic
125
126
TCKL2DTL
Min
Max
Units
10
ns
15
ns
Conditions
DS39609B-page 339
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-25: A/D CONVERTER CHARACTERISTICS: PIC18FXX20 (INDUSTRIAL, EXTENDED)
PIC18LFXX20 (INDUSTRIAL)
Param
Symbol
No.
Characteristic
Min
Typ
Max
Units
Conditions
A01
NR
Resolution
10
A03
EIL
<1
A04
EDL
<1
A05
EG
Gain Error
<1
A06
EOFF
Offset Error
<1.5
A10
Monotonicity
A20
A20A
VREF
Reference Voltage
(VREFH VREFL)
A21
VREFH
A22
VREFL
bit
guaranteed(2)
1.8V
3V
V
V
AVSS
AVDD + 0.3V
AVSS 0.3V(5)
VREFH
AVDD + 0.3V
(5)
A25
VAIN
A30
ZAIN
Recommended Impedance of
Analog Voltage Source
2.5
(Note 4)
A50
IREF
5
150
A
A
Note 1:
2:
3:
4:
5:
AVSS 0.3V
(5)
FIGURE 26-26:
BSF ADCON0, GO
(Note 2)
131
Q4
130
A/D CLK
132
A/D DATA
ADRES
...
...
OLD_DATA
NEW_DATA
TCY
ADIF
GO
SAMPLE
DONE
SAMPLING STOPPED
Note 1: If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts. This allows the SLEEP instruction to be
executed.
2: This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
DS39609B-page 340
PIC18F6520/8520/6620/8620/6720/8720
TABLE 26-26: A/D CONVERSION REQUIREMENTS
Param
Symbol
No.
130
TAD
Characteristic
A/D Clock Period
Min
Max
Units
1.6
20(5)
PIC18LFXX20
3.0
(5)
PIC18FXX20
2.0
6.0
A/D RC mode
PIC18LFXX20
A/D RC mode
PIC18FXX20
20
Conditions
3.0
9.0
131
TCNV
Conversion Time
(not including acquisition time) (Note 1)
11
12
TAD
132
TACQ
15
10
s
s
135
TSWC
(Note 4)
136
TAMP
Note 1:
2:
3:
4:
5:
DS39609B-page 341
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 342
PIC18F6520/8520/6620/8620/6720/8720
27.0
Note:
Typical represents the mean of the distribution at 25C. Maximum or minimum represents (mean + 3) or (mean
3) respectively, where is a standard deviation, over the whole temperature range.
FIGURE 27-1:
20
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
IDD (mA)
16
5.5V
14
5.0V
12
4.5V
10
4.0V
3.5V
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
FIGURE 27-2:
20
5.5V
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
16
5.0V
4.5V
IDD (mA)
14
12
4.0V
10
3.5V
8
3.0V
6
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
DS39609B-page 343
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-3:
20
5.5V
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.0V
4.5V
14
4.0V
I DD (mA)
12
3.5V
10
8
3.0V
6
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
FIGURE 27-4:
20
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.5V
14
5.0V
IDD (mA)
12
4.5V
10
4.0V
3.5V
6
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
DS39609B-page 344
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-5:
20
18
5.5V
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
16
5.0V
14
4.5V
12
IDD (mA)
4.0V
10
3.5V
8
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
FIGURE 27-6:
20
5.5V
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.0V
4.5V
IDD (mA)
14
12
4.0V
10
3.5V
8
3.0V
4
2.5V
2
2.0V
0
4.0
6.0
8.0
10.0
12.0
14.0
16.0
18.0
20.0
22.0
24.0
26.0
FOSC (MHz)
DS39609B-page 345
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-7:
3.0
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
2.5
2.0
IDD (uA)
5.5V
5.0V
1.5
4.5V
4.0V
1.0
3.5V
3.0V
2.5V
0.5
2.0V
0.0
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
3.5
4.0
FOSC (MHz)
FIGURE 27-8:
3.0
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
2.5
5.5V
2.0
IDD (uA)
5.0V
4.5V
1.5
4.0V
3.5V
1.0
3.0V
2.5V
2.0V
0.5
0.0
0.0
0.5
1.0
1.5
2.0
2.5
3.0
FOSC (MHz)
DS39609B-page 346
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-9:
100
90
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
80
5.5V
70
5.0V
60
IDD (uA)
4.5V
50
4.0V
3.5V
40
3.0V
30
2.5V
2.0V
20
10
0
0
10
20
30
40
50
60
70
80
90
100
90
100
FOSC (kHz)
FIGURE 27-10:
120
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
100
5.5V
5.0V
80
IDD (uA)
4.5V
4.0V
60
3.5V
3.0V
40
2.5V
2.0V
20
0
0
10
20
30
40
50
60
70
80
FOSC (kHz)
DS39609B-page 347
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-11:
300
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
250
5.5V
5.0V
200
4.5V
IDD (uA)
4.0V
150
3.5V
3.0V
2.5V
100
2.0V
50
0
0
10
20
30
40
50
60
70
80
90
100
FOSC (kHz)
FIGURE 27-12:
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.5V
14
5.0V
12
IDD (mA)
4.5V
10
4.0V
3.5V
6
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
DS39609B-page 348
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-13:
18
5.5V
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.0V
14
4.5V
12
IDD (mA)
4.0V
10
3.5V
8
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
FIGURE 27-14:
100
Max
(-40C:+125C)
10
IPD (uA)
Max
(-40C:+85C)
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
0.1
Typ
(25C)
0.01
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
VDD (V)
DS39609B-page 349
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-15:
1000
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
IPD (uA)
100
Max
(-40C:+125C)
Max
(-40C:+85C)
10
Typ
(25C)
1
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
VDD (V)
FIGURE 27-16:
TYPICAL AND MAXIMUM IWDT vs. VDD OVER TEMPERATURE (WDT ENABLED)
1000
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
Max
(-40C:+125C)
100
IPD (uA)
Max
(-40C:+85C)
10
Typ
(25C)
0.1
2.0
2.5
3.0
3.5
4.0
4.5
5.0
5.5
VDD (V)
DS39609B-page 350
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-17:
0.55
0.50
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
0.45
0.40
5.5V
0.35
IDD (mA)
5.0V
0.30
4.5V
0.25
4.0V
0.20
3.5V
0.15
3.0V
0.10
2.5V
0.05
2.0V
0.00
0.00
0.02
0.04
0.06
0.08
0.10
0.12
0.14
0.16
0.18
0.20
0.18
0.20
FOSC (MHz)
FIGURE 27-18:
0.55
0.50
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
5.5V
5.0V
0.45
0.40
4.5V
IDD (mA)
0.35
0.30
4.0V
0.25
3.5V
0.20
0.15
3.0V
2.5V
0.10
2.0V
0.05
0.00
0.00
0.02
0.04
0.06
0.08
0.10
0.12
0.14
0.16
FOSC (MHz)
DS39609B-page 351
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-19:
TYPICAL IDD vs. FOSC OVER VDD (EC MODE) (PIC18F8520 DEVICES ONLY)
30
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
25
5.5V
20
IDD (mA)
5.0V
4.5V
15
4.2V
4.0V
10
3.5V
3.0V
5
2.5V
2.0V
0
4
12
16
20
24
28
32
36
40
FOSC (MHz)
FIGURE 27-20:
30
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
5.5V
25
5.0V
20
IDD (mA)
4.5V
4.2V
4.0V
15
3.5V
10
3.0V
5
2.5V
2.0V
0
4
12
16
20
24
28
32
36
40
FOSC (MHz)
DS39609B-page 352
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-21:
20
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
18
16
5.5V
14
5.0V
IDD (mA)
12
4.5V
10
4.2V
4.0V
8
3.5V
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
FIGURE 27-22:
30
27
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
24
5.5V
21
5.0V
IDD (mA)
18
4.5V
15
4.2V
4.0V
12
3.5V
6
3.0V
3
2.5V
2.0V
0
4
12
16
20
24
28
32
36
40
FOSC (MHz)
DS39609B-page 353
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-23:
30
27
5.5V
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +85C)
Minimum: mean 3 (-40C to +85C)
24
5.0V
21
4.5V
IDD (mA)
18
4.2V
4.0V
15
12
3.5V
9
3.0V
2.5V
2.0V
0
4
12
16
20
24
28
32
36
40
FOSC (MHz)
FIGURE 27-24:
20
18
Typical:
statistical mean @ 25C
Maximum: mean + 3 (-40C to +125C)
Minimum: mean 3 (-40C to +125C)
16
5.5V
14
5.0V
IDD (mA)
12
4.5V
4.2V
10
4.0V
8
3.5V
3.0V
4
2.5V
2
2.0V
0
4
10
12
14
16
18
20
22
24
26
FOSC (MHz)
DS39609B-page 354
PIC18F6520/8520/6620/8620/6720/8720
FIGURE 27-25:
3.5
-40C
-40C
3
+25C
25C
2.5
+85C
85C
2
1.5
0.5
+125C
125C
0
2
2.5
3.5
4.5
5.5
FIGURE 27-26:
2.5
1.5
Max
+125C)
Max (-40C
(-40C toto125C)
1
Typ
Typ (+25C)
(25C)
0.5
0
2
2.5
3.5
4.5
5.5
VREFH (V)
DS39609B-page 355
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 356
PIC18F6520/8520/6620/8620/6720/8720
28.0
PACKAGING INFORMATION
28.1
64-Lead TQFP
Example
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
80-Lead TQFP
PIC18F6620
-I/PT
0410017
Example
XXXXXXXXXXXX
XXXXXXXXXXXX
YYWWNNN
Legend: XX...X
Y
YY
WW
NNN
Note:
PIC18F8720
-E/PT
0410017
In the event the full Microchip part number cannot be marked on one line, it will
be carried over to the next line thus limiting the number of available characters
for customer specific information.
Standard PICmicro device marking consists of Microchip part number, year code, week code, and
traceability code. For PICmicro device marking beyond this, certain price adders apply. Please check
with your Microchip Sales Office. For QTP devices, any special marking adders are included in QTP
price.
DS39609B-page 357
PIC18F6520/8520/6620/8620/6720/8720
28.2
Package Details
64-Lead Plastic Thin Quad Flatpack (PT) 10x10x1 mm Body, 1.0/0.10 mm Lead Form (TQFP)
E
E1
#leads=n1
p
D1
2
1
B
n
CH x 45
A
c
A2
A1
(F)
Units
Dimension Limits
n
p
Number of Pins
Pitch
Pins per Side
Overall Height
Molded Package Thickness
Standoff
Foot Length
Footprint (Reference)
Foot Angle
Overall Width
Overall Length
Molded Package Width
Molded Package Length
Lead Thickness
Lead Width
Pin 1 Corner Chamfer
Mold Draft Angle Top
Mold Draft Angle Bottom
n1
A
A2
A1
L
(F)
E
D
E1
D1
c
B
CH
MIN
.039
.037
.002
.018
0
.463
.463
.390
.390
.005
.007
.025
5
5
INCHES
NOM
64
.020
16
.043
.039
.006
.024
.039
3.5
.472
.472
.394
.394
.007
.009
.035
10
10
MAX
.047
.041
.010
.030
7
.482
.482
.398
.398
.009
.011
.045
15
15
MILLIMETERS*
NOM
64
0.50
16
1.00
1.10
0.95
1.00
0.05
0.15
0.45
0.60
1.00
0
3.5
11.75
12.00
11.75
12.00
9.90
10.00
9.90
10.00
0.13
0.18
0.17
0.22
0.64
0.89
5
10
5
10
MIN
MAX
1.20
1.05
0.25
0.75
7
12.25
12.25
10.10
10.10
0.23
0.27
1.14
15
15
* Controlling Parameter
Significant Characteristic
Notes:
Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MS-026
Drawing No. C04-085
DS39609B-page 358
PIC18F6520/8520/6620/8620/6720/8720
80-Lead Plastic Thin Quad Flatpack (PT) 12x12x1 mm Body, 1.0/0.10 mm Lead Form (TQFP)
E
E1
#leads=n1
p
D1
2
1
CH x 45
A
A2
A1
(F)
Units
Dimension Limits
n
p
Number of Pins
Pitch
Pins per Side
Overall Height
Molded Package Thickness
Standoff
Foot Length
Footprint (Reference)
Foot Angle
Overall Width
Overall Length
Molded Package Width
Molded Package Length
Lead Thickness
Lead Width
Pin 1 Corner Chamfer
Mold Draft Angle Top
Mold Draft Angle Bottom
n1
A
A2
A1
L
(F)
E
D
E1
D1
c
B
CH
MIN
.039
.037
.002
.018
0
.541
.541
.463
.463
.004
.007
.025
5
5
INCHES
NOM
80
.020
20
.043
.039
.004
.024
.039
3.5
.551
.551
.472
.472
.006
.009
.035
10
10
MAX
.047
.041
.006
.030
7
.561
.561
.482
.482
.008
.011
.045
15
15
MILLIMETERS*
NOM
80
0.50
20
1.00
1.10
0.95
1.00
0.05
0.10
0.45
0.60
1.00
0
3.5
13.75
14.00
13.75
14.00
11.75
12.00
11.75
12.00
0.09
0.15
0.17
0.22
0.64
0.89
5
10
5
10
MIN
MAX
1.20
1.05
0.15
0.75
7
14.25
14.25
12.25
12.25
0.20
0.27
1.14
15
15
* Controlling Parameter
Significant Characteristic
Notes:
Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MS-026
Drawing No. C04-092
DS39609B-page 359
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 360
PIC18F6520/8520/6620/8620/6720/8720
APPENDIX A:
REVISION HISTORY
APPENDIX B:
DEVICE
DIFFERENCES
TABLE B-1:
DEVICE DIFFERENCES
Feature
PIC18F6520
PIC18F6620
PIC18F6720
PIC18F8520
PIC18F8620
PIC18F8720
32
64
128
32
64
128
2048
3840
3840
2048
3840
3840
2048
512
512
2048
512
512
Yes
No
No
Yes
No
No
I/O Ports
A/D Channels
12
12
12
16
16
16
No
No
No
Yes
Yes
Yes
Maximum Operating
Frequency (MHz)
40
25
25
40
25
25
Package Types
64-pin TQFP 64-pin TQFP 64-pin TQFP 80-pin TQFP 80-pin TQFP
80-pin TQFP
DS39609B-page 361
PIC18F6520/8520/6620/8620/6720/8720
APPENDIX C:
CONVERSION
CONSIDERATIONS
APPENDIX D:
MIGRATION FROM
MID-RANGE TO
ENHANCED DEVICES
DS39609B-page 362
PIC18F6520/8520/6620/8620/6720/8720
APPENDIX E:
MIGRATION FROM
HIGH-END TO
ENHANCED DEVICES
A detailed discussion of the migration pathway and differences between the high-end MCU devices (i.e.,
PIC17CXXX) and the enhanced devices (i.e.,
PIC18FXXXX) is provided in AN726, PIC17CXXX to
PIC18CXXX Migration. This Application Note is
available as Literature Number DS00726.
DS39609B-page 363
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 364
PIC18F6520/8520/6620/8620/6720/8720
INDEX
A
A/D ................................................................................... 213
A/D Converter Interrupt, Configuring ....................... 217
Acquisition Requirements ........................................ 218
Acquisition Time ....................................................... 218
ADCON0 Register .................................................... 213
ADCON1 Register .................................................... 213
ADCON2 Register .................................................... 213
ADRESH Register ............................................ 213, 215
ADRESL Register ............................................ 213, 215
Analog Port Pins ...................................................... 128
Analog Port Pins, Configuring .................................. 219
Associated Register Summary ................................. 221
Calculating Minimum Required
Acquisition Time (Example) ............................. 218
CCP2 Trigger ........................................................... 220
Configuring the Module ............................................ 217
Conversion Clock (TAD) ........................................... 219
Conversion Requirements ....................................... 341
Conversion Status (GO/DONE Bit) .......................... 215
Conversion TAD Cycles ............................................ 220
Conversions ............................................................. 220
Converter Characteristics ........................................ 340
Equations ................................................................. 218
Minimum Charging Time .......................................... 218
Special Event Trigger (CCP) .................................... 152
Special Event Trigger (CCP2) .................................. 220
TAD vs. Device Operating Frequencies (Table) ....... 219
Absolute Maximum Ratings ............................................. 307
AC (Timing) Characteristics ............................................. 320
Load Conditions for Device
Timing Specifications ....................................... 321
Parameter Symbology ............................................. 320
Temperature and Voltage Specifications ................. 321
Timing Conditions .................................................... 321
ACKSTAT Status Flag ..................................................... 187
ADCON0 Register ............................................................ 213
GO/DONE Bit ........................................................... 215
ADCON1 Register ............................................................ 213
ADCON2 Register ............................................................ 213
ADDLW ............................................................................ 265
Addressable Universal Synchronous Asynchronous
Receiver Transmitter (USART) ................................ 197
ADDWF ............................................................................ 265
ADDWFC ......................................................................... 266
ADRESH Register .................................................... 213, 215
ADRESL Register .................................................... 213, 215
Analog-to-Digital Converter. See A/D.
ANDLW ............................................................................ 266
ANDWF ............................................................................ 267
Assembler
MPASM Assembler .................................................. 301
B
Baud Rate Generator ....................................................... 183
BC .................................................................................... 267
BCF .................................................................................. 268
BF Status Flag ................................................................. 187
Block Diagrams
16-bit Byte Select Mode ............................................. 75
16-bit Byte Write Mode .............................................. 73
16-bit Word Write Mode ............................................. 74
A/D ........................................................................... 216
DS39609B-page 365
PIC18F6520/8520/6620/8620/6720/8720
USART Transmit ...................................................... 204
Voltage Reference Output Buffer Example .............. 231
Watchdog Timer ....................................................... 251
BN .................................................................................... 268
BNC .................................................................................. 269
BNN .................................................................................. 269
BNOV ............................................................................... 270
BNZ .................................................................................. 270
BOR. See Brown-out Reset.
BOV .................................................................................. 273
BRA .................................................................................. 271
BRG. See Baud Rate Generator.
Brown-out Reset (BOR) ..................................................... 30
BSF .................................................................................. 271
BTFSC ............................................................................. 272
BTFSS .............................................................................. 272
BTG .................................................................................. 273
BZ ..................................................................................... 274
C
C Compilers
MPLAB C17 ............................................................. 302
MPLAB C18 ............................................................. 302
MPLAB C30 ............................................................. 302
CALL ................................................................................ 274
Capture (CCP Module) ..................................................... 151
Associated Registers ............................................... 153
CCP Pin Configuration ............................................. 151
CCPR1H:CCPR1L Registers ................................... 151
Software Interrupt .................................................... 151
Timer1/Timer3 Mode Selection ................................ 151
Capture/Compare/PWM (CCP) ........................................ 149
Capture Mode. See Capture.
CCP Mode and Timer Resources ............................ 150
CCPRxH Register .................................................... 150
CCPRxL Register ..................................................... 150
Compare Mode. See Compare.
Interconnect Configurations ..................................... 150
Module Configuration ............................................... 150
PWM Mode. See PWM.
Capture/Compare/PWM Requirements
(All CCP Modules) ................................................... 329
CLKO and I/O Timing Requirements ....................... 324, 325
Clocking Scheme/Instruction Cycle .................................... 44
CLRF ................................................................................ 275
CLRWDT .......................................................................... 275
Code Examples
16 x 16 Signed Multiply Routine ................................ 86
16 x 16 Unsigned Multiply Routine ............................ 86
8 x 8 Signed Multiply Routine .................................... 85
8 x 8 Unsigned Multiply Routine ................................ 85
Changing Between Capture Prescalers ................... 151
Data EEPROM Read ................................................. 81
Data EEPROM Refresh Routine ................................ 82
Data EEPROM Write ................................................. 81
Erasing a Flash Program Memory Row ..................... 66
Fast Register Stack .................................................... 44
How to Clear RAM (Bank 1)
Using Indirect Addressing .................................. 57
Implementing a Real-Time Clock Using a
Timer1 Interrupt Service .................................. 139
Initializing PORTA .................................................... 103
Initializing PORTB .................................................... 106
Initializing PORTC .................................................... 109
Initializing PORTD .................................................... 111
Initializing PORTE .................................................... 114
DS39609B-page 366
D
Data EEPROM Memory
Associated Registers ................................................. 83
EEADR Register ........................................................ 79
EEADRH Register ..................................................... 79
EECON1 Register ...................................................... 79
EECON2 Register ...................................................... 79
Operation During Code-Protect ................................. 82
Protection Against Spurious Write ............................. 82
Reading ..................................................................... 81
Using ......................................................................... 82
Write Verify ................................................................ 82
Writing ....................................................................... 81
PIC18F6520/8520/6620/8620/6720/8720
Data Memory ..................................................................... 47
General Purpose Registers ........................................ 47
Map for PIC18FX520 Devices ................................... 48
Map for PIC18FX620/X720 Devices .......................... 49
Special Function Registers ........................................ 47
DAW ................................................................................. 278
DC and AC Characteristics
Graphs and Tables .................................................. 343
DC Characteristics
PIC18FXX20 (Industrial and Extended),
PIC18LFXX20 (Industrial) ................................ 315
Power-Down and Supply Current ............................ 311
Supply Voltage ......................................................... 310
DCFSNZ .......................................................................... 279
DECF ............................................................................... 278
DECFSZ ........................................................................... 279
Demonstration Boards
PICDEM 1 ................................................................ 304
PICDEM 17 .............................................................. 304
PICDEM 18R ........................................................... 305
PICDEM 2 Plus ........................................................ 304
PICDEM 3 ................................................................ 304
PICDEM 4 ................................................................ 304
PICDEM LIN ............................................................ 305
PICDEM USB ........................................................... 305
PICDEM.net Internet/Ethernet ................................. 304
Development Support ...................................................... 301
Device Differences ........................................................... 361
Direct Addressing ............................................................... 58
Direct Addressing ....................................................... 56
E
Electrical Characteristics .................................................. 307
Errata ................................................................................... 5
Evaluation and Programming Tools ................................. 305
Example SPI Mode Requirements
(Master Mode, CKE = 0) .......................................... 331
Example SPI Mode Requirements
(Master Mode, CKE = 1) .......................................... 332
Example SPI Mode Requirements
(Slave Mode, CKE = 0) ............................................ 333
Example SPI Slave Mode Requirements (CKE = 1) ........ 334
Extended Microcontroller Mode ......................................... 71
External Clock Timing Requirements ............................... 322
External Memory Interface ................................................. 71
16-bit Byte Select Mode ............................................. 75
16-bit Byte Write Mode .............................................. 73
16-bit Mode ................................................................ 73
16-bit Mode Timing .................................................... 76
16-bit Word Write Mode ............................................. 74
PIC18F8X20 External Bus - I/O Port Functions ......... 72
Program Memory Modes and
External Memory Interface ................................. 71
F
Firmware Instructions ....................................................... 259
Flash Program Memory ..................................................... 61
Associated Registers ................................................. 69
Control Registers ....................................................... 62
Erase Sequence ........................................................ 66
Erasing ....................................................................... 66
Operation During Code-Protect ................................. 69
Reading ...................................................................... 65
Table Pointer
Boundaries Based on Operation ........................ 64
Table Pointer Boundaries .......................................... 64
G
General Call Address Support ......................................... 180
GOTO .............................................................................. 280
H
Hardware Multiplier ............................................................ 85
Introduction ................................................................ 85
Operation ................................................................... 85
Performance Comparison .......................................... 85
HS/PLL .............................................................................. 23
I
I/O Ports .......................................................................... 103
I2C Bus Data Requirements (Slave Mode) ...................... 336
I2C Bus Start/Stop Bits Requirements (Slave Mode) ....... 335
I2C Mode
General Call Address Support ................................. 180
Master Mode
Operation ......................................................... 182
Read/Write Bit Information (R/W Bit) ............... 170, 171
Serial Clock (RC3/SCK/SCL) .................................. 171
ID Locations ............................................................. 239, 257
INCF ................................................................................ 280
INCFSZ ............................................................................ 281
In-Circuit Debugger .......................................................... 257
Resources (Table) ................................................... 257
In-Circuit Serial Programming (ICSP) ...................... 239, 257
Indirect Addressing ............................................................ 58
INDF and FSR Registers ........................................... 57
Operation ................................................................... 57
Indirect Addressing Operation ........................................... 58
Indirect File Operand ......................................................... 47
INFSNZ ............................................................................ 281
Instruction Cycle ................................................................ 44
Instruction Flow/Pipelining ................................................. 45
Instruction Format ............................................................ 261
Instruction Set .................................................................. 259
ADDLW .................................................................... 265
ADDWF ................................................................... 265
ADDWFC ................................................................. 266
ANDLW .................................................................... 266
ANDWF ................................................................... 267
BC ............................................................................ 267
BCF ......................................................................... 268
BN ............................................................................ 268
BNC ......................................................................... 269
BNN ......................................................................... 269
BNOV ...................................................................... 270
BNZ ......................................................................... 270
BOV ......................................................................... 273
BRA ......................................................................... 271
BSF .......................................................................... 271
BTFSC ..................................................................... 272
BTFSS ..................................................................... 272
BTG ......................................................................... 273
BZ ............................................................................ 274
CALL ........................................................................ 274
CLRF ....................................................................... 275
CLRWDT ................................................................. 275
DS39609B-page 367
PIC18F6520/8520/6620/8620/6720/8720
COMF ...................................................................... 276
CPFSEQ .................................................................. 276
CPFSGT .................................................................. 277
CPFSLT ................................................................... 277
DAW ......................................................................... 278
DCFSNZ .................................................................. 279
DECF ....................................................................... 278
DECFSZ ................................................................... 279
GOTO ...................................................................... 280
INCF ......................................................................... 280
INCFSZ .................................................................... 281
INFSNZ .................................................................... 281
IORLW ..................................................................... 282
IORWF ..................................................................... 282
LFSR ........................................................................ 283
MOVF ....................................................................... 283
MOVFF .................................................................... 284
MOVLB .................................................................... 284
MOVLW ................................................................... 285
MOVWF ................................................................... 285
MULLW .................................................................... 286
MULWF .................................................................... 286
NEGF ....................................................................... 287
NOP ......................................................................... 287
POP ......................................................................... 288
PUSH ....................................................................... 288
RCALL ..................................................................... 289
RESET ..................................................................... 289
RETFIE .................................................................... 290
RETLW .................................................................... 290
RETURN .................................................................. 291
RLCF ........................................................................ 291
RLNCF ..................................................................... 292
RRCF ....................................................................... 292
RRNCF .................................................................... 293
SETF ........................................................................ 293
SLEEP ..................................................................... 294
SUBFWB .................................................................. 294
SUBLW .................................................................... 295
SUBWF .................................................................... 295
SUBWFB .................................................................. 296
SWAPF .................................................................... 296
TBLRD ..................................................................... 297
TBLWT ..................................................................... 298
TSTFSZ ................................................................... 299
XORLW .................................................................... 299
XORWF .................................................................... 300
Summary Table ........................................................ 262
INT Interrupt (RB0/INT). See Interrupt Sources.
INTCON Registers ............................................................. 89
Inter-Integrated Circuit. See I2C.
Interrupt Sources .............................................................. 239
A/D Conversion Complete ....................................... 217
Capture Complete (CCP) ......................................... 151
Compare Complete (CCP) ....................................... 152
INT0 ......................................................................... 102
Interrupt-on-Change (RB7:RB4) .............................. 106
PORTB, Interrupt-on-Change .................................. 102
RB0/INT Pin, External .............................................. 102
TMR0 ....................................................................... 102
TMR0 Overflow ........................................................ 133
TMR1 Overflow ................................................ 135, 138
TMR2 to PR2 Match ................................................ 142
TMR2 to PR2 Match (PWM) ............................ 141, 154
TMR3 Overflow ................................................ 143, 145
TMR4 to PR4 Match ................................................ 148
TMR4 to PR4 Match (PWM) .................................... 147
DS39609B-page 368
Interrupts ............................................................................ 87
Control Registers ....................................................... 89
Enable Registers ....................................................... 95
Flag Registers ............................................................ 92
Logic .......................................................................... 88
Priority Registers ....................................................... 98
Reset Control Registers ........................................... 101
IORLW ............................................................................. 282
IORWF ............................................................................. 282
IPR Registers ..................................................................... 98
K
Key Features
Easy Migration ............................................................. 7
Expanded Memory ....................................................... 7
External Memory Interface ........................................... 7
Other Special Features ................................................ 7
L
LFSR ................................................................................ 283
Low-Voltage Detect ......................................................... 233
Characteristics ......................................................... 318
Converter Characteristics ........................................ 318
Effects of a Reset .................................................... 237
Operation ................................................................. 236
Current Consumption ...................................... 237
During Sleep .................................................... 237
Reference Voltage Set Point ........................... 237
Typical Application ................................................... 233
Low-Voltage ICSP Programming ..................................... 257
LVD. See Low-Voltage Detect.
M
Master SSP (MSSP) Module
Overview .................................................................. 157
Master SSP I2C Bus Data Requirements ........................ 338
Master SSP I2C Bus Start/Stop Bits Requirements ......... 337
Master Synchronous Serial Port (MSSP). See MSSP.
Memory Organization
Data Memory ............................................................. 47
Memory Programming Requirements .............................. 319
Microcontroller Mode ......................................................... 71
Microprocessor Mode ........................................................ 71
Microprocessor with Boot Block Mode ............................... 71
Migration from High-End to Enhanced Devices ............... 363
Migration from Mid-Range to Enhanced Devices ............ 362
MOVF .............................................................................. 283
MOVFF ............................................................................ 284
MOVLB ............................................................................ 284
MOVLW ........................................................................... 285
MOVWF ........................................................................... 285
MPLAB ASM30 Assembler, Linker, Librarian .................. 302
MPLAB ICD 2 In-Circuit Debugger .................................. 303
MPLAB ICE 2000 High-Performance
Universal In-Circuit Emulator ................................... 303
MPLAB ICE 4000 High-Performance
Universal In-Circuit Emulator ................................... 303
MPLAB Integrated Development
Environment Software ............................................. 301
MPLINK Object Linker/MPLIB Object Librarian ............... 302
MSSP ............................................................................... 157
ACK Pulse ....................................................... 170, 171
Clock Stretching ....................................................... 176
10-bit Slave Receive Mode (SEN = 1) ............. 176
10-bit Slave Transmit Mode ............................. 176
7-bit Slave Receive Mode (SEN = 1) ............... 176
7-bit Slave Transmit Mode ............................... 176
PIC18F6520/8520/6620/8620/6720/8720
Clock Synchronization and the CKP bit ................... 177
Control Registers (general) ...................................... 157
Enabling SPI I/O ...................................................... 161
I2C Mode .................................................................. 166
Acknowledge Sequence Timing ...................... 190
Baud Rate Generator ....................................... 183
Bus Collision
During a Repeated Start Condition .......... 194
Bus Collision During a Start Condition ............. 192
Bus Collision During a Stop Condition ............. 195
Clock Arbitration .............................................. 184
Effect of a Reset .............................................. 191
I2C Clock Rate w/BRG ..................................... 183
Master Mode .................................................... 181
Reception ................................................. 187
Repeated Start Timing ............................. 186
Master Mode Start Condition ........................... 185
Master Mode Transmission ............................. 187
Multi-Master Communication, Bus Collision
and Arbitration ......................................... 191
Multi-Master Mode ........................................... 191
Registers .......................................................... 166
Sleep Operation ............................................... 191
Stop Condition Timing ..................................... 190
I2C Mode. See I2C.
Module Operation .................................................... 170
Operation ................................................................. 160
Slave Mode .............................................................. 170
Addressing ....................................................... 170
Reception ......................................................... 171
Transmission ................................................... 171
SPI
Master Mode .................................................... 162
SPI Clock ......................................................... 162
SPI Master Mode ..................................................... 162
SPI Mode ................................................................. 157
SPI Mode. See SPI.
SPI Slave Mode ....................................................... 163
Select Synchronization .................................... 163
SSPBUF Register .................................................... 162
SSPSR Register ...................................................... 162
Typical Connection .................................................. 161
MSSP Module
SPI Master/Slave Connection .................................. 161
MULLW ............................................................................ 286
MULWF ............................................................................ 286
N
NEGF ............................................................................... 287
NOP ................................................................................. 287
O
Opcode Field Descriptions ............................................... 260
OPTION_REG Register
PSA Bit ..................................................................... 133
T0CS Bit ................................................................... 133
T0PS2:T0PS0 Bits ................................................... 133
T0SE Bit ................................................................... 133
Oscillator Configuration ...................................................... 21
EC .............................................................................. 21
ECIO .......................................................................... 21
HS .............................................................................. 21
HS + PLL ................................................................... 21
LP ............................................................................... 21
RC .............................................................................. 21
RCIO .......................................................................... 21
XT .............................................................................. 21
P
Packaging Information ..................................................... 357
Details ...................................................................... 358
Marking .................................................................... 357
Parallel Slave Port (PSP) ......................................... 111, 128
Associated Registers ............................................... 130
RE0/RD/AN5 Pin ..................................................... 128
RE1/WR/AN6 Pin .................................................... 128
RE2/CS/AN7 Pin ..................................................... 128
Read Waveforms ..................................................... 130
Select (PSPMODE Bit) .................................... 111, 128
Write Waveforms ..................................................... 129
Parallel Slave Port Requirements (PIC18F8X20) ............ 330
PICkit 1 Flash Starter Kit ................................................. 305
PICSTART Plus Development Programmer .................... 303
PIE Registers ..................................................................... 95
Pin Functions
AVDD .......................................................................... 20
AVSS .......................................................................... 20
MCLR/VPP ................................................................. 11
OSC1/CLKI ................................................................ 11
OSC2/CLKO/RA6 ...................................................... 11
RA0/AN0 .................................................................... 12
RA1/AN1 .................................................................... 12
RA2/AN2/VREF- ......................................................... 12
RA3/AN3/VREF+ ........................................................ 12
RA4/T0CKI ................................................................ 12
RA5/AN4/LVDIN ........................................................ 12
RA6 ............................................................................ 12
RB0/INT0 ................................................................... 13
RB1/INT1 ................................................................... 13
RB2/INT2 ................................................................... 13
RB3/INT3/CCP2 ........................................................ 13
RB4/KBI0 ................................................................... 13
RB5/KBI1/PGM .......................................................... 13
RB6/KBI2/PGC .......................................................... 13
RB7/KBI3/PGD .......................................................... 13
RC0/T1OSO/T13CKI ................................................. 14
RC1/T1OSI/CCP2 ..................................................... 14
RC2/CCP1 ................................................................. 14
RC3/SCK/SCL ........................................................... 14
RC4/SDI/SDA ............................................................ 14
RC5/SDO ................................................................... 14
RC6/TX1/CK1 ............................................................ 14
RC7/RX1/DT1 ............................................................ 14
RD0/PSP0/AD0 ......................................................... 15
RD1/PSP1/AD1 ......................................................... 15
RD2/PSP2/AD2 ......................................................... 15
RD3/PSP3/AD3 ......................................................... 15
RD4/PSP4/AD4 ......................................................... 15
RD5/PSP5/AD5 ......................................................... 15
RD6/PSP6/AD6 ......................................................... 15
RD7/PSP7/AD7 ......................................................... 15
RE0/RD/AD8 ............................................................. 16
RE1/WR/AD9 ............................................................. 16
RE2/CS/AD10 ............................................................ 16
RE3/AD11 .................................................................. 16
DS39609B-page 369
PIC18F6520/8520/6620/8620/6720/8720
RE4/AD12 .................................................................. 16
RE5/AD13 .................................................................. 16
RE6/AD14 .................................................................. 16
RE7/CCP2/AD15 ....................................................... 16
RF0/AN5 .................................................................... 17
RF1/AN6/C2OUT ....................................................... 17
RF2/AN7/C1OUT ....................................................... 17
RF3/AN8 .................................................................... 17
RF4/AN9 .................................................................... 17
RF5/AN10/CVREF ....................................................... 17
RF6/AN11 .................................................................. 17
RF7/SS ...................................................................... 17
RG0/CCP3 ................................................................. 18
RG1/TX2/CK2 ............................................................ 18
RG2/RX2/DT2 ............................................................ 18
RG3/CCP4 ................................................................. 18
RG4/CCP5 ................................................................. 18
RH0/A16 .................................................................... 19
RH1/A17 .................................................................... 19
RH2/A18 .................................................................... 19
RH3/A19 .................................................................... 19
RH4/AN12 .................................................................. 19
RH5/AN13 .................................................................. 19
RH6/AN14 .................................................................. 19
RH7/AN15 .................................................................. 19
RJ0/ALE ..................................................................... 20
RJ1/OE ...................................................................... 20
RJ2/WRL .................................................................... 20
RJ3/WRH ................................................................... 20
RJ4/BA0 ..................................................................... 20
RJ5/CE ....................................................................... 20
RJ6/LB ....................................................................... 20
RJ7/UB ....................................................................... 20
VDD ............................................................................. 20
VSS ............................................................................. 20
PIR Registers ..................................................................... 92
PLL Clock Timing Specifications ...................................... 323
PLL Lock Time-out ............................................................. 30
Pointer, FSR ....................................................................... 57
POP .................................................................................. 288
POR. See Power-on Reset.
PORTA
Associated Registers ............................................... 105
Functions ................................................................. 105
LATA Register .......................................................... 103
PORTA Register ...................................................... 103
TRISA Register ........................................................ 103
PORTB
Associated Registers ............................................... 108
Functions ................................................................. 108
LATB Register .......................................................... 106
PORTB Register ...................................................... 106
RB0/INT Pin, External .............................................. 102
TRISB Register ........................................................ 106
PORTC
Associated Registers ............................................... 110
Functions ................................................................. 110
LATC Register ......................................................... 109
PORTC Register ...................................................... 109
RC3/SCK/SCL Pin ................................................... 171
TRISC Register ................................................ 109, 197
DS39609B-page 370
PIC18F6520/8520/6620/8620/6720/8720
Program Memory ............................................................... 39
Access for PIC18F8X20 Program
Memory Modes .................................................. 40
Instructions ................................................................. 45
Interrupt Vector .......................................................... 39
Map and Stack for PIC18FXX20 ................................ 40
Maps for PIC18F8X20 Program Memory Modes ....... 41
PIC18F8X20 Modes ................................................... 39
Reset Vector .............................................................. 39
Program Memory Write Timing Requirements ................. 326
Program Verification and Code Protection ....................... 253
Associated Registers ............................................... 253
Configuration Register Protection ............................ 257
Data EEPROM Code Protection .............................. 257
Memory Code Protection ......................................... 255
Programming, Device Instructions ................................... 259
PSP. See Parallel Slave Port.
Pulse Width Modulation. See PWM (CCP Module).
PUSH ............................................................................... 288
PWM (CCP Module) ........................................................ 154
Associated Registers ............................................... 155
CCPR1H:CCPR1L Registers ................................... 154
Duty Cycle ................................................................ 154
Example Frequencies/Resolutions .......................... 155
Period ....................................................................... 154
Setup for PWM Operation ........................................ 155
TMR2 to PR2 Match ........................................ 141, 154
TMR4 to PR4 Match ................................................ 147
Q
Q Clock ............................................................................ 154
R
RAM. See Data Memory.
RC Oscillator ...................................................................... 22
RCALL ............................................................................. 289
RCON Registers .............................................................. 101
RCSTA Register
SPEN Bit .................................................................. 197
Register File ....................................................................... 47
Registers
ADCON0 (A/D Control 0) ......................................... 213
ADCON1 (A/D Control 1) ......................................... 214
ADCON2 (A/D Control 2) ......................................... 215
CCPxCON (Capture/Compare/PWM Control) ......... 149
CMCON (Comparator Control) ................................ 223
CONFIG1H (Configuration 1 High) .......................... 240
CONFIG2H (Configuration 2 High) .......................... 241
CONFIG2L (Configuration 2 Low) ............................ 241
CONFIG3H (Configuration 3 High) .......................... 242
CONFIG3L (Configuration 3 Low) ............................ 242
CONFIG3L (Configuration Byte) ................................ 41
CONFIG4L (Configuration 4 Low) ............................ 243
CONFIG5H (Configuration 5 High) .......................... 245
CONFIG5L (Configuration 5 Low) ............................ 244
CONFIG6H (Configuration 6 High) .......................... 247
CONFIG6L (Configuration 6 Low) ............................ 246
CONFIG7H (Configuration 7 High) .......................... 249
CONFIG7L (Configuration 7 Low) ............................ 248
CVRCON (Comparator Voltage
Reference Control) .......................................... 229
Device ID 1 .............................................................. 249
Device ID 2 .............................................................. 249
EECON1 (Data EEPROM Control 1) ................... 63, 80
INTCON (Interrupt Control) ........................................ 89
INTCON2 (Interrupt Control 2) ................................... 90
INTCON3 (Interrupt Control 3) ................................... 91
2004 Microchip Technology Inc.
S
SCI. See USART.
SCK ................................................................................. 157
SDI ................................................................................... 157
SDO ................................................................................. 157
Serial Clock, SCK ............................................................ 157
Serial Communication Interface. See USART.
Serial Data In, SDI ........................................................... 157
Serial Data Out, SDO ...................................................... 157
Serial Peripheral Interface. See SPI.
SETF ............................................................................... 293
Slave Select, SS .............................................................. 157
SLEEP ............................................................................. 294
Sleep ....................................................................... 239, 252
DS39609B-page 371
PIC18F6520/8520/6620/8620/6720/8720
Software Simulator (MPLAB SIM) .................................... 302
Software Simulator (MPLAB SIM30) ................................ 302
Special Event Trigger. See Compare
Special Features of the CPU ............................................ 239
Configuration Registers ................................... 240249
Special Function Registers ................................................ 47
Map ............................................................................ 50
SPI
Serial Clock .............................................................. 157
Serial Data In ........................................................... 157
Serial Data Out ........................................................ 157
Slave Select ............................................................. 157
SPI Mode ................................................................. 157
SPI Master/Slave Connection .......................................... 161
SPI Module
Associated Registers ............................................... 165
Bus Mode Compatibility ........................................... 165
Effects of a Reset ..................................................... 165
Master/Slave Connection ......................................... 161
Slave Mode .............................................................. 163
Sleep Operation ....................................................... 165
SS .................................................................................... 157
SSP
TMR2 Output for Clock Shift ............................ 141, 142
TMR4 Output for Clock Shift .................................... 148
SSPOV Status Flag .......................................................... 187
SSPSTAT Register
R/W Bit ............................................................. 170, 171
Status Bits
Significance and Initialization Condition
for RCON Register ............................................. 31
SUBFWB .......................................................................... 294
SUBLW ............................................................................ 295
SUBWF ............................................................................ 295
SUBWFB .......................................................................... 296
SWAPF ............................................................................ 296
T
Table Pointer Operations (table) ........................................ 64
TBLRD ............................................................................. 297
TBLWT ............................................................................. 298
Time-out in Various Situations ........................................... 31
Timer0 .............................................................................. 131
16-bit Mode Timer Reads and Writes ...................... 133
Associated Registers ............................................... 133
Clock Source Edge Select (T0SE Bit) ...................... 133
Clock Source Select (T0CS Bit) ............................... 133
Operation ................................................................. 133
Overflow Interrupt .................................................... 133
Prescaler. See Prescaler, Timer0.
Timer0 and Timer1 External Clock
Requirements ........................................................... 328
Timer1 .............................................................................. 135
16-bit Read/Write Mode ........................................... 138
Associated Registers ............................................... 139
Operation ................................................................. 136
Oscillator .......................................................... 135, 137
Overflow Interrupt ............................................ 135, 138
Special Event Trigger (CCP) ............................ 138, 152
TMR1H Register ...................................................... 135
TMR1L Register ....................................................... 135
Use as a Real-Time Clock ....................................... 138
DS39609B-page 372
PIC18F6520/8520/6620/8620/6720/8720
I2C Master Mode First Start Bit Timing .................... 185
I2C Slave Mode (10-bit Reception, SEN = 0) ........... 174
I2C Slave Mode (10-bit Reception, SEN = 1) ........... 179
I2C Slave Mode (10-bit Transmission) ..................... 175
I2C Slave Mode (7-bit Reception, SEN = 0) ............. 172
I2C Slave Mode (7-bit Reception, SEN = 1) ............. 178
I2C Slave Mode (7-bit Transmission) ....................... 173
Low-Voltage Detect .................................................. 236
Master SSP I2C Bus Data ........................................ 337
Master SSP I2C Bus Start/Stop Bits ........................ 337
Parallel Slave Port (PIC18F8X20) ........................... 329
Program Memory Read ............................................ 324
Program Memory Write ............................................ 325
PWM Output ............................................................ 154
Repeat Start Condition ............................................. 186
Reset, Watchdog Timer (WDT),
Oscillator Start-up Timer (OST) and
Power-up Timer (PWRT) ................................. 326
Slave Mode General Call Address Sequence
(7 or 10-bit Address Mode) .............................. 180
Slave Synchronization ............................................. 163
Slow Rise Time (MCLR Tied to VDD
via 1 kOhm Resistor) ......................................... 38
SPI Mode (Master Mode) ......................................... 162
SPI Mode (Slave Mode with CKE = 0) ..................... 164
SPI Mode (Slave Mode with CKE = 1) ..................... 164
Stop Condition Receive or Transmit Mode .............. 190
Synchronous Reception
(Master Mode, SREN) ..................................... 210
Synchronous Transmission ...................................... 209
Synchronous Transmission (Through TXEN) .......... 209
Time-out Sequence on POR w/PLL Enabled
(MCLR Tied to VDD via 1 kOhm Resistor) ......... 38
Time-out Sequence on Power-up
(MCLR Not Tied to VDD)
Case 1 ............................................................... 37
Case 2 ............................................................... 37
Time-out Sequence on Power-up (MCLR Tied
to VDD via 1 kOhm Resistor) .............................. 37
Timer0 and Timer1 External Clock .......................... 327
Timing for Transition Between Timer1 and
OSC1 (HS with PLL) .......................................... 27
Transition Between Timer1 and OSC1
(HS, XT, LP) ...................................................... 26
Transition Between Timer1 and OSC1 (RC, EC) ....... 27
Transition from OSC1 to Timer1 Oscillator ................ 26
USART Asynchronous Reception ............................ 207
USART Asynchronous Transmission ....................... 205
USART Asynchronous Transmission
(Back to Back) ................................................. 205
USART Synchronous Receive ( Master/Slave) ....... 339
USART Synchronous Transmission
(Master/Slave) ................................................. 339
Wake-up from Sleep via Interrupt ............................ 253
TRISE Register
PSPMODE Bit .................................................. 111, 128
TSTFSZ ........................................................................... 299
Two-Word Instructions
Example Cases .......................................................... 46
TXSTA Register
BRGH Bit ................................................................. 200
U
Universal Synchronous Asynchronous Receiver
Transmitter. See USART.
USART
Asynchronous Mode ................................................ 204
Associated Registers, Receive ........................ 207
Associated Registers, Transmit ....................... 205
Receiver .......................................................... 206
Setting up 9-bit Mode with Address Detect ..... 206
Transmitter ...................................................... 204
Baud Rate Generator (BRG) ................................... 200
Associated Registers ....................................... 200
Baud Rate Error, Calculating ........................... 200
Baud Rate Formula ......................................... 200
Baud Rates for Asynchronous Mode
(BRGH = 0) .............................................. 202
Baud Rates for Asynchronous Mode
(BRGH = 1) .............................................. 203
Baud Rates for Synchronous Mode ................. 201
High Baud Rate Select (BRGH Bit) ................. 200
Sampling ......................................................... 200
Serial Port Enable (SPEN Bit) ................................. 197
Synchronous Master Mode ...................................... 208
Associated Registers, Reception ..................... 210
Associated Registers, Transmit ....................... 208
Reception ........................................................ 210
Transmission ................................................... 208
Synchronous Slave Mode ........................................ 211
Associated Registers, Receive ........................ 212
Associated Registers, Transmit ....................... 211
Reception ........................................................ 212
Transmission ................................................... 211
USART Synchronous Receive Requirements ................. 339
USART Synchronous Transmission Requirements ......... 339
V
Voltage Reference Specifications .................................... 317
W
Wake-up from Sleep ................................................ 239, 252
Using Interrupts ....................................................... 252
Watchdog Timer (WDT) ........................................... 239, 250
Associated Registers ............................................... 251
Control Register ....................................................... 250
Postscaler ................................................................ 251
Programming Considerations .................................. 250
RC Oscillator ........................................................... 250
Time-out Period ....................................................... 250
WCOL .............................................................................. 185
WCOL Status Flag ................................... 185, 186, 187, 190
WDT Postscaler ............................................................... 250
WWW, On-Line Support ...................................................... 5
X
XORLW ........................................................................... 299
XORWF ........................................................................... 300
DS39609B-page 373
PIC18F6520/8520/6620/8620/6720/8720
NOTES:
DS39609B-page 374
PIC18F6520/8520/6620/8620/6720/8720
ON-LINE SUPPORT
Microchip provides on-line support on the Microchip
World Wide Web site.
The web site is used by Microchip as a means to make
files and information easily available to customers. To
view the site, the user must have access to the Internet
and a web browser, such as Netscape or Microsoft
Internet Explorer. Files are also available for FTP
download from our FTP site.
DS39609B-page 375
PIC18F6520/8520/6620/8620/6720/8720
READER RESPONSE
It is our intention to provide you with the best documentation possible to ensure successful use of your Microchip product. If you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation
can better serve you, please FAX your comments to the Technical Publications Manager at (480) 792-4150.
Please list the following information, and use this outline to provide us with your comments about this document.
To:
RE:
Reader Response
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________
Application (optional):
Would you like a reply?
Device: PIC18F6520/8520/6620/8620/6720/8720
Questions:
1. What are the best features of this document?
2. How does this document meet your hardware and software development needs?
3. Do you find the organization of this document easy to follow? If not, why?
4. What additions to the document do you think would enhance the structure and subject?
5. What deletions from the document could be made without affecting the overall usefulness?
DS39609B-page 376
PIC18F6520/8520/6620/8620/6720/8720
PIC18F6520/8520/6620/8620/6720/8720 PRODUCT IDENTIFICATION SYSTEM
To order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office.
PART NO.
Device
Device
X
Temperature
Range
/XX
XXX
Package
Pattern
PIC18F6520/8520/6620/8620/6720/8720(1),
PIC18F6520/8520/6620/8620/6720/8720T(2);
VDD range 4.2V to 5.5V
PIC18LF6520/8520/6620/8620/6720/8720(1),
Examples:
a)
b)
c)
PIC18LF6520/8520/6620/8620/6720/8720T(2);
VDD range 2.0V to 5.5V
Temperature
Range
I
E
=
=
Package
PT
Pattern
DS39609B-page 377
ASIA/PACIFIC
Korea
Corporate Office
Australia
Atlanta
Unit 706B
Wan Tai Bei Hai Bldg.
No. 6 Chaoyangmen Bei Str.
Beijing, 100027, China
Tel: 86-10-85282100
Fax: 86-10-85282104
Boston
2 Lan Drive, Suite 120
Westford, MA 01886
Tel: 978-692-3848
Fax: 978-692-3821
Chicago
333 Pierce Road, Suite 180
Itasca, IL 60143
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
4570 Westgrove Drive, Suite 160
Addison, TX 75001
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Tri-Atria Office Building
32255 Northwestern Highway, Suite 190
Farmington Hills, MI 48334
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
2767 S. Albright Road
Kokomo, IN 46902
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
China - Beijing
China - Chengdu
Rm. 2401-2402, 24th Floor,
Ming Xing Financial Tower
No. 88 TIDU Street
Chengdu 610016, China
Tel: 86-28-86766200
Fax: 86-28-86766599
China - Fuzhou
Unit 28F, World Trade Plaza
No. 71 Wusi Road
Fuzhou 350001, China
Tel: 86-591-7503506
Fax: 86-591-7503521
China - Shanghai
Room 701, Bldg. B
Far East International Plaza
No. 317 Xian Xia Road
Shanghai, 200051
Tel: 86-21-6275-5700
Fax: 86-21-6275-5060
China - Shenzhen
Phoenix
China - Shunde
San Jose
China - Qingdao
Toronto
6285 Northam Drive, Suite 108
Mississauga, Ontario L4V 1X5, Canada
Tel: 905-673-0699
Fax: 905-673-6509
India
Divyasree Chambers
1 Floor, Wing A (A3/A4)
No. 11, OShaugnessey Road
Bangalore, 560 025, India
Tel: 91-80-2290061 Fax: 91-80-2290062
Japan
Benex S-1 6F
3-18-20, Shinyokohama
Kohoku-Ku, Yokohama-shi
Kanagawa, 222-0033, Japan
Tel: 81-45-471- 6166 Fax: 81-45-471-6122
DS39609B-page 378
Singapore
200 Middle Road
#07-02 Prime Centre
Singapore, 188980
Tel: 65-6334-8870 Fax: 65-6334-8850
Taiwan
Kaohsiung Branch
30F - 1 No. 8
Min Chuan 2nd Road
Kaohsiung 806, Taiwan
Tel: 886-7-536-4818
Fax: 886-7-536-4803
Taiwan
Taiwan Branch
11F-3, No. 207
Tung Hua North Road
Taipei, 105, Taiwan
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPE
Austria
Durisolstrasse 2
A-4600 Wels
Austria
Tel: 43-7242-2244-399
Fax: 43-7242-2244-393
Denmark
Regus Business Centre
Lautrup hoj 1-3
Ballerup DK-2750 Denmark
Tel: 45-4420-9895 Fax: 45-4420-9910
France
Parc dActivite du Moulin de Massy
43 Rue du Saule Trapu
Batiment A - ler Etage
91300 Massy, France
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Germany
Steinheilstrasse 10
D-85737 Ismaning, Germany
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Italy
Via Quasimodo, 12
20025 Legnano (MI)
Milan, Italy
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands
P. A. De Biesbosch 14
NL-5152 SC Drunen, Netherlands
Tel: 31-416-690399
Fax: 31-416-690340
United Kingdom
505 Eskdale Road
Winnersh Triangle
Wokingham
Berkshire, England RG41 5TU
Tel: 44-118-921-5869
Fax: 44-118-921-5820
01/08/04