Escolar Documentos
Profissional Documentos
Cultura Documentos
PIC18FXX8
Data Sheet
High Performance, 28/40-Pin
Enhanced FLASH Microcontrollers
with CAN
Preliminary
DS41159B
Note the following details of the code protection feature on PICmicro MCUs.
The PICmicro family meets the specifications contained in the Microchip Data Sheet.
Microchip believes that its family of PICmicro microcontrollers is one of the most secure products 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 PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.
The person doing so may be 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 product.
If you have any further questions about this matter, please contact the local sales office nearest to you.
Trademarks
The Microchip name and logo, the Microchip logo, FilterLab,
KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER,
PICSTART, PRO MATE, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, microPort,
Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,
MXDEV, MXLAB, PICC, PICDEM, PICDEM.net, rfPIC, Select
Mode and Total Endurance are trademarks of Microchip
Technology Incorporated in the U.S.A.
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.
2002, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
DS41159B - page ii
Preliminary
PIC18FXX8
Peripheral Features:
High current sink/source 25 mA/25 mA
Three external interrupt pins
Timer0 module: 8-bit/16-bit timer/counter with
8-bit programmable prescaler
Timer1 module: 16-bit timer/counter
Timer2 module: 8-bit timer/counter with 8-bit
period register (time-base for PWM)
Timer3 module: 16-bit timer/counter
Secondary oscillator clock option - Timer1/Timer3
Capture/Compare/PWM (CCP) modules CCP
pins can be configured as:
- Capture input: 16-bit, max resolution 6.25 ns
- Compare: 16-bit, max resolution 100 ns (TCY)
- PWM output: PWM resolution is 1- to 10-bit
Max. PWM freq. @:8-bit resolution = 156 kHz
10-bit resolution = 39 kHz
Enhanced CCP module which has all the features
of the standard CCP module, but also has the
following features for advanced motor control:
- 1, 2, or 4 PWM outputs
- Selectable PWM polarity
- Programmable PWM deadtime
Master Synchronous Serial Port (MSSP) with two
modes of operation:
- 3-wire SPI (Supports all 4 SPI modes)
- I2C Master and Slave mode
Addressable USART module: Supports Interrupt
on Address bit
FLASH Technology:
Preliminary
DS41159B-page 1
Program Memory
Device
FLASH
(bytes)
Comparators
PIC18FXX8
Data Memory
# Single
SRAM EEPROM
Word
(bytes) (bytes)
Instructions
I/O
10-bit
A/D
(ch)
MSSP
CCP/
ECCP
(PWM)
SPI
Master
I2C
USART
Timers
8/16-bit
PIC18F248
16K
8192
768
256
22
1/0
1/3
PIC18F258
32K
16384
1536
256
22
1/0
1/3
PIC18F448
16K
8192
768
256
33
1/1
1/3
PIC18F458
32K
16384
1536
256
33
1/1
1/3
Pin Diagrams
PDIP
RB7/PGD
RB6/PGC
RB5/PGM
RB4
RB3/CANRX
RB2/CANTX/INT2
RB1/INT1
RB0/INT0
VDD
VSS
RD7/PSP7/P1D
RD6/PSP6/P1C
RD5/PSP5/P1B
RD4/PSP4/ECCP1/P1A
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3/C2INRD2/PSP2/C2IN+
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
6
5
4
3
2
1
44
43
42
41
40
RA3/AN3/VREF+
RA2/AN2/VREFRA1/AN1
RA0/AN0/CVREF
MCLR/VPP
NC
RB7/PGD
RB6/PGC
RB5/PGM
RB4
NC
PLCC
PIC18F448
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PIC18F458
MCLR/VPP
RA0/AN0/CVREF
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS/LVDIN
RE0/AN5/RD
RE1/AN6/WR/C1OUT
RE2/AN7/CS/C2OUT
VDD
VSS
OSC1/CLKI
OSC2/CLKO/RA6
RC0/T1OSO/T1CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0/C1IN+
RD1/PSP1/C1IN-
7
8
9
10
11
12
13
14
15
16
17
PIC18F448
PIC18F458
39
38
37
36
35
34
33
32
31
30
29
RB3/CANRX
RB2/CANTX/INT2
RB1/INT1
RB0/INT0
VDD
VSS
RD7/PSP7/P1D
RD6/PSP6/P1C
RD5/PSP5/P1B
RD4/PSP4/ECCP1/P1A
RC7/RX/DT
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0/C1IN+
RD1/PSP1/C1INRD2/PSP2/C2IN+
RD3/PSP3/C2INRC4/SDI/SDA
RC5/SDO
RC6/TX/CK
NC
18
19
20
21
22
23
24
25
26
27
28
RA4/T0CKI
RA5/AN4/SS/LVDIN
RE0/AN5/RD
RE1/AN6/WR/C1OUT
RE2/AN7/CS/C2OUT
VDD
VSS
OSC1/CLKI
OSC2/CLKO/RA6
RC0/T1OSO/T1CK1
NC
DS41159B-page 2
Preliminary
PIC18FXX8
Pin Diagrams (Continued)
44
43
42
41
40
39
38
37
36
35
34
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
RD3/PSP3/C2INRD2/PSP2/C2IN+
RD1/PSP1/C1INRD0/PSP0/C1IN+
RC3/SCK/SCL
RC2/CCP1
RC1/T1OSI
NC
TQFP
1
2
3
4
5
6
7
8
9
10
11
PIC18F448
PIC18F458
33
32
31
30
29
28
27
26
25
24
23
NC
RC0/T1OSO/T1CKI
OSC2/CLKO/RA6
OSC1/CLKI
VSS
VDD
RE2/AN7/CS/C2OUT
RE1/AN6/WR/C1OUT
RE0//AN5/RD
RA5/AN4/SS/LVDIN
RA4/T0CKI
RA0/AN0/CVREF
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
NC
NC
RB4
RB5/PGM
RB6/PGC
RB7/PGD
MCLR/VPP
12
13
14
15
16
17
18
19
20
21
22
RC7/RX/DT
RD4/PSP4/ECCP1/P1A
RD5/PSP5/P1B
RD6/PSP6/P1C
RD7/PSP7/P1D
VSS
VDD
RB0/INT0
RB1/INT1
RB2/CANTX/INT2
RB3/CANRX
SPDIP, SOIC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PIC18F258
PIC18F258
MCLR/VPP
RA0/AN0/CVREF
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS/LVDIN
VSS
OSC1/CLKI
OSC2/CLKO/RA6
RC0/T1OSO/T1CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
28
27
26
25
24
23
22
21
20
19
18
17
16
15
Preliminary
RB7/PGD
RB6/PGC
RB5/PGM
RB4
RB3/CANRX
RB2/CANTX/INT2
RB1/INT1
RB0/INT0
VDD
VSS
RC7/RX/DT
RC6/TX/CK
RC5/SDO
RC4/SDI/SDA
DS41159B-page 3
PIC18FXX8
Table of Contents
1.0 Device Overview .......................................................................................................................................................................... 7
2.0 Oscillator Configurations ............................................................................................................................................................ 17
3.0 Reset .......................................................................................................................................................................................... 25
4.0 Memory Organization ................................................................................................................................................................. 37
5.0 Data EEPROM Memory ............................................................................................................................................................ 59
6.0 FLASH Program Memory ........................................................................................................................................................... 65
7.0 8 X 8 Hardware Multiplier ........................................................................................................................................................... 75
8.0 Interrupts .................................................................................................................................................................................... 77
9.0 I/O Ports ..................................................................................................................................................................................... 93
10.0 Parallel Slave Port .................................................................................................................................................................... 105
11.0 Timer0 Module ......................................................................................................................................................................... 107
12.0 Timer1 Module ......................................................................................................................................................................... 111
13.0 Timer2 Module ......................................................................................................................................................................... 115
14.0 Timer3 Module ......................................................................................................................................................................... 117
15.0 Capture/Compare/PWM (CCP) Modules ................................................................................................................................. 121
16.0 Enhanced Capture/Compare/PWM (ECCP) Module................................................................................................................ 129
17.0 Master Synchronous Serial Port (MSSP) Module .................................................................................................................... 141
18.0 Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART).............................................................. 181
19.0 CAN Module ............................................................................................................................................................................. 197
20.0 Compatible 10-bit Analog-to-Digital Converter (A/D) Module................................................................................................... 237
21.0 Comparator Module.................................................................................................................................................................. 245
22.0 Comparator Voltage Reference Module ................................................................................................................................... 251
23.0 Low Voltage Detect .................................................................................................................................................................. 255
24.0 Special Features of the CPU .................................................................................................................................................... 261
25.0 Instruction Set Summary .......................................................................................................................................................... 277
26.0 Development Support............................................................................................................................................................... 319
27.0 Electrical Characteristics .......................................................................................................................................................... 325
28.0 DC and AC Characteristics Graphs and Tables ....................................................................................................................... 355
29.0 Packaging Information.............................................................................................................................................................. 357
Appendix A: Data Sheet Revision History.......................................................................................................................................... 365
Appendix B: Device Differences......................................................................................................................................................... 365
Appendix C: Device Migrations .......................................................................................................................................................... 366
Appendix D: Migrating from other PICmicro Devices......................................................................................................................... 366
Appendix E: Development Tool Version Requirements ..................................................................................................................... 367
Index .................................................................................................................................................................................................. 369
On-Line Support................................................................................................................................................................................. 379
Reader Response .............................................................................................................................................................................. 380
PIC18FXX8 Product Identification System......................................................................................................................................... 381
DS41159B-page 4
Preliminary
PIC18FXX8
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.
Preliminary
DS41159B-page 5
PIC18FXX8
NOTES:
DS41159B-page 6
Preliminary
PIC18FXX8
1.0
DEVICE OVERVIEW
2.
3.
1.
2.
3.
4.
4.
PIC18F248
PIC18F258
PIC18F448
PIC18F458
PIC18FX58 devices have twice the FLASH program memory and data RAM of PIC18FX48
devices (32 Kbytes and 1536 bytes vs.
16 Kbytes and 768 bytes, respectively).
TABLE 1-1:
Operating Frequency
Internal Program Bytes
Memory
# of Single Word
Instructions
Data Memory (Bytes)
Data EEPROM Memory (Bytes)
Interrupt Sources
I/O Ports
Timers
Capture/Compare/PWM Modules
Enhanced Capture/Compare/PWM
Modules
Serial Communications
PIC18F248
PIC18F258
PIC18F448
PIC18F458
DC - 40 MHz
16K
8192
DC - 40 MHz
DC - 40 MHz
16K
8192
DC - 40 MHz
768
256
17
Ports A, B, C
4
1
1536
256
17
Ports A, B, C
4
1
32K
16384
768
1536
256
256
21
21
Ports A, B, C, D, E Ports A, B, C, D, E
4
4
1
1
1
1
MSSP, CAN,
MSSP, CAN,
MSSP, CAN,
Addressable
Addressable
Addressable
USART
USART
USART
No
No
Yes
5 input channels 5 input channels
8 input channels
No
No
2
N/A
N/A
Yes
POR, BOR,
POR, BOR,
POR, BOR,
RESET Instruction, RESET Instruction, RESET Instruction,
Stack Full,
Stack Full,
Stack Full,
Stack Underflow
Stack Underflow
Stack Underflow
(PWRT, OST)
(PWRT, OST)
(PWRT, OST)
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
75 Instructions
28-pin SPDIP
28-pin SOIC
75 Instructions
28-pin SPDIP
28-pin SOIC
Preliminary
32K
16384
75 Instructions
40-pin PDIP
44-pin PLCC
44-pin TQFP
MSSP, CAN,
Addressable
USART
Yes
8 input channels
2
Yes
POR, BOR,
RESET Instruction,
Stack Full,
Stack Underflow
(PWRT, OST)
Yes
Yes
Yes
Yes
75 Instructions
40-pin PDIP
44-pin PLCC
44-pin TQFP
DS41159B-page 7
PIC18FXX8
FIGURE 1-1:
Data Bus<8>
PORTA
21 Table Pointer<21>
8
Data RAM
up to 1536 bytes
inc/dec logic
21
RA0/AN0/CVREF
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS/LVDIN
OSC2/CLKO/RA6
Data Latch
Address Latch
21
PCLATU PCLATH
PCU PCH PCL
Program Counter
RB0/INT0
RB1/INT1
RB2/CANTX/INT2
RB3/CANRX
RB4
RB5/PGM
RB6/PGC
RB7/PGD
Address<12>
12
4
BSR
Address Latch
Program Memory
up to 32 Kbytes
PORTB
12
31 Level Stack
4
FSR0 Bank0, F
FSR1
FSR2
12
Data Latch
Decode
Table Latch
inc/dec
logic
PORTC
RC0/T1OSO/T1CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
16
ROM Latch
IR
8
PRODH PRODL
Instruction
Decode &
Control
8 x 8 Multiply
3
OSC2/CLKO/RA6
OSC1/CLKI
T1OSI
T1OSO
Timing
Generation
4X PLL
Precision
Bandgap
Reference
W
8
BITOP
8
Power-up
Timer
Oscillator
Start-up Timer
8
8
8
ALU<8>
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
Test Mode
Select
Bandgap
MCLR
PBOR
PLVD
Data EEPROM
DS41159B-page 8
Timer0
Timer1
CCP1
VDD, VSS
Timer2
USART
Timer3
10-bit
ADC
Synchronous
Serial Port
Preliminary
CAN Module
PIC18FXX8
FIGURE 1-2:
Data RAM
up to 1536 Kbytes
inc/dec logic
21
RA0/AN0/CVREF
RA1/AN1
RA2/AN2/VREFRA3/AN3/VREF+
RA4/T0CKI
RA5/AN4/SS/LVDIN
OSC2/CLKO/RA6
Data Latch
Address Latch
21
PCLATU PCLATH
PCU PCH PCL
Program Counter
RB0/INT0
RB1/INT1
RB2/CANTX/INT2
RB3/CANRX
RB4
RB5/PGM
RB6/PGC
RB7/PGD
12
4
BSR
Address Latch
Program Memory
up to 32 Kbytes
PORTB
12
Address<12>
31 Level Stack
4
FSR0 Bank0, F
FSR1
FSR2
12
Data Latch
Decode
Table Latch
inc/dec
logic
PORTC
RC0/T1OSO/T1CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
16
ROM Latch
IR
PORTD
RD0/PSP0/C1IN+
RD1/PSP1/C1INRD2/PSP2/C2IN+
RD3/PSP3/C2INRD4/PSP4/ECCP1/P1A
RD5/PSP5/P1B
RD6/PSP6/P1C
RD7/PSP7/P1D
PRODH PRODL
Instruction
Decode &
Control
8 x 8 Multiply
OSC2/CLKO/RA6
OSC1/CLKI
Timing
Generation
Oscillator
Start-up Timer
Precision
Bandgap
Reference
PORTE
RE0/AN5/RD
RE1/AN6/WR//C1OUT
RE2/AN7/CS/C2OUT
ALU<8>
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
Test Mode
Select
4X
PLL
W
8
BITOP
8
Power-up
Timer
T1OSI
T1OSO
Bandgap
MCLR
PBOR
PLVD
Data EEPROM
Timer0
Comparators
Timer1
CCP1
VDD, VSS
USART
Timer2
Enhanced
CCP
Timer3
10-bit
ADC
USART
Synchronous
Serial Port
Preliminary
Parallel
Slave Port
CAN Module
DS41159B-page 9
PIC18FXX8
TABLE 1-2:
Pin Name
MCLR/VPP
PIC18F248/258
Pin
Type
PIC18F448/458
SPDIP, SOIC
PDIP
TQFP
PLCC
18
MCLR
VPP
NC
OSC1/CLKI
13
ST
CLKI
10
14
31
15
O
CLKO
RA6
I/O
TTL
Legend:
TTL =
ST =
I
=
P =
DS41159B-page 10
CMOS
Analog
O
OD
Preliminary
Description
14
OSC1
OSC2/CLKO/RA6
OSC2
Buffer
Type
=
=
=
=
PIC18FXX8
TABLE 1-2:
Pin Name
PIC18F248/258
SPDIP, SOIC
Pin
Type
PIC18F448/458
PDIP
TQFP
Buffer
Type
Description
PLCC
PORTA is a bi-directional I/O port.
RA0/AN0/CVREF
RA0
AN0
CVREF
RA1/AN1
RA1
AN1
RA2/AN2/VREFRA2
AN2
VREF-
RA3/AN3/VREF+
RA3
AN3
VREF+
RA4/T0CKI
RA4
19
20
21
22
23
3
I/O
I
O
TTL
Analog
Analog
Digital I/O.
Analog input 0.
Comparator voltage reference
output.
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
TTL/OD
ST
I/O
I
I
I
TTL
Analog
ST
Analog
T0CKI
RA5/AN4/SS/LVDIN
RA5
AN4
SS
LVDIN
24
RA6
Legend:
Digital I/O.
Analog input 4.
SPI slave select input.
Low voltage detect input.
See the OSC2/CLKO/RA6 pin.
TTL =
ST =
I
=
P =
CMOS
Analog
O
OD
Preliminary
=
=
=
=
DS41159B-page 11
PIC18FXX8
TABLE 1-2:
Pin Name
PIC18F248/258
SPDIP, SOIC
Pin
Type
PIC18F448/458
PDIP
TQFP
Buffer
Type
Description
PLCC
PORTB is a bi-directional I/O port.
PORTB can be software
programmed for internal weak
pull-ups on all inputs.
RB0/INT0
RB0
INT0
21
RB1/INT1
RB1
INT1
22
RB2/CANTX/INT2
RB2
CANTX
INT2
23
RB3/CANRX
RB3
CANRX
24
RB4
25
37
14
41
RB5/PGM
RB5
26
38
15
42
33
34
35
36
10
11
36
I/O
I
TTL
ST
Digital I/O.
External interrupt 0.
I/O
I
TTL
ST
Digital I/O.
External interrupt 1.
I/O
O
I
TTL
TTL
ST
Digital I/O.
Transmit signal for CAN bus.
External interrupt 2.
I/O
I
TTL
TTL
Digital I/O.
Receive signal for CAN bus.
I/O
TTL
Digital I/O.
Interrupt-on-change pin.
I/O
TTL
ST
Digital I/O.
Interrupt-on-change pin.
Low voltage ICSP
programming enable.
I/O
TTL
ST
I/O
TTL
I/O
ST
37
38
39
PGM
RB6/PGC
RB6
27
39
16
43
PGC
RB7/PGD
RB7
28
40
17
PGD
Legend:
TTL =
ST =
I
=
P =
DS41159B-page 12
44
CMOS
Analog
O
OD
Preliminary
=
=
=
=
PIC18FXX8
TABLE 1-2:
Pin Name
PIC18F248/258
Pin
Type
PIC18F448/458
SPDIP, SOIC
PDIP
TQFP
PLCC
RC0/T1OSO/T1CKI
RC0
T1OSO
T1CKI
11
15
32
16
RC1/T1OSI
RC1
T1OSI
12
RC2/CCP1
RC2
CCP1
13
RC3/SCK/SCL
RC3
SCK
14
Buffer
Type
Description
16
17
18
35
36
37
15
RC5/SDO
RC5
SDO
16
RC6/TX/CK
RC6
TX
17
23
24
25
42
43
44
Legend:
TTL =
ST =
I
=
P =
18
26
Digital I/O.
Timer1 oscillator output.
Timer1/Timer3 external clock
input.
I/O
I
ST
CMOS
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
ST
I/O
ST
Digital I/O.
USART asynchronous
transmit.
USART synchronous clock
(see RX/DT).
I/O
I
I/O
ST
ST
ST
Digital I/O.
Timer1 oscillator input.
19
20
25
26
27
CK
RC7/RX/DT
RC7
RX
DT
ST
ST
18
SCL
RC4/SDI/SDA
RC4
SDI
SDA
I/O
O
I
29
CMOS
Analog
O
OD
Preliminary
=
=
=
=
Digital I/O.
USART asynchronous receive.
USART synchronous data
(see TX/CK).
DS41159B-page 13
PIC18FXX8
TABLE 1-2:
Pin Name
PIC18F248/258
SPDIP, SOIC
Pin
Type
PIC18F448/458
PDIP
TQFP
Buffer
Type
Description
PLCC
PORTD is a bi-directional I/O port.
These pins have TTL input buffers
when external memory is enabled.
RD0/PSP0/C1IN+
RD0
PSP0
C1IN+
RD1/PSP1/C1INRD1
PSP1
C1IN-
RD2/PSP2/C2IN+
RD2
PSP2
C2IN+
RD3/PSP3/C2INRD3
PSP3
C2IN-
RD4/PSP4/ECCP1/
P1A
RD4
PSP4
ECCP1
P1A
RD5/PSP5/P1B
RD5
PSP5
P1B
RD6/PSP6/P1C
RD6
PSP6
P1C
RD7/PSP7/P1D
RD7
PSP7
P1D
Legend:
TTL =
ST =
I
=
P =
DS41159B-page 14
19
20
21
22
27
28
29
30
38
39
40
41
21
I/O
I/O
I
ST
TTL
Analog
Digital I/O.
Parallel slave port data.
Comparator 1 input.
I/O
I/O
I
ST
TTL
Analog
Digital I/O.
Parallel slave port data.
Comparator 1 input.
I/O
I/O
I
ST
TTL
Analog
Digital I/O.
Parallel slave port data.
Comparator 2 input.
I/O
I/O
I
ST
TTL
Analog
Digital I/O.
Parallel slave port data.
Comparator 2 input.
I/O
I/O
I/O
O
ST
TTL
ST
Digital I/O.
Parallel slave port data.
ECCP1 capture/compare.
ECCP1 PWM output A.
I/O
I/O
O
ST
TTL
Digital I/O.
Parallel slave port data.
ECCP1 PWM output B.
I/O
I/O
O
ST
TTL
Digital I/O.
Parallel slave port data.
ECCP1 PWM output C.
I/O
I/O
O
ST
TTL
Digital I/O.
Parallel slave port data.
ECCP1 PWM output D.
22
23
24
30
31
32
33
CMOS
Analog
O
OD
Preliminary
=
=
=
=
PIC18FXX8
TABLE 1-2:
Pin Name
PIC18F248/258
Pin
Type
PIC18F448/458
SPDIP, SOIC
PDIP
TQFP
PLCC
RE0/AN5/RD
RE0
AN5
RD
25
RE1/AN6/WR/C1OUT
RE1
AN6
WR
Buffer
Type
Description
26
I/O
I
I
ST
Analog
TTL
Digital I/O.
Analog input 5.
Read control for parallel slave
port (see WR and CS pins).
I/O
I
I
ST
Analog
TTL
Analog
Digital I/O.
Analog input 6.
Write control for parallel slave
port (see CS and RD pins).
Comparator 1 output.
I/O
I
I
ST
Analog
TTL
Analog
10
C1OUT
RE2/AN7/CS/C2OUT
RE2
AN7
CS
10
27
11
C2OUT
Digital I/O.
Analog input 7.
Chip select control for parallel
slave port (see RD and WR
pins).
Comparator 2 output.
VSS
19, 8
12, 31
6, 29
13, 34
VDD
20
11, 32
7, 28
12, 35
Legend:
TTL =
ST =
I
=
P =
CMOS
Analog
O
OD
Preliminary
=
=
=
=
DS41159B-page 15
PIC18FXX8
NOTES:
DS41159B-page 16
Preliminary
PIC18FXX8
2.0
OSCILLATOR
CONFIGURATIONS
2.1
Oscillator Types
FIGURE 2-1:
C1(1)
The PIC18FXX8 can be operated in one of eight Oscillator modes, programmable by three configuration bits
(FOSC2, FOSC1, and FOSC0).
1.
2.
3.
4.
LP
XT
HS
HS4
5.
6.
RC
RCIO
7.
8.
EC
ECIO
2.2
Crystal Oscillator/Ceramic
Resonators
Use of a series cut crystal may give a frequency out of the crystal manufacturers
specifications.
OSC1
XTAL
To
Internal
Logic
RF(3)
SLEEP
RS(2)
C2(1)
PIC18FXX8
OSC2
TABLE 2-1:
CRYSTAL/CERAMIC
RESONATOR OPERATION
(HS, XT OR LP OSC
CONFIGURATION)
CERAMIC RESONATORS
Ranges Tested:
Mode
Freq
OSC1
OSC2
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
10 - 68 pF
10 - 68 pF
HS
8.0 MHz
16.0 MHz
10 - 22 pF
10 - 22 pF
TBD
TBD
20.0 MHz
25.0 MHz
TBD
TBD
HS+PLL
4.0 MHz
TBD
TBD
8.0 MHz
10 - 68 pF
10 - 68 pF
10.0 MHz
TBD
TBD
These values are for design guidance only.
See notes following Table 2-2.
Resonators Used:
455 kHz Panasonic EFO-A455K04B
0.3%
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.
Preliminary
DS41159B-page 17
PIC18FXX8
TABLE 2-2:
Osc Type
Crystal
Freq
Cap. Range
C1
Cap. Range
C2
LP
32.0 kHz
33 pF
33 pF
XT
HS
HS+PLL
200 kHz
15 pF
15 pF
200 kHz
47-68 pF
47-68 pF
1.0 MHz
15 pF
15 pF
4.0 MHz
15 pF
15 pF
4.0 MHz
15 pF
15 pF
8.0 MHz
15-33 pF
15-33 pF
20.0 MHz
15-33 pF
15-33 pF
25.0 MHz
TBD
TBD
4.0 MHz
15 pF
15 pF
8.0 MHz
15-33 pF
15-33 pF
10.0 MHz
TBD
TBD
2.3
RC Oscillator
FIGURE 2-2:
RC OSCILLATOR MODE
VDD
Crystals Used
Epson C-001R32.768K-A
20 PPM
200 kHz
20 PPM
1.0 MHz
ECS ECS-10-13-1
50 PPM
CEXT
4.0 MHz
ECS ECS-40-20-1
50 PPM
VSS
8.0 MHz
30 PPM
20.0 MHz
30 PPM
OSC1
FOSC/4
Recommended values:
DS41159B-page 18
PIC18FXX8
REXT
32.0 kHz
Internal
Clock
OSC2/CLKO
3 k REXT 100 k
CEXT > 20 pF
Preliminary
PIC18FXX8
2.4
FIGURE 2-4:
FIGURE 2-3:
Clock from
Ext. System
FOSC/4
PIC18FXX8
OSC2
Clock from
Ext. System
PIC18FXX8
I/O (OSC2)
2.5
HS4 (PLL)
A Phase Locked Loop circuit is provided as a programmable option for users that want to multiply the frequency of the incoming crystal oscillator signal by 4.
For an input clock frequency of 10 MHz, the internal
clock frequency will be multiplied to 40 MHz. This is
useful for customers who are concerned with EMI due
to high frequency crystals.
The PLL can only be enabled when the oscillator configuration bits are programmed for HS mode. If they are
programmed for any other mode, the PLL is not
enabled and the system clock will come directly from
OSC1.
The PLL is one of the modes of the FOSC2:FOSC0
configuration bits. The Oscillator mode is specified during device programming.
A PLL lock timer is used to ensure that the PLL has
locked before device execution starts. The PLL lock
timer has a time-out referred to as TPLL.
FIGURE 2-5:
Phase
Comparator
FIN
Crystal
Osc
OSC1
FOUT
Loop
Filter
VCO
MUX
OSC2
SYSCLK
Divide by 4
Preliminary
DS41159B-page 19
PIC18FXX8
2.6
2.6.1
FIGURE 2-6:
4 x PLL
TOSC/4
Timer 1 Oscillator
T1OSO
MUX
TOSC
OSC1
TT1P
T1OSCEN
Enable
Oscillator
T1OSI
TSCLK
Clock
Source
Clock Source Option
for Other Modules
Note:
REGISTER 2-1:
OSCCON REGISTER
U-0
bit 7
bit 7-1
bit 0
U-0
U-0
U-0
U-0
U-0
U-0
R/W-0
SCS
bit 0
DS41159B-page 20
W = Writable bit
1 = Bit is set
Preliminary
PIC18FXX8
2.6.2
OSCILLATOR TRANSITIONS
The sequence of events that takes place when switching from the Timer1 oscillator to the main oscillator will
depend on the mode of the main oscillator. In addition
to eight clock cycles of the main oscillator, additional
delays may take place.
If the main oscillator is configured for an external crystal (HS, XT, LP), the transition will take place after an
oscillator start-up time (TOST) has occurred. A timing
diagram indicating the transition from the Timer1 oscillator to the main oscillator for HS, XT, and LP modes is
shown in Figure 2-8.
Figure 2-7 shows a timing diagram indicating the transition from the main oscillator to the Timer1 oscillator.
The Timer1 oscillator is assumed to be running all the
time. After the SCS bit is set, the processor is frozen at
the next occurring Q1 cycle. After eight synchronization
cycles are counted from the Timer1 oscillator, operation resumes. No additional delays are required after
the synchronization cycles.
FIGURE 2-7:
Q1 Q2 Q3 Q4 Q1
Q1
Q2
Q4
Q3
Q1
Q2
Q3
Q4
Q1
TT1P
1
T1OSI
Tscs
OSC1
TOSC
Internal
System
Clock
SCS
(OSCCON<0>)
Program
Counter
TDLY
PC
PC + 4
PC + 2
Note 1: Delay on internal system clock is eight oscillator cycles for synchronization.
FIGURE 2-8:
TIMING DIAGRAM FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS, XT, LP)
Q3
Q4
Q1
Q1 Q2 Q3 Q4
TT1P
Q1 Q2 Q3
T1OSI
1
OSC1
TOST
TSCS
OSC2
TOSC
Internal System
Clock
SCS
(OSCCON<0>)
Program
Counter
PC
PC + 2
PC + 4
Preliminary
DS41159B-page 21
PIC18FXX8
If the main oscillator is configured for HS4 (PLL) mode,
an oscillator start-up time (TOST) plus an additional PLL
time-out (TPLL) will occur. The PLL time-out is typically
2 ms and allows the PLL to lock to the main oscillator
frequency. A timing diagram indicating the transition
from the Timer1 oscillator to the main oscillator for HS4
mode is shown in Figure 2-9.
FIGURE 2-9:
TIMING FOR TRANSITION BETWEEN TIMER1 AND OSC1 (HS WITH PLL)
Q4
TT1P
Q1
Q1 Q2 Q3 Q4
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-10:
Q4
Q1
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
TT1P
T1OSI
TOSC
OSC1
OSC2
Internal System
Clock
SCS
(OSCCON<0>)
TSCS
Program
Counter
PC
PC + 2
PC + 4
DS41159B-page 22
Preliminary
PIC18FXX8
2.7
RESET until the device power supply and clock are stable. For additional information on RESET operation,
see Section 3.0.
2.8
Power-up Delays
TABLE 2-3:
OSC Mode
OSC1 Pin
OSC2 Pin
RC
At logic low
RCIO
ECIO
Floating
EC
Floating
At logic low
Note:
See Table 3-1 in Section 3.0, for time-outs due to SLEEP and MCLR Reset.
Preliminary
DS41159B-page 23
PIC18FXX8
NOTES:
DS41159B-page 24
Preliminary
PIC18FXX8
3.0
RESET
FIGURE 3-1:
state on Power-on Reset, MCLR, WDT Reset, Brownout Reset, MCLR Reset during SLEEP and by the
RESET instruction.
Most registers are not affected by a WDT wake-up,
since this is viewed as the resumption of normal operation. Status bits from the RCON register, RI, TO, PD,
POR and BOR are set or cleared differently in different
RESET situations, as indicated in Table 3-2. These bits
are used in software to determine the nature of the
RESET. See Table 3-3 for a full description of the
RESET states of all registers.
A simplified block diagram of the on-chip RESET circuit
is shown in Figure 3-1.
The Enhanced MCU devices have a MCLR noise filter
in the MCLR Reset path. The filter will detect and
ignore small pulses.
A WDT Reset does not drive MCLR pin low.
RESET
Instruction
Stack
Pointer
External Reset
MCLR
SLEEP
WDT
Module
WDT
Time-out
Reset
VDD Rise
Detect
Power-on Reset
VDD
Brown-out
Reset
BOREN
OST/PWRT
OST
Chip_Reset
OSC1
PWRT
On-chip
RC OSC(1)
Enable PWRT
Enable OST(2)
Note 1: This is a separate oscillator from the RC oscillator of the CLKI pin.
2: See Table 3-1 for time-out situations.
Preliminary
DS41159B-page 25
PIC18FXX8
3.1
3.3
3.2
MCLR
FIGURE 3-2:
RECOMMENDED MCLR
CIRCUIT
VDD
PIC18FXX8
R1
1 k (or greater)
MCLR
C1
0.1 F
(not critical)
DS41159B-page 26
3.4
3.5
3.6
Preliminary
PIC18FXX8
3.7
Time-out Sequence
TABLE 3-1:
Oscillator
Configuration
PWRTEN = 0
Brown-out(2)
PWRTEN = 1
Wake-up from
SLEEP or
Oscillator Switch
HS with PLL enabled(1) 72 ms + 1024 TOSC + 2 ms 1024 TOSC + 2 ms 72 ms + 1024 TOSC + 2 ms 1024 TOSC + 2 ms
HS, XT, LP
72 ms + 1024 TOSC
1024 TOSC
72 ms + 1024 TOSC
1024 TOSC
EC
72 ms
72 ms
External RC
72 ms
72 ms
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
TABLE 3-2:
bit 0
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
Condition
WDT Wake-up
Brown-out Reset
Interrupt Wake-up from SLEEP
PC + 2
u--u 00uu
0000h
0--1 11u0
PC + 2(1)
u--u 00uu
Preliminary
DS41159B-page 27
PIC18FXX8
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
DS41159B-page 28
Preliminary
PIC18FXX8
FIGURE 3-6:
0V
1V
MCLR
TDEADTIME
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
OST TIME-OUT
INTERNAL RESET
FIGURE 3-7:
VDD
MCLR
INTERNAL POR
TPWRT
PWRT TIME-OUT
TOST
TPLL
OST TIME-OUT
PLL TIME-OUT
INTERNAL RESET
Preliminary
DS41159B-page 29
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
TOSU
PIC18F2X8 PIC18F4X8
---0 0000
---0 0000
---0 uuuu(3)
TOSH
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu(3)
TOSL
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu(3)
STKPTR
PIC18F2X8 PIC18F4X8
00-0 0000
uu-0 0000
uu-u uuuu(3)
PCLATU
PIC18F2X8 PIC18F4X8
---0 0000
---0 0000
---u uuuu
PCLATH
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
PCL
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
PC + 2(2)
TBLPTRU
PIC18F2X8 PIC18F4X8
--00 0000
--00 0000
--uu uuuu
TBLPTRH
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TBLPTRL
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TABLAT
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
PRODH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PRODL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
INTCON
PIC18F2X8 PIC18F4X8
0000 000x
0000 000u
uuuu uuuu(1)
INTCON2
PIC18F2X8 PIC18F4X8
111- -1-1
111- -1-1
uuuu -u-u(1)
INTCON3
PIC18F2X8 PIC18F4X8
11-- 0-00
11-- 0-00
uu-u u-uu(1)
INDF0
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTINC0
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTDEC0
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PREINC0
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PLUSW0
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
FSR0H
PIC18F2X8 PIC18F4X8
---- 0000
---- 0000
---- uuuu
FSR0L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
WREG
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
INDF1
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTINC1
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTDEC1
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PREINC1
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PLUSW1
PIC18F2X8 PIC18F4X8
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
DS41159B-page 30
Preliminary
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
FSR1H
PIC18F2X8 PIC18F4X8
---- 0000
---- 0000
---- uuuu
FSR1L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
BSR
PIC18F2X8 PIC18F4X8
---- 0000
---- 0000
---- uuuu
INDF2
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTINC2
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
POSTDEC2
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PREINC2
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
PLUSW2
PIC18F2X8 PIC18F4X8
N/A
N/A
N/A
FSR2H
PIC18F2X8 PIC18F4X8
---- 0000
---- 0000
---- uuuu
FSR2L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
STATUS
PIC18F2X8 PIC18F4X8
---x xxxx
---u uuuu
---u uuuu
TMR0H
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR0L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
T0CON
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
OSCCON
PIC18F2X8 PIC18F4X8
---- ---0
---- ---0
---- ---u
LVDCON
PIC18F2X8 PIC18F4X8
--00 0101
--00 0101
--uu uuuu
WDTCON
PIC18F2X8 PIC18F4X8
---- ---0
---- ---0
---- ---u
PIC18F2X8 PIC18F4X8
0--1 11q0
0--1 qquu
u--u qquu
RCON(4)
TMR1H
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR1L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
T1CON
PIC18F2X8 PIC18F4X8
0-00 0000
u-uu uuuu
u-uu uuuu
TMR2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PR2
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
1111 1111
T2CON
PIC18F2X8 PIC18F4X8
-000 0000
-000 0000
-uuu uuuu
SSPBUF
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
SSPADD
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
SSPSTAT
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
SSPCON1
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
SSPCON2
PIC18F2X8 PIC18F4X8
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
Preliminary
DS41159B-page 31
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
ADRESH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADRESL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
ADCON0
PIC18F2X8 PIC18F4X8
0000 00-0
0000 00-0
uuuu uu-u
ADCON1
PIC18F2X8 PIC18F4X8
00-- 0000
00-- 0000
uu-- uuuu
CCPR1H
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCPR1L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
CCP1CON
PIC18F2X8 PIC18F4X8
--00 0000
--00 0000
--uu uuuu
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
ECCPR1H
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
ECCPR1L
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
0000 0000
ECCP1CON
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
0000 0000
ECCP1DEL
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
0000 0000
ECCPAS
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
CVRCON
CMCON
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TMR3H
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TMR3L
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
T3CON
PIC18F2X8 PIC18F4X8
0000 0000
uuuu uuuu
uuuu uuuu
SPBRG
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RCREG
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXREG
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXSTA
PIC18F2X8 PIC18F4X8
0000 -01x
0000 -01u
uuuu -uuu
RCSTA
PIC18F2X8 PIC18F4X8
0000 000x
0000 000u
uuuu uuuu
EEADR
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
EEDATA
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
EECON2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
EECON1
PIC18F2X8 PIC18F4X8
xx-0 x000
uu-0 u000
uu-0 u000
IPR3
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
PIR3
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
PIE3
PIC18F2X8 PIC18F4X8
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
DS41159B-page 32
Preliminary
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
IPR2
PIC18F2X8 PIC18F4X8
-1-1 1111
-1-1 1111
-u-u uuuu
PIR2
PIC18F2X8 PIC18F4X8
-0-0 0000
-0-0 0000
-u-u uuuu(1)
PIE2
PIC18F2X8 PIC18F4X8
-0-0 0000
-0-0 0000
-u-u uuuu
IPR1
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
PIR1
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu(1)
PIE1
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
PIC18F2X8 PIC18F4X8
0000 -111
0000 -111
uuuu -uuu
TRISE
TRISD
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
TRISC
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
TRISB
PIC18F2X8 PIC18F4X8
1111 1111
1111 1111
uuuu uuuu
PIC18F2X8 PIC18F4X8
-111 1111(5)
-111 1111(5)
-uuu uuuu(5)
TRISA(5)
LATE
PIC18F2X8 PIC18F4X8
---- -xxx
---- -uuu
---- -uuu
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATD
LATC
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
LATB
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PIC18F2X8 PIC18F4X8
-xxx xxxx(5)
-uuu uuuu(5)
-uuu uuuu(5)
LATA(5)
PORTE
PIC18F2X8 PIC18F4X8
---- -xxx
---- -000
---- -uuu
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTD
PORTC
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PORTB
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
PIC18F2X8 PIC18F4X8
-x0x 0000(5)
-u0u 0000(5)
-uuu uuuu(5)
PORTA(5)
TXERRCNT
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
RXERRCNT
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
COMSTAT
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
CIOCON
PIC18F2X8 PIC18F4X8
1000 ---1000 ---uuuu ---BRGCON3
PIC18F2X8 PIC18F4X8
-0-- -000
-0-- -000
-u-- -uuu
BRGCON2
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
BRGCON1
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
CANCON
PIC18F2X8 PIC18F4X8
xxxx xxxuuuu uuuuuuu uuuPIC18F2X8 PIC18F4X8
xxx- xxxuuu- uuuuuu- uuuCANSTAT(6)
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
Preliminary
DS41159B-page 33
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
RXB0D7
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D6
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D5
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D4
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D3
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D1
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0D0
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0DLC
PIC18F2X8 PIC18F4X8
0xxx xxxx
0uuu uuuu
uuuu uuuu
RXB0EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0SIDL
PIC18F2X8 PIC18F4X8
xxxx x-xx
uuuu u-uu
uuuu u-uu
RXB0SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB0CON
PIC18F2X8 PIC18F4X8
000- 0000
000- 0000
uuu- uuuu
RXB1D7
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D6
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D5
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D4
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D3
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D1
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1D0
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1DLC
PIC18F2X8 PIC18F4X8
0xxx xxxx
0uuu uuuu
uuuu uuuu
RXB1EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1SIDL
PIC18F2X8 PIC18F4X8
xxxx x0xx
uuuu u0uu
uuuu uuuu
RXB1SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXB1CON
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TXB0D7
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D6
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D5
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D4
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D3
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D1
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0D0
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
DS41159B-page 34
Preliminary
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
TXB0DLC
PIC18F2X8 PIC18F4X8
0x00 xxxx
0u00 uuuu
uuuu uuuu
TXB0EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0SIDL
PIC18F2X8 PIC18F4X8
xxx0 x0xx
uuu0 u0uu
uuuu uuuu
TXB0SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB0CON
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TXB1D7
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D6
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D5
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D4
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D3
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D1
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1D0
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1DLC
PIC18F2X8 PIC18F4X8
0x00 xxxx
0u00 uuuu
uuuu uuuu
TXB1EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1SIDL
PIC18F2X8 PIC18F4X8
xxx0 x0xx
uuu0 u0uu
uuuu uuuu
TXB1SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB1CON
PIC18F2X8 PIC18F4X8
0000 0000
0000 0000
uuuu uuuu
TXB2D7
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D6
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D5
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D4
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D3
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D2
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D1
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2D0
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2DLC
PIC18F2X8 PIC18F4X8
0x00 xxxx
0u00 uuuu
uuuu uuuu
TXB2EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2SIDL
PIC18F2X8 PIC18F4X8
xxx0 x0xx
uuu0 u0uu
uuuu uuuu
TXB2SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
TXB2CON
PIC18F2X8 PIC18F4X8
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
Preliminary
DS41159B-page 35
PIC18FXX8
TABLE 3-3:
Register
Applicable Devices
Power-on Reset,
Brown-out Reset
MCLR Reset
WDT Reset
RESET Instruction
Stack Resets
RXM1EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXM1EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXM1SIDL
PIC18F2X8 PIC18F4X8
xxx- --xx
uuu- --uu
uuu- --uu
RXM1SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXM0EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXM0EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXM0SIDL
PIC18F2X8 PIC18F4X8
xxx- --xx
uuu- --uu
uuu- --uu
RXM0SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF5EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF5EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF5SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF5SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF4EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF4EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF4SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF4SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF3EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF3EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF3SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF3SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF2EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF2EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF2SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF2SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF1EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF1EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF1SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF1SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF0EIDL
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF0EIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
uuuu uuuu
RXF0SIDL
PIC18F2X8 PIC18F4X8
xxx- x-xx
uuu- u-uu
uuu- u-uu
RXF0SIDH
PIC18F2X8 PIC18F4X8
xxxx xxxx
uuuu uuuu
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: Values for CANSTAT also apply to to its other instances (CANSTATRO1 through CANSTATRO4).
DS41159B-page 36
Preliminary
PIC18FXX8
4.0
MEMORY ORGANIZATION
4.1.1
4.1
FIGURE 4-1:
FIGURE 4-2:
PC<20:0>
21
CALL,RCALL,RETURN
RETFIE,RETLW
Stack Level 1
PC<20:0>
21
CALL,RCALL,RETURN
RETFIE,RETLW
Stack Level 1
Stack Level 31
Stack Level 31
RESET Vector
RESET Vector
0000h
0000h
7FFFh
8000h
On-Chip
Program Memory
3FFFh
4000h
Read 0
Read 0
1FFFFFh
200000h
1FFFFFh
200000h
Preliminary
DS41159B-page 37
PIC18FXX8
4.2
4.2.2
4.2.1
TOP-OF-STACK ACCESS
DS41159B-page 38
Preliminary
PIC18FXX8
REGISTER 4-1:
R/C-0
STKUNF
U-0
R/W-0
SP4
bit 7
bit 6
bit 5
R/W-0
SP3
R/W-0
SP2
R/W-0
SP1
R/W-0
SP0
bit 0
Bit 7 and bit 6 need to be cleared following a stack underflow or a stack overflow.
Legend:
FIGURE 4-3:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
C = Clearable bit
TOSH
1Ah
TOSL
34h
Top-of-Stack 001A34h
000D58h
000000h
STKPTR<4:0>
00010
00011
00010
00001
00000(1)
Preliminary
DS41159B-page 39
PIC18FXX8
4.2.3
EXAMPLE 4-1:
4.3
RETURN FAST
SUB1
The POP instruction discards the current TOS by decrementing the stack pointer. The previous value pushed
onto the stack then becomes the TOS value.
4.2.4
4.4
If high priority interrupts are not disabled during low priority interrupts, users must save the key registers in
software during a low priority interrupt.
If no interrupts are used, the fast register stack can be
used to restore the STATUS, WREG and BSR registers
at the end of a subroutine call. To use the fast register
stack for a subroutine call, a fast call instruction
must be executed.
Example 4-1 shows a source code example that uses
the fast register stack.
DS41159B-page 40
Preliminary
PIC18FXX8
4.5
Clocking Scheme/Instruction
Cycle
FIGURE 4-4:
CLOCK/INSTRUCTION CYCLE
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
OSC1
Q1
Internal
Phase
Clock
Q2
Q3
Q4
PC
OSC2/CLKO
(RC Mode)
4.6
PC
PC+2
Instruction Flow/Pipelining
4.7
PC+4
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-3 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).
The CALL and GOTO instructions have an absolute program memory address embedded into the instruction.
Since instructions are always stored on word boundaries, the data contained in the instruction is a word
address. The word address is written to PC<20:1>,
which accesses the desired byte address in program
memory. Instruction #2 in Example 4-3 shows how the
instruction GOTO 000006h is encoded in the program
memory. Program branch instructions that encode a
relative address offset operate in the same manner.
The offset value stored in a branch instruction represents the number of single word instructions by which
the PC will be offset. Section 25.0 provides further
details of the instruction set.
Preliminary
DS41159B-page 41
PIC18FXX8
EXAMPLE 4-2:
1. MOVLW 55h
TCY0
TCY1
Fetch 1
Execute 1
Fetch 2
2. MOVWF PORTB
TCY3
TCY5
Execute 3
Fetch 4
Flush
Fetch SUB_1
Note:
TCY4
Execute 2
Fetch 3
3. BRA SUB_1
4. BSF
TCY2
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.
EXAMPLE 4-3:
Instruction
Opcode
Memory
000007h
0E55h
MOVLW 055h
GOTO 000006h
EF03h, F000h
C123h, F456h
DS41159B-page 42
Address
55h
000008h
0Eh
000009h
03h
00000Ah
EFh
00000Bh
00h
00000Ch
F0h
00000Dh
23h
00000Eh
C1h
00000Fh
56h
000010h
F4h
000011h
000012h
Preliminary
PIC18FXX8
4.7.1
TWO-WORD INSTRUCTIONS
4.8
Lookup Tables
4.8.2
Computed GOTO
Table Reads
4.8.1
COMPUTED GOTO
Lookup table data may be stored as 2 bytes per program word by using table reads and writes. The table
pointer (TBLPTR) specifies the byte address and the
table latch (TABLAT) contains the data that is read
from, or written to, program memory. Data is
transferred to/from program memory, one byte at a
time.
A description of the Table Read/Table Write operation
is shown in Section 6.1.
EXAMPLE 4-4:
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
; is RAM location 0?
REG3
; continue code
Preliminary
DS41159B-page 43
PIC18FXX8
4.9
4.9.1
The register file can be accessed either directly, or indirectly. Indirect addressing operates through the File
Select Registers (FSR). The operation of indirect
addressing is shown in Section 4.12.
Enhanced MCU devices may have banked memory in
the GPR area. GPRs are not initialized by a Power-on
Reset and are unchanged on all other RESETS.
Data RAM is available for use as GPR registers by all
instructions. Bank 15 (F00h to FFFh) contains SFRs.
All other banks of data memory contain GPR registers,
starting with bank 0.
4.9.2
DS41159B-page 44
Preliminary
PIC18FXX8
FIGURE 4-5:
BSR<3:0>
= 0000
= 0001
Access RAM
FFh
00h
GPR
Bank 0
000h
05Fh
060h
0FFh
100h
GPR
Bank 1
1FFh
200h
FFh
00h
GPR
300h
FFh
Access Bank
Access RAM
= 0010
= 1110
Bank 2
to
Bank 14
SFR
Unused
Read 00h
00h
5Fh
60h
FFh
When a = 0,
the BSR is ignored and
the Access Bank is used.
The first 96 bytes are
General Purpose RAM
(from Bank 0).
The next 160 bytes are
Special Function
Registers (from Bank 15).
= 1111
00h
Unused
FFh
SFR
Bank 15
EFFh
F00h
F5Fh
F60h
FFFh
Preliminary
When a = 1,
the BSR is used to specify
the RAM location that the
instruction uses.
DS41159B-page 45
PIC18FXX8
FIGURE 4-6:
BSR<3:0>
= 0000
= 0001
Access RAM
FFh
00h
GPR
Bank 0
GPR
Bank 1
FFh
00h
= 0010
Bank 2
= 0011
1FFh
200h
GPR
2FFh
300h
FFh
00h
Bank 3
GPR
3FFh
400h
FFh
= 0100
= 0101
Bank 4
= 1110
Access Bank
GPR
00h
4FFh
500h
00h
Access Bank low 5Fh
(GPR)
5FFh
600h
60h
Access Bank high FFh
(SFR)
GPR
Bank 5
FFh
= 0110
000h
05Fh
060h
0FFh
100h
Bank 6
to
Bank 14
When a = 0,
the BSR is ignored and the
Access Bank is used.
Unused
Read 00h
00h
SFR
FFh
SFR
Bank 15
EFFh
F00h
F5Fh
F60h
FFFh
DS41159B-page 46
Preliminary
PIC18FXX8
TABLE 4-1:
Address
Address
FFFh TOSU
Name
FDFh
INDF2(2)
POSTINC2(2)
Address
Name
Address
FBFh CCPR1H
Name
F9Fh IPR1
FFEh TOSH
FDEh
FBEh CCPR1L
F9Eh PIR1
FFDh TOSL
FDDh POSTDEC2(2)
FBDh CCP1CON
F9Dh PIE1
FFCh STKPTR
FDCh PREINC2(2)
FBCh ECCPR1H(5)
F9Ch
FFBh PCLATU
(2)
FBBh ECCPR1L(5)
F9Bh
FDBh PLUSW2
(5)
FFAh PCLATH
FDAh FSR2H
FBAh ECCP1CON
F9Ah
FF9h PCL
FD9h FSR2L
FB9h
F99h
F98h
F97h
FF8h TBLPTRU
FD8h STATUS
FB8h
FF7h TBLPTRH
FD7h TMR0H
FB7h ECCP1DEL(5)
FF6h TBLPTRL
FD6h TMR0L
FF5h TABLAT
FD5h T0CON
FF4h PRODH
FD4h
FF3h PRODL
FD3h OSCCON
FF2h INTCON
FF1h INTCON2
FB6h
ECCPAS(5)
F96h TRISE(5)
FB5h
CVRCON(5)
F95h TRISD(5)
FB4h CMCON(5)
F94h TRISC
FB3h TMR3H
F93h TRISB
FD2h LVDCON
FB2h TMR3L
F92h TRISA
FD1h WDTCON
FB1h T3CON
F91h
FF0h INTCON3
FD0h RCON
FB0h
FEFh INDF0(2)
FCFh TMR1H
FAFh SPBRG
(2)
F90h
F8Fh
FEEh POSTINC0
FCEh TMR1L
FAEh RCREG
F8Eh
FEDh POSTDEC0(2)
FCDh T1CON
FADh TXREG
F8Dh LATE(5)
FECh PREINC0(2)
FCCh TMR2
FACh TXSTA
F8Ch LATD(5)
FCBh PR2
FABh RCSTA
F8Bh LATC
FEAh FSR0H
FCAh T2CON
FAAh
FE9h FSR0L
FC9h SSPBUF
FA9h EEADR
FE8h WREG
FC8h SSPADD
FA8h EEDATA
F88h
FE7h INDF1(2)
FC7h SSPSTAT
FA7h EECON2
F87h
FE6h POSTINC1(2)
FC6h SSPCON1
FA6h EECON1
F86h
FE5h POSTDEC1(2)
FC5h SSPCON2
FA5h IPR3
F85h
(2)
FC4h ADRESH
FA4h PIR3
F84h PORTE(5)
PLUSW1(2)
FC3h ADRESL
FA3h PIE3
F83h PORTD(5)
FE2h FSR1H
FC2h ADCON0
FA2h IPR2
F82h PORTC
FE1h FSR1L
FC1h ADCON1
FA1h PIR2
F81h PORTB
FE0h BSR
FC0h
FA0h PIE2
F80h PORTA
FEBh PLUSW0
(2)
FE4h PREINC1
FE3h
F8Ah LATB
F89h LATA
Preliminary
DS41159B-page 47
PIC18FXX8
TABLE 4-1:
Address
F7Fh
Address
F5Fh
Name
Address
F3Fh
(4)
Name
Address
Name
F1Fh RXM1EIDL
F3Eh CANSTATRO3
(4)
F7Eh
F5Eh CANSTATRO1
F7Dh
F5Dh RXB1D7
F3Dh TXB1D7
F1Dh RXM1SIDL
F1Eh RXM1EIDH
F7Ch
F5Ch RXB1D6
F3Ch TXB1D6
F1Ch RXM1SIDH
F7Bh
F5Bh RXB1D5
F3Bh TXB1D5
F1Bh RXM0EIDL
F7Ah
F5Ah RXB1D4
F3Ah TXB1D4
F1Ah RXM0EIDH
F79h
F59h RXB1D3
F39h TXB1D3
F19h RXM0SIDL
F78h
F58h RXB1D2
F38h TXB1D2
F18h RXM0SIDH
F77h
F57h RXB1D1
F37h TXB1D1
F17h RXF5EIDL
F76h TXERRCNT
F56h RXB1D0
F36h TXB1D0
F16h RXF5EIDH
F75h RXERRCNT
F55h RXB1DLC
F35h TXB1DLC
F15h RXF5SIDL
F74h COMSTAT
F54h RXB1EIDL
F34h TXB1EIDL
F14h RXF5SIDH
F73h CIOCON
F53h RXB1EIDH
F33h TXB1EIDH
F13h RXF4EIDL
F72h BRGCON3
F52h RXB1SIDL
F32h TXB1SIDL
F12h RXF4EIDH
F71h BRGCON2
F51h RXB1SIDH
F31h TXB1SIDH
F11h RXF4SIDL
F70h BRGCON1
F50h RXB1CON
F30h TXB1CON
F10h RXF4SIDH
F6Fh CANCON
F4Fh
F2Fh
F0Fh RXF3EIDL
F6Eh CANSTAT
F4Eh CANSTATRO2(4)
F2Eh CANSTATRO4(4)
F0Eh RXF3EIDH
RXB0D7(3)
F4Dh TXB0D7
F2Dh TXB2D7
F0Dh RXF3SIDL
F6Ch RXB0D6(3)
F4Ch TXB0D6
F2Ch TXB2D6
F0Ch RXF3SIDH
F6Bh RXB0D5(3)
F4Bh TXB0D5
F2Bh TXB2D5
F0Bh RXF2EIDL
RXB0D4(3)
F4Ah TXB0D4
F2Ah TXB2D4
F0Ah RXF2EIDH
F69h RXB0D3(3)
F49h TXB0D3
F29h TXB2D3
F09h RXF2SIDL
RXB0D2(3)
F48h TXB0D2
F28h TXB2D2
F08h RXF2SIDH
F67h RXB0D1(3)
F47h TXB0D1
F27h TXB2D1
F07h RXF1EIDL
(3)
F6Dh
F6Ah
F68h
F46h TXB0D0
F26h TXB2D0
F06h RXF1EIDH
F65h RXB0DLC(3)
F45h TXB0DLC
F25h TXB2DLC
F05h RXF1SIDL
RXB0EIDL(3)
F44h TXB0EIDL
F24h TXB2EIDL
F04h RXF1SIDH
F63h RXB0EIDH(3)
F43h TXB0EIDH
F23h TXB2EIDH
F03h RXF0EIDL
RXB0SIDL(3)
F42h TXB0SIDL
F22h TXB2SIDL
F02h RXF0EIDH
F61h RXB0SIDH(3)
F41h TXB0SIDH
F21h TXB2SIDH
F01h RXF0SIDL
(3)
F40h TXB0CON
F20h TXB2CON
F00h RXF0SIDH
F66h RXB0D0
F64h
F62h
F60h RXB0CON
Note:
Shaded registers are available in Bank 15, while the rest are in Access Bank low.
DS41159B-page 48
Preliminary
PIC18FXX8
TABLE 4-2:
File Name
TOSU
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
---0 0000
30, 38
TOSH
0000 0000
30, 38
TOSL
0000 0000
30, 38
00-0 0000
30, 39
STKPTR
STKFUL
STKUNF
PCLATU
bit21(2)
Value on Details on
POR, BOR
Page:
---0 0000
30, 40
PCLATH
0000 0000
30, 40
PCL
0000 0000
30, 40
--00 0000
30, 68
TBLPTRU
bit21(2)
TBLPTRH
0000 0000
30, 68
TBLPTRL
0000 0000
30, 68
TABLAT
0000 0000
30, 68
PRODH
xxxx xxxx
30, 75
PRODL
xxxx xxxx
30, 75
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 000x
30, 79
INTCON2
RBPU
INTEDG0
INTEDG1
TMR0IP
RBIP
111- -1-1
30, 80
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
11-1 0-00
30, 81
INDF0
Uses contents of FSR0 to address data memory - value of FSR0 not changed (not a physical register)
n/a
30, 55
POSTINC0
Uses contents of FSR0 to address data memory - value of FSR0 post-incremented (not a physical register)
n/a
30, 55
POSTDEC0
Uses contents of FSR0 to address data memory - value of FSR0 post-incremented (not a physical register)
n/a
30, 55
PREINC0
Uses contents of FSR0 to address data memory - value of FSR0 pre-incremented (not a physical register)
n/a
30, 55
PLUSW0
Uses contents of FSR0 to address data memory - value of FSR0 offset by W (not a physical register)
n/a
30, 55
---- xxxx
30, 55
INTCON3
FSR0H
FSR0L
xxxx xxxx
30, 55
WREG
Working Register
uuuu uuuu
30, 55
INDF1
Uses contents of FSR1 to address data memory - value of FSR1 not changed (not a physical register)
n/a
30, 55
POSTINC1
Uses contents of FSR1 to address data memory - value of FSR1 post-incremented (not a physical register)
n/a
30, 55
POSTDEC1
Uses contents of FSR1 to address data memory - value of FSR1 post-incremented (not a physical register)
n/a
30, 55
PREINC1
Uses contents of FSR1 to address data memory - value of FSR1 pre-incremented (not a physical register)
n/a
30, 55
PLUSW1
Uses contents of FSR1 to address data memory - value of FSR1 offset by W (not a physical register) -
n/a
30, 55
---- xxxx
31, 55
xxxx xxxx
31, 55
---- 0000
31, 54
FSR1H
FSR1L
BSR
INDF2
Uses contents of FSR2 to address data memory - value of FSR2 not changed (not a physical register)
n/a
31, 55
POSTINC2
Uses contents of FSR2 to address data memory - value of FSR2 post-incremented (not a physical register)
n/a
31, 55
POSTDEC2
Uses contents of FSR2 to address data memory - value of FSR2 post-incremented (not a physical register)
n/a
31, 55
PREINC2
Uses contents of FSR2 to address data memory - value of FSR2 pre-incremented (not a physical register)
n/a
31, 55
PLUSW2
Uses contents of FSR2 to address data memory - value of FSR2 offset by W (not a physical register) -
n/a
31, 55
---- xxxx
31, 55
FSR2H
FSR2L
STATUS
OV
DC
xxxx xxxx
31, 55
---x xxxx
31, 57
TMR0H
0000 0000
31, 109
TMR0L
xxxx xxxx
31, 109
31, 107
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
1111 1111
OSCCON
T0CON
SCS
---- ---0
31, 20
LVDCON
IRVST
LVDEN
LVDL3
LVDL2
LVDL1
LVDL0
--00 0101
31, 257
WDTCON
31, 268
IPEN
RI
TO
PD
POR
RCON
BOR
Preliminary
DS41159B-page 49
PIC18FXX8
TABLE 4-2:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on Details on
POR, BOR
Page:
TMR1H
xxxx xxxx
31, 113
TMR1L
xxxx xxxx
31, 113
T1CON
RD16
TMR2
Timer2 Register
PR2
T2CON
TOUTPS3
T1CKPS1
TOUTPS2
T1CKPS0
TOUTPS1
T1OSCEN
TOUTPS0
T1SYNC
TMR2ON
TMR1CS
31, 111
0000 0000
31, 116
1111 1111
31, 116
31, 115
xxxx xxxx
31, 144
0000 0000
31, 150
SSPBUF
SSPADD
SSP Address Register in I2C Slave mode. SSP Baud Rate Reload Register in I2C Master mode.
SSPSTAT
SMP
CKE
D/A
SSPCON1
SSPCON2
WCOL
SSPOV
GCEN
ACKSTAT
R/W
UA
BF
SSPEN
CKP
SSPM3
SSPM2
SSPM1
SSPM0
ACKDT
ACKEN
RCEN
PEN
RSEN
SEN
ADRESH
ADRESL
ADCON0
ADCON1
ADCS1
ADCS0
CHS2
CHS1
CHS0
GO/DONE
ADON
ADFM
ADCS2
PCFG3
PCFG2
PCFG1
PCFG0
CCPR1H
CCPR1L
CCP1CON
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
0000 0000
31, 153
xxxx xxxx
32, 239
xxxx xxxx
32, 239
0000 00-0
32, 237
00-- 0000
32, 238
xxxx xxxx
32, 122
xxxx xxxx
32, 122
32, 121
32, 131
(1)
ECCPR1H
xxxx xxxx
ECCPR1L(1)
xxxx xxxx
32, 131
32, 129
EDC1B1
EDC1B0
EPDC7
EPDC6
EPDC5
EPDC4
EPDC3
EPDC2
EPDC1
EPDC0
0000 0000
32, 138
ECCPAS(1)
ECCPASE
ECCPAS2
ECCPAS1
ECCPAS0
PSSAC1
PSSAC0
PSSBD1
32, 140
CVRCON(1)
CVREN
CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
0000 0000
32, 251
CMCON(1)
C2OUT
C1OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
0000 0000
32, 245
TMR3H
xxxx xxxx
32, 119
TMR3L
xxxx xxxx
32, 119
T3CON
RD16
T3ECCP1
T3CKPS1
T3CKPS0
T3CCP1
T3SYNC
TMR3CS
32, 117
0000 0000
32, 183
SPBRG
RCREG
0000 0000
32, 189
TXREG
0000 0000
32, 187
TXSTA
CSRC
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 -010
32, 181
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000X
32, 182
EEADR
xxxx xxxx
32, 59
EEDATA
xxxx xxxx
32, 59
EECON2
xxxx xxxx
32, 59
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
IPR3
IRXIP
WAKIP
ERRIP
TXB2IP
TXB1IP
TXB0IP
RXB1IP
RXB0IP
1111 1111
32, 90
PIR3
IRXIF
WAKIF
ERRIF
TXB2IF
TXB1IF
TXB0IF
RXB1IF
RXB0IF
0000 0000
32, 84
PIE3
IRXIE
WAKIE
ERRIE
TXB2IE
TXB1IE
TXB0IE
RXB1IE
RXB0IE
0000 0000
32, 87
IPR2
CMIP
EEIP
BCLIP
LVDIP
33, 89
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
33, 83
PIE2
CMIE
EEIE
BCLIE
LVDIE
33, 86
EECON1
DS41159B-page 50
Preliminary
PIC18FXX8
TABLE 4-2:
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
1111 1111
33, 88
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
33, 82
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
0000 0000
33, 85
IBF
OBF
IBOV
PSPMODE
0000 -111
33, 103
TRISE(1)
TRISD(1)
1111 1111
33, 100
TRISC
1111 1111
33, 98
TRISB
1111 1111
33, 95
--11 1111
33, 93
---- -xxx
33, 102
TRISA(3)
LATE(1)
LATD(1)
xxxx xxxx
33, 100
LATC
xxxx xxxx
33, 98
LATB
xxxx xxxx
33, 95
(3)
LATA
PORTE(1)
-xxx xxxx
33, 93
---- -000
33, 102
PORTD(1)
xxxx xxxx
33, 100
PORTC
xxxx xxxx
33, 98
PORTB
xxxx xxxx
33, 95
(3)
PORTA
TXERRCNT
RXERRCNT
COMSTAT
TEC7
TEC6
REC7
REC6
RXB0OVFL RXB1OVFL
TEC5
TEC4
TEC3
TEC2
TEC1
-x0x 0000
33, 93
TEC0
0000 0000
33, 207
33, 212
REC5
REC4
REC3
REC2
REC1
REC0
0000 0000
TXBO
TXBP
RXBP
TXWARN
RXWARN
EWARN
0000 0000
33, 203
ENDRHI
CANCAP
--00 ----
33, 217
BRGCON3
WAKFIL
33, 217
BRGCON2
SEG2PHTS
SAM
SEG1PH2
SEG1PH1
SEG1PH0
PRSEG2
PRSEG1
33, 216
CIOCON
BRGCON1
CANCON
SJW1
SJW0
BRP5
BRP4
BRP3
BRP2
BRP1
BRP0
0000 0000
33, 215
REQOP2
REQOP1
REQOP0
ABAT
WIN2
WIN1
WIN0
xxxx xxx-
33, 199
ICODE2
ICODE1
ICODE0
xxx- xxx-
33, 200
CANSTAT
RXB0D7
RXB0D77
RXB0D76
RXB0D75
RXB0D74
RXB0D73
RXB0D72
34, 211
RXB0D6
RXB0D67
RXB0D66
RXB0D65
RXB0D64
RXB0D63
RXB0D62
34, 211
RXB0D5
RXB0D57
RXB0D56
RXB0D55
RXB0D54
RXB0D53
RXB0D52
34, 211
RXB0D4
RXB0D47
RXB0D46
RXB0D45
RXB0D44
RXB0D43
RXB0D42
34, 211
RXB0D3
RXB0D37
RXB0D36
RXB0D35
RXB0D34
RXB0D33
RXB0D32
34, 211
RXB0D2
RXB0D27
RXB0D26
RXB0D25
RXB0D24
RXB0D23
RXB0D22
34, 211
RXB0D1
RXB0D17
RXB0D16
RXB0D15
RXB0D14
RXB0D13
RXB0D12
34, 211
RXB0D0
RXB0D07
RXB0D06
RXB0D05
RXB0D04
RXB0D03
RXB0D02
34, 211
RXB0DLC
RXRTR
RB1
RB0
DLC3
DLC2
DLC1
DLC0
-xxx xxxx
34, 211
RXB0EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
34, 210
34, 210
RXB0EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
RXB0SIDL
SID2
SID1
SID0
SRR
EXID
EID17
EID16
xxxx x-xx
34, 210
RXB0SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
34, 209
RXB0CON
RXFUL
RXM1
RXM0
JTOFF
FILHIT0
000- 0000
34, 208
RXRTRRO RXB0DBEN
Preliminary
DS41159B-page 51
PIC18FXX8
TABLE 4-2:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
ICODE0
Value on Details on
POR, BOR
Page:
ICODE2
ICODE1
xxx- xxx-
33, 200
RXB1D7
RXB1D77
RXB1D76
RXB1D75
RXB1D74
RXB1D73
RXB1D72
34, 211
RXB1D6
RXB1D67
RXB1D66
RXB1D65
RXB1D64
RXB1D63
RXB1D62
34, 211
RXB1D5
RXB1D57
RXB1D56
RXB1D55
RXB1D54
RXB1D53
RXB1D52
34, 211
RXB1D4
RXB1D47
RXB1D46
RXB1D45
RXB1D44
RXB1D43
RXB1D42
34, 211
RXB1D3
RXB1D37
RXB1D36
RXB1D35
RXB1D34
RXB1D33
RXB1D32
34, 211
RXB1D2
RXB1D27
RXB1D26
RXB1D25
RXB1D24
RXB1D23
RXB1D22
34, 211
RXB1D1
RXB1D17
RXB1D16
RXB1D15
RXB1D14
RXB1D13
RXB1D12
34, 211
RXB1D0
RXB1D07
RXB1D06
RXB1D05
RXB1D04
RXB1D03
RXB1D02
34, 211
RXB1DLC
RXRTR
RB1
RB0
DLC3
DLC2
DLC1
DLC0
-xxx xxxx
34, 211
RXB1EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
34, 210
34, 210
RXB1EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
RXB1SIDL
SID2
SID1
SID0
SRR
EXID
EID17
EID16
xxxx x-xx
34, 210
RXB1SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
34, 209
RXB1CON
RXFUL
RXM1
RXM0
RXRTRRO
FILHIT2
FILHIT1
FILHIT0
000- 0000
34, 209
ICODE2
ICODE1
ICODE0
xxx- xxx-
33, 200
TXB0D77
TXB0D76
TXB0D75
TXB0D74
TXB0D73
TXB0D72
TXB0D71
34, 206
TXB0D6
TXB0D67
TXB0D66
TXB0D65
TXB0D64
TXB0D63
TXB0D62
TXB0D61
34, 206
TXB0D5
TXB0D57
TXB0D56
TXB0D55
TXB0D54
TXB0D53
TXB0D52
TXB0D51
34, 206
TXB0D4
TXB0D47
TXB0D46
TXB0D45
TXB0D44
TXB0D43
TXB0D42
TXB0D41
34, 206
34, 206
TXB0D3
TXB0D37
TXB0D36
TXB0D35
TXB0D34
TXB0D33
TXB0D32
TXB0D31
TXB0D2
TXB0D27
TXB0D26
TXB0D25
TXB0D24
TXB0D23
TXB0D22
TXB0D21
34, 206
TXB0D1
TXB0D17
TXB0D16
TXB0D15
TXB0D14
TXB0D13
TXB0D12
TXB0D11
34, 206
TXB0D0
TXB0D07
TXB0D06
TXB0D05
TXB0D04
TXB0D03
TXB0D02
TXB0D01
TXRTR
DLC3
DLC2
DLC1
TXB0DLC
DLC0
-x-- xxxx
34, 206
35, 207
TXB0EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
35, 206
TXB0EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
35, 205
TXB0SIDL
SID2
SID1
SID0
EXIDE
EID17
EID16
xxx- x-xx
35, 205
TXB0SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
35, 205
TXB0CON
TXABT
TXLARB
TXERR
TXREQ
TXPRI1
TXPRI0
-000 0-00
35, 204
ICODE2
ICODE1
ICODE0
xxx- xxx-
33, 200
TXB1D77
TXB1D76
TXB1D75
TXB1D74
TXB1D73
TXB1D72
TXB1D71
35, 206
TXB1D6
TXB1D67
TXB1D66
TXB1D65
TXB1D64
TXB1D63
TXB1D62
TXB1D61
35, 206
TXB1D5
TXB1D57
TXB1D56
TXB1D55
TXB1D54
TXB1D53
TXB1D52
TXB1D51
35, 206
TXB1D4
TXB1D47
TXB1D46
TXB1D45
TXB1D44
TXB1D43
TXB1D42
TXB1D41
35, 206
35, 206
TXB1D3
TXB1D37
TXB1D36
TXB1D35
TXB1D34
TXB1D33
TXB1D32
TXB1D31
TXB1D2
TXB1D27
TXB1D26
TXB1D25
TXB1D24
TXB1D23
TXB1D22
TXB1D21
35, 206
TXB1D1
TXB1D17
TXB1D16
TXB1D15
TXB1D14
TXB1D13
TXB1D12
TXB1D11
35, 206
TXB1D0
TXB1D07
TXB1D06
TXB1D05
TXB1D04
TXB1D03
TXB1D02
TXB1D01
TXRTR
DLC3
DLC2
DLC1
TXB1DLC
DLC0
-x-- xxxx
35, 206
35, 207
TXB1EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
35, 206
TXB1EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
35, 205
TXB1SIDL
SID2
SID1
SID0
EXIDE
EID17
EID16
xxx- x-xx
35, 205
TXB1SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
35, 205
TXB1CON
TXABT
TXLARB
TXERR
TXREQ
TXPRI1
TXPRI0
0000 0000
35, 204
DS41159B-page 52
Preliminary
PIC18FXX8
TABLE 4-2:
File Name
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on Details on
POR, BOR
Page:
ICODE2
ICODE1
ICODE0
xxx- xxx-
33, 200
TXB2D7
TXB2D77
TXB2D76
TXB2D75
TXB2D74
TXB2D73
TXB2D72
TXB2D71
35, 206
TXB2D6
TXB2D67
TXB2D66
TXB2D65
TXB2D64
TXB2D63
TXB2D62
TXB2D61
35, 206
TXB2D5
TXB2D57
TXB2D56
TXB2D55
TXB2D54
TXB2D53
TXB2D52
TXB2D51
35, 206
TXB2D4
TXB2D47
TXB2D46
TXB2D45
TXB2D44
TXB2D43
TXB2D42
TXB2D41
35, 206
TXB2D3
TXB2D37
TXB2D36
TXB2D35
TXB2D34
TXB2D33
TXB2D32
TXB2D31
35, 206
TXB2D2
TXB2D27
TXB2D26
TXB2D25
TXB2D24
TXB2D23
TXB2D22
TXB2D21
35, 206
TXB2D1
TXB2D17
TXB2D16
TXB2D15
TXB2D14
TXB2D13
TXB2D12
TXB2D11
35, 206
TXB2D0
TXB2D07
TXB2D06
TXB2D05
TXB2D04
TXB2D03
TXB2D02
TXB2D01
TXRTR
DLC3
DLC2
DLC1
TXB2DLC
DLC0
-x-- xxxx
35, 206
35, 207
TXB2EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
35, 206
TXB2EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
35, 205
TXB2SIDL
SID2
SID1
SID0
EXIDE
EID17
EID16
xxx- x-xx
35, 205
TXB2SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
35, 205
TXB2CON
TXABT
TXLARB
TXERR
TXREQ
TXPRI1
TXPRI0
-000 0-00
35, 204
RXM1EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 214
RXM1EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 214
RXM1SIDL
SID2
SID1
SID0
EID17
EID16
xxx- --xx
36, 214
RXM1SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 213
RXM0EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 214
RXM0EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 214
RXM0SIDL
SID2
SID1
SID0
EID17
EID16
xxx- --xx
36, 214
RXM0SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 213
RXF5EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF5EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF5SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF5SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
RXF4EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF4EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF4SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF4SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
RXF3EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF3EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF3SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF3SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
RXF2EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF2EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF2SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF2SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
RXF1EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF1EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF1SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF1SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
RXF0EIDL
EID7
EID6
EID5
EID4
EID3
EID2
EID1
EID0
xxxx xxxx
36, 213
RXF0EIDH
EID15
EID14
EID13
EID12
EID11
EID10
EID9
EID8
xxxx xxxx
36, 213
RXF0SIDL
SID2
SID1
SID0
EXIDEN
EID17
EID16
xxx- x-xx
36, 212
RXF0SIDH
SID10
SID9
SID8
SID7
SID6
SID5
SID4
SID3
xxxx xxxx
36, 212
Preliminary
DS41159B-page 53
PIC18FXX8
4.10
Access Bank
4.11
FIGURE 4-7:
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
Bank 1
DS41159B-page 54
Preliminary
PIC18FXX8
4.12
Indirect addressing is a mode of addressing data memory, where the data memory address in the instruction
is not fixed. A SFR register is used as a pointer to the
data memory location that 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-8
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 indicated by the File Select Register, FSR. Reading the INDF register itself, indirectly (FSR
= 0), will read 00h. Writing to the INDF register indirectly,
results in a no operation. The FSR register contains a
12-bit address, which is shown in Figure 4-8.
The INDFn (0 n 2) 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-5 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-5:
NEXT
LFSR
FSR0, 100h ;
CLRF
POSTINC0
BTFSS
FSR0H, 1
BRA
CONTINUE
:
NEXT
;
;
;
;
;
;
;
;
Clear INDF
register
& inc pointer
All done
w/ Bank1?
NO, clear next
YES, continue
4.12.1
INDIRECT ADDRESSING
OPERATION
Preliminary
DS41159B-page 55
PIC18FXX8
FIGURE 4-8:
INDIRECT ADDRESSING
Indirect Addressing
FSR Register
11
FSRnH
FSRnL
Location Select
0000h
Data
Memory(1)
0FFFh
DS41159B-page 56
Preliminary
PIC18FXX8
4.13
STATUS Register
REGISTER 4-2:
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
bit 4
N: Negative bit
This bit is used for signed arithmetic (2s complement). It indicates whether the result of the ALU
operation 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
For borrow, the polarity is reversed. A subtraction is executed by adding the 2s complement of the second operand. For rotate (RRCF, RRNCF, RLCF, and RLNCF)
instructions, this bit is loaded with either the bit 4 or bit 3 of the source register.
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:
For borrow, the polarity is reversed. A subtraction is executed by adding the 2s complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low order bit of the source register.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 57
PIC18FXX8
4.14
RCON Register
REGISTER 4-3:
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
bit 4
bit 3
bit 2
bit 1
bit 0
DS41159B-page 58
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
5.0
5.1
EECON1
EECON2
EEDATA
EEADR
EEADR Register
5.2
Note:
Preliminary
DS41159B-page 59
PIC18FXX8
REGISTER 5-1:
EECON1 REGISTER
R/W-x
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
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
DS41159B-page 60
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
5.3
5.4
EXAMPLE 5-1:
MOVLW
MOVWF
DATA_EE_ADDR
EEADR
BCF
BCS
BSF
MOVF
EECON1,
EECON1,
EECON1,
EEDATA,
EEPGD
CFGS
RD
W
;
;Data Memory Address
;to read
;Point to DATA memory
;
;EEPROM Read
;W = EEDATA
EXAMPLE 5-2:
Required
Sequence
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
0AAh
EECON2
EECON1, WR
INTCON, GIE
;
;
;
;
;
;
;
BCF
EECON1, WREN
Preliminary
DS41159B-page 61
PIC18FXX8
5.5
Write Verify
5.7
5.8
5.6
If Data EEPROM is only used to store constants and/or data that changes rarely, an
array refresh is likely not required. See
specification D124 or D124A.
clrf
bcf
bcf
bcf
bsf
EEADR
EECON1,CFGS
EECON1,EEPGD
INTCON,GIE
EECON1,WREN
bsf
movlw
movwf
movlw
movwf
bsf
btfsc
bra
EECON1,RD
55h
EECON2
AAh
EECON2
EECON1,WR
EECON1,WR
$-2
incfsz
bra
EEADR,F
Loop
; Increment address
; Not zero, do it again
bcf
bsf
EECON1,WREN
INTCON,GIE
; Disable writes
; Enable interrupts
Loop
DS41159B-page 62
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 or D124A. 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 5-3.
Note:
EXAMPLE 5-3:
;
;
;
;
;
;
;
;
;
;
;
;
;
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
Preliminary
PIC18FXX8
TABLE 5-1:
Name
Bit 6
Bit 5
Value on
all other
RESETS
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR, BOR
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
INTCON
EEADR
EEDATA
EECON2
CFGS
FREE
WRERR
WREN
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
PIE2
Legend:
WR
RD
EEPGD
EECON1
Preliminary
DS41159B-page 63
PIC18FXX8
NOTES:
DS41159B-page 64
Preliminary
PIC18FXX8
6.0
6.1
Writing or erasing program memory will cease instruction fetches until the operation is complete. The program memory cannot be accessed during the write or
erase, therefore, code cannot execute. An internal programming timer terminates program memory writes
and erases.
Table Write operations store data from the data memory space into holding registers in program memory.
The procedure to write the contents of the holding registers into program memory is detailed in Section 6.5,
Writing to FLASH Program Memory. Figure 6-2 shows
the operation of a Table Write with program memory
and data RAM.
Table operations work with byte entities. A table block
containing data, rather than program instructions, is not
required to be word aligned. Therefore, a table block
can start and end at any byte address. If a Table Write
is being used to write executable code into program
memory, program instructions will need to be word
aligned.
FIGURE 6-1:
Program Memory
Table Pointer(1)
TBLPTRU
TBLPTRH
Program Memory
(TBLPTR)
Preliminary
DS41159B-page 65
PIC18FXX8
FIGURE 6-2:
Program Memory
Holding Registers
Table Pointer(1)
TBLPTRU
TBLPTRH
TABLAT
Program Memory
(TBLPTR)
Note 1: 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 6.5.
6.2
Control Registers
EECON1 register
EECON2 register
TABLAT register
TBLPTR registers
6.2.1
DS41159B-page 66
Note:
Preliminary
PIC18FXX8
REGISTER 6-1:
EECON1 REGISTER
R/W-x
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
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
Preliminary
x = Bit is unknown
DS41159B-page 67
PIC18FXX8
6.2.2
6.2.4
6.2.3
TABLE 6-1:
TBLRD*
TBLWT*
TBLRD*+
TBLWT*+
TBLRD*TBLWT*TBLRD+*
TBLWT+*
21
Example
FIGURE 6-3:
16
15
TBLPTRH
TBLPTRL
ERASE - TBLPTR<21:6>
WRITE - TBLPTR<21:3>
READ - TBLPTR<21:0>
DS41159B-page 68
Preliminary
PIC18FXX8
6.3
The TBLRD instruction is used to retrieve data from program memory and place into data RAM. Table Reads
from program memory are performed one byte at a
time.
FIGURE 6-4:
Program Memory
TBLPTR = xxxxx1
Instruction Register
(IR)
EXAMPLE 6-1:
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
FETCH
TBLRD
TBLPTR = xxxxx0
TABLAT
Read Register
READ_WORD
TBLRD*+
MOVF TABLAT, W
MOVWF WORD_LSB
TBLRD*+
MOVF TABLAT, W
MOVWF WORD_MSB
Preliminary
DS41159B-page 69
PIC18FXX8
6.4
6.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.
7.
EXAMPLE 6-2:
8.
9.
Note:
upper (CODE_ADDR)
TBLPTRU
high (CODE_ADDR)
TBLPTRH
low (CODE_ADDR)
TBLPTRL
BSF
BCF
BSF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
BSF
EECON1,EEPGD
EECON1,CFGS
EECON1,WREN
EECON1,FREE
INTCON,GIE
55h
EECON2
0AAh
EECON2
EECON1,WR
;
;
;
;
;
ERASE_ROW
Required
Sequence
DS41159B-page 70
INTCON,GIE
; write 55H
;
;
;
;
write 0AAH
start erase (CPU stall)
NOP needed for proper code execution
re-enable interrupts
Preliminary
PIC18FXX8
6.5
5.
6.
7.
8.
9.
10.
11.
12.
The long write is necessary for programming the internal FLASH. Instruction execution is halted while in a
long write cycle. The long write will be terminated by
the internal programming timer.
13.
14.
15.
16.
6.5.1
1.
2.
3.
4.
FIGURE 6-5:
8
TBLPTR = xxxxx0
TBLPTR = xxxxx1
Holding Register
8
TBLPTR = xxxxx2
Holding Register
Holding Register
8
TBLPTR = xxxxx7
Holding Register
Program Memory
Preliminary
DS41159B-page 71
PIC18FXX8
EXAMPLE 6-3:
D64
COUNTER
high (BUFFER_ADDR)
FSR0H
low (BUFFER_ADDR)
FSR0L
upper (CODE_ADDR)
TBLPTRU
high (CODE_ADDR)
TBLPTRH
low (CODE_ADDR)
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
; point to buffer
upper (CODE_ADDR)
TBLPTRU
high (CODE_ADDR)
TBLPTRH
low (CODE_ADDR)
TBLPTRL
EECON1,EEPGD
EECON1,CFGS
EECON1,WREN
EECON1,FREE
INTCON,GIE
55h
EECON2
AAh
EECON2
EECON1,WR
INTCON,GIE
; re-enable interrupts
; dummy read decrement
8
COUNTER_HI
high (BUFFER_ADDR)
FSR0H
low (BUFFER_ADDR)
FSR0L
8
COUNTER
POSTINC0, W
TABLAT
;
;
;
;
;
; point to buffer
READ_BLOCK
;
;
;
;
;
MODIFY_WORD
ERASE_BLOCK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BCF
BSF
BSF
BCF
MOVLW
Required
MOVWF
Sequence
MOVLW
MOVWF
BSF
NOP
BSF
TBLRD*WRITE_BUFFER_BACK
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
PROGRAM_LOOP
MOVLW
MOVWF
WRITE_WORD_TO_HREGS
MOVFW
MOVWF
TBLWT+*
;
;
;
;
;
; write 55H
; write AAH
; start erase (CPU stall)
DECFSZ COUNTER
BRA
WRITE_WORD_TO_HREGS
DS41159B-page 72
; point to buffer
Preliminary
PIC18FXX8
EXAMPLE 6-3:
WRITE_WORD_TO_HREGS
MOVFW
POSTINC0, W
MOVWF
TABLAT
TBLWT+*
;
;
;
;
;
EECON1,EEPGD
EECON1,CFGS
EECON1,WREN
INTCON,GIE
55h
EECON2
0AAh
EECON2
EECON1,WR
;
;
;
;
;
INTCON,GIE
COUNTER_HI
PROGRAM_LOOP
EECON1,WREN
; re-enable interrupts
; loop until done
DECFSZ COUNTER
BRA
WRITE_WORD_TO_HREGS
PROGRAM_MEMORY
Required
Sequence
6.5.2
BSF
BCF
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
NOP
BSF
DECFSZ
BRA
BCF
; write 0AAH
; start program (CPU stall)
6.5.4
WRITE VERIFY
6.5.3
6.6
UNEXPECTED TERMINATION OF
WRITE OPERATION
Preliminary
DS41159B-page 73
PIC18FXX8
TABLE 6-2:
Value on
all other
RESETS
--00 0000
--00 0000
0000 0000
0000 0000
0000 0000
0000 0000
TABLAT
0000 0000
0000 0000
0000 000x
0000 000u
Name
Bit 7
Bit 6
Bit 5
TBLPTRU
bit21
Bit 4
Bit 3
Bit 1
Bit 0
INTCON
EECON2
EECON1
Bit 2
INTE
RBIE
TMR0IF
INTF
RBIF
EEPGD
CFGS
FREE
WRERR
WREN
WR
RD
xx-0 x000
uu-0 u000
IPR2
EEIP
BCLIP
LVDIP
TMR3IP
CCP2IP
---1 1111
---1 1111
PIR2
EEIF
BCLIF
LVDIF
TMR3IF
CCP2IF
---0 0000
---0 0000
PIE2
EEIE
BCLIE
LVDIE
TMR3IE
CCP2IE
---0 0000
---0 0000
Legend:
DS41159B-page 74
Preliminary
PIC18FXX8
7.0
8 X 8 HARDWARE MULTIPLIER
7.2
7.1
Introduction
Operation
EXAMPLE 7-1:
MOVF
MULWF
8 x 8 UNSIGNED
MULTIPLY ROUTINE
ARG1, W
ARG2
;
; ARG1 * ARG2 ->
;
PRODH:PRODL
TABLE 7-1:
8 x 8 SIGNED MULTIPLY
ROUTINE
MOVF
MULWF
ARG1,
ARG2
BTFSC
SUBWF
ARG2,
PRODH
SB
MOVF
BTFSC
SUBWF
ARG2,
ARG1,
PRODH
W
SB
;
;
;
;
;
PERFORMANCE COMPARISON
Routine
8 x 8 unsigned
8 x 8 signed
16 x 16 unsigned
16 x 16 signed
EXAMPLE 7-2:
Program
Memory
(Words)
Cycles
(Max)
13
Hardware multiply
33
Hardware multiply
Multiply Method
Time
@ 40 MHz
@ 10 MHz
@ 4 MHz
69
6.9 s
27.6 s
69 s
100 ns
400 ns
1 s
91
9.1 s
36.4 s
91 s
600 ns
2.4 s
6 s
21
242
24.2 s
96.8 s
242 s
24
24
2.4 s
9.6 s
24 s
52
254
25.4 s
102.6 s
254 s
36
36
3.6 s
14.4 s
36 s
DS41159B-page 75
PIC18FXX8
Example 7-3 shows the sequence to do a 16 x 16
unsigned multiply. Equation 7-1 shows the algorithm
that is used. The 32-bit result is stored in four registers,
RES3:RES0.
EQUATION 7-1:
RES3:RES0
=
=
EXAMPLE 7-3:
MOVF
MULWF
16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
ARG1H:ARG1L ARG2H:ARG2L
(ARG1H ARG2H 216)+
(ARG1H ARG2L 28)+
(ARG1L ARG2H 28)+
(ARG1L ARG2L)
EQUATION 7-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 7-4:
16 x 16 UNSIGNED
MULTIPLY ROUTINE
ARG1L, W
ARG2L
MOVFF
MOVFF
MOVF
MULWF
ARG1H, W
ARG2H
MOVFF
MOVFF
MOVF
MULWF
ARG1L, W
ARG2H
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1
PRODH, W
RES2
WREG
RES3
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1
PRODH, W
RES2
WREG
RES3
DS41159B-page 76
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
PRODH, W
RES2
WREG
RES3
MOVF
MULWF
ARG1H, W
ARG2L
MOVF
ADDWF
MOVF
ADDWFC
CLRF
ADDWFC
PRODL, W
RES1
PRODH, W
RES2
WREG
RES3
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
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
MOVF
MULWF
;
;
;
;
;
;
;
;
;
16 x 16 SIGNED
MULTIPLY ROUTINE
;
; ARG1H * ARG2H ->
; PRODH:PRODL
PRODH, RES3 ;
PRODL, RES2 ;
16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
;
;
;
;
;
;
;
;
;
;
SIGN_ARG1
BTFSS
BRA
MOVF
SUBWF
MOVF
SUBWFB
;
CONT_CODE
:
PIC18FXX8
8.0
INTERRUPTS
RCON
INTCON
INTCON2
INTCON3
PIR1, PIR2, PIR3
PIE1, PIE2, PIE3
IPR1, IPR2, IPR3
It is recommended that the Microchip header files supplied with MPLAB IDE, be used for the symbolic bit
names in these registers. This allows the assembler/
compiler to automatically take care of the placement of
these bits within the specified register.
Each interrupt source has three bits to control its
operation. The functions of these bits are:
Flag bit to indicate that an interrupt event
occurred
Enable bit that allows program execution to
branch to the interrupt vector address when the
flag bit is set
Priority bit to select high priority or low priority
When the IPEN bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with PICmicro mid-range devices. In
Compatibility mode, the interrupt priority bits for each
source have no effect. The PEIE bit (INTCON register)
enables/disables all peripheral interrupt sources. The
GIE bit (INTCON register) enables/disables all interrupt
sources. All interrupts branch to address 000008h in
Compatibility mode.
When an interrupt is responded to, the Global Interrupt
Enable bit is cleared to disable further interrupts. If the
IPEN bit is cleared, this is the GIE bit. If interrupt priority levels are used, this will be either the GIEH or GIEL
bit. High priority interrupt sources can interrupt a low
priority interrupt.
The return address is pushed onto the stack and the
PC is loaded with the interrupt vector address
(000008h or 000018h). Once in the Interrupt Service
Routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. The interrupt
flag bits must be cleared in software before re-enabling
interrupts, to avoid recursive interrupts.
The "return from interrupt" instruction, RETFIE, exits
the interrupt routine and sets the GIE bit (GIEH or GIEL
if priority levels are used), which re-enables interrupts.
For external interrupt events, such as the INT pins or
the PORTB input change interrupt, the interrupt latency
will be three to four instruction cycles. The exact
latency is the same for one or two-cycle instructions.
Individual interrupt flag bits are set, regardless of the
status of their corresponding enable bit, or the GIE bit.
Note:
Preliminary
DS41159B-page 77
PIC18FXX8
FIGURE 8-1:
INTERRUPT LOGIC
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
INT1IF
INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
Interrupt to CPU
Vector to Location
0008h
GIE/GIEH
TMR1IF
TMR1IE
TMR1IP
IPEN
IPEN
GIEL/PEIE
XXXXIF
XXXXIE
XXXXIP
IPEN
Additional Peripheral Interrupts
High Priority Interrupt Generation
Low Priority Interrupt Generation
TMR1IF
TMR1IE
TMR1IP
XXXXIF
XXXXIE
XXXXIP
TMR0IF
TMR0IE
TMR0IP
RBIF
RBIE
RBIP
INT0IF
INT0IE
Interrupt to CPU
Vector to Location
0018h
PEIE/GIEL
GIE/GIEH
INT1IF
Additional Peripheral Interrupts INT1IE
INT1IP
INT2IF
INT2IE
INT2IP
DS41159B-page 78
Preliminary
PIC18FXX8
8.1
INTCON Registers
Note:
The INTCON Registers are readable and writable registers, which contain various enable, priority, and flag
bits. Because of the number of interrupts to be controlled, PIC18FXX8 devices have three INTCON registers. They are detailed in Register 8-1 through
Register 8-3.
REGISTER 8-1:
INTCON REGISTER
R/W-0
R/W-0
GIE/GIEH PEIE/GIEL
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-x
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
bit 7
bit 7
bit 0
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
Preliminary
x = Bit is unknown
DS41159B-page 79
PIC18FXX8
REGISTER 8-2:
INTCON2 REGISTER
R/W-1
RBPU
bit 7
R/W-1
R/W-1
INTEDG0 INTEDG1
U-0
U-0
R/W-1
U-0
TMR0IP
bit 7
bit 6
bit 5
bit 4-3
Unimplmented: Read as 0
bit 2
bit 1
Unimplmented: Read as 0
bit 0
R/W-1
RBIP
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Note:
DS41159B-page 80
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 software polling.
Preliminary
PIC18FXX8
REGISTER 8-3:
INTCON3 REGISTER
R/W-1
R/W-1
U-0
R/W-0
R/W-0
U-0
R/W-0
R/W-0
INT2IP
INT1IP
INT2IE
INT1IE
INT2IF
INT1IF
bit 7
bit 0
bit 7
bit 6
bit 5
Unimplmented: Read as 0
bit 4
bit 3
bit 2
Unimplmented: Read as 0
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 software polling.
Preliminary
DS41159B-page 81
PIC18FXX8
8.2
PIR Registers
The Peripheral Interrupt Request (PIR) registers contain the individual flag bits for the peripheral interrupts
(Register 8-4 through Register 8-6). Due to the number
of peripheral interrupt sources, there are three Peripheral Interrupt Request (Flag) registers (PIR1, PIR2,
PIR3).
REGISTER 8-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
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
DS41159B-page 82
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 8-5:
R/W-0
(1)
CMIF
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
EEIF
BCLIF
LVDIF
TMR3IF
ECCP1IF(1)
bit 7
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 83
PIC18FXX8
REGISTER 8-6:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
IRXIF
WAKIF
ERRIF
TXB2IF
TXB1IF
TXB0IF
RXB1IF
RXB0IF
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS41159B-page 84
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
8.3
PIE Registers
REGISTER 8-7:
PSPIE
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 85
PIC18FXX8
REGISTER 8-8:
R/W-0
CMIE
(1)
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
EEIE
BCLIE
LVDIE
TMR3IE
ECCP1IE(1)
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
DS41159B-page 86
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 8-9:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
IRXIE
WAKIE
ERRIE
TXB2IE
TXB1IE
TXB0IE
RXB1IE
RXB0IE
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
Preliminary
x = Bit is unknown
DS41159B-page 87
PIC18FXX8
8.4
IPR Registers
The Interrupt Priority (IPR) registers contain the individual priority bits for the peripheral interrupts. Due to the
number of peripheral interrupt sources, there are three
Peripheral Interrupt Priority registers (IPR1, IPR2 and
IPR3). The operation of the priority bits requires that
the Interrupt Priority Enable bit (IPEN) be set.
REGISTER 8-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
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
DS41159B-page 88
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 8-11:
R/W-1
(1)
CMIP
U-0
R/W-0
R/W-1
R/W-1
R/W-1
R/W-1
EEIP
BCLIP
LVDIP
TMR3IP
ECCP1IP(1)
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
1:
This bit is only available on PIC18F4X8 devices. For PIC18F2X8 devices, this bit
is unimplemented and reads as 0.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 89
PIC18FXX8
REGISTER 8-12:
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
R/W-1
IRXIP
WAKIP
ERRIP
TXB2IP
TXB1IP
TXB0IP
RXB1IP
RXB0IP
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS41159B-page 90
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
8.5
RCON Register
REGISTER 8-13:
RCON REGISTER
R/W-0
IPEN
bit 7
bit 7
U-0
U-0
R/W-1
R-1
R-1
R/W-0
RI
TO
PD
POR
R/W-0
BOR
bit 0
bit 6-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
Preliminary
x = Bit is unknown
DS41159B-page 91
PIC18FXX8
8.6
INT Interrupts
8.8
8.7
PORTB Interrupt-on-Change
8.9
TMR0 Interrupt
EXAMPLE 8-1:
MOVWF
W_TEMP
MOVFF
STATUS, STATUS_TEMP
MOVFF
BSR, BSR_TEMP
;
; USER ISR CODE
;
MOVFF
BSR_TEMP, BSR
MOVF
W_TEMP, W
MOVFF
STATUS_TEMP, STATUS
DS41159B-page 92
; Restore BSR
; Restore WREG
; Restore STATUS
Preliminary
PIC18FXX8
9.0
I/O PORTS
FIGURE 9-1:
RD LATA
WR LATA or
WR PORTA
Data Bus
9.1
Q
VDD
CK
Data Latch
D
WR TRISA
Analog
Input Mode
CK
VSS
TRIS Latch
RD TRISA
PORTA is a 7-bit wide, bi-directional 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).
On a Power-on Reset, these pins are configured as
inputs and read as '0'.
I/O pin(1)
TTL
Input
Buffer
EN
RD PORTA
SS Input (RA5 only)
To A/D Converter and LVD Modules
Note 1: I/O pins have diode protection to VDD and VSS.
FIGURE 9-2:
RD LATA
Data Bus
WR LATA or
WR PORTA
CK
I/O pin(1)
Data Latch
WR TRISA
CK
VSS
TRIS Latch
TTL
Input
Buffer
Schmitt
Trigger
Input
Buffer
RD TRISA
EXAMPLE 9-1:
CLRF
CLRF
MOVLW
MOVWF
MOVLW
MOVWF
PORTA ;
;
LATA
;
;
07h
;
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 RA3:RA0 as inputs,
RA5:RA4 as outputs
D
EN
RD PORTA
TMR0 Clock Input
Note 1: I/O pin has diode protection to VSS only.
Preliminary
DS41159B-page 93
PIC18FXX8
FIGURE 9-3:
CLKO (FOSC/4)
Oscillator
Circuit
1
Data Latch
Data Bus
WR PORTA
D
CK
VDD
RA6/OSC2/
CLKO pin(2)
TRIS Latch
Q
N
WR TRISA
CK
(FOSC = 100,
101, 110, 111)
VSS
Schmitt
Trigger
Input Buffer
RD TRISA
Q
D
Data Latch
EN
RD PORTA
(FOSC = 110, 100)
Note
TABLE 9-1:
PORTA FUNCTIONS
Name
Bit#
Buffer
Function
RA0/AN0/CVREF
bit0
TTL
RA1/AN1
bit1
TTL
RA2/AN2/VREF-
bit2
TTL
RA3/AN3/VREF+
bit3
TTL
RA4/T0CKI
bit4
RA5/SS/AN4/LVDIN
bit5
TTL
Input/output, slave select input for synchronous serial port, analog input,
or low voltage detect input.
RA6/OSC2/CLKO
bit6
TTL
ST/OD Input/output, external clock input for Timer0, output is open drain type.
TABLE 9-2:
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
PORTA
RA6
RA5
RA4
RA3
RA2
RA1
RA0
LATA
TRISA
Name
ADCON1
ADFM ADCS2
PCFG3
PCFG2
PCFG1
Legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. Shaded cells are not used by PORTA.
DS41159B-page 94
Preliminary
PIC18FXX8
9.2
PORTB is an 8-bit wide, bi-directional 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).
Read-modify-write operations on the LATB register,
read and write the latched output value for PORTB.
EXAMPLE 9-2:
CLRF
PORTB
CLRF
LATB
MOVLW
0CFh
MOVWF
TRISB
INITIALIZING PORTB
;
;
;
;
;
;
;
;
;
;
;
;
FIGURE 9-4:
Initialize PORTB by
clearing output
data latches
Alternate method
to clear output
data latches
Value used to
initialize data
direction
Set RB3:RB0 as inputs
RB5:RB4 as outputs
RB7:RB6 as inputs
Data Bus
WR LATB
or
WR PORTB
Weak
P Pull-up
Data Latch
D
b)
VDD
RBPU(2)
Q
I/O pin(1)
FIGURE 9-5:
CK
TRIS Latch
D
Q
WR TRISB
VDD
RBPU(2)
TTL
Input
Buffer
CK
Weak
P Pull-up
Data Latch
ST
Buffer
Data Bus
Q
I/O pin(1)
WR Port
RD TRISB
D
CK
TRIS Latch
D
Q
RD LATB
Latch
Q
WR TRIS
TTL
Input
Buffer
CK
RD PORTB
EN
Q1
Set RBIF
Q
From other
RB7:RB4 pins
RD TRIS
Q
D
EN
D
EN
Q3
RD Port
RBx/INTx
Note 1: I/O pins have diode protection to VDD and VSS.
2: To enable weak pull-ups, set the appropriate TRIS
bit(s) and clear the RBPU bit (INTCON2 register).
RBx/INTx
Schmitt Trigger
Buffer
Note 1: I/O pins have diode protection to VDD and VSS.
2: To enable weak pull-ups, set the appropriate TRIS
bit(s) and clear the RBPU bit (INTCON2 register).
Preliminary
DS41159B-page 95
PIC18FXX8
FIGURE 9-6:
OPMODE2:OPMODE0 = 000
ENDRHI
CANTX
0
RD LATB
VDD
Data Latch
D
Q
Data Bus
WR PORTB or
WR LATB
CK
1
P
TRIS Latch
D
RB2 pin(1)
Q
N
WR TRISB
CK
Q
VSS
Schmitt
Trigger
RD TRISB
Q
D
EN
RD PORTB
Note 1: I/O pin has diode protection to VDD and VSS.
FIGURE 9-7:
VDD
(2)
P Weak
Pull-up
Data Latch
Data Bus
WR LATB or PORTB
Q
I/O
pin(1)
CK
TRIS Latch
D
Q
WR TRISB
CK
TTL
Input
Buffer
RD TRISB
RD LATB
Q
D
EN
RD PORTB
RB3 or CANRX
Schmitt Trigger
Buffer
Note 1: I/O pins have diode protection to VDD and VSS.
2: To enable weak pull-ups, set the appropriate TRIS bit(s) and clear the RBPU bit (INTCON2<7>).
.
DS41159B-page 96
Preliminary
PIC18FXX8
TABLE 9-3:
Name
PORTB FUNCTIONS
Bit#
Buffer
Function
(1)
RB0/INT0
bit0
TTL/ST
RB1/INT1
bit1
RB2/INT2/
CANTX
bit2
TTL/ST(1) Input/output pin, external interrupt 2 input or CAN bus transmit pin.
Internal software programmable weak pull-up.
RB3/CANRX
bit3
TTL
RB4
bit4
TTL
RB5/PGM
bit5
TTL
RB6/PGC
bit6
RB7/PGD
bit7
TABLE 9-4:
Name
PORTB
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
INTCON
GIE/GIEH PEIE/GIEL
INTCON2
RBPU
INTCON3
INT2IP
RBIE
TMR0IF
INT0IF
RBIF
0000 000x
0000 000u
TMR0IP
RBIP
1111 -1-1
1111 -1-1
INT1IE
INT2IF
INT1IF
11-0 0-00
11-0 0-00
INT1IP
TMR0IE
INT0IE
INT2IE
Preliminary
DS41159B-page 97
PIC18FXX8
9.3
PORTC is an 8-bit wide, bi-directional 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).
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 9-3:
FIGURE 9-8:
CLRF
PORTC
CLRF
LATC
MOVLW
0CFh
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 RC3:RC0 as inputs
RC5:RC4 as outputs
RC7:RC6 as inputs
VDD
RD LATC
Data Bus
WR LATC
or
WR PORTC
1
D
CK
Data Latch
D
WR TRISC
I/O pin(1)
CK
Q
Q
TRIS OVERRIDE
N
VSS
TRIS
Override
TRIS Latch
RD TRISC
Schmitt
Trigger
Peripheral Enable
Q
Pin
Override
RC0
Yes
RC1
Yes
RC2
No
RC3
Yes
SPI/I2C Master
Clock
RC4
Yes
RC5
Yes
RC6
Yes
USART Async
Xmit, Sync Clock
RC7
Yes
USART Sync
Data Out
D
EN
RD PORTC
Peripheral Data In
Peripheral
DS41159B-page 98
Preliminary
PIC18FXX8
TABLE 9-5:
PORTC FUNCTIONS
Name
Bit#
Buffer Type
Function
RC0/T1OSO/T1CKI
bit0
ST
RC1/T1OSI
bit1
ST
RC2/CCP1
bit2
ST
RC3/SCK/SCL
bit3
ST
RC4/SDI/SDA
bit4
ST
Input/output port pin or SPI Data in (SPI mode) or Data I/O (I2C mode).
RC5/SDO
bit5
ST
RC6/TX/CK
bit6
ST
RC7/RX/DT
bit7
ST
TABLE 9-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
Preliminary
DS41159B-page 99
PIC18FXX8
9.4
Note:
on
the
PORTD is an 8-bit wide, bi-directional port. The corresponding Data Direction register for the port 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).
Read-modify-write operations on the LATD register
reads and writes the latched output value for PORTD.
PORTD is uses Schmitt Trigger input buffers. Each pin
is individually configurable as an input or output.
FIGURE 9-9:
PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port, or PSP) by setting
the control bit PSPMODE (TRISE<4>). In this mode,
the input buffers are TTL. See Section 10.0 for
additional information on the Parallel Slave Port.
PORTD is also multiplexed with the analog comparator
module and the ECCP module.
EXAMPLE 9-4:
CLRF
PORTD
CLRF
LATD
MOVLW
MOVWF
MOVLW
07h
CMCON
0CFh
MOVWF
TRISD
INITIALIZING PORTD
;
;
;
;
;
;
;
Initialize PORTD by
clearing output
data latches
Alternate method
to clear output
data latches
comparator off
;
;
;
;
;
;
Value used to
initialize data
direction
Set RD3:RD0 as inputs
RD5:RD4 as outputs
RD7:RD6 as inputs
VDD
P
RD LATD
Data Bus
WR LATD
or
PORTD
D
CK
RD0 pin(1)
Q
N
Data Latch
D
WR TRISD
CK
Vss
TRIS Latch
RD TRISD
PSP Read
Schmitt
Trigger
Q
D
EN
RD PORTD
PSP Write
C1IN+
Note 1: I/O pins have diode protection to VDD and VSS.
DS41159B-page 100
Preliminary
PIC18FXX8
TABLE 9-7:
PORTD FUNCTIONS
Name
Bit#
Buffer Type
(1)
Function
RD0/PSP0/C1IN+
bit0
ST/TTL
RD1/PSP1/C1IN-
bit1
ST/TTL(1)
RD2/PSP2/C2IN+
bit2
ST/TTL(1)
RD3/PSP3/C2IN-
bit3
ST/TTL(1)
RD4/PSP4/ECCP1/P1A
bit4
ST/TTL(1)
RD5/PSP5/P1B
bit5
ST/TTL
(1)
RD6/PSP6/P1C
bit6
ST/TTL(1)
bit7
ST/TTL(1)
RD7/PSP7/P1D
TABLE 9-8:
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
PORTD
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
xxxx xxxx
uuuu uuuu
LATD
xxxx xxxx
uuuu uuuu
TRISD
1111 1111
1111 1111
0000 -111
0000 -111
TRISE
IBF
OBF
IBOV
PSPMODE
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTD.
Preliminary
DS41159B-page 101
PIC18FXX8
9.5
Note:
the
EXAMPLE 9-5:
FIGURE 9-10:
CLRF
PORTE
CLRF
LATE
MOVLW
03h
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
RE2 as an output
(RE4=0 - PSPMODE Off)
P
RD LATE
Data Bus
WR LATE
or
WR PORTE
WR TRISE
1
D
CK
I/O pin(1)
Data Latch
CK
N
VSS
TRIS
Override
TRIS Latch
RD TRISE
Schmitt
Trigger
Peripheral Enable
Q
TRIS OVERRIDE
Pin
Override Peripheral
RE0
Yes
PSP
RD PORTE
RE1
Yes
PSP
Peripheral Data In
RE2
Yes
PSP
EN
DS41159B-page 102
Preliminary
PIC18FXX8
REGISTER 9-1:
TRISE REGISTER
R-0
R-0
R/W-0
R/W-0
U-0
R/W-1
R/W-1
R/W-1
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
TABLE 9-9:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
PORTE FUNCTIONS
Name
Bit#
Buffer Type
Function
RE0/AN5/RD
bit0
ST/TTL(1)
RE1/AN6/WR/C1OUT
bit1
ST/TTL(1)
Input/output port pin, analog input, write control input in Parallel Slave
Port mode or Comparator 1 output.
RE2/AN7/CS/C2OUT
bit2
ST/TTL(1)
Input/output port pin, analog input, chip select control input in Parallel
Slave Port mode or Comparator 2 output.
Preliminary
DS41159B-page 103
PIC18FXX8
TABLE 9-10:
Bit 3
Bit 2
Bit 1
Bit 0
Value on:
POR, BOR
Value on
all other
RESETS
TRISE2
TRISE1
TRISE0
0000 -111
0000 -111
---- -xxx
---- -uuu
---- -xxx
---- -uuu
Name
Bit 7
Bit 6
Bit 5
TRISE
IBF
OBF
IBOV PSPMODE
PORTE
LATE
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTE.
DS41159B-page 104
Preliminary
PIC18FXX8
10.0
Note:
FIGURE 10-1:
Q
RDx pin
CK
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 the
control bit PSPMODE enables the PORTE I/O pins to
become control inputs for the microprocessor port.
When set, port pin RE0 is the RD input, RE1 is the WR
input, and RE2 is 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).
TTL
Data Latch
RD PORTD
D
ENEN
RD LATD
PORTE pins
Read
TTL
RD
Chip Select
TTL
CS
Write
TTL
Note:
FIGURE 10-2:
WR
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
CS
WR
RD
PORTD
IBF
OBF
PSPIF
Preliminary
DS41159B-page 105
PIC18FXX8
FIGURE 10-3:
Q2
Q3
Q4
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
CS
WR
RD
PORTD
IBF
OBF
PSPIF
TABLE 10-1:
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
PORTD
LATD
TRISD
PORTE
LATE
TRISE
INTCON
RE2
RE1
RE0
OBF
IBOV
PSPMODE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
PSPIF
ADIF
RCIF
TXIF
SSPIF
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
PIR1
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Parallel Slave Port.
DS41159B-page 106
Preliminary
PIC18FXX8
11.0
TIMER0 MODULE
REGISTER 11-1:
T0CON 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
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
Preliminary
x = Bit is unknown
DS41159B-page 107
PIC18FXX8
FIGURE 11-1:
RA4/T0CKI
pin(2)
T0SE
1
FOSC/4
0
Programmable
Prescaler
Sync with
Internal
Clocks
TMR0L
(2 TCY delay)
PSA
Set Interrupt
Flag bit TMR0IF
on Overflow
Note 1: Upon RESET, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
2: I/O pins have diode protection to VDD and VSS.
FIGURE 11-2:
T0CKI pin(2)
1
1
T0SE
FOSC/4
0
Programmable
Prescaler
Sync with
Internal
Clocks
TMR0L
TMR0
High Byte
8
(2 TCY delay)
Read TMR0L
Set Interrupt
Flag bit TMR0IF
on Overflow
Write TMR0L
PSA
8
8
TMR0H
8
Data Bus<7:0>
Note 1: Upon RESET, Timer0 is enabled in 8-bit mode with clock input from T0CKI max. prescale.
2: I/O pins have diode protection to VDD and VSS.
DS41159B-page 108
Preliminary
PIC18FXX8
11.1
11.2.1
Timer0 Operation
The prescaler assignment is fully under software control (i.e., it can be changed on-the-fly during program
execution).
11.3
11.4
Prescaler
Name
TABLE 11-1:
Note:
Timer0 Interrupt
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h in 8-bit mode, or FFFFh
to 0000h in 16-bit mode. This overflow sets the TMR0IF
bit. The interrupt can be masked by clearing the
TMR0IE bit. The TMR0IF bit must be cleared in software by the Timer0 module Interrupt Service Routine
before re-enabling this interrupt. The TMR0 interrupt
cannot awaken the processor from SLEEP, since the
timer is shut-off during SLEEP.
11.2
SWITCHING PRESCALER
ASSIGNMENT
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
TMR0L
xxxx xxxx
uuuu uuuu
TMR0H
0000 0000
0000 0000
INTCON
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
0000 000x
0000 000u
T0CON
TMR0ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
1111 1111
1111 1111
--11 1111
--11 1111
TRISA
(1)
Legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. Shaded cells are not used by Timer0.
Note 1: 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 as 0.
Preliminary
DS41159B-page 109
PIC18FXX8
NOTES:
DS41159B-page 110
Preliminary
PIC18FXX8
12.0
TIMER1 MODULE
REGISTER 12-1:
T1CON REGISTER
R/W-0
U-0
RD16
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
T1SYNC
TMR1CS
TMR1ON
bit 7
bit 0
bit 7
bit 6
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
Preliminary
x = Bit is unknown
DS41159B-page 111
PIC18FXX8
12.1
Timer1 Operation
FIGURE 12-1:
TMR1IF
Overflow
Interrupt
Flag bit
TMR1
TMR1H
Synchronized
Clock Input
CLR
TMR1L
1
TMR1ON
On/Off
T1SYNC
T1OSC
T13CKI/T1OSO
T1OSCEN
Enable
Oscillator(1)
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
FOSC/4
Internal
Clock
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 reduces power drain.
FIGURE 12-2:
Data Bus<7:0>
8
TMR1H
8
8
Write TMR1L
Read TMR1L
TMR1IF
Overflow
Interrupt
Flag bit
Timer 1
high byte
Synchronized
Clock Input
TMR1
TMR1L
1
TMR1ON
On/Off
T1SYNC
T1OSC
T13CKI/T1OSO
T1OSI
1
T1OSCEN
Enable
Oscillator(1)
Synchronize
Prescaler
1, 2, 4, 8
FOSC/4
Internal
Clock
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 reduces power drain.
DS41159B-page 112
Preliminary
PIC18FXX8
12.2
Timer1 Oscillator
12.4
TABLE 12-1:
Osc Type
Freq
C1
C2
LP
32 kHz
TBD(1)
TBD(1)
Crystal to be Tested:
20 PPM
12.5
Timer1 Interrupt
TABLE 12-2:
Name
Bit 7
12.3
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.
The high byte of Timer1 is not directly readable or writable in this mode. All reads and writes must take place
through the Timer1 high byte buffer register. Writes to
TMR1H do not clear the Timer1 prescaler. The
prescaler is only cleared on writes to TMR1L.
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
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.
Preliminary
DS41159B-page 113
PIC18FXX8
NOTES:
DS41159B-page 114
Preliminary
PIC18FXX8
13.0
TIMER2 MODULE
13.1
Timer2 Operation
REGISTER 13-1:
T2CON REGISTER
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
TMR2ON
R/W-0
R/W-0
T2CKPS1 T2CKPS0
bit 7
bit 0
bit 7
bit 6-3
bit 2
bit 1-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 115
PIC18FXX8
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
TOUTPS3:TOUTPS0
Note 1: TMR2 register output can be software selected by the SSP Module as a baud clock.
TABLE 13-1:
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
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
TMR2
T2CON
PR2
TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Timer2 module.
DS41159B-page 116
Preliminary
PIC18FXX8
14.0
TIMER3 MODULE
16-bit timer/counter
(Two 8-bit registers: TMR3H and TMR3L)
Readable and writable (both registers)
Internal or external clock select
Interrupt-on-overflow from FFFFh to 0000h
RESET from CCP1/ECCP1 module trigger
REGISTER 14-1:
T3CON REGISTER
R/W-0
RD16
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
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
Preliminary
x = Bit is unknown
DS41159B-page 117
PIC18FXX8
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
CLR
TMR3L
Synchronized
Clock Input
1
TMR3ON
On/Off
T3SYNC
T1OSC
T1OSO/
T13CKI
1
T1OSCEN FOSC/4
Enable
Internal
Oscillator(1) Clock
T1OSI
Synchronize
Prescaler
1, 2, 4, 8
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
TMR3IF Overflow
Interrupt Flag
bit
TMR3
TMR3H
TMR3L
CLR
Synchronized
Clock Input
1
To Timer1 Clock Input
T1OSO/
T13CKI
T1OSI
TMR3ON
On/Off
T3SYNC
T1OSC
1
T1OSCEN
Enable
Oscillator(1)
FOSC/4
Internal
Clock
Prescaler
1, 2, 4, 8
Synchronize
det
0
2
T3CKPS1:T3CKPS0
SLEEP Input
TMR3CS
Note 1: When the T1OSCEN bit is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
DS41159B-page 118
Preliminary
PIC18FXX8
14.2
Timer1 Oscillator
14.4
14.3
Timer3 Interrupt
TABLE 14-1:
INTCON
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 registers pair
becomes the period register for Timer3. Refer to
Section 15.0, Capture/Compare/PWM (CCP) Modules
for CCP details.
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
Value on
POR,
BOR
Value on
all other
RESETS
PIR2
CMIF
EEIF
BCLIF
LVDIF
PIE2
CMIE
EEIE
BCLIE
LVDIE
CMIP
EEIP
BCLIP
LVDIP
IPR2
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
T1CON
T3CON
Legend:
RD16
RD16
T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON 0-00 0000 u-uu uuuu
T3CCP1
x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Timer1 module.
Preliminary
DS41159B-page 119
PIC18FXX8
NOTES:
DS41159B-page 120
Preliminary
PIC18FXX8
15.0
CAPTURE/COMPARE/PWM
(CCP) MODULES
REGISTER 15-1:
CCP1CON REGISTER
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
CCP1M0
bit 7
bit 0
bit 7-6
bit 5-4
bit 3-0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 121
PIC18FXX8
15.1
CCP1 Module
Capture/Compare/PWM Register1 (CCPR1) is comprised of two 8-bit registers: CCPR1L (low byte) and
CCPR1H (high byte). The CCP1CON register controls
the operation of CCP1. All are readable and writable.
15.2.1
TABLE 15-1:
CCP1 Mode
Timer Resource
Capture
Compare
PWM
Timer1 or Timer3
Timer1 or Timer3
Timer2
15.2
Note:
15.2.2
Capture Mode
If the RC2/CCP1 is configured as an output, a write to the port can cause a capture
condition.
TABLE 15-2:
CCP1
Mode
Interaction
Capture
Capture
Capture
Compare
The compare could be configured for the special event trigger, which clears either TMR1
or TMR3, depending upon which time-base is used.
Compare
Compare
The compare(s) could be configured for the special event trigger, which clears TMR1 or
TMR3, depending upon which time-base is used.
PWM
PWM
The PWMs will have the same frequency and update rate (TMR2 interrupt).
PWM
Capture
None.
PWM
Compare
None.
DS41159B-page 122
Preliminary
PIC18FXX8
15.2.3
SOFTWARE INTERRUPT
15.2.5
15.2.4
CCP1 PRESCALER
FIGURE 15-1:
EXAMPLE 15-1:
CHANGING BETWEEN
CAPTURE PRESCALERS
CLRF
MOVLW
CCP1CON, F
NEW_CAPT_PS
MOVWF
CCP1CON
;
;
;
;
;
;
TMR3H
TMR3
Enable
Prescaler
1, 4, 16
CCP1 pin
CCPR1H
and
Edge Detect
TMR3L
CCPR1L
TMR1
Enable
T3ECCP1
T3CCP1
TMR1H
TMR1L
CCP1CON<3:0>
Qs
Preliminary
DS41159B-page 123
PIC18FXX8
15.3
15.3.2
Compare Mode
Driven high
Driven low
Toggle output (high to low or low to high)
Remains unchanged
15.3.3
15.3.4
15.3.1
FIGURE 15-2:
Note:
TMR3H
TMR1L
TMR3L
Q
CCP1
Output Enable
S
R
Output
Logic
T3CCP1
T3ECCP1
Match
Comparator
CCPR1H
CCPR1L
CCP1CON<3:0>
Mode Select
DS41159B-page 124
Preliminary
PIC18FXX8
TABLE 15-3:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
INTCON
GIE/
GIEH
PEIE/
GIEL
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
TRISD
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
CCPR1L
CCPR1H
TMR1CS
CCP1CON
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
T3CON
Legend:
RD16
T3CCP1
T3SYNC
TMR3CS
x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by Capture and Timer1.
Preliminary
DS41159B-page 125
PIC18FXX8
15.4
15.4.1
PWM Mode
FIGURE 15-3:
CCP1CON<5:4>
The PWM period is specified by writing to the PR2 register. The PWM period can be calculated using the
following formula.
EQUATION 15-1:
PWM period = [(PR2) + 1] 4 TOSC
(TMR2 prescale value)
PWM frequency is defined as 1 / [PWM period].
When TMR2 is equal to PR2, the following three events
occur on the next increment cycle:
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
Note:
CCPR1L (Master)
CCPR1H (Slave)
15.4.2
R
Comparator
Q
RC2/CCP1
(Note 1)
TMR2
S
TRISC<2>
Comparator
Clear Timer,
Set CCP1 pin and
latch D.C.
PR2
Period
EQUATION 15-2:
PWM OUTPUT
FIGURE 15-4:
PWM PERIOD
Duty Cycle
TMR2 = PR2
TMR2 = Duty Cycle
TMR2 = PR2
DS41159B-page 126
Preliminary
PIC18FXX8
15.4.3
EQUATION 15-3:
1.
F OSC
log ---------------
F PWM
PWM Resolution (max) = -----------------------------bits
log ( 2 )
2.
3.
Note:
4.
TABLE 15-4:
5.
PWM Frequency
2.44 kHz
9.76 kHz
39.06 kHz
156.3 kHz
312.5 kHz
416.6 kHz
16
FFh
FFh
FFh
3Fh
1Fh
17h
10
10
10
5.5
Value on
all other
RESETS
TABLE 15-5:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
INTCON
GIE/
GIEH
PEIE/
GIEL
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
TRISD
TMR2
PR2
T2CON
TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
CCPR1L
CCPR1H
CCP1CON
Legend:
DC1B1
DC1B0
CCP1M3
CCP1M2
CCP1M1
x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PWM and Timer2.
Preliminary
DS41159B-page 127
PIC18FXX8
NOTES:
DS41159B-page 128
Preliminary
PIC18FXX8
16.0
Note:
ENHANCED CAPTURE/
COMPARE/PWM (ECCP)
MODULE
The ECCP (Enhanced Capture/Compare/
PWM) module is only available on
PIC18F448 and PIC18F458 devices.
This module contains a 16-bit register which can operate as a 16-bit Capture register, a 16-bit Compare
register, or a PWM Master/Slave Duty Cycle register.
REGISTER 16-1:
bit 5-4
bit 3-0
for
ECCP1
is
shown
in
ECCP1CON REGISTER
R/W-0
R/W-0
EPWM1M1 EPWM1M0
bit 7
bit 7-6
R/W-0
EDC1B1
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
EDC1B0 ECCP1M3 ECCP1M2 ECCP1M1 ECCP1M0
bit 0
W = Writable bit
1 = Bit is set
Preliminary
DS41159B-page 129
PIC18FXX8
16.1
ECCP1 Module
TABLE 16-2:
ECCP1 Mode
TABLE 16-1:
ECCP1 Mode
Timer Resource
Capture
Compare
PWM
Timer1 or Timer3
Timer1 or Timer3
Timer2
Interaction
Capture
Capture
Capture
Compare
The compare could be configured for the special event trigger, which clears either
TMR1 or TMR3, depending upon which time-base is used.
Compare
Compare
The compare(s) could be configured for the special event trigger, which clears TMR1
or TMR3 depending upon which time-base is used.
PWM
PWM
PWM
Capture
None
PWM
Compare
None
TABLE 16-3:
The PWMs will have the same frequency and update rate (TMR2 interrupt).
RD4
RD5
RD6
RD7
00xx11xx
ECCP1
RD<5>,
PSP<5>
RD<6>,
PSP<6>
RD<7>,
PSP<7>
10xx11xx
P1A
P1B
RD<6>,
PSP<6>
RD<7>,
PSP<7>
x1xx11xx
P1A
P1B
P1C
P1D
ECCP Mode(1)
Legend: x = Dont care. Shaded cells indicate pin assignments not used by ECCP in a given mode.
Note 1: In all cases, the appropriate TRISD bits must be cleared to make the corresponding pin an output.
2: In these modes, the PSP I/O control for PORTD is overridden by P1B, P1C and P1D.
DS41159B-page 130
Preliminary
PIC18FXX8
16.2
Capture Mode
16.3
Compare Mode
16.3.1
Other operational details, including timer selection, output pin configuration and software interrupts, are
exactly the same as the standard CCP module.
16.2.1
TABLE 16-4:
Name
Bit 6
Bit 5
Bit 3
Bit 2
Bit 1
Value on
all other
RESETS
Bit 0
Value on
POR, BOR
RBIF
INT0IE
RBIE
TMR0IF
INT0IF
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
INTCON
Bit 4
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
TMR3L
Holding Register for the Least Significant Byte of the 16-bit TMR3 Register
TMR3H
Holding Register for the Most Significant Byte of the 16-bit TMR3 Register
T3CON
RD16
T3CCP1
T3SYNC
TRISD
ECCPR1L
ECCPR1H
EDC1B0
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the ECCP module and Timer1.
Preliminary
DS41159B-page 131
PIC18FXX8
16.4
When setting up single output PWM operations, users are free to use either of the processes described in Section 15.4.3 or
Section 16.5.8. The latter is more generic,
but will work for either single or multi-output
PWM.
16.5
As before, the user must manually configure the appropriate TRISD bits for output.
16.5.1
Single Output
Half-Bridge Output
Full-Bridge Output, Forward mode
Full-Bridge Output, Reverse mode
FIGURE 16-1:
EPWM1M1<1:0>
ECCP1M<3:0>
4
ECCPR1L
ECCP1/P1A
RD4/PSP4/ECCP1/P1A
TRISD<4>
ECCPR1H (Slave)
P1B
R
Comparator
Output
Controller
RD5/PSP5/P1B
TRISD<5>
RD6/PSP6/P1C
P1C
TMR2
(Note 1)
TRISD<6>
S
P1D
Comparator
PR2
Note:
Clear Timer,
set ECCP1 pin and
latch D.C.
RD7/PSP7/P1D
TRISD<7>
ECCP1DEL
The 8-bit TMR2 register is concatenated with the 2-bit internal Q clock, or 2 bits of the prescaler to create the 10-bit time-base.
DS41159B-page 132
Preliminary
PIC18FXX8
FIGURE 16-2:
ECCP1CON
<7:6>
SIGNAL
PR2+1
DUTY
CYCLE
PERIOD
Delay
Delay
Relationships:
Period = 4 * TOSC * (PR2 + 1) * (TMR2 prescale value)
Duty Cycle = TOSC * (CCPR1L<7:0>:CCP1CON<5:4>) * (TMR2 prescale value)
Delay = 4 * TOSC * ECCP1DEL
Preliminary
DS41159B-page 133
PIC18FXX8
16.5.2
HALF-BRIDGE MODE
FIGURE 16-3:
HALF-BRIDGE PWM
OUTPUT
Period
Period
Duty Cycle
P1A(2)
td
td
P1B(2)
In Half-Bridge Output mode, the programmable deadband delay can be used to prevent shoot-through
current in bridge power devices. The value of register
ECCP1DEL dictates the number of clock cycles before
the output is driven active. If the value is greater than
the duty cycle, the corresponding output remains inactive during the entire cycle. See Section 16.5.4 for
more details of the deadband delay operations.
(1)
(1)
(1)
td = Deadband Delay
Note 1: At this time, the TMR2 register is equal to the
PR2 register.
2: Output signals are shown as asserted high.
FIGURE 16-4:
FET
Driver
+
V
-
P1A
+
Load
FET
Driver
+
V
-
P1B
FET
Driver
P1A
+
FET
Driver
Load
FET
Driver
P1B
V-
DS41159B-page 134
Preliminary
PIC18FXX8
16.5.3
FULL-BRIDGE MODE
In Full-Bridge Output mode, four pins are used as outputs; however, only two outputs are active at a time. In
the Forward mode, pin RD4/PSP4/ECCP1/P1A is continuously active, and pin RD7/PSP7/P1D is modulated.
In the Reverse mode, RD6/PSP6/P1C pin is continuously active, and RD5/PSP5/P1B pin is modulated.
These are illustrated in Figure 16-5.
FIGURE 16-5:
FORWARD MODE
Period
P1A(2)
Duty Cycle
P1B(2)
P1C(2)
P1D(2)
(1)
(1)
REVERSE MODE
Period
Duty Cycle
P1A(2)
P1B(2)
P1C(2)
P1D(2)
(1)
(1)
Note 1: At this time, the TMR2 register is equal to the PR2 register.
Note 2: Output signal is shown as asserted high.
Preliminary
DS41159B-page 135
PIC18FXX8
FIGURE 16-6:
V+
PIC18F448/458
FET
Driver
QB
QD
FET
Driver
P1D
Load
P1C
FET
Driver
P1B
FET
Driver
QA
QC
VP1A
16.5.3.1
Figure 16-8 shows an example where the PWM direction changes from forward to reverse, at a near 100%
duty cycle. At time t1, the output P1A and P1D become
inactive, while output P1C becomes active. In this
example, since the turn off time of the power devices is
longer than the turn on time, a shoot-through current
flows through power devices QB and QD (see
Figure 16-6) for the duration of t. The same phenomenon will occur to power devices QA and QC for PWM
direction change from reverse to forward.
If changing PWM direction at high duty cycle is required
for an application, one of the following requirements
must be met:
1.
2.
DS41159B-page 136
Preliminary
PIC18FXX8
FIGURE 16-7:
SIGNAL
PERIOD
DC
P1A (Active High)
P1B (Active High)
P1C (Active High)
(2)
Note 1: The direction bit in the ECCP1 Control Register (ECCP1CON.EPWM1M1) is written any time during the PWM
cycle.
2: The P1A and P1C signals switch at intervals of TOSC, 4 TOSC or 16 TOSC, depending on the Timer2 prescaler value
earlier when changing direction. The modulated P1B and P1D signals are inactive at this time.
FIGURE 16-8:
REVERSE PERIOD
P1A
P1B
(PWM)
P1C
P1D
(PWM)
ton
External Switch C
toff
External Switch D
Potential
Shoot-Through
Current
t = toff ton
t1
Preliminary
DS41159B-page 137
PIC18FXX8
16.5.4
PROGRAMMABLE DEADBAND
DELAY
16.5.5
SYSTEM IMPLEMENTATION
REGISTER 16-2:
16.5.6
START-UP CONSIDERATIONS
16.5.7
OUTPUT POLARITY
CONFIGURATION
ECCP1DEL 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
EPDC7
EPDC6
EPDC5
EPDC4
EPDC3
EPDC2
EPDC1
EPDC0
bit 7
bit 7-0
bit 0
DS41159B-page 138
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
16.5.8
2.
TABLE 16-5:
3.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
GIE/GIEH
PEIE/GIEL
TMR0IE
INT0IE
RBIE
TMR0IF
INT0IF
RBIF
IPEN
RI
TO
PD
POR
BOR
IPR2
CMIP
EEIP
BCLIP
LVDIP
TMR3IP
PIR2
CMIF
EEIF
BCLIF
LVDIF
TMR3IF
PIE2
CMIE
EEIE
BCLIE
LVDIE
TMR3IE
Name
INTCON
RCON
TMR2
PR2
T2CON
TOUTPS3
TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
TRISD
ECCPR1H
ECCPR1L
ECCPASE ECCPAS2
ECCP1DEL
Legend:
EPDC7
EPDC6
EDC1B1
EDC1B0
ECCPAS1 ECCPAS0
EPDC5
EPDC4
PSSAC0
PSSBD1
EPDC3
EPDC2
EPDC1
x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the ECCP module.
Preliminary
DS41159B-page 139
PIC18FXX8
16.6
REGISTER 16-3:
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
PSSAC1
PSSAC0
PSSBD1
PSSBD0
bit 7
bit 0
bit 7
bit 6-4
bit 3-2
bit 1-0
DS41159B-page 140
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
17.0
17.1
MASTER SYNCHRONOUS
SERIAL PORT (MSSP)
MODULE
17.3
SPI Mode
FIGURE 17-1:
Internal
Data Bus
Master mode
Multi-Master mode
Slave mode
17.2
Read
Write
SSPBUF reg
Control Registers
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
Preliminary
DS41159B-page 141
PIC18FXX8
17.3.1
REGISTERS
REGISTER 17-1:
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
DS41159B-page 142
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
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
Preliminary
x = Bit is unknown
DS41159B-page 143
PIC18FXX8
17.3.2
OPERATION
EXAMPLE 17-1:
MOVWF RXDATA
MOVF TXDATA, W
MOVWF SSPBUF
DS41159B-page 144
Preliminary
PIC18FXX8
17.3.3
17.3.4
TYPICAL CONNECTION
Any serial port function that is not desired may be overridden by programming the corresponding data direction (TRIS) register to the opposite value.
FIGURE 17-2:
SDI
SDI
Shift Register
(SSPSR)
MSb
SDO
LSb
MSb
SCK
Serial Clock
PROCESSOR 1
Shift Register
(SSPSR)
LSb
SCK
PROCESSOR 2
Preliminary
DS41159B-page 145
PIC18FXX8
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, Figure 17-5, and Figure 17-6, where the
MSB is transmitted first. In Master mode, the SPI clock
rate (bit rate) is user programmable to be one of the
following:
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)
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
SDO
(CKE = 1)
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
SDI
(SMP = 0)
bit0
bit7
Input
Sample
(SMP = 0)
SDI
(SMP = 1)
bit0
bit7
Input
Sample
(SMP = 1)
SSPIF
Next Q4 cycle
after Q2
SSPSR to
SSPBUF
DS41159B-page 146
Preliminary
PIC18FXX8
17.3.6
SLAVE MODE
the SDO pin is no longer driven, even if in the middle of a transmitted byte, and becomes a floating
output. External pull-up/pull-down resistors may be
desirable, depending on the application.
Note 1: When the SPI is in Slave mode with SS
pin control enabled (SSPCON<3:0> =
0100), the SPI module will reset if the SS
pin is set to VDD.
2: If the SPI is used in Slave mode with CKE
set, then the SS pin control must be
enabled.
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)
bit7
bit6
bit7
bit0
bit0
bit7
bit7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
after Q2
SSPSR to
SSPBUF
Preliminary
DS41159B-page 147
PIC18FXX8
FIGURE 17-5:
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDO
SDI
(SMP = 0)
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
bit0
bit7
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
SDI
(SMP = 0)
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
bit0
bit7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
after Q2
SSPSR to
SSPBUF
DS41159B-page 148
Preliminary
PIC18FXX8
17.3.8
SLEEP OPERATION
17.3.10
TABLE 17-1:
17.3.9
CKE
0, 0
0, 1
1, 0
1, 1
Name
EFFECTS OF A RESET
TABLE 17-2:
Bit 6
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
TRISF4
TRISF3
TRISF2
TRISF1
TRISF0
INTCON
TRISC
TRISF
SSPBUF
GIE/GIEH PEIE/GIEL
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.
Preliminary
DS41159B-page 149
PIC18FXX8
17.4
I2C Mode
17.4.1
FIGURE 17-7:
Write
Shift
Clock
LSb
MSb
Match Detect
Addr Match
During transmission, the SSPBUF is not double buffered. A write to SSPBUF will write to both SSPBUF and
SSPSR.
SSPADD reg
START and
STOP bit Detect
DS41159B-page 150
SSPSR reg
RC4/
SDI/
SDA
SSPBUF reg
RC3/SCK/SCL
Internal
Data Bus
Read
REGISTERS
Set, Reset
S, P bits
(SSPSTAT reg)
Preliminary
PIC18FXX8
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 IDLE mode.
bit 1
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 151
PIC18FXX8
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:
DS41159B-page 152
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
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
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 153
PIC18FXX8
17.4.2
OPERATION
17.4.3.1
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).
1.
2.
3.
4.
5.
2C
Addressing
6.
7.
8.
9.
DS41159B-page 154
Preliminary
PIC18FXX8
17.4.3.2
Reception
17.4.3.3
Transmission
Preliminary
DS41159B-page 155
DS41159B-page 156
Preliminary
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
PIC18FXX8
I2C SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 7-BIT ADDRESS)
Preliminary
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
PIC18FXX8
DS41159B-page 157
DS41159B-page 158
Preliminary
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
P
Bus Master
terminates
transfer
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
ACK
FIGURE 17-10:
SDA
PIC18FXX8
I2C SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 10-BIT ADDRESS)
Preliminary
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
PIC18FXX8
DS41159B-page 159
PIC18FXX8
17.4.4
CLOCK STRETCHING
17.4.4.3
17.4.4.1
17.4.4.2
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 by the BF flag,
as in 7-bit Slave Transmit mode (see Figure 17-11).
DS41159B-page 160
Preliminary
PIC18FXX8
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
de-asserts clock
WR
SSPCON
Preliminary
DS41159B-page 161
DS41159B-page 162
Preliminary
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
PIC18FXX8
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESS)
Preliminary
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
Note:
ACK
D2
Cleared in software
CKP written to 1
in software
D3
D1 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
PIC18FXX8
DS41159B-page 163
PIC18FXX8
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>)
DS41159B-page 164
Preliminary
PIC18FXX8
17.4.6
MASTER MODE
Note:
In Firmware Controlled Master mode, user code conducts all I 2C bus operations based on START and
STOP bit conditions.
Once Master mode is enabled, the user has six
options.
3.
4.
5.
6.
START condition
STOP condition
Data transfer byte transmitted/received
Acknowledge Transmit
Repeated START
FIGURE 17-16:
Internal
Data Bus
Read
Write
SSPBUF
Baud
Rate
Generator
Shift
Clock
SDA
SDA in
SCL in
Bus Collision
LSb
Preliminary
Clock Cntl
SCL
Receive Enable
SSPSR
MSb
1.
2.
DS41159B-page 165
PIC18FXX8
17.4.6.1
DS41159B-page 166
1.
Preliminary
PIC18FXX8
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 17-3 demonstrates clock rates based on
instruction cycles and the BRG value loaded into
SSPADD.
SSPM3:SSPM0
Reload
SCL
Control
CLKO
TABLE 17-3:
SSPADD<6:0>
Reload
FOSC/4
FCY
FCY*2
BRG Value
FSCL(2)
(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
100kHz
1 MHz
2 MHz
00h
1 MHz(1)
Note 1: The I2C interface does not conform to the 400 kHz I2C 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.
2: Actual frequency will depend on bus conditions.
Preliminary
DS41159B-page 167
PIC18FXX8
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
DS41159B-page 168
Preliminary
PIC18FXX8
17.4.8
17.4.8.1
Note:
FIGURE 17-19:
TBRG
SDA
2nd bit
TBRG
SCL
TBRG
S
Preliminary
DS41159B-page 169
PIC18FXX8
17.4.9
17.4.9.1
FIGURE 17-20:
Set S (SSPSTAT<3>)
Write to SSPCON2
occurs here.
SDA = 1,
SCL (no change)
SDA = 1,
SCL = 1
TBRG
TBRG
TBRG
1st bit
SDA
Write to SSPBUF occurs here
TBRG
SCL
TBRG
Sr = Repeated START
DS41159B-page 170
Preliminary
PIC18FXX8
17.4.10
17.4.10.3
17.4.10.1
BF Status Flag
17.4.11
17.4.11.1
BF Status Flag
17.4.11.2
17.4.11.3
17.4.10.2
Preliminary
DS41159B-page 171
DS41159B-page 172
S
Preliminary
R/W
PEN
SEN
BF (SSPSTAT<0>)
SSPIF
SCL
SDA
A6
A5
A4
A3
A2
A1
Cleared in software
D7
1
SCL held low
while CPU
responds to SSPIF
SSPBUF written
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
PIC18FXX8
I 2C MASTER MODE WAVEFORM (TRANSMISSION, 7 OR 10-BIT ADDRESS)
Preliminary
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
PIC18FXX8
DS41159B-page 173
PIC18FXX8
17.4.12
ACKNOWLEDGE SEQUENCE
TIMING
17.4.13
17.4.12.1
17.4.13.1
FIGURE 17-23:
TBRG
TBRG
SDA
SCL
D0
ACK
SSPIF
Cleared in
software
Cleared in
software
Set SSPIF at the end
of Acknowledge sequence
DS41159B-page 174
Preliminary
PIC18FXX8
FIGURE 17-24:
Write to SSPCON2
Set PEN
Falling edge of
9th clock
TBRG
SCL
SDA
ACK
P
TBRG
TBRG
TBRG
17.4.14
17.4.17
SLEEP OPERATION
2
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
COMMUNICATION, BUS COLLISION
AND BUS ARBITRATION
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 de-asserted, 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 de-asserted, 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.
Preliminary
DS41159B-page 175
PIC18FXX8
FIGURE 17-25:
SDA
SCL
BCLIF
DS41159B-page 176
Preliminary
PIC18FXX8
17.4.17.1
b)
FIGURE 17-26:
SDA
SCL
Set SEN, enable START
condition if SDA = 1, SCL=1
SEN
BCLIF
SSPIF
Preliminary
DS41159B-page 177
PIC18FXX8
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
SCL
TBRG
S
SCL pulled low after BRG
Time-out
SEN
BCLIF
Set SSPIF
SSPIF
SDA = 0, SCL = 1
Set SSPIF
DS41159B-page 178
Preliminary
Interrupts cleared
in software
PIC18FXX8
17.4.17.2
If SCL goes from high to low before the BRG times out
and SDA has not already been asserted, a bus collision
occurs. In this case, another master is attempting to
transmit a data 1 during the Repeated START
condition, Figure 17-30.
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.
FIGURE 17-29:
SDA
SCL
Sample SDA when SCL goes high.
If SDA = 0, set BCLIF and release SDA and SCL.
RSEN
BCLIF
Cleared in software
'0'
'0'
SSPIF
FIGURE 17-30:
TBRG
SDA
SCL
BCLIF
RSEN
0
S
SSPIF
Preliminary
DS41159B-page 179
PIC18FXX8
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
SCL goes low before SDA goes high
Set BCLIF
Assert SDA
SCL
PEN
BCLIF
P
SSPIF
DS41159B-page 180
Preliminary
PIC18FXX8
18.0
ADDRESSABLE UNIVERSAL
SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (USART)
REGISTER 18-1:
TXSTA REGISTER
R/W-0
CSRC
bit 7
bit 7
bit 6
bit 5
bit 3
bit 2
bit 1
bit 0
R/W-0
TX9
R/W-0
TXEN
R/W-0
SYNC
U-0
R/W-0
BRGH
R-1
TRMT
R/W-0
TX9D
bit 0
bit 4
W = Writable bit
1 = Bit is set
Preliminary
DS41159B-page 181
PIC18FXX8
REGISTER 18-2:
RCSTA REGISTER
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R-0
R-0
R-x
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS41159B-page 182
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
18.1
The BRG supports both the Asynchronous and Synchronous modes of the USART. It is a dedicated 8-bit
baud rate generator. The SPBRG register controls the
period of a free running 8-bit timer. In Asynchronous
mode, bit BRGH (TXSTA register) also controls the
baud rate. In Synchronous mode, bit BRGH is ignored.
Table 18-1 shows the formula for computation of the
baud rate for different USART modes, which only apply
in Master mode (internal clock).
Given the desired baud rate and FOSC, the nearest
integer value for the SPBRG register can be calculated
using the formula in Table 18-1. From this, the error in
baud rate can be determined.
FOSC = 16 MHz
Desired Baud Rate = 9600
BRGH = 0
SYNC = 0
It may be advantageous to use the high baud rate
(BRGH = 1), even for slower baud clocks. This is
because the FOSC/(16(X + 1)) equation can reduce the
baud rate error in some cases.
Writing a new value to the SPBRG register causes the
BRG timer to be reset (or cleared). This ensures the
BRG does not wait for a timer overflow before
outputting the new baud rate.
18.1.1
SAMPLING
EXAMPLE 18-1:
Solving for X:
X
X
X
Error
TABLE 18-1:
SYNC
0
1
TABLE 18-2:
Name
TXSTA
RCSTA
SPBRG
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.
Preliminary
DS41159B-page 183
PIC18FXX8
TABLE 18-3:
BAUD
RATE
(Kbps)
FOSC = 40 MHz
SPBRG
value
(decimal)
33 MHz
SPBRG
value
(decimal)
25 MHz
SPBRG
value
(decimal)
20 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
0.3
NA
NA
NA
NA
1.2
NA
NA
NA
NA
2.4
NA
NA
NA
NA
9.6
NA
NA
NA
NA
19.2
NA
NA
NA
NA
76.8
76.92
+0.16
129
77.10
+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
SPBRG
value
(decimal)
10 MHz
SPBRG
value
(decimal)
7.15909 MHz
SPBRG
value
(decimal)
5.0688 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
NA
+0.23
185
9.60
131
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
0.3
NA
NA
NA
1.2
NA
NA
NA
2.4
NA
NA
NA
9.6
NA
NA
9.62
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
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
0.3
NA
1.2
NA
2.4
NA
SPBRG
value
(decimal)
3.579545 MHz
SPBRG
value
(decimal)
1 MHz
KBAUD
%
ERROR
NA
NA
NA
1.20
+0.16
NA
2.40
+0.16
KBAUD
%
ERROR
SPBRG
value
(decimal)
32.768 kHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
0.30
+1.14
207
1.17
-2.48
103
2.73
+13.78
2
0
26
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
DS41159B-page 184
Preliminary
PIC18FXX8
TABLE 18-4:
BAUD
RATE
(Kbps)
FOSC = 40 MHz
SPBRG
value
(decimal)
33 MHz
SPBRG
value
(decimal)
25 MHz
SPBRG
value
(decimal)
20 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
0.3
NA
NA
NA
NA
1.2
NA
NA
NA
NA
2.4
NA
2.40
-0.07
214
2.40
-0.15
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
SPBRG
value
(decimal)
10 MHz
SPBRG
value
(decimal)
7.15909 MHz
SPBRG
value
(decimal)
5.0688 MHz
SPBRG
value
(decimal)
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
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
KBAUD
%
ERROR
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
0
-
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
0.30
-0.16
1.2
1.20
+1.67
2.4
2.40
9.6
%
ERROR
SPBRG
value
(decimal)
3.579545 MHz
KBAUD
%
ERROR
207
0.30
+0.23
51
1.19
-0.83
+1.67
25
2.43
8.93
-6.99
19.2
20.83
+8.51
76.8
62.50
SPBRG
value
(decimal)
1 MHz
KBAUD
%
ERROR
185
0.30
+0.16
46
1.20
+0.16
+1.32
22
2.23
9.32
-2.90
18.64
-2.90
-18.62
55.93
SPBRG
value
(decimal)
32.768 kHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
51
0.26
-14.67
12
NA
-6.99
NA
7.81
-18.62
NA
15.63
-18.62
NA
-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
Preliminary
DS41159B-page 185
PIC18FXX8
TABLE 18-5:
BAUD
RATE
(Kbps)
FOSC = 40 MHz
SPBRG
value
(decimal)
33 MHz
SPBRG
value
(decimal)
25 MHz
SPBRG
value
(decimal)
20 MHz
SPBRG
value
(decimal)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
0.3
NA
NA
NA
NA
1.2
NA
NA
NA
NA
2.4
NA
NA
NA
NA
9.6
NA
9.60
-0.07
214
9.59
-0.15
162
9.62
+0.16
129
19.2
19.23
+0.16
129
19.28
+0.39
106
19.30
+0.47
80
19.23
+0.16
64
76.8
75.76
-1.36
32
76.39
-0.54
26
78.13
+1.73
19
78.13
+1.73
15
96
96.15
+0.16
25
98.21
+2.31
20
97.66
+1.73
15
96.15
+0.16
12
300
312.50
+4.17
294.64
-1.79
312.50
+4.17
312.50
+4.17
500
500
515.63
+3.13
520.83
+4.17
416.67
-16.67
HIGH
2500
2062.50
1562.50
1250
LOW
9.77
255
8,06
255
6.10
255
4.88
255
FOSC = 16 MHz
SPBRG
value
(decimal)
10 MHz
SPBRG
value
(decimal)
7.15909 MHz
SPBRG
value
(decimal)
BAUD
RATE
(Kbps)
KBAUD
%
ERROR
KBAUD
%
ERROR
KBAUD
%
ERROR
0.3
NA
NA
NA
1.2
NA
NA
NA
2.4
NA
NA
2.41
+0.23
185
5.0688 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
NA
NA
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
BAUD
RATE
(Kbps)
FOSC = 4 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
3.579545 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
1 MHz
KBAUD
%
ERROR
SPBRG
value
(decimal)
32.768 kHz
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
DS41159B-page 186
Preliminary
PIC18FXX8
18.2
empty and flag bit TXIF (PIR registers) is set. This interrupt can be enabled/disabled by setting/clearing
enable bit TXIE (PIE registers). Flag bit TXIF will be
set, regardless of the state of enable bit TXIE and cannot be cleared in software. It will reset only when new
data is loaded into the TXREG register. While flag bit
TXIF indicated the status of the TXREG register,
another bit TRMT (TXSTA register) shows the status of
the TSR register. Status bit TRMT is a read only bit,
which is set when the TSR register 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.
In this mode, the USART uses 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 x16 or x64 of the bit shift rate, depending
on the BRGH bit (TXSTA register). 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.
18.2.1
2.
3.
4.
USART ASYNCHRONOUS
TRANSMITTER
5.
FIGURE 18-1:
6.
7.
Note:
TXIF is not cleared immediately upon loading data into the transmit buffer TXREG. The
flag bit becomes valid in the second instruction cycle following the load instruction.
TXREG register
TXIE
8
MSb
LSb
(8)
Pin Buffer
and Control
TSR register
RC6/TX/CK pin
Interrupt
TXEN
SPEN
SPBRG
Baud Rate Generator
TX9
TX9D
Preliminary
DS41159B-page 187
PIC18FXX8
FIGURE 18-2:
ASYNCHRONOUS TRANSMISSION
Write to TXREG
BRG Output
(Shift Clock)
Word 1
RC6/TX/CK (pin)
START bit
bit 0
bit 1
TXIF bit
(Transmit Buffer
Register Empty Flag)
TRMT bit
(Transmit Shift
Register 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/TX/CK (pin)
TXIF bit
(Interrupt Reg. Flag)
Word 2
START bit
TRMT bit
(Transmit Shift
Reg. Empty Flag)
bit 0
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.
TABLE 18-6:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
RBIE
Bit 2
Bit 1
TMR0IF INT0IF
Value on
all other
RESETS
Bit 0
Value on
POR, BOR
RBIF
PIR1
PSPIF
ADIF
RCIF
TXIF
PIE1
PSPIE
ADIE
RCIE
TXIE
IPR1
PSPIP
ADIP
RCIP
TXIP
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
SYNC
BRGH
TRMT
TX9D
TXREG
TXSTA
TX9
TXEN
DS41159B-page 188
Preliminary
PIC18FXX8
18.2.2
USART ASYNCHRONOUS
RECEIVER
18.2.3
2.
3.
4.
5.
6.
7.
8.
9.
FIGURE 18-4:
FERR
OERR
CREN
SPBRG
64
or
16
RSR Register
MSb
STOP (8)
LSb
0 START
RC7/RX/DT
Pin Buffer
and Control
Data
Recovery
RX9
RX9D
SPEN
RCREG Register
FIFO
8
Interrupt
RCIF
Data Bus
RCIE
Note:
Preliminary
DS41159B-page 189
PIC18FXX8
FIGURE 18-5:
ASYNCHRONOUS RECEPTION
START
bit
bit0
RX (pin)
bit1
bit7/8 STOP
bit
Rcv shift
Reg
Rcv Buffer Reg
START
bit
bit0
START
bit
bit7/8
STOP
bit
Word 2
RCREG
Word 1
RCREG
Read Rcv
Buffer Reg
RCREG
bit7/8 STOP
bit
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
INTCON
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 000x
0000 000u
PIR1
PSPIF
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
0000 0000
0000 0000
PIE1
PSPIE
ADIE
RCIE
TXIE
SSPIE
0000 0000
0000 0000
IPR1
PSPIP
ADIP
RCIP
TXIP
SSPIP
0000 0000
0000 0000
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
0000 000x
0000 000x
RCREG
TXSTA
SPBRG
FERR
OERR
RX9D
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
0000 0000
0000 0000
0000 -010
0000 -010
0000 0000
0000 0000
Legend: x = unknown, - = unimplemented locations read as '0'. Shaded cells are not used for Asynchronous Reception.
DS41159B-page 190
Preliminary
PIC18FXX8
18.3
18.3.1
2.
TABLE 18-8:
3.
4.
5.
6.
7.
Note:
TXIF is not cleared immediately upon loading data into the transmit buffer TXREG. The
flag bit becomes valid in the second instruction cycle following the load instruction.
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 000x
0000 000u
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
0000 0000
0000 0000
RCSTA
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
TXREG
TXSTA
SPBRG
TX9
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Master Transmission.
Preliminary
DS41159B-page 191
PIC18FXX8
FIGURE 18-6:
SYNCHRONOUS TRANSMISSION
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
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
RC7/RX/DT
pin
bit 0
bit 1
bit 2
bit 7
bit 0
bit 1
bit 7
Word 2
Word 1
RC6/TX/CK
pin
Write to
TXREG Reg
Write Word 1
TXIF bit
(Interrupt Flag)
Write Word 2
TXEN bit
Note: Sync Master mode; SPBRG = 0; continuous transmission of two 8-bit words.
FIGURE 18-7:
RC7/RX/DT pin
bit0
bit1
bit2
bit6
bit7
RC6/TX/CK pin
Write to
TXREG reg
TXIF bit
TRMT bit
TXEN bit
DS41159B-page 192
Preliminary
PIC18FXX8
18.3.2
TABLE 18-9:
Name
INTCON
Bit 6
Bit 5
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 000x
0000 000u
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
0000 0000
0000 0000
RCSTA
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
RCREG
TXSTA
SPBRG
TX9
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Master Reception.
FIGURE 18-8:
RC7/RX/DT pin
bit0
bit1
bit2
bit3
bit4
bit5
bit6
bit7
RC6/TX/CK 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.
Preliminary
DS41159B-page 193
PIC18FXX8
18.4
18.4.2
a)
1.
18.4.1
b)
c)
d)
e)
2.
3.
4.
5.
6.
7.
Enable the synchronous slave serial port by setting bits SYNC and SPEN and clearing bit
CSRC.
Clear bits CREN and SREN.
If interrupts are desired, set enable bit TXIE.
If 9-bit transmission is desired, set bit TX9.
Enable the transmission by setting enable bit
TXEN.
If 9-bit transmission is selected, the ninth bit
should be loaded in bit TX9D.
Start transmission by loading data to the TXREG
register.
DS41159B-page 194
2.
3.
4.
5.
6.
7.
8.
Preliminary
PIC18FXX8
TABLE 18-10: REGISTERS ASSOCIATED WITH SYNCHRONOUS SLAVE TRANSMISSION
Name
INTCON
Bit 7
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 000x
0000 000u
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
0000 0000
0000 0000
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
0000 000x
0000 000x
0000 0000
0000 0000
0000 -010
0000 -010
0000 0000
0000 0000
TXREG
TXSTA
SPBRG
TX9
TXEN
SYNC
BRGH
TRMT
TX9D
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Slave Transmission.
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
GIE/GIEH
PEIE/GIEL
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
RCSTA
SPEN
RX9
SREN
CREN
ADDEN
FERR
OERR
RX9D
TXEN
SYNC
BRGH
TRMT
TX9D
RCREG
TXSTA
SPBRG
TX9
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Slave Reception.
Preliminary
DS41159B-page 195
PIC18FXX8
NOTES:
DS41159B-page 196
Preliminary
PIC18FXX8
19.0
CAN MODULE
19.1
Overview
19.1.1
19.1.2
TRANSMIT/RECEIVE BUFFERS
The PIC18FXX8 has three transmit and two receive buffers, two acceptance masks (one for each receive
buffer), and a total of six acceptance filters. Figure 19-1
is a block diagram of these buffers and their connection
to the protocol engine.
Preliminary
DS41159B-page 197
PIC18FXX8
FIGURE 19-1:
BUFFERS
Message
Request
Accept
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
MESSAGE
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
MESSAGE
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
Acceptance Mask
RXM1
Acceptance Filter
RXM2
TXB0
Accept
TXB1
Acceptance Mask
RXM0
Acceptance Filter
RXF3
Acceptance Filter
RXF0
Acceptance Filter
RXF4
Acceptance Filter
RXF1
Acceptance Filter
RXF5
RXB0
RXB1
TXB2
MESSAGE
Message
Queue
Control
Identifier
Data and
Identifier
Data and
Identifier
Identifier
PROTOCOL
ENGINE
Receive Shift
Transmit Shift
RXERRCNT
Comparator
CRC Register
Bus-Off
Bit Timing
Generator
Transmit
Logic
Err-Pas
Protocol
FSM
Bit Timing
Logic
Transmit
Error
Counter
TX
DS41159B-page 198
Receive
Error
Counter
TXERRCNT
RX
Preliminary
PIC18FXX8
19.2
Note:
19.2.1
The registers described in this section control the overall operation of the CAN module and show its
operational status.
REGISTER 19-1:
R/W-0
REQOP1
R/W-0
REQOP0
R/W-0
ABAT
R/W-0
WIN2
R/W-0
WIN1
R/W-0
WIN0
U-0
bit 0
bit 7-5
bit 4
bit 3-1
bit 0
Unimplemented: Read as 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 199
PIC18FXX8
REGISTER 19-2:
bit 7-5
U-0
R-0
ICODE2
R-0
ICODE1
R-0
ICODE0
U-0
bit 0
Before the device goes into SLEEP mode, select Disable mode.
bit 4
Unimplemented: Read as 0
bit 3-1
bit 0
Unimplemented: Read as 0
Legend:
DS41159B-page 200
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
EXAMPLE 19-1:
CANSTAT, TempCANSTAT
;
;
;
;
;
MOVF
ANDLW
ADDWF
TempCANSTAT, W
b00001110
PCL, F
BRA
BRA
BRA
BRA
BRA
BRA
BRA
NoInterrupt
ErrorInterrupt
TXB2Interrupt
TXB1Interrupt
TXB0Interrupt
RXB1Interrupt
RXB0Interrupt
000
001
010
011
100
101
110
111
=
=
=
=
=
=
=
=
No interrupt
Error interrupt
TXB2 interrupt
TXB1 interrupt
TXB0 interrupt
RXB1 interrupt
RXB0 interrupt
Wake-up on interrupt
WakeupInterrupt
BCF
PIR3, WAKIF
; Clear the interrupt flag
;
; User code to handle wake-up procedure
;
;
; Continue checking for other interrupt source or return from here
NoInterrupt
ErrorInterrupt
BCF
PIR3, ERRIF
RETFIE
TXB2Interrupt
BCF
PIR3, TXB2IF
GOTO
AccessBuffer
TXB1Interrupt
BCF
PIR3, TXB1IF
GOTO
AccessBuffer
TXB0Interrupt
BCF
PIR3, TXB0IF
GOTO
AccessBuffer
RXB1Interrupt
BCF
PIR3, RXB1IF
GOTO
Accessbuffer
Preliminary
DS41159B-page 201
PIC18FXX8
EXAMPLE 19-1:
RXB0Interrupt
BCF
PIR3, RXB0IF
GOTO
AccessBuffer
AccessBuffer
; This is either TX or RX interrupt
; Copy CANCON.ICODE bits to CANSTAT.WIN bits
MOVF
TempCANCON, W
; Clear CANCON.WIN bits before copying
; new ones.
ANDLW
b11110001
; Use previously saved CANCON value to
; make sure same value.
MOVWF
TempCANCON
; Copy masked value back to TempCANCON
MOVF
ANDLW
TempCANSTAT, W
b00001110
IORWF
MOVFF
TempCANCON
TempCANCON, CANCON
DS41159B-page 202
Preliminary
PIC18FXX8
REGISTER 19-3:
R-0
TXBO
R-0
TXBP
R-0
RXBP
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
R-0
R-0
TXWARN RXWARN
R-0
EWARN
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 203
PIC18FXX8
19.2.2
REGISTER 19-4:
bit 7
R-0
TXABT
R-0
TXLARB
R-0
TXERR
R/W-0
TXREQ
U-0
R/W-0
TXPRI1
bit 7
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3
Clearing this bit in software while the bit is set, will request a message abort.
bit 2
Unimplemented: Read as 0
bit 1-0
R/W-0
TXPRI0
bit 0
These bits set the order in which Transmit buffer will be transferred. They do not
alter CAN message identifier.
Legend:
DS41159B-page 204
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 19-5:
bit 7-0
R/W-x
SID9
R/W-x
SID8
R/W-x
SID7
R/W-x
SID6
R/W-x
SID5
R/W-x
SID4
R/W-x
SID3
bit 0
REGISTER 19-6:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
SID1
R/W-x
SID0
R/W-x
R/W-x
EXIDE
R/W-x
R/W-x
EID17
bit 7-5
bit 4
Unimplemented: Read as 0
bit 3
bit 2
Unimplemented: Read as 0
bit 1-0
R/W-x
EID16
bit 0
Legend:
REGISTER 19-7:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 7-0
x = Bit is unknown
R/W-x
EID14
R/W-x
EID13
R/W-x
EID12
R/W-x
EID11
R/W-x
EID10
R/W-x
EID9
R/W-x
EID8
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 205
PIC18FXX8
REGISTER 19-8:
bit 7-0
R/W-x
EID6
R/W-x
EID5
R/W-x
EID4
R/W-x
EID3
R/W-x
EID2
R/W-x
EID1
R/W-x
EID0
bit 0
REGISTER 19-9:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7-0
TXBnDm7:TXBnDm0: Transmit Buffer n Data Field Byte m bits (where 0n<3 and 0<m<8)
Each Transmit Buffer has an array of registers. For example, Transmit buffer 0 has 7 registers:
TXB0D0 to TXB0D7.
Legend:
DS41159B-page 206
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 19-10: TXBnDLC TRANSMIT BUFFER n DATA LENGTH CODE REGISTERS
U-0
bit 7
R/W-x
TXRTR
U-0
U-0
R/W-x
DLC3
R/W-x
DLC2
bit 7
Unimplemented: Read as 0
bit 6
bit 5-4
Unimplemented: Read as 0
bit 3-0
R/W-x
DLC1
R/W-x
DLC0
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R-0
TEC6
R-0
TEC5
R-0
TEC4
R-0
TEC3
R-0
TEC2
R-0
TEC1
R-0
TEC0
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 207
PIC18FXX8
19.2.3
R/W-0
RXM1(1)
R/W-0
RXM0(1)
U-0
R-0
R/W-0
RXRTRRO RXB0DBEN
R/W-0
FILHIT0
bit 0
This bit is set by the CAN module and must be cleared by software after the buffer
is read.
bit 6-5
bit 4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
R-0
JTOFF
This bit allows same filter jump table for both RXB0CON and RXB1CON.
1: Bits RXFUL, RXM1 and RXM0 of RXB0CON are not mirrored in RXB1CON.
Legend:
DS41159B-page 208
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 19-13: RXB1CON RECEIVE BUFFER 1 CONTROL REGISTER
R/C-0
RXFUL(1)
bit 7
bit 7
R/W-0
RXM1(1)
R/W-0
RXM0(1)
U-0
R-0
RXRTRRO
R-0
FILHIT2
R-0
FILHIT1
R-0
FILHIT0
bit 0
This bit is set by the CAN module and should be cleared by software after the buffer
is read.
bit 6-5
bit 4
Unimplemented: Read as 0
bit 3
bit 2-0
1: Bits RXFUL, RXM1 and RXM0 of RXB1CON are not mirrored in RXB0CON.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
SID9
R/W-x
SID8
R/W-x
SID7
R/W-x
SID6
R/W-x
SID5
R/W-x
SID4
R/W-x
SID3
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 209
PIC18FXX8
REGISTER 19-15: RXBnSIDL RECEIVE BUFFER n STANDARD IDENTIFIER, LOW BYTE
R/W-x
SID2
bit 7
R/W-x
SID1
R/W-x
SID0
R/W-x
SRR
R/W-x
EXID
U-0
R/W-x
EID17
R/W-x
EID16
bit 0
bit 7-5
bit 4
bit 3
bit 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
R/W-x
EID14
R/W-x
EID13
R/W-x
EID12
R/W-x
EID11
R/W-x
EID10
R/W-x
EID9
R/W-x
EID8
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
EID6
R/W-x
EID5
R/W-x
EID4
R/W-x
EID3
R/W-x
EID2
R/W-x
EID1
R/W-x
EID0
bit 0
DS41159B-page 210
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 19-18: RXBnDLC RECEIVE BUFFER n DATA LENGTH CODE REGISTERS
U-0
bit 7
R/W-x
RXRTR
R/W-x
RB1
R/W-x
RB0
R/W-x
DLC3
bit 7
Unimplemented: Read as 0
bit 6
bit 5
bit 4
bit 3-0
R/W-x
DLC2
R/W-x
DLC1
R/W-x
DLC0
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
RXBnDm7:RXBnDm0: Receive Buffer n Data Field Byte m bits (where 0n<1 and 0<m<7)
Each Receive Buffer has an array of registers. For example, Receive buffer 0 has 8 registers:
RXB0D0 to RXB0D7.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 211
PIC18FXX8
REGISTER 19-20: RXERRCNT RECEIVE ERROR COUNT REGISTER
R-0
REC7
bit 7
bit 7-0
R-0
REC6
R-0
REC5
R-0
REC4
R-0
REC3
R-0
REC2
R-0
REC1
R-0
REC0
bit 0
19.2.3.1
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
SID9
R/W-x
SID8
R/W-x
SID7
R/W-x
SID6
R/W-x
SID5
R/W-x
SID4
R/W-x
SID3
bit 0
W = Writable bit
1 = Bit is set
R/W-x
SID1
R/W-x
SID0
U-0
R/W-x
EXIDEN
bit 7-5
bit 4
Unimplemented: Read as 0
bit 3
bit 2
Unimplemented: Read as 0
bit 1-0
DS41159B-page 212
W = Writable bit
1 = Bit is set
Preliminary
U-0
R/W-x
EID17
R/W-x
EID16
bit 0
PIC18FXX8
REGISTER 19-23: RXFnEIDH RECEIVE ACCEPTANCE FILTER n EXTENDED IDENTIFIER,
HIGH BYTE
R/W-x
EID15
bit 7
bit 7-0
R/W-x
EID14
R/W-x
EID13
R/W-x
EID12
R/W-x
EID11
R/W-x
EID10
R/W-x
EID9
R/W-x
EID8
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
EID6
R/W-x
EID5
R/W-x
EID4
R/W-x
EID3
R/W-x
EID2
R/W-x
EID1
R/W-x
EID0
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
SID9
R/W-x
SID8
R/W-x
SID7
R/W-x
SID6
R/W-x
SID5
R/W-x
SID4
R/W-x
SID3
bit 0
SID10:SID3: Standard Identifier Mask bits, or Extended Identifier Mask bits EID28:EID21
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 213
PIC18FXX8
REGISTER 19-26: RXMnSIDL RECEIVE ACCEPTANCE MASK n STANDARD IDENTIFIER MASK,
LOW BYTE
R/W-x
SID2
bit 7
R/W-x
SID1
R/W-x
SID0
U-0
U-0
U-0
R/W-x
EID17
R/W-x
EID16
bit 0
bit 7-5
SID2:SID0: Standard Identifier Mask bits, or Extended Identifier Mask bits EID20:EID18
bit 4-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
R/W-x
EID14
R/W-x
EID13
R/W-x
EID12
R/W-x
EID11
R/W-x
EID10
R/W-x
EID9
R/W-x
EID8
bit 0
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
R/W-x
EID6
R/W-x
EID5
R/W-x
EID4
R/W-x
EID3
R/W-x
EID2
R/W-x
EID1
R/W-x
EID0
bit 0
DS41159B-page 214
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
19.2.4
R/W-0
SJW0
R/W-0
BRP5
R/W-0
BRP4
bit 7-6
bit 5-0
R/W-0
BRP3
R/W-0
BRP2
R/W-0
BRP1
R/W-0
BRP0
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Note:
x = Bit is unknown
Preliminary
DS41159B-page 215
PIC18FXX8
REGISTER 19-30: BRGCON2 BAUD RATE CONTROL REGISTER 2
R/W-0
SEG2PHTS
bit 7
R/W-0
SAM
R/W-0
R/W-0
R/W-0
R/W-0
SEG1PH2 SEG1PH1 SEG1PH0 PRSEG2
R/W-0
PRSEG1
bit 7
bit 6
bit 5-3
bit 2-0
R/W-0
PRSEG0
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Note:
DS41159B-page 216
x = Bit is unknown
Preliminary
PIC18FXX8
REGISTER 19-31: BRGCON3 BAUD RATE CONTROL REGISTER 3
U-0
bit 7
R/W-0
WAKFIL
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
SEG2PH2(1) SEG2PH1(1) SEG2PH0(1)
bit 0
bit 7
Unimplemented: Read as 0
bit 6
bit 5-3
Unimplemented: Read as 0
bit 2-0
19.2.5
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 7
U-0
R/W-0
ENDRHI
R/W-0
CANCAP
U-0
U-0
U-0
bit 7-6
Unimplemented: Read as 0
bit 5
bit 4
bit 3-0
Unimplemented: Read as 0
U-0
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 217
PIC18FXX8
19.2.6
R/W-0
WAKIF
R/W-0
ERRIF
R/W-0
TXB2IF
R/W-0
TXB1IF
R/W-0
TXB0IF
R/W-0
RXB1IF
R/W-0
RXB0IF
bit 0
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
DS41159B-page 218
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
REGISTER 19-34: PIE3 PERIPHERAL INTERRUPT ENABLE REGISTER
R/W-0
IRXIE
bit 7
R/W-0
WAKIE
R/W-0
ERRIE
R/W-0
TXB2IE
R/W-0
TXB1IE
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
R/W-0
TXB0IE
R/W-0
RXB1IE
R/W-0
RXB0IE
bit 0
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 219
PIC18FXX8
REGISTER 19-35: IPR3 PERIPHERAL INTERRUPT PRIORITY REGISTER
R/W-1
IRXIP
bit 7
R/W-1
WAKIP
R/W-1
ERRIP
R/W-1
TXB2IP
R/W-1
TXB1IP
bit 7
bit 6
bit 5
bit 4
bit 3
bit 2
bit 1
bit 0
R/W-1
TXB0IP
R/W-1
RXB1IP
R/W-1
RXB0IP
bit 0
Legend:
DS41159B-page 220
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
PIC18FXX8
TABLE 19-1:
Address
F7Fh
Address
Name
F5Fh
F7Eh
F7Dh
F7Ch
F7Bh
F7Ah
F79h
F78h
F77h
F76h TXERRCNT
F75h RXERRCNT
F74h COMSTAT
F73h
CIOCON
F72h BRGCON3
F71h BRGCON2
F70h BRGCON1
F6Fh CANCON
F5Eh
F5Dh
F5Ch
F5Bh
F5Ah
F59h
F58h
F57h
F56h
F55h
F54h
F53h
F52h
F51h
F50h
F4Fh
CANSTATRO1(2)
F6Eh
F6Dh
F6Ch
F6Bh
F6Ah
F69h
F68h
F67h
F66h
F65h
F64h
F63h
F62h
F61h
F60h
F4Eh CANSTATRO2(2)
F4Dh
TXB0D7
F4Ch
TXB0D6
F4Bh
TXB0D5
F4Ah
TXB0D4
F49h
TXB0D3
F48h
TXB0D2
F47h
TXB0D1
F46h
TXB0D0
F45h
TXB0DLC
F44h
TXB0EIDL
F43h
TXB0EIDH
F42h
TXB0SIDL
F41h
TXB0SIDH
F40h
TXB0CON
CANSTAT
RXB0D7
RXB0D6
RXB0D5
RXB0D4
RXB0D3
RXB0D2
RXB0D1
RXB0D0
RXB0DLC
RXB0EIDL
RXB0EIDH
RXB0SIDL
RXB0SIDH
RXB0CON
RXB1D7
RXB1D6
RXB1D5
RXB1D4
RXB1D3
RXB1D2
RXB1D1
RXB1D0
RXB1DLC
RXB1EIDL
RXB1EIDH
RXB1SIDL
RXB1SIDH
RXB1CON
Address
Name
Address
Name
F3Fh
F1Fh
RXM1EIDL
F3Eh
F3Dh
F3Ch
F3Bh
F3Ah
F39h
F38h
F37h
F36h
F35h
F34h
F33h
F32h
F31h
F30h
F2Fh
CANSTATRO3(2)
F1Eh
F1Dh
F1Ch
F1Bh
F1Ah
F19h
F18h
F17h
F16h
F15h
F14h
F13h
F12h
F11h
F10h
F0Fh
RXM1EIDH
RXM1SIDL
RXM1SIDH
RXM0EIDL
RXM0EIDH
RXM0SIDL
RXM0SIDH
RXF5EIDL
RXF5EIDH
RXF5SIDL
RXF5SIDH
RXF4EIDL
RXF4EIDH
RXF4SIDL
RXF4SIDH
RXF3EIDL
F0Eh
F0Dh
F0Ch
F0Bh
F0Ah
F09h
F08h
F07h
F06h
F05h
F04h
F03h
F02h
F01h
F00h
RXF3EIDH
RXF3SIDL
RXF3SIDH
RXF2EIDL
RXF2EIDH
RXF2SIDL
RXF2SIDH
RXF1EIDL
RXF1EIDH
RXF1SIDL
RXF1SIDH
RXF0EIDL
RXF0EIDH
RXF0SIDL
RXF0SIDH
TXB1D7
TXB1D6
TXB1D5
TXB1D4
TXB1D3
TXB1D2
TXB1D1
TXB1D0
TXB1DLC
TXB1EIDL
TXB1EIDH
TXB1SIDL
TXB1SIDH
TXB1CON
F2Eh CANSTATRO4(2)
F2Dh
TXB2D7
F2Ch
TXB2D6
F2Bh
TXB2D5
F2Ah
TXB2D4
F29h
TXB2D3
F28h
TXB2D2
F27h
TXB2D1
F26h
TXB2D0
F25h
TXB2DLC
F24h
TXB2EIDL
F23h
TXB2EIDH
F22h
TXB2SIDL
F21h
TXB2SIDH
F20h
TXB2CON
Note 1: Shaded registers are available in Access Bank Low area, while the rest are available in Bank 15.
2: CANSTAT register is repeated in these locations to simplify application firmware. Unique names are given
for each instance of the CANSTAT register, due to the Microchip Header file requirement.
Preliminary
DS41159B-page 221
PIC18FXX8
19.3
Configuration mode
Disable mode
Normal Operation mode
Listen Only mode
Loopback mode
Error Recognition mode
19.3.1
CONFIGURATION MODE
The CAN module has to be initialized before the activation. This is only possible if the module is in the Configuration mode. The Configuration mode is requested by
setting REQOP2 bit. Only when the status bit
OPMODE2 has a high level, can the initialization be
performed. Afterwards, the configuration registers, the
acceptance mask registers, and the acceptance filter
registers can be written. The module is activated by
setting the REQOP control bits to zero.
The module will protect the user from accidentally violating the CAN protocol through programming errors.
All registers which control the configuration of the module can not be modified while the module is on-line.
The CAN module will not be allowed to enter the Configuration mode while a transmission is taking place.
The CONFIG bit serves as a lock to protect the
following registers.
Configuration registers
Bus Timing registers
Identifier Acceptance Filter registers
Identifier Acceptance Mask registers
19.3.2
19.3.3
NORMAL MODE
19.3.4
DISABLE MODE
DS41159B-page 222
Preliminary
PIC18FXX8
19.3.5
LOOPBACK MODE
19.4.2
19.3.6
19.4.1
FIGURE 19-2:
19.4
TRANSMIT PRIORITY
TRANSMIT BUFFER
BLOCK DIAGRAM
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
Message
Request
TRANSMIT BUFFERS
Message
Queue
Control
TXB0
MESSAGE
TXB1
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
MESSAGE
TXREQ
TXABT
TXLARB
TXERR
TXBUFF
MESSAGE
TXB2
Preliminary
DS41159B-page 223
PIC18FXX8
19.4.3
INITIATING TRANSMISSION
19.4.4
DS41159B-page 224
ABORTING TRANSMISSION
Preliminary
PIC18FXX8
FIGURE 19-3:
No
Yes
Clear: TXABT, TXLARB
and TXERR
No
Is
CAN bus Available
to Start Transmission
?
No
Is
TXREQ = 0
ABAT = 1
?
Yes
Yes
Examine TXPRI <1:0> to
Determine Highest Priority Message
Was
Message Transmitted
Successfully?
No
Set
TXERR = 1
Yes
Set TXREQ = 0
Is
TXLARB = 1?
Yes
Generate
Interrupt
Is
TXIE = 1?
No
Set
TXBUFE = 1
No
Is
TXREQ = 0
or TXABT = 1
?
Yes
No
Abort Transmission:
Set TXABT = 1
END
Preliminary
DS41159B-page 225
PIC18FXX8
19.5
19.5.1
Message Reception
RECEIVE MESSAGE BUFFERING
19.5.2
RECEIVE BUFFERS
Of the three receive buffers, the MAB is always committed to receiving the next message from the bus. The
remaining two receive buffers are called RXB0 and
RXB1 and can receive a complete message from the
protocol engine. The MCU can access one buffer while
the other buffer is available for message reception, or
holding a previously received message.
The MAB assembles all messages received. These
messages will be transferred to the RXBn buffers, only
if the acceptance filter criteria are met.
Note:
19.5.3
19.5.4
TIME-STAMPING
FIGURE 19-4:
RECEIVE PRIORITY
DS41159B-page 226
Preliminary
Acceptance Filter
RXM2
Accept
Acceptance Mask
RXM0
Acceptance Filter
RXF3
Acceptance Filter
RXF0
Acceptance Filter
RXF4
Acceptance Filter
RXF1
Acceptance Filter
RXF5
RXB0
RXB1
Identifier
Data and
Identifier
Data and
Identifier
Identifier
PIC18FXX8
FIGURE 19-5:
Detect
Start of
Message?
No
Yes
Begin Loading Message into
Message Assembly Buffer (MAB)
Generate
Error
Frame
Valid
Message
Received?
No
Yes
Yes, meets criteria
Yes, meets criteria
Message
for RXB1
for RXBO
Identifier meets
a Filter Criteria?
No
Go to Start
The RXFUL bit determines if the
receive register is empty and able
to accept a new message.
The RXB0DBEN bit determines if
RXB0 can rollover into RXB1 if it is
full.
Is
RXFUL = 0?
No
Yes
Is
RX0DBEN = 1?
Yes
No
No
Set RXRDY = 1
Is
RXFUL = 0?
Yes
Move Message into RXB1
Is
ERRIE = 1?
No
Set RXRDY = 1
Yes
Go to Start
Is
RXIE = 1?
Yes
Generate
Interrupt
No
Yes
Is
RXIE = 1?
No
Set CANSTAT <3:0> according
to which Receive Buffer the
Message was loaded into
Preliminary
DS41159B-page 227
PIC18FXX8
19.6
TABLE 19-2:
Accept or
Reject
bit n
Accept
Accept
Reject
Reject
Accept
Mask
bit n
Filter bit n
FIGURE 19-6:
If the RXB0DBEN bit is clear, there are six codes corresponding to the six filters. If the RXB0DBEN bit is set,
there are six codes corresponding to the six filters, plus
two additional codes corresponding to RXF0 and RXF1
filters that rollover into RXB1.
If more than one acceptance filter matches, the FILHIT
bits will encode the binary value of the lowest numbered filter that matched. In other words, if filter RXF2
and filter RXF4 match, FILHIT will be loaded with the
value for RXF2. This essentially prioritizes the acceptance filters with a lower number filter having higher priority. Messages are compared to filters in ascending
order of filter number.
The mask and filter registers can only be modified
when the PIC18FXX8 is in Configuration mode. The
mask and filter registers cannot be read outside of Configuration mode. When outside of Configuration mode,
all mask and filter registers will be read as 0.
RXFn0
RXFn1
RXFnn
RxRqst
RXMnn
DS41159B-page 228
Preliminary
PIC18FXX8
19.7
FIGURE 19-7:
The time segments (and thus the Nominal Bit Time) are
in turn made up of integer units of time called Time
Quanta or TQ (see Figure 19-7). By definition, the nominal bit time is programmable from a minimum of 8 TQ
to a maximum of 25 TQ. Also, by definition, the minimum Nominal Bit Time is 1 s, corresponding to a maximum 1 Mb/s rate. The actual duration is given by the
relationship
Nominal Bit Time = TQ * (Sync_Seg + Prop_Seg +
Phase_Seg1 + Phase_Seg2)
The Time Quantum is a fixed unit derived from the
oscillator period. It is also defined by the programmable
baud rate prescaler with integer values from 1 to 64, in
addition to a fixed divide-by-two for clock generation.
Mathematically, this is
TQ (s) = (2 * (BRP+1)) / FOSC (MHz)
or
TQ (s) = (2 * (BRP+1)) * TOSC (s)
where FOSC is the clock frequency, TOSC is the corresponding oscillator period, and BRP is an integer (0
through 63) represented by the binary values of
BRGCON1<5:0>.
Input
Signal
Bit
Time
Intervals
Sync Propagation
Segment Segment
Phase
Segment 1
Phase
Segment 2
TQ
Sample Point
Nominal Bit Time
Preliminary
DS41159B-page 229
PIC18FXX8
19.7.1
TIME QUANTA
19.7.3
EXAMPLE 19-2:
CALCULATING TQ,
NOMINAL BIT RATE AND
NOMINAL BIT TIME
PROPAGATION SEGMENT
This part of the bit time is used to compensate for physical delay times within the network. These delay times
consist of the signal propagation time on the bus line
and the internal delay time of the nodes. The length of
the Propagation Segment can be programmed from
1 TQ to 8 TQ by setting the PRSEG2:PRSEG0 bits.
19.7.4
19.7.5
19.7.2
19.7.6
TQ = (2*64) / 25 = 5.12 s
SAMPLE POINT
The Information Processing Time (IPT) is the time segment, starting at the sample point that is reserved for
calculation of the subsequent bit level. The CAN specification defines this time to be less than or equal to
2 TQ. The PIC18FXX8 defines this time to be 2 TQ.
Thus, phase segment 2 must be at least 2 TQ long.
SYNCHRONIZATION SEGMENT
This part of the bit time is used to synchronize the various CAN nodes on the bus. The edge of the input signal is expected to occur during the sync segment. The
duration is 1 TQ.
DS41159B-page 230
Preliminary
PIC18FXX8
19.8
Synchronization
19.8.1
HARD SYNCHRONIZATION
19.8.2
RESYNCHRONIZATION
FIGURE 19-8:
19.8.3
SYNCHRONIZATION RULES
Input
Signal
Bit
Time
Segments
Sync
Prop
Segment
Phase
Segment 1
SJW
Phase
Segment 2
TQ
Sample Point
Nominal Bit Length
Actual Bit Length
Preliminary
DS41159B-page 231
PIC18FXX8
FIGURE 19-9:
Sync
Prop
Segment
Phase
Segment 1
TQ
Phase
Segment 2
SJW
Sample Point
Actual Bit Length
Nominal Bit Length
19.9
19.11.1
19.11.2
BRGCON1
BRGCON2
The PRSEG bits set the length of the propagation segment in terms of TQ. The SEG1PH bits set the length of
phase segment 1 in TQ. The SAM bit controls how
many times the RXCAN pin is sampled. Setting this bit
to a 1 causes the bus to be sampled three times; twice
at TQ/2 before the sample point, and once at the normal
sample point (which is at the end of phase segment 1).
The value of the bus is determined to be the value read
during at least two of the samples. If the SAM bit is set
to a 0, then the RXCAN pin is sampled only once at
the sample point. The SEG2PHTS bit controls how the
length of phase segment 2 is determined. If this bit is
set to a 1, then the length of phase segment 2 is determined by the SEG2PH bits of BRGCON3. If the
SEG2PHTS bit is set to a 0, then the length of phase
segment 2 is the greater of phase segment 1 and the
information processing time (which is fixed at 2 TQ for
the PIC18FXX8).
19.11.3
BRGCON3
DS41159B-page 232
Preliminary
PIC18FXX8
19.12 Error Detection
19.12.6
19.12.1
CRC ERROR
With the Cyclic Redundancy Check (CRC), the transmitter calculates special check bits for the bit
sequence, from the start of a frame until the end of the
data field. This CRC sequence is transmitted in the
CRC field. The receiving node also calculates the CRC
sequence using the same formula and performs a comparison to the received sequence. If a mismatch is
detected, a CRC error has occurred and an error frame
is generated. The message is repeated.
19.12.2
ACKNOWLEDGE ERROR
19.12.3
FORM ERROR
lf a node detects a dominant bit in one of the four segments, including end of frame, interframe space,
Acknowledge delimiter, or CRC delimiter, then a Form
Error has occurred and an error frame is generated.
The message is repeated.
19.12.4
BIT ERROR
19.12.5
lf, between the start of frame and the CRC delimiter, six
consecutive bits with the same polarity are detected,
the bit stuffing rule has been violated. A Stuff Bit Error
occurs and an error frame is generated. The message
is repeated.
19.12.7
ERROR STATES
Preliminary
DS41159B-page 233
PIC18FXX8
FIGURE 19-10:
RESET
ErrorActive
128 occurrences of
11 consecutive
"recessive" bits
ErrorPassive
TXERRCNT > 255
BusOff
19.13.1
Receive Interrupts
Wake-up Interrupt
Receiver Overrun Interrupt
Receiver Warning Interrupt
Receiver Error-Passive Interrupt
Transmit Interrupts
Transmitter Warning Interrupt
Transmitter Error-Passive Interrupt
Bus-Off Interrupt
DS41159B-page 234
19.13.2
TRANSMIT INTERRUPT
19.13.3
RECEIVE INTERRUPT
Preliminary
PIC18FXX8
TABLE 19-3:
19.13.6
ERROR INTERRUPT
ICOD
<2:0>
Interrupt
Boolean Expression
000
None
ERRWAKTX0TX1TX2RX0
RX1
When the Error Interrupt is enabled, an interrupt is generated if an overflow condition occurs, or if the error
state of transmitter or receiver has changed. The error
flags in COMSTAT will indicate one of the following
conditions.
001
Error
ERR
19.13.6.1
010
TXB2
ERRTX0TX1TX2
011
TXB1
ERRTX0TX1
100
TXB0
ERRTX0
101
RXB1
ERRTX0TX1TX2RX0RX1
110
RXB0
ERRTX0TX1TX2RX0
111
Wake on
Interrupt
19.13.6.2
ERRTX0TX1TX2RX0RX1
WAK
Key:
ERR = ERRIF * ERRIE RX0 = RXB0IF * RXB0IE
TX0 = TXB0IF * TXB0IE RX1 = RXB1IF * RXB1IE
TX1 = TXB1IF * TXB1IE WAK = WAKIF * WAKIE
TX2 = TXB2IF * TXB2IE
19.13.5
19.13.6.3
Transmitter Warning
The receive error counter has exceeded the errorpassive limit of 127 and the device has gone to
error-passive state.
19.13.6.5
The transmit error counter has exceeded the errorpassive limit of 127 and the device has gone to
error- passive state.
19.13.6.6
Receiver Warning
19.13.6.4
19.13.4
Receiver Overflow
Bus-Off
19.13.7
INTERRUPT ACKNOWLEDGE
Interrupts are directly associated with one or more status flags in the PIR register. Interrupts are pending as
long as one of the flags is set. Once an interrupt flag is
set by the device, the flag can not be reset by the
microcontroller until the interrupt condition is removed.
Preliminary
DS41159B-page 235
PIC18FXX8
NOTES:
DS41159B-page 236
Preliminary
PIC18FXX8
20.0
COMPATIBLE 10-BIT
ANALOG-TO-DIGITAL
CONVERTER (A/D) MODULE
REGISTER 20-1:
bit 7-6
bit 5-3
The ADCON0 register, shown in Register 20-1, controls the operation of the A/D module. The ADCON1
register, shown in Register 20-2, configures the
functions of the port pins.
ADCON0 REGISTER
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
U-0
R/W-0
ADCS1
bit 7
ADCS0
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 0
ADCON0
<ADCS1:ADCS0>
0
0
0
0
1
1
1
1
00
01
10
11
00
01
10
11
Clock Conversion
FOSC/2
FOSC/8
FOSC/32
FRC (clock derived from the internal A/D RC oscillator)
FOSC/4
FOSC/16
FOSC/64
FRC (clock derived from the internal A/D RC oscillator)
bit 2
bit 1
bit 0
W = Writable bit
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 237
PIC18FXX8
REGISTER 20-2:
ADCON1 REGISTER
R/W-0
ADFM
bit 7
R/W-0
ADCS2
U-0
U-0
R/W-0
PCFG3
R/W-0
PCFG2
R/W-0
PCFG1
bit 7
bit 6
Clock Conversion
FOSC/2
FOSC/8
FOSC/32
FRC (clock derived from the internal A/D RC oscillator)
FOSC/4
FOSC/16
FOSC/64
FRC (clock derived from the internal A/D RC oscillator)
00
01
10
11
00
01
10
11
0
0
0
0
1
1
1
1
R/W-0
PCFG0
bit 0
bit 5-4
bit 3-0
AN7
AN6
AN5
AN4
AN3
AN2
AN1
AN0
VREF+
VREF-
C/R
0000
0001
VREF+
VDD
VSS
8/0
AN3
VSS
0010
7/1
VDD
VSS
0011
VREF+
5/0
AN3
VSS
0100
4/1
VDD
VSS
0101
3/0
VREF+
AN3
VSS
011x
2/1
0/0
1000
VREF+
VREF-
AN3
AN2
6/2
1001
VDD
VSS
6/0
1010
VREF+
AN3
VSS
5/1
1011
VREF+
VREF-
AN3
AN2
4/2
1100
VREF+
VREF-
AN3
AN2
3/2
1101
VREF+
VREF-
AN3
AN2
2/2
1110
VDD
VSS
1/0
1111
VREF+
VREF-
AN3
AN2
1/2
Legend:
R = Readable bit
W = Writable bit
1 = Bit is set
0 = Bit is cleared
Note:
DS41159B-page 238
x = Bit is unknown
On any device RESET, the port pins that are multiplexed with analog functions (ANx)
are forced to be analog inputs.
Preliminary
PIC18FXX8
The analog reference voltage is software selectable to
either the devices positive and negative supply voltage
(VDD and VSS), or the voltage level on the
RA3/AN3/VREF+ pin and RA2/AN2/VREF- pin.
The A/D converter has a unique feature of being able
to operate while the device is in SLEEP mode. To operate in SLEEP, the A/D conversion clock must be
derived from the A/Ds internal RC oscillator.
The output of the sample and hold is the input into the
converter, which generates the result via successive
approximation.
FIGURE 20-1:
111
AN7(1)
110
AN6(1)
101
AN5(1)
100
VAIN
011
(Input Voltage)
010
10-bit
Converter
A/D
001
PCFG0
000
VDD
AN4
AN3
AN2
AN1
AN0
VREF+
Reference
voltage
VREF-
VSS
Note 1: Channels AN5 through AN7 are not available on PIC18F2X8 devices.
2: All I/O pins have diode protection to VDD and VSS.
Preliminary
DS41159B-page 239
PIC18FXX8
The value that is 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.
6.
7.
2.
3.
4.
5.
20.1
Note:
When the conversion is started, the holding capacitor is disconnected from the
input pin.
OR
Waiting for the A/D interrupt
FIGURE 20-2:
VT = 0.6V
Rs
RIC 1k
ANx
CPIN
5 pF
VAIN
VT = 0.6V
SS
RSS
I LEAKAGE
500 nA
CHOLD = 120 pF
VSS
Legend: CPIN
= input capacitance
VT
= threshold voltage
I LEAKAGE = leakage current at the pin due to
various junctions
RIC
SS
CHOLD
DS41159B-page 240
= interconnect resistance
= sampling switch
= sample/hold capacitance (from DAC)
Preliminary
VDD
6V
5V
4V
3V
2V
5 6 7 8 9 10 11
Sampling Switch (k)
PIC18FXX8
To calculate the minimum acquisition time,
Equation 20-1 may be used. This equation assumes
that 1/2 LSb error is used (1024 steps for the A/D). The
1/2 LSb error is the maximum error allowed for the A/D
to meet its specified resolution.
Example 20-1 shows the calculation of the minimum
required acquisition time TACQ. This calculation is
based on the following application system assumptions:
CHOLD
Rs
Conversion Error
VDD
Temperature
VHOLD
EQUATION 20-1:
TACQ
120 pF
2.5 k
1/2 LSb
5V Rss = 7 k
50C (system max.)
0V @ time = 0
ACQUISITION TIME
TAMP + TC + TCOFF
EQUATION 20-2:
VHOLD
or
Tc
EXAMPLE 20-1:
TACQ
=
=
=
=
=
TAMP + TC + TCOFF
TC
TACQ
Preliminary
DS41159B-page 241
PIC18FXX8
20.2
2 TOSC
4 TOSC
8 TOSC
16 TOSC
32 TOSC
64 TOSC
Internal RC oscillator.
20.3
Note 1: When reading the port register, all pins configured as analog input channels will read
as cleared (a low level). Pins configured as
digital inputs will convert an analog input.
Analog levels on a digitally configured input
will not affect the conversion accuracy.
2: Analog levels on any pin that is defined as
a digital input (including the AN4:AN0
pins) may cause the input buffer to consume current that is out of the devices
specification.
TABLE 20-1:
ADCS2:ADCS0
Device Frequency
20 MHz
ns(2)
5 MHz
ns(2)
1.25 MHz
333.33 kHz
2 TOSC
000
100
1.6 s
6 s
4 TOSC
100
200 ns(2)
800 ns(2)
3.2 s
12 s
8 TOSC
001
400 ns(2)
1.6 s
6.4 s
24 s(3)
16 TOSC
101
ns(2)
3.2 s
12.8 s
48 s(3)
32 TOSC
010
6.4 s
25.6 s(3)
96 s(3)
s(3)
192 s(3)
2 - 6 s(1)
2 - 6 s(1)
800
1.6 s
400
64 TOSC
110
3.2 s
12.8 s
RC
011
2 - 6 s(1)
2 - 6 s(1)
Legend:
Note 1:
2:
3:
51.2
TABLE 20-2:
ADCS2:ADCS0
000
Device Frequency
4 MHz
500
ns(2)
s(2)
2 MHz
1.0
s(2)
2.0
s(2)
1.25 MHz
1.6
s(2)
3.2
s(2)
333.33 kHz
6 s
12 s
4 TOSC
100
1.0
8 TOSC
001
2.0 s(2)
4.0 s
6.4 s
24 s(3)
16 TOSC
101
4.0 s(2)
8.0 s
12.8 s
48 s(3)
s(3)
96 s(3)
192 s(3)
32 TOSC
010
8.0 s
16.0 s
25.6
64 TOSC
110
16.0 s
32.0 s
51.2 s(3)
RC
Legend:
Note 1:
2:
3:
011
3-9
s(1,4)
3-9
s(1,4)
3-9
s(1,4)
3 - 9 s(1,4)
DS41159B-page 242
Preliminary
PIC18FXX8
20.4
A/D Conversions
20.5
FIGURE 20-3:
TCY - TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11
b9
b8
b7
b6
b4
b5
b3
b1
b2
b0
b0
Conversion Starts
Holding capacitor is disconnected from analog input
(typically 100 ns)
Next Q4: ADRESH/ADRESL is loaded, GO bit is cleared,
ADIF bit is set, holding capacitor is connected to analog input.
Set GO bit
TABLE 20-3:
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
PIR1
PSPIF(1)
ADIF
RCIF
TXIF
SSPIF
CCP1IF
TMR2IF
TMR1IF
PIE1
PSPIE
(1)
ADIE
RCIE
TXIE
SSPIE
CCP1IE
TMR2IE
TMR1IE
IPR1
PSPIP(1)
ADIP
RCIP
TXIP
SSPIP
CCP1IP
TMR2IP
TMR1IP
PIR2
CMIF(1)
EEIF
BCLIF
LVDIF
TMR3IF
PIE2
CMIE(1)
EEIE
BCLIE
LVDIE
CMIP(1)
EEIP
BCLIP
LVDIP
IPR2
ADRESH
ADRESL
ADCON0
ADCS1
ADCS0
CHS2
CHS1
CHS0
GO/DONE
ADON
ADCON1
ADFM
ADCS2
PCFG3
PCFG2
PCFG1
PCFG0
PORTA
RA6
RA5
RA4
RA3
RA2
RA1
RA0
TRISA
PORTE
RE2
RE1
RE0
LATE
LATE2
LATE1
LATE0
TRISE
IBF
OBF
IBOV
PSPMODE
TRISE2
TRISE1
TRISE0
Legend: x = unknown, u = unchanged, - = unimplemented, read as 0. Shaded cells are not used for A/D conversion.
Note 1: These bits are reserved on PIC18F2X8 devices; always maintain these bits clear.
Preliminary
DS41159B-page 243
PIC18FXX8
NOTES:
DS41159B-page 244
Preliminary
PIC18FXX8
21.0
Note:
COMPARATOR MODULE
The analog comparators are only available
on the PIC18F448 and PIC18F458.
The comparator module contains two analog comparators. The inputs to the comparators are multiplexed
with the RD0 through RD3 pins. The On-Chip Voltage
Reference (Section 22.0) can also be an input to the
comparators.
REGISTER 21-1:
CMCON REGISTER
R-0
C2OUT
bit 7
bit 7
R-0
C1OUT
R/W-0
C2INV
R/W-0
C1INV
R/W-0
CIS
R/W-0
CM2
R/W-0
CM1
R/W-0
CM0
bit 0
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
Preliminary
x = Bit is unknown
DS41159B-page 245
PIC18FXX8
21.1
Comparator Configuration
There are eight modes of operation for the comparators. The CMCON register is used to select these
modes. Figure 21-1 shows the eight possible modes.
The TRISD register controls the data direction of the
comparator pins for each mode. If the Comparator
FIGURE 21-1:
VIN-
RD0/PSP0 A
VIN+
VIN-
RD3/PSP3
RD2/PSP2 A
VIN+
Comparators Off
CM2:CM0 = 111
VIN-
RD0/PSP0 A
VIN+
VIN-
RD0/PSP0 D
VIN+
VIN-
RD2/PSP2 D
VIN+
RD1/PSP1
C1
Off (Read as 0)
C2
Off (Read as 0)
RD3/PSP3
RD1/PSP1
C1
C1
Off (Read as 0)
C2
Off (Read as 0)
Note:
C1OUT
RD0/PSP0
VIN-
VIN+
C1
C1OUT
C2
C2OUT
RE1/WR/AN6
RD3/PSP3
RD2/PSP2
VIN-
VIN+
C2
RD3/PSP3
C2OUT
RD2/PSP2
VIN-
VIN+
RE2/CS/AN7
Two Common Reference Comparators
CM2:CM0 = 100
RD1/PSP1
VIN-
RD0/PSP0 A
VIN+
VIN-
RD2/PSP2 D
VIN+
VIN-
RD0/PSP0 A
VIN+
RD1/PSP1
C1
C1OUT
C1
C1OUT
C2
C2OUT
RE1/WR/AN6
RD3/PSP3
C2
C2OUT
VIN-
RD2/PSP2 D
VIN+
RD3/PSP3
RE2/CS/AN7
Four Inputs Multiplexed to Two Comparators
CM2:CM0 = 110
VIN-
RD0/PSP0 A
VIN+
RD1/PSP1
RD1/PSP1
C1
C1OUT
RD0/PSP0 A
RE1/WR/AN6
RD3/PSP3
VIN-
RD2/PSP2 D
VIN+
RD3/PSP3
A
VINVIN+
C1
C1OUT
C2
C2OUT
RD2/PSP2 A
C2
CIS = 0
CIS = 1
CIS = 0
CIS = 1
VINVIN+
Off (Read as 0)
CVREF
DS41159B-page 246
Preliminary
PIC18FXX8
21.2
21.3.2
Comparator Operation
21.3
Comparator Reference
FIGURE 21-2:
VIN+
VIN-
SINGLE COMPARATOR
+
-
21.4
21.5
Comparator Outputs
Output
VIN
VIN
VIN
+
VIN+
Output
utput
21.3.1
Preliminary
2: Analog levels on any pin defined as a digital input, may cause the input buffer to
consume more current than is specified.
DS41159B-page 247
PIC18FXX8
FIGURE 21-3:
MULTIPLEX
+
CxINV
To RE1 or
RE2 pin
Bus
Data
Q
Read CMCON
Set
CMIF
bit
D
EN
Q
From
Other
Comparator
D
EN
CL
Read CMCON
RESET
21.6
Comparator Interrupts
Note:
DS41159B-page 248
Preliminary
PIC18FXX8
21.7
21.8
FIGURE 21-4:
Effects of a RESET
21.9
RS < 10k
RIC
AIN
CPIN
5 pF
VA
VT = 0.6V
I LEAKAGE
500 nA
VSS
Legend:
CPIN
VT
I LEAKAGE
RIC
RS
VA
=
=
=
=
=
=
Input Capacitance
Threshold Voltage
Leakage Current at the pin due to various junctions
Interconnect Resistance
Source Impedance
Analog Voltage
Preliminary
DS41159B-page 249
PIC18FXX8
TABLE 21-1:
Name
Bit 5
Value on
POR
Value on
all other
RESETS
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
C1INV
CIS
CM2
CM1
CM0
CVR2
CVR1
CVR0
TMR0IF INT0IF
RBIF
CMCON
Bit 7
CVRSS
CVR3
GIE/
GIEH
PEIE/
GIEL
TMR0IE
INT0IE
RBIE
PIR2
CMIF(1)
EEIF
BCLIF
LVDIF
PIE2
CMIE(1)
EEIE
BCLIE
(1)
EEIP
BCLIP
INTCON
IPR2
PORTD
RD7
CMIP
RD6
RD5
RD4
RD3
RD2
RD1
RD0
LATD5
LATD4
LATD3
LATD2
LATD1
LATD0
RE2
RE1
RE0
LATD
LATD7 LATD6
TRISD
PORTE
LATE
TRISE
IBF(1)
LATE2
LATE1
LATE0
TRISE2 TRISE1
TRISE0
DS41159B-page 250
Preliminary
PIC18FXX8
22.0
Note:
COMPARATOR VOLTAGE
REFERENCE MODULE
22.1
The Comparator Voltage Reference can output 16 distinct voltage levels for each range. The equations used
to calculate the output of the Comparator Voltage
Reference are as follows.
EQUATION 22-1:
If CVRR = 1:
CVREF = (CVR<3:0>/24) x CVRSRC
where:
CVRSS = 1, CVRSRC = (VREF+) (VREF-)
CVRSS = 0, CVRSRC = VDD VSS
EQUATION 22-2:
If CVRR = 0:
CVREF = (CVRSRC x 1/4) + (CVR<3:0>/32) x CVRSRC
where:
CVRSS = 1, CVRSRC = (VREF+) (VREF-)
CVRSS = 0, CVRSRC = VDD VSS
The settling time of the Comparator Voltage Reference
must be considered when changing the RA0/AN0/CVREF
output (see Table 27-4 in Section 27.2).
REGISTER 22-1:
CVRCON REGISTER
R/W-0
CVREN
bit 7
R/W-0
CVROE
R/W-0
CVRR
R/W-0
CVRSS
R/W-0
CVR3
R/W-0
CVR2
R/W-0
CVR1
bit 7
bit 6
bit 5
bit 4
bit 3-0
R/W-0
CVR0
bit 0
When CVRR = 0:
CVREF = 1/4 (CVRSRC) + (CVR3:CVR0/32) (CVRSRC)
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 251
PIC18FXX8
FIGURE 22-1:
VDD VREF+
CVRSS = 0
CVREN
16 Stages
CVRSS = 1
8R
R
CVRR
8R
CVRSS = 0
CVRSS = 1
RA0/AN0/CVREF
or CVREF of Comparator
22.2
22.4
RA2/AN2VREFCVR3
(From CVRCON<3:0>)
CVR0
Effects of a RESET
22.3
22.5
Connection Considerations
DS41159B-page 252
Preliminary
PIC18FXX8
FIGURE 22-2:
R(1)
CVREF
Module
RA0/AN0
CVREF Output
Voltage
Reference
Output
Impedance
Note 1: R is dependent upon the voltage reference configuration CVRCON<3:0> and CVRCON<5>.
TABLE 22-1:
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR
Value on
all other
RESETS
CVRCON
CVREN CVROE
CVRR
CVRSS
CVR3
CVR2
CVR1
CVR0
CMCON
C2OUT
C2INV
C1INV
CIS
CM2
CM1
CM0
TRISA
C1OUT
TRISA6 TRISA5 TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 -111 1111 -111 1111
Preliminary
DS41159B-page 253
PIC18FXX8
NOTES:
DS41159B-page 254
Preliminary
PIC18FXX8
23.0
Voltage
FIGURE 23-1:
VA
VB
Legend:
VA = LVD trip point
VB = Minimum valid device
operating voltage
Time
TA
TB
Preliminary
DS41159B-page 255
PIC18FXX8
FIGURE 23-2:
LVD3:LVD0
LVDCON
Register
16 to 1 MUX
VDD
Internally Generated
Reference Voltage
LVDEN
FIGURE 23-3:
LVDIF
The other input is connected to the internally generated voltage reference (parameter D423 in
Section 27.2). This gives users flexibility, because it
allows them to configure the Low Voltage Detect interrupt to occur at any voltage in the valid operating
range.
16 to 1 MUX
LVD3:LVD0
LVDIN
Externally Generated
Trip Point
LVDEN
LVD
VxEN
BODEN
EN
BGAP
DS41159B-page 256
Preliminary
PIC18FXX8
23.1
Control Register
REGISTER 23-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
bit 5
bit 4
bit 3-0
LVDL3:LVDL0 modes, which result in a trip point below the valid operating voltage
of the device, are not tested.
Legend:
R = Readable bit
W = Writable bit
- n = Value at POR
1 = Bit is set
0 = Bit is cleared
Preliminary
x = Bit is unknown
DS41159B-page 257
PIC18FXX8
23.2
Operation
2.
3.
4.
5.
6.
FIGURE 23-4:
CASE 1:
.
VLVD
LVDIF
Enable LVD
Internally Generated
Reference Stable
TIVRST
LVDIF cleared in software
CASE 2:
VDD
VLVD
LVDIF
Enable LVD
Internally Generated
Reference Stable
TIVRST
DS41159B-page 258
Preliminary
PIC18FXX8
23.2.1
23.2.2
23.3
23.4
Effects of a RESET
CURRENT CONSUMPTION
Preliminary
DS41159B-page 259
PIC18FXX8
NOTES:
DS41159B-page 260
Preliminary
PIC18FXX8
24.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:
OSC 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
24.1
TABLE 24-1:
Configuration Bits
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Default/
Unprogrammed
Value
FOSC2
FOSC1
FOSC0
--1- -111
300001h
CONFIG1H
OSCSEN
300002h
CONFIG2L
BORV1
BORV0
BOREN
PWRTEN
---- 1111
300003h
CONFIG2H
WDTPS2
WDTPS1
WDTPS0
WDTEN
---- 1111
300006h
CONFIG4L
DEBUG
LVP
STVREN
1--- -1-1
300008h
CONFIG5L
CP3
CP2
CP1
CP0
---- 1111
300009h
CONFIG5H
CPD
CPB
11-- ----
30000Ah
CONFIG6L
WRT3
WRT2
WRT1
WRT0
---- 1111
30000Bh
CONFIG6H
WRTD
WRTB
WRTC
111- ----
30000Ch
CONFIG7L
EBTR3
EBTR2
EBTR1
EBTR0
---- 1111
30000Dh
CONFIG7H
EBTRB
-1-- ----
3FFFFEh
DEVID1
DEV2
DEV1
DEV0
REV4
REV3
REV2
REV1
REV0
(1)
3FFFFFh
DEVID2
DEV10
DEV9
DEV8
DEV7
DEV6
DEV5
DEV4
DEV3
0000 1000
Preliminary
DS41159B-page 261
PIC18FXX8
REGISTER 24-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
REGISTER 24-2:
bit 1
bit 0
U-0
U-0
U-0
U-0
R/P-1
R/P-1
R/P-1
R/P-1
BORV1
BORV0
BOREN
PWRTEN
bit 0
Unimplemented: Read as 0
BORV1:BORV0: Brown-out Reset Voltage bits
11 = VBOR set to 2.0V
10 = VBOR set to 2.7V
01 = VBOR set to 4.2V
00 = VBOR set to 4.5V
BOREN: Brown-out Reset Enable bit(1)
1 = Brown-out Reset enabled
0 = Brown-out Reset disabled
PWRTEN: Power-up Timer Enable bit(1)
1 = PWRT disabled
0 = PWRT enabled
Legend:
R = Readable bit
P = Programmable bit
- n = Value when device is unprogrammed
DS41159B-page 262
bit 7
bit 7-4
bit 3-2
Preliminary
PIC18FXX8
REGISTER 24-3:
bit 7
bit 7-4
bit 3-1
U-0
U-0
R/P-1
WDTPS2
R/P-1
WDTPS1
R/P-1
WDTPS0
R/P-1
WDTEN
bit 0
Unimplemented: Read as 0
WDTPS2:WDTPS0: Watchdog Timer Postscale Select bits
111 = 1:128
110 = 1:64
101 = 1:32
100 = 1:16
011 = 1:8
010 = 1:4
001 = 1:2
000 = 1:1
Note:
bit 0
U-0
The Watchdog Timer postscale select bits configuration used in the PIC18FXXX
devices has changed from the configuration used in the PIC18CXXX devices.
REGISTER 24-4:
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
C = Clearable bit
Preliminary
DS41159B-page 263
PIC18FXX8
REGISTER 24-5:
U-0
U-0
U-0
R/C-1
R/C-1
(1)
(1)
CP3
CP2
R/C-1
R/C-1
CP1
CP0
bit 7
bit 0
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
C = Clearable bit
REGISTER 24-6:
R/C-1
U-0
U-0
U-0
U-0
U-0
U-0
CPD
CPB
bit 7
bit 0
bit 7
bit 6
bit 5-0
Unimplemented: Read as 0
Legend:
R = Readable bit
C = Clearable bit
DS41159B-page 264
Preliminary
PIC18FXX8
REGISTER 24-7:
U-0
U-0
U-0
R/P-1
WRT3
(1)
R/P-1
WRT2
(1)
R/P-1
R/P-1
WRT1
WRT0
bit 7
bit 0
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
P = Programmable bit
REGISTER 24-8:
R/P-1
R-1
U-0
U-0
U-0
U-0
U-0
WRTD
WRTB
WRTC
bit 7
bit 0
bit 7
bit 6
bit 5
bit 4-0
Unimplemented: Read as 0
Legend:
R = Readable bit
P =Programmable bit
Preliminary
DS41159B-page 265
PIC18FXX8
REGISTER 24-9:
U-0
U-0
U-0
R/P-1
EBTR3
(1)
R/P-1
EBTR2
(1)
R/P-1
R/P-1
EBTR1
EBTR0
bit 7
bit 0
bit 7-4
Unimplemented: Read as 0
bit 3
bit 2
bit 1
bit 0
P = Programmable bit
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
DS41159B-page 266
Preliminary
PIC18FXX8
REGISTER 24-11: DEVICE ID REGISTER 1 FOR PIC18FXX8 DEVICE
(DEVID1: BYTE ADDRESS 3FFFFEh)
R
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
Preliminary
DS41159B-page 267
PIC18FXX8
24.2
Note:
Note:
24.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
W = Writable bit
DS41159B-page 268
Preliminary
PIC18FXX8
24.2.2
WDT POSTSCALER
FIGURE 24-1:
WDT Timer
Postscaler
8
8 - to - 1 MUX
WDTEN
Configuration bit
WDTPS2:WDTPS0
SWDTEN bit
WDT
Time-out
Note:
TABLE 24-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
Preliminary
DS41159B-page 269
PIC18FXX8
24.3
24.3.1
3.
24.3.2
DS41159B-page 270
Preliminary
PIC18FXX8
WAKE-UP FROM SLEEP THROUGH INTERRUPT(1,2)
FIGURE 24-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
1:
2:
3:
4:
PC
PC+2
Inst(PC) = SLEEP
Inst(PC + 2)
PC+4
Inst(PC + 4)
PC+4
Inst(PC - 1)
SLEEP
Inst(PC + 2)
PC + 4
Dummy Cycle
0008h
000Ah
Inst(0008h)
Inst(000Ah)
Dummy Cycle
Inst(0008h)
Preliminary
DS41159B-page 271
PIC18FXX8
24.4
FIGURE 24-3:
16 Kbytes
(PIC18FX48)
32 Kbytes
(PIC18FX58)
Address
Range
Boot Block
Boot Block
000000h
0001FFh
Block 0
Block 0
000200h
CP0, WRT0, EBTR0
001FFFh
002000h
Block 1
Block 1
Unimplemented
Read 0s
Block 2
Unimplemented
Read 0s
Block 3
Unimplemented
Read 0s
Unimplemented
Read 0s
1FFFFFh
TABLE 24-3:
File Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
300008h
CONFIG5L
CP3
CP2
CP1
CP0
300009h
CONFIG5H
CPD
CPB
30000Ah
CONFIG6L
WRT3
WRT2
WRT1
WRT0
30000Bh
CONFIG6H
WRTD
WRTB
WRTC
30000Ch
CONFIG7L
EBTR3
EBTR2
EBTR1
EBTR0
30000Dh
CONFIG7H
EBTRB
DS41159B-page 272
Preliminary
PIC18FXX8
24.4.1
PROGRAM MEMORY
CODE PROTECTION
Note:
FIGURE 24-4:
Register Values
Program Memory
WRTB,EBTRB = 11
TBLPTR = 000FFF
WRT0,EBTR0 = 01
PC = 001FFE
TBLWT *
001FFFh
002000h
WRT1,EBTR1 = 11
003FFFh
004000h
PC = 004FFE
WRT2,EBTR2 = 11
TBLWT *
005FFFh
006000h
WRT3,EBTR3 = 11
007FFFh
Results: All Table Writes disabled to Blockn whenever WRTn = 0.
Preliminary
DS41159B-page 273
PIC18FXX8
FIGURE 24-5:
Register Values
Program Memory
TBLPTR = 000FFF
WRT0,EBTR0 = 10
001FFFh
002000h
PC = 002FFE
TBLRD *
WRT1,EBTR1 = 11
003FFFh
004000h
WRT2,EBTR2 = 11
005FFFh
006000h
WRT3,EBTR3 = 11
007FFFh
Results: All Table Reads from external blocks to Blockn are disabled whenever EBTRn = 0.
TABLAT register returns a value of 0.
FIGURE 24-6:
Register Values
Program Memory
TBLPTR = 000FFF
PC = 001FFE
WRT0,EBTR0 = 10
TBLRD *
001FFFh
002000h
WRT1,EBTR1 = 11
003FFFh
004000h
WRT2,EBTR2 = 11
005FFFh
006000h
WRT3,EBTR3 = 11
007FFFh
DS41159B-page 274
Preliminary
PIC18FXX8
24.4.2
DATA EEPROM
CODE PROTECTION
24.4.3
24.8
CONFIGURATION REGISTER
PROTECTION
24.5
ID Locations
Eight memory locations (200000h - 200007h) are designated as ID locations, where the user can store
checksum or other code identification numbers. These
locations are accessible during normal execution
through the TBLRD and TBLWT instructions, or during
program/verify. The ID locations can be read when the
device is code protected.
24.6
In-Circuit Debugger
PIC18FXXX 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.
24.7
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. The
Microchip In-Circuit Debugger (ICD) used with the
PIC18FXXX microcontrollers is the MPLAB ICD 2.
3: When using Low Voltage ICSP programming (LVP) and the pull-ups on PORTB
are enabled, bit 5 in the TRISB register
must be cleared to disable the pull-up on
RB5 and ensure the proper operation of
the device.
If Low Voltage Programming mode is not used, the LVP
bit can be programmed to a '0' and RB5/PGM becomes
a digital I/O pin. However, the LVP bit may only be programmed when programming is entered with VIHH on
MCLR/VPP. The LVP bit can only be charged when
using high voltage on MCLR.
It should be noted that once the LVP bit is programmed
to 0, only the High Voltage Programming mode is available and only High Voltage Programming mode can be
used to program the device.
When using Low Voltage ICSP, the part must be supplied 4.5V to 5.5V, if a bulk erase will be executed. This
includes reprogramming of the code protect bits from
an on-state to off-state. For all other cases of Low Voltage ICSP, the part may be programmed at the normal
operating voltage. This means unique user IDs, or user
code can be reprogrammed or added.
Preliminary
DS41159B-page 275
PIC18FXX8
NOTES:
DS41159B-page 276
Preliminary
PIC18FXX8
25.0
Byte-oriented operations
Bit-oriented operations
Literal operations
Control operations
The bit field designator 'b' selects the number of the bit
affected by the operation, while the file register designator 'f' represents the number of the file in which the
bit is located.
The literal instructions may use some of the following
operands:
A literal value to be loaded into a file register
(specified by k)
The desired FSR register to load the literal value
into (specified by f)
No operand required
(specified by )
25.1
READ-MODIFY-WRITE
OPERATIONS
DS41159B-page 277
PIC18FXX8
TABLE 25-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:
*+
*-
+*
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
< >
In the set of
italics
DS41159B-page 278
PIC18FXX8
FIGURE 25-1:
10
9 8 7
OPCODE d
a
Example Instruction
0
f (FILE #)
ADDWF MYREG, W, B
0
f (Source FILE #)
12 11
0
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
DS41159B-page 279
PIC18FXX8
TABLE 25-2:
Mnemonic,
Operands
Cycles
MSb
LSb
Status
Affected
Notes
DS41159B-page 280
PIC18FXX8
TABLE 25-2:
Mnemonic,
Operands
CONTROL OPERATIONS
BC
n
Branch if Carry
BN
n
Branch if Negative
BNC
n
Branch if Not Carry
BNN
n
Branch if Not Negative
BNOV
n
Branch if Not Overflow
BNZ
n
Branch if Not Zero
BOV
n
Branch if Overflow
BRA
n
Branch Unconditionally
BZ
n
Branch if Zero
CALL
n, s
Call subroutine 1st word
2nd word
CLRWDT
Clear Watchdog Timer
DAW
No Operation
NOP
No Operation (Note 4)
POP
Cycles
MSb
1 (2)
1 (2)
1 (2)
1 (2)
1 (2)
2
1 (2)
1 (2)
1 (2)
2
1
1
2
1110
1110
1110
1110
1110
1110
1110
1101
1110
1110
1111
0000
0000
1110
1111
0000
1111
0000
0000
1101
0000
0000
LSb
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
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
nnnn
kkkk
kkkk
0100
0111
kkkk
kkkk
0000
xxxx
0110
0101
nnnn
1111
000s
Status
Affected
Notes
None
None
None
None
None
None
None
None
None
None
TO, PD
C
None
None
None
None
None
None
All
GIE/GIEH,
PEIE/GIEL
RETLW
k
Return with literal in WREG
2
0000 1100 kkkk kkkk None
RETURN s
Return from Subroutine
2
0000 0000 0001 001s None
SLEEP
1
1
1
1
2
1
2
DS41159B-page 281
PIC18FXX8
TABLE 25-2:
Mnemonic,
Operands
Cycles
MSb
LSb
Status
Affected
Notes
LITERAL OPERATIONS
ADDLW
k
Add literal and WREG
1
0000 1111 kkkk
kkkk C, DC, Z, OV, N
ANDLW
k
AND literal with WREG
1
0000 1011 kkkk
kkkk Z, N
IORLW
k
Inclusive OR literal with WREG 1
0000 1001 kkkk
kkkk Z, N
LFSR
f, k
Move literal (12-bit) 2nd word 2
1110 1110 00ff
kkkk None
to FSRx 1st word
1111 0000 kkkk
kkkk
MOVLB
k
Move literal to BSR<3:0>
1
0000 0001 0000
kkkk None
MOVLW
k
Move literal to WREG
1
0000 1110 kkkk
kkkk None
MULLW
k
Multiply literal with WREG
1
0000 1101 kkkk
kkkk None
RETLW
k
Return with literal in WREG
2
0000 1100 kkkk
kkkk None
SUBLW
k
Subtract WREG from literal
1
0000 1000 kkkk
kkkk C, DC, Z, OV, N
XORLW
k
Exclusive OR literal with WREG 1
0000 1010 kkkk
kkkk Z, N
DATA MEMORY PROGRAM MEMORY OPERATIONS
TBLRD*
Table Read
2
0000 0000 0000
1000 None
TBLRD*+
Table Read with post-increment
0000 0000 0000
1001 None
TBLRD*Table Read with post-decrement
0000 0000 0000
1010 None
TBLRD+*
Table Read with pre-increment
0000 0000 0000
1011 None
TBLWT*
Table Write
2 (5)
0000 0000 0000
1100 None
TBLWT*+
Table Write with post-increment
0000 0000 0000
1101 None
TBLWT*Table Write with post-decrement
0000 0000 0000
1110 None
TBLWT+*
Table Write with pre-increment
0000 0000 0000
1111 None
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.
DS41159B-page 282
PIC18FXX8
25.2
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
1111
kkkk
kkkk
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
literal k
Process
Data
Write to W
ADDLW
0x15
Before Instruction
W
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
f [,d [,a]]
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
0x10
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
After Instruction
W
0x25
Example:
ADDWF
REG, W
Before Instruction
W
REG
=
=
0x17
0xC2
After Instruction
W
REG
=
=
0xD9
0xC2
DS41159B-page 283
PIC18FXX8
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
REG, W
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
Before Instruction
Carry bit =
REG
=
W
=
1
0x02
0x4D
After Instruction
Carry bit =
REG
=
W
=
DS41159B-page 284
0
0x02
0x50
PIC18FXX8
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
-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, W
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
=
=
Operands:
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
JUMP
Before Instruction
PC
address (HERE)
=
=
=
=
1;
address (JUMP)
0;
address (HERE+2)
After Instruction
If Carry
PC
If Carry
PC
DS41159B-page 285
PIC18FXX8
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
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
DS41159B-page 286
PIC18FXX8
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
DS41159B-page 287
PIC18FXX8
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
DS41159B-page 288
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
PIC18FXX8
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
Before Instruction
FLAG_REG
Before Instruction
bbba
Description:
Example:
Example:
1000
f,b[,a]
0x0A
0x8A
After Instruction
FLAG_REG
DS41159B-page 289
PIC18FXX8
BTFSC
BTFSS
Syntax:
Syntax:
Operands:
0 f 255
0b7
a [0,1]
Operands:
0 f 255
0b7
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
Decode
Q2
Q3
Q4
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
Before Instruction
PC
DS41159B-page 290
HERE
FALSE
TRUE
BTFSS
:
:
FLAG, 1
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
PIC18FXX8
BTG
Bit Toggle f
BOV
Branch if Overflow
Syntax:
Syntax:
[ label ] BOV
Operands:
0 f 255
0b7
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
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
DS41159B-page 291
PIC18FXX8
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,FAST
Before Instruction
PC
address (HERE)
After Instruction
PC
=
TOS
=
WS
=
BSRS
=
STATUSS=
DS41159B-page 292
address (THERE)
address (HERE + 4)
W
BSR
STATUS
PIC18FXX8
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
Before Instruction
FLAG_REG
Q3
Q4
Process
Data
No
operation
CLRWDT
Before Instruction
WDT Counter
0x5A
0x00
After Instruction
FLAG_REG
Q2
No
operation
=
=
=
=
0x00
0
1
1
After Instruction
WDT Counter
WDT Postscaler
TO
PD
DS41159B-page 293
PIC18FXX8
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, W
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
:
:
Before Instruction
PC Address
W
REG
=
=
=
HERE
?
?
=
=
W;
Address (EQUAL)
W;
Address (NEQUAL)
After Instruction
If REG
PC
If REG
PC
DS41159B-page 294
PIC18FXX8
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
Encoding:
Q2
Q3
Q4
Process
Data
No
operation
If skip:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
Cycles:
1(2)
Note: 3 cycles if skip and followed
by a 2-word instruction.
Q Cycle Activity:
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
NGREATER
GREATER
CPFSGT REG
:
:
>
=
W;
Address (GREATER)
W;
Address (NGREATER)
After Instruction
If REG
PC
If REG
PC
Q4
No
operation
Q1
No
operation
Address (HERE)
?
Q3
Process
Data
No
operation
No
operation
=
=
Q2
Read
register f
If skip:
No
operation
PC
W
ffff
Words:
No
operation
Before Instruction
ffff
No
operation
Example:
000a
Description:
Decode
Read
register f
0110
f [,a]
Example:
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
HERE
NLESS
LESS
CPFSLT REG
:
:
Before Instruction
PC
W
=
=
Address (HERE)
?
<
=
W;
Address (LESS)
W;
Address (NLESS)
After Instruction
If REG
PC
If REG
PC
DS41159B-page 295
PIC18FXX8
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
Description:
0000
0000
Cycles:
Q Cycle Activity:
Q1
Q3
Q4
Process
Data
Write
W
Example1:
DAW
Before Instruction
=
=
=
0xA5
0
0
ffff
Words:
Cycles:
Decode
Q2
ffff
Q Cycle Activity:
Q1
Read
register W
01da
Description:
0111
Words:
W
C
DC
0000
Encoding:
Decode
Encoding:
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
DECF
CNT,
Before Instruction
CNT
Z
=
=
0x01
0
After Instruction
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
=
=
=
DS41159B-page 296
0x34
1
0
PIC18FXX8
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
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
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
DECFSZ
GOTO
CNT
LOOP
Example:
CONTINUE
Before Instruction
PC
=
=
=
=
DCFSNZ
:
:
TEMP
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
DS41159B-page 297
PIC18FXX8
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,
Before Instruction
CNT
Z
C
DC
=
=
=
=
0xFF
0
?
?
After Instruction
CNT
Z
C
DC
DS41159B-page 298
=
=
=
=
0x00
1
1
1
PIC18FXX8
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
Q Cycle Activity:
Q1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Q1
Q2
Q3
Q4
Q1
Q2
Q3
Q4
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
No
operation
Decode
If skip:
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
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
Before Instruction
Address (HERE)
After Instruction
CNT
If CNT
PC
If CNT
PC
CNT
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)
DS41159B-page 299
PIC18FXX8
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, W
Before Instruction
RESULT =
W
=
0x13
0x91
After Instruction
RESULT =
W
=
DS41159B-page 300
0x13
0x93
PIC18FXX8
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
00da
f [,d [,a]]
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Example:
Q2
Q3
Q4
Read
register f
Process
Data
Write W
MOVF
REG, W
Before Instruction
REG
W
=
=
0x22
0xFF
=
=
0x22
0x22
After Instruction
REG
W
DS41159B-page 301
PIC18FXX8
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
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
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
REG1, REG2
Before Instruction
REG1
REG2
=
=
0x33
0x11
=
=
0x33,
0x33
After Instruction
REG1
REG2
DS41159B-page 302
PIC18FXX8
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
Before Instruction
W
REG
=
=
0x4F
0xFF
After Instruction
W
REG
=
=
0x4F
0x4F
DS41159B-page 303
PIC18FXX8
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
Q2
Q3
Q4
Read
literal k
Process
Data
Write
registers
PRODH:
PRODL
MULLW
0xC4
W
PRODH
PRODL
Encoding:
=
=
=
0xE2
?
?
=
=
=
0xE2
0xAD
0x08
After Instruction
0000
001a
f [,a]
ffff
ffff
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
Before Instruction
W
PRODH
PRODL
kkkk
Words:
Decode
1101
MULWF
Example:
Q2
Q3
Q4
Read
register f
Process
Data
Write
registers
PRODH:
PRODL
MULWF
REG
Before Instruction
W
REG
PRODH
PRODL
=
=
=
=
0xC4
0xB5
?
?
=
=
=
=
0xC4
0xB5
0x8A
0x94
After Instruction
W
REG
PRODH
PRODL
DS41159B-page 304
PIC18FXX8
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
DS41159B-page 305
PIC18FXX8
POP
PUSH
Syntax:
[ label ]
Syntax:
[ label ]
Operands:
None
Operands:
None
Operation:
Operation:
(PC+2) TOS
Status Affected:
None
Status Affected:
None
Encoding:
Description:
0000
0000
0000
0110
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
POP
Encoding:
Q3
Q4
POP TOS
value
No
operation
POP
GOTO
Cycles:
=
=
DS41159B-page 306
=
=
Q3
Q4
No
operation
No
operation
PUSH
TOS
PC
0x0031A2
0x014332
After Instruction
TOS
PC
Q2
PUSH PC+2
onto return
stack
Before Instruction
NEW
Before Instruction
TOS
Stack (1 level down)
0101
Words:
Decode
Q2
0000
Q Cycle Activity:
Q1
No
operation
0000
Description:
Example:
Example:
0000
PUSH
0x014332
NEW
=
=
0x00345A
0x000124
=
=
=
0x000126
0x000126
0x00345A
After Instruction
PC
TOS
Stack (1 level down)
PIC18FXX8
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)
DS41159B-page 307
PIC18FXX8
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
Cycles:
Decode
0000
0001
Example:
kkkk
kkkk
Words:
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:
Q2
Q3
Q4
No
operation
No
operation
pop PC from
stack
Set GIEH or
GIEL
No
operation
1100
Description:
000s
Words:
Q Cycle Activity:
Q1
0000
GIE/GIEH, PEIE/GIEL.
Encoding:
Description:
Encoding:
No
operation
RETFIE
No
operation
No
operation
CALL TABLE ;
;
;
;
:
TABLE
ADDWF PCL ;
RETLW k0
;
RETLW k1
;
:
:
RETLW kn
;
W contains table
offset value
W now has
table value
W = offset
Begin table
End of table
After Interrupt
PC
W
BSR
STATUS
GIE/GIEH, PEIE/GIEL
DS41159B-page 308
=
=
=
=
=
TOS
WS
BSRS
STATUSS
1
Before Instruction
W
0x07
After Instruction
W
value of kn
PIC18FXX8
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
0011
Description:
Q2
Q3
Q4
No
operation
Process
Data
pop PC from
stack
No
operation
No
operation
No
operation
No
operation
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
After Interrupt
PC = TOS
ffff
register f
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example:
RETURN
ffff
Decode
Example:
01da
RLCF
REG, W
Before Instruction
REG
C
=
=
1110 0110
0
After Instruction
REG
W
C
=
=
=
1110 0110
1100 1100
1
DS41159B-page 309
PIC18FXX8
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
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, W
Before Instruction
0101 0111
REG
C
=
=
1110 0110
0
After Instruction
REG
W
C
DS41159B-page 310
=
=
=
1110 0110
0111 0011
0
PIC18FXX8
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
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, W
Before Instruction
W
REG
=
=
?
1101 0111
After Instruction
W
REG
=
=
1110 1011
1101 0111
DS41159B-page 311
PIC18FXX8
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
TO, PD
Encoding:
Status Affected:
Encoding:
0000
0000
0000
0011
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Decode
No
operation
Q3
Process
Data
Q4
Go to
sleep
TO =
PD =
?
?
After Instruction
TO =
PD =
1
0
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
SLEEP
Before Instruction
01da
Description:
Decode
Example:
0101
f [,d [,a]]
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
SUBFWB REG
Before Instruction
REG
W
C
=
=
=
0x03
0x02
0x01
After Instruction
REG
W
C
Z
N
=
=
=
=
=
Example 2:
0xFF
0x02
0x00
0x00
0x01
SUBFWB
; result is negative
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
DS41159B-page 312
=
=
=
=
=
0
2
1
1
0
; result is zero
PIC18FXX8
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
=
=
=
=
=
=
Example 3:
0
1
1
0
SUBLW
=
=
; result is zero
0x02
=
=
=
=
1
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
SUBWF
REG
Before Instruction
=
=
=
3
2
?
REG
W
C
Z
N
=
=
=
=
=
Example 2:
1
2
1
0
0
; result is positive
SUBWF
REG, W
Before Instruction
3
?
After Instruction
W
C
Z
N
Cycles:
After Instruction
Before Instruction
W
C
REG
W
C
After Instruction
W
C
Z
N
ffff
Words:
Example 1:
2
?
ffff
; result is positive
0x02
11da
Description:
Decode
Before Instruction
W
C
0101
Q Cycle Activity:
Q1
After Instruction
W
C
Z
N
Encoding:
f [,d [,a]]
REG
W
C
=
=
=
2
2
?
After Instruction
FF ; (2s complement)
0 ; result is negative
0
1
REG
W
C
Z
N
=
=
=
=
=
Example 3:
2
0
1
1
0
; result is zero
SUBWF
REG
Before Instruction
REG
W
C
=
=
=
0x01
0x02
?
After Instruction
REG
W
C
Z
N
=
=
=
=
=
DS41159B-page 313
PIC18FXX8
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:
0101
Description:
ffff
ffff
Subtract W and the carry flag (borrow) from register 'f' (2s complement
method). 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 is 1,
then the bank will be selected as per
the BSR value (default).
Words:
Cycles:
Q Cycle Activity:
Q1
Decode
10da
f [,d [,a]]
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
Example 1:
SUBWFB
=
=
=
ffff
ffff
Cycles:
Q Cycle Activity:
Q1
Decode
Q2
Q3
Q4
Read
register f
Process
Data
Write to
destination
(0001 1001)
(0000 1101)
SWAPF
REG
Before Instruction
REG
0x53
After Instruction
=
=
=
=
=
Example 2:
10da
Words:
Example:
0x19
0x0D
0x01
After Instruction
REG
W
C
Z
N
0011
REG, 1, 0
Before Instruction
REG
W
C
Encoding:
Description:
0x0C
0x0D
0x01
0x00
0x00
(0000 1011)
(0000 1101)
REG
0x35
; result is positive
SUBWFB REG, 0, 0
Before Instruction
REG
W
C
=
=
=
0x1B
0x1A
0x00
(0001 1011)
(0001 1010)
0x1B
0x00
0x01
0x01
0x00
(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
0x01
(0000 0011)
(0000 1101)
(1111 0100)
; [2s comp]
(0000 1101)
After Instruction
REG
0xF5
W
C
Z
N
=
=
=
=
0x0E
0x00
0x00
0x01
DS41159B-page 314
; result is negative
PIC18FXX8
TBLRD
Table Read
TBLRD
Syntax:
[ label ]
Example1:
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:
0000
0000
0000
10nn
nn=0 *
=1 *+
=2 *=3 +*
Description:
Words:
Cycles:
Q Cycle Activity:
Q1
*+ ;
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
No
operation
No operation
(Read Program
Memory)
TABLAT
TBLPTR
MEMORY(0x00A356)
=
=
=
0x55
0x00A356
0x34
=
=
0x34
0x00A357
After Instruction
TABLAT
TBLPTR
Example2:
TBLRD
+* ;
Before Instruction
TABLAT
TBLPTR
MEMORY(0x01A357)
MEMORY(0x01A358)
=
=
=
=
0xAA
0x01A357
0x12
0x34
=
=
0x34
0x01A358
After Instruction
TABLAT
TBLPTR
No
No operation
operation (Write TABLAT)
DS41159B-page 315
PIC18FXX8
TBLWT
Table Write
Syntax:
[ label ]
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 +*
DS41159B-page 316
Q2
Q3
Q4
Decode
No
operation
No
operation
No
operation
No
operation
No
operation
(Read
TABLAT)
No
operation
No
operation
(Write to
Holding
Register )
Example1:
TBLWT
*+;
Before Instruction
Q1
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
PIC18FXX8
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
Before Instruction
PC
Address (HERE)
=
=
0x00,
Address (ZERO)
0x00,
Address (NZERO)
After Instruction
If CNT
PC
If CNT
PC
DS41159B-page 317
PIC18FXX8
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
Before Instruction
REG
W
=
=
0xAF
0xB5
After Instruction
REG
W
=
=
DS41159B-page 318
0x1A
0xB5
PIC18FXX8
26.0
DEVELOPMENT SUPPORT
26.1
26.2
MPASM Assembler
26.3
Preliminary
DS41159B-page 319
PIC18FXX8
26.4
26.6
26.5
26.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 of the pins. 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 the MPLAB C18 C compilers and the MPASM assembler. The software simulator
offers the flexibility to develop and debug code outside of
the laboratory environment, making it an excellent multiproject software development tool.
DS41159B-page 320
Preliminary
PIC18FXX8
26.8
Microchips In-Circuit Debugger, MPLAB ICD, is a powerful, low cost, run-time development tool. This tool is
based on the FLASH PICmicro MCUs and can be used
to develop for this and other PICmicro microcontrollers.
The MPLAB ICD utilizes the in-circuit debugging capability built into the FLASH devices. This feature, along
with Microchips In-Circuit Serial ProgrammingTM protocol, offers cost-effective in-circuit FLASH debugging
from the graphical user interface of the MPLAB
Integrated Development Environment. This enables a
designer to develop and debug source code by watching variables, single-stepping and setting break points.
Running at full speed enables testing hardware in realtime.
26.9
Preliminary
DS41159B-page 321
PIC18FXX8
26.13 PICDEM 3 Low Cost PIC16CXXX
Demonstration Board
The PICDEM 3 demonstration board is a simple demonstration board that supports the PIC16C923 and
PIC16C924 in the PLCC package. It will also support
future 44-pin PLCC microcontrollers with an LCD Module. All the necessary hardware and software is
included to run the basic demonstration programs. The
user can program the sample microcontrollers provided with the PICDEM 3 demonstration board on a
PRO MATE II device programmer, or a PICSTART Plus
development programmer with an adapter socket, and
easily test firmware. The MPLAB ICE in-circuit emulator may also be used with the PICDEM 3 demonstration
board to test firmware. A prototype area has been provided to the user for adding hardware and connecting it
to the microcontroller socket(s). Some of the features
include a RS-232 interface, push button switches, a
potentiometer for simulated analog input, a thermistor
and separate headers for connection to an external
LCD module and a keypad. Also provided on the
PICDEM 3 demonstration board is a LCD panel, with 4
commons and 12 segments, that is capable of displaying time, temperature and day of the week. The
PICDEM 3 demonstration board provides an additional
RS-232 interface and Windows software for showing
the demultiplexed LCD signals on a PC. A simple serial
interface allows the user to construct a hardware
demultiplexer for the LCD signals.
DS41159B-page 322
Preliminary
Software Tools
9 9 9
9
9
9
PIC17C7XX
9 9
9 9
9
9
PIC17C4X
9 9
9 9
9
9
PIC16C9XX
9
9 9
9
9
PIC16F8XX
9
9 9
9
9
PIC16C8X/
PIC16F8X
9
9 9
9
9
9
PIC16C7XX
9
9 9
9
9
9
PIC16C7X
9
9 9
9
9
9
PIC16F62X
9
9 9
PIC16CXXX
9
9 9
9
PIC16C6X
9
9 9
9
PIC16C5X
9
9 9
9
PIC14000
9
9 9
PIC12CXXX
9
9 9
9
9
9
9
9
9
9
9
9
9
9
Preliminary
MCRFXXX
9 9
9
9
9
9
MCP2510
* Contact the Microchip Technology Inc. web site at www.microchip.com for information on how to use the MPLAB ICD In-Circuit Debugger (DV164001) with PIC16C62, 63, 64, 65, 72, 73, 74, 76, 77.
** Contact Microchip Technology Inc. for availability date.
Development tool is available on select devices.
9 9
9
9
PICDEMTM 17 Demonstration
Board
9
9
9
9
PICDEMTM 3 Demonstration
Board
24CXX/
25CXX/
93CXX
PICDEMTM 2 Demonstration
Board
HCSXXX
PICDEMTM 1 Demonstration
Board
**
PRO MATE II
Universal Device Programmer
**
PIC18FXXX
PIC18CXX2
9 9 9
**
MPASMTM Assembler/
MPLINKTM Object Linker
TABLE 26-1:
MPLAB Integrated
Development Environment
PIC18FXX8
DS41159B-page 323
PIC18FXX8
NOTES:
DS41159B-page 324
Preliminary
PIC18FXX8
27.0
ELECTRICAL CHARACTERISTICS
Note:
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.
Preliminary
DS41159B-page 325
PIC18FXX8
FIGURE 27-1:
Voltage
5.0V
4.5V
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
40 MHz
Frequency
FIGURE 27-2:
6.0V
5.5V
Voltage
5.0V
PIC18LFXX8
4.5V
4.2V
4.0V
3.5V
3.0V
2.5V
2.0V
40 MHz
4 MHz
Frequency
FMAX = (16.36 MHz/V) (VDDAPPMIN 2.0V) + 4 MHz, if VDDAPPMIN 4.2V
= 40 MHz, if VDDAPPMIN > 4.2V
Note: VDDAPPMIN is the minimum voltage of the PICmicro device in the application.
DS41159B-page 326
Preliminary
PIC18FXX8
27.1
DC Characteristics
PIC18LFXX8
(Industrial)
PIC18FXX8
(Industrial, Extended)
Param
Symbol
No.
VDD
Characteristic/
Device
Min
Conditions
Supply Voltage
D001
PIC18LFXX8
2.0
5.5
D001
PIC18FXX8
4.2
5.5
D002
VDR
1.5
D003
VPOR
0.7
D004
SVDD
0.05
VBOR
2.0
2.16
BORV1:BORV0 = 10
2.7
2.86
BORV1:BORV0 = 01
4.2
4.46
BORV1:BORV0 = 00
4.5
4.78
BORV1:BORV0 = 1x
N.A.
N.A.
BORV1:BORV0 = 01
4.2
4.46
BORV1:BORV0 = 00
4.5
4.78
PIC18LFXX8
D005
PIC18FXX8
D005
Preliminary
DS41159B-page 327
PIC18FXX8
27.1
DC Characteristics (Continued)
PIC18LFXX8
(Industrial)
PIC18FXX8
(Industrial, Extended)
Param
Symbol
No.
IDD
Characteristic/
Device
Conditions
Supply Current(2,3,4)
D010
D010
D010A
D010A
D010C
D010C
D013
D013
D014
D014
PIC18LFXX8
TBD
mA
TBD
mA
30
TBD
LP osc configuration
FOSC = 32 kHz, VDD = 2.0V
185
TBD
LP osc configuration
FOSC = 32 kHz, VDD = 4.2V
22
TBD
mA
22
TBD
mA
1.4
14
TBD
TBD
mA
mA
22
TBD
mA
14
TBD
mA
22
TBD
mA
HS osc configurations
FOSC = 25 MHz, VDD = 5.5V
HS + PLL osc configuration
FOSC = 10 MHz, VDD = 5.5V
32
TBD
62
TBD
PIC18FXX8
PIC18LFXX8
PIC18FXX8
PIC18LFXX8
PIC18FXX8
PIC18LFXX8
PIC18FXX8
PIC18LFXX8
PIC18FXX8
HS osc configurations
FOSC = 6 MHz, VDD = 2.5V
FOSC = 25 MHz, VDD = 5.5V
HS + PLL osc configuration
FOSC = 10 MHz, VDD = 5.5V
DS41159B-page 328
Preliminary
PIC18FXX8
27.1
DC Characteristics (Continued)
PIC18LFXX8
(Industrial)
PIC18FXX8
(Industrial, Extended)
Param
Symbol
No.
IPD
Characteristic/
Device
Conditions
Power-down Current(3)
D020
PIC18LFXX8
0.09 TBD
0.11 TBD
A
A
D020
PIC18FXX8
0.1
0.11
TBD
TBD
A
A
0.1
0.11
TBD
TBD
A
A
D021B
IWDT
D022
Watchdog Timer
PIC18LFXX8
1
15
TBD
TBD
A
A
VDD = 2.5V
VDD = 5.5V
D022
Watchdog Timer
PIC18FXX8
15
15
TBD
TBD
A
A
D022A IBOR
Brown-out Reset
PIC18LFXX8
40
TBD
VDD = 5.5V
D022A
Brown-out Reset
PIC18FXX8
40
40
TBD
TBD
A
A
D022B ILVD
30
TBD
VDD = 2.5V
D022B
40
40
TBD
TBD
A
A
Timer1 Oscillator
PIC18LFXX8
TBD
VDD = 2.5V
Timer1 Oscillator
PIC18FXX8
9
9
TBD
TBD
A
A
D025
D025
IOSCB
Preliminary
DS41159B-page 329
PIC18FXX8
27.2
DC CHARACTERISTICS
Param
Symbol
No.
VIL
Characteristic/
Device
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.3 VDD
D033
VSS
0.2 VDD
VDD
VIH
D040
D040A
D041
2.0
VDD
0.8 VDD
0.7 VDD
VDD
VDD
V
V
D042
MCLR
0.8 VDD
VDD
D042A
0.7 VDD
VDD
D043
0.9 VDD
VDD
TBD
TBD
D050
VHYS
IIL
D060
I/O ports
D061
MCLR
OSC1
50
400
D063
D070
IPU
IPURB
Note 1: 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.
2: 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.
3: Negative current is defined as current sourced by the pin.
DS41159B-page 330
Preliminary
PIC18FXX8
27.2
DC CHARACTERISTICS
Param
Symbol
No.
VOL
D080
Characteristic/
Device
D080A
OSC2/CLKO
(RC mode)
D083A
VOH
D090
D090A
OSC2/CLKO
(RC mode)
D092A
D150
VOD
Max
Units
Conditions
0.6
0.6
0.6
0.6
VDD - 0.7
VDD - 0.7
VDD - 0.7
VDD - 0.7
7.5
RA4 pin
D092
Min
D083
D101
CIO
50
pF
D102
CB
SCL, SDA
400
pF
In I2C mode
Note 1: 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.
2: 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.
3: Negative current is defined as current sourced by the pin.
Preliminary
DS41159B-page 331
PIC18FXX8
FIGURE 27-3:
VLVD
(LVDIF set by hardware)
37
LVDIF
TABLE 27-1:
Param
Symbol
No.
D420
D423
VLVD
VBGAP
Characteristic
LVD Voltage
Min
Max
Units
Conditions
LVDL<3:0> = 0000
(Note 1)
LVDL<3:0> = 0001
2.0
2.12
LVDL<3:0> = 0010
2.2
2.33
LVDL<3:0> = 0011
2.4
2.54
LVDL<3:0> = 0100
2.5
2.66
LVDL<3:0> = 0101
2.7
2.86
LVDL<3:0> = 0110
2.8
2.98
LVDL<3:0> = 0111
3.0
3.2
LVDL<3:0> = 1000
3.3
3.52
LVDL<3:0> = 1001
3.5
3.72
LVDL<3:0> = 1010
3.6
3.84
LVDL<3:0> = 1011
3.8
4.04
LVDL<3:0> = 1100
4.0
4.26
LVDL<3:0> = 1101
4.2
4.46
LVDL<3:0> = 1110
4.5
4.78
1.17
1.23
Note 1: This is not a valid setting since the minimum supply voltage is 2.0V.
DS41159B-page 332
Preliminary
PIC18FXX8
TABLE 27-2:
DC Characteristics
Param
No.
Sym
Min
Typ
Max
Units
Conditions
100K
10K
VMIN
1M
100K
5.5
E/W
E/W
V
-40C to +85C
+85C to +125C
Using EECON to read/write
VMIN = Minimum operating voltage
D120
D120A
D121
ED
ED
VDRW
D122
D123
40
D124
TREF
1M
10M
ms
Years Provided no specifications are
violated
Cycles -40C to +85C
D124A
TREF
100K
1M
10K
1000
VMIN
4.5
4.5
VMIN
100K
10K
5.5
5.5
5.5
5.5
E/W
E/W
V
V
V
V
ms
ms
40
D130
D130A
D131
D132
D132A
D132B
EP
EP
VPR
VIE
VIW
VPEW
D133
D133A
TIE
TIW
-40C to +85C
+85C to +125C
VMIN = Minimum operating voltage
Using ICSP port
Using ICSP port
Using EECON to erase/write
VMIN = Minimum operating voltage
VDD > 4.5V
VDD > 4.5V
ms
Years Provided no specifications are
violated
Data in Typ column is at 5.0V, 25C unless otherwise stated. These parameters are for design guidance only
and are not tested.
D133B
D134
Cell Endurance
Cell Endurance
VDD for Read
VDD for ISCP Erase
VDD for ISCP Write
VDD for EECON Erase/Write
Preliminary
DS41159B-page 333
PIC18FXX8
TABLE 27-3:
COMPARATOR SPECIFICATIONS
Operating Conditions: VDD range as described in Section 27.1, -40C < TA < +125C.
Param
No.
Sym
Characteristics
Min
Typ
Max
Units
10
mV
VDD 1.5
5.0
D300
VIOFF
D301
VICM
D302
CMRR
CMRR
0
+55*
Response
Time(1)
db
TBD*
TBD*
D300
TRESP
D301
Comments
TBD*
TBD*
ns
ns
10*
PIC18FXX8
PIC18LFXX8
TABLE 27-4:
Operating Conditions: VDD range as described in Section 27.1, -40C < TA < +125C.
Param No.
D310
Sym
Characteristics
VRES
Resolution
D311
VRAA
Absolute Accuracy
D312
VRUR
TSET
Time(1)
D310
Settling
Min
Typ
VDD/24
Max
Units
VDD/32
LSB
TBD
LSB
Comments
2K*
10*
DS41159B-page 334
Preliminary
PIC18FXX8
27.3
27.3.1
AC (Timing) Characteristics
TIMING PARAMETER SYMBOLOGY
1. TppS2ppS
2. TppS
T
F
Frequency
Lowercase letters (pp) and their meanings:
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
Hi-impedance
High
Low
High
Low
Hold
SU
Setup
STO
STOP condition
pp
cc
CCP1
ck
CLKO
cs
CS
di
SDI
do
SDO
dt
Data in
io
I/O port
mc
MCLR
Uppercase letters and their meanings:
S
F
H
I
L
Fall
High
Invalid (Hi-impedance)
Low
I2C only
AA
output access
BUF
Bus free
TCC:ST (I2C specifications only)
CC
HD
ST
DAT
STA
Preliminary
DS41159B-page 335
PIC18FXX8
27.3.2
TIMING CONDITIONS
TABLE 27-5:
AC CHARACTERISTICS
FIGURE 27-4:
Load Condition 1
VDD/2
RL
CL
Pin
VSS
CL
Pin
RL = 464
VSS
DS41159B-page 336
CL = 50 pF
Preliminary
PIC18FXX8
27.3.3
FIGURE 27-5:
Q1
Q2
Q3
Q4
Q1
OSC1
1
CLKO
TABLE 27-6:
Param No.
1A
FOSC
Characteristic
Min
DC
MHz XT osc
DC
25
MHz HS osc
Oscillator Frequency(1)
TOSC
External CLKI
Period(1)
Oscillator Period(1)
Max
Units
Conditions
10
DC
DC
200
40
kHz LP osc
MHz EC
DC
MHz RC osc
0.1
MHz XT osc
25
MHz HS osc
10
200
kHz
250
ns
XT and RC osc
40
ns
HS osc
100
ns
HS + PLL osc
5
5
s
ns
LP osc
EC
250
ns
RC osc
250
10,000
ns
XT osc
100
40
10,000
100
ns
ns
HS osc
HS + PLL osc
LP osc
LP osc
TCY
100
ns
TCY = 4/FOSC
TosL,
TosH
30
ns
XT osc
2.5
ns
LP osc
TosR,
TosF
10
HS osc
20
ns
XT osc
50
ns
LP osc
7.5
ns
HS osc
Note 1: Instruction cycle period (TCY) equals four times the input oscillator time-base period. 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.
Preliminary
DS41159B-page 337
PIC18FXX8
TABLE 27-7:
Characteristic
TPLL
CLK
FIGURE 27-6:
Min
Max
Units
ms
TBD
TBD
Conditions
Q4
Q2
Q3
OSC1
11
10
CLKO
13
19
14
12
18
16
I/O Pin
(Input)
15
17
I/O Pin
(Output)
New Value
Old Value
20, 21
TABLE 27-8:
Param
No.
Symbol
Characteristic
Min
Typ
Max
Units Conditions
10
75
200
ns
(1)
11
75
200
ns
(1)
12
TckR
35
100
ns
(1)
13
TckF
35
100
ns
(1)
14
0.5 TCY + 20
ns
(1)
0.25 TCY + 25
ns
(1)
ns
(1)
50
150
ns
100
ns
15
16
TckH2ioI
17
18
TosH2ioI
18A
200
ns
19
ns
20
TIOR
PIC18FXX8
10
25
ns
PIC18LFXX8
60
ns
PIC18FXX8
10
25
ns
PIC18LFXX8
60
ns
20A
21
TIOF
21A
22
TINP
TCY
ns
23
TRBP
TCY
ns
24
TRCP
20
ns
These parameters are asynchronous events, not related to any internal clock edges.
Note 1: Measurements are taken in RC mode where CLKO pin output is 4 x TOSC.
DS41159B-page 338
Preliminary
PIC18FXX8
FIGURE 27-7:
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
31
34
34
I/O Pins
Note: Refer to Figure 27-4 for load conditions.
FIGURE 27-8:
VDD
35, 37
VBGAP = 1.2V
VIRVST
TABLE 27-9:
36
Param
No.
Symbol
30
TmcL
31
TWDT
18
33
ms
Characteristic
Min
Typ
Max
Units
32
TOST
1024 TOSC
1024 TOSC
33
TPWRT
28
72
132
ms
34
TIOZ
35
TBOR
200
36
TIVRST
20
50
37
TLVD
200
Preliminary
Conditions
DS41159B-page 339
PIC18FXX8
FIGURE 27-9:
41
40
42
T1OSO/T1CKI
46
45
47
48
TMR0 or
TMR1
Note: Refer to Figure 27-4 for load conditions.
Characteristic
40
Tt0H
No prescaler
41
Tt0L
No prescaler
42
Tt0P
T0CKI Period
With prescaler
With prescaler
45
Tt1H
T1CKI
High Time
Tt1L
T1CKI
Low Time
ns
10
ns
0.5 TCY + 20
ns
ns
ns
Greater of:
20 ns or TCY + 40
N
ns
0.5 TCY + 20
ns
Synchronous, PIC18FXX8
with prescaler PIC18LFXX8
10
ns
25
ns
Asynchronous PIC18FXX8
30
ns
50
ns
0.5 TCY + 5
ns
Synchronous, no prescaler
Synchronous, no prescaler
Synchronous, PIC18FXX8
with prescaler PIC18LFXX8
10
ns
25
ns
30
ns
TBD
TBD
ns
Greater of:
20 ns or TCY + 40
N
ns
PIC18LFXX8
48
0.5 TCY + 20
Asynchronous PIC18FXX8
47
Units
10
PIC18LFXX8
46
Max
TCY + 10
No prescaler
With prescaler
Min
Tt1P
T1CKI
Synchronous
Input Period
Asynchronous
60
ns
Ft1
DC
50
kHz
2 TOSC
7 TOSC
DS41159B-page 340
Preliminary
Conditions
N = prescale
value
(1, 2, 4,..., 256)
N = prescale
value
(1, 2, 4, 8)
PIC18FXX8
FIGURE 27-10:
50
51
52
CCPx
(Compare or PWM Mode)
54
53
Note: Refer to Figure 27-4 for load conditions.
51
TccL
TccH
Characteristic
Min
Max
Units
0.5 TCY + 20
ns
10
ns
20
ns
CCPx input
high time
0.5 TCY + 20
ns
PIC18FXX8
10
ns
PIC18LFXX8
20
ns
3 TCY + 40
N
ns
25
ns
No Prescaler
With
Prescaler
52
TccP
53
TccR
PIC18FXX8
PIC18LFXX8
45
ns
54
TccF
PIC18FXX8
25
ns
PIC18LFXX8
45
ns
Preliminary
Conditions
N = prescale
value (1,4 or 16)
DS41159B-page 341
PIC18FXX8
FIGURE 27-11:
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
62
64
63
Note: Refer to Figure 27-4 for load conditions.
Symbol
Characteristic
Min
Max
Units
Conditions
62
TdtV2wrH
20
25
ns
ns
63
TwrH2dtI
WR or CS to data-in invalid
(hold time)
PIC18FXX8
20
ns
PIC18LFXX8
35
ns
64
TrdL2dtV
80
90
ns
ns
65
TrdH2dtI
RD or CS to data-out invalid
10
30
ns
66
TibfINH
3 TCY
ns
DS41159B-page 342
Preliminary
PIC18FXX8
FIGURE 27-12:
SS
70
SCK
(CKP = 0)
71
72
78
79
79
78
SCK
(CKP = 1)
80
Bit6 - - - - - -1
MSb
SDO
LSb
75, 76
SDI
MSb In
Bit6 - - - -1
LSb In
74
73
Note: Refer to Figure 27-4 for load conditions.
Symbol
Characteristic
70
TssL2scH,
TssL2scL
71
TscH
71A
72
TscL
72A
Min
Max Units
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
PIC18FXX8
25
ns
PIC18LFXX8
45
ns
25
ns
PIC18FXX8
25
ns
PIC18LFXX8
45
ns
73
TdiV2scH,
TdiV2scL
73A
TB2B
74
TscH2diL,
TscL2diL
75
TdoR
76
TdoF
78
TscR
79
TscF
25
ns
80
TscH2doV,
TscL2doV
PIC18FXX8
50
ns
PIC18LFXX8
100
ns
Conditions
(Note 1)
(Note 1)
(Note 2)
Preliminary
DS41159B-page 343
PIC18FXX8
FIGURE 27-13:
SS
81
SCK
(CKP = 0)
71
72
79
73
SCK
(CKP = 1)
80
78
MSb
SDO
Bit6 - - - - - -1
LSb
Bit6 - - - -1
LSb In
75, 76
SDI
MSb In
74
Symbol
TscH
71A
72
TscL
72A
Characteristic
Min
Max Units
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
PIC18FXX8
25
ns
PIC18LFXX8
45
ns
25
ns
PIC18FXX8
25
ns
PIC18LFXX8
ns
73
TdiV2scH,
TdiV2scL
73A
TB2B
74
TscH2diL,
TscL2diL
75
TdoR
76
TdoF
78
TscR
45
79
TscF
25
ns
80
TscH2doV,
TscL2doV
50
ns
100
ns
81
TCY
ns
PIC18FXX8
PIC18LFXX8
Conditions
(Note 1)
(Note 1)
(Note 2)
DS41159B-page 344
Preliminary
PIC18FXX8
FIGURE 27-14:
SS
70
SCK
(CKP = 0)
83
71
72
78
79
79
78
SCK
(CKP = 1)
80
SDO
MSb
Bit6 - - - - - -1
LSb
77
75, 76
SDI
MSb In
73
Bit6 - - - -1
LSb In
74
TABLE 27-15: EXAMPLE SPI MODE REQUIREMENTS, SLAVE MODE TIMING (CKE = 0)
Param
No.
Symbol
Characteristic
70
71
TscH
TCY
71A
72
TscL
Min
72A
ns
Continuous
1.25 TCY + 30
ns
40
ns
Continuous
1.25 TCY + 30
ns
Single Byte
TdiV2scH, Setup time of SDI data input to SCK edge
TdiV2scL
73A
TB2B
74
TscH2diL,
TscL2diL
75
TdoR
PIC18FXX8
40
ns
100
ns
1.5 TCY + 40
ns
100
ns
25
ns
45
ns
PIC18LFXX8
TdoF
Single Byte
73
76
25
ns
ns
77
TssH2doZ
10
50
78
TscR
25
ns
45
ns
PIC18LFXX8
79
TscF
80
83
25
ns
50
ns
100
ns
ns
PIC18LFXX8
1.5 TCY + 40
(Note 1)
(Note 1)
(Note 2)
Preliminary
DS41159B-page 345
PIC18FXX8
FIGURE 27-15:
SS
SCK
(CKP = 0)
70
83
71
72
SCK
(CKP = 1)
80
MSb
SDO
Bit6 - - - - - -1
LSb
75, 76
SDI
MSb In
77
Bit6 - - - -1
LSb In
74
Note: Refer to Figure 27-4 for load conditions.
Symbol
TssL2scH,
TssL2scL
TscH
Characteristic
Min
ns
ns
ns
ns
ns
ns
ns
75
TB2B
TscH2diL,
TscL2diL
TdoR
Continuous
1.25 TCY + 30
Single Byte
40
SCK input low time
Continuous
1.25 TCY + 30
(Slave mode)
Single Byte
40
Last clock edge of Byte1 to the 1st clock edge of Byte2 1.5 TCY + 40
Hold time of SDI data input to SCK edge
100
SDO data output rise time
76
TdoF
25
45
25
ns
ns
ns
77
78
TssH2doZ
TscR
79
80
TscF
TscH2doV,
TscL2doV
10
50
25
45
25
50
100
ns
ns
ns
ns
ns
ns
82
TssL2doV
50
ns
100
ns
1.5 TCY + 40
ns
71
71A
72
72A
73A
74
TscL
TCY
PIC18FXX8
PIC18LFXX8
PIC18FXX8
PIC18LFXX8
PIC18FXX8
PIC18LFXX8
83
DS41159B-page 346
Preliminary
(Note 1)
(Note 1)
(Note 2)
PIC18FXX8
FIGURE 27-16:
SCL
91
93
90
92
SDA
STOP
Condition
START
Condition
Note: Refer to Figure 27-4 for load conditions.
Symbol
90
TSU:STA
91
92
93
THD:STA
TSU:STO
Characteristic
Max
Units
Conditions
ns
ns
START condition
4700
Setup time
600
START condition
4000
Hold time
600
STOP condition
4700
Setup time
600
4000
600
FIGURE 27-17:
Min
ns
ns
102
100
101
SCL
90
106
107
91
92
SDA
In
110
109
109
SDA
Out
Note: Refer to Figure 27-4 for load conditions.
Preliminary
DS41159B-page 347
PIC18FXX8
TABLE 27-18: I2C BUS DATA REQUIREMENTS (SLAVE MODE)
Param
No.
100
Symbol
THIGH
Characteristic
Clock high time
Min
Max
Units
4.0
0.6
1.5 TCY
4.7
1.3
SSP Module
101
TLOW
1.5 TCY
ns
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
START condition
setup time
4.7
0.6
START condition
hold time
4.0
0.6
ns
0.9
250
ns
100
ns
STOP condition
setup time
4.7
0.6
3500
ns
ns
4.7
1.3
400
pF
SSP module
102
103
90
91
106
107
92
109
110
D102
TR
TF
TSU:STA
THD:STA
THD:DAT
TSU:DAT
TSU:STO
TAA
TBUF
CB
Conditions
CB is specified to be from
10 to 400 pF
(Note 2)
(Note 1)
Time the bus must be free
before a new transmission
can start
Note 1: 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.
2: 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.
Before the SCL line is released, TR max. + TSU;DAT = 1000 + 250 = 1250 ns (according to the Standard
mode I2C bus specification).
DS41159B-page 348
Preliminary
PIC18FXX8
FIGURE 27-18:
SCL
93
91
90
92
SDA
STOP
Condition
START
Condition
Note: Refer to Figure 27-4 for load conditions.
91
TSU:STA
Characteristic
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 27-19:
Units
START condition
Setup time
93
Max
Setup time
Hold time
92
Min
I2C
Conditions
ns
ns
pins.
102
100
101
SCL
90
106
91
107
92
SDA
In
109
109
110
SDA
Out
Note: Refer to Figure 27-4 for load conditions.
Preliminary
DS41159B-page 349
PIC18FXX8
TABLE 27-20: MASTER SSP I2C BUS DATA REQUIREMENTS
Param.
Symbol
No.
100
101
THIGH
TLOW
Characteristic
Clock high time
Min
Max
Units
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
mode(1)
1 MHz
102
103
TR
TF
2(TOSC)(BRG + 1)
ms
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)
90
91
106
107
92
109
TSU:STA
THD:STA
THD:DAT
TSU:DAT
TSU:STO
TAA
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
1 MHz mode(1)
2(TOSC)(BRG + 1)
ms
3500
ns
1000
ns
mode(1)
ns
4.7
ms
Data input
hold time
Data input
setup time
STOP condition
setup time
110
D102
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)
DS41159B-page 350
Preliminary
PIC18FXX8
FIGURE 27-20:
RC6/TX/CK
pin
121
121
RC7/RX/DT
pin
120
122
Symbol
Characteristic
Min
Max
Units
ns
PIC18FXX8
40
PIC18LFXX8
100
ns
121
Tckrf
PIC18FXX8
20
ns
PIC18LFXX8
50
ns
122
Tdtrf
PIC18FXX8
20
ns
PIC18LFXX8
50
ns
120
FIGURE 27-21:
Conditions
RC6/TX/CK
pin
RC7/RX/DT
pin
125
126
Note: Refer to Figure 27-4 for load conditions.
Symbol
Characteristic
Min
Max
Units
125
TdtV2ckl
10
ns
126
TckL2dtl
15
ns
Preliminary
Conditions
DS41159B-page 351
PIC18FXX8
TABLE 27-23: A/D CONVERTER CHARACTERISTICS: PIC18FXX8 (INDUSTRIAL, EXTENDED)
PIC18LFXX8 (INDUSTRIAL)
Param
Symbol
No.
Characteristic
Min
Typ
Max
Units
bit
bit
Conditions
VREF = VDD 3.0V
VREF = VDD < 3.0V
A01
NR
Resolution
10
TBD
A03
EIL
<1
TBD
A04
EDL
<1
TBD
A05
EFS
<1
TBD
A06
EOFF
Offset error
<1.5
TBD
A10
Monotonicity
A20
VREF
Reference voltage
(VREFH VREFL)
A20A
guaranteed(3)
0V
3V
A21
VREFH
VSS
VDD + 0.3V
A22
VREFL
VSS - 0.3V
VDD
A25
VAIN
VSS - 0.3V
VREF + 0.3V
A30
ZAIN
Recommended impedance of
analog voltage source
10.0
A40
IAD
180
90
10
1000
10
A50
IREF
Average current
consumption when
A/D is on (Note 1).
During VAIN acquisition.
Based on differential of
VHOLD to VAIN. To charge
CHOLD.
During A/D conversion
cycle.
Note 1: When A/D is off, it will not consume any current other than minor leakage current. The power-down current
spec includes any such leakage from the A/D module.
VREF current is from RA2/AN2/VREF- and RA3/AN3/VREF+ pins or VDD and VSS pins, whichever is selected
as reference input.
2: VSS VAIN VREF
3: The A/D conversion result never decreases with an increase in the input voltage, and has no missing codes.
DS41159B-page 352
Preliminary
PIC18FXX8
FIGURE 27-22:
BSF ADCON0, GO
(Note 2)
131
Q4
130
A/D CLK
132
A/D DATA
...
...
NEW_DATA
OLD_DATA
ADRES
TCY
ADIF
GO
DONE
SAMPLING STOPPED
SAMPLE
Note
1:
2:
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.
This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
TAD
Characteristic
A/D clock period
PIC18FXX8
Min
Max
Units
1.6
20(5)
A/D RC mode
A/D RC mode
PIC18LFXX8
3.0
20(5)
PIC18FXX8
2.0
6.0
PIC18LFXX8
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
Preliminary
DS41159B-page 353
PIC18FXX8
NOTES:
DS41159B-page 354
Preliminary
PIC18FXX8
28.0
DC AND AC
CHARACTERISTICS GRAPHS
AND TABLES
Preliminary
DS41159B-page 355
PIC18FXX8
NOTES:
DS41159B-page 356
Preliminary
PIC18FXX8
29.0
PACKAGING INFORMATION
29.1
Example
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
YYWWNNN
40-Lead PDIP
PIC18F258-I/SP
0220017
Example
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX
YYWWNNN
PIC18F448-I/P
0220017
Example
28-Lead SOIC
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
PIC18F248-E/SO
0220017
YYWWNNN
Legend: XX...X
Y
YY
WW
NNN
Note:
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.
Preliminary
DS41159B-page 357
PIC18FXX8
29.1
44-Lead PLCC
Example
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
44-Lead TQFP
PIC18F458
-I/L
0220017
Example
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
YYWWNNN
DS41159B-page 358
PIC18F448
-I/PT
0220017
Preliminary
PIC18FXX8
29.2
Package Details
2
n
A2
A
L
B1
A1
eB
Units
Number of Pins
Pitch
Dimension Limits
n
p
INCHES*
MIN
NOM
MILLIMETERS
MAX
MIN
NOM
28
MAX
28
.100
2.54
.140
.150
.160
3.56
3.81
4.06
A2
.125
.130
.135
3.18
3.30
3.43
8.26
A1
.015
.300
.310
.325
7.62
7.87
E1
.275
.285
.295
6.99
7.24
7.49
Overall Length
1.345
1.365
1.385
34.16
34.67
35.18
L
c
.125
.130
.135
3.18
3.30
3.43
.008
.012
.015
0.20
0.29
0.38
B1
.040
.053
.065
1.02
1.33
1.65
Lead Thickness
Upper Lead Width
Lower Lead Width
Overall Row Spacing
Mold Draft Angle Top
Mold Draft Angle Bottom
0.38
.016
.019
.022
0.41
0.48
0.56
eB
.320
.350
.430
8.13
8.89
10.92
10
15
10
15
10
15
10
15
* Controlling Parameter
Significant Characteristic
Notes:
Dimension D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MO-095
Preliminary
DS41159B-page 359
PIC18FXX8
40-Lead Plastic Dual In-line (P) 600 mil (PDIP)
E1
2
1
n
E
A2
B1
A1
eB
B
Units
Dimension Limits
n
p
MIN
INCHES*
NOM
40
.100
.175
.150
MAX
MILLIMETERS
NOM
40
2.54
4.06
4.45
3.56
3.81
0.38
15.11
15.24
13.46
13.84
51.94
52.26
3.05
3.30
0.20
0.29
0.76
1.27
0.36
0.46
15.75
16.51
5
10
5
10
MIN
Number of Pins
Pitch
Top to Seating Plane
A
.160
.190
Molded Package Thickness
A2
.140
.160
Base to Seating Plane
.015
A1
Shoulder to Shoulder Width
E
.595
.600
.625
Molded Package Width
E1
.530
.545
.560
Overall Length
D
2.045
2.058
2.065
Tip to Seating Plane
L
.120
.130
.135
c
Lead Thickness
.008
.012
.015
Upper Lead Width
B1
.030
.050
.070
Lower Lead Width
B
.014
.018
.022
Overall Row Spacing
eB
.620
.650
.680
5
10
15
Mold Draft Angle Top
DS41159B-page 360
Preliminary
MAX
4.83
4.06
15.88
14.22
52.45
3.43
0.38
1.78
0.56
17.27
15
15
PIC18FXX8
28-Lead Plastic Small Outline (SO) Wide, 300 mil (SOIC)
E
E1
p
B
2
1
n
h
45
c
A2
L
Units
Dimension Limits
n
p
Number of Pins
Pitch
Overall Height
Molded Package Thickness
Standoff
Overall Width
Molded Package Width
Overall Length
Chamfer Distance
Foot Length
Foot Angle Top
Lead Thickness
Lead Width
Mold Draft Angle Top
Mold Draft Angle Bottom
* Controlling Parameter
Significant Characteristic
A
A2
A1
E
E1
D
h
L
c
B
A1
MIN
.093
.088
.004
.394
.288
.695
.010
.016
0
.009
.014
0
0
INCHES*
NOM
28
.050
.099
.091
.008
.407
.295
.704
.020
.033
4
.011
.017
12
12
MAX
.104
.094
.012
.420
.299
.712
.029
.050
8
.013
.020
15
15
MILLIMETERS
NOM
28
1.27
2.36
2.50
2.24
2.31
0.10
0.20
10.01
10.34
7.32
7.49
17.65
17.87
0.25
0.50
0.41
0.84
0
4
0.23
0.28
0.36
0.42
0
12
0
12
MIN
MAX
2.64
2.39
0.30
10.67
7.59
18.08
0.74
1.27
8
0.33
0.51
15
15
Notes:
Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MS-013
Drawing No. C04-052
Preliminary
DS41159B-page 361
PIC18FXX8
44-Lead Plastic Leaded Chip Carrier (L) Square (PLCC)
E
E1
#leads=n1
D1 D
n 1 2
CH2 x 45
CH1 x 45
A3
A2
35
A
B1
B
E2
Units
Dimension Limits
n
p
A1
p
D2
INCHES*
NOM
44
.050
11
.165
.173
.145
.153
.020
.028
.024
.029
.040
.045
.000
.005
.685
.690
.685
.690
.650
.653
.650
.653
.590
.620
.590
.620
.008
.011
.026
.029
.013
.020
0
5
0
5
MIN
MAX
MILLIMETERS
NOM
44
1.27
11
4.19
4.39
3.68
3.87
0.51
0.71
0.61
0.74
1.02
1.14
0.00
0.13
17.40
17.53
17.40
17.53
16.51
16.59
16.51
16.59
14.99
15.75
14.99
15.75
0.20
0.27
0.66
0.74
0.33
0.51
0
5
0
5
MIN
Number of Pins
Pitch
Pins per Side
n1
Overall Height
A
.180
Molded Package Thickness
.160
A2
Standoff
A1
.035
A3
Side 1 Chamfer Height
.034
Corner Chamfer 1
CH1
.050
Corner Chamfer (others)
CH2
.010
Overall Width
E
.695
Overall Length
D
.695
Molded Package Width
E1
.656
Molded Package Length
D1
.656
Footprint Width
E2
.630
Footprint Length
.630
D2
c
Lead Thickness
.013
Upper Lead Width
B1
.032
B
.021
Lower Lead Width
10
Mold Draft Angle Top
DS41159B-page 362
Preliminary
MAX
4.57
4.06
0.89
0.86
1.27
0.25
17.65
17.65
16.66
16.66
16.00
16.00
0.33
0.81
0.53
10
10
PIC18FXX8
44-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
A1
A2
(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
* Controlling Parameter
Significant Characteristic
n1
A
A2
A1
L
(F)
E
D
E1
D1
c
B
CH
MIN
.039
.037
.002
.018
0
.463
.463
.390
.390
.004
.012
.025
5
5
INCHES
NOM
44
.031
11
.043
.039
.004
.024
.039
3.5
.472
.472
.394
.394
.006
.015
.035
10
10
MAX
.047
.041
.006
.030
7
.482
.482
.398
.398
.008
.017
.045
15
15
MILLIMETERS*
NOM
44
0.80
11
1.00
1.10
0.95
1.00
0.05
0.10
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.09
0.15
0.30
0.38
0.64
0.89
5
10
5
10
MIN
MAX
1.20
1.05
0.15
0.75
7
12.25
12.25
10.10
10.10
0.20
0.44
1.14
15
15
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-076
Preliminary
DS41159B-page 363
PIC18FXX8
NOTES:
DS41159B-page 364
Preliminary
PIC18FXX8
APPENDIX A:
DATA SHEET
REVISION HISTORY
APPENDIX B:
DEVICE
DIFFERENCES
TABLE B-1:
DEVICE DIFFERENCES
Features
Internal
Program
Memory
PIC18F248
PIC18F258
PIC18F448
PIC18F458
Bytes
16K
32K
16K
32K
# of Single word
Instructions
8192
16384
8192
16384
768
1536
768
1536
Ports A, B, C
Ports A, B, C
Ports A, B, C, D, E Ports A, B, C, D, E
1
No
No
Yes
Yes
5 input channels
5 input channels
8 input channels
8 input channels
Analog Comparators
No
No
N/A
N/A
Yes
Yes
28-pin SPDIP
28-pin SOIC
28-pin SPDIP
28-pin SOIC
40-pin PDIP
44-pin PLCC
44-pin TQFP
40-pin PDIP
44-pin PLCC
44-pin TQFP
Packages
Preliminary
DS41159B-page 365
PIC18FXX8
APPENDIX C:
DEVICE MIGRATIONS
APPENDIX D:
MIGRATING FROM
OTHER PICmicro
DEVICES
D.1
PIC16CXXX to PIC18FXX8
D.2
PIC17CXXX to PIC18FXX8
DS41159B-page 366
Preliminary
PIC18FXX8
APPENDIX E:
DEVELOPMENT
TOOL VERSION
REQUIREMENTS
TBD
40-pin PDIP
44-pin TQFP
44-pin PLCC
DVA16XP282
DVA16XP282 with
XLT 28SO Transition
Socket
DVA16XP401
DVA16PQ441 with
XLT 44PT Transition
Socket
DVA16XL441
MPLAB ICD 2:
TBD
TBD
version TBD
PICSTART Plus:
Development Programmer
MPASMTM Assembler:
V2.80
(MPLAB IDE V5.40)
OSEK/VDX
operating
system available from
Vector Infromatik GmbH,
Germany and Realogy
Ltd, UK.
Note:
Preliminary
DS41159B-page 367
PIC18FXX8
NOTES:
DS41159B-page 368
Preliminary
PIC18FXX8
INDEX
A
A/D ................................................................................... 237
A/D Converter Flag (ADIF bit) .................................. 239
A/D Converter Interrupt, Configuring ....................... 240
Acquisition Requirements ........................................ 240
Acquisition Time ....................................................... 241
ADCON0 Register .................................................... 237
ADCON1 Register .................................................... 237
ADRESH Register .................................................... 237
ADRESH/ADRESL Registers .................................. 239
ADRESL Register .................................................... 237
Analog Port Pins, Configuring .................................. 242
Associated Registers Summary ............................... 243
Calculating the Minimum Required
Acquisition Time ............................................... 241
Configuring the Module ............................................ 240
Conversion Clock (TAD) ........................................... 242
Conversion Status (GO/DONE bit) .......................... 239
Conversion TAD Cycles ............................................ 243
Conversions ............................................................. 243
Converter Characteristics ........................................ 352
Minimum Charging Time .......................................... 241
Selecting the Conversion Clock ............................... 242
Special Event Trigger (CCP) .................................... 124
Special Event Trigger (ECCP) ......................... 131, 243
TAD vs. Device Operating Frequencies
(For Extended, LC Devices) (table) ................. 242
TAD vs. Device Operating Frequencies (table) ........ 242
Use of the ECCP Trigger ......................................... 243
Absolute Maximum Ratings ............................................. 325
AC (Timing) Characteristics ............................................. 335
Parameter Symbology ............................................. 335
Access Bank ...................................................................... 54
ACKSTAT ......................................................................... 171
ADCON0 Register ............................................................ 237
GO/DONE bit ........................................................... 239
ADCON1 Register ............................................................ 237
ADDLW ............................................................................ 283
Addressable Universal Synchronous Asynchronous
Receiver Transmitter. See USART
ADDWF ............................................................................ 283
ADDWFC ......................................................................... 284
ADRESH Register ............................................................ 237
ADRESH/ADRESL Registers ........................................... 239
ADRESL Register ............................................................ 237
Analog-to-Digital Converter. See A/D
ANDLW ............................................................................ 284
ANDWF ............................................................................ 285
Assembler
MPASM Assembler .................................................. 319
Associated Registers ............................................... 190, 195
B
Bank Select Register (BSR) ............................................... 54
Baud Rate Generator ....................................................... 167
BC .................................................................................... 285
BCF .................................................................................. 286
BF ..................................................................................... 171
Bit Timing Configuration Registers
BRGCON1 ............................................................... 232
BRGCON2 ............................................................... 232
BRGCON3 ............................................................... 232
Block Diagrams
A/D ........................................................................... 239
Analog Input Model ...........................................240, 249
Baud Rate Generator .............................................. 167
CAN Buffers and Protocol Engine ........................... 198
Capture Mode (CCP Module) .................................. 123
Comparator I/O Operating Modes ........................... 246
Comparator Output .................................................. 248
Compare (CCP Module) Mode Operation ............... 124
Enhanced PWM ....................................................... 132
Interrupt Logic ............................................................ 78
Low Voltage Detect ................................................. 256
Low Voltage Detect with External Input ................... 256
MSSP (I2C Master Mode) ........................................ 165
MSSP (I2C Mode) .................................................... 150
MSSP (SPI Mode) ................................................... 141
On-Chip Reset Circuit ................................................ 25
PIC18F248/258 Architecture ....................................... 8
PIC18F448/458 Architecture ....................................... 9
PLL ............................................................................ 19
PORTC (Peripheral Output Override) ........................ 98
PORTD and PORTE (Parallel Slave Port) ............... 105
PORTD in I/O Port Mode ......................................... 100
PORTE .................................................................... 102
PWM (CCP Module) ................................................ 126
RA3:RA0 and RA5 Port Pins ..................................... 93
RA4/T0CKI Pin .......................................................... 93
RA6/OSC2/CLKO Pin ................................................ 94
RB1:RB0 Port Pins .................................................... 95
RB2:CANTX Port Pins ............................................... 96
RB3:CANRX Port Pins ............................................... 96
RB7:RB4 Port Pins .................................................... 95
Reads from FLASH Program Memory ....................... 69
Receive Buffer ......................................................... 226
Table Read Operation ............................................... 65
Table Write Operation ................................................ 66
Table Writes to FLASH Program Memory ................. 71
Timer0 Module
16-bit Mode ...................................................... 108
8-bit Mode ........................................................ 108
Timer1 Module ......................................................... 112
Timer1 Module (16-bit Read/Write Mode) ............... 112
Timer2 ..................................................................... 116
Timer3 ..................................................................... 118
Timer3 (16-bit Read/Write Mode) ............................ 118
Transmit Buffer ........................................................ 223
USART Receive ....................................................... 189
USART Transmit ...................................................... 187
Voltage Reference ................................................... 252
Watchdog Timer ...................................................... 269
BN .................................................................................... 286
BNC ................................................................................. 287
BNN ................................................................................. 287
BNOV ............................................................................... 288
BNZ .................................................................................. 288
BOR. See Brown-out Reset
BOV ................................................................................. 291
BRA ................................................................................. 289
Preliminary
DS41159B-page 369
PIC18FXX8
BRG. See Baud Rate Generator
Brown-out Reset (BOR) ............................................. 26, 261
BSF .................................................................................. 289
BTFSC ............................................................................. 290
BTFSS .............................................................................. 290
BTG .................................................................................. 291
BZ ..................................................................................... 292
C
CALL ................................................................................ 292
CAN Module ..................................................................... 197
Aborting Transmission ............................................. 224
Acknowledge Error ................................................... 233
Baud Rate Registers ................................................ 215
Baud Rate Setting .................................................... 229
Bit Error .................................................................... 233
Bit Time Partitioning ................................................. 229
Bit Timing Configuration Registers ........................... 232
Calculating TQ, Nominal bit Rate and
Nominal bit Time .............................................. 230
Configuration Mode .................................................. 222
Control and Status Registers ................................... 199
Controller Register Map ........................................... 221
CRC Error ................................................................ 233
Disable Mode ........................................................... 222
Error Detection ......................................................... 233
Error Modes and Error Counters .............................. 233
Error Modes State Diagram ..................................... 234
Error States .............................................................. 233
Filter Mask Truth (table) ........................................... 228
Form Error ................................................................ 233
Hard Synchronization ............................................... 231
I/O Control Register ................................................. 217
Information Processing Time ................................... 230
Initiating Transmission ............................................. 224
Interrupt Acknowledge ............................................. 235
Interrupt Registers .................................................... 218
Interrupts .................................................................. 234
Bus Activity Wake-up ....................................... 235
Bus-Off ............................................................. 235
Code bits .......................................................... 234
Error ................................................................. 235
Message Error ................................................. 235
Receive ............................................................ 234
Receiver Bus Passive ...................................... 235
Receiver Overflow ............................................ 235
Receiver Warning ............................................ 235
Transmit ........................................................... 234
Transmitter Bus Passive .................................. 235
Transmitter Warning ........................................ 235
Lengthening a bit Period .......................................... 231
Listen Only Mode ..................................................... 222
Loopback Mode ........................................................ 223
Message Acceptance Filters and
Masks ....................................................... 212, 228
Message Acceptance Mask and
Filter Operation ................................................ 228
Message Reception ................................................. 226
Message Reception Flow Chart ............................... 227
Message Time-Stamping ......................................... 226
Message Transmission ............................................ 223
Modes of Operation .................................................. 222
Normal Mode ............................................................ 222
Oscillator Tolerance ................................................. 232
Overview .................................................................. 197
Phase Buffer Segments ........................................... 230
DS41159B-page 370
Preliminary
PIC18FXX8
WIN and ICODE bits Usage in Interrupt
Service Routine to Access TX/RX Buffers ....... 201
Writing to FLASH Program Memory .................... 7273
Code Protection ............................................................... 261
COMF ............................................................................... 294
Comparator Module ......................................................... 245
Analog Input Connection Considerations ................. 249
Associated Registers ............................................... 250
Configuration ............................................................ 246
Effects of a RESET .................................................. 249
External Reference Signal ....................................... 247
Internal Reference Signal ........................................ 247
Interrupts .................................................................. 248
Operation ................................................................. 247
Operation During SLEEP ......................................... 249
Outputs .................................................................... 247
Reference ................................................................ 247
Response Time ........................................................ 247
Comparator Specifications ............................................... 334
Comparator Voltage Reference Module ........................... 251
Accuracy/Error ......................................................... 252
Associated Registers ............................................... 253
Configuring ............................................................... 251
Connection Considerations ...................................... 252
Effects of a RESET .................................................. 252
Operation During SLEEP ......................................... 252
Output Buffer Example ............................................. 253
Compare (CCP Module) ................................................... 124
Associated Registers ............................................... 125
CCP1 Pin Configuration ........................................... 124
CCPR1H:CCPR1L Registers ................................... 124
Software Interrupt .................................................... 124
Special Event Trigger ........................113, 119, 124, 243
Timer1/Timer3 Mode Selection ................................ 124
Compare (ECCP Module) ................................................ 131
Associated Registers ............................................... 131
Special Event Trigger ............................................... 131
Compatible 10-bit Analog-to-Digital Converter
(A/D) Module. See A/D.
Configuration Mode (CAN Module) .................................. 222
CPFSEQ .......................................................................... 294
CPFSGT ........................................................................... 295
CPFSLT ........................................................................... 295
Crystal Oscillator
Capacitor Selection .................................................... 18
D
Data EEPROM Memory ..................................................... 59
Associated Registers ................................................. 63
EEADR Register ........................................................ 59
EECON1 Register ...................................................... 59
EECON2 Register ...................................................... 59
Operation During Code Protect .................................. 62
Protection Against Spurious Writes ........................... 62
Reading ...................................................................... 61
Usage ......................................................................... 62
Write Verify ................................................................ 62
Writing to .................................................................... 61
Data Memory ...................................................................... 44
General Purpose Registers ........................................ 44
Special Function Registers ........................................ 44
Data Memory Map
PIC18F248/448 .......................................................... 45
PIC18F258/458 .......................................................... 46
DAW ................................................................................. 296
DC and AC Characteristics Graphs and Tables ............... 355
E
Electrical Characteristics ................................................. 325
Enhanced Capture/Compare/PWM (ECCP) .................... 129
Auto-Shutdown ........................................................ 140
Capture Mode. See Capture (ECCP Module)
Compare Mode. See Compare (ECCP Module)
ECCPR1H Register ................................................. 130
ECCPR1L Register .................................................. 130
Interaction of CCP1 and ECCP1 Modules ............... 130
Pin Assignments for Various Modes ........................ 130
PWM Mode. See PWM (ECCP Module)
Timer Resources ..................................................... 130
Enhanced CCP Auto-Shutdown ...................................... 140
Enhanced PWM Mode. See PWM
(ECCP Module) ........................................................ 132
Errata ................................................................................... 5
Error Recognition Mode (CAN Module) ........................... 222
External Clock Input ........................................................... 19
F
Firmware Instructions ...................................................... 277
FLASH Program Memory .................................................. 65
Associated Registers ................................................. 74
Control Registers ....................................................... 66
Erase Sequence ........................................................ 70
Erasing ...................................................................... 70
Operation During Code Protect ................................. 73
Reading ..................................................................... 69
TABLAT (Table Latch) Register ................................. 68
Table Pointer
Boundaries Based on Operation ....................... 68
Table Pointer Boundaries .......................................... 68
Table Reads and Table Writes .................................. 65
TBLPTR (Table Pointer) Register .............................. 68
Write Sequence ......................................................... 71
Writing to ................................................................... 71
Protection Against Spurious Writes ................... 73
Unexpected Termination ................................... 73
Write Verify ........................................................ 73
G
GOTO .............................................................................. 298
H
Hardware Multiplier ............................................................ 75
Operation ................................................................... 75
Performance Comparison (table) ............................... 75
HS4 (PLL) .......................................................................... 19
Preliminary
DS41159B-page 371
PIC18FXX8
I
I/O Ports ............................................................................. 93
I2C Mode .......................................................................... 150
ACK Pulse ........................................................ 154, 155
Acknowledge Sequence Timing ............................... 174
Baud Rate Generator ............................................... 167
Bus Collision and Arbitration .................................... 175
Bus Collision During a Repeated
START Condition ............................................. 179
Bus Collision During a START Condition ................. 177
Bus Collision During a STOP Condition ................... 180
Clock Arbitration ....................................................... 168
Clock Stretching ....................................................... 160
Effect of a RESET .................................................... 175
General Call Address Support ................................. 164
Master Mode ............................................................ 165
Operation ......................................................... 166
Reception ......................................................... 171
Repeated START Condition Timing ................. 170
Master Mode START Condition Timing ................... 169
Master Mode Transmission ...................................... 171
Multi-Master Mode ................................................... 175
Read/Write bit Information (R/W bit) ................ 154, 155
Registers .................................................................. 150
Serial Clock (RC3/SCK/SCL) ................................... 155
Slave Mode .............................................................. 154
Addressing ....................................................... 154
Reception ......................................................... 155
Transmission .................................................... 155
SLEEP Operation ..................................................... 175
STOP Condition Timing ........................................... 174
ICEPIC In-Circuit Emulator .............................................. 320
ID Locations ............................................................. 261, 275
INCF ................................................................................. 298
INCFSZ ............................................................................ 299
In-Circuit Debugger .......................................................... 275
In-Circuit Serial Programming (ICSP) ...................... 261, 275
Indirect Addressing ............................................................ 56
FSR Register .............................................................. 55
INDF Register ............................................................ 55
Operation ................................................................... 55
INFSNZ ............................................................................ 299
Initialization Conditions for All Registers ............................ 30
Instruction Cycle ................................................................. 41
Instruction Flow/Pipelining ................................................. 41
Instruction Format ............................................................ 279
Instruction Set .................................................................. 277
ADDLW .................................................................... 283
ADDWF .................................................................... 283
ADDWFC ................................................................. 284
ANDLW .................................................................... 284
ANDWF .................................................................... 285
BC ............................................................................ 285
BCF .......................................................................... 286
BN ............................................................................ 286
BNC .......................................................................... 287
BNN .......................................................................... 287
BNOV ....................................................................... 288
BNZ .......................................................................... 288
BOV .......................................................................... 291
BRA .......................................................................... 289
BSF .......................................................................... 289
BTFSC ..................................................................... 290
BTFSS ...................................................................... 290
BTG .......................................................................... 291
DS41159B-page 372
BZ ............................................................................ 292
CALL ........................................................................ 292
CLRF ....................................................................... 293
CLRWDT ................................................................. 293
COMF ...................................................................... 294
CPFSEQ .................................................................. 294
CPFSGT .................................................................. 295
CPFSLT ................................................................... 295
DAW ........................................................................ 296
DCFSNZ .................................................................. 297
DECF ....................................................................... 296
DECFSZ .................................................................. 297
GOTO ...................................................................... 298
INCF ........................................................................ 298
INCFSZ .................................................................... 299
INFSNZ .................................................................... 299
IORLW ..................................................................... 300
IORWF ..................................................................... 300
LFSR ........................................................................ 301
MOVF ...................................................................... 301
MOVFF .................................................................... 302
MOVLB .................................................................... 302
MOVLW ................................................................... 303
MOVWF ................................................................... 303
MULLW .................................................................... 304
MULWF .................................................................... 304
NEGF ....................................................................... 305
NOP ......................................................................... 305
POP ......................................................................... 306
PUSH ....................................................................... 306
RCALL ..................................................................... 307
RESET ..................................................................... 307
RETFIE .................................................................... 308
RETLW .................................................................... 308
RETURN .................................................................. 309
RLCF ....................................................................... 309
RLNCF ..................................................................... 310
RRCF ....................................................................... 310
RRNCF .................................................................... 311
SETF ........................................................................ 311
SLEEP ..................................................................... 312
SUBFWB ................................................................. 312
SUBLW .................................................................... 313
SUBWF .................................................................... 313
SUBWFB ................................................................. 314
SWAPF .................................................................... 314
TBLRD ..................................................................... 315
TBLWT ..................................................................... 316
TSTFSZ ................................................................... 317
XORLW .................................................................... 317
XORWF ................................................................... 318
Summary Table ....................................................... 280
INTCON Register
RBIF bit ...................................................................... 95
Inter-Integrated Circuit. See I2C
Interrupt Sources
A/D Conversion Complete ....................................... 240
CAN Module ............................................................ 234
Capture Complete (CCP) ......................................... 123
Compare Complete (CCP) ....................................... 124
Interrupt-on-Change (RB7:RB4) ................................ 95
TMR0 Overflow ........................................................ 109
TMR1 Overflow .................................................111, 113
TMR2 to PR2 Match ................................................ 116
TMR2 to PR2 Match (PWM) .............................115, 126
TMR3 Overflow .................................................117, 119
Preliminary
PIC18FXX8
Interrupt-on-Change (RB7:RB4) Flag
(RBIF bit) .................................................................... 95
Interrupts ............................................................................ 77
Context Saving During ............................................... 92
Enable Registers ........................................................ 85
Flag Registers ............................................................ 82
INT ............................................................................. 92
PORTB Interrupt-on-Change ..................................... 92
Priority Registers ........................................................ 88
TMR0 ......................................................................... 92
Interrupts, Flag bits
CCP1 Flag (CCP1IF bit) ...........................122, 123, 124
Interrupts, Flag bits
A/D Converter Flag (ADIF bit) .................................. 239
IORLW ............................................................................. 300
IORWF ............................................................................. 300
K
KEELOQ Evaluation and Programming Tools ................... 322
L
LFSR ................................................................................ 301
Listen Only Mode (CAN Module) ..................................... 222
Lookup Tables .................................................................... 43
Computed GOTO ....................................................... 43
Table Reads/Table Writes ......................................... 43
Loopback Mode (CAN Module) ........................................ 222
Low Voltage Detect .......................................................... 255
Characteristics ......................................................... 332
Characteristics (diagram) ......................................... 332
Current Consumption ............................................... 259
Effects of a RESET .................................................. 259
Operation ................................................................. 258
Operation During SLEEP ......................................... 259
Reference Voltage Set Point .................................... 259
Typical Application ................................................... 255
Low Voltage ICSP Programming ..................................... 275
LVD. See Low Voltage Detect.
M
Master Synchronous Serial Port (MSSP). See MSSP.
Master Synchronous Serial Port. See MSSP.
Memory Organization ......................................................... 37
Data Memory ............................................................. 44
Internal Program Memory Operation ......................... 37
Program Memory ....................................................... 37
Migrating from other PICmicro Devices ........................... 366
MOVF ............................................................................... 301
MOVFF ............................................................................. 302
MOVLB ............................................................................. 302
MOVLW ............................................................................ 303
MOVWF ........................................................................... 303
MPLAB C17 and MPLAB C18 C Compilers ..................... 319
MPLAB ICD In-Circuit Debugger ...................................... 321
MPLAB ICE High Performance Universal
In-Circuit Emulator with MPLAB IDE ........................ 320
MPLAB Integrated Development
Environment Software .............................................. 319
MPLINK Object Linker/MPLIB Object Librarian ............... 320
MSSP ............................................................................... 141
Control Registers ..................................................... 141
Enabling SPI I/O ...................................................... 145
I2C Mode Operation ................................................. 154
Operation ................................................................. 144
Overview .................................................................. 141
SPI Master Mode ..................................................... 146
N
NEGF ............................................................................... 305
NOP ................................................................................. 305
Normal Operation Mode (CAN Module) ........................... 222
O
OPCODE Field Descriptions ............................................ 278
OPTION_REG Register
PSA bit ..................................................................... 109
T0CS bit ................................................................... 109
T0PS2:T0PS0 bits ................................................... 109
T0SE bit ................................................................... 109
Oscillator
Effects of SLEEP Mode ............................................. 23
Power-up Delays ....................................................... 23
Switching Feature ...................................................... 20
System Clock Switch bit ............................................ 20
Transitions ................................................................. 21
Oscillator Configurations .................................................... 17
Crystal Oscillator, Ceramic Resonators ..................... 17
EC .............................................................................. 17
ECIO .......................................................................... 17
HS .............................................................................. 17
HS4 ............................................................................ 17
LP .............................................................................. 17
RC ........................................................................17, 18
RCIO .......................................................................... 17
XT .............................................................................. 17
Oscillator Selection .......................................................... 261
Oscillator, Timer1 .............................................. 111, 113, 119
Oscillator, WDT ................................................................ 268
P
Packaging Information ..................................................... 357
Details ...................................................................... 359
Marking .................................................................... 357
Parallel Slave Port (PSP) ..........................................100, 105
Associated Registers ............................................... 106
PORTD .................................................................... 105
PSP Mode Select (PSPMODE) bit .......................... 100
RE2/CS .................................................................... 105
PIC18FXX8 Voltage-Frequency Graph
(Industrial) ................................................................ 326
PIC18LFXX8 Voltage-Frequency Graph
(Industrial) ................................................................ 326
PICDEM 1 Low Cost PICmicro
Demonstration Board ............................................... 321
PICDEM 17 Demonstration Board ................................... 322
PICDEM 2 Low Cost PIC16CXX
Demonstration Board ............................................... 321
PICDEM 3 Low Cost PIC16CXXX
Demonstration Board ............................................... 322
PICSTART Plus Entry Level Development
Programmer ............................................................. 321
Preliminary
DS41159B-page 373
PIC18FXX8
Pin Functions
MCLR/VPP .................................................................. 10
OSC1/CLKI ................................................................ 10
OSC2/CLKO/RA6 ....................................................... 10
RA0/AN0/CVREF ........................................................ 11
RA1/AN1 .................................................................... 11
RA2/AN2/VREF- .......................................................... 11
RA3/AN3/VREF+ ......................................................... 11
RA4/T0CKI ................................................................. 11
RA5/AN4/SS/LVDIN ................................................... 11
RA6 ............................................................................ 11
RB0/INT0 ................................................................... 12
RB1/INT1 ................................................................... 12
RB2/CANTX ............................................................... 12
RB3/CANRX ............................................................... 12
RB4 ............................................................................ 12
RB5/PGM ................................................................... 12
RB6/PGC ................................................................... 12
RB7/PGD ................................................................... 12
RC0/T1OSO/T1CKI .................................................... 13
RC1/T1OSI ................................................................. 13
RC2/CCP1 ................................................................. 13
RC3/SCK/SCL ............................................................ 13
RC4/SDI/SDA ............................................................. 13
RC5/SDO ................................................................... 13
RC6/TX/CK ................................................................ 13
RC7/RX/DT ................................................................ 13
RD0/PSP0/C1IN+ ...................................................... 14
RD1/PSP1/C1IN- ....................................................... 14
RD2/PSP2/C2IN+ ...................................................... 14
RD3/PSP3/C2IN- ....................................................... 14
RD4/PSP4/ECCP/PA ................................................. 14
RD5/PSP5/PB ............................................................ 14
RD6/PSP6/PC ............................................................ 14
RD7/PSP7/PD ............................................................ 14
RE0/AN5/RD .............................................................. 15
RE1/AN6/WR/C1OUT ................................................ 15
RE2/AN7/CS/C2OUT ................................................. 15
Pinout I/O Descriptions ...................................................... 10
Pointer, FSRn ..................................................................... 55
POP .................................................................................. 306
POR. See Power-on Reset.
PORTA
Associated Register Summary ................................... 94
Functions .................................................................... 94
LATA Register ............................................................ 93
PORTA Register ........................................................ 93
TRISA Register .......................................................... 93
PORTB
Associated Registers ................................................. 97
Functions .................................................................... 97
LATB Register ............................................................ 95
PORTB Register ........................................................ 95
RB7:RB4 Interrupt-on-Change Flag
(RBIF bit) ............................................................ 95
TRISB Register .......................................................... 95
PORTC
Associated Registers ................................................. 99
Functions .................................................................... 99
LATC Register ............................................................ 98
PORTC Register ........................................................ 98
RC3/SCK/SCL Pin ................................................... 155
RC7/RX/DT Pin ........................................................ 183
TRISC Register .................................................. 98, 181
DS41159B-page 374
PORTD
Associated Register Summary ................................ 101
Functions ................................................................. 101
LATD Register ......................................................... 100
Parallel Slave Port (PSP) Function .......................... 100
PORTD Register ...................................................... 100
TRISD Register ........................................................ 100
PORTE
Associated Register Summary ................................ 104
Functions ................................................................. 103
LATE Register ......................................................... 102
PORTE Register ...................................................... 102
PSP Mode Select (PSPMODE) bit .......................... 100
RE2/CS .................................................................... 105
TRISE Register ........................................................ 102
Postscaler, WDT
Assignment (PSA bit) ............................................... 109
Rate Select (T0PS2:T0PS0 bits) ............................. 109
Power-down Mode. See SLEEP
Power-on Reset (POR) ...............................................26, 261
MCLR ......................................................................... 26
Oscillator Start-up Timer (OST) ..........................26, 261
PLL Lock Time-out ..................................................... 26
Power-up Timer (PWRT) ....................................26, 261
Time-out Sequence ................................................... 27
Power-up Delays
OSC1 and OSC2 Pin States in SLEEP Mode ........... 23
Prescaler, Capture ........................................................... 123
Prescaler, Timer0 ............................................................. 109
Assignment (PSA bit) ............................................... 109
Rate Select (T0PS2:T0PS0 bits) ............................. 109
Prescaler, Timer2 ............................................................. 126
PRO MATE II Universal Device Programmer .................. 321
Product Identification System .......................................... 381
Program Counter
PCL Register ............................................................. 40
PCLATH Register ...................................................... 40
PCLATU Register ...................................................... 40
Program Memory ............................................................... 37
Fast Register Stack ................................................... 40
Instructions ................................................................ 41
Two-Word .......................................................... 43
Map and Stack for PIC18F248/448 ........................... 37
Map and Stack for PIC18F258/458 ........................... 37
PUSH and POP Instructions ...................................... 40
Return Address Stack ................................................ 38
Return Stack Pointer (STKPTR) ................................ 38
Stack Full/Underflow Resets ...................................... 40
Top-of-Stack Access .................................................. 38
Program Verification and Code Protection ....................... 272
Associated Registers Summary ............................... 272
Configuration Register Protection ............................ 275
Data EEPROM Code Protection .............................. 275
Program Memory Code Protection .......................... 273
Programming, Device Instructions ................................... 277
PUSH ............................................................................... 306
PWM (CCP Module) ........................................................ 126
CCPR1H:CCPR1L Registers ................................... 126
Duty Cycle ............................................................... 126
Example Frequencies/Resolutions .......................... 127
Output Diagram ....................................................... 126
Period ...................................................................... 126
Registers Associated with PWM and Timer2 ........... 127
Setup for PWM Operation ........................................ 127
TMR2 to PR2 Match .........................................115, 126
Preliminary
PIC18FXX8
PWM (ECCP Module) ...................................................... 132
Associated Registers ............................................... 139
Direction Change in Full-Bridge Output Mode ......... 136
Enhanced CCP Auto-Shutdown ............................... 140
Full-Bridge Application Example .............................. 136
Full-Bridge Mode ...................................................... 135
Full-Bridge PWM Output Diagram ........................... 135
Half-Bridge Mode ..................................................... 134
Half-Bridge Output Diagram ..................................... 134
Half-Bridge Output Mode Applications Example ...... 134
Output Configurations .............................................. 132
Output Polarity Configuration ................................... 138
Output Relationships Diagram ................................. 133
Programmable Deadband Delay .............................. 138
PWM Direction Change at Near 100%
Duty Cycle Diagram ......................................... 137
PWM Direction Change Diagram ............................. 137
Setup for PWM Operation ........................................ 139
Standard Mode ........................................................ 132
Start-up Considerations ........................................... 138
System Implementation ........................................... 138
Q
Q Clock ............................................................................ 126
R
RAM. See Data Memory.
RCALL .............................................................................. 307
RCON Register
Significance of Status bits vs.
Initialization Condition ........................................ 27
RCSTA Register ............................................................... 181
SPEN bit .................................................................. 181
Receiver Warning ............................................................. 235
Register File ....................................................................... 44
Register File Summary ....................................................... 49
Registers
ADCON0 (A/D Control 0) ......................................... 237
ADCON1 (A/D Control 1) ......................................... 238
BRGCON1 (Baud Rate Control 1) ........................... 215
BRGCON2 (Baud Rate Control 2) ........................... 216
BRGCON3 (Baud Rate Control 3) ........................... 217
CANCON (CAN Control) .......................................... 199
CANSTAT (CAN Status) .......................................... 200
CCP1CON (CCP1 Control) ...................................... 121
CIOCON (CAN I/O Control) ..................................... 217
CMCON (Comparator Control) ................................ 245
COMSTAT (CAN Communication Status) ............... 203
CONFIG1H (Configuration 1 High) .......................... 262
CONFIG2H (Configuration 2 High) .......................... 263
CONFIG2L (Configuration 2 Low) ............................ 262
CONFIG4L (Configuration 4 Low) ............................ 263
CONFIG5H (Configuration 5 High) .......................... 264
CONFIG5L (Configuration 5 Low) ............................ 264
CONFIG6H (Configuration 6 High) .......................... 265
CONFIG6L (Configuration 6 Low) ............................ 265
CONFIG7H (Configuration 7 High) .......................... 266
CONFIG7L (Configuration 7 Low) ............................ 266
CVRCON (Comparator Voltage
Reference Control) ........................................... 251
Device ID Register 1 ................................................ 267
Device ID Register 2 ................................................ 267
ECCP1CON (ECCP1 Control) ................................. 129
ECCP1DEL (PWM Delay) ........................................ 138
ECCPAS (Enhanced Capture/Compare/PWM
Auto-Shutdown Control) ................................... 140
Preliminary
DS41159B-page 375
PIC18FXX8
TXBnDLC (Transmit Buffer n Data
Length Code) ................................................... 207
TXBnDm (Transmit Buffer n
Data Field Byte m) ........................................... 206
TXBnEIDH (Transmit Buffer n
Extended Identifier, High Byte) ........................ 205
TXBnEIDL (Transmit Buffer n
Extended Identifier, Low Byte) ......................... 206
TXBnSIDH (Transmit Buffer n
Standard Identifier, High Byte) ......................... 205
TXBnSIDL (Transmit Buffer n
Standard Identifier, Low Byte) .......................... 205
TXERRCNT (Transmit Error Count) ......................... 207
TXSTA (USART Transmit Status) ............................ 181
WDTCON (Watchdog Timer Control) ....................... 268
RESET ............................................................... 25, 261, 307
MCLR Reset During Normal Operation ...................... 25
MCLR Reset During SLEEP ...................................... 25
Power-on Reset (POR) .............................................. 25
Programmable Brown-out Reset (PBOR) .................. 25
RESET Instruction ...................................................... 25
Stack Full Reset ......................................................... 25
Stack Underflow Reset ............................................... 25
Watchdog Timer (WDT) Reset ................................... 25
RETFIE ............................................................................ 308
RETLW ............................................................................. 308
RETURN .......................................................................... 309
Revision History ............................................................... 365
RLCF ................................................................................ 309
RLNCF ............................................................................. 310
RRCF ............................................................................... 310
RRNCF ............................................................................. 311
S
Sales and Support ............................................................ 381
SCI. See USART
SCK pin ............................................................................ 141
SDI pin ............................................................................. 141
SDO pin ............................................................................ 141
Serial Clock (SCK) pin ..................................................... 141
Serial Communication Interface. See USART
Serial Peripheral Interface. See SPI
SETF ................................................................................ 311
Slave Select (SS) Pin ....................................................... 141
Slave Select Synchronization ........................................... 147
Slave Select, SS pin ......................................................... 141
SLEEP .............................................................. 261, 270, 312
Software Simulator (MPLAB SIM) .................................... 320
Special Event Trigger. See Compare
Special Features of the CPU ............................................ 261
Configuration bits ..................................................... 261
Configuration bits and Device IDs ............................ 261
Configuration Registers .................................... 262267
Special Function Register Map .......................................... 47
Special Function Registers ................................................ 44
SPI Mode
Associated Registers ............................................... 149
Bus Mode Compatibility ........................................... 149
Effects of a RESET .................................................. 149
Master Mode ............................................................ 146
Master/Slave Connection ......................................... 145
Serial Clock .............................................................. 141
Serial Data In (SDI) pin ............................................ 141
Serial Data Out (SDO) pin ........................................ 141
Slave Mode .............................................................. 147
Slave Select ............................................................. 141
DS41159B-page 376
T
Table Pointer Operations (table) ........................................ 68
TBLRD ............................................................................. 315
TBLWT ............................................................................. 316
Timer0 .............................................................................. 107
16-bit Mode Timer Reads and Writes ...................... 109
Clock Source Edge Select (T0SE bit) ...................... 109
Clock Source Select (T0CS bit) ............................... 109
Operation ................................................................. 109
Overflow Interrupt .................................................... 109
Prescaler .................................................................. 109
Prescaler. See Prescaler, Timer0
Switching Prescaler Assignment ............................. 109
Timer1 .............................................................................. 111
Associated Registers ............................................... 113
Operation ................................................................. 112
Oscillator ...........................................................111, 113
Overflow Interrupt .............................................111, 113
Special Event Trigger (CCP) ............................113, 124
Special Event Trigger (ECCP) ................................. 131
TMR1H Register ...................................................... 111
TMR1L Register ....................................................... 111
TMR3L Register ....................................................... 117
Timer2 .............................................................................. 115
Associated Registers ............................................... 116
Operation ................................................................. 115
Postscaler. See Postscaler, Timer2
PR2 Register ....................................................115, 126
Prescaler. See Prescaler, Timer2
SSP Clock Shift ................................................115, 116
TMR2 Register ......................................................... 115
TMR2 to PR2 Match Interrupt ...................115, 116, 126
Timer3 .............................................................................. 117
Associated Registers ............................................... 119
Operation ................................................................. 118
Oscillator .................................................................. 119
Overflow Interrupt .............................................117, 119
Special Event Trigger (CCP) ................................... 119
TMR3H Register ...................................................... 117
Timing Conditions ............................................................ 336
Load Conditions for Device Specifications .............. 336
Temperature and Voltage
Specifications - AC .......................................... 336
Timing Diagrams
A/D Conversion ........................................................ 353
Acknowledge Sequence .......................................... 174
Baud Rate Generator with Clock Arbitration ............ 168
BRG Reset Due to SDA Arbitration During
START Condition ............................................. 178
Brown-out Reset (BOR) and Low
Voltage Detect ................................................. 339
Preliminary
PIC18FXX8
Bus Collision During a Repeated
START Condition (Case 1) .............................. 179
Bus Collision During a Repeated
START Condition (Case2) ............................... 179
Bus Collision During a STOP
Condition (Case 1) ........................................... 180
Bus Collision During a STOP
Condition (Case 2) ........................................... 180
Bus Collision During START
Condition (SCL = 0) ......................................... 178
Bus Collision During START
Condition (SDA Only) ....................................... 177
Bus Collision for Transmit and
Acknowledge .................................................... 176
Capture/Compare/PWM
(CCP1 and ECCP1) ......................................... 341
CLKO and I/O .......................................................... 338
Clock Synchronization ............................................. 161
External Clock .......................................................... 337
First START bit Timing ............................................. 169
I2C Bus Data ............................................................ 347
I2C Bus START/STOP bits ...................................... 347
I2C Master Mode (Reception, 7-bit Address) ........... 173
I2C Master Mode (Transmission, 7 or
10-bit Address) ................................................. 172
I2C Slave Mode (Transmission,
10-bit Address) ................................................. 159
I2C Slave Mode (Transmission,
7-bit Address) ................................................... 157
I2C Slave Mode SEN = 1 (Reception,
10-bit Address) ................................................. 163
I2C Slave Mode with SEN = 0 (Reception,
10-bit Address) ................................................. 158
I2C Slave Mode with SEN = 0 (Reception,
7-bit Address) ................................................... 156
I2C Slave Mode with SEN = 1 (Reception,
7-bit Address) ................................................... 162
Low Voltage Detect .................................................. 258
Master SSP I2C Bus Data ........................................ 349
Master SSP I2C Bus START/STOP bits .................. 349
Parallel Slave Port (PIC18F248
and PIC18F458) ............................................... 342
Parallel Slave Port Read Waveforms ....................... 106
Parallel Slave Port Write Waveforms ....................... 105
Repeat START Condition ........................................ 170
RESET, Watchdog Timer (WDT), Oscillator
Start-up Timer (OST), Power-up Timer
(PWRT) ............................................................ 339
Slave Mode General Call Address Sequence
(7 or 10-bit Address Mode) .............................. 164
Slave Synchronization ............................................. 147
Slow Rise Time (MCLR Tied to VDD
Via RC Network) ................................................ 29
SPI Master Mode (CKE = 0) .................................... 343
SPI Master Mode (CKE = 1) .................................... 344
SPI Mode (Master Mode) ......................................... 146
SPI Mode (Slave Mode with CKE = 0) ..................... 148
SPI Mode (Slave Mode with CKE = 1) ..................... 148
SPI Slave Mode (CKE = 0) ...................................... 345
SPI Slave Mode (CKE = 1) ...................................... 346
STOP Condition Receive or Transmit Mode ............ 175
Time-out Sequence on POR w/ PLL Enabled
(MCLR Tied to VDD Via RC Network) ................ 29
Time-out Sequence on Power-up
(MCLR Not Tied to VDD): Case 1 ....................... 28
Preliminary
DS41159B-page 377
PIC18FXX8
U
DS41159B-page 378
W
Wake-up from SLEEP ...............................................261, 270
Using Interrupts ....................................................... 270
Watchdog Timer (WDT) ............................................261, 268
Associated Registers ............................................... 269
Control Register ....................................................... 268
Postscaler ................................................................ 269
Programming Considerations .............................66, 268
RC Oscillator ............................................................ 268
Time-out Period ....................................................... 268
WCOL ...............................................................169, 171, 174
WCOL Status Flag ........................................................... 169
WDT. See Watchdog Timer. ............................................ 268
WWW, On-Line Support ...................................................... 5
X
XORLW ............................................................................ 317
XORWF ........................................................................... 318
Preliminary
PIC18FXX8
ON-LINE SUPPORT
013001
www.microchip.com
The file transfer site is available by using an FTP service to connect to:
ftp://ftp.microchip.com
The web site and file transfer site provide a variety of
services. Users may download files for the latest
Development Tools, Data Sheets, Application Notes,
Users Guides, Articles and Sample Programs. A variety of Microchip specific business information is also
available, including listings of Microchip sales offices,
distributors and factory representatives. Other data
available for consideration is:
Latest Microchip Press Releases
Technical Support Section with Frequently Asked
Questions
Design Tips
Device Errata
Job Postings
Microchip Consultant Program Member Listing
Links to other useful web sites related to
Microchip Products
Conferences for products, Development Systems,
technical information and more
Listing of seminars and events
Preliminary
DS41159B-page 379
PIC18FXX8
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 Data Sheet.
To:
RE:
Reader Response
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________
Application (optional):
Would you like a reply?
Device: PIC18FXX8
N
Literature Number: DS41159B
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 data sheet easy to follow? If not, why?
4. What additions to the data sheet do you think would enhance the structure and subject?
5. What deletions from the data sheet could be made without affecting the overall usefulness?
8. How would you improve our software, systems, and silicon products?
DS41159B-page 380
Preliminary
PIC18FXX8
PIC18FXX8 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
X
Temperature
Range
/XX
XXX
Package
Pattern
Examples:
a)
b)
Device
PIC18F248/258(1), PIC18F448/458(1),
PIC18F448/458T(2)
(2)
PIC18F248/258T ,
;
VDD range 4.2V to 5.5V
PIC18LF248/258(1), PIC18LF448/458(1), PIC18LF248/258T(2),
PIC18LF448/458T(2);
VDD range 2.0V to 5.5V
Temperature Range I
E
= -40C to +85C
= -40C to +125C
Package
PT
L
SO
SP
P
=
=
=
=
=
Pattern
(Industrial)
(Extended)
c)
Note 1:
2:
Please specify which device, revision of silicon and Data Sheet (include Literature #) you are using.
New Customer Notification System
Register on our web site (www.microchip.com/cn) to receive the most current information on our products.
Preliminary
DS41159B-page 381
M
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
Japan
Corporate Office
Australia
Rocky Mountain
China - Beijing
Atlanta
500 Sugar Mill Road, Suite 200B
Atlanta, GA 30350
Tel: 770-640-0034 Fax: 770-640-0307
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, Indiana 46902
Tel: 765-864-8360 Fax: 765-864-8387
Los Angeles
18201 Von Karman, Suite 1090
Irvine, CA 92612
Tel: 949-263-1888 Fax: 949-263-1338
China - Chengdu
Microchip Technology Consulting (Shanghai)
Co., Ltd., Chengdu Liaison Office
Rm. 2401, 24th Floor,
Ming Xing Financial Tower
No. 88 TIDU Street
Chengdu 610016, China
Tel: 86-28-86766200 Fax: 86-28-86766599
China - Fuzhou
Microchip Technology Consulting (Shanghai)
Co., Ltd., Fuzhou Liaison Office
Unit 28F, World Trade Plaza
No. 71 Wusi Road
Fuzhou 350001, China
Tel: 86-591-7503506 Fax: 86-591-7503521
China - Shanghai
Microchip Technology Consulting (Shanghai)
Co., Ltd.
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
San Jose
New York
Toronto
6285 Northam Drive, Suite 108
Mississauga, Ontario L4V 1X5, Canada
Tel: 905-673-0699 Fax: 905-673-6509
India
Microchip Technology Inc.
India Liaison Office
Divyasree Chambers
1 Floor, Wing A (A3/A4)
No. 11, OShaugnessey Road
Bangalore, 560 025, India
Tel: 91-80-2290061 Fax: 91-80-2290062
Korea
Microchip Technology Korea
168-1, Youngbo Bldg. 3 Floor
Samsung-Dong, Kangnam-Ku
Seoul, Korea 135-882
Tel: 82-2-554-7200 Fax: 82-2-558-5934
Singapore
Microchip Technology Singapore Pte Ltd.
200 Middle Road
#07-02 Prime Centre
Singapore, 188980
Tel: 65-6334-8870 Fax: 65-6334-8850
Taiwan
Microchip Technology (Barbados) Inc.,
Taiwan Branch
11F-3, No. 207
Tung Hua North Road
Taipei, 105, Taiwan
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPE
Denmark
Microchip Technology Nordic ApS
Regus Business Centre
Lautrup hoj 1-3
Ballerup DK-2750 Denmark
Tel: 45 4420 9895 Fax: 45 4420 9910
France
Microchip Technology SARL
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
Microchip Technology GmbH
Gustav-Heinemann Ring 125
D-81739 Munich, Germany
Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
Italy
Microchip Technology SRL
Centro Direzionale Colleoni
Palazzo Taurus 1 V. Le Colleoni 1
20041 Agrate Brianza
Milan, Italy
Tel: 39-039-65791-1 Fax: 39-039-6899883
United Kingdom
Microchip Ltd.
505 Eskdale Road
Winnersh Triangle
Wokingham
Berkshire, England RG41 5TU
Tel: 44 118 921 5869 Fax: 44-118 921-5820
Austria
Microchip Technology Austria GmbH
Durisolstrasse 2
A-4600 Wels
Austria
Tel: 43-7242-2244-399
Fax: 43-7242-2244-393
05/16/02
DS41159B-page 382
Preliminary