PIC16F15213
PIC16F15213
Introduction
The PIC16F152 microcontroller family has a suite of digital and analog peripherals that enable cost-sensitive sensor
and real-time control applications. This product family is available from 8 to 44-pin packages in a memory range
of 3.5 KB to 28 KB, with speeds up to 32 MHz. The family includes a 10-bit Analog-to-Digital Converter (ADC),
Peripheral Pin Select (PPS), Memory Access Partition (MAP) to support users in data protection and bootloader
applications, Device Information Area (DIA) that stores Fixed Voltage Reference (FVR) offset values to help improve
ADC accuracy, digital communication peripherals, timers and waveform generators. This small form factor device is
well suited for low-cost sensor and control applications.
Interrupt-on-Change Pins
Device Information Area
Program Flash Memory
(External/Internal)
16-Bit Timers(2)
Watchdog Timer
10-Bit PWM/
I/O Pins(1) /
Data SRAM
EUSART
(bytes)
(bytes)
Device
MSSP
CCP
Interrupt-on-Change Pins
Device Information Area
Program Flash Memory
(External/Internal)
16-Bit Timers(2)
Watchdog Timer
10-Bit PWM/
I/O Pins(1) /
Data SRAM
EUSART
Device
(bytes)
(bytes)
MSSP
CCP
PIC16F15225 14k 1024 Y/Y 12/Y 1/2 2/2 9/2 1 1 Y 1 12 Y
Notes:
1. Total I/O count includes one pin (MCLR) that is input-only.
2. Timer0 can be configured as either an 8 or 16-bit timer.
Core Features
• C Compiler Optimized RISC Architecture
• Operating Speed:
– DC – 32 MHz clock input
– 125 ns minimum instruction time
• 16-Level Deep Hardware Stack
• Low-Current Power-on Reset (POR)
• Configurable Power-up Timer (PWRT)
• Brown-out Reset (BOR)
• Watchdog Timer (WDT)
Memory
• Up to 28 KB of Program Flash Memory
• Up to 2 KB of Data SRAM Memory
• Memory Access Partition (MAP): The Program Flash Memory Can Be Partitioned into:
– Application Block
– Boot Block
– Storage Area Flash (SAF) Block
• Programmable Code Protection and Write Protection
• Device Information Area (DIA) Stores:
– Fixed Voltage Reference (FVR) measurement data
– Microchip Unique Identifier
• Device Characteristics Area (DCI) Stores:
Operating Characteristics
• Operating Voltage Range:
– 1.8V to 5.5V
• Temperature Range:
– Industrial: -40°C to 85°C
– Extended: -40°C to 125°C
Power-Saving Functionality
• Sleep:
– Reduce device power consumption
– Reduce system electrical noise while performing ADC conversions
• Low Power Mode Features:
– Sleep:
• < 900 nA typical @ 3V/25°C (WDT enabled)
• < 600 nA typical @ 3V/25°C (WDT disabled)
– Operating Current:
• 48 µA typical @ 32 kHz, 3V/25°C
• < 1 mA typical @ 4 MHz, 5V/25°C
Digital Peripherals
• Two Capture/Compare/PWM (CCP) Modules:
– 16-bit resolution for Capture/Compare modes
– 10-bit resolution for PWM mode
• Two Pulse-Width Modulators (PWM):
– 10-bit resolution
– Independent pulse outputs
• One Configurable 8/16-Bit Timer (TMR0)
• One 16-Bit Timer (TMR1) with Gate Control
• One 8-Bit Timer (TMR2) with Hardware Limit Timer (HLT)
• One Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART):
– RS-232, RS-485, LIN compatible
– Auto-wake-up on Start
• One Host Synchronous Serial Port (MSSP):
– Serial Peripheral Interface (SPI) mode
• Client Select Synchronization
– Inter-Integrated Circuit (I2C) mode
• 7/10-bit Addressing modes
• Peripheral Pin Select (PPS):
– Enables pin mapping of digital I/O
• Device I/O Port Features:
– Up to 35 I/O pins
– 1 input-only pin
– Individual I/O direction, open-drain, input threshold, slew rate and weak pull-up control
– Interrupt-on-change (IOC) on up to 25 pins
– One external interrupt pin
Analog Peripherals
• Analog-to-Digital Converter (ADC):
– 10-bit resolution
– Up to 28 external input channels
– Two internal input channels
– Internal ADC oscillator (ADCRC)
– Operates in Sleep
– Selectable auto-conversion trigger sources
• Fixed Voltage Reference (FVR):
– Selectable 1.024V, 2.048V and 4.096V output levels
– Internally connected to ADC
Clocking Structure
• High-Precision Internal Oscillator Block (HFINTOSC):
– Selectable frequencies up to 32 MHz
– ±2% at calibration
• Internal 31 kHz Oscillator (LFINTOSC)
• External High-Frequency Clock Input:
– Two External Clock (EC) Power modes
Programming/Debug Features
• In-Circuit Serial Programming™ (ICSP™) via Two Pins
• In-Circuit Debug (ICD) with One Breakpoint via Two Pins
• Debug Integrated On-Chip
Block Diagram
Figure 1. PIC16F15213/14/23/24/43/44 Block Diagram
Ports
PPS Module
Memory Peripherals
Interconnect Bus
Timers ADC
FVR
Power-up Brown-out
Controller
Interrupt
Timer Reset
Power-on
WDT
CPU
Reset
HFINTOSC
with
Active Clock
Precision Band Gap Reference CLKIN EXTOSC Tuning
LFINTOSC
Notes:
1. Available on 20-pin devices only.
2. Available on 14/20-pin devices only.
Table of Contents
Introduction ...........................................................................................................................................................1
Core Features.......................................................................................................................................................2
1. Packages.......................................................................................................................................................8
2. Pin Diagrams.................................................................................................................................................9
6. Register Legend......................................................................................................................................... 19
Trademarks...................................................................................................................................................... 432
1. Packages
Table 1-1. Packages
16- 20-Pin
8-Pin 8-Pin 8-Pin 14-Pin 14-Pin 14-Pin 20-Pin 20-Pin 20-Pin
Device Pin VQFN
PDIP SOIC DFN PDIP SOIC TSSOP PDIP SOIC SSOP
QFN 3x3x0.9
PIC16F15213 • • •
PIC16F15214 • • •
PIC16F15223 • • • •
PIC16F15224 • • • •
PIC16F15243 • • • •
PIC16F15244 • • • •
2. Pin Diagrams
Figure 2-1. 8-Pin PDIP, SOIC, DFN
VDD 1 8 VSS
RA5 2 7 RA0/ICSPDAT
RA4 3 6 RA1/ICSPCLK
MCLR/VPP/RA3 4 5 RA2
VDD 1 14 VSS
RA5 2 13 RA0/ICSPDAT
RA4 3 12 RA1/ICSPCLK
MCLR/VPP/RA3 4 11 RA2
RC5 5 10 RC0
RC4 6 9 RC1
RC3 7 8 RC2
VSS
NC
NC
16 15 14 13
RA5 1 12 RA0/ICSPDAT
RA4 2 11 RA1/ICSPCLK
MCLR/VPP/RA3 3 10 RA2
RC5 4 9 RC0
5 6 7 8
RC4
RC3
RC2
RC1
Note: It is recommended that the exposed bottom pad be connected to VSS, however, it must not be the only VSS
connection to the device.
VDD 1 20 VSS
RA5 2 19 RA0/ICSPDAT
RA4 3 18 RA1/ICSPCLK
MCLR/VPP/RA3 4 17 RA2
RC5 5 16 RC0
RC4 6 15 RC1
RC3 7 14 RC2
RC6 8 13 RB4
RC7 9 12 RB5
RB7 10 11 RB6
RA0/ICSPDAT
RA4
RA5
V DD
VSS
20 19 18 17 16
MCLR/VPP/RA3 1 15 RA1/ICSPCLK
RC5 2 14 RA2
RC4 3 13 RC0
RC3 4 12 RC1
RC6 5 11 RC2
6 7 8 9 10
RC7
RB4
RB7
RB6
RB5
Note: It is recommended that the exposed bottom pad be connected to VSS, however, it must not be the only VSS
connection to the device.
VDD VSS
RA5 RA0/ICSPDAT
3. Pin Allocation Tables RA4 RA1/ICSPCLK
8-Pin PDIP
10-Bit
I/O SOIC ADC Reference Timers CCP MSSP EUSART IOC Interrupt Basic
PWM
DFN
VDD 1 — — — — — — — — — VDD
VSS 8 — — — — — — — — — VSS
Notes:
1. This is a PPS remappable input signal. The input function may be moved from the default location shown to any PORTx pin.
2. All output signals shown in this row are PPS remappable.
3. This is a bidirectional signal. For normal operation, user software must map this signal to the same pin via the PPS input and PPS output registers.
...........continued
I/O 14-Pin PDIP 16-Pin ADC Reference Timers CCP 10-Bit MSSP EUSART IOC Interrupt Basic
SOIC QFN PWM
TSSOP
VDD 1 16 — — — — — — — — — VDD
VSS 14 13 — — — — — — — — — VSS
Notes:
1. This is a PPS remappable input signal. The input function may be moved from the default location shown to any PORTx pin.
2. All output signals shown in this row are PPS remappable.
3. This is a bidirectional signal. For normal operation, user software must map this signal to the same pin via the PPS input and PPS output registers.
4. These pins can be configured for I2 C or SMBus logic levels via the RxyI2C registers. The SCL1/SDA1 signals may be assigned to these pins for expected
operation. PPS assignments of these signals to other pins will operate; however, the logic levels will be standard TTL/ST as selected by the INLVL register.
RC0 16 13 — — — — — — — IOCC0 — —
RC1 15 12 — — — — — — — IOCC1 — —
RC7 9 6 — — — — — — — IOCC7 — —
...........continued
I/O 20-Pin 20-Pin ADC Reference Timers CCP 10-Bit MSSP EUSART IOC Interrupt Basic
PDIP VQFN PWM
SOIC
SSOP
VDD 1 18 — — — — — — — — — VDD
VSS 20 17 — — — — — — — — — VSS
Notes:
1. This is a PPS remappable input signal. The input function may be moved from the default location shown to any PORTx pin.
2. All output signals shown in this row are PPS remappable.
3. This is a bidirectional signal. For normal operation, user software must map this signal to the same pin via the PPS input and PPS output registers.
4. These pins can be configured for I2 C or SMBus logic levels via the RxyI2C registers. The SCL1/SDA1 signals may be assigned to these pins for expected
operation. PPS assignments of these signals to other pins will operate; however, the logic levels will be standard TTL/ST as selected by the INLVL register.
VDD C2
R1
VDD
Vss
R2
MCLR
C1
PIC® MCU
Vss
Decoupling Capacitors
The use of decoupling capacitors on every pair of power supply pins (VDD and VSS) is required.
Consider the following criteria when using decoupling capacitors:
• Value and type of capacitor: A 0.1 μF (100 nF), 10-25V capacitor is recommended. The capacitor may be
a low-ESR device, with a resonance frequency in the range of 200 MHz and higher. Ceramic capacitors are
recommended.
• Placement on the printed circuit board: The decoupling capacitors may be placed as close to the pins as
possible. It is recommended to place the capacitors on the same side of the board as the device. If space is
constricted, the capacitor can be placed on another layer on the PCB using a via; however, ensure that the trace
length from the pin to the capacitor is no greater than 0.25 inch (6 mm).
• Handling high-frequency noise: If the board is experiencing high-frequency noise (upward of tens of MHz),
add a second ceramic type capacitor in parallel to the above described decoupling capacitor. The value of the
second capacitor can be in the range of 0.01 μF to 0.001 μF. Place this second capacitor next to each primary
decoupling capacitor. In high-speed circuit designs, consider implementing a decade pair of capacitances as
close to the power and ground pins as possible (e.g., 0.1 μF in parallel with 0.001 μF).
• Maximizing performance: On the board layout from the power supply circuit, run the power and return traces to
the decoupling capacitors first, and then to the device pins. This ensures that the decoupling capacitors are first
in the power chain. Equally important is to keep the trace length between the capacitor and the power pins to a
minimum, thereby reducing PCB trace inductance.
Tank Capacitors
With on boards with power traces running longer than six inches in length, it is suggested to use a tank capacitor for
integrated circuits, including microcontrollers, to supply a local power source. The value of the tank capacitor may be
determined based on the trace resistance that connects the power supply source to the device, and the maximum
current drawn by the device in the application. In other words, select the tank capacitor that meets the acceptable
voltage sag at the device. Typical values range from 4.7 μF to 47 μF.
R1
R2
MCLR
PIC® MCU
JP
C1
Notes:
1. R1 ≤ 10 kΩ is recommended. A suggested starting value is 10 kΩ. Ensure that the MCLR pin VIH and VIL
specifications are met.
2. R2 ≤ 470Ω will limit any current flowing into MCLR from the extended capacitor, C1, in the event of MCLR pin
breakdown, due to Electrostatic Discharge (ESD) or Electrical Overstress (EOS). Ensure that the MCLR pin
VIH and VIL specifications are met.
Pull-up resistors, series diodes and capacitors on the ICSPCLK and ICSPDAT pins are not recommended as they
can interfere with the programmer/debugger communications to the device. If such discrete components are an
application requirement, they may be removed from the circuit during programming and debugging. Alternatively,
refer to the AC/DC characteristics and timing requirements information in the respective device Flash programming
specification for information on capacitive loading limits, and pin input voltage high (VIH) and input low (VIL)
requirements.
For device emulation, ensure that the Communication Channel Select (i.e., ICSPCLK/ICSPDAT pins), programmed
into the device, matches the physical connections for the ICSP to the Microchip debugger/emulator tool.
Unused I/Os
Unused I/O pins may be configured as outputs and driven to a Logic Low state. Alternatively, connect a 1 kΩ to 10 kΩ
resistor to VSS on unused pins to drive the output to Logic Low.
Register Names
When there are multiple instances of the same peripheral in a device, the Peripheral Control registers will be depicted
as the concatenation of a peripheral identifier, peripheral instance, and control identifier. The Control registers section
will show just one instance of all the register names with an ‘x’ in the place of the peripheral instance number. This
naming convention may also be applied to peripherals when there is only one instance of that peripheral in the device
to maintain compatibility with other devices in the family that contain more than one.
Bit Names
There are two variants for bit names:
• Short name: Bit function abbreviation
• Long name: Peripheral abbreviation + short name
Bit Fields
Bit fields are two or more adjacent bits in the same register. Bit fields adhere only to the short bit naming convention.
For example, the three Least Significant bits of the ADCON2 register contain the ADC Operating Mode Selection bit.
The short name for this field is MD and the long name is ADMD. Bit field access is only possible in C programs. The
following example demonstrates a C program instruction for setting the ADC to operate in Accumulate mode:
ADCON2bits.MD = 0b001;
Individual bits in a bit field can also be accessed with long and short bit names. Each bit is the field name appended
with the number of the bit position within the field. For example, the Most Significant MODE bit has the short bit name
MD2 and the long bit name is ADMD2. The following two examples demonstrate assembly program sequences for
setting the ADC to operate in Accumulate mode:
BCF ADCON2,ADMD2
BCF ADCON2,ADMD1
BSF ADCON2,ADMD0
6. Register Legend
Table 6-1. Register Legend
Symbol Definition
R Readable bit
W Writable bit
HS Hardware settable bit
HC Hardware clearable bit
S Set only bit
C Clear only bit
U Unimplemented bit, read as ‘0’
‘1’ Bit value is set
Data Bus
PCLATH PCL
Data Latch
Program Counter
Address Latch
16-Level Stack
Address Latch
Instruction
Instruction Bus
Latch inc/dec
logic
Data Bus
Address
Decode
Instruction STATUS
Decode and Register
Control
State Machine
MUX
Control Signals
ALU
W Register
Instruction Set
There are 50 instructions for the enhanced mid-range CPU to support the features of the CPU. See the “Instruction
Set Summary” section for more details.
8. Device Configuration
Device configuration consists of the Configuration Words, User ID, Device ID, Device Information Area (DIA) and the
Device Configuration Information (DCI) regions.
Configuration Words
There are five Configuration Words that allow the user to select the device oscillator, Reset and memory protection
options. These are implemented at addresses 0x8007 - 0x800B.
Note: The DEBUG bit in the Configuration Words is managed automatically by device development tools, including
debuggers and programmers. For normal device operation, this bit needs to be maintained as a ‘1’.
Code Protection
Code protection allows the device to be protected from unauthorized access. Internal access to the program memory
is unaffected by any code protection setting.
The entire program memory space is protected from external reads and writes by the CP bit. When CP = 0, external
reads and writes of program memory are inhibited and a read will return all ‘0’s. The CPU can continue to read
program memory, regardless of the protection bit settings. Self-writing the program memory is dependent upon the
write-protection setting.
Write Protection
Write protection allows the device to be protected from unintended self-writes. Applications, such as bootloader
software, can be protected while allowing other regions of the program memory to be modified.
The WRTn Configuration bits determine which of the program memory blocks are protected.
User ID
Four words in the memory space (8000h-8003h) are designated as ID locations where the user can store checksum
or other code identification numbers. These locations are readable and writable during normal execution. See the
“NVMREG Access to DIA, DCI, User ID, DEV/REV ID, and Configuration Words” section for more information
on accessing these memory locations. See the “Memory Programming Specification” section in the “Electrical
Specifications” chapter for information on the electrical parameters required to program these memory locations.
For more information on checksum calculation, see the “Family Programming Specification”.
CONFIG1
Name: CONFIG1
Offset: 0x8007
Configuration Word 1
Bit 15 14 13 12 11 10 9 8
VDDAR CLKOUTEN
Access R/W R/W
Reset 1 1
Bit 7 6 5 4 3 2 1 0
RSTOSC[1:0] FEXTOSC[1:0]
Access R/W R/W R/W R/W
Reset 1 1 1 1
CONFIG2
Name: CONFIG2
Offset: 0x8008
Configuration Word 2
Bit 15 14 13 12 11 10 9 8
DEBUG STVREN PPS1WAY BORV
Access R/W R/W R/W R/W
Reset 1 1 1 1
Bit 7 6 5 4 3 2 1 0
BOREN[1:0] WDTE[1:0] PWRTS[1:0] MCLRE
Access R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1
Value Description
01 PWRT is set at 16 ms
00 PWRT is set at 1 ms
Notes:
1. The DEBUG bit is managed automatically by device development tools including debuggers and
programmers. For normal device operation, this bit needs to be maintained as a ‘1’.
2. The higher voltage selection is recommended for operation at or above 16 MHz.
3. When enabled, Brown-out Reset voltage (VBOR) is set by the BORV bit.
CONFIG3
Name: CONFIG3
Offset: 0x8009
Configuration Word 3
Note: This register is reserved.
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
Access
Reset
CONFIG4
Name: CONFIG4
Offset: 0x800A
Configuration Word 4
Bit 15 14 13 12 11 10 9 8
LVP WRTSAF WRTC WRTB
Access R/W R/W R/W R/W
Reset 1 1 1 1
Bit 7 6 5 4 3 2 1 0
WRTAPP SAFEN BBEN BBSIZE[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1
Notes:
1. The LVP bit cannot be written (to zero) while operating from the LVP programming interface. The purpose
of this rule is to prevent the user from dropping out of LVP mode while programming from LVP mode, or
accidentally eliminating LVP mode from the Configuration state.
2. Once protection is enabled through ICSP or a self-write, it can only be reset through a Bulk Erase.
3. Applicable only if SAFEN = 0.
4. Applicable only if BBEN = 0.
5. The BBSIZE[2:0] bits can only be changed when BBEN = 1. Once BBEN = 0, BBSIZE[2:0] can only be
changed through a Bulk Erase.
6. The maximum Boot Block size is half of the user program memory size. Any selection that will exceed the half
of a device’s program memory will default to a maximum Boot Block size of half PFM. For example, all settings
of BBSIZE from ‘110’ to ‘000’ for a PIC16F15213 (Max PFM = 2048 words) will result in a maximum Boot
Block size of 1024 words.
CONFIG5
Name: CONFIG5
Offset: 0x800B
Bit 15 14 13 12 11 10 9 8
Access
Reset
Bit 7 6 5 4 3 2 1 0
CP
Access R/W
Reset 1
Notes:
1. Since device code protection takes effect immediately, this Configuration Word needs to be written last.
2. Once code protection is enabled it can only be removed through a Bulk Erase.
Device ID
Name: DEVICEID
Offset: 0x8006
Device ID Register
Bit 15 14 13 12 11 10 9 8
Reserved Reserved DEV[11:8]
Access R R R R R R
Reset 1 1 q q q q
Bit 7 6 5 4 3 2 1 0
DEV[7:0]
Access R R R R R R R R
Reset q q q q q q q q
Device Device ID
PIC16F15213 30E3h
PIC16F15214 30E6h
PIC16F15223 30E4h
PIC16F15224 30E7h
PIC16F15243 30E5h
PIC16F15244 30E8h
Revision ID
Name: REVISIONID
Offset: 0x8005
Revision ID Register
Bit 15 14 13 12 11 10 9 8
Reserved Reserved MJRREV[5:2]
Access R R R R R R
Reset 1 0 q q q q
Bit 7 6 5 4 3 2 1 0
MJRREV[1:0] MNRREV[5:0]
Access R R R R R R R R
Reset q q q q q q q q
9. Memory Organization
There are 2 types of memory in PIC16F152 microcontroller devices:
• Program Memory
– Program Flash Memory
– Configuration Words
– Device ID
– Revision ID
– User ID
– Device Information Area (DIA)
– Device Configuration Information (DCI)
• Data Memory
– Core Registers
– Special Function Registers (FSR)
– General Purpose RAM (GPR)
– Common RAM
In Harvard architecture devices, the data and program memories use separate buses that allow for concurrent
access of the two memory spaces.
Additional detailed information on the operation of the Program Flash Memory is provided in the “NVM - Nonvolatile
Memory Module” section.
PC[14:0]
CALL, CALLW
RETURN, RETLW 15
Interrupt, RETFIE
Stack Level 0
Stack Level 1
Stack Level 15
Unimplemented
7FFFh
PC[14:0]
CALL, CALLW
RETURN, RETLW 15
Interrupt, RETFIE
Stack Level 0
Stack Level 1
Stack Level 15
On-chip
Program
Memory
0FFFh
1000h
Unimplemented
7FFFh
There are three methods of accessing constants in program memory. The first method is to use tables of RETLW
instructions, the second, to set an FSR to point to the program memory, and the third is to use the NVMREG interface
to access the program memory.
RETLW Instruction
The RETLW instruction can be used to provide access to tables of constants. The recommended way to create such a
table is shown in the following example.
constants
BRW ;Add Index in W to
;program counter to
;select data
Application Block
Default settings of the Configuration bits (BBEN = 1 and SAFEN = 1) assign all memory in the user Flash area to the
application block.
Boot Block
If BBEN = 1, the Boot Block is enabled and a specific address range is allotted as the Boot Block, based on the value
of the BBSIZE bits.
Important: Storage Area Flash, when enabled, may be used to store variables or other information, often
in devices without EEPROM; however, the SAF is accessed in the same manner as other Flash memory
areas.
Memory Violation
A Memory Execution Violation Reset occurs while executing an instruction that has been fetched from outside a valid
execution area, clearing the MEMV bit. Refer to the “Memory Execution Violation” section in the “Resets” chapter
for the available valid program execution areas and the PCON1 register definition for MEMV bit conditions.
Table 9-2. Memory Access Partition
Partition
REG Address
BBEN = 1 BBEN = 1 BBEN = 0 BBEN = 0
SAFEN = 1 SAFEN = 0 SAFEN = 1 SAFEN = 0
00 0000h ... Last Block
Boot Block(4) Boot Block(4)
Memory Address
Last Boot Block Memory Application
Address + 1(1) ... Block(4) Application
Last Program Memory Application Block(4)
PFM
Address - 80h Block(4) Application
Last Program Memory Block(4)
Address - 7Fh(2) ...
SAF(4) SAF(4)
Last Program Memory
Address
Config Memory
CONFIG CONFIG
Address(3)
Notes:
1. Last Boot Block Memory Address is based on the BBSIZE Configuration bits.
2. Last Program Memory Address is the Flash size given in the “Program Memory Organization” section in the
“NVM - Nonvolatile Memory Control” chapter.
3. Config Memory Address are the address locations of the Configuration Words given in the “NVMREG Access
to DIA, DCI, User ID, DEV/REV ID, and Configuration Words” section in the “NVM - Nonvolatile Memory
Control” chapter.
4. Each memory block has a corresponding write protection fuse defined by the WRTAPP, WRTB, WRTC, and
WRTSAF Configuration bits.
Important: For applications requiring verified unique identification, contact the Microchip Technology
sales office to create a serialized quick turn programming option.
Important: Data is stored in this address range on receiving a request from the customer. The customer
may contact the local sales representative or Field Applications Engineer, and provide them the unique
identifier information that is required to be stored in this region.
Value
PIC16F15213 PIC16F15214
Address Name Description Units
PIC16F15223 PIC16F15224
PIC16F15243 PIC16F15244
00h
Core Registers
(12 bytes)
0Bh
0Ch
Special Function Registers
(up to 20 bytes maximum)
1Fh
20h
6Fh
70h
Common RAM
(16 bytes)
7Fh
Bank Selection
The active bank is selected by writing the bank number into the Bank Select Register (BSR). All data memory can
be accessed either directly via instructions that use the file registers, or indirectly via the two File Select Registers
(FSRs). Data memory uses a 13-bit address. The upper six bits of the address define the Bank Address and the
lower seven bits select the registers/RAM in that bank.
Core Registers
The core registers contain the registers that directly affect the basic operation. The core registers occupy the first 12
addresses of every data memory bank. These registers are listed in the Core Registers table below.
Common RAM
There are 16 bytes of common RAM accessible from all banks.
Legend:
Unimplemented data memory locations, read as '0'
Legend:
Unimplemented data memory locations, read as '0'
Legend:
Unimplemented data memory locations, read as '0'
Legend:
Unimplemented data memory locations, read as '0'
Legend:
Unimplemented data memory locations, read as '0'
Legend:
Unimplemented data memory locations, read as '0'
Core Registers Core Registers Core Registers Core Registers Core Registers Core Registers Core Registers Core Registers
Unimplemented
Read as '0'
1FE3h
1FE4h STATUS_SHAD
1FE5h WREG_SHAD
1FE6h BSR_SHAD
1FE7h PCLATH_SHAD
1FE8h FSR0L_SHAD
1FE9h FSR0H_SHAD
1FEAh FSR1L_SHAD
1FEBh FSR1H_SHAD
1FECh —
1FEDh STKPTR
1FEEh TOSL
1C6Fh 1CEFh 1D6Fh 1DEFh 1E6Fh 1EEFh 1F6Fh 1FEFh TOSH
1C70h Common RAM 1CF0h Common RAM 1D70h Common RAM 1DF0h Common RAM 1E70h Common RAM 1EF0h Common RAM 1F70h Common RAM 1FF0h Common RAM
(Accesses (Accesses (Accesses (Accesses (Accesses (Accesses (Accesses (Accesses
1C7Fh 70h‐7Fh) 1CFFh 70h‐7Fh) 1D7Fh 70h‐7Fh) 1DFFh 70h‐7Fh) 1E7Fh 70h‐7Fh) 1EFFh 70h‐7Fh) 1F7Fh 70h‐7Fh) 1FFFh 70h‐7Fh)
Legend:
Unimplemented data memory locations, read as '0'
BANK 61
1E80h
Core Registers
1E8Bh
1E8Ch
Unimplemented
1E8Dh
Read as '0'
1E8Eh
1E8Fh PPSLOCK
1E90h INTPPS
1E91h T0CKIPPS
1E92h T1CKIPPS
1E93h T1GPPS
1E94h
Unimplemented
Read as '0'
1E9Bh
1E9Ch T2INPPS
1E9Dh
Unimplemented
Read as '0'
1EA0h
1EA1h CCP1PPS
1EA2h CCP2PPS
1EA3h
Unimplemented
Read as '0'
1EC2h
1EC3h ADACTPPS
1EC4h —
1EC5h SSP1CLKPPS
1EC6h SSP1DATPPS
1EC7h SSP1SSPPS
1EC8h
Unimplemented
Read as '0'
1ECAh
1ECBh RX1PPS
1ECCh CK1PPS
1ECDh
Unimplemented
Read as '0'
1E6Fh
1E70h Common RAM
(Accesses
1E7Fh 70h‐7Fh)
Legend:
Unimplemented data memory locations, read as '0'
BANK 62
1F00h 1F3Bh SLRCONA
Core registers 1F3Ch INLVLA
1F0Bh 1F3Dh IOCAP
1F0Ch 1F3Eh IOCAN
Unimplemented
1F3Fh IOCAF
Read as '0'
1F0Fh 1F40h
Unimplemented
1F10h RA0PPS
Read as '0'
1F11h RA1PPS 1F42h
1F12h RA2PPS 1F43h ANSELB(1)
1F13h RA3PPS 1F44h WPUB(1)
1F14h RA4PPS 1F45h ODCONB(1)
1F15h RA5PPS 1F46h SLRCONB(1)
1F16h 1F47h INLVLB(1)
Unimplemented
1F48h IOCBP(1)
Read as '0'
1F1Bh 1F49h IOCBN(1)
1F1Ch RB4PPS (1)
1F4Ah IOCBF(1)
1F1Dh RB5PPS(1) 1F4Bh
Unimplemented
1F1Eh RB6PPS(1)
Read as '0'
1F1Fh RB7PPS(1) 1F4Dh
1F20h RC0PPS(2) 1F4Eh ANSELC(2)
1F21h RC1PPS(2) 1F4Fh WPUC(2)
1F22h RC2PPS(2) 1F50h ODCONC(2)
1F23h RC3PPS(2) 1F51h SLRCONC(2)
1F24h RC4PPS(2) 1F52h INLVLC(2)
1F25h RC5PPS(2) 1F53h IOCCP(2)
1F26h RC6PPS(1) 1F54h IOCCN(2)
1F27h RC7PPS(1) 1F55h IOCCF(2)
1F28h 1F56h
Unimplemented Unimplemented
Read as '0' Read as '0'
1F37h 1F6Fh
1F38h ANSELA 1F70h Common RAM
1F39h WPUA (Accesses
1F3Ah ODCONA 1F7Fh 70h‐7Fh)
STATUS Register
The STATUS register contains:
• the arithmetic status of the ALU
• the Reset status
The STATUS register can be the destination for any instruction, like any other register. If the STATUS register is the
destination for an instruction that affects the Z, DC or C bits, then writes to these three bits are disabled. These bits
are set or cleared according to the device logic. Furthermore, the TO and PD bits are not writable. Therefore, the
result of an instruction with the STATUS register as destination may be different than intended.
For example, CLRF STATUS will clear bits [4:3] and [1:0], and set the Z bit. This leaves the STATUS register as
‘000u u1uu’ (where u = unchanged).
It is recommended, therefore, that only BCF, BSF, SWAPF and MOVWF instructions are used to alter the STATUS
register, because these instructions do not affect any Status bits. For other instructions not affecting any Status bits,
refer to the “Instruction Set Summary” chapter.
Important: The C and DC bits operate as Borrow and Digit Borrow out bits, respectively, in subtraction.
14 PCH PCL 0
PC CALLW
6 7 8
0
PCLATH W
14 PCH PCL 0
PC BRW
15
PC + W
14 PCH PCL 0
PC BRA
15
PC + OPCODE [8:0]
Modifying PCL
Executing any instruction with the PCL register as the destination simultaneously causes the Program Counter
PC[14:8] bits (PCH) to be replaced by the contents of the PCLATH register. This allows the entire contents of the
Program Counter to be changed by writing the desired upper seven bits to the PCLATH register. When the lower
eight bits are written to the PCL register, all 15 bits of the Program Counter will change to the values contained in the
PCLATH register and those being written to the PCL register.
Computed GOTO
A computed GOTO is accomplished by adding an offset to the Program Counter (ADDWF PCL). When performing a
table read using a computed GOTO method, care has to be exercised if the table location crosses a PCL memory
boundary (each 256-byte block). Refer to application note AN556, “Implementing a Table Read” (DS00556).
Branching
The branching instructions add an offset to the PC. This allows relocatable code and code that crosses page
boundaries. There are two forms of branching, BRW and BRA. The PC will have incremented to fetch the next
instruction in both cases. When using either branching instruction, a PCL memory boundary may be crossed.
If using BRW, load the W register with the desired unsigned address and execute BRW. The entire PC will be loaded
with the address PC + 1 + W.
If using BRA, the entire PC will be loaded with PC + 1 + the signed value of the operand of the BRA instruction.
Stack
All devices have a 16-level by 15-bit wide hardware stack. The stack space is not part of either program or data
space. The PC is PUSHed onto the stack when the CALL or CALLW instructions are executed or an interrupt causes
a branch. The stack is POPed in the event of a RETURN, RETLW or a RETFIE instruction execution. PCLATH is not
affected by a PUSH or POP operation.
The stack operates as a circular buffer if the STVREN Configuration bit is programmed to ‘0’. This means that after
the stack has been PUSHed sixteen times, the seventeenth PUSH overwrites the value that was stored from the first
PUSH. The eighteenth PUSH overwrites the second PUSH, and so on. The STKOVF and STKUNF flag bits will be
set on an Overflow/Underflow, regardless of whether the Reset is enabled.
If the STVREN bit is programmed to ‘1’, the device will be reset if the stack is PUSHed beyond the sixteenth level or
POPed beyond the fist level, setting the appropriate bits (STKOVF or STKUNF, respectively).
Important: There are no instructions/mnemonics called PUSH or POP. These are actions that occur
from the execution of the CALL, CALLW, RETURN, RETLW and RETFIE instructions or the vectoring to an
interrupt address.
Important: Care must be taken when modifying STKPTR while interrupts are enabled.
During normal program operation, CALL, CALLW and interrupts will increment STKPTR, while RETLW, RETURN and
RETFIE will decrement STKPTR. STKPTR can be monitored to obtain the value of stack memory left at any given
time. STKPTR always points at the currently used place on the stack. Therefore, a CALL or CALLW will increment
STKPTR and then write the PC, and a return will unload the PC value from the stack and then decrement STKPTR.
Reference the following figures for examples of accessing the stack.
0x0F
0x0E
0x0D
0x0C
0x0B
0x0A
0x09 This figure shows the stack configuration
after the first CALL or a single interrupt.
0x08 If a RETURN instruction is executed, the
0x07 return address will be placed in the
Program Counter and the Stack Pointer
0x06 decremented to the empty state (0x1F).
0x05
0x04
0x03
0x02
0x01
TOSH:TOSL 0x00 Return Address STKPTR = 0x00
0x0F
0x0E
0x0D
0x0C
After seven CALLs or six CALLs and an
0x0B interrupt, the stack looks like the figure on
the left. A series of RETURN instructions will
0x0A
repeatedly place the return addresses into
0x09 the Program Counter and pop the stack.
0x08
0x07
TOSH:TOSL 0x06 Return Address STKPTR = 0x06
Overflow/Underflow Reset
If the STVREN bit is programmed to ‘1’, the device will be reset if the stack is PUSHed beyond the sixteenth level or
POPed beyond the first level, setting the appropriate bits (STKOVF or STKUNF, respectively).
Indirect Addressing
The INDFn registers are not physical registers. Any instruction that accesses an INDFn register actually accesses
the register at the address specified by the File Select Registers (FSR). If the FSRn address specifies one of the two
INDFn registers, the read will return ‘0’ and the write will not occur (though Status bits may be affected). The FSRn
register value is created by the pair FSRnH and FSRnL.
The FSR registers form a 16-bit address that allows an addressing space with 65536 locations. These locations are
divided into three memory regions:
• Traditional/Banked Data Memory
• Linear Data Memory
• Program Flash Memory
Figure 9-19. Indirect Addressing
0x0000 0x0000
Traditional
Data Memory
0x1FFF
0x2000
Linear Data
FSR Memory
Address 0x2FEF
0x2FF0
Range
Reserved
0x7FFF
0x8000 PC value = 0x0000
Program Flash
Memory
From Opcode
5 BSR 0 6 0 7 FSRxH 0 7 FSRxL 0
0 0 0
Bank Select Location Select Bank Select Location Select
0x7F
Bank 0 Bank 1 Bank 2 Bank 63
7 FSRnH 0 7 FSRnL 0
Location Select
0x2000
0x020
Bank 0
0x06F
0x0A0
Bank 1
0x0EF
0x120
Bank 2
0x16F
0x1920
Bank 50
0x196F
0x2FEF
Important: The address range 0x2000 to 0x2FEF represents the complete addressable Linear Data
Memory for PIC® devices (up to Bank 50). The actual implemented Linear Data Memory will differ from one
device to the other in a family.
Unimplemented memory reads as 0x00. Use of the linear data memory region allows buffers to be larger than 80
bytes because incrementing the FSR beyond one bank will go directly to the GPR memory of the next bank.
The 16 bytes of common memory are not included in the linear data memory region.
7 FSRnH 0 7 FSRnL 0
1
Location Select
0x8000
0x0000
Program
Flash
Memory
(low 8 bits)
0x7FFF
0xFFFF
INDF0
Name: INDF0
Offset: 0x0000
Indirect Data Register. This is a virtual register. The GPR/SFR register addressed by the FSR0 register is the target
for all operations involving the INDF0 register.
Bit 7 6 5 4 3 2 1 0
INDF0[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
INDF1
Name: INDF1
Offset: 0x0001
Indirect Data Register. This is a virtual register. The GPR/SFR register addressed by the FSR1 register is the target
for all operations involving the INDF1 register.
Bit 7 6 5 4 3 2 1 0
INDF1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
PCL
Name: PCL
Offset: 0x0002
Bit 7 6 5 4 3 2 1 0
PCL[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
STATUS
Name: STATUS
Offset: 0x0003
Status Register
Bit 7 6 5 4 3 2 1 0
TO PD Z DC C
Access R R R/W R/W R/W
Reset 1 1 0 0 0
Bit 4 – TO Time-Out
Reset States: POR/BOR = 1
All Other Resets = q
Value Description
1 Set at power-up or by execution of CLRWDT or SLEEP instruction
0 A WDT time-out occurred
Bit 3 – PD Power-Down
Reset States: POR/BOR = 1
All Other Resets = q
Value Description
1 Set at power-up or by execution of CLRWDT instruction
0 Cleared by execution of the SLEEP instruction
Bit 2 – Z Zero
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 The result of an arithmetic or logic operation is zero
0 The result of an arithmetic or logic operation is not zero
Bit 0 – C Carry/Borrow(1)
ADDWF, ADDLW, SUBLW, SUBWF instructions
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 A carry-out from the Most Significant bit of the result occurred
0 No carry-out from the Most Significant bit of the result occurred
Note:
1. For Borrow, the polarity is reversed. A subtraction is executed by adding the two’s complement of the second
operand. For Rotate (RRCF, RLCF) instructions, this bit is loaded with either the high or low-order bit of the
Source register.
FSR0
Name: FSR0
Offset: 0x0004
Indirect Address Register
The FSR0 value is the address of the data to which the INDF0 register points.
Bit 15 14 13 12 11 10 9 8
FSR0[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FSR0[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
1. FSR0H: Accesses the high byte FSR0[15:8].
2. FSR0L: Accesses the low byte FSR0[7:0].
FSR1
Name: FSR1
Offset: 0x0006
Indirect Address Register
The FSR1 value is the address of the data to which the INDF1 register points.
Bit 15 14 13 12 11 10 9 8
FSR1[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
FSR1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
1. FSR1H: Accesses the high byte FSR1[15:8].
2. FSR1L: Accesses the low byte FSR1[7:0].
BSR
Name: BSR
Offset: 0x0008
Bit 7 6 5 4 3 2 1 0
BSR[ 5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
WREG
Name: WREG
Offset: 0x0009
Bit 7 6 5 4 3 2 1 0
WREG[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
PCLATH
Name: PCLATH
Offset: 0x000A
Bit 7 6 5 4 3 2 1 0
PCLATH[6:0]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
10. Resets
There are multiple ways to reset this device:
• Power-on Reset (POR)
• Brown-out Reset (BOR)
• MCLR Reset
• WDT Reset
• RESET instruction
• Stack Overflow
• Stack Underflow
• Programming mode exit
To allow VDD to stabilize, an optional Power-up Timer can be enabled to extend the Reset time after a BOR or POR
event.
A simplified block diagram of the On-Chip Reset Circuit is shown in Figure 10-1.
Figure 10-1. Simplified Block Diagram of On-Chip Reset Circuit
Stack Underflow
Stack Overflow
VPP/MCLR MCLRE
Power-on
Reset
VDD
Brown-out Power-up
Reset Timer
LFINTOSC
2
PWRTS[1:0]
BOR Is Always On
When the BOREN bits are programmed to ‘11’, the BOR is always on. The device start-up will be delayed until the
BOR is ready and VDD is higher than the BOR threshold.
BOR protection is active during Sleep. The BOR does not delay wake-up from Sleep.
Note:
1. In this specific case, ‘Release of POR’ and ‘Wake-up from Sleep’, there is no delay in start-up. The BOR
Ready flag (BORRDY = 1) will be set before the CPU is ready to execute instructions because the BOR circuit
is forced on by the BOREN bits.
Figure 10-2. Brown-Out Situations
Rev. 30-000092A
4/12/2017
VDD
VBOR
Internal
Reset TPWRT(1)
VDD
VBOR
VDD
VBOR
Internal
Reset TPWRT(1)
Note: TPWRT delay when the PWRTS bits are enabled (PWRTS != 00).
MCLR Reset
The MCLR is an optional external input that can reset the device. The MCLR function is controlled by the MCLRE bit
and the LVP bit (see Table 10-2). The RMCLR bit will be set to ‘0’ if a MCLR has occurred.
Table 10-2. MCLR Configuration
MCLRE LVP MCLR
x 1 Enabled
1 0 Enabled
0 0 Disabled
MCLR Enabled
When MCLR is enabled and the pin is held low, the device is held in Reset. The MCLR pin is connected to V DD
through an internal weak pull-up.
The device has a noise filter in the MCLR Reset path. The filter will detect and ignore small pulses.
Important: An internal Reset event (RESET instruction, BOR, WDT, POR, STKOVF, STKUNF) does not
drive the MCLR pin low.
MCLR Disabled
When MCLR is disabled, the MCLR becomes input-only and pin functions such as internal weak pull-ups are under
software control.
RESET Instruction
A RESET instruction will cause a device Reset. The RI bit will be set to ‘0’. See Table 10-4 for default conditions after
a RESET instruction has occurred.
Start-Up Sequence
Upon the release of a POR or BOR, the following must occur before the device will begin executing:
1. Power-up Timer runs to completion (if enabled).
2. MCLR must be released (if enabled).
The Power-up Timer runs independently of MCLR Reset. If MCLR is kept low long enough, the Power-up Timer will
expire. Upon bringing MCLR high, the device will begin execution after 10 F OSC cycles (see Figure 10-3). This is
useful for testing purposes or for synchronizing more than one device operating in parallel.
VDD
Internal POR
T PWRT
Power-up Timer
MCLR
Internal RESET
Int. Oscillator
F OSC
Begin Execution
code execution (1) code execution (1)
Internal Oscillator, PWRTS = 00 Internal Oscillator, PWRTS ≠ 00
VDD
Internal POR
T PWRT
Power-up Timer
MCLR
Internal RESET
Ext. Clock (EC)
F OSC
Begin Execution
code execution (1) code execution (1)
External Clock (EC modes), PWRTS = 00 External Clock (EC modes), PWRTS ≠ 00
Note:
1. Code execution begins 10 FOSC cycles after the FOSC clock is released.
...........continued
STKOVF STKUNF RWDT RMCLR RI POR BOR TO PD MEMV Condition
0 0 u 1 1 u 0 1 1 u Brown-out Reset
u u 0 u u u u 0 u u WDT Reset
WDT Wake-up
u u u u u u u 0 0 u
from Sleep
Interrupt Wake-up
u u u u u u u 1 0 u
from Sleep
MCLR Reset
u u u 0 u u u u u 1 during normal
operation
MCLR Reset
u u u 0 u u u 1 0 u
during Sleep
RESET Instruction
u u u u 0 u u u u u
Executed
Stack Overflow
1 u u u u u u u u u Reset (STVREN =
1)
Stack Underflow
u 1 u u u u u u u u Reset (STVREN =
1)
Memory Violation
u u u u u u u u u 0
Reset
MCLR Reset during normal operation 0 -uuu uuuu uuuu 0uuu ---- --1-
MCLR Reset during Sleep 0 ---1 0uuu uuuu 0uuu ---- --u-
WDT Time-out Reset 0 ---0 uuuu uuu0 uuuu ---- --u-
WDT Wake-up from Sleep PC + 1 ---0 0uuu uuuu uuuu ---- --u-
Interrupt Wake-up from Sleep PC + 1(1) ---1 0uuu uuuu uuuu ---- --u-
RESET Instruction Executed 0 ---u uuuu uuuu u0uu ---- --u-
Stack Overflow Reset (STVREN = 1) 0 ---u uuuu 1uuu uuuu ---- --u-
Stack Underflow Reset (STVREN = 1) 0 ---u uuuu u1uu uuuu ---- --u-
Memory Violation Reset 0 -uuu uuuu uuuu uuuu ---- --0-
BORCON
Name: BORCON
Offset: 0x811
Bit 7 6 5 4 3 2 1 0
SBOREN BORRDY
Access R/W R
Reset 1 q
PCON0
Name: PCON0
Offset: 0x813
Bit 7 6 5 4 3 2 1 0
STKOVF STKUNF RWDT RMCLR RI POR BOR
Access R/W/HS R/W/HS R/W/HC R/W/HC R/W/HC R/W/HC R/W/HC
Reset 0 0 1 1 1 0 q
PCON1
Name: PCON1
Offset: 0x814
Bit 7 6 5 4 3 2 1 0
MEMV
Access R/W/HC
Reset 1
0x00
... Reserved
0x0810
0x0811 BORCON 7:0 SBOREN BORRDY
0x0812 Reserved
0x0813 PCON0 7:0 STKOVF STKUNF RWDT RMCLR RI POR BOR
0x0814 PCON1 7:0 MEMV
If an external clock source is selected by the RSTOSC bits, the External Oscillator Mode Select (FEXTOSC)
Configuration bits must be used to select the external clock mode. These modes include:
• ECL: External Clock Low Power mode
• ECH: External Clock High Power mode
The ECH and ECL modes rely on an external logic-level signal as the device clock source. Each mode is optimized
for a specific frequency range. The internal oscillator block produces both low-frequency and high-frequency clock
signals, designated LFINTOSC and HFINTOSC, respectively. Multiple system operating frequencies may be derived
from these clock sources.
Figure 11-1 illustrates a block diagram of the oscillator module.
COSC[1:0]
External
CLKIN Oscillator 11 Sleep
(EXTOSC) System Clock
10
LFINTOSC
Peripheral
31kHz SYSCMD
01 Clock
Oscillator Sleep
2x PLL Mode 00
HFINTOSC
FRQ[2:0]
1 – 32 MHz
MFINTOSC
Oscillator
500 kHz
To Peripherals
SFINTOSC
31.25 kHz
HFINTOSC (1-32 MHz)
1 MHz
Important: The PIC16F152 microcontroller family does not allow the system clock source to be changed
through clock switching. Once the RSTOSC Configuration bits select the oscillator source, the source
cannot be changed via software. If the HFINTOSC is selected as the clock source, the HFINTOSC
frequency may be changed by modifying the FRQ bits.
The instruction clock (FOSC/4) can be routed to the CLKOUT pin when the pin is not in use. The Clock Out
Enable (CLKOUTEN) Configuration bit controls the functionality of the CLKOUT signal. When CLKOUTEN is clear
(CLKOUTEN = 0), the CLKOUT signal is routed to the CLKOUT pin. When CLKOUTEN is set (CLKOUTEN = 1), the
CLKOUT pin functions as an I/O pin.
• Program the FEXTOSC Configuration bits to select the appropriate External Clock (EC) mode:
– ECH mode for oscillators operating at or above 16 MHz (FEXTOSC = 11)
– ECL mode for oscillator operating below 16 MHz (FEXTOSC = 01)
EC Mode
The External Clock (EC) mode allows an externally generated logic level signal to be the system clock source. When
operating in EC mode, an external clock source is connected to the CLKIN input pin. The CLKOUT pin is available as
a general purpose I/O pin or as the CLKOUT signal pin.
EC mode provides two Power mode selections:
• ECH: High Power mode (16 MHz and above)
• ECL: Low Power mode (below 16 MHz)
When EC mode is selected, there is no delay in operation after a Power-on Reset (POR) or wake-up from Sleep.
Because the PIC® MCU design is fully static, stopping the external clock input will have the effect of halting the device
while leaving all data intact. Upon restarting the external clock, the device will resume operation as if no time had
elapsed.
Figure 11-2 shows the pin connections for EC mode.
Figure 11-2. External Clock (EC) Mode Operation
External Clock
Source PIC® MCU
CLKIN
CLKOUT (FOSC / 4)
or I/O(1) CLKOUT
Note:
1. Output depends on the setting of the CLKOUTEN Configuration bit.
HFINTOSC
The High-Frequency Internal Oscillator (HFINTOSC) is a factory-calibrated, precision digitally-controlled internal
clock source that produces a wide range of stable clock frequencies. The HFINTOSC can be enabled by
programming the RSTOSC Configuration bits to select the one of two HFINTOSC options upon device Reset or
power-up.
The HFINTOSC frequency is selected via the HFINTOSC Frequency Selection (FRQ) bits. Fine-tuning of the
HFINTOSC is done via the HFINTOSC Frequency Tuning (TUN) bits.
MFINTOSC
The Medium-Frequency Internal Oscillator (MFINTOSC) generates two constant clock outputs (500 kHz and 31.25
kHz). The MFINTOSC clock signals are created from the HFINTOSC using dynamic divider logic, which provides
constant MFINTOSC clock rates regardless of selected HFINTOSC frequency.
The MFINTOSC cannot be used as the system clock, but can be used as a clock source for certain peripherals, such
as a Timer.
SFINTOSC
The Specified Frequency Internal Oscillator (SFINTOSC) generates a 1 MHz output clock. The SFINTOSC clock
signal is created from the HFINTOSC using dynamic divider logic, which provides a constant SFINTOSC clock rate
regardless of the selected HFINTOSC frequency.
The SFINTOSC cannot be used as the system clock, but may be selected as a clock source for certain peripherals,
such as a Timer.
LFINTOSC
The Low-Frequency Internal Oscillator (LFINTOSC) is a factory-calibrated 31 kHz internal clock source.
The LFINTOSC can be used as a system clock source, and may be used by certain peripheral modules as a clock
source. Additionally, the LFINTOSC provides a time base for the following:
• Power-up Timer (PWRT)
• Watchdog Timer (WDT)
The LFINTOSC is enabled by programming the RSTOSC Configuration bits to select LFINTOSC.
ADCRC
The Analog-to-Digital RC (ADCRC) oscillator is dedicated to the ADC module. This oscillator is also referred to as the
FRC clock. The ADCRC operates at a fixed frequency of approximately 600 kHz, and is used as a conversion clock
source. The ADCRC allows the ADC module to operate in Sleep mode, which can reduce system noise during the
ADC conversion. The ADCRC is automatically enabled when it is selected as the clock source for the ADC module,
or when selected as the clock source of any peripheral that may use it. The ADCRC may also be manually enabled
via the ADC Oscillator Enable (ADOEN) bit, thereby avoiding start-up delays when this source is used intermittently.
The HFINTOSC Oscillator Ready (HFOR), MFINTOSC Oscillator Ready (MFOR), LFINTOSC Oscillator Ready
(LFOR), ADCRC Oscillator Ready (ADOR), and SFINTOSC Oscillator Ready (SFOR) Status bits indicate whether
the respective oscillators are ready for use. These clock sources are available for use at any time, but may require
a finite amount of time before they have reached the specified accuracy levels. When the oscillators are ready and
have achieved the specified accuracy, module hardware sets the respective bits.
When a new value is loaded into the OSCFRQ register, the HFOR bit is cleared by hardware, and will be set again
once the HFINTOSC is ready. During pending OSCFRQ changes, the HFINTOSC will stall at either a high or a low
state until the oscillator locks in the new frequency and resumes operation.
The Oscillator Enable (OSCEN) register can be used to manually enable the following oscillators:
• HFINTOSC
• MFINTOSC
• LFINTOSC
• ADCRC
OSCCON
Name: OSCCON
Offset: 0x88E
Bit 7 6 5 4 3 2 1 0
COSC[1:0]
Access R R
Reset q q
OSCSTAT
Name: OSCSTAT
Offset: 0x890
Oscillator Status Register
Bit 7 6 5 4 3 2 1 0
HFOR MFOR LFOR ADOR SFOR
Access R R R R R
Reset 0 0 0 0 0
OSCEN
Name: OSCEN
Offset: 0x891
Bit 7 6 5 4 3 2 1 0
HFOEN MFOEN LFOEN ADOEN
Access R/W R/W R/W R/W
Reset 0 0 0 0
OSCFRQ
Name: OSCFRQ
Offset: 0x893
Bit 7 6 5 4 3 2 1 0
FRQ[2:0]
Access R/W R/W R/W
Reset 0 0 0
OSCTUNE
Name: OSCTUNE
Offset: 0x892
Bit 7 6 5 4 3 2 1 0
TUN[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
TUN Condition
01 1111 Maximum frequency
• •
• •
• •
00 0000 Center frequency. Oscillator is operating at the selected nominal frequency. (Default value)
• •
• •
• •
10 0000 Minimum frequency
0x00
... Reserved
0x088D
0x088E OSCCON 7:0 COSC[1:0]
0x088F Reserved
0x0890 OSCSTAT 7:0 HFOR MFOR LFOR ADOR SFOR
0x0891 OSCEN 7:0 HFOEN MFOEN LFOEN ADOEN
0x0892 OSCTUNE 7:0 TUN[5:0]
0x0893 OSCFRQ 7:0 FRQ[2:0]
12. Interrupts
The interrupt feature allows certain events to preempt normal program flow. Firmware is used to determine the
source of the interrupt and act accordingly. Some interrupts can be configured to wake the MCU from Sleep mode.
Many peripherals can produce interrupts. Refer to the corresponding chapters for details.
A block diagram of the interrupt logic is shown in Figure 12-1.
Figure 12-1. Interrupt Logic
TMR0IF Wake-up
TMR0IE (If in Sleep mode)
INTF
Peripheral Interrupts INTE
PIR0
IOCIF
PIE0 Interrupt
IOCIE to CPU
PEIE
PIRn
PIEn
GIE
INTCON Register
The Interrupt Control (INTCON) register is readable and writable, and contains the Global Interrupt Enable (GIE),
Peripheral Interrupt Enable (PEIE), and External Interrupt Edge Select (INTEDG) bits.
PIE Registers
The Peripheral Interrupt Enable (PIE) registers contain the individual enable bits for the peripheral interrupts. Due to
the number of peripheral interrupt sources, there are three PIE registers in the PIC16F152 family.
PIR Registers
The Peripheral Interrupt Request (PIR) registers contain the individual flag bits for the peripheral interrupts. Due to
the number of peripheral interrupt sources, there are three PIR registers.
Operation
Interrupts are disabled upon any device Reset. They are enabled by setting the following bits:
• GIE bit
• PEIE bit (if the Interrupt Enable bit of the interrupt event is contained in the PIE registers)
• Interrupt Enable bit(s) for the specific interrupt event(s)
The PIR registers record individual interrupts via interrupt flag bits. Interrupt flag bits will be set, regardless of the
status of the GIE, PEIE and individual interrupt enable bits.
The following events happen when an interrupt event occurs while the GIE bit is set:
• Current prefetched instruction is flushed
• GIE bit is cleared
• Current Program Counter (PC) is pushed onto the stack
• Critical registers are automatically saved to the shadow registers (see Automatic Context Saving)
• PC is loaded with the interrupt vector 0004h
The firmware within the Interrupt Service Routine (ISR) may determine the source of the interrupt by polling the
interrupt flag bits. The interrupt flag bits must be cleared before exiting the ISR to avoid repeated interrupts. Because
the GIE bit is cleared, any interrupt that occurs while executing the ISR will be recorded through its interrupt flag, but
will not cause the processor to redirect to the interrupt vector.
The RETFIE instruction exits the ISR by popping the previous address from the stack, restoring the saved context
from the shadow registers and setting the GIE bit.
For additional information on a specific interrupts operation, refer to its peripheral section.
Important:
1. Individual interrupt flag bits are set, regardless of the state of any other enable bits.
2. All interrupts will be ignored while the GIE bit is cleared. Any interrupt occurring while the GIE bit is
clear will be serviced when the GIE bit is set again.
Interrupt Latency
Interrupt latency is defined as the time from when the interrupt event occurs to the time code execution at the
interrupt vector begins. The interrupt is sampled during Q1 of the instruction cycle. The actual interrupt latency then
depends on the instruction that is executing at the time the interrupt is detected. See the following figures for more
details.
Figure 12-2. Interrupt Latency
Rev. 10-000269E
8/31/2016
CLKIN
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
CLKOUT
INT
pin
Valid Interrupt
window (1) 1 Cycle Instruction at PC
Indeterminate Latency
Latency(2)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
CLKIN
(4)
INT pin
(1)
(1) (2)
INTF (5) Interrupt Latency
GIE
INSTRUCTION FLOW
PC PC PC + 1 PC + 1 0004h 0005h
Instruction
Fetched Inst (PC) Inst (PC + 1) — Inst (0004h) Inst (0005h)
Notes:
1. INTF flag is sampled here (every Q1).
2. Asynchronous interrupt latency = 3-5 TCY. Synchronous latency = 3-4 TCY, where TCY = instruction cycle time.
Latency is the same whether Inst (PC) is a single-cycle or a two-cycle instruction.
3. For minimum width of INT pulse, refer to AC specifications in the “Electrical Specifications” section.
4. INTF may be set any time during the Q4-Q1 cycles.
INT Pin
The INT pin can be used to generate an asynchronous edge-triggered interrupt. This interrupt is enabled by setting
the External Interrupt Enable (INTE) bit. The External Interrupt Edge Select (INTEDG) bit determines on which edge
the interrupt will occur. When the INTEDG bit is set, the rising edge will cause the interrupt. When the INTEDG bit
is clear, the falling edge will cause the interrupt. The External Interrupt Flag (INTF) bit will be set when a valid edge
appears on the INT pin. If the GIE and INTE bits are also set, the processor will redirect program execution to the
interrupt vector.
• FSR registers
• PCLATH register
Upon exiting the Interrupt Service Routine, these registers are automatically restored. Any modifications to these
registers during the ISR will be lost. If modifications to any of these registers are desired, the corresponding shadow
register may be modified and the value will be restored when exiting the ISR. The shadow registers are available in
Bank 63 and are readable and writable. Depending on the user’s application, other registers may also need to be
saved.
INTCON
Name: INTCON
Offset: 0x000B
Bit 7 6 5 4 3 2 1 0
GIE PEIE INTEDG
Access R/W R/W R/W
Reset 0 0 1
Note: Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit or the Global Interrupt Enable (GIE) bit. User software needs to ensure the appropriate interrupt flag bits
are clear prior to enabling an interrupt. This feature allows for software polling.
PIE0
Name: PIE0
Offset: 0x716
Bit 7 6 5 4 3 2 1 0
TMR0IE IOCIE INTE
Access R/W R/W R/W
Reset 0 0 0
Notes:
1. The external interrupt INT pin is selected by INTPPS.
2. Bit PEIE in the INTCON register must be set to enable any peripheral interrupt controlled by the PIE1 and
PIE2 registers. Interrupt sources controlled by the PIE0 register do not require the PEIE bit to be set in order to
allow interrupt vectoring (when the GIE bit in the INTCON register is set).
PIE1
Name: PIE1
Offset: 0x717
Bit 7 6 5 4 3 2 1 0
CCP1IE TMR2IE TMR1IE RC1IE TX1IE BCL1IE SSP1IE ADIE
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note: Bit PEIE of the INTCON register must be set to enable any peripheral interrupt controlled by registers PIE1
and PIE2.
PIE2
Name: PIE2
Offset: 0x718
Bit 7 6 5 4 3 2 1 0
CCP2IE NVMIE TMR1GIE
Access R/W R/W R/W
Reset 0 0 0
Note: Bit PEIE of the INTCON register must be set to enable any peripheral interrupt controlled by PIE1 and PIE2
registers.
PIR0
Name: PIR0
Offset: 0x70C
Bit 7 6 5 4 3 2 1 0
TMR0IF IOCIF INTF
Access R/W/HS R R/W/HS
Reset 0 0 0
Notes:
1. The external interrupt INT pin is selected by INTPPS.
2. The IOCIF bit is the logical OR of all the IOCAF-IOCCF flags. Therefore, to clear the IOCIF flag, application
firmware must clear all of the lower level IOCAF-IOCCF register bits.
3. Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit or the Global Interrupt Enable (GIE) bit. User software needs to ensure the appropriate interrupt flag
bits are cleared before enabling an interrupt.
PIR1
Name: PIR1
Offset: 0x70D
Bit 7 6 5 4 3 2 1 0
CCP1IF TMR2IF TMR1IF RC1IF TX1IF BCL1IF SSP1IF ADIF
Access R/W/HS R/W/HS R/W/HS R R R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
CCP Mode
Value
Capture Compare PWM
1 Capture occurred (must be Compare match occurred (must be Output trailing edge occurred (must
cleared in software) cleared in software) be cleared in software)
0 Capture did not occur Compare match did not occur Output trailing edge did not occur
Notes:
1. RC1IF is read-only. User software must read RC1REG to clear RC1IF.
2. TX1IF is read-only. User software must load TX1REG to clear TX1IF. TX1IF does not indicate a completed
transmission (use TMRT for this purpose instead).
3. Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit or the Global Interrupt Enable (GIE) bit. User software needs to ensure the appropriate interrupt flag
bits are cleared before enabling an interrupt.
PIR2
Name: PIR2
Offset: 0x70E
Bit 7 6 5 4 3 2 1 0
CCP2IF NVMIF TMR1GIF
Access R/W/HS R/W/HS R/W/HS
Reset 0 0 0
CCP Mode
Value
Capture Compare PWM
1 Capture occurred (must be Compare match occurred (must be Output trailing edge occurred (must
cleared in software) cleared in software) be cleared in software)
0 Capture did not occur Compare match did not occur Output trailing edge did not occur
Note: Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding
enable bit or the Global Interrupt Enable (GIE) bit. User software needs to ensure the appropriate interrupt flag bits
are cleared before enabling an interrupt.
0x00
... Reserved
0x070B
0x070C PIR0 7:0 TMR0IF IOCIF INTF
0x070D PIR1 7:0 CCP1IF TMR2IF TMR1IF RC1IF TX1IF BCL1IF SSP1IF ADIF
0x070E PIR2 7:0 CCP2IF NVMIF TMR1GIF
0x070F
... Reserved
0x0715
0x0716 PIE0 7:0 TMR0IE IOCIE INTE
0x0717 PIE1 7:0 CCP1IE TMR2IE TMR1IE RC1IE TX1IE BCL1IE SSP1IE ADIE
0x0718 PIE2 7:0 CCP2IE NVMIE TMR1GIE
WDTE[1:0] = 11
WDTE[1:0] = 10
Sleep 1 23-bit WDT Prescaler WDT
0 Counter Time-out
WDTE[1:0] = 01
SEN
CS PS[4:0]
WDTE[1:0] = 00
Important: Time intervals detailed in this section are based on a minimum nominal interval of 1 ms
generated from the LFINTOSC clock source.
...........continued
WDTE[1:0] SEN Device Mode WDT Mode
Awake Active
10 x
Sleep Disabled
1 X Active
01
0 X Disabled
00 x X Disabled
WDT Is Always On
When the WDTE bits are set to ‘11’, the WDT is always on. The WDT protection is active during Sleep mode.
WDT Is Off
When the WDTE bits are set to ‘00’, the WDT is disabled. In this mode, the SEN bit is ignored.
WDTCON
Name: WDTCON
Offset: 0x80C
Bit 7 6 5 4 3 2 1 0
CS PS[4:0] SEN
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Note:
1. Times are approximate and based on the 31 kHz LFINTOSC clock source.
0x00
... Reserved
0x080B
0x080C WDTCON 7:0 CS PS[4:0] SEN
Note:
1. The maximum Program Flash Memory address for the PIC16F152 family is 0x3FFF.
Important: To modify only a portion of a previously programmed row, the contents of the entire row must
be read. Then, the new data and retained data can be written into the write latches to reprogram the row
of program memory. However, any unprogrammed locations can be written without first erasing the row. In
this case, it is not necessary to save and rewrite the other previously programmed locations.
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, so code cannot execute. An internal programming timer
controls the write time of program memory writes and erases.
A value written to program memory does not need to be a valid instruction. Executing a program memory location
that forms an invalid instruction results in a NOP.
FSR Read
The FSRs are used to provide read access to program memory.
Program memory is accessed by loading the FSRxH:FSRxL register pair with the address to be read, and setting
bit 7 of the FSRxH register to ‘1’. When a MOVIW instruction, or any instruction that accesses INDFx, is executed,
the value loaded into the FSRx register pair points to the location in program memory to be accessed. If the FSRx
register pair points to an INDFx register, the read will return ‘0’.
Reading from NVM requires one instruction cycle. The CPU operation is suspended during the read and resumes
immediately after. Read operations return a single byte of memory.
FSR Write
Writing/erasing the NVM through the FSR registers (e.g., the MOVWI instruction) is not supported in the PIC16F152
microcontroller family.
NVMREG Access
The NVMREG interface allows read/write access to all the locations accessible by FSRs, read/write access to the
User ID locations, and read-only access to the device identification, revision, and configuration data.
Writing or erasing of NVM via the NVMREG interface is prevented when the device is write-protected.
Start
Read Operation
Select Memory:
Program Memory, DIA, DCI,
Config Words, User ID (NVMREGS)
Select
Word Address
(NVMADRH:NVMADRL)
End
Read Operation
Start
Unlock Sequence
Write 0x55 to
NVMCON2
Write 0xAA to
NVMCON2
Initiate
Write or Erase operation
(WR = 1)
End
Unlock Sequence
Note: Sequence begins when NVMCON2 is written; the three unlock steps must occur in the
cycle-accurate order shown. If the timing of the sequence is corrupted by an interrupt or a
debugger Halt, the action will not take place.
Rev. 10-000048B
8/24/2015
Start
Erase Operation
Select Memory:
PFM, Config Words, User ID
(NVMREGS)
Select Erase
Operation (FREE = 1)
Enable Write/Erase
Operation (WREN = 1)
Disable Interrupts
(GIE = 0)
Unlock Sequence
(See Note 1)
Re-enable Interrupts
(GIE = 1)
End
Erase Operation
Note:
1. See the NVM Unlock Sequence section.
Important: The special unlock sequence is required to load a write latch with data or initiate a Flash
programming operation. If the unlock sequence is interrupted, writing to the latches or program memory
will not be initiated.
11. Execute the unlock sequence. The entire program memory latch content is now written to Flash program
memory.
Important: The program memory write latches are reset to the Blank state (0x3FFF) at the completion
of every write or erase operation. As a result, it is not necessary to load all the program memory write
latches. Unloaded latches will remain in the Blank state.
An example of the complete write sequence is shown in Example 15-4. The initial address is loaded into the
NVMADRH:NVMADRL register pair; the data is loaded using indirect addressing.
Figure 15-4. NVMREG Writes to Program Flash Memory with 32 Write Latches
7 6 0 7 5 4 0 7 5 0 7 0
NVMADRH NVMADRL - - NVMDATH NVMDATL
- r9 r8 r7 r6 r5 r4 r3 r2 r1 r0 c4 c3 c2 c1 c0 6 8
14
Write Latch #0 Write Latch #1 Write Latch #30 Write Latch #31
00h 01h 1Eh 1Fh
NVMADRL[4:0]
14 14 14 14
End
Row End Addr
Addr
Address
NVMADRH[6:0] Decode Program Flash Memory
NVMADRL[7:5]
Configuration Memory
User ID, Device ID, Revision ID, Configuration Words, DIA, DCI
NVMREGS = 1
Re-enable interrupts
(GIE = 1)
Disable Write/Erase
Operation (WREN = 0)
Increment Address
(NVMADRH:NVMADRL++)
End Write Operation
Note:
1. See the NVM Unlock Sequence section.
// INTCONbits.GIE
PFM row must be=erased
0; before writes can//occur
Disable interrupts
NVMCON1bits.NVMREGS = 0; // Point to PFM
// PFM row
NVMADR must be erased//before
= PFMStartAddress; writes
Must start can occur
at beginning of PFM row
NVMCON1bits.NVMREGS = 0; // Point to PFM
NVMCON1bits.FREE = 1; //
NVMADR = PFMStartAddress; Specify an erase operation
// Must start at beginning of PFM row
NVMCON1bits.WREN
NVMCON1bits.FREE ==1;1; // Allow erase cycle
// Specify an erase operation
NVMCON1bits.WREN = 1; // Allow erase cycle
// Required unlock sequence
// Required
NVMCON2 unlock sequence
= 0x55;
NVMCON2 = 0x55;
NVMCON2
NVMCON2 == 0xAA;
0xAA;
NVMCON1bits.WR
NVMCON1bits.WR == 1;
1;
NVMCON1bits.LWLO = 1; // Load write latches
NVMCON1bits.LWLO = 1; // Load write latches
// Write to the data latches
//(i Write
for = 0; i < to the data latches
PFM_ROW_SIZE; i++)
for (i = 0; i < PFM_ROW_SIZE; i++)
{{
NVMADR = PFMStartAddress;
NVMADR // Load starting
= PFMStartAddress; // address
Load starting address
NVMDAT NVMDAT = PFM_WRITE_DATA;
= PFM_WRITE_DATA; // Load data
// Load data
// Required
// Required unlock sequence
unlock sequence
NVMCON2 = 0x55;
NVMCON2 = 0x55;
NVMCON2 = 0xAA;
NVMCON2 = 0xAA;
NVMCON1bits.WR = 1;
NVMCON1bits.WR = 1;
PFMStartAddress++;
PFMStartAddress++; // Increment address // Increment address
if(i = (PFM_ROW_SIZE
if(i = (PFM_ROW_SIZE - 1))
- 1)) // All // All latches loaded?
latches loaded?
{ {
NVMCON1bits.LWLO = 0; // Start PFM write
NVMCON1bits.LWLO
} = 0; // Start PFM write
}}
}
NVMCON1bits.WREN == 0;
NVMCON1bits.WREN 0; // Disable writes // Disable writes
INTCONbits.GIE= 1;
INTCONbits.GIE = 1;
// Enable interrupts // Enable interrupts
Start
Modify Operation
Read Operation
(See Note 1)
Modify Image
The words to be modified are
changed in the RAM image
Erase Operation
(See Note 2)
Write Operation
Use RAM image
(See Note 3)
End
Modify Operation
Notes:
1. See Figure 15-1.
2. See Figure 15-3.
3. See Figure 15-5.
NVMREG Access to DIA, DCI, User ID, Device ID, Revision ID, and Configuration Words
NVMREGS can be used to access the following memory regions:
• Device Information Area (DIA)
• Device Configuration Information (DCI)
• User ID region
• Device ID and Revision ID
• Configuration Words
The value of NVMREGS is set to ‘1’ to access these regions. The memory regions listed above will be pointed to
by PC[15] = 1, but not all addresses reference valid data. Different access may exist for reads and writes. Refer to
the table below. When read access is initiated on an address outside the parameters listed in the following table, the
NVMDATH: NVMDATL register pair is cleared, reading back ‘0’s.
Table 15-2. NVMREG Access to DIA, DCI, User ID, Device ID, Revision ID and Configuration Words
(NVMREGS = 1)
Write Verify
It is considered good programming practice to verify that program memory writes agree with the intended value.
Since program memory is stored as a full row then the stored program memory contents are compared with the
intended data stored in RAM after the last write is complete.
Figure 15-7. Program Flash Memory Write Verify Sequence
Rev. 10-000051B
12/4/2015
Start
Verify Operation
Read Operation(1)
NVMDAT = No
RAM image ?
Yes
Fail
Verify Operation
No
Last word ?
Yes
End
Verify Operation
Note:
1. See Figure 15-1.
WRERR Bit
The WRERR bit can be used to determine if a write error occurred. WRERR will be set if one of the following
conditions occurs:
• If WR is set while the NVMADRH:NMVADRL points to a write-protected address
• A Reset occurs while a self-write operation was in progress
• An unlock sequence was interrupted
The WRERR bit is normally set by hardware, but can be set by the user for test purposes. Once set, WRERR must
be cleared in software.
Table 15-3. Actions for PFM When WR = 1
NVMADR
Name: NVMADR
Offset: 0x1C8C
Nonvolatile Memory Address Register
Bit 15 14 13 12 11 10 9 8
NVMADR[14:8]
Access R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
NVMADR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. The individual bytes in this multibyte register can be accessed with the following register names:
– NVMADRH: Accesses the high byte NVMADR[15:8]
– NVMADRL: Accesses the low byte NVMADR[7:0].
2. Bit [15] is undefined while WR = 1.
NVMDAT
Name: NVMDAT
Offset: 0x1C8E
Bit 15 14 13 12 11 10 9 8
NVMDAT[13:8]
Access R/W R/W R/W R/W R/W R/W
Reset x x x x x x
Bit 7 6 5 4 3 2 1 0
NVMDAT[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• NVMDATH: Accesses the high byte NVMDAT[13:8]
• NVMDATL: Accesses the low byte NVMDAT[7:0]
NVMCON1
Name: NVMCON1
Offset: 0x1C90
Bit 7 6 5 4 3 2 1 0
NVMREGS LWLO FREE WRERR WREN WR RD
Access R/W R/W R/S/HC R/W/HS R/W R/S/HC R/S/HC
Reset 0 0 0 0 0 0 0
Bit 3 – WRERR
Write-Reset Error Flag(1,2,3)
Value Description
1 A write operation error has occurred
0 All write operations have completed normally
Notes:
1. Bit is undefined while WR = 1.
2. Bit must be cleared by software; hardware will not clear this bit.
3. Bit may be written to ‘1’ by the user to implement test sequences.
4. This bit can only be set by following the sequence described in the “NVM Unlock Sequence” section.
5. Operations are self-timed and the WR bit is cleared by hardware when complete.
6. Once a write operation is initiated, setting this bit to zero will have no effect.
NVMCON2
Name: NVMCON2
Offset: 0x1C91
Bit 7 6 5 4 3 2 1 0
NVMCON2[7:0]
Access WO WO WO WO WO WO WO WO
Reset 0 0 0 0 0 0 0 0
Note: To unlock writes, a 0x55 must be written first followed by an 0xAA before setting the WR bit of the NVMCON1
register. The value written to this register is used to unlock the writes.
0x00
... Reserved
0x1C8B
7:0 NVMADR[7:0]
0x1C8C NVMADR
15:8 NVMADR[14:8]
7:0 NVMDAT[7:0]
0x1C8E NVMDAT
15:8 NVMDAT[13:8]
0x1C90 NVMCON1 7:0 NVMREGS LWLO FREE WRERR WREN WR RD
0x1C91 NVMCON2 7:0 NVMCON2[7:0]
Overview
Table 16-1. Port Availability per Device
Each port has eight registers to control the operation. These registers are:
• PORTx registers (reads the levels on the pins of the device)
• LATx registers (output latch)
• TRISx registers (data direction)
• ANSELx registers (analog select)
• WPUx registers (weak pull-up)
• INLVLx (input level control)
• SLRCONx registers (slew rate control)
• ODCONx registers (open-drain control)
In this section, the generic names such as PORTx, LATx, TRISx, etc. can be associated with PORTA, PORTB,
PORTC, etc., depending on availability per device.
A simplified model of a generic I/O port, without the interfaces to other peripherals, is shown in the following figure:
Figure 16-1. Generic I/O Port Operation
Re v . 10 -00 00 52 A
TRISx
D Q
Write LATx
Write PORTx VDD
CK
Data Register
Data bus
I/O pin
Read PORTx
To digital peripherals
ANSELx
To analog peripherals
VSS
Reading the PORTx register reads the status of the pins, whereas writing to it will write to the PORT latch. All write
operations are Read-Modify-Write operations. Therefore, a write to a port implies that the PORT pins are read, and
this value is modified, then written to the PORT data latch (LATx). The PORT data latch LATx holds the output port
data and contains the latest value of a LATx or PORTx write. The example below shows how to initialize PORTA.
BANKSEL PORTA ;
CLRF PORTA ;Clear PORTA
BANKSEL LATA ;
CLRF LATA ;Clear Data Latch
BANKSEL ANSELA ;
CLRF ANSELA ;Enable digital drivers
BANKSEL TRISA ;
MOVLW B'00111000' ;Set RA[5:3] as inputs
MOVWF TRISA ;and set others as outputs
Important: Most PORT pins share functions with device peripherals, both analog and digital. In general,
when a peripheral is enabled on a PORT pin, that pin cannot be used as a general purpose output;
however, the pin can still be read.
Important: As a general rule, output operations to a port must use the LAT register to avoid Read-
Modify-Write issues. For example, a bit set or clear operation reads the port, modifies the bit, and writes
the result back to the port. When two bit operations are executed in succession, output loading on the
changed bit may delay the change at the output in which case the bit will be misread in the second bit
operation and written to an unexpected level. The LAT registers are isolated from the port loading and
therefore changes are not delayed.
Important: The ANSELx bits default to the Analog mode after Reset. To use any pins as digital general
purpose or peripheral inputs, the corresponding ANSEL bits must be changed to ‘0’ by the user.
Important: Changing the input threshold selection must be performed while all peripheral modules are
disabled. Changing the threshold level during the time a module is active may inadvertently generate a
transition associated with an input pin, regardless of the actual voltage level on that pin.
rate limited. When a SLRCONx bit is cleared (SLRCONx = 0), the corresponding PORT pin drive slews at the
maximum rate possible.
Important: It is necessary to set open-drain control when using the pin for I2C.
Important: Any peripheral using the I2C pins reads the I2C input levels when enabled via RxyI2C.
I/O Priorities
Each pin defaults to the data latch after Reset. Other functions are selected with the Peripheral Pin Select logic.
Refer to the “PPS - Peripheral Pin Select Module” chapter for more details.
Analog input functions, such as ADC and comparator inputs, are not shown in the Peripheral Pin Select lists. These
inputs are active when the I/O pin is set for Analog mode using the ANSELx register. Digital output functions may
continue to control the pin when it is in Analog mode.
Analog outputs, when enabled, take priority over digital outputs and force the digital output driver into a High-
Impedance state.
The pin function priorities are as follows:
1. Port functions determined by the Configuration bits.
2. Analog outputs (input buffers must be disabled).
3. Analog inputs.
4. Port inputs and outputs from PPS.
MCLR/VPP/RA3 Pin
The MCLR/VPP pin is an input-only pin. Its operation is controlled by the MCLRE Configuration bit. When selected
as a PORT pin (MCLRE = 0), it functions as a digital input-only pin; as such, it does not have TRISx and LATx bits
associated with its operation. Otherwise, it functions as the device’s Master Clear input. In either configuration, the
MCLR/VPP pin also functions as the programming voltage input pin during high-voltage programming.
The MCLR/VPP pin is a read-only bit and will read ‘1’ when MCLRE = 1 (i.e., Master Clear enabled).
Important: On a Power-on Reset (POR), the MCLR/VPP pin is enabled as a digital input-only if Master
Clear functionality is disabled.
The MCLR/VPP pin has an individually controlled internal weak pull-up. When set, the corresponding WPU bit
enables the pull-up. When the MCLR/VPP pin is configured as MCLR (MCLRE = 1 and LVP = 0), or configured for
Low-Voltage Programming (MCLRE = x and LVP = 1), the pull-up is always enabled and the WPU bit has no effect.
PORTx
Name: PORTx
PORTx Register
Bit 7 6 5 4 3 2 1 0
Rx7 Rx6 Rx5 Rx4 Rx3 Rx2 Rx1 Rx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Important:
• Writes to PORTx are actually written to the corresponding LATx register. Reads from PORTx register
return actual I/O pin values.
• The PORT bit associated with the MCLR pin is read-only and will read ‘1’ when the MCLR function is
enabled (LVP = 1 or (LVP = 0 and MCLRE = 1))
• Refer to the “Pin Allocation Table” for details about MCLR pin and pin availability per port
• Unimplemented bits will read back as ‘0’
LATx
Name: LATx
Bit 7 6 5 4 3 2 1 0
LATx7 LATx6 LATx5 LATx4 LATx3 LATx2 LATx1 LATx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Important:
• Writes to LATx are equivalent to writes to the corresponding PORTx register. Reads from LATx
register return register values, not I/O pin values.
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
TRISx
Name: TRISx
Bit 7 6 5 4 3 2 1 0
TRISx7 TRISx6 TRISx5 TRISx4 TRISx3 TRISx2 TRISx1 TRISx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• The TRIS bit associated with the MCLR pin is read-only and the value is ‘1’
• Refer to the “Pin Allocation Table” for details about MCLR pin and pin availability per port
• Unimplemented bits will read back as ‘0’
ANSELx
Name: ANSELx
Bit 7 6 5 4 3 2 1 0
ANSELx7 ANSELx6 ANSELx5 ANSELx4 ANSELx3 ANSELx2 ANSELx1 ANSELx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• When setting a pin as an analog input, the corresponding TRIS bit must be set to Input mode to allow
external control of the voltage on the pin
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
WPUx
Name: WPUx
Bit 7 6 5 4 3 2 1 0
WPUx7 WPUx6 WPUx5 WPUx4 WPUx3 WPUx2 WPUx1 WPUx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• The weak pull-up device is automatically disabled if the pin is configured as an output, but this
register remains unchanged
• If MCLRE = 1, the weak pull-up on MCLR pin is always enabled and the corresponding WPU bit is
not affected
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
INLVLx
Name: INLVLx
Bit 7 6 5 4 3 2 1 0
INLVLx7 INLVLx6 INLVLx5 INLVLx4 INLVLx3 INLVLx2 INLVLx1 INLVLx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
SLRCONx
Name: SLRCONx
Bit 7 6 5 4 3 2 1 0
SLRx7 SLRx6 SLRx5 SLRx4 SLRx3 SLRx2 SLRx1 SLRx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
ODCONx
Name: ODCONx
Bit 7 6 5 4 3 2 1 0
ODCx7 ODCx6 ODCx5 ODCx4 ODCx3 ODCx2 ODCx1 ODCx0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• Refer to the “Pin Allocation Table” for details about pin availability per port
• Unimplemented bits will read back as ‘0’
RxyI2C
Name: RxyI2C
Bit 7 6 5 4 3 2 1 0
SLEW[1:0] PU[1:0] TH[1:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Important: Refer to the “Pin Allocation Table” for details about I2C compatible pins.
0x00
... Reserved
0x0B
0x0C PORTA 7:0 RA5 RA4 RA3 RA2 RA1 RA0
0x0D PORTB 7:0 RB7 RB6 RB5 RB4
0x0E PORTC 7:0 RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0
0x0F
... Reserved
0x11
0x12 TRISA 7:0 TRISA5 TRISA4 Reserved TRISA2 TRISA1 TRISA0
0x13 TRISB 7:0 TRISB7 TRISB6 TRISB5 TRISB4
0x14 TRISC 7:0 TRISC7 TRISC6 TRISC5 TRISC4 TRISC3 TRISC2 TRISC1 TRISC0
0x15
... Reserved
0x17
0x18 LATA 7:0 LATA5 LATA4 LATA2 LATA1 LATA0
0x19 LATB 7:0 LATB7 LATB6 LATB5 LATB4
0x1A LATC 7:0 LATC7 LATC6 LATC5 LATC4 LATC3 LATC2 LATC1 LATC0
0x1B
... Reserved
0x010B
0x010C RB4I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x010D RB6I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x010E RC0I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x010F RC1I2C 7:0 SLEW[1:0] PU[1:0] TH[1:0]
0x0110
... Reserved
0x1F37
0x1F38 ANSELA 7:0 ANSELA5 ANSELA4 ANSELA3 ANSELA2 ANSELA1 ANSELA0
0x1F39 WPUA 7:0 WPUA5 WPUA4 WPUA3 WPUA2 WPUA1 WPUA0
0x1F3A ODCONA 7:0 ODCA5 ODCA4 ODCA2 ODCA1 ODCA0
0x1F3B SLRCONA 7:0 SLRA5 SLRA4 SLRA2 SLRA1 SLRA0
0x1F3C INLVLA 7:0 INLVLA5 INLVLA4 INLVLA3 INLVLA2 INLVLA1 INLVLA0
0x1F3D
... Reserved
0x1F42
0x1F43 ANSELB 7:0 ANSELB7 ANSELB6 ANSELB5 ANSELB4
0x1F44 WPUB 7:0 WPUB7 WPUB6 WPUB5 WPUB4
0x1F45 ODCONB 7:0 ODCB7 ODCB6 ODCB5 ODCB4
0x1F46 SLRCONB 7:0 SLRB7 SLRB6 SLRB5 SLRB4
0x1F47 INLVLB 7:0 INLVLB7 INLVLB6 INLVLB5 INLVLB4
0x1F48
... Reserved
0x1F4D
0x1F4E ANSELC 7:0 ANSELC7 ANSELC6 ANSELC5 ANSELC4 ANSELC3 ANSELC2 ANSELC1 ANSELC0
0x1F4F WPUC 7:0 WPUC7 WPUC6 WPUC5 WPUC4 WPUC3 WPUC2 WPUC1 WPUC0
0x1F50 ODCONC 7:0 ODCC7 ODCC6 ODCC5 ODCC4 ODCC3 ODCC2 ODCC1 ODCC0
0x1F51 SLRCONC 7:0 SLRC7 SLRC6 SLRC5 SLRC4 SLRC3 SLRC2 SLRC1 SLRC0
0x1F52 INLVLC 7:0 INLVLC7 INLVLC6 INLVLC5 INLVLC4 INLVLC3 INLVLC2 INLVLC1 INLVLC0
Overview
The pins denoted in the table below can be configured to operate as interrupt-on-change (IOC) pins for this device.
An interrupt can be generated by detecting a signal that has either a rising edge or a falling edge. Any individual
PORT pin, or combination of PORT pins, can be configured to generate an interrupt.
Table 17-1. IOC Pin Availability per Device
Important: If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is
not available.
Positive
Edge
Detect
IOC
IOCAPx Flag
RAx Write to IOCAFx flag
Set/Reset
Logic
Interrupt Flags
The bits located in the IOCxF registers are status flags that correspond to the interrupt-on-change pins of each port.
If an expected edge is detected on an appropriately enabled pin, then the status flag for that pin will be set, and
an interrupt will be generated if the IOCIE bit is set. The IOCIF bit located in the corresponding Peripheral Interrupt
Request (PIRx) register, is all the IOCxF bits ORd together. The IOCIF bit is read-only. All of the IOCxF Status bits
must be cleared to clear the IOCIF bit.
MOVLW 0xff
XORWF IOCAF, W
ANDWF IOCAF, F
Operation in Sleep
An interrupt-on-change event will wake the device from Sleep mode, if the IOCIE bit is set. If an edge is detected
while in Sleep mode, the IOCxF register will be updated prior to the first instruction executed out of Sleep.
IOCxF
Name: IOCxF
Bit 7 6 5 4 3 2 1 0
IOCxF7 IOCxF6 IOCxF5 IOCxF4 IOCxF3 IOCxF2 IOCxF1 IOCxF0
Access R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS R/W/HS
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
IOCxN
Name: IOCxN
Bit 7 6 5 4 3 2 1 0
IOCxN7 IOCxN6 IOCxN5 IOCxN4 IOCxN3 IOCxN2 IOCxN1 IOCxN0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
IOCxP
Name: IOCxP
Bit 7 6 5 4 3 2 1 0
IOCxP7 IOCxP6 IOCxP5 IOCxP4 IOCxP3 IOCxP2 IOCxP1 IOCxP0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Important:
• If MCLRE = 1 or LVP = 1, the MCLR pin port functionality is disabled and IOC on that pin is not
available
• Refer to the “Pin Allocation Table” for details about pins with configurable IOC per port
0x00
... Reserved
0x1F3C
0x1F3D IOCAP 7:0 IOCAP5 IOCAP4 IOCAP3 IOCAP2 IOCAP1 IOCAP0
0x1F3E IOCAN 7:0 IOCAN5 IOCAN4 IOCAN3 IOCAN2 IOCAN1 IOCAN0
0x1F3F IOCAF 7:0 IOCAF5 IOCAF4 IOCAF3 IOCAF2 IOCAF1 IOCAF0
0x1F40
... Reserved
0x1F47
0x1F48 IOCBP 7:0 IOCBP7 IOCBP6 IOCBP5 IOCBP4
0x1F49 IOCBN 7:0 IOCBN7 IOCBN6 IOCBN5 IOCBN4
0x1F4A IOCBF 7:0 IOCBF7 IOCBF6 IOCBF5 IOCBF4
0x1F4B
... Reserved
0x1F52
0x1F53 IOCCP 7:0 IOCCP7 IOCCP6 IOCCP5 IOCCP4 IOCCP3 IOCCP2 IOCCP1 IOCCP0
0x1F54 IOCCN 7:0 IOCCN7 IOCCN6 IOCCN5 IOCCN4 IOCCN3 IOCCN2 IOCCN1 IOCCN0
0x1F55 IOCCF 7:0 IOCCF7 IOCCF6 IOCCF5 IOCCF4 IOCCF3 IOCCF2 IOCCF1 IOCCF0
Overview
The Peripheral Pin Select (PPS) module connects peripheral inputs and outputs to the device I/O pins. Only digital
signals are included in the selections.
Important: All analog inputs and outputs remain fixed to their assigned pins and cannot be changed
through PPS.
Input and output selections are independent as shown in the figure below.
Figure 18-1. PPS Block Diagram
abcPPS
RA0PPS
RA0
Peripheral abc
RA0
Rxy
Peripheral xyz
Rxy
xyzPPS RxyPPS
PPS Inputs
Each digital peripheral has a dedicated PPS Peripheral Input Selection (xxxPPS) register with which the input pin to
the peripheral is selected. Devices that have 20 leads or less (8/14/16/20) allow PPS routing to any I/O pin, while
devices with 28 leads or more allow PPS routing to I/Os contained within two ports (see the table below).
Important: The notation “xxx” in the generic register name is a placeholder for the peripheral identifier.
For example, xxx = T0CKI for the T0CKIPPS register.
Multiple peripherals can operate from the same source simultaneously. Port reads always return the pin level
regardless of peripheral PPS selection. If a pin also has analog functions associated, the ANSEL bit for that pin must
be cleared to enable the digital input buffer.
Note:
1. Bidirectional pin. The corresponding output must select the same pin.
PPS Outputs
Each digital peripheral has a dedicated Pin Rxy Output Source Selection (RxyPPS) register with which the pin output
source is selected. With few exceptions, the port TRIS control associated with that pin retains control over the pin
output driver. Peripherals that control the pin output driver as part of the peripheral operation will override the TRIS
control as needed. The I2C module is an example of such a peripheral.
Important: The notation ‘Rxy’ is a placeholder for the pin identifier. The ‘x’ holds the place of the PORT
letter and the ‘y’ holds the place of the bit number. For example, Rxy = RA0 for the RA0PPS register.
The table below shows the output codes for each peripheral, as well as the available Port selections.
Table 18-2. PPS Output Selection Table
RxyPPS Output Source
0x09 TMR0
0x08 SDA1/SDO1(1)
0x07 SCL1/SCK1(1)
0x06 DT1
0x05 TX1/CK1
0x04 PWM4
0x03 PWM3
0x02 CCP2
0x01 CCP1
0x00 LATxy
Note:
1. Bidirectional pin. The corresponding input must select the same pin.
Bidirectional Pins
PPS selections for peripherals with bidirectional signals on a single pin must be made so that the PPS input and PPS
output select the same pin. The I2C Serial Clock (SCL) and Serial Data (SDA) are examples of such pins.
Important: The I2C default pins and a limited number of other alternate pins are I 2C and SMBus
compatible. SDA and SCL signals can be routed to any pin; however, pins without I2C compatibility will
operate at standard TTL/ST logic levels as selected by the port’s INLVL register.
PPS Lock
The PPS module provides an extra layer of protection to prevent inadvertent changes to the PPS selection registers.
The PPSLOCKED bit is used in combination with specific code execution blocks to lock/unlock the PPS selection
registers.
Important: The PPSLOCKED bit is clear by default (PPSLOCKED = 0), which allows the PPS selection
registers to be modified without an unlock sequence.
PPS selection registers are locked when the PPSLOCKED bit is set (PPSLOCKED = 1). Setting the PPSLOCKED bit
requires a specific lock sequence as shown in the examples below in both C and assembly languages.
PPS selection registers are unlocked when the PPSLOCKED bit is clear (PPSLOCKED = 0). Clearing the
PPSLOCKED bit requires a specific unlock sequence as shown in the examples below in both C and assembly
languages.
Important: All interrupts must be disabled before starting the lock/unlock sequence to ensure proper
execution.
; suspend interrupts
BCF INTCON0,GIE
BANKSEL PPSLOCK
; required sequence, next 5 instructions
MOVLW 0x55
MOVWF PPSLOCK
MOVLW 0xAA
MOVWF PPSLOCK
; Set PPSLOCKED bit
BSF PPSLOCK,PPSLOCKED
; restore interrupts
BSF INTCON0,GIE
; suspend interrupts
BCF INTCON0,GIE
BANKSEL PPSLOCK
; required sequence, next 5 instructions
MOVLW 0x55
MOVWF PPSLOCK
MOVLW 0xAA
MOVWF PPSLOCK
; Clear PPSLOCKED bit
BCF PPSLOCK,PPSLOCKED
; restore interrupts
BSF INTCON0,GIE
Effects of a Reset
A device Power-on Reset (POR) or Brown-out Reset (BOR) returns all PPS input selection registers to their default
values and clears all PPS output selection registers. All other Resets leave the selections unchanged. Default input
selections are shown in the PPS input register details table. The PPSLOCKED bit is cleared in all Reset conditions.
xxxPPS
Name: xxxPPS
Bit 7 6 5 4 3 2 1 0
PORT[2:0] PIN[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset m m m m m m
Notes:
1. The Reset value ‘m’ is determined by device default locations for that input.
2. Refer to the “Pin Allocation Table” for details about available pins per port.
RxyPPS
Name: RxyPPS
Bit 7 6 5 4 3 2 1 0
RxyPPS[5:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
PPSLOCK
Name: PPSLOCK
Bit 7 6 5 4 3 2 1 0
PPSLOCKED
Access R/W
Reset 0
0x00
... Reserved
0x1E8E
0x1E8F PPSLOCK 7:0 PPSLOCKED
0x1E90 INTPPS 7:0 PORT[2:0] PIN[2:0]
0x1E91 T0CKIPPS 7:0 PORT[2:0] PIN[2:0]
0x1E92 T1CKIPPS 7:0 PORT[2:0] PIN[2:0]
0x1E93 T1GPPS 7:0 PORT[2:0] PIN[2:0]
0x1E94
... Reserved
0x1E9B
0x1E9C T2INPPS 7:0 PORT[2:0] PIN[2:0]
0x1E9D
... Reserved
0x1EA0
0x1EA1 CCP1PPS 7:0 PORT[2:0] PIN[2:0]
0x1EA2 CCP2PPS 7:0 PORT[2:0] PIN[2:0]
0x1EA3
... Reserved
0x1EC2
0x1EC3 ADACTPPS 7:0 PORT[2:0] PIN[2:0]
0x1EC4 Reserved
0x1EC5 SSP1CLKPPS 7:0 PORT[2:0] PIN[2:0]
0x1EC6 SSP1DATPPS 7:0 PORT[2:0] PIN[2:0]
0x1EC7 SSP1SSPPS 7:0 PORT[2:0] PIN[2:0]
0x1EC8
... Reserved
0x1ECA
0x1ECB RX1PPS 7:0 PORT[2:0] PIN[2:0]
0x1ECC CK1PPS 7:0 PORT[2:0] PIN[2:0]
0x1ECD
... Reserved
0x1F0F
0x1F10 RA0PPS 7:0 RA0PPS[5:0]
0x1F11 RA1PPS 7:0 RA1PPS[5:0]
0x1F12 RA2PPS 7:0 RA2PPS[5:0]
0x1F13 Reserved
0x1F14 RA4PPS 7:0 RA4PPS[5:0]
0x1F15 RA5PPS 7:0 RA5PPS[5:0]
0x1F16
... Reserved
0x1F1B
0x1F1C RB4PPS 7:0 RB4PPS[5:0]
0x1F1D RB5PPS 7:0 RB5PPS[5:0]
0x1F1E RB6PPS 7:0 RB6PPS[5:0]
0x1F1F RB7PPS 7:0 RB7PPS[5:0]
0x1F20 RC0PPS 7:0 RC0PPS[5:0]
0x1F21 RC1PPS 7:0 RC1PPS[5:0]
0x1F22 RC2PPS 7:0 RC2PPS[5:0]
0x1F23 RC3PPS 7:0 RC3PPS[5:0]
0x1F24 RC4PPS 7:0 RC4PPS[5:0]
0x1F25 RC5PPS 7:0 RC5PPS[5:0]
0x1F26 RC6PPS 7:0 RC6PPS[5:0]
0x1F27 RC7PPS 7:0 RC7PPS[5:0]
T0CS
8-bit TMR0 Body Diagram (T016BIT = 0) 16-bit TMR0 Body Diagram (T016BIT = 1)
Read TMR0L
COMPARATOR OUT
Write TMR0L
T0_match 8
8
TMR0H
Timer 0 High
Byte
Latch 8
Enable
TMR0H
8
Internal Data Bus
Timer0 Operation
Timer0 can operate as either an 8-bit or 16-bit timer. The mode is selected with the MD16 bit.
8-Bit Mode
In this mode, Timer0 increments on the rising edge of the selected clock source. A prescaler on the clock input gives
several prescale options (see the prescaler control bits, CKPS). In this mode, as shown in Figure 19-1, a buffered
version of TMR0H is maintained.
This is compared with the value of TMR0L on each cycle of the selected clock source. When the two values match,
the following events occur:
• TMR0L is reset
• The contents of TMR0H are copied to the TMR0H buffer for next comparison
16-Bit Mode
In this mode, Timer0 increments on the rising edge of the selected clock source. A prescaler on the clock input gives
several prescale options (see the prescaler control bits, CKPS). In this mode, TMR0H:TMR0L form the 16-bit timer
value. As shown in Figure 19-1, reads and writes of the TMR0H register are buffered. The TMR0H register is updated
with the contents of the high byte of Timer0 when the TMR0L register is read. Similarly, writing the TMR0L register
causes a transfer of the TMR0H register value to the Timer0 high byte.
This buffering allows all 16 bits of Timer0 to be read and written at the same time. Timer0 rolls over to 0x0000 on
incrementing past 0xFFFF. This makes the timer free-running. While actively operating in 16-bit mode, the Timer0
value can be read but not written.
Clock Selection
Timer0 has several options for clock source selections, the option to operate synchronously/asynchronously and an
available programmable prescaler. The CS bits are used to select the clock source for Timer0.
Synchronous Mode
When the ASYNC bit is clear, Timer0 clock is synchronized to the system clock (FOSC/4). When operating in
Synchronous mode, Timer0 clock frequency cannot exceed FOSC/4. During Sleep mode, the system clock is not
available and Timer0 cannot operate.
Asynchronous Mode
When the ASYNC bit is set, Timer0 increments with each rising edge of the input source (or output of the prescaler,
if used). Asynchronous mode allows Timer0 to continue operation during Sleep mode provided the selected clock
source operates during Sleep.
Programmable Prescaler
Timer0 has 16 programmable input prescaler options ranging from 1:1 to 1:32768. The prescaler values are selected
using the CKPS bits. The prescaler counter is not directly readable or writable. The prescaler counter is cleared on
the following events:
• A write to the TMR0L register
• A write to either the T0CON0 or T0CON1 registers
• Any device Reset
Programmable Postscaler
Timer0 has 16 programmable output postscaler options ranging from 1:1 to 1:16. The postscaler values are selected
using the OUTPS bits. The postscaler divides the output of Timer0 by the selected ratio. The postscaler counter is not
directly readable or writable. The postscaler counter is cleared on the following events:
• A write to the TMR0L register
• A write to either the T0CON0 or T0CON1 registers
• Any device Reset
Timer0 Output
TMR0_out toggles on every match between TMR0L and TMR0H in 8-bit mode, or when TMR0H:TMR0L rolls over
in 16-bit mode. If the output postscaler is used, the output is scaled by the ratio selected. The Timer0 output can
be routed to an I/O pin via the RxyPPS output selection register, or internally to a number of Core Independent
Peripherals. The Timer0 output can be monitored through software via the OUT output bit.
Timer0 Interrupt
The Timer0 Interrupt Flag (TMR0IF) bit is set when the TMR0_out toggles. If the Timer0 interrupt is enabled
(TMR0IE), the CPU will be interrupted when the TMR0IF bit is set. When the postscaler bits (T0OUTPS) are set to
1:1 operation (no division), the T0IF flag bit will be set with every TMR0 match or rollover. In general, the TMR0IF flag
bit will be set every T0OUTPS +1 matches or rollovers.
Timer0 Example
Timer0 Configuration:
• Timer0 mode = 16-bit
• Clock Source = FOSC/4 (250 kHz)
• Synchronous operation
• Prescaler = 1:1
• Postscaler = 1:2 (T0OUTPS = 1)
In this case, the TMR0_out toggles every two rollovers of TMR0H:TMR0L.
i.e., (0xFFFF)*2*(1/250 kHz) = 524.28 ms
T0CON0
Name: T0CON0
Offset: 0x059E
Bit 7 6 5 4 3 2 1 0
EN OUT MD16 OUTPS[3:0]
Access R/W R R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0
T0CON1
Name: T0CON1
Offset: 0x059F
Bit 7 6 5 4 3 2 1 0
CS[2:0] ASYNC CKPS[3:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
TMR0H
Name: TMR0H
Offset: 0x059D
Bit 7 6 5 4 3 2 1 0
TMR0H[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
TMR0L
Name: TMR0L
Offset: 0x059C
Bit 7 6 5 4 3 2 1 0
TMR0L[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
0x00
... Reserved
0x059B
0x059C TMR0L 7:0 TMR0L[7:0]
0x059D TMR0H 7:0 TMR0H[7:0]
0x059E T0CON0 7:0 EN OUT MD16 OUTPS[3:0]
0x059F T0CON1 7:0 CS[2:0] ASYNC CKPS[3:0]
Important: References to the module Timer1 apply to all the odd numbered timers on this device.
TxGATE
4
TxGPPS
GSPM
PPS 0000
1
0 Single Pulse D Q GVAL
NOTE (5) 0
1111
1 Acq. Control
Q1
D Q
GPOL GGO/DONE
CK Q
ON Interrupt
R set bit
GTM det TMRxGIF
GE
set flag bit
TMRxIF
ON
EN
To Comparators (6)
TMRx(2)
Tx_overflow Synchronized Clock Input
TMRxH TMRxL Q D 0
1
TxCLK
SYNC
TxCLK
4
TxCKIPPS
(1)
PPS 000 0
Notes:
1. This signal comes from the pin selected by Timer1 PPS register.
2. TMRx register increments on rising edge.
3. Synchronize does not operate while in Sleep.
4. See TxCLK for clock source selections.
5. See TxGATE for gate source selections.
6. Synchronized comparator output must not be used in conjunction with synchronized input clock.
Timer1 Operation
The Timer1 module is a 16-bit incrementing counter accessed through the TMRx register. Writes to TMRx directly
update the counter. When used with an internal clock source, the module is a timer that increments on every
instruction cycle. When used with an external clock source, the module can be used as either a timer or counter and
increments on every selected edge of the external source.
Timer1 is enabled by configuring the ON and GE bits. Table 20-1 shows the possible Timer1 enable selections.
ON GE Timer1 Operation
1 1 Count enabled
1 0 Always on
0 1 Off
0 0 Off
Important: In Counter mode, a falling edge must be registered by the counter prior to the first
incrementing rising edge after any one or more of the following conditions:
• Timer1 enabled after POR
• Write to TMRxH or TMRxL
• Timer1 is disabled
• Timer1 is disabled (ON = 0) when TxCKI is high, then Timer1 is enabled (ON = 1) when TxCKI is low.
Refer to the figure below.
TxCKI = 1
When TMRx
Enabled
TxCKI = 0
When TMRx
Enabled
Notes:
1. Arrows indicate counter increments.
2. In Counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge of
the clock.
Timer1 Prescaler
Timer1 has four prescaler options allowing 1, 2, 4 or 8 divisions of the clock input. The CKPS bits control the prescale
counter. The prescale counter is not directly readable or writable; however, the prescaler counter is cleared upon a
write to TMRx.
From
TMRx
Circuitr y
Read TMRxL
Write TMRxL
8
8
TMRxH
8
8
Inte rnal Data Bus
Timer1 Gate
Timer1 can be configured to count freely or the count can be enabled and disabled using Timer1 gate circuitry. This is
also referred to as Timer1 gate enable. Timer1 gate can also be driven by multiple selectable sources.
TMRxGE
TxGPOL
TxG_IN
TxCKI
TxGVAL
Timer1
Important: Enabling Toggle mode at the same time as changing the gate polarity may result in
indeterminate operation.
TMRxGE
TxGPOL
TxGTM
TxTxG_IN
TxCKI
TxGVAL
Timer1
TMRxGE
TxGPOL
TxGSPM
Cleared by hardware on
TxGGO/ Set by software falling edge of TxGVAL
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
TIMER1
Cleared by
TMRxGIF Cleared by software Set by hardware on software
falling edge of TxGVAL
Clearing the GSPM bit will also clear the GGO/DONE bit. See the figure below for timing details. Enabling the Toggle
mode and the Single Pulse mode simultaneously will permit both sections to work together. This allows the cycle
times on the Timer1 gate source to be measured. See the figure below for timing details.
Figure 20-7. Timer1 Gate Single Pulse and Toggle Combined Mode
TMRxGE
TxGPOL
TxGSPM
TxGTM
Cleared by hardware on
TxGGO/ Set by software falling edge of TxGVAL
DONE
Counting enabled on
rising edge of TxG
TxG_IN
TxCKI
TxGVAL
TIMER1
Timer1 Interrupt
The TMRx register increments to FFFFh and rolls over to 0000h. When TMRx rolls over, the TMRx Interrupt Flag
(TMRxIF) bit of the PIRx register is set. To enable the interrupt-on-rollover, the following bits must be set:
• ON bit of the TxCON register
• TMRxIE bits of the PIEx register
• Global interrupts must be enabled
The interrupt is cleared by clearing the TMRxIF bit as a task in the Interrupt Service Routine.
Important: The TMRx register and the TMRxIF bit need to be cleared before enabling interrupts.
TxCON
Name: TxCON
Offset: 0x020E
Bit 7 6 5 4 3 2 1 0
CKPS[1:0] SYNC RD16 ON
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
Bit 0 – ON Timer On
Reset States: POR/BOR = 0
All Other Resets = u
Value Description
1 Enables Timer
0 Disables Timer
TxGCON
Name: TxGCON
Offset: 0x020F
Bit 7 6 5 4 3 2 1 0
GE GPOL GTM GSPM GGO/DONE GVAL
Access R/W R/W R/W R/W R/W R
Reset 0 0 0 0 0 x
TxCLK
Name: TxCLK
Offset: 0x0211
Bit 7 6 5 4 3 2 1 0
CS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
TxGATE
Name: TxGATE
Offset: 0x0210
Bit 7 6 5 4 3 2 1 0
GSS[4:0]
Access R/W R/W R/W R/W R/W
Reset 0 0 0 0 0
TMRx
Name: TMRx
Offset: 0x020C
Timer Register
Bit 15 14 13 12 11 10 9 8
TMRx[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
TMRx[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• TMRxH: Accesses the high byte TMRx[15:8]
• TMRxL: Accesses the low byte TMRx[7:0]
0x00
... Reserved
0x020B
7:0 TMR1[7:0]
0x020C TMR1
15:8 TMR1[15:8]
0x020E T1CON 7:0 CKPS[1:0] SYNC RD16 ON
0x020F T1GCON 7:0 GE GPOL GTM GSPM GGO/DONE GVAL
0x0210 T1GATE 7:0 GSS[4:0]
0x0211 T1CLK 7:0 CS[4:0]
Important: References to module Timer2 apply to all the even numbered timers on this device (Timer2,
Timer4, etc.).
Figure 21-1. Timer2 with Hardware Limit Timer (HLT) Block Diagram
RSEL
TxINPPS Rev. 10-000168D
4/29/2019
TxIN PPS
MODE MODE[3]
External
TMRx_ers Edge Detector reset
Reset
Sources(2) Level Detector CCP_pset(1)
Mode Control
(2 clock Sync)
Sync
1
(2 Clocks) OUTPS
TxPR
ON 0
CSYNC
Notes:
1. Signal to the CCP peripheral for PWM pulse trigger in PWM mode.
2. See RSEL for external Reset sources.
3. See CS for clock source selections.
Timer2 Operation
Timer2 operates in three major modes:
• Free-Running Period
• One Shot
• Monostable
Within each operating mode, there are several options for starting, stopping and Reset. Table 21-1 lists the options.
In all modes, the T2TMR count register increments on the rising edge of the clock signal from the programmable
prescaler. When T2TMR equals T2PR, a high level output to the postscaler counter is generated. T2TMR is cleared
on the next clock input.
An external signal from hardware can also be configured to gate the timer operation or force a T2TMR count Reset.
In Gate modes, the counter stops when the gate is disabled and resumes when the gate is enabled. In Reset modes,
the T2TMR count is reset on either the level or edge from the external source.
The T2TMR and T2PR registers are both directly readable and writable. The T2TMR register is cleared and the
T2PR register initializes to 0xFF on any device Reset. Both the prescaler and postscaler counters are cleared on the
following events:
• A write to the T2TMR register
• A write to the T2CON register
• Any device Reset
• External Reset source event that resets the timer
Monostable Mode
Monostable modes are similar to One Shot modes except that the ON bit is not cleared and the timer can be
restarted by an external Reset event.
Timer2 Output
The Timer2 module’s primary output is TMR2_postscaled, which pulses for a single TMR2_clk period upon each
match of the postscaler counter and the OUTPS bits of the T2CON register. The postscaler is incremented each time
the T2TMR value matches the T2PR value. This signal can also be selected as an input to other Core Independent
Peripherals.
In addition, the Timer2 is also used by the CCP module for pulse generation in PWM mode. See the “PWM
Overview” and “PWM Period” sections in the “CCP - Capture/Compare/PWM Module” chapter for more details on
setting up Timer2 for use with the CCP and PWM modules.
Timer2 Interrupt
Timer2 can also generate a device interrupt. The interrupt is generated when the postscaler counter matches the
selected postscaler value (OUTPS bits of T2CON register). The interrupt is enabled by setting the TMR2IE interrupt
enable bit. Interrupt timing is illustrated in the figure below.
Figure 21-2. Timer2 Prescaler, Postscaler, and Interrupt Timing Diagram
Rev. 10-000 205B
3/6/201 9
CKPS ‘b010
TxPR 1
OUTPS ‘b0001
TMRx_clk
TxTMR 0 1 0 1 0 1 0
TMRx_postscaled
Notes: 1. Setting the interrupt flag is synchronized with the instruction clock.
Synchronization may take as many as two instruction cycles.
2. Cleared by software.
PSYNC Bit
Setting the PSYNC bit synchronizes the prescaler output to FOSC/4. Setting this bit is required for reading the Timer2
counter register while the selected Timer clock is asynchronous to FOSC/4.
Note: Setting PSYNC requires that the output of the prescaler is slower than FOSC/4. Setting PSYNC when the
output of the prescaler is greater than or equal to FOSC/4 may cause unexpected results.
CSYNC Bit
All bits in the Timer2 SFRs are synchronized to FOSC/4 by default, not the Timer2 input clock. As such, if the Timer2
input clock is not synchronized to FOSC/4, it is possible for the Timer2 input clock to transition at the same time as
the ON bit is set in software, which may cause undesirable behavior and glitches in the counter. Setting the CSYNC
bit remedies this problem by synchronizing the ON bit to the Timer2 input clock instead of FOSC/4. However, as this
synchronization uses an edge of the TMR2 input clock, up to one input clock cycle will be consumed and not counted
by the Timer2 when CSYNC is set. Conversely, clearing the CSYNC bit synchronizes the ON bit to F OSC/4, which
does not consume any clock edges, but has the previously stated risk of glitches.
Operating Modes
The mode of the timer is controlled by the MODE bits. Edge Triggered modes require six Timer clock periods
between external triggers. Level Triggered modes require the triggering level to be at least three Timer clock periods
long. External triggers are ignored while in Debug mode.
Table 21-1. Operating Modes Table
MODE Output Timer Control
Mode Operation Operation
[4:3] [2:0] Start Reset Stop
000 Software gate (Figure 21-3) ON = 1 — ON = 0
Hardware gate, active-high ON = 1 and — ON = 0 or
001 (Figure 21-4) TMRx_ers = 1 TMRx_ers = 0
Period Pulse
ON = 1 and — ON = 0 or
010 Hardware gate, active-low TMRx_ers = 0 TMRx_ers = 1
011 Rising or falling edge Reset TMRx_ers ↕
Free-Running Period 00
100 Rising edge Reset (Figure 21-5) TMRx_ers ↑ ON = 0
101 Period Pulse Falling edge Reset TMRx_ers ↓
with ON = 1 ON = 0 or
110 Low-level Reset TMRx_ers = 0 TMRx_ers = 0
Hardware Reset
High-level Reset (Figure 21-6) ON = 0 or
111 TMRx_ers = 1 TMRx_ers = 1
...........continued
MODE Output Timer Control
Mode Operation Operation
[4:3] [2:0] Start Reset Stop
000 Reserved
Rising edge start ON = 1 and
001 — ON = 0
(Figure 21-11) TMRx_ers ↑
or
Monostable Edge-Triggered Start ON = 1 and
010 Falling edge start — Next clock after
(Note 1) TMRx_ers ↓
TxTMR = TxPR
ON = 1 and
011 Any edge start TMRx_ers ↕ — (Note 3)
10
Reserved 100 Reserved
Reserved 101 Reserved
High-level start and ON = 1 and
110 Level-Triggered Start Low-level Reset (Figure 21-12) TMRx_ers = 1 TMRx_ers = 0 ON = 0 or
and Held in Reset
One Shot
Low-level start and ON = 1 and (Note 2)
111 Hardware Reset High-level Reset TMRx_ers = 0 TMRx_ers = 1
Reserved 11 xxx Reserved
Notes:
1. If ON = 0, then an edge is required to restart the timer after ON = 1.
2. When T2TMR = T2PR, the next clock clears ON and stops T2TMR at 00h.
3. When T2TMR = T2PR, the next clock stops T2TMR at 00h but does not clear ON.
Operation Examples
Unless otherwise specified, the following notes apply to the following timing diagrams:
• Both the prescaler and postscaler are set to 1:1 (both the CKPS and OUTPS bits).
• The diagrams illustrate any clock except FOSC/4 and show clock-sync delays of at least two full cycles for both
ON and TMRx_ers. When using FOSC/4, the clock-sync delay is at least one instruction period for TMRx_ers;
ON applies in the next instruction period.
• ON and TMRx_ers are somewhat generalized, and clock-sync delays may produce results that are slightly
different than illustrated.
• The PWM Duty Cycle and PWM output are illustrated assuming that the timer is used for the PWM function of
the CCP module as described in the “PWM Overview” section. The signals are not a part of the Timer2 module.
TMRx_clk
ON
TxPR 5
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TMRx_ers
TxPR 5
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 0 1 2 3 4 5 0 1 2 3 4 5 0 1
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by
the CPU to set or clear the ON bit of TxCON. CPU execution is asynchronous
to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 0 1 2 3 4 5 0 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU
to set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2
CCP_pset
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
Figure 21-11. Rising Edge Triggered Monostable Mode Timing Diagram (MODE = ‘b10001)
R ev. 10- 000203B
3/6/2019
TMRx_clk
TxPR 5
(1)
Instruction BSF BCF BSF BCF BSF
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
TMRx_clk
TxPR 5
(1)
Instruction BSF BSF BCF BSF
ON
TMRx_ers
TxTMR 0 1 2 3 4 5 0 1 2 3 0 1 2 3 4 5 0
TMRx_postscaled
PWM Duty
‘D3
Cycle
PWM Output
Note: 1. BSF and BCF represent Bit-Set File and Bit-Clear File instructions executed by the CPU to
set or clear the ON bit of TxCON. CPU execution is asynchronous to the timer clock input.
Important: References to module Timer2 apply to all the even numbered timers on this device (Timer2,
Timer4, etc.).
TxTMR
Name: TxTMR
Offset: 0x028C
Timer Counter Register
Bit 7 6 5 4 3 2 1 0
TxTMR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
TxPR
Name: TxPR
Offset: 0x028D
Timer Period Register
Bit 7 6 5 4 3 2 1 0
TxPR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
TxCON
Name: TxCON
Offset: 0x028E
Timerx Control Register
Bit 7 6 5 4 3 2 1 0
ON CKPS[2:0] OUTPS[3:0]
Access R/W/HC R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Note:
1. In certain modes, the ON bit will be auto-cleared by hardware. See Table 21-1.
TxHLT
Name: TxHLT
Offset: 0x028F
Bit 7 6 5 4 3 2 1 0
PSYNC CPOL CSYNC MODE[4:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes:
1. Setting this bit ensures that reading TxTMR will return a valid data value.
2. When this bit is ‘1’, the Timer cannot operate in Sleep mode.
3. CKPOL must not be changed while ON = 1.
4. Setting this bit ensures glitch-free operation when the ON is enabled or disabled.
5. When this bit is set, then the timer operation will be delayed by two input clocks after the ON bit is set.
6. Unless otherwise indicated, all modes start upon ON = 1 and stop upon ON = 0 (stops occur without affecting
the value of TxTMR).
7. When TxTMR = TxPR, the next clock clears TxTMR, regardless of the operating mode.
TxCLKCON
Name: TxCLKCON
Offset: 0x0290
Bit 7 6 5 4 3 2 1 0
CS[2:0]
Access R/W R/W R/W
Reset 0 0 0
TxRST
Name: TxRST
Offset: 0x0291
Timer External Reset Signal Selection Register
Bit 7 6 5 4 3 2 1 0
RSEL[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
0x00
... Reserved
0x028B
0x028C T2TMR 7:0 T2TMR[7:0]
0x028D T2PR 7:0 T2PR[7:0]
0x028E T2CON 7:0 ON CKPS[2:0] OUTPS[3:0]
0x028F T2HLT 7:0 PSYNC CPOL CSYNC MODE[4:0]
0x0290 T2CLKCON 7:0 CS[2:0]
0x0291 T2RST 7:0 RSEL[3:0]
Important: In devices with more than one CCP module, it is very important to pay close attention to
the register names used. Throughout this section, the prefix ‘CCPx’ is used as a generic replacement for
specific numbering. A number placed where the ‘x’ is in the prefix is used to distinguish between separate
modules. For example, CCP1CON and CCP2CON control the same operational aspects of two completely
different CCP modules.
All of the modules may be active at once and may share the same timer resource if they are configured to operate in
the same mode (Capture/Compare or PWM) at the same time.
Capture Mode
Capture mode makes use of the 16-bit odd numbered timer resources (Timer1) . When an event occurs on the
capture source, the 16-bit CCPRx register captures and stores the 16-bit value of the TMRx register. An event is
defined as one of the following and is configured by the MODE bits:
• Every falling edge of CCPx input
• Every rising edge of CCPx input
• Every 4th rising edge of CCPx input
• Every 16th rising edge of CCPx input
Important: If an event occurs during a 2-byte read, the high and low-byte data will be from different
events. It is recommended while reading the CCPRx register pair to either disable the module or read the
register pair twice for data integrity.
RxyPPS
CCPx
PPS
CTS
TRIS
CCPRx
16
Capture Trigger Sources set CCPxIF
See CCPxCAP register Prescaler and
1,4,16 Edge Detect
16
CCPx PPS
MODE TMR1
CCPxPPS
Capture Sources
The capture source is selected with the CTS bits.
In Capture mode, the CCPx pin must be configured as an input by setting the associated TRIS control bit.
Important: If the CCPx pin is configured as an output, a write to the port can cause a capture event.
Important: Clocking Timer1 from the system clock (FOSC) must not be used in Capture mode. For
Capture mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the instruction
clock (FOSC/4) or from an external clock source.
CCP Prescaler
There are four prescaler settings specified by the MODE bits. Whenever the CCP module is turned off, or the CCP
module is not in Capture mode, the prescaler counter is cleared. Any Reset will clear the prescaler counter.
Switching from one capture prescaler to another does not clear the prescaler and may generate a false interrupt.
To avoid this unexpected operation, turn the module off by clearing the CCPxCON register before changing the
prescaler. The example below demonstrates the code to perform this function.
BANKSEL CCP1CON
CLRF CCP1CON ;Turn CCP module off
MOVLW NEW_CAPT_PS ;CCP ON and Prescaler select → W
MOVWF CCP1CON ;Load CCP1CON with this value
Compare Mode
The Compare mode function described in this section is available and identical for all CCP modules.
Compare mode makes use of the 16-bit odd numbered Timer resources (Timer1). The 16-bit value of the CCPRx
register is constantly compared against the 16-bit value of the TMR1 register. When a match occurs, one of the
following events can occur:
• Toggle the CCPx output and clear TMR1
• Toggle the CCPx output without clearing TMR1
• Set the CCPx output
• Clear the CCPx output
• Generate a Pulse output
• Generate a Pulse output and clear TMR1
The action on the pin is based on the value of the MODE control bits.
All Compare modes can generate an interrupt. When MODE = ‘b0001 or ‘b1011, the CCP resets the TMR1
register.
The following figure shows a simplified diagram of the compare operation.
MODE
Auto-conversion Trigger
CCPRx
RxyPPS
TMR1
TRIS
Important: Clearing the CCPxCON register will force the CCPx compare output latch to the default low
level. This is not the PORT I/O data latch.
Important: Clocking Timer1 from the system clock (FOSC) must not be used in Compare mode. For
Compare mode to recognize the trigger event on the CCPx pin, Timer1 must be clocked from the
instruction clock (FOSC/4) or from an external clock source.
PWM Overview
Pulse-Width Modulation (PWM) is a scheme that controls power to a load by switching quickly between fully ON and
fully OFF states. The PWM signal resembles a square wave where the high portion of the signal is considered the
ON state and the low portion of the signal is considered the OFF state. The high portion, also known as the pulse
width, can vary in time and is defined in steps. A larger number of steps applied, which lengthens the pulse width,
also supplies more power to the load. Lowering the number of steps applied, which shortens the pulse width, supplies
less power. The PWM period is defined as the duration of one complete cycle or the total amount of ON and OFF
time combined.
PWM resolution defines the maximum number of steps that can be present in a single PWM period. A higher
resolution allows for more precise control of the power applied to the load.
The term duty cycle describes the proportion of the ON time to the OFF time and is expressed in percentages, where
0% is fully OFF and 100% is fully ON. A lower duty cycle corresponds to less power applied and a higher duty cycle
corresponds to more power applied. The figure below shows a typical waveform of the PWM signal.
Figure 22-3. CCP PWM Output Signal
Period
Pulse Width
TMR2 = PR2
TMR2 = CCPRx
TMR2 = 0
CCPRxH CCPRxL
CCPx_out
to peripherals
set CCPIF
10-bit Latch(2)
(Not accessible by user)
S RxyPPS
TMR2 Module TRIS Control
R
TMR2 (1)
ERS logic
Comparator CCPx_pset
PR2
Notes: 1. An 8-bit timer is concatenated with two bits generated by Fosc or two bits of the internal prescaler
to create 10-bit time base.
2. The alignment of the 10 bits from the CCPR register is determined by the CCPxFMT bit.
Important: The corresponding TRIS bit must be cleared to enable the PWM output on the CCPx pin.
PWM Period
The PWM period is specified by the T2PR register of Timer2. The PWM period can be calculated using the formula in
the equation below.
Equation 22-1. PWM Period
PWM Period = T2PR + 1 • 4 • TOSC • TMR2 Prescale Value
where TOSC = 1/FOSC
When T2TMR is equal to T2PR, the following three events occur on the next increment event:
• T2TMR is cleared
• The CCPx pin is set (Exception: If the PWM duty cycle = 0%, the pin will not be set)
• The PWM duty cycle is transferred from the CCPRx register into a 10-bit buffer
Important: The Timer postscaler (see the “Timer2 Interrupt” section) is not used in the determination of
the PWM frequency.
CCPRxH CCPRxL
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
FMT = 0
CCPRxH CCPRxL
FMT = 1 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
PWM Resolution
The resolution determines the number of available duty cycles for a given period. For example, a 10-bit resolution will
result in 1024 discrete duty cycles, whereas an 8-bit resolution will result in 256 discrete duty cycles.
The maximum PWM resolution is 10 bits when T2PR is 0xFF. The resolution is a function of the T2PR register value,
as shown below.
Equation 22-4. PWM Resolution
log 4 T2PR + 1
Resolution = bits
log 2
Important: If the pulse-width value is greater than the period, the assigned PWM pin(s) will remain
unchanged.
PWM Frequency 1.22 kHz 4.88 kHz 19.53 kHz 78.12 kHz 156.3 kHz 208.3 kHz
Timer Prescale 16 4 1 1 1 1
T2PR Value 0xFF 0xFF 0xFF 0x3F 0x1F 0x17
Maximum Resolution (bits) 10 10 10 8 7 6.6
PWM Frequency 1.22 kHz 4.90 kHz 19.61 kHz 76.92 kHz 153.85 kHz 200.0 kHz
Timer Prescale 16 4 1 1 1 1
T2PR Value 0x65 0x65 0x65 0x19 0x0C 0x09
Maximum Resolution (bits) 8 8 8 6 5 5
Effects of Reset
Any Reset will force all ports to Input mode and the CCP registers to their Reset states.
Important: To send a complete duty cycle and period on the first PWM output, the above
steps must be included in the setup sequence. If it is not critical to start with a complete PWM
signal on the first output, then step 6 may be ignored.
CCPxCON
Name: CCPxCON
Offset: 0x30E,0x312
Bit 7 6 5 4 3 2 1 0
EN OUT FMT MODE[3:0]
Access R/W R R/W R/W R/W R/W R/W
Reset 0 x 0 0 0 0 0
Notes:
1. The set and clear operations of the Compare mode are reset by setting MODE = ‘b0000 or EN = 0.
2. When MODE = ‘b0001 or ‘b1011, then the timer associated with the CCP module is cleared. TMR1 is the
default selection for the CCP module, so it is used for indication purposes only.
CCPxCAP
Name: CCPxCAP
Offset: 0x30F,0x313
Capture Trigger Input Selection Register
Bit 7 6 5 4 3 2 1 0
CTS[1:0]
Access R/W R/W
Reset 0 0
CCPRx
Name: CCPRx
Offset: 0x30C,0x310
Capture/Compare/Pulse-Width Register
Bit 15 14 13 12 11 10 9 8
CCPR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
CCPR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• When MODE = Capture or Compare
– CCPRxH: Accesses the high byte CCPR[15:8]
– CCPRxL: Accesses the low byte CCPR[7:0]
• When MODE = PWM and FMT = 0
– CCPRx[15:10]: Not used
– CCPRxH[1:0]: Accesses the two Most Significant bits CCPR[9:8]
– CCPRxL: Accesses the eight Least Significant bits CCPR[7:0]
• When MODE = PWM and FMT = 1
– CCPRxH: Accesses the eight Most Significant bits CCPR[9:2]
– CCPRxL[7:6]: Accesses the two Least Significant bits CCPR[1:0]
– CCPRx[5:0]: Not used
0x00
... Reserved
0x030B
7:0 CCPR[7:0]
0x030C CCPR1
15:8 CCPR[15:8]
0x030E CCP1CON 7:0 EN OUT FMT MODE[3:0]
0x030F CCP1CAP 7:0 CTS[1:0]
7:0 CCPR[7:0]
0x0310 CCPR2
15:8 CCPR[15:8]
0x0312 CCP2CON 7:0 EN OUT FMT MODE[3:0]
0x0313 CCP2CAP 7:0 CTS[1:0]
Important: The corresponding TRIS bit must be cleared to enable the PWM output on the PWMx pin.
Each PWM module uses the same timer source, Timer2, to control each module.
Figure 23-1 shows a simplified block diagram of PWM operation.
Figure 23-2 shows a typical waveform of the PWM signal.
Figure 23-1. Simplified PWM Block Diagram
PWMxDCH
PWMx_out
To Peripherals
10-bit Latch
(Not visible to user)
Comparator R Q
0
PPS PWMx
1
S Q
TMR2 Module
POL RxyPPS TRIS Control
R
T2TMR (1)
Comparator
T2_match
T2PR
Note:
1. 8-bit timer is concatenated with two bits generated by FOSC or two bits of the internal prescaler to create 10-bit
time base.
Period
Pulse Width
T2TMR = T2PR
T2TMR reloaded with 0
T2TMR = T2PR
T2TMR reloaded with 0
For a step-by-step procedure on how to set up this module for PWM operation, refer to 23.9. Setup for PWM
Operation Using PWMx Output Pins.
Fundamental Operation
The PWM module produces a 10-bit resolution output. The timer selection for PWMx is TMR2. T2TMR and T2PR set
the period of the PWM. The PWMxDCL and PWMxDCH registers configure the duty cycle. The period is common to
all PWM modules, whereas the duty cycle is independently controlled.
Important: The Timer2 postscaler is not used in the determination of the PWM frequency. The postscaler
might be used to have a servo update rate at a different frequency than the PWM output.
All PWM outputs associated with Timer2 are set when T2TMR is cleared. Each PWMx is cleared when T2TMR is
equal to the value specified in the corresponding PWMxDCH (8 MSb) and PWMxDCL[7:6] (2 LSb) registers. When
the value is greater than or equal to T2PR, the PWM output is never cleared (100% duty cycle).
Important: The PWMxDCH and PWMxDCL registers are double-buffered. The buffers are updated when
T2TMR matches T2PR. Care has to be taken to update both registers before the timer match occurs.
PWM Period
The PWM period is specified by the T2PR register. The PWM period can be calculated using the formula of Equation
23-1. It is required to have FOSC/4 as the selected clock input to the timer for correct PWM operation.
Equation 23-1. PWM Period
PWM Period = T2PR + 1 • 4 • Tosc • TMR2 Prescale Value
Note: TOSC = 1/FOSC
When T2TMR is equal to T2PR, the following three events occur on the next increment cycle:
• T2TMR is cleared
• The PWM output is active (Exception: When the PWM duty cycle = 0%, the PWM output will remain inactive)
• The PWMxDCH and PWMxDCL register values are latched into the buffers
PWM Resolution
The resolution determines the number of available duty cycles for a given period. For example, a 10-bit resolution will
result in 1024 discrete duty cycles, whereas an 8-bit resolution will result in 256 discrete duty cycles.
The maximum PWM resolution is 10 bits when T2PR is 255. The resolution is a function of the T2PR register value
as shown below.
Equation 23-4. PWM Resolution
log 4 T2PR + 1
Resolution = bits
log 2
Important: If the pulse-width value is greater than the period, the assigned PWM pin(s) will remain
unchanged.
PWM Frequency 0.31 kHz 4.88 kHz 19.53 kHz 78.12 kHz 156.3 kHz 208.3 kHz
Timer Prescale 64 4 1 1 1 1
T2PR Value 0xFF 0xFF 0xFF 0x3F 0x1F 0x17
Maximum Resolution (bits) 10 10 10 8 7 6.6
PWM Frequency 0.31 kHz 4.90 kHz 19.61 kHz 76.92 kHz 153.85 kHz 200.0 kHz
Timer Prescale 64 4 1 1 1 1
T2PR Value 0x65 0x65 0x65 0x19 0x0C 0x09
Maximum Resolution (bits) 8 8 8 6 5 5
Effects of Reset
Any Reset will force all ports to Input mode and the PWM registers to their Reset states.
PWMxCON
Name: PWMxCON
Offset: 0x316,0x31A
PWM Control Register
Bit 7 6 5 4 3 2 1 0
EN OUT POL
Access R/W R R/W
Reset 0 0 0
PWMxDC
Name: PWMxDC
Offset: 0x314,0x318
PWM Duty Cycle Register
Bit 15 14 13 12 11 10 9 8
DCH[7:0]
Access
Reset x x x x x x x x
Bit 7 6 5 4 3 2 1 0
DCL[1:0]
Access
Reset x x
0x00
... Reserved
0x0313
7:0 DCL[1:0]
0x0314 PWM3DC
15:8 DCH[7:0]
0x0316 PWM3CON 7:0 EN OUT POL
0x0317 Reserved
7:0 DCL[1:0]
0x0318 PWM4DC
15:8 DCH[7:0]
0x031A PWM4CON 7:0 EN OUT POL
Data bu s
8 TXIE
Inte rrupt
TXREG register TXIF
SYNC 8
CSRC
RxyPP S(1)
TXEN
CKx Pin MSb LSb RXx/DTx Pin
PPS 1 Pin Buffer
(8) 0 PPS
and Control
0 Transmit Shift Register (TSR)
CKPPS(2)
TX_out
TRMT
Bau d Rate Gene rato r
FOSC ÷n TX9
n TXx/CKx Pi n
BRG16 TX9D 0
+1 Multiplier x4 x16 x64 PPS
1
SYNC 1 x 0 0 0
RxyPP S(2)
BRGH x 1 1 0 0
SPB RGH SPB RGL SYNC
BRG16 x 1 0 1 0
CSRC
SPE N
RXPPS(1)
RXx/DTx pin MSb RSR Register LSb
Pin Buffer Data
PPS Stop (8) 7 1 0 Start
and Control Recove ry
SYNC
CSRC
RX9
PPS 1
CKx Pi n 0
CKPPS(2)
8
BRG16 n
Multiplier x4 x16 x64 Data B us
+1
SYNC 1 x 0 0 0
RCxIF
Inte rrupt
BRGH x 1 1 0 0
RCxIE
SPB RGH SPB RGL
BRG16 x 1 0 1 0
• The Serial Port Enable (SPEN) bit is set to ‘1’ to enable the EUSART interface and to enable automatically the
output drivers for the RxyPPS selected as the TXx/CKx output
All other EUSART control bits are assumed to be in their default state.
If the TXx/CKx pin is shared with an analog peripheral, the analog I/O function must be disabled by clearing the
corresponding ANSEL bit.
Important: The TXxIF Transmitter Interrupt Flag in the PIRx register is set when the TXEN enable bit is
set and the Transmit Shift Register (TSR) is Idle.
Transmitting Data
A transmission is initiated by writing a character to the TXxREG register. If this is the first character, or the previous
character has been completely flushed from the TSR, the data in the TXxREG is immediately transferred to the TSR
register. If the TSR still contains all or part of a previous character, the new character data is held in the TXxREG until
the Stop bit of the previous character has been transmitted. The pending character in the TXxREG is then transferred
to the TSR in one TCY immediately following the Stop bit transmission. The transmission of the Start bit, data bits and
Stop bit sequence commences immediately following the transfer of the data to the TSR from the TXxREG.
TSR Status
The Transmit Shift Register Status (TRMT) bit indicates the status of the TSR register. This is a read-only bit. The
TRMT bit is set when the TSR register is empty and is cleared when a character is transferred to the TSR register
from the TXxREG. The TRMT bit remains clear until all bits have been shifted out of the TSR register. No interrupt
logic is tied to this bit, so the user needs to poll this bit to determine the TSR status.
Important: The TSR register is not mapped in data memory, so it is not available to the user.
A special 9-bit Address mode is available for use with multiple receivers. See 24.1.2.7. Address Detection for more
information on the Address mode.
Word 1
2/7/201 7
Write to TXxREG
BRG Output
(Shift Clock)
TXx/CKx pin Start bit bit 0 bit 1 bit 7/8 Stop bit
Write to TXxREG
BRG Output
(Shift Clock)
TXx/CKx pin Start bit bit 0 bit 1 bit 7/8 Stop bit Start bit bit 0
characters and the start of a third character before software must start servicing the EUSART receiver. The FIFO and
RSR registers are not directly accessible by software. Access to the received data is via the RCxREG register.
Important: If the RX/DT function is on an analog pin, the corresponding ANSEL bit must be cleared for
the receiver to function.
Receiving Data
The receiver data recovery circuit initiates character reception on the falling edge of the first bit. The first bit, also
known as the Start bit, is always a zero. The data recovery circuit counts one-half bit time to the center of the Start
bit and verifies that the bit is still a zero. If it is not a zero, then the data recovery circuit aborts character reception
without generating an error, and resumes looking for the falling edge of the Start bit. If the Start bit zero verification
succeeds, then the data recovery circuit counts a full bit time to the center of the next bit. The bit is then sampled by
a majority detect circuit and the resulting ‘0’ or ‘1’ is shifted into the RSR. This repeats until all data bits have been
sampled and shifted into the RSR. One final bit time is measured and the level sampled. This is the Stop bit, which
is always a ‘1’. If the data recovery circuit samples a ‘0’ in the Stop bit position, then a framing error is set for this
character, otherwise the framing error is cleared for this character. See 24.1.2.4. Receive Framing Error for more
information on framing errors.
Immediately after all data bits and the Stop bit have been received, the character in the RSR is transferred to the
EUSART receive FIFO, and the EUSART Receive Interrupt Flag (RCxIF) bit of the PIRx register is set. The top
character in the FIFO is transferred out of the FIFO by reading the RCxREG register.
Important: If the receive FIFO is overrun, no additional characters will be received until the Overrun
condition is cleared. See 24.1.2.4. Receive Framing Error for more information.
Receive Interrupts
The EUSART Receive Interrupt Flag (RCxIF) bit of the PIRx register is set whenever the EUSART receiver is
enabled and there is an unread character in the receive FIFO. The RCxIF Interrupt Flag bit is read-only, it cannot be
set or cleared by software.
RCxIF interrupts are enabled by setting all of the following bits:
• RCxIE, Interrupt Enable bit of the PIEx register
• PEIE, Peripheral Interrupt Enable bit of the INTCON register
• GIE, Global Interrupt Enable bit of the INTCON register
The RCxIF Interrupt Flag bit will be set when there is an unread character in the FIFO, regardless of the state of
interrupt enable bits.
Receive Framing Error
Each character in the receive FIFO buffer has a corresponding framing error Status bit. A framing error indicates that
a Stop bit was not seen at the expected time. The framing error status is accessed via the Framing Error (FERR) bit.
The FERR bit represents the status of the top unread character in the receive FIFO. Therefore, the FERR bit must be
read before reading the RCxREG register.
The FERR bit is read-only and only applies to the top unread character in the receive FIFO. A framing error (FERR
= 1) does not preclude reception of additional characters. It is not necessary to clear the FERR bit. Reading the next
character from the FIFO buffer will advance the FIFO to the next character and the next corresponding framing error.
The FERR bit can be forced clear by clearing the SPEN bit, which resets the EUSART. Clearing the CREN bit does
not affect the FERR bit. A framing error by itself does not generate an interrupt.
Important: If all receive characters in the receive FIFO have framing errors, repeated reads of the
RCxREG register will not clear the FERR bit.
Address Detection
A special Address Detection mode is available for use when multiple receivers share the same transmission line,
such as in RS-485 systems. Address detection is enabled by setting the Address Detect Enable (ADDEN) bit.
Address detection requires 9-bit character reception. When address detection is enabled, only characters with the
ninth data bit set will be transferred to the receive FIFO buffer, thereby setting the RCxIF interrupt bit. All other
characters will be ignored.
Upon receiving an address character, user software determines if the address matches its own. Upon address match,
user software must disable address detection by clearing the ADDEN bit before the next Stop bit occurs. When user
software detects the end of the message, determined by the message protocol used, software places the receiver
back into the Address Detection mode by setting the ADDEN bit.
RCIDL
Read
RCxREG
RCxIF
(Interrupt flag)
OERR Flag
CREN
(software clear)
Note: This timing diagram shows three bytes appearing on the RXx input. The OERR flag is set because the
RCxREG register is not read before the third word is received.
Configuration Bits
BRG/EUSART Mode Baud Rate Formula
SYNC BRG16 BRGH
0 0 0 8-bit/Asynchronous FOSC/[64 (n+1)]
0 0 1 8-bit/Asynchronous
FOSC/[16 (n+1)]
0 1 0 16-bit/Asynchronous
...........continued
Configuration Bits
BRG/EUSART Mode Baud Rate Formula
SYNC BRG16 BRGH
0 1 1 16-bit/Asynchronous
1 0 x 8-bit/Synchronous FOSC/[4 (n+1)]
1 1 x 16-bit/Synchronous
Note: x = Don’t care, n = value of SPxBRGH:SPxBRGL register pair.
9600 9615 0.16 207 9615 0.16 103 9600 0.00 95 9615 0.16 25
10417 10417 0 191 10417 0.00 95 10473 0.53 87 10417 0.00 23
19.2k 19.23k 0.16 103 19.23k 0.16 51 19.20k 0.00 47 19.23k 0.16 12
57.6k 57.14k -0.79 34 58.82k 2.12 16 57.60k 0.00 15 — — —
115.2k 117.6k 2.12 16 111.1k -3.55 8 115.2k 0.00 7 — — —
Auto-Baud Detect
The EUSART module supports automatic detection and calibration of the baud rate.
In the Auto-Baud Detect (ABD) mode, the clock to the BRG is reversed. Rather than the BRG clocking the incoming
RX signal, the RX signal is timing the BRG. The Baud Rate Generator is used to time the period of a received 55h
(ASCII “U”) which is the Sync character for the LIN bus. The unique feature of this character is that it has five rising
edges, including the Stop bit edge.
Setting the Auto-Baud Detect Enable (ABDEN) bit starts the auto-baud calibration sequence. While the ABD
sequence takes place, the EUSART state machine is held in Idle. On the first rising edge of the receive line, after the
Start bit, the SPxBRG register begins counting up using the BRG counter clock as shown in Figure 24-6. The fifth
rising edge will occur on the RXx pin at the end of the eighth bit period. At that time, an accumulated value totaling
the proper BRG period is left in the SPxBRGH:SPxBRGL register pair, the ABDEN bit is automatically cleared, and
the RCxIF interrupt flag is set. The value in the RCxREG register needs to be read to clear the RCxIF interrupt.
RCxREG content may be discarded. When calibrating for modes that do not use the SPxBRGH register, the user can
verify that the SPxBRGL register did not overflow by checking for 00h in the SPxBRGH register.
The BRG auto-baud clock is determined by the BRG16 and BRGH bits, as shown in Table 24-3. During ABD, both
the SPxBRGH and SPxBRGL registers are used as a 16-bit counter, independent of the BRG16 bit setting. While
calibrating the baud rate period, the SPxBRGH and SPxBRGL registers are clocked at 1/8 th the BRG base clock rate.
The resulting byte measurement is the average bit time when clocked at full speed.
Notes:
1. If the Wake-Up Enable (WUE) bit is set with the ABDEN bit, auto-baud detection will occur on the byte
following the Break character (see 24.3.3. Auto-Wake-Up on Break).
2. It is up to the user to determine that the incoming character baud rate is within the range of the selected BRG
clock source. Some combinations of oscillator frequency and EUSART baud rates are not possible.
3. During the auto-baud process, the auto-baud counter starts counting at one. Upon completion of the auto-
baud sequence, to achieve maximum accuracy, subtract 1 from the SPxBRGH:SPxBRGL register pair.
Table 24-3. BRG Counter Clock Rates
RXxNDTx pin start bit s bit 4 bit 5 bit 6 bit y bit 5 bit 6 bit 7
BRG clock
RCxIF bit
kInterrupt FlagS
Read
RCxREG
Auto-Baud Overflow
During the course of automatic baud detection, the Auto-Baud Detect Overflow (ABDOVF) bit will be set if the baud
rate counter overflows before the fifth rising edge is detected on the RXx pin. The ABDOVF bit indicates that the
counter has exceeded the maximum count that can fit in the 16 bits of the SPxBRGH:SPxBRGL register pair. After
the ABDOVF bit has been set, the counter continues to count until the fifth rising edge is detected on the RXx pin.
Upon detecting the fifth RX edge, the hardware will set the RCxIF interrupt flag and clear the ABDEN bit. The RCxIF
flag can be subsequently cleared by reading the RCxREG register. The ABDOVF bit can be cleared by software
directly.
To terminate the auto-baud process before the RCxIF flag is set, clear the ABDEN bit then clear the ABDOVF bit. The
ABDOVF bit will remain set if the ABDEN bit is not cleared first.
Auto-Wake-Up on Break
During Sleep mode, all clocks to the EUSART are suspended. Because of this, the Baud Rate Generator is inactive
and a proper character reception cannot be performed. The Auto-Wake-Up feature allows the controller to wake up
due to activity on the RX/DT line. This feature is available only in Asynchronous mode.
The Auto-Wake-Up feature is enabled by setting the WUE bit. Once set, the normal receive sequence on RX/DT is
disabled, and the EUSART remains in an Idle state, monitoring for a wake-up event independent of the CPU mode. A
wake-up event consists of a high-to-low transition on the RX/DT line. This coincides with the start of a Sync Break or
a wake-up signal character for the LIN protocol.
The EUSART module generates an RCxIF interrupt coincident with the wake-up event. The interrupt is generated
synchronously to the Q clocks in normal CPU operating modes as shown in Figure 24-7, and asynchronously if the
device is in Sleep mode, as shown in Figure 24-8. The Interrupt condition is cleared by reading the RCxREG register.
The WUE bit is automatically cleared by the low-to-high transition on the RX line at the end of the Break. This signals
to the user that the Break event is over. At this point, the EUSART module is in Idle mode waiting to receive the next
character.
Break Character
To avoid character errors or character fragments during a wake-up event, the wake-up character must be all zeros.
When the wake-up is enabled, the function works independent of the low time on the data stream. If the WUE bit is
set and a valid nonzero character is received, the low time from the Start bit to the first rising edge will be interpreted
as the wake-up event. The remaining bits in the character will be received as a fragmented character and subsequent
characters can result in framing or overrun errors.
Therefore, the initial character in the transmission must be all ‘0’s. This must be 10 or more bit times, 13-bit times
recommended for LIN bus, or any number of bit times for standard RS-232 devices.
WUE Bit
The wake-up event causes a receive interrupt by setting the RCxIF bit. The WUE bit is cleared in hardware by
a rising edge on RX/DT. The Interrupt condition is then cleared in software by reading the RCxREG register and
discarding its contents.
To ensure that no actual data is lost, check the RCIDL bit to verify that a receive operation is not in process before
setting the WUE bit. If a receive operation is not occurring, the WUE bit may then be set just prior to entering the
Sleep mode.
Figure 24-7. Auto-Wake-Up (WUE) Bit Timing During Normal Operation
Rev. 10-000 326A
2/13/201 7
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
FOSC
RXx/DTx
line
RCxIF
Cleared due to user read of RCxREG
Note: The EUSART remains in Idle while the WUE bit is set.
q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4
FOSC
RXx/DTx
line
RCxIF
Cleared due to user read of RCxREG
Note: The EUSART remains in Idle while the WUE bit is set.
The Transmit Shift Register Status (TRMT) bit indicates when the transmit operation is Active or Idle, just as it does
during normal transmission. See Figure 24-9 for more details.
Write 2/13/201 7
Write to TXxREG
BRG Output
(Shift Clock)
SENDB
SENDB sampled here Auto cleared
(send break
control bit)
There are two signal lines in Synchronous mode: A bidirectional data line (DT) and a clock line (CK). The clients use
the external clock supplied by the host to shift the serial data into and out of their respective receive and transmit shift
registers. Since the data line is bidirectional, synchronous operation is half-duplex only. Half-duplex refers to the fact
that host and client devices can receive and transmit data but not both simultaneously. The EUSART can operate as
either a host or client device.
Start and Stop bits are not used in synchronous transmissions.
Important: Clearing the SREN and CREN bits ensure that the device is in the Transmit mode, otherwise
the device will be configured to receive.
Host Clock
Synchronous data transfers use a separate clock line, which is synchronous with the data. A device configured as
a host transmits the clock on the TX/CK line. The TXx/CKx pin output driver is automatically enabled when the
EUSART is configured for synchronous transmit or receive operation. Serial data bits change on the leading edge to
ensure they are valid at the trailing edge of each clock. One clock cycle is generated for each data bit. Only as many
clock cycles are generated as there are data bits.
Clock Polarity
A clock polarity option is provided for Microwire compatibility. Clock polarity is selected with the Clock/Transmit
Polarity Select (SCKP) bit. Setting the SCKP bit sets the clock Idle state as high. When the SCKP bit is set, the data
changes on the falling edge of each clock. Clearing the SCKP bit sets the Idle state as low. When the SCKP bit is
cleared, the data changes on the rising edge of each clock.
4. Enable the synchronous host serial port by setting bits SYNC, SPEN and CSRC.
5. Disable Receive mode by clearing the SREN and CREN bits.
6. Enable Transmit mode by setting the TXEN bit.
7. If 9-bit transmission is desired, set the TX9 bit.
8. If interrupts are desired, set the TXxIE bit of the PIEx register and the GIE and PEIE bits of the INTCON
register.
9. If 9-bit transmission is selected, the ninth bit will be loaded in the TX9D bit.
10. Start transmission by loading data to the TXxREG register.
Figure 24-10. Synchronous Transmission
Rev. 10-000 115A
Word 1
2/7/201 7
Write to TXxREG
BRG Output
(Shift Clock)
TXx/CKx pin Start bit bit 0 bit 1 bit 7/8 Stop bit
Client Clock
Synchronous data transfers use a separate clock line, which is synchronous with the data. A device configured as a
client receives the clock on the TX/CK line. The TXx/CKx pin output driver is automatically disabled when the device
is configured for synchronous client transmit or receive operation. Serial data bits change on the leading edge to
ensure they are valid at the trailing edge of each clock. One data bit is transferred for each clock cycle. Only as many
clock cycles may be received as there are data bits.
Important: If the device is configured as a client and the TX/CK function is on an analog pin, the
corresponding ANSEL bit must be cleared.
RXx/DTx pin bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
TXx/CKx pin
SCKP = 0
TXx/CKx pin
SCKP = 1
Write to SREN
SREN bit
RCxIF
(Interrupt)
Read
RCxREG
Important: Clearing the SREN and CREN bits ensure that the device is in Transmit mode, otherwise the
device will be configured to receive.
TXxSTA
Name: TXxSTA
Offset: 0x011E
Bit 7 6 5 4 3 2 1 0
CSRC TX9 TXEN SYNC SENDB BRGH TRMT TX9D
Access R/W R/W R/W R/W R/W R/W R R/W
Reset 0 0 0 0 0 0 1 0
Note: 1. The SREN and CREN bits override TXEN in Sync mode.
RCxSTA
Name: RCxSTA
Offset: 0x011D
Bit 7 6 5 4 3 2 1 0
SPEN RX9 SREN CREN ADDEN FERR OERR RX9D
Access R/W R/W R/W/HC R/W R/W R R/HC R/HC
Reset 0 0 0 0 0 0 0 0
BAUDxCON
Name: BAUDxCON
Offset: 0x011F
Bit 7 6 5 4 3 2 1 0
ABDOVF RCIDL SCKP BRG16 WUE ABDEN
Access R R R/W R/W R/W R/W
Reset 0 0 0 0 0 0
RCxREG
Name: RCxREG
Offset: 0x0119
Bit 7 6 5 4 3 2 1 0
RCREG[7:0]
Access R R R R R R R R
Reset 0 0 0 0 0 0 0 0
TXxREG
Name: TXxREG
Offset: 0x011A
Bit 7 6 5 4 3 2 1 0
TXREG[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
SPxBRG
Name: SPxBRG
Offset: 0x011B
Bit 15 14 13 12 11 10 9 8
SPBRG[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
SPBRG[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• SPxBRGH: Accesses the high byte SPBRG[15:8]
• SPxBRGL: Accesses the low byte SPBRG[7:0]
0x00
... Reserved
0x0118
0x0119 RC1REG 7:0 RCREG[7:0]
0x011A TX1REG 7:0 TXREG[7:0]
7:0 SPBRG[7:0]
0x011B SP1BRG
15:8 SPBRG[15:8]
0x011D RC1STA 7:0 SPEN RX9 SREN CREN ADDEN FERR OERR RX9D
0x011E TX1STA 7:0 CSRC TX9 TXEN SYNC SENDB BRGH TRMT TX9D
0x011F BAUD1CON 7:0 ABDOVF RCIDL SCKP BRG16 WUE ABDEN
Data bus
Read Write
8 8
SSPxBUF
SSPxDATPPS 8
RxyPPS (1)
Edge Prescaler
SCK PPS TOSC
select 4, 16, 64
The SPI bus operates with a single host device and one or more client devices. When multiple client devices
are used, an independent Client Select connection is required from the host device to each client device. The
host selects only one client at a time. Most client devices have tri-state outputs, so their output signal appears
disconnected from the bus when they are not selected.
Figure 25-2 shows a typical connection between a host device and multiple client devices.
SCK
SDI
SDO
SS
SPI Client #3
SCK
SDI
SDO
SS
Transmissions involve two shift registers, eight bits in size: One in the host and one in the client. Data is always
shifted out one bit at a time, with the Most Significant bit (MSb) shifted out first. At the same time, a new Least
Significant bit (LSb) is shifted into the same register.
Figure 25-3 shows a typical connection between two processors configured as host and client devices.
3/31/2017
Client Select
GPIO SS
Processor 1 (optional) Processor 2
Data is shifted out of both shift registers on the programmed clock edge and latched on the opposite edge of the
clock.
The host device transmits information out on its SDO output pin, which is connected to and received by the client’s
SDI input pin. The client device transmits information out on its SDO output pin, which is connected to and received
by the host’s SDI input pin.
To begin communication, the host device transmits both the MSb from its shift register and the clock signal. Both the
host and client devices need to be configured for the same clock polarity. During each SPI clock cycle, a full-duplex
data transmission occurs. This means that while the host device is sending out the MSb from its shift register (on its
SDO pin) and the client device is reading this bit and saving it as the LSb of its shift register, the client device is also
sending out the MSb from its shift register (on its SDO pin) and the host device is reading this bit and saving it as the
LSb of its shift register.
After eight bits have been shifted out, the host and client have exchanged register values. If there is more data to
exchange, the shift registers are loaded with new data and the process repeats itself.
Whether the data is meaningful or not (dummy data) depends on the application software. This leads to three
scenarios for data transmission:
• Host sends useful data and client sends dummy data.
• Host sends useful data and client sends useful data.
• Host sends dummy data and client sends useful data.
Transmissions must be performed in multiples of eight clock cycles. When there is no more data to be transmitted,
the host stops sending the clock signal and it deselects the client.
Every client device connected to the bus that has not been selected through its Client Select line must disregard the
clock and transmission signals and must not transmit out any data of its own.
Important: The SSPSR is not directly readable or writable and can only be accessed by addressing the
SSPxBUF register.
Important: In Host mode, the clock signal output to the SCK pin is also the clock signal input to the
peripheral. The pin selected for output with the RxyPPS register must also be selected as the peripheral
input with the SSPxCLKPPS register.
Write to
SSPxBUF
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0) 4 Clock
SCK Modes
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Input
Sample
(SMP = 1)
SSPxIF
SSPSR to
SSPxBUF
Daisy-Chain Configuration
The SPI bus can sometimes be connected in a daisy-chain configuration. The first client output is connected to the
second client input, the second client output is connected to the third client input, and so on. The final client output is
connected to the host input. Each client sends out, during a second group of clock pulses, an exact copy of what was
received during the first group of clock pulses. The whole chain acts as one large communication shift register. The
daisy-chain feature only requires a single Client Select line from the host device.
In a daisy-chain configuration, only the most recent byte on the bus is required by the client. Setting the Buffer
Overwrite Enable (BOEN) bit will enable writes to the SSPxBUF register, even if the previous byte has not been read.
This allows the software to ignore data that may not apply to it.
Figure 25-5 shows the block diagram of a typical daisy-chain connection when operating in SPI mode.
Figure 25-5. SPI Daisy-Chain Connection
SPI Client #2
SCK
SDI
SDO
SS
SPI Client #3
SCK
SDI
SDO
SS
Important:
1. When the SPI is in Client mode with SS pin control enabled (SSPM = 0100), the SPI module will
reset if the SS pin is set to VDD.
2. When the SPI is used in Client mode with CKE set, the user must enable SS pin control (see Figure
25-8). If CKE is clear, SS pin control is optional (see Figure 25-7).
3. While operated in SPI Client mode, the SMP bit must remain clear.
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPxBUF
Shift register SSPSR
and bit count are reset
SSPxBUF to
SSPSR
SDI bit 0
bit 7 bit 7
Input
Sample
SSPxIF
Interrupt
Flag
SSPSR to
SSPxBUF
SS
Optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPxBUF
Valid
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
SDI
bit 7 bit 0
Input
Sample
SSPxIF
Interrupt
Flag
SSPSR to
SSPxBUF
Write Collision
detection active
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPxBUF
Valid
SDO bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
SDI
bit 7 bit 0
Input
Sample
SSPxIF
Interrupt
Flag
SSPSR to
SSPxBUF
Write Collision
detection active
Internal
d ata bus [SSPM[3:0]]
SSPxDATPPS(1) Read Write
SDA
SDA in
PPS SSPxBUF
Generator
(SSPxADD)
Shift
RxyPPS(1) Clock
Clock Cntl
PPS
Notes: 1. SDA pin selections must be the same for input and output.
2. SCL pin selections must be the same for input and output.
Read Write
PPS
Shift
Clock
PPS Clock SSPSR Reg
Stretching
MSb LSb
RxyPPS (2)
SSPxMSK Reg
SSPxDATPPS(1
SDA ) Match Detect Addr Match
PPS
SSPxADD Reg
PPS
Start and Set, Reset
Stop bit Detect S, P bits
(1)
RxyPPS (SSPxSTAT Reg)
Notes: 1. SDA pin selections must be the same for input and output.
2. SCL pin selections must be the same for input and output.
VDD
SCL SCL
VDD
Host Client
SDA SDA
The I2C bus can operate with one or more host devices and one or more client devices.
There are four potential modes of operation for a given device:
• Host Transmit mode (host is transmitting data to a client)
• Host Receive mode (host is receiving data from a client)
• Client Transmit mode (client is transmitting data to a host)
• Client Receive mode (client is receiving data from the host)
To begin communication, the host device transmits a Start condition followed by the address byte of the client it
intends to communicate with. A Start condition is indicated by a high-to-low transition of the SDA line while the SCL
line is held high. Address and data bytes are sent out, MSb first. This is followed by a single Read/Write Information
(R/W) bit, which determines whether the host intends to transmit to or receive data from the client device. The R/W
bit is sent out as a logical one when the host intends to read data from the client, and is sent out as a logical zero
when it intends to write data to the client.
If the requested client exists on the bus, it will respond with an Acknowledge sequence, otherwise known as an ACK.
The Acknowledge sequence is an active-low signal, which holds the SDA line low to indicate to the transmitter that
the client device has received the transmitted data and is ready to receive more. The host then continues to either
transmit to or receive data from the client.
The transition of a data bit is always performed while the SCL line is held low. Transitions that occur while the SCL
line is held high are used to indicate Start and Stop conditions.
If the host intends to write to the client, then it repeatedly sends out a byte of data, with the client responding after
each byte with an ACK sequence. In this example, the host device is in Host Transmit mode and the client is in Client
Receive mode.
If the host intends to read from the client, then it repeatedly receives a byte of data from the client, and responds after
each byte with an ACK sequence. In this example, the host device is in Host Receive mode and the client is in Client
Transmit mode.
On the last byte of data communicated, the host device may end the transmission by sending a Stop condition. If the
host device is in Receive mode, it sends the Stop condition in place of the last ACK sequence. A Stop condition is
indicated by a low-to-high transition of the SDA line while the SCL line is held high.
In some cases, the host may want to maintain control of the bus and re-initiate another transmission. If so, the host
device may send a Restart condition in place of the Stop condition or last ACK sequence when it is in Receive mode.
The I2C bus specifies three message protocols:
• Single message where a host writes data to a client.
• Single message where a host reads data from a client.
• Combined message where a host initiates a minimum of two writes, or two reads, or a combination of writes and
reads, to one or more clients.
Term Description
Transmitter The device that shifts data out onto the bus
Receiver The device that shifts data in from the bus
Host The device that initiates a transfer, generates clock signals, and terminates a transfer
Client The device addressed by the host
Multi-Host A bus with more than one device that can initiate data transfers
Arbitration Procedure to ensure that only one host at a time controls the bus. Winning arbitration ensures
that the message is not corrupted.
Synchronization Procedure to synchronize the clocks of two or more devices on the bus
Idle No host is controlling the bus, and both SDA and SCL lines are high
Active Any time one or more host devices are controlling the bus
Addressed Client Client device that has received a matching address and is actively being clocked by a host
Matching Address Address byte that is clocked into a client that matches the value stored in SSPxADD
Write Request Client receives a matching address with the R/W bit clear, and is ready to clock in data
Read Request Host sends an address byte with the R/W bit set, indicating that it wishes to clock data out of the
client. This data is the next and all following bytes until a Restart or Stop.
Clock Stretching When a device on the bus hold SCL low to stall communication
Bus Collision Any time the SDA line is sampled low by the module while it is outputting and expected High
state
Byte Format
All communication in I2C is done in 9-bit segments. A byte is sent from a host to a client or vice versa, followed by
an Acknowledge sequence sent back. After the eighth falling edge of the SCL line, the device outputting data on the
SDA changes that pin to an input and reads the Acknowledge value on the next clock pulse.
The clock signal, SCL, is provided by the host. Data is valid to change while the SCL signal is low, and sampled on
the rising edge of the clock. Changes on the SDA line while the SCL line is high define special conditions on the bus,
such as a Start or Stop condition.
Important: Any device pin can be selected for SDA and SCL functions with the PPS peripheral. These
functions are bidirectional. The SDA input is selected with the SSPxDATPPS registers. The SCL input is
selected with the SSPxCLKPPS registers. Outputs are selected with the RxyPPS registers. It is the user’s
responsibility to make the selections so that both the input and the output for each function is on the same
pin.
Clock Stretching
Clock stretching occurs when a device on the bus holds the SCL line low, effectively pausing communication. The
client may stretch the clock to allow more time to handle data or prepare a response for the host device. A host
device is not concerned with stretching as anytime it is active on the bus and not transferring data it is stretching. Any
stretching done by a client is invisible to the host software and handled by the hardware that generates SCL.
The CKP bit is used to control stretching in software. Any time the CKP bit is cleared, the module will wait for the SCL
line to go low and then hold it. Setting CKP will release SCL and allow more communication.
Arbitration
Each host device must monitor the bus for Start and Stop conditions. If the device detects that the bus is busy, it
cannot begin a new message until the bus returns to an Idle state.
However, two host devices may try to initiate a transmission on or about the same time. When this occurs, the
process of arbitration begins. Each transmitter checks the level of the SDA data line and compares it to the level that
it expects to find. The first transmitter to observe that the two levels do not match, loses arbitration, and must stop
transmitting on the SDA line.
For example, if one transmitter holds the SDA line to a logical one (lets SDA float) and a second transmitter holds it
to a logical zero (pulls SDA low), the result is that the SDA line will be low. The first transmitter then observes that the
level of the line is different than expected and concludes that another transmitter is communicating.
The first transmitter to notice this difference is the one that loses arbitration and must stop driving the SDA line.
If this transmitter is also a host device, it also must stop driving the SCL line. It then can monitor the lines for a
Stop condition before trying to reissue its transmission. In the meantime, the other device that has not noticed any
difference between the expected and actual levels on the SDA line continues with its original transmission. It can do
so without any complications, because so far, the transmission appears exactly as expected with no other transmitter
disturbing the message.
Client Transmit mode can also be arbitrated, when a host addresses multiple clients, but this is less common.
Start Condition
The I2C Specification defines a Start condition as a transition of SDA from a High to a Low state while SCL line is
high. A Start condition is always generated by the host and signifies the transition of the bus from an Idle to an Active
state. Figure 25-12 shows wave forms for Start and Stop conditions.
A bus collision can occur on a Start condition if the module samples the SDA line low before asserting it low. This
does not conform to the I2C Specification that states no bus collision can occur on a Start.
Stop Condition
A Stop condition is a transition of the SDA line from Low-to-High state while the SCL line is high.
Important: At least one SCL low time must appear before a Stop is valid, therefore, if the SDA line goes
low then high again while the SCL line stays high, only the Start condition is detected.
SDA
SCL
S P
Change of Change of
Data Allowed Data Allowed
Start Stop
Condition Condition
Restart Condition
A Restart condition is valid any time that a Stop is valid. A host can issue a Restart if it wishes to hold the bus after
terminating the current transfer. A Restart has the same effect on the client that a Start would, resetting all client
logic and preparing it to clock in an address. The host may want to address the same or another client. Figure 25-13
shows the waveform for a Restart condition.
In 10-bit Addressing Client mode, a Restart is required for the host to clock data out of the addressed client. Once a
client has been fully addressed, matching both high and low address bytes, the host can issue a Restart and the high
address byte with the R/W bit set. The client logic will then hold the clock and prepare to clock out data.
Figure 25-13. I2C Restart Condition
Rev. 30-000023A
4/3/2017
Sr
Change of Change of
Acknowledge Sequence
The ninth SCL pulse for any transferred byte in I 2C is dedicated as an Acknowledge sequence (ACK). It allows
receiving devices to respond back to the transmitter by pulling the SDA line low. The transmitter must release control
of the line during this time to shift in the response. The Acknowledge (ACK) is an active-low signal, pulling the SDA
line low indicates to the transmitter that the device has received the transmitted data and is ready to receive more.
The result of an ACK is placed in the Acknowledge Status (ACKSTAT) bit.
The client software, when the Address Hold Enable (AHEN) and Data Hold Enable (DHEN) bits are set, allows the
user to select the ACK value sent back to the transmitter. The Acknowledge Data (ACKDT) bit is set/cleared to
determine the response.
The client hardware will generate an ACK response under most circumstances. However, if the BF bit or the Receive
Overflow Indicator (SSPOV) bit are set when a byte is received then the ACK will not be sent by the client.
When the module is addressed, after the eighth falling edge of SCL on the bus, the Acknowledge Time Status
(ACKTIM) bit is set. The ACKTIM bit indicates the acknowledge time of the active bus. The ACKTIM bit is only active
when either the AHEN bit or DHEN bit is enabled.
Clock Stretching
Clock stretching occurs when a device on the bus holds the SCL line low, effectively pausing communication. The
client may stretch the clock to allow more time to handle data or prepare a response for the host device. A host
device is not concerned with stretching as anytime it is active on the bus and not transferring data it is stretching. Any
stretching done by a client is invisible to the host software and handled by the hardware that generates SCL.
The CKP bit is used to control stretching in software. Any time the CKP bit is cleared, the module will wait for the SCL
line to go low and then hold it. Setting CKP will release SCL and allow more communication.
Byte NACKing
When the AHEN bit is set, CKP is cleared by hardware after the eighth falling edge of SCL for a received matching
address byte. When the DHEN bit is set, CKP is cleared after the eighth falling edge of SCL for received data.
Stretching after the eighth falling edge of SCL allows the client to look at the received address or data and decide if it
wants to acknowledge (ACK) the received address or data, or not acknowledge (NACK) the address or data.
Receiving Data
SDA General Call Address ACK D7 D6 D5 D4 D3 D2 D1 D0
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Start
BF SSPxBUF is read
In 10-bit Address mode, the UA bit will not be set on the reception of the general call address. The client will prepare
to receive the second byte as data, just as it would in 7-bit mode.
If the AHEN bit is set, just as with any other address reception, the client hardware will stretch the clock after the
eighth falling edge of SCL. The client must then set its Acknowledge Sequence Enable (ACKEN) bit and release the
clock.
Client Reception
When the R/W bit of a matching received address byte is clear, the R/W bit is cleared. The received address is
loaded into the SSPxBUF register and acknowledged.
When the Overflow condition exists for a received address, a Not Acknowledge (NACK) is transmitted and the
Receive Overflow Indicator (SSPOV) bit is set. The Buffer Override Enable (BOEN) bit modifies this operation.
An MSSP interrupt is generated for each transferred data byte. The SSPxIF flag bit must be cleared by software.
When the SEN bit is set, SCL will be held low (clock stretch) following each received byte. The clock must be
released by setting the CKP bit, except sometimes in 10-bit mode. See 25.2.3.2.2. 10-Bit Addressing Mode for more
details.
Figure 25-15. I2C Client, 7-Bit Address, Reception (SEN = 0, AHEN = 0, DHEN = 0)
SDA A7 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0 Hardware
Hardware sets P
R/W ACK from Client to Host
sets S
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Cleared by Cleared by
SSPxIF software software
SSPxIF set on
Software reads SSPxBUF, the 9th falling
hardware clears BF edge of SCL
PIC16F15213/14/23/24/43/44
available in SSPxBUF ACK is not sent
SSPOV
DS40002195D-page 268
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
Figure 25-16. I2C Client, 7-Bit Address, Reception (SEN = 1, AHEN = 0, DHEN = 0)
Cleared by Cleared by
SSPxIF software software
hardware clears BF
BF
PIC16F15213/14/23/24/43/44
SSPOV is set
First byte of data because SSPxBUF is
available in SSPxBUF full, NACK sent by
SSPOV hardware
CKP
Software sets CKP; Software sets CKP;
hardware releases SCL hardware releases SCL
DS40002195D-page 269
PIC16F15213/14/23/24/43/44
MSSP - Host Synchronous Serial Port Module
Important: SSPxIF is still set after the ninth falling edge of SCL even if there is no clock stretching
and BF has been cleared. Only if a NACK is sent to the host is SSPxIF not set.
11. SSPxIF is set and CKP cleared after eighth falling edge of SCL for a received data byte.
12. Client looks at the ACKTIM bit to determine the source of the interrupt.
13. Client reads the received data from SSPxBUF, clearing BF.
14. Steps 7-14 are the same for each received data byte.
15. Communication is ended by either the client sending a NACK, or the host sending a Stop condition. If a Stop is
sent and the Stop Condition Interrupt Enable (PCIE) bit is clear, the client will only know by polling the Stop (P)
bit.
Figure 25-17. I2C Client, 7-Bit Address, Reception (SEN = 0, AHEN = 1, DHEN = 1)
R/W
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Clock held low by client
until CKP = 1
SSPxIF
PIC16F15213/14/23/24/43/44
First byte of data
available in SSPxBUF
Software sets ACKDT
ACKDT Software clears ACKDT to to transmit NACK
ACK received byte
Figure 25-18. I2C Client, 7-Bit Address, Reception (SEN = 1, AHEN = 1, DHEN = 1)
R/W
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
SSPxIF
PIC16F15213/14/23/24/43/44
First byte of data
Software clears ACKDT to available in SSPxBUF
ACK received byte
Software sets ACKDT
ACKDT to transmit NACK
SEN = 1, hardware
clears CKP SEN = 1, hardware
DHEN = 1, hardware clears CKP
clears CKP
Important: Updates to the SSPxADD register are not allowed until after the ACK sequence.
Important: If the low address does not match, SSPxIF and UA are still set so that the client
software can set SSPxADD back to the high address. BF is not set because there is no match. CKP
is unaffected.
Figure 25-19. I2C Client, 10-Bit Address, Reception (SEN = 1, AHEN = 0, DHEN = 0)
SCL
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S P
SCL is held low
while CKP = 0
Set by hardware on Cleared by
9th falling edge software
SSPxIF
Receive address is read
If address matches from SSPxBUF
SSPxADD it is loaded
into SSPxBUF
BF
PIC16F15213/14/23/24/43/44
CKP
When SEN = 1; CKP is Set by software,
cleared after 9th falling edge releasing SCL
of received byte
DS40002195D-page 274
PIC16F15213/14/23/24/43/44
MSSP - Host Synchronous Serial Port Module
Figure 25-20. I2C Client, 10-Bit Address, Reception (SEN = 0, AHEN = 1, DHEN = 0)
R/W ACK
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2
S
SSPxIF
Set by hardware on
Cleared by Cleared by
9th falling edge
software software
BF
PIC16F15213/14/23/24/43/44
Client software clears
ACKDT to ACK the
received byte
UA
Update to SSPxADD Update of SSPxADD,
is not allowed until 9th clears UA and releases
falling edge of SCL SCL
cleared
ACKTIM is set by hardware
on 8th falling edge of SCL
and its subsidiaries
© 2020-2022 Microchip Technology Inc.
Figure 25-21. I2C Client, 10-Bit Address, Transmission (SEN = 0, AHEN = 0, DHEN = 0)
Cleared by
SSPxIF Hardware set
software
Software loads SSPxBUF, Data transmitted, hardware
Software reads SSPxBUF, hardware sets BF clears BF
hardware clears BF
Address loaded
BF into SSPxBUF
PIC16F15213/14/23/24/43/44
UA updated into SSPxADD
Client Transmission
When the R/W bit of the incoming address byte is set and an address match occurs, the R/W bit is set. The received
address is loaded into the SSPxBUF register, and an ACK pulse is sent by the client on the ninth bit.
Following the ACK, client hardware clears the CKP bit and the SCL pin is held low (see 25.2.2.5. Clock Stretching
for more details). By stretching the clock, the host will be unable to assert another clock pulse until the client is done
preparing the transmit data.
The transmit data must be loaded into the SSPxBUF register, which also loads the SSPSR register. Then the SCL pin
will be released by setting the CKP bit. The eight data bits are shifted out on the falling edge of the SCL input. This
ensures that the SDA signal is valid during the SCL high time.
The ACK pulse from the host receiver is latched on the rising edge of the ninth SCL input pulse. This ACK value is
copied to the ACKSTAT bit. If ACKSTAT is set (NACK), then the data transfer is complete. In this case, when the
NACK is latched by the client, the client goes Idle and waits for another occurrence of a Start condition. If the SDA
line was low (ACK), the next transmit data must be loaded into the SSPxBUF register. Again, the SCL pin must be
released by setting bit CKP.
An MSSP interrupt is generated for each data transfer byte. The SSPxIF bit must be cleared by software and the
SSPxSTAT register is used to determine the status of the byte. The SSPxIF bit is set on the falling edge of the ninth
clock pulse.
7-Bit Transmission
A host device can transmit a read request to a client, and then clock data out of the clien. The list below outlines what
software for a client will need to do to accomplish a standard transmission. Figure 25-22 can be used as a reference
to this list.
1. Host sends a Start condition.
2. The Start (S) bit is set; SSPxIF is set if SCIE is set.
3. Matching address with R/W bit set is received by the Client, setting SSPxIF bit.
4. Client hardware generates an ACK and sets SSPxIF.
5. The SSPxIF bit is cleared by software.
6. Software reads the received address from SSPxBUF, clearing BF.
7. R/W is set so CKP was automatically cleared after the ACK.
8. The client software loads the transmit data into SSPxBUF.
9. CKP bit is set by software, releasing SCL, allowing the host to clock the data out of the client.
10. SSPxIF is set after the ACK response from the host is loaded into the ACKSTAT bit.
11. SSPxIF bit is cleared.
12. The client software checks the ACKSTAT bit to see if the host wants to clock out more data.
Important:
1. If the host ACKs then the clock will be stretched.
2. ACKSTAT is the only bit updated on the rising edge of the ninth SCL clock instead of the falling
edge.
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
hardware sets BF
PIC16F15213/14/23/24/43/44
CKP R/W = 1, hardware Software sets CKP,
clears CKP hardware releases SCL Host’s NACK copied
to ACKSTAT
13. Client software sets the CKP bit, releasing the clock.
14. Host clocks out the data from the client and sends an ACK value on the ninth SCL pulse.
15. Client hardware copies the ACK value into the ACKSTAT bit.
16. Steps 10-15 are repeated for each byte transmitted to the host from the client.
17. If the host sends a not ACK, the client releases the bus allowing the host to send a Stop and end the
communication.
Important: Host must send a not ACK on the last byte to ensure that the client releases the SCL
line to receive a Stop.
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
SSPxIF
Software reads SSPxBUF, Cleared by hardware on
hardware clears BF 8th falling SCL edge
PIC16F15213/14/23/24/43/44
CKP AHEN = 1, hardware clears CKP Software sets CKP,
hardware releases SCL
Software sets CKP,
hardware releases SCL R/W = 1, hardware clears CKP
Important:
1. The MSSP module, when configured in I2C Host mode, does not allow queuing of events. For
instance, the user is not allowed to initiate a Start condition and immediately write the SSPxBUF
register to initiate transmission before the Start condition is complete. In this case, SSPxBUF will
not be written to and the Write Collision Detect (WCOL) bit will be set, indicating that a write to
SSPxBUF did not occur.
2. Host mode suspends Start/Stop detection when sending the Start/Stop condition by means of the
SEN/PEN control bits. The SSPxIF bit is set at the end of the Start/Stop generation when hardware
clears the control bit.
Clock Arbitration
Clock arbitration occurs when the host, during any receive, transmit or Repeated Start/Stop condition, releases the
SCL pin (SCL allowed to float high). When the SCL pin is allowed to float high, the Baud Rate Generator (BRG) is
suspended from counting until the SCL pin is actually sampled high. When the SCL pin is sampled high, the Baud
Rate Generator is reloaded with the contents of SSPxADD and begins counting. This ensures that the SCL high time
will always be at least one BRG rollover count in the event that the clock is held low by an external device as shown
in Figure 25-24.
SDA DX DX, -1
SCL deasserted but client holds SCL allowed to
SCL low (clock arbitration) transition high
SCL
BRG decrements on
Q2 and Q4 cycles
BRG
03h 02h 01h 00h (hold off) 03h 02h
Value
SCL is sampled high, reload takes
place and BRG starts its count
BRG
Reload
Important: Because queuing of events is not allowed, writing to the lower five bits of SSPxCON2 is
disabled until the Start condition is complete.
Important:
1. If at the beginning of the Start condition, the SDA and SCL pins are already sampled low, or if
during the Start condition, the SCL line is sampled low before the SDA line is driven low, a bus
collision occurs, the Bus Collision Interrupt Flag (BCLxIF) is set, the Start condition is aborted and
the I2C module is reset into its Idle state.
2. The Philips I2C Specification states that a bus collision cannot occur on a Start.
SDA TBRG
1st bit 2nd bit
SDA, SCL
sampled ‘high’
TBRG
TBRG
SCL
Important:
1. If RSEN is programmed while any other event is in progress, it will not take effect.
2. A bus collision during the Repeated Start condition occurs if:
– SDA is sampled low when SCL goes from low-to-high.
– SCL goes low before SDA is asserted low. This may indicate that another host is attempting to
transmit a data ‘1’.
write to SSPxCON2
ACKEN = 1, ACKDT = 0
TBRG TBRG
SDA D0 ACK
SCL 8 9
SSPxIF
SDA ACK/NACK
TBRG
TBRG TBRG
Sleep Operation
While in Sleep mode, the I2C client module can receive addresses or data and when an address match or complete
byte transfer occurs, wake the processor from Sleep (if the MSSP interrupt is enabled).
Effects of a Reset
A Reset disables the MSSP module and terminates the current transfer.
BF Status Flag
In Transmit mode, the Buffer Full Status (BF) bit is set when the CPU writes to SSPxBUF, and is cleared when all
eight bits are shifted out.
SDA A7 A6 A5 A4 A3 A2 A1 ACK D7 D6 D5 D4 D3 D2 D1 D0
SSPxBUF loaded with SCL stretched while
address and R/W bit CPU responds to
SCL SSPxIF
Cleared by Cleared by
SSPxIF software software
Cleared by
software
BF
Cleared by
hardware
Cleared by
SEN hardware
PEN
Cleared by
software
Cleared by Cleared by Cleared by
SSPxIF software software software
BF Cleared by Cleared by
Cleared by hardware hardware
hardware
SEN
Cleared by
hardware
Important: The MSSP module must be in an Idle state before the RCEN bit is set or the RCEN bit will be
disregarded.
The Baud Rate Generator begins counting and on each rollover, the state of the SCL pin changes (high-to-low/
low-to-high) and data is shifted into the SSPxSR. After the falling edge of the eighth clock all the following events
occur:
• RCEN is automatically cleared by hardware.
• The contents of the SSPxSR are loaded into the SSPxBUF.
• The BF flag bit is set.
• The SSPxIF flag bit is set.
• The Baud Rate Generator is suspended from counting.
• The SCL pin is held low.
The MSSP is now in Idle state awaiting the next command. When the buffer is read by the CPU, the BF flag bit
is automatically cleared. The Host can then send an Acknowledge sequence at the end of reception by setting the
Acknowledge Sequence Enable (ACKEN) bit.
BF Status Flag
In receive operation, the BF bit is set when an address or data byte is loaded into SSPxBUF from SSPSR. It is
cleared when the SSPxBUF register is read.
SCL 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
PIC16F15213/14/23/24/43/44
Host receives
Write to SSPxBUF Cleared by
full byte
hardware
BF
Software reads SSPxBUF,
hardware clears BF
Software sets RCEN = Cleared by
RCEN Host receiver Cleared by Software set hardware
hardware
DS40002195D-page 290
PIC16F15213/14/23/24/43/44
MSSP - Host Synchronous Serial Port Module
NACK
R/W Restart R/W (from Stop
ACK (from client) Host)
SDA
1 1 1 1 0 A9 A8 0 A7 A6 A5 A4 A3 A2 A1 A0 1 1 1 1 0 A9 A8 1 D7 D6 D5 D4 D3 D2 D1 D0
SSPxIF
Cleared by software
Software
Hardware set reads
SSPxBUF
BF Byte loaded into Host receives byte
SSPxBUF
Cleared by
hardware
Software sets RCEN = Host as receiver Cleared by
RCEN
hardware
ACKSTAT
Client’s ACK copied
to ACKSTAT
Multi-Host Mode
In Multi-Host mode, the interrupt generation on the detection of the Start and Stop conditions allows the
determination of when the bus is free. The Stop (P) and Start (S) bits are cleared from a Reset or when the MSSP
module is disabled. Control of the I2C bus may be taken when the P bit is set, or the bus is Idle, with both the S and
P bits cleared. When the bus is busy, enabling the MSSP interrupt will generate an interrupt when the Stop condition
occurs.
In Multi-Host operation, the SDA line must be monitored for arbitration to see if the signal level is the expected output
level. This check is performed by hardware with the result placed in the BCLxIF bit.
The states where arbitration can be lost are:
• Address Transfer
• Data Transfer
• A Start Condition
• A Repeated Start Condition
• An Acknowledge Condition
The host will continue to monitor the SDA and SCL pins. If a Stop condition occurs, the SSPxIF bit will be set.
A write to the SSPxBUF 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-Host mode, the interrupt generation on the detection of Start and Stop conditions allows the determination of
when the bus is free. Control of the I 2C bus can be taken when the P bit is set, or the bus is Idle and the S and P bits
are cleared.
Figure 25-33. Bus Collision Timing for Transmit and Acknowledge
SCL
Expected SDA
value
SDA released
SDA by Host
SDA
SCL
Set SEN, enable Start SEN cleared automatically because of bus collision.
condition if SDA = 1, SCL = 1 SSPx module reset into Idle state.
SEN
SDA sampled low before
Start condition. Set BCLxIF.
S bit and SSPxIF set because
BCLxIF SDA = 0, SCL = 1.
SSPxIF and BCLxIF are
cleared by software
SSPxIF
The Start condition begins with the SDA and SCL pins deasserted. When the SDA pin is sampled high, the Baud
Rate Generator is loaded and counts down. If the SCL pin is sampled low while SDA is high, a bus collision occurs
because it is assumed that another host is attempting to drive a data ‘1’ during the Start condition.
Figure 25-35. Bus Collision During Start Condition (SCL = 0)
Rev. 30-000044A
4/3/2017
SDA = 0, SCL = 1
T BRG T BRG
SDA
If the SDA pin is sampled low during this count, the BRG is reset and the SDA line is asserted early (see Figure
25-36). If, however, a ‘1’ is sampled on the SDA pin, the SDA pin is asserted low at the end of the BRG count. The
Baud Rate Generator is then reloaded and counts down to zero; if the SCL pin is sampled as ‘0’ during this time, a
bus collision does not occur. At the end of the BRG count, the SCL pin is asserted low.
Figure 25-36. BRG Reset Due to SDA Arbitration During Start Condition
SDA = 0, SCL = 1
Set S Set SSPxIF
Less than TBRG
TBRG
SCL
S
SSPxIF
Important: The reason that a bus collision is not a factor during a Start condition is that no two bus hosts
can assert a Start condition at the exact same time. Therefore, one host will always assert SDA before the
other. This condition does not cause a bus collision because the two hosts must be allowed to arbitrate
the first address following the Start condition. If the address is the same, arbitration must be allowed to
continue into the data portion, Repeated Start or Stop conditions.
SDA
SCL
RSEN
BCLxIF
Cleared by software
S ’0’
SSPxIF ’0’
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 host is attempting to transmit a data ‘1’ during the Repeated Start condition (see Figure
25-38).
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 25-38. Bus Collision During Repeated Start Condition (Case 2)
Rev. 30-000047A
4/3/2017
TBRG TBRG
SDA
SCL
S ’0’
SSPxIF
PEN
BCLxIF
P ’0’
SSPxIF ’0’
SDA
PEN
BCLxIF
P ’0’
SSPxIF ’0’
SSPM[3:0] SSPxADD[7:0]
Important: Values of 0x00, 0x01 and 0x02 are not valid for SSPxADD when used as a Baud Rate
Generator for I2C. This is an implementation limitation.
FCLOCK
FOSC FCY BRG Value
(2 Rollovers of BRG)
32 MHz 8 MHz 13h 400 kHz
32 MHz 8 MHz 19h 308 kHz
32 MHz 8 MHz 4Fh 100 kHz
16 MHz 4 MHz 09h 400 kHz
16 MHz 4 MHz 0Ch 308 kHz
16 MHz 4 MHz 27h 100 kHz
4 MHz 1 MHz 09h 100 kHz
Note: Refer to the I/O port electrical specifications in the “Electrical Specifications” chapter, Internal Oscillator
Parameters, to ensure the system is designed to support all requirements.
SSPxBUF
Name: SSPxBUF
Offset: 0x018C
Bit 7 6 5 4 3 2 1 0
BUF[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset x x x x x x x x
Bits 7:0 – BUF[7:0] MSSP Input and Output Data Buffer bits
SSPxADD
Name: SSPxADD
Offset: 0x018D
Bit 7 6 5 4 3 2 1 0
ADD[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
SSPxMSK
Name: SSPxMSK
Offset: 0x018E
Bit 7 6 5 4 3 2 1 0
MSK[6:0] MSK0
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 1 1 1 1 1 1 1 1
Bit 0 – MSK0
Mask bit for I2C 10-bit Client mode
Value Mode Description
x SPI or I2C 7-bit This bit is not used
1 I2C 10-bit Client The received address bit 0 is compared to SSPxADD bit 0 to detect I2C address
match
0 I2C 10-bit Client The received address bit 0 is not used to detect I2C address match
SSPxSTAT
Name: SSPxSTAT
Offset: 0x018F
Bit 7 6 5 4 3 2 1 0
SMP CKE D/A P S R/W UA BF
Access R/W R/W R R R R R R
Reset 0 0 0 0 0 0 0 0
Bit 6 – CKE SPI: Clock Select bit(4); I2C: SMBus Select bit
Value Mode Description
1 SPI Transmit occurs on the transition from Active to Idle clock state
0 SPI Transmit occurs on the transition from Idle to Active clock state
1 I2C Enables SMBus-specific inputs
0 I2C Disables SMBus-specific inputs
Notes:
1. This bit is cleared on Reset and when SSPEN is cleared.
2. In I2C Client mode, 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.
3. ORing this bit with SEN, RSEN, PEN, RCEN or ACKEN will indicate if the MSSP is in Active mode.
4. Polarity of clock state is set by the CKP bit.
5. I2C receive status does not include ACK and Stop bits.
SSPxCON1
Name: SSPxCON1
Offset: 0x0190
Bit 7 6 5 4 3 2 1 0
WCOL SSPOV SSPEN CKP SSPM[3:0]
Access R/W/HS R/W/HS R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 – WCOL
Write Collision Detect bit
Value Mode Description
x Host or Client receive This bit is not used
1 SPI or I2C Host or Client transmit The SSPxBUF register is written while it is still transmitting the
previous word (must be cleared in software)
0 SPI or I2C Host or Client transmit No collision
Bit 6 – SSPOV
Receive Overflow Indicator bit(1)
Value Mode Description
x SPI Host or I2C Host This bit is not used
transmit
1 SPI Client A byte is received while the SSPxBUF register is still holding the previous
byte. Data contained in the shift register will be discarded. The user must read
SSPxBUF, even if only transmitting data, to avoid setting overflow (must be
cleared in software).
1 I2C Receive A byte is received while the SSPxBUF register is still holding the previous
byte (must be cleared in software)
0 SPI Client or I2C No overflow
Receive
Bit 5 – SSPEN
Host Synchronous Serial Port Enable bit.(2)
Value Description
1 Enables the serial port
0 Disables serial port and configures these pins as I/O PORT pins
Bit 4 – CKP
SCK Release Control bit
Value Mode Description
x I2C Host This bit is not used
1 SPI Idle state for the clock is a high level
0 SPI Idle state for the clock is a low level
1 I2C Client Releases clock
0 I2C Client Holds clock low (clock stretch), used to ensure data setup time
Value Description
1010 SPI Host mode: Clock = FOSC/(4*(SSPxADD+1)). SSPxADD must be greater than 0.(3)
1001 Reserved - do not use
1000 I2C Host mode: Clock = FOSC/(4 * (SSPxADD + 1))
0111 I2C Client mode: 10-bit address
0110 I2C Client mode: 7-bit address
0101 SPI Client mode: Clock = SCKx pin. SSx pin control is disabled
0100 SPI Client mode: Clock = SCKx pin. SSx pin control is enabled
0011 SPI Host mode: Clock = TMR2 output/2
0010 SPI Host mode: Clock = FOSC/64
0001 SPI Host mode: Clock = FOSC/16
0000 SPI Host mode: Clock = FOSC/4
Notes:
1. In Host mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to
the SSPxBUF register.
2. When enabled, these pins must be properly configured as inputs or outputs.
3. SSPxADD = 0 is not supported.
4. Bit combinations not specifically listed here are either reserved or implemented in I2C mode only.
SSPxCON2
Name: SSPxCON2
Offset: 0x0191
MSSP Control Register 2
Control Register for I2C Operation Only
Bit 7 6 5 4 3 2 1 0
GCEN ACKSTAT ACKDT ACKEN RCEN PEN RSEN SEN
Access R/W R/W/HC R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 – GCEN
General Call Enable bit (Client mode only)
Value Mode Description
x Host mode Don’t care
1 Client mode General Call is enabled
0 Client mode General Call is not enabled
Bit 5 – ACKDT
Acknowledge Data bit (Host Receive mode only)(1)
Value Description
1 Not Acknowledge
0 Acknowledge
Bit 4 – ACKEN
Acknowledge Sequence Enable bit(2)
Value Description
1 Initiates Acknowledge sequence on SDAx and SCLx pins and transmits ACKDT data bit;
automatically cleared by hardware
0 Acknowledge sequence is Idle
Bit 3 – RCEN
Receive Enable bit (Host Receive mode only)(2)
Value Description
1 Enables Receive mode for I2C
0 Receive is Idle
Bit 2 – PEN
Stop Condition Enable bit (Host mode only)(2)
Value Description
1 Initiates Stop condition on SDAx and SCLx pins; automatically cleared by hardware
0 Stop condition is Idle
Bit 1 – RSEN
Repeated Start Condition Enable bit (Host mode only)(2)
Value Description
1 Initiates Repeated Start condition on SDAx and SCLx pins; automatically cleared by hardware
0 Repeated Start condition is Idle
Bit 0 – SEN
Start Condition Enable bit(2)
Value Mode Description
1 Host Initiates Start condition on SDAx and SCLx pins; automatically cleared by hardware
0 Host Start condition is Idle
1 Client Clock stretching is enabled
0 Client Clock stretching is disabled
Notes:
1. The value that will be transmitted when the user initiates an Acknowledge sequence at the end of a receive.
2. If the I2C module is active, these bits may not be set (no spooling) and the SSPxBUF may not be written (or
writes to the SSPxBUF are disabled).
SSPxCON3
Name: SSPxCON3
Offset: 0x0192
Bit 7 6 5 4 3 2 1 0
ACKTIM PCIE SCIE BOEN SDAHT SBCDE AHEN DHEN
Access R/HS/HC R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 – ACKTIM
Acknowledge Time Status bit
Value Mode Description
x SPI or I2C Host This bit is not used
1 I2C Client and AHEN = 1 or DHEN Eighth falling edge of SCL has occurred and the ACK/NACK state
=1 is Active
0 I2C Client ACK/NACK state is not Active. Transitions low on ninth rising edge
of SCL.
Bit 6 – PCIE
Stop Condition Interrupt Enable bit
Value Mode Description
x SPI or SSPM = 1111 or 1110 This bit is not used
1 SSPM ≠ 1111 and SSPM ≠ 1110 Enable interrupt on detection of Stop condition
0 SSPM ≠ 1111 and SSPM ≠ 1110 Stop detection interrupts are disabled
Bit 4 – BOEN
Buffer Overwrite Enable bit(1)
Value Mode Description
1 SPI SSPxBUF is updated every time a new data byte is available, ignoring the BF bit
0 SPI If a new byte is receive with BF set then SSPOV is set and SSPxBUF is not updated
1 I2C SSPxBUF is updated every time a new data byte is available, ignoring the SSPOV effect on
updating the buffer
0 I2C SSPxBUF is only updated when SSPOV is clear
Note:
1. For daisy-chained SPI operation; allows the user to ignore all except the last received byte. SSPOV is still set
when a new byte is received and BF = 1, but hardware continues to write the most recent byte to SSPxBUF.
0x00
... Reserved
0x018B
0x018C SSP1BUF 7:0 BUF[7:0]
0x018D SSP1ADD 7:0 ADD[7:0]
0x018E SSP1MSK 7:0 MSK[6:0] MSK0
0x018F SSP1STAT 7:0 SMP CKE D/A P S R/W UA BF
0x0190 SSP1CON1 7:0 WCOL SSPOV SSPEN CKP SSPM[3:0]
0x0191 SSP1CON2 7:0 GCEN ACKSTAT ACKDT ACKEN RCEN PEN RSEN SEN
0x0192 SSP1CON3 7:0 ACKTIM PCIE SCIE BOEN SDAHT SBCDE AHEN DHEN
2
ADCFVR[1:0]
1x To ADC module
2x as reference and
4x input channel
FVR Buffer 1
EN
+
_ RDY
Any peripheral
requiring Fixed
Reference
FVRCON
Name: FVRCON
Offset: 0x090C
Bit 7 6 5 4 3 2 1 0
FVREN FVRRDY ADFVR[1:0]
Access R/W R R/W R/W
Reset 0 0 0 0
Notes:
1. Fixed Voltage Reference output cannot exceed VDD.
2. FVRRDY is always ‘1’.
0x00
... Reserved
0x090B
0x090C FVRCON 7:0 FVREN FVRRDY ADFVR[1:0]
PREF[1:0]
FVR_buffer1 11 Positive
VREF+ pin Reference
10 Select
Reserved 01
00
V DD
V SS CS[2:0]
AN0
ANa VREF - VREF +
External .
Channel . FOSC/n Fosc
. Divider F OSC
Inputs ADC
ANz ADC_clk
sampled Clock
input Select
ADCRC
VSS
Internal
Channel ADC CLOCK SOURCE
Inputs
FVR_buffer1 ADC
Sample Circuit
CHS[5:0]
FM
set bit ADIF
complete 10
Write to bit 10-bit Result
GO/DONE
GO/DONE 16
start
ADRESH ADRESL
Enable
Trigger Select
TRIGSEL[3:0] ADON
. . . V SS
Trigger Sources
AUTO CONVERSION
TRIGGER
ADC Configuration
When configuring and using the ADC, the following functions must be considered:
• PORT Configuration
• Channel Selection
• ADC Voltage Reference Selection
• ADC Conversion Clock Source
• Interrupt Control
• Result Formatting
Port Configuration
The ADC will convert the voltage on a pin whether or not the ANSEL bit is set. When converting analog signals, the
I/O pin may be configured for analog by setting the associated TRIS and ANSEL bits. Refer to the “I/O Ports” section
for more information.
Important: Analog voltages on any pin that is defined as a digital input may cause the input buffer to
conduct excess current.
Channel Selection
The Analog Channel Select (CHS) bits determine which channel is connected to the Sample-and-Hold circuit for
conversion. When switching channels, it is recommended to add an acquisition delay before starting the next
conversion. Refer to the ADC Operation section for more information.
Important: To reduce the chance of measurement error, it is recommended to discharge the Sample-
and-Hold capacitor when switching between ADC channels by starting a conversion on a channel
connected to VSS and terminating the conversion after the acquisition time has elapsed. If the ADC does
not have a dedicated VSS input channel, a free input channel can be connected to VSS and used in place
of the dedicated input channel.
Conversion Clock
The conversion clock source is selected via the ADC Conversion Clock Select (CS) bits. The available clock sources
include several derivatives of the system clock (FOSC), as well as a dedicated internal fixed-frequency clock referred
to as the ADCRC.
The time to complete one bit conversion is defined as the TAD. Refer to Figure 27-2 for complete timing details of the
ADC conversion.
For a correct conversion, the appropriate TAD specification must be met. Refer to the ADC Timing Specifications
table in the “Electrical Specifications” section for more details. Table 27-1 gives examples of appropriate ADC clock
selections.
Important:
• With the exception of the ADCRC clock source, any changes in the system clock frequency will
change the ADC clock frequency, which may adversely affect the ADC result.
• The internal control logic of the ADC operates off of the clock selected by the CS bits. When the CS
bits select the ADCRC, there may be unexpected delays in operation when setting the ADC control
bits.
Table 27-1. ADC Clock Period (TAD) for Different Device Frequencies (FOSC)
ADC Clock ADC Clock Period (TAD) for Different Device Frequencies (FOSC)
CS[2:0]
Source 32 MHz 20 MHz 16 MHz 8 MHz 4 MHz 1 MHz
FOSC/2 ‘b000 62.5 ns(2) 100 ns(2) 125 ns(2) 250 ns(2) 500 ns 2.0 µs
FOSC/4 ‘b100 125 ns(2) 200 ns(2) 250 ns(2) 500 ns 1.0 µs 4.0 µs
...........continued
ADC Clock ADC Clock Period (TAD) for Different Device Frequencies (FOSC)
CS[2:0]
Source 32 MHz 20 MHz 16 MHz 8 MHz 4 MHz 1 MHz
FOSC/8 ‘b001 250 ns(2) 400 ns(2) 500 ns 1.0 µs 2.0 µs 8.0 µs
FOSC/16 ‘b101 500 ns 800 ns 1.0 µs 2.0 µs 4.0 µs 16.0 µs(2)
FOSC/32 ‘b010 1.0 µs 1.6 µs 2.0 µs 4.0 µs 8.0 µs 32.0 µs(2)
FOSC/64 ‘b110 2.0 µs 3.2 µs 4.0 µs 8.0 µs 16.0 µs(2) 64.0 µs(2)
ADCRC ‘bx11 1.0 - 6.0(1,3)
Notes:
1. Refer to the “Electrical Specifications” section to see the TAD parameter for the ADCRC source typical TAD
value.
2. These values violate the required TAD time.
3. The ADC clock period (TAD) and the total ADC conversion time can be minimized when the ADC clock is
derived from the system clock FOSC. However, the ADCRC oscillator source must be used when conversions
are to be performed with the device in Sleep mode.
1 – 1.5T AD
T AD1 T AD2 T AD3 T AD4 T AD5 T AD6 T AD7 T AD8 T AD9 T AD10 TAD11
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
T HCD
Conversion Starts
T ACQ On the following cycle:
Holding capacitor disconnected
from analog input (T HCD) ADRESH:ADRESL is loaded,
GO bit is cleared,
Set GO bit ADIF bit is set,
holding capacitor is reconnected to analog input.
Enable ADC (ON bit)
and
select channel (CS bits)
Interrupts
The ADC module allows for the ability to generate an interrupt upon completion of an analog-to-digital conversion.
The ADC Interrupt Flag (ADIF) bit is set upon the completion of each conversion. If the ADC Interrupt Enable (ADIE)
bit is set, an ADC interrupt event occurs. The ADIF bit must be cleared by software.
Important:
1. The ADIF bit is set at the completion of every conversion, regardless of whether or not the ADC
Interrupt is enabled.
2. The ADC operates in Sleep only when the ADCRC oscillator is selected as the clock source.
The ADC Interrupt can be generated while the device is operating or while in Sleep. While the device is operating in
Sleep mode:
• If ADIE = 1, PEIE = 1, and GIE = 0: An interrupt will wake the device from Sleep. Upon waking from Sleep, the
instructions following the SLEEP instruction are executed. The Interrupt Service Routine is not executed.
• If ADIE = 1, PEIE = 1, and GIE = 1: An interrupt will wake the device from Sleep. Upon waking from Sleep,
the instruction following the SLEEP instruction is always executed. Then the execution will switch to the Interrupt
Service Routine.
ADRESH ADRESL
Important: Writes to the ADRES register pair are always right-justified, regardless of the selected format
mode. Therefore, data read after writing to ADRES when FM = 0 will be shifted left four places.
ADC Operation
Starting a Conversion
To enable the ADC module, the ON bit must be set to ‘1’. A conversion may be started by either of the following:
• Software setting the GO bit to ‘1’
• An external trigger (source selected by the ADC Auto-Conversion Trigger (ADACT) register)
Important: The GO bit must not be set in the same instruction that turns on the ADC. Refer to
27.2.5. ADC Conversion Procedure for more details.
Completion of a Conversion
When the conversion is complete, the ADC module will:
• Clear the GO bit
Auto-Conversion Trigger
The auto-conversion trigger allows periodic ADC measurements without software intervention. When a rising edge of
the selected source occurs, the GO bit is set by hardware.
The auto-conversion trigger source is selected with the Auto-Conversion Trigger Select (ACT) bits.
Important: Using the auto-conversion trigger does not ensure proper ADC timing. It is the user’s
responsibility to ensure that the ADC timing requirements are met.
Notes:
1. With global interrupts disabled (GIE = 0), the device will wake from Sleep but will not enter an Interrupt Service
Routine.
2. Refer to 27.3. ADC Acquisition Requirements for more details.
BANKSEL TRISA
BSF TRISA,0 ; Set RA0 to input
BANKSEL ANSEL
BSF ANSEL,0 ; Set RA0 to analog
BANKSEL ADCON0
CLRF ADCON0
CLRF ADCON1
CLRF ADACT ; Auto-conversion disabled
BSF ADCON0,0 ; CHS = RA0, ADC ON
MOVLW B’11110000’ ; FM = Right-justified, CS = ADCRC, PREF = VDD
MOVWF ADCON1
CALL SampleTime ; Acquisition delay
BANKSEL ADCON0
BSF ADCON0,GO ; Start conversion
BTFSC ADCON0,GO ; Is conversion done?
GOTO $-1 ; No, test again
BANKSEL ADRESH
MOVF ADRESH,W ; Read upper byte
MOVWF RESULTHI ; Store in GPR space
MOVF ADRESL,W ; Read lower byte
MOVWF RESULTLO ; Store in GPR space
// Configure Port
TRISAbits.TRISA0 = 1; // Set RA0 to input
ANSELAbits.ANSELA0 = 1; // Set RA0 to analog
// Configure ADC
ADCON1bits.CS = 1; // ADCRC Clock
ADCON1bits.PREF = ‘b11; // VDD
ADCON0bits.CHS = ‘b000000; // RA0
ADCON1bits.FM = 1; // Right justify
ADCON0bits.ON = 1; // Turn ADC On
while (1) {
ADCON0bits.GO = 1; // Start conversion
while (ADCON0bits.GO); // Wait for conversion done
resultHigh = ADRESH; // Read result
resultLow = ADRESL; // Read result
}
}
1
VAPPLIED 1 − = VCHOLD ; [1] VCHOLD charged to within ½ lsb
2n + 1 − 1
−TC
VAPPLIED 1 − e RC = VCHOLD ; [2] VCHOLD charge response to VAPPLIED
−TC
VAPPLIED 1 − e RC = VAPPLIED 1 − 1 ; Combining [1] and [2]
n+1
2 −1
TC = 1.37 μs
Therefore:
Important:
• The reference voltage (VREF) has no effect on the equation, since it cancels itself out.
• The charge holding capacitor (CHOLD) is not discharged after each conversion.
• The maximum recommended impedance for analog sources is 10 kΩ. This is required to meet the pin
leakage specification.
Sampling
VDD
Switch
Analog
VT ≈ 0.6V SS
RS Input pin R IC ≤ 1 KΩ RSS
VSS Ref-
Rev. 30-000115A
5/16/2017
Full-Scale Range
3FFh
3FEh
3FDh
3FCh
ADC Output Code
3FBh
03h
02h
01h
00h
Analog Input Voltage
0.5 LSB 1.5 LSB
REF- Zero-Scale
Transition Full-Scale
Transition REF+
ADCON0
Name: ADCON0
Offset: 0x09D
Bit 7 6 5 4 3 2 1 0
CHS[5:0] GO ON
Access R/W R/W R/W R/W R/W R/W R/W/HS/HC R/W
Reset 0 0 0 0 0 0 0 0
ADCON1
Name: ADCON1
Offset: 0x09E
Bit 7 6 5 4 3 2 1 0
FM CS[2:0] PREF[1:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
ADACT
Name: ADACT
Offset: 0x09F
Bit 7 6 5 4 3 2 1 0
ACT[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
ADRES
Name: ADRES
Offset: 0x09B
Bit 15 14 13 12 11 10 9 8
ADRES[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
ADRES[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register names:
• ADRESH: Accesses the high byte ADRES[15:18]
• ADRESL: Accesses the low byte ADRES[7:0]
0x00
... Reserved
0x9A
7:0 ADRES[7:0]
0x9B ADRES
15:8 ADRES[15:8]
0x9D ADCON0 7:0 CHS[5:0] GO ON
0x9E ADCON1 7:0 FM CS[2:0] PREF[1:0]
0x9F ADACT 7:0 ACT[3:0]
Manually Enabled
The charge pump can be manually enabled via the Charge Pump Enable (CPON) bits. When the CPON bits are
configured as ‘11’, the charge pump is enabled. In this case, the charge pump provides additional voltage to all
analog systems, regardless of VDD levels, but also consumes additional current.
Automatically Enabled
The charge pump can also be enabled automatically. This allows the application to determine when to enable the
charge pump. If the charge pump is enabled while VDD levels are above a sufficient threshold, the charge pump
does not improve analog performance, but also consumes additional current. Allowing hardware to monitor V DD and
determine when to enable the charge pump prevents unnecessary current consumption.
When the CPON bits are configured as ‘10’, charge pump hardware monitors VDD and compares the VDD levels
to a reference voltage threshold (VAUTO), which is set to 4.096V. When hardware detects a VDD level lower than
the threshold, the charge pump is automatically enabled. If VDD returns to a level above the threshold, hardware
automatically disables the charge pump.
When the CPON bits are configured as ‘01’, charge pump hardware waits for an analog peripheral, such as the ADC,
to be enabled before monitoring VDD. In this case, charge pump hardware monitors all analog peripherals, and once
an analog peripheral is enabled, hardware begins to compare VDD to VAUTO. When hardware detects a VDD level
lower than the threshold, hardware enables the charge pump. If VDD returns to a level above the threshold, or if the
analog peripheral is disabled, the charge pump is automatically disabled.
Disabled
The charge pump is disabled by default (CPON = 00). Clearing the CPON bits will disable the charge pump.
28.6.1 CPCON
Name: CPCON
Offset: 0x009A
Bit 7 6 5 4 3 2 1 0
CPON[1:0] CPT CPRDY
Access R/W R/W R R
Reset 0 0 0 0
Bit 1 – CPT
Charge Pump Threshold
Value Description
1 VDD is above the charge pump auto-enable threshold (VAUTO)
0 VDD is below the charge pump auto-enable threshold (VAUTO)
Bit 0 – CPRDY
Charge Pump Ready Status
Value Description
1 Charge pump has reached a steady-state operation
0 Charge pump is Off or has not reached a steady-state operation
Read-Modify-Write Operations
Any instruction that specifies a file register as part of the instruction performs a Read-Modify-Write (RMW) operation.
The register is read, the data is modified, and the result is stored according to either the Working (W) register, or the
originating file register, depending on the state of the destination designator ‘d’ (see Table 29-1 for more information).
A read operation is performed on a register even if the instruction writes to that register.
Table 29-1. Opcode Field Descriptions
Field Description
f Register file address (0x00 to 0x7F)
W Working register (accumulator)
b Bit address within an 8-bit file register
k Literal field, constant data or label
“Don’t care” location (= 0 or 1).
x The assembler will generate code with x = 0.
It is the recommended form of use for compatibility with all Microchip software tools.
d Destination select; d = 0: store result in W, d = 1: store result in file register f.
n FSR or INDF number. (0-1)
mm Pre/post increment/decrement mode selection
Field Description
PC Program Counter
...........continued
Field Description
TO Time-Out bit
C Carry bit
DC Digit Carry bit
Z Zero bit
PD Power-Down bit
CLRF f Clear f 1 Z 2
00 0001 lfff ffff
COMF f, d Complement f 1 Z 2
00 1001 dfff ffff
DECF f, d Decrement f 1 Z 2
00 0011 dfff ffff
INCF f, d Increment f 1 Z 2
00 1010 dfff ffff
MOVF f, d Move f 1 Z 2
00 1000 dfff ffff
...........continued
Mnemonic, 14-Bit Opcode Status
Operands Description Cycles Affected Notes
MSb LSb
RRF f, d Rotate Right f through Carry 1 C 2
00 1100 dfff ffff
LITERAL OPERATIONS
ADDLW k Add literal and WREG 1 C, DC, Z
11 1110 kkkk kkkk
CONTROL OPERATIONS
...........continued
Mnemonic, 14-Bit Opcode Status
Operands Description Cycles Affected Notes
MSb LSb
BRA k Relative Branch 2 None
11 001k kkkk kkkk
INHERENT OPERATIONS
CLRWDT — Clear Watchdog Timer 1 TO, PD
00 0000 0110 0100
C-COMPILER OPTIMIZED
ADDFSR n, k Add Literal k to FSRn 1 None
11 0001 0nkk kkkk
Notes:
1. If the Program Counter (PC) is modified, or a conditional test is true, the instruction requires two cycles. The
second cycle is executed as a NOP.
2. If this instruction addresses an INDF register and the MSb of the corresponding FSR is set, this instruction will
require one additional instruction cycle.
3. Details on MOVIW and MOVWI instruction descriptions are available in the next section.
ADDWF Add W to f
Syntax: [ label ] ADDWF f, d
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
Operation: (W) + (f) → dest
Status Affected: C, DC, Z
Add the contents of the W register with register ‘f’. If ‘d’ is ‘0’, the result is stored in the W register.
Description:
If ‘d’ is ‘1’, the result is stored back in register ‘f’.
...........continued
ADDWFC Add W and Carry Bit to f
Add W, the Carry flag and data memory location ‘f’. If ‘d’ is ‘0’, the result is placed in W.
Description:
If ‘d’ is ‘1’, the result is placed in data memory location ‘f’.
(f[7]) → dest[7]
Operation: (f[7:1]) → dest[6:0]
(f[0]) → C
Status Affected: C, Z
The contents of register ‘f’ are shifted one bit to the right through the Carry flag.
The MSb remains unchanged.
Description: If ‘d’ is ‘0’, the result is placed in W.
If ‘d’ is ‘1’, the result is stored back in register ‘f’.
Register f → C
Operation: 0 → f[b]
Status Affected: None
...........continued
BCF Bit Clear f
Description: Bit ‘b’ in register ‘f’ is cleared.
Operation: (PC) + 1 + k → PC
Status None
Affected:
Add the signed 9-bit literal ‘k’ to the PC.
Since the PC will have incremented to fetch the next instruction, the new address will be PC + 1 +
Description:
k.
This instruction is a two-cycle instruction. This branch has a limited range.
Operation: 1 → (f[b])
Status Affected: None
Description: Bit ‘b’ in register ‘f’ is set.
...........continued
BTFSC Bit Test File, Skip If Clear
CLRF Clear f
Syntax: [ label ] CLRF f
Operands: 0 ≤ f ≤ 127
...........continued
CLRF Clear f
000h → f
Operation: 1→Z
Status Affected: Z
Description: The contents of register ‘f’ are cleared and the Z bit is set.
CLRW Clear W
Syntax: [ label ] CLRW
Operands: None
00h → (W)
Operation: 1→Z
Status Affected: Z
Description: W register is cleared. Zero (Z) bit is set.
1 → PD
Status Affected: TO, PD
The CLRWDT instruction resets the
Watchdog Timer.
Description:
It also resets the prescaler of the WDT.
Status bits, TO and PD, are set.
COMF Complement f
Syntax: [ label ] COMF f, d
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
DECF Decrement f
Syntax: [ label ] DECF f, d
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
...........continued
DECF Decrement f
Operation: (f) – 1 → dest
Status Affected: Z
Decrement register ‘f’.
Description: If ‘d’ is ‘0’, the result is stored in the W register.
If ‘d’ is ‘1’, the result is stored back in register ‘f’.
(f) – 1 → dest,
Operation:
skip if result = 0
INCF Increment f
Syntax: [ label ] INCF f, d
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
...........continued
INCFSZ Increment f, Skip If 0
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
(f) + 1 → dest,
Operation: skip if result = 0
(f[7]) → C
Operation: (f[6:0]) → dest[7:1]
0 → dest[0]
Status Affected: C, Z
...........continued
LSLF Logical Left Shift
The contents of register ‘f’ are shifted one bit to the left through the Carry flag.
A ‘0’ is shifted into the LSb.
Description: If ‘d’ is ‘0’, the result is placed in W.
If ‘d’ is ‘1’, the result is stored back in register ‘f’.
C ← Register f ← 0
Status Affected: C, Z
The contents of register ‘f’ are shifted one bit to the right through the Carry flag.
A ‘0’ is shifted into the MSb.
Description: If ‘d’ is ‘0’, the result is placed in W.
If ‘d’ is ‘1’, the result is stored back in register ‘f’.
0 → Register f → C
MOVF Move f
Syntax: [ label ] MOVF f, d
0 ≤ f ≤ 127
Operands:
d ∈ [0,1]
Operation: f → dest
Status Affected: Z
The contents of register f is moved to a destination dependent upon the status of d.
If d = 0, destination is W register.
Description:
If d = 1, the destination is file register f itself.
d = 1 is useful to test a file register since status flag Z is affected.
Words: 1
Cycles: 1
Example:
MOVF FSR, 0
After Instruction
W = value in FSR register
Z=1
n ∈ [0,1]
Operands: mm ∈ [00,01,10,11]
-32 ≤ k ≤ 31
INDFn → (W)
Effective address is determined by
• FSR + 1 (preincrement)
• FSR - 1 (predecrement)
Operation: • FSR + k (relative offset)
After the Move, the FSR value will be either:
• FSR + 1 (all increments)
• FSR - 1 (all decrements)
• Unchanged
Z
MODE SYNTAX mm
...........continued
MOVLP Move Literal to PCLATH
Operation: k → PCLATH
Status Affected: None
Description: The 7-bit literal ‘k’ is loaded into the PCLATH register.
Example:
MOVLW 5Ah
After Instruction
W = 5Ah
MOVWF Move W to f
Syntax: [ label ] MOVWF f
Operands: 0 ≤ f ≤ 127
Operation: (W) → f
Status Affected: None
Description: Move data from W to register ‘f’.
Words: 1
Cycles: 1
Example:
MOVWF LATA
Before Instruction
LATA = FFh
W = 4Fh
After Instruction
LATA = 4Fh
W = 4Fh
n ∈ [0,1]
Operands: mm ∈ [00,01,10,11]
-32 ≤ k ≤ 31
(W) → INDFn
Effective address is determined by
• FSR + 1 (preincrement)
• FSR - 1 (predecrement)
Operation: • FSR + k (relative offset)
After the Move, the FSR value will be either:
• FSR + 1 (all increments)
• FSR - 1 (all decrements)
• Unchanged
None
MODE SYNTAX mm
NOP No Operation
Syntax: [ label ] NOP
Operands: None
Operation: No operation
Status Affected: None
Description: No operation.
Words: 1
Cycles: 1
Example: NOP
None.
Example:
RETFIE
After Interrupt
PC = TOS
GIE = 1
Example:
CALL TABLE ; W contains table
; offset value
; W now has
; table value
:
TABLE
ADDWF PC ; W = offset
RETLW k1 ; Begin table
RETLW k2 ;
:
:
RETLW kn ; End of table
Before Instruction
W = 07h
After Instruction
W = value of k8
Status Affected: C
Encoding: 0011 01da ffff ffff
The contents of register ‘f’ are rotated one bit to the left through the Carry flag.
If ‘d’ is ‘0’, the result is placed in W.
Description: If ‘d’ is ‘1’, the result is stored back in register ‘f’ (default).
C register f
Words: 1
Cycles: 1
Example:
RLF REG1, 0
Before Instruction
REG1 = 1110 0110
C=0
After Instruction
REG = 1110 0110
W = 1100 1100
C=1
Status Affected: C
The contents of register ‘f’ are rotated one bit to the right through the Carry flag.
If ‘d’ is ‘0’, the result is placed in W.
Description: If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default).
C register f
0 → PD
Status Affected: TO, PD
The Power-Down (PD) Status bit is cleared.
Description: The Time-Out (TO) Status bit is set.
Watchdog Timer and its prescaler are cleared.
...........continued
SUBLW Subtract W from Literal
The W register is subtracted (two’s complement method) from the 8-bit literal ‘k’.
The result is placed in the W register.
C = 0, W > k
Description C = 1, W ≤ k
DC = 0, W[3:0] > k[3:0]
DC = 1, W[3:0] ≤ k[3:0]
(f[3:0]) → dest[7:4],
Operation: (f[7:4]) → dest[3:0]
...........continued
SWAPF Swap Nibbles in f
The upper and lower nibbles of register ‘f’ are exchanged.
Description: If ‘d’ is ‘0’, the result is placed in W.
If ‘d’ is ‘1’, the result is placed in register ‘f’ (default).
ICSPDAT
VDD 2 4 6 NC
ICSPCLK
13 5 Target
VPP/MCLR VSS PC Board
Bottom Side
Pin Description
1 = VPP/MCLR
2 = VDD Target
3 = VSS (ground)
4 = ICSPDAT
5 = ICSPCLK
6 = No Connect
Another connector often found in use with the PICkit ™ programmers is a standard 6-pin header with 0.1 inch spacing.
Refer to Figure 30-2.
For additional interface recommendations, refer to the specific device programmer manual prior to PCB design.
It is recommended that isolation devices be used to separate the programming pins from other circuitry. The type of
isolation is highly dependent on the specific application and may include devices such as resistors, diodes, or even
jumpers. See Figure 30-3 for more information.
Figure 30-2. PICkit™ Programmer Style Connector Interface
Pin 1 Indicator
1
2
3
4
5
6
Pin Description(1):
1 = VPP/MCLR
2 = VDD Target
3 = VSS (ground)
4 = ICSPDAT
5 = ICSPCLK
6 = No Connect
Note:
1. The 6-pin header (0.100" spacing) accepts 0.025" square pins.
Figure 30-3. Typical Connection for ICSP™ Programming
External
Programming VDD Device to be
Signals Programmed
VDD VDD
VPP MCLR/VPP
VSS VSS
Data ICSPDAT
Clock ICSPCLK
* * *
To Normal Connections
...........continued
...........continued
...........continued
...........continued
Offset Name Bit Pos. 7 6 5 4 3 2 1 0
0x1F51 SLRCONC 7:0 SLRC7 SLRC6 SLRC5 SLRC4 SLRC3 SLRC2 SLRC1 SLRC0
0x1F52 INLVLC 7:0 INLVLC7 INLVLC6 INLVLC5 INLVLC4 INLVLC3 INLVLC2 INLVLC1 INLVLC0
0x1F53 IOCCP 7:0 IOCCP7 IOCCP6 IOCCP5 IOCCP4 IOCCP3 IOCCP2 IOCCP1 IOCCP0
0x1F54 IOCCN 7:0 IOCCN7 IOCCN6 IOCCN5 IOCCN4 IOCCN3 IOCCN2 IOCCN1 IOCCN0
0x1F55 IOCCF 7:0 IOCCF7 IOCCF6 IOCCF5 IOCCF4 IOCCF3 IOCCF2 IOCCF1 IOCCF0
0x1F56
... Reserved
0x8004
7:0 MJRREV[1:0] MNRREV[5:0]
0x8005 REVISIONID
15:8 Reserved Reserved MJRREV[5:2]
7:0 DEV[7:0]
0x8006 DEVICEID
15:8 Reserved Reserved DEV[11:8]
7:0 RSTOSC[1:0] FEXTOSC[1:0]
0x8007 CONFIG1
15:8 VDDAR CLKOUTEN
7:0 BOREN[1:0] WDTE[1:0] PWRTS[1:0] MCLRE
0x8008 CONFIG2
15:8 DEBUG STVREN PPS1WAY BORV
7:0
0x8009 CONFIG3
15:8
7:0 WRTAPP SAFEN BBEN BBSIZE[2:0]
0x800A CONFIG4
15:8 LVP WRTSAF WRTC WRTB
7:0 CP
0x800B CONFIG5
15:8
Notes:
1. Maximum current rating requires even load distribution across I/O pins. Maximum current rating may be limited
by the device package power dissipation characterizations, see 32.3.6. Thermal Characteristics to calculate
device specifications.
2. Power dissipation is calculated as follows:
PDIS = VDD x {IDD - Σ IOH} + Σ {(VDD - VOH) x IOH} + Σ (VOI x IOL)
3. Internal Power Dissipation is calculated as follows:
PINTERNAL = IDD x VDD
where IDD is current to run the chip alone without driving any load on the output pins.
4. I/O Power Dissipation is calculated as follows:
PI/O = Σ(IOL*VOL)+Σ(IOH*(VDD-VOH))
5. Derated Power is calculated as follows:
PDER = PDMAX(TJ-TA)/θJA
where TA = Ambient Temperature, TJ = Junction Temperature.
Notice: Stresses above those listed under the Absolute Maximum Ratings section may cause permanent
CAUTION
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
above maximum rating conditions for extended periods may affect device reliability.
Parameter Condition
Operating Voltage: VDDMIN ≤ VDD ≤ VDDMAX
Operating Temperature: TAMIN ≤ TA ≤ TAMAX
Parameter Ratings
VDD — Operating Supply Voltage(1)
VDDMIN (FOSC ≤ 16 MHz) +1.8V
VDDMIN (FOSC ≤ 32 MHz) +2.5V
VDDMAX +5.5V
TA — Operating Ambient Temperature Range
TA_MIN -40°C
Industrial Temperature
TA_MAX +85°C
TA_MIN -40°C
Extended Temperature
TA_MAX +125°C
Note:
1. See Parameter D002, DC Characteristics: Supply Voltage.
5.5
VDD (V)
2.5
1.8
0 4 10 16 32
Frequency (MHz)
Notes:
1. The shaded region indicates the permissible combinations of voltage and frequency.
2. Refer to “External Clock/Oscillator Timing Requirements” section for each Oscillator mode’s supported
frequencies.
DC Characteristics
Supply Voltage
Table 32-1.
— — V Device in Sleep
D003 VDR 1.7
mode
Power-on Reset Release Voltage(2)
† - Data in “Typ.” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Notes:
1. This is the limit to which VDD can be lowered in Sleep mode without losing RAM data.
2. See the following figure: POR and POR REARM with Slow Rising VDD.
3. See “Reset, WDT, Power-up Timer, and Brown-Out Reset Specifications” for BOR trip point information.
Figure 32-2. POR and POR Rearm with Slow Rising VDD
V DD
V POR
V PORR
S VDD
V SS
NPOR(1)
POR REARM
V SS
Note:
1. When NPOR is low, the device is held in Reset.
Device Conditions
Param. No. Sym. Min. Typ.† Max. Units
Characteristics VDD Note
HFINTOSC = 16
D101 IDDHFO16 — 1.5 2.1 mA 3.0V
MHz
HFINTOSC = 32
D102 IDDHFOPLL — 2.7 3.6 mA 3.0V
MHz
† - Data in “Typ.” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Notes:
1. The test conditions for all IDD measurements in active operation mode are: all I/O pins are outputs driven low;
MCLR = VDD; WDT disabled.
2. The supply current is mainly a function of the operating voltage and frequency. Other factors, such as I/O
pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an
impact on the current consumption.
I/O Ports
Table 32-4.
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Device Characteristics Min. Typ.† Max. Units Conditions
Input Low Voltage
VIL I/O PORT:
D300 • with TTL buffer — — 0.8 V 4.5V ≤ VDD ≤ 5.5V
D301 — — 0.15 VDD V 1.8V ≤ VDD ≤ 4.5V
D302 • with Schmitt Trigger — — 0.2 VDD V 1.8V ≤ VDD ≤ 5.5V
buffer
D303 • with I2C levels — — 0.3 VDD V
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Device Characteristics Min. Typ.† Max. Units Conditions
VIH I/O PORT:
D320 • with TTL buffer 2.0 — — V 4.5V ≤ VDD ≤ 5.5V
D321 0.25 VDD+0.8 — — V 1.8V ≤ VDD ≤ 4.5V
D322 • with Schmitt Trigger 0.8VDD — — V 1.8V ≤ VDD ≤ 5.5V
buffer
D323 • with I2C levels 0.7 VDD — — V
...........continued
Standard Operating Conditions (unless otherwise stated)
Param Sym. Device Characteristics Min. Typ† Max. Units Conditions
No.
Programming Mode Specifications
MEM10 VBE VDD for Bulk Erase — 2.9 — V (Note 3)
MEM11 IDDPGM Supply Current during — — 10 mA
Programming operation
Program Flash Memory Specifications
MEM30 EP Flash Memory Cell Endurance -40°C ≤ TA ≤ +85°C
10k — — E/W (Note 1)
Thermal Characteristics
Table 32-6.
AC Characteristics
Figure 32-3. Load Conditions
Pin
CL = 50 pF
(for all pins)
VSS
OS2,
OS4,
OS6
CLKIN Q4 Q1 Q2 Q3 Q4 Q1
CLKOUT
OS21
Table 32-7.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
System Oscillator
OS20 FOSC System Clock — — 32 MHz Note 2, Note 3
Frequency
OS21 FCY Instruction — FOSC/4 — MHz
Frequency
OS22 TCY Instruction Period 125 1/FCY — ns Note 1
* These parameters are characterized but not tested.
† - Data in “Typ” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Notes:
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 CLKIN pin. When an external clock input is used, the “max” cycle time limit is “DC” (no clock)
for all devices.
2. The system clock frequency (FOSC) is selected by the “main clock switch controls” as described in the “OSC -
Oscillator Module” chapter.
3. The system clock frequency (FOSC) must meet the voltage requirements defined in the “Standard Operating
Conditions” section.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
OS56 TLFOSCST LFINTOSC Wake-up — 0.2 1 ms
from Sleep Start-up
Time
† - Data in “Typ” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only
and are not tested.
Notes:
1. To ensure these oscillator frequency tolerances, VDD and VSS must be capacitively decoupled as close to the
device as possible. 0.1 μF and 0.01 μF values in parallel are recommended.
2. See Figure 32-5.
Figure 32-5. Precision Calibrated HFINTOSC Frequency Accuracy Over Device VDD and Temperature
125
± 5%
85
± 3%
Temperature (°C)
60
± 2%
0
± 5%
-40
1.8 2.0 2.3 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FOSC
IO1
IO2
CLKOUT IO5
V DD
MCLR
RST01
Internal
POR
RST04
PWRT
Time-out
Internal
Reset(1)
WDT RST03
Reset RST02
RST02
I/O Pins
Note:
1. Asserted low.
Figure 32-8. Brown-out Reset Timing and Characteristics
Rev. 30-000076A
4/6/2017
VDD
VBOR and VHYST
VBOR
RST08
Reset
RST04(1)
(due to BOR)
Note:
1. Only if PWRTE bit in the Configuration Word register is programmed to ‘1’; 2 ms delay if PWRTE = 0.
Table 32-10.
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
RST01* TMCLR MCLR Pulse Width Low to 2 — — μs
ensure Reset
RST02* TIOZ I/O high-impedance from — — 2 μs
Reset detection
RST03 TWDT Watchdog Timer Time-out — 16 — ms 1:512 Prescaler
Period
RST04* TPWRT Power-up Timer Period — 65 — ms PWRTS = ‘10’ (64 ms)
RST06 VBOR Brown-out Reset Voltage 2.4 2.8 3.0 V BORV = 0
V
1.8 1.9 2.0(1) BORV = 1
RST07 VBORHYS Brown-out Reset Hysteresis — 40 — mV
RST08 TBORDC Brown-out Reset Response — 3 — μs
Time
* - These parameters are characterized but not tested.
† Data in “Typ” column is at 3.0V, 25°C unless otherwise stated. These parameters are for design guidance only and
are not tested.
Note:
1. This value corresponds to VBORMAX.
...........continued
Standard Operating Conditions (unless otherwise stated)
VDD = 3.0V, TA = 25°C
BSF ADCON0, GO
1 TCY
AD22
1 TCY
AD20
ADC_clk
ADIF
AD24
GO DONE
BSF ADCON0, GO
1 TCY
AD22
AD21
2 TCY(1)
ADC_clk
ADIF
AD24
GO DONE
Note:
1. If the ADC clock source is selected as FRC, a time of TCY is added before the ADC clock starts. This allows the
SLEEP instruction to be executed.
...........continued
Standard Operating Conditions (unless otherwise stated)
Operating Temperature: -40°C ≤ TA ≤ +125°C
T0CKI
40 41
42
T1CKI
45 46
47 49
TMR0 or
TMR1
CCPx
(Capture mode)
CC01 CC02
CC03
Note: Refer to Figure 32-3 for load conditions.
US121 TCKRF Clock out rise time and fall time — 45 ns 3.0V ≤ VDD ≤ 5.5V
(Host mode) — 50 ns 1.8V ≤ VDD ≤ 5.5V
US122 TDTRF Data-out rise time and fall time — 45 ns 3.0V ≤ VDD ≤ 5.5V
— 50 ns 1.8V ≤ VDD ≤ 5.5V
CK
US121 US121
DT
US120 US122
CK
US125
DT
US126
...........continued
Standard Operating Conditions (unless otherwise stated)
Param No. Sym. Characteristic Min. Typ. † Max. Units Conditions
SP75* TDOR SDO data output rise time — 25 50 ns 1.8V ≤ VDD ≤
5.5V
SP76* TDOF SDO data output fall time — 10 25 ns
SP77* TSSH2DOZ SS↑ to SDO output high- 10 — 50 ns
impedance
SP78* TSCR SCK output rise time (Host — 25 50 ns 1.8V ≤ VDD ≤
mode) 5.5V
SP79* TSCF SCK output fall time (Host — 10 25 ns
mode)
SP80* TSCH2DOV, SDO data output valid after — — 145 ns 1.8V ≤ VDD ≤
SCK edge 5.5V
TSCL2DOV
SS
SP81
SCK
(CKP = 0)
SP71 SP72
SP78 SP79
SCK
(CKP = 1)
SP79 SP78
SP80
SP75, SP76
SP74
SP73
SS
SP81
SCK
(CKP = 0)
SP71 SP72
SP79
SP73
SCK
(CKP = 1)
SP80
SP78
SP75, SP76
SP74
Note: Refer to Figure 32-3 for load conditions.
SS
SP70
SCK
SP83
(CKP = 0)
SP71 SP72
SP78 SP79
SCK
(CKP = 1)
SP79 SP78
SP80
SDO MSb bit 6 ----------- 1 LSb
SP74
SP73
SS SP82
SP70
SCK SP83
(CKP = 0)
SP71 SP72
SCK
(CKP = 1)
SP80
SP77
SP75, SP76
SDI
MSb In bit 6--------1 LSb In
SP74
SP91* THD:STA Start condition 100 kHz mode 4000 — — ns After this period, the first clock
pulse is generated
Hold time 400 kHz mode 600 — —
SCL
SP91 SP93
SP90 SP92
SDA
Start Stop
Condition Condition
Note: Refer to Figure 32-3 for load conditions.
...........continued
Standard Operating Conditions (unless otherwise stated)
Param. No. Sym. Characteristic Min. Max. Units Conditions
SP101* TLOW Clock low 100 kHz 4.7 — μs Device must
time mode operate at a
minimum of 1.5
MHz
400 kHz 1.3 — μs Device must
mode operate at a
minimum of 10
MHz
SSP module 1.5TCY —
SP102* TR SDA and 100 kHz — 1000 ns
SCL rise mode
time
400 kHz 20 + 0.1CB 300 ns CB is specified to
mode be from 10-400 pF
SP103* TF SDA and 100 kHz — 250 ns
SCL fall time mode
400 kHz 20 + 0.1CB 250 ns CB is specified to
mode be from 10-400 pF
SP106* THD:DAT Data input 100 kHz 0 — ns
hold time mode
400 kHz 0 0.9 μs
mode
SP107* TSU:DAT Data input 100 kHz 250 — ns Note 2
setup time mode
400 kHz 100 — ns
mode
SP109* TAA Output valid 100 kHz — 3500 ns Note 1
from clock mode
400 kHz — — ns
mode
SP110* TBUF Bus free time 100 kHz 4.7 — μs Time the bus must
mode be free before a
new transmission
400 kHz 1.3 — μs can start
mode
SP111 CB Bus capacitive loading — 400 pF
* - These parameters are characterized but not tested.
Notes:
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 (400 kHz) I2C bus device can be used in a Standard mode (100 kHz) I 2C bus system, but the
requirement TSU:DAT ≥ 250 ns must then be met. This will automatically be the case if the device does not
stretch the low period of the SCL signal. If such a device does stretch the low period of the SCL signal, it
must output the next data bit to the SDA line TR max. + TSU:DAT = 1000 + 250 = 1250 ns (according to the
Standard mode I2C bus specification), before the SCL line is released.
SCL
SP90
SP106
SP107
SP91 SP92
SDA
In
SP110
SP109
SP109
SDA
Out
Figure 33-3. ADC, DNL, VDD = 3.0V, TAD = 8 μs Figure 33-4. ADC, INL, VDD = 3.0V, TAD = 1 μs
Figure 33-5. ADC, INL, VDD = 3.0V, TAD = 4 μs Figure 33-6. ADC, INL, VDD = 3.0V, TAD = 8 μs
65
60
55
50
45
40
Time[us]
35
30
25
20
15
10
5
0
2 2.5 3 3.5 4 4.5 5 5.5
VDD[V]
Figure 33-8. BROWN-OUT RESET VOLTAGE, TRIP Figure 33-9. BROWN-OUT RESET HYSTERESIS,
POINT (BORV = 0) TRIP POINT (BORV = 0)
40
2.925
2.9 35
2.875
30
VDD[mV]
VDD[V]
2.85
25
2.825
20
2.8
2.775 15
-50 0 50 100 -50 0 50 100
Temperature[°C] Temperature[°C]
- 3σ Mean + 3σ - 3σ Mean + 3σ
Figure 33-10. BROWN-OUT RESET VOLTAGE, TRIP Figure 33-11. BROWN-OUT RESET HYSTERESIS,
POINT (BORV = 1) TRIP POINT (BORV = 1)
1.96
40
1.94
35
1.92
VDD[mV]
VDD[V]
30
1.9
25
1.88
1.86 20
Temperature[°C] Temperature[°C]
- 3σ Mean + 3σ - 3σ Mean + 3σ
4
Time [us]
1
2.5 3 3.5 4 4.5 5 5.5
VDD [V]
Figure 33-13. FVR Voltage Error 1x (VDD = 5.5 V) Figure 33-14. FVR Voltage Error 2x (VDD = 5.5 V)
0.2
0.2
0.1
0.0
0.0
Error[%]
Error[%]
-0.2
-0.1
-0.4 -0.2
-0.3
-0.6
2.5 3.0 3.5 4.0 4.5 5.0 5.5 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD[V] VDD[V]
125°C Mean 25°C Mean -40°C Mean 85°C Mean 125°C Mean 25°C Mean -40°C Mean 85°C Mean
1.2
0.9
0.6
0.3
Error[%]
0.0
-0.3
-0.6
-0.9
VDD[V]
Figure 33-16. HFINTOSC Error % over VDD Figure 33-17. HFINTOSC Error % over Temperature,
VDD = 3V
2.0
1.5 2.0
1.5
1.0
1.0
0.5
0.5
Error[%]
0.0
0.0
Error[%]
-0.5 -0.5
-1.0 -1.0
-1.5
-1.5
-2.0
-2.0
-2.5
2 2.5 3 3.5 4 4.5 5 5.5
-3.0
VDD[V] -50 0 50 100
- 3σ Mean + 3σ
30
28
26
Time[us]
24
22
20
18
VDD[V]
Figure 33-19. Rise Time, Slew Rate Control enabled Figure 33-20. Fall Time, Slew Rate Control enabled
55
50 50
45
40
40
Time [ns]
Time [ns]
35 30
30
25 20
20
10
15
10 0
2 2.5 3 3.5 4 4.5 5 5.5 2 2.5 3 3.5 4 4.5 5 5.5
Figure 33-21. Rise Time, Slew Rate Control disabled Figure 33-22. Fall Time, Slew Rate Control disabled
25
20
20
15
15
Time [ns]
Time [ns]
10 10
5 5
0 0
2 2.5 3 3.5 4 4.5 5 5.5 2 2.5 3 3.5 4 4.5 5 5.5
IDD Graphs
Figure 33-23. IDD, HFINTOSC, FHFO = 16 MHz Figure 33-24. IDD HFINTOSC, FHFO = 32 MHz
3.0 6.0
2.5 5.0
2.0 4.0
IDD[mA]
IDD[mA]
1.5 3.0
1.0 2.0
0.5 1.0
0.0 0.0
2 2.5 3 3.5 4 4.5 5 5.5 2 2.5 3 3.5 4 4.5 5 5.5
VDD[V] VDD[V]
Figure 33-25. Schmitt Trigger High Values Figure 33-26. Schmitt Trigger Low Values
3.5
2.0
3
2.5 1.5
Voltage[V]
VIL[V]
2
1.0
1.5
0.5
1
500m 0.0
2 2.5 3 3.5 4 4.5 5 5.5 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD[V] VDD[V]
-40 to 125°C - 3σ 25°C Mean -40 to 125°C + 3σ -40 to 125°C + 3σ 25°C Mean------------------ 40 to 125°C - 3σ
1.8
1.6
1.4
Voltage[V]
1.2
1.0
0.8
0.6
VDD[V]
IPD Graphs
Figure 33-28. IPD BASE Figure 33-29. IPD, BROWN-OUT RESET (BOR)
34.0
800
33.0
700
32.0
600
31.0
500 30.0
Current[nA]
Current[uA]
400 29.0
28.0
300
27.0
200
26.0
100 25.0
0 24.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
Figure 33-30. IPD, FIXED VOLTAGE REFERENCE Figure 33-31. IPD, WATCH DOG TIMER (WDT)
(FVR)
2.0
48
1.5
46
Current[uA]
44
1.0
Current[uA]
42
0.5
40
38
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
36
2.5 3.0 3.5 4.0 4.5 5.0 5.5 VDD [V]
LFINTOSC Graphs
35.0
34.0
33.0
32.0
Frequency[kHz]
31.0
30.0
29.0
28.0
27.0
26.0
25.0
2 2.5 3 3.5 4 4.5 5 5.5
VDD[V]
OSCTUNE Graphs
15
10
5
Error[%]
-5
-10
-15
-30 -20 -10 0 10 20 30
OSCTUNE Setting
Figure 33-36. VOH vs. IOH OVER TEMPERATURE, VDD Figure 33-37. VOH vs. IOH OVER TEMPERATURE, VDD
= 5.5V = 3V
6.0 3.5
3.0
5.5
2.5
5.0
2.0
VOH[V]
VOH[V]
4.5
1.5
4.0
1.0
3.5
0.5
3.0 0.0
-50 -40 -30 -20 -10 0 -35 -30 -25 -20 -15 -10 -5 0
IOH[mA] IOH[mA]
Figure 33-38. VOL vs. IOL OVER TEMPERATURE, VDD Figure 33-39. VOL vs. IOL OVER TEMPERATURE, VDD
= 5.5V = 3V
2.5 1.5
2.0
1.0
1.5
VOL[V]
VDD[V]
1.0
0.5
0.5
0.0 0.0
0 20 40 60 80 100 0 10 20 30 40 50 60 70
IOL[mA] IOL[mA]
4.35
4.3
Time [ms]
4.25
4.2
4.15
VDD [V]
250
200
Current[uA]
150
100
50
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD[V]
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.
XXXXXXXX 16F15214
XXXXXNNN P e3 017
YYWW 2115
XXXX MGL0
YYWW 2115
NNN 017
PIN 1 PIN 1
16F15214
SN e3 2115
NNN 017
XXXXXXXX 16F15224
YYWW 2115 e3
NNN 017
PIC16F15224
/SL e3
2115017
PIC16F15224
/P e3
2115017
XXXXXXXXXXXXXXXXX PIC16F15244
XXXXXXXXXXXXXXXXX /P e3
YYWWNNN 2115017
PIC16F15244
/SS e3
2115017
PIC16F15244
/SO e3
2115017
Package Details
The following sections give the technical details of the packages.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A
N B
E1
NOTE 1
1 2
TOP VIEW
A A2
C
PLANE
L c
A1
e eB
8X b1
8X b
.010 C
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
DATUM A DATUM A
b b
e e
2 2
e e
Units INCHES
Dimension Limits MIN NOM MAX
Number of Pins N 8
Pitch e .100 BSC
Top to Seating Plane A - - .210
Molded Package Thickness A2 .115 .130 .195
Base to Seating Plane A1 .015 - -
Shoulder to Shoulder Width E .290 .310 .325
Molded Package Width E1 .240 .250 .280
Overall Length D .348 .365 .400
Tip to Seating Plane L .115 .130 .150
Lead Thickness c .008 .010 .015
Upper Lead Width b1 .040 .060 .070
Lower Lead Width b .014 .018 .022
Overall Row Spacing § eB - - .430
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or
protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
5. Lead design above seating plane may vary, based on assembly vendor.
8-Lead Plastic Small Outline (SN) - Narrow, 3.90 mm (.150 In.) Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
2X
0.10 C A–B
D
A D
NOTE 5
N
E
2
E1
2
E1 E
2X
0.10 C A–B
2X
0.10 C A–B
NOTE 1 1 2
e NX b
B 0.25 C A–B D
NOTE 5
TOP VIEW
0.10 C
C A A2
SEATING
PLANE 8X
0.10 C
A1 SIDE VIEW
4X θ 1
θ2
h
R1
h
R
H c
L θ
SEE VIEW C
(L1)
VIEW A–A 4X θ 1
VIEW C
8- Lead Plastic Small Outline (SN) - Narrow, 3.90 mm (.150 In.) Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Pins N 8
Pitch e 1.27 BSC
Overall Height A – – 1.75
Molded Package Thickness A2 1.25 – -
Standoff § A1 0.10 – 0.25
Overall Width E 6.00 BSC
Molded Package Width E1 3.90 BSC
Overall Length D 4.90 BSC
Chamfer (Optional) h 0.25 – 0.50
Foot Length L 0.40 – 1.27
Footprint L1 1.04 REF
Lead Thickness c 0.17 – 0.25
Lead Width b 0.31 – 0.51
Lead Bend Radius R 0.07 – –
Lead Bend Radius R1 0.07 – –
Foot Angle θ 0° – 8°
Mold Draft Angle θ1 5° – 15°
Lead Angle θ2 0° – 8°
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or
protrusions shall not exceed 0.15mm per side.
4. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
5. Datums A & B to be determined at Datum H.
8- Lead Plastic Small Outline (SN) - Narrow, 3.90 mm (.150 In.) Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
SI LK SCREEN
Y1
X1
E
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Contact Pitch E 1.27 BSC
Contact Pad Spacing C 5.40
Contact Pad Width (X8) X1 0.60
Contact Pad Length (X8) Y1 1.55
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
NOTE 1
E1
1 2 3
A A2
L c
A1
b1
b e eB
Units INCHES
Dimension Limits MIN NOM MAX
Number of Pins N 14
Pitch e .100 BSC
Top to Seating Plane A – – .210
Molded Package Thickness A2 .115 .130 .195
Base to Seating Plane A1 .015 – –
Shoulder to Shoulder Width E .290 .310 .325
Molded Package Width E1 .240 .250 .280
Overall Length D .735 .750 .775
Tip to Seating Plane L .115 .130 .150
Lead Thickness c .008 .010 .015
Upper Lead Width b1 .045 .060 .070
Lower Lead Width b .014 .018 .022
Overall Row Spacing § eB – – .430
Notes:
1. Pin 1 visual index feature may vary, but must be located with the hatched area.
2. § Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
2X
0.10 C A–B
D
A NOTE 5
D
N
E
2
E2
2
E1 E
2X
0.10 C D
2X N/2 TIPS
NOTE 1 1 2 3 0.20 C
e NX b
B NOTE 5 0.25 C A–B D
TOP VIEW
0.10 C
C A A2
SEATING
PLANE 14X
A1 SIDE VIEW 0.10 C
h
h
H R0.13
R0.13
SEE VIEW C
L
VIEW A–A (L1)
VIEW C
Microchip Technology Drawing No. C04-065-SL Rev D Sheet 1 of 2
14- Lead Plastic Small Outline (SL) - Narrow, 3.90 mm Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Pins N 14
Pitch e 1.27 BSC
Overall Height A - - 1.75
Molded Package Thickness A2 1.25 - -
Standoff § A1 0.10 - 0.25
Overall Width E 6.00 BSC
Molded Package Width E1 3.90 BSC
Overall Length D 8.65 BSC
Chamfer (Optional) h 0.25 - 0.50
Foot Length L 0.40 - 1.27
Footprint L1 1.04 REF
Lead Angle 0° - -
Foot Angle 0° - 8°
Lead Thickness c 0.10 - 0.25
Lead Width b 0.31 - 0.51
Mold Draft Angle Top 5° - 15°
Mold Draft Angle Bottom 5° - 15°
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic
3. Dimension D does not include mold flash, protrusions or gate burrs, which shall
not exceed 0.15 mm per end. Dimension E1 does not include interlead flash
or protrusion, which shall not exceed 0.25 mm per side.
4. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
5. Datums A & B to be determined at Datum H.
14- Lead Plastic Small Outline (SL) - Narrow, 3.90 mm Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
14
SILK SCREEN
1 2
X
E
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Contact Pitch E 1.27 BSC
Contact Pad Spacing C 5.40
Contact Pad Width (X14) X 0.60
Contact Pad Length (X14) Y 1.55
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
14-Lead Thin Shrink Small Outline Package [ST] – 4.4 mm Body [TSSOP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A B
N
E
2
E1
2
E1 E
2X 7 TIPS
1 2 0.20 C B A
e
TOP VIEW
A
C A2 A
SEATING
PLANE
14X A1
14X b A
0.10 C 0.10 C B A
SIDE VIEW
SEE DETAIL B
VIEW A–A
14- Lead Thin Shrink Small Outline Package [ST] – 4.4 mm Body [TSSOP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
(θ2)
R1
H
R2
L θ1
(L1)
(θ3)
DETAIL B
Units MILLIMETERS
Dim ension Limits MIN NOM MAX
Number of Terminals N 14
Pitch e 0.65 BSC
Overall Height A – – 1.20
Standoff A1 0.05 – 0.15
Molded Package Thickness A2 0.80 1.00 1.05
Overall Length D 4.90 5.00 5.10
Overall Width E 6.40 BSC
Molded Package Width E1 4.30 4.40 4.50
Terminal Width b 0.19 – 0.30
Terminal Thickness c 0.09 – 0.20
Terminal Length L 0.45 0.60 0.75
Footprint L1 1.00 REF
Lead Bend Radius R1 0.09 – –
Lead Bend Radius R2 0.09 – –
Foot Angle θ1 0° – 8°
Mold Draft Angle θ2 – 12° REF –
Mold Draft Angle θ3 – 12° REF –
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Dim ensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for inform ation purposes only.
14- Lead Thin Shrink Small Outline Package [ST] – 4.4 mm Body [TSSOP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
SILK SCREEN
X
E
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
NOTE 1 E1
1 2 3
A A2
L
c
A1
b1
b e eB
Units INCHES
Dimension Limits MIN NOM MAX
Number of Pins N 20
Pitch e .100 BSC
Top to Seating Plane A – – .210
Molded Package Thickness A2 .115 .130 .195
Base to Seating Plane A1 .015 – –
Shoulder to Shoulder Width E .300 .310 .325
Molded Package Width E1 .240 .250 .280
Overall Length D .980 1.030 1.060
Tip to Seating Plane L .115 .130 .150
Lead Thickness c .008 .010 .015
Upper Lead Width b1 .045 .060 .070
Lower Lead Width b .014 .018 .022
Overall Row Spacing § eB – – .430
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. § Significant Characteristic.
3. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed .010" per side.
4. Dimensioning and tolerancing per ASME Y14.5M.
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D
A
E
2
E1
2
E1 E
2X 10 TIPS
NOTE 1 0.33 C
B 20X b
e 0.25 C A-B D
TOP VIEW
0.10 C A
A2 A C
SEATING
PLANE
A1 20X A
SIDE VIEW 0.10 C
h
SEE DETAIL B
VIEW A–A
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
θ2
θ1
R2
H R1
θ3 θ
L
(L1)
DETAIL B
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Terminals N 20
Pitch e 1.27 BSC
Overall Height A - - 2.65
Standoff § A1 0.10 - 0.30
Molded Package Thickness A2 2.05 - -
Overall Length D 12.80 BSC
Overall Width E 10.30 BSC
Molded Package Width E1 7.50 BSC
Terminal Width b 0.31 - 0.51
Terminal Thickness c 0.25 - 0.75
Corner Chamfer h 0.25 - 0.75
Terminal Length L 0.40 0.65 1.27
Footprint L1 1.40 REF
Lead Bend Radius R1 0.07 - -
Lead Bend Radius R2 0.07 - -
Foot Angle θ 0° - 8°
Lead Angle θ1 0° - -
Mold Draft Angle θ2 5° - 15°
Mold Draft Angle θ3 5° - 15°
Notes:
1. Pin 1 visual index feature m ay vary, but must be located within the hatched area.
2. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
3. Dimension D does not include mold flash, protrusions or gate burrs, which shall
not exceed 0.15 mm per end. Dimension E1 does not include interlead flash
or protrusion, which shall not exceed 0.25 mm per side.
4. § Significant Characteristic
20- Lead Plastic Small Outline (SO) - Wide, 7.50 mm Body [SOIC]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
G1
20
SILK SCREEN
C G
1 2
X
E
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Contact Pitch E 1.27 BSC
Contact Pad Spacing C 9.40
Contact Pad Width (X20) X 0.60
Contact Pad Length (X20) Y 1.95
Contact Pad to Contact Pad G 0.67
Contact Pad to Contact Pad G1 7.45
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
2. For best soldering results, thermal vias, if used, should be filled or tented to avoid solder loss during
reflow process
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
D A B
N
(DATUM A)
(DATUM B)
E1 E
1 2
20X b
e 0.15 C A B
TOP VIEW
A
A1
C A A2
SEATING
PLANE 20X
0.10 C A
SIDE VIEW
c
L
(L1)
VIEW A-A
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Pins N 20
Pitch e 0.65 BSC
Overall Height A - - 2.00
Molded Package Thickness A2 1.65 1.75 1.85
Standoff A1 0.05 - -
Overall Width E 7.40 7.80 8.20
Molded Package Width E1 5.00 5.30 5.60
Overall Length D 6.90 7.20 7.50
Foot Length L 0.55 0.75 0.95
Footprint L1 1.25 REF
Lead Thickness c 0.09 - 0.25
Foot Angle 0° 4° 8°
Lead Width b 0.22 - 0.38
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Dimensions D and E1 do not include mold flash or protrusions. Mold flash or
protrusions shall not exceed 0.20mm per side.
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
20- Lead Plastic Shrink Small Outline (SS) - 5.30 mm Body [SSOP]
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
G1
20
C
SILK SCREEN
Y1
1 2
X1
E
Notes:
1. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
2. For best soldering results, therm al vias, if used, should be filled or tented to avoid solder loss during
reflow process
20-Lead Very Thin Plastic Quad Flat, No Lead Package (REB) - 3x3 mm Body [VQFN]
With 1.7 mm Exposed Pad; Atmel Legacy Global Package Code ZCL
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
0.08 C
16X
0.10 C
D A B
NOTE 1
N
E
(DATUM B)
(DATUM A)
2X
0.10 C
2X
A1
0.10 C TOP VIEW
(A3)
0.10 C A B
D2 A
SEATING
C
PLANE
SIDE VIEW
0.10 C A B
E2
2
(CH)
1
NOTE 1 K
N
L 20X b
e 0.10 C A B
0.05 C
BOTTOM VIEW
Microchip Technology Drawing C04-21380 Rev A Sheet 1 of 2
20- Lead Very Thin Plastic Quad Flat, No Lead Package (REB) - 3x3 mm Body [VQFN]
With 1.7 mm Exposed Pad; Atmel Legacy Global Package Code ZCL
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
Units MILLIMETERS
Dimension Limits MIN NOM MAX
Number of Terminals N 20
Pitch e 0.40 BSC
Overall Height A 0.80 0.85 0.90
Standoff A1 0.00 0.035 0.05
Terminal Thickness A3 0.203 REF
Overall Length D 3.00 BSC
Exposed Pad Length D2 1.60 1.70 1.80
Overall Width E 3.00 BSC
Exposed Pad Width E2 1.60 1.70 1.80
Terminal Width b 0.15 0.20 0.25
Terminal Length L 0.35 0.40 0.45
Terminal-to-Exposed-Pad K 0.20 - -
Pin 1 Index Chamfer CH 0.35 REF
Notes:
1. Pin 1 visual index feature may vary, but must be located within the hatched area.
2. Package is saw singulated
3. Dimensioning and tolerancing per ASME Y14.5M
BSC: Basic Dimension. Theoretically exact value shown without tolerances.
REF: Reference Dimension, usually without tolerance, for information purposes only.
20- Lead Very Thin Plastic Quad Flat, No Lead Package (REB) - 3x3 mm Body [VQFN]
With 1.7 mm Exposed Pad; Atmel Legacy Global Package Code ZCL
Note: For the most current package drawings, please see the Microchip Packaging Specification located at
http://www.microchip.com/packaging
C1
X2
EV
ØV
G2
C2 Y2 EV
G1
Y1
X1
SILK SCREEN E
Customer Support
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Embedded Solutions Engineer (ESE)
• Technical Support
Customers should contact their distributor, representative or ESE for support. Local sales offices are also available to
help customers. A listing of sales offices and locations is included in this document.
Technical support is available through the website at: www.microchip.com/support
Examples:
• PIC16F15213 T-E/P: Tape and Reel, Extended temperature, 8-lead PDIP
• PIC16F15244 T-I/SS: Tape and Reel, Industrial temperature, 20-lead SSOP
Notes:
1. Tape and Reel identifier only appears in the catalog part number description. This identifier is used for ordering
purposes and is not printed on the device package. Check with your Microchip Sales Office for package
availability with the Tape and Reel option.
2. Small form-factor packaging options may be available. Please check www.microchip.com/packaging for small-
form factor package availability, or contact your local Sales Office.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of its code. Code
protection does not mean that we are guaranteeing the product is “unbreakable”. Code protection is constantly
evolving. Microchip is committed to continuously improving the code protection features of our products.
Legal Notice
This publication and the information herein may be used only with Microchip products, including to design, test,
and integrate Microchip products with your application. Use of this information in any other manner violates these
terms. Information regarding device applications is provided only for your convenience and may be superseded
by updates. It is your responsibility to ensure that your application meets with your specifications. Contact your
local Microchip sales office for additional support or, obtain additional support at www.microchip.com/en-us/support/
design-help/client-support-services.
THIS INFORMATION IS PROVIDED BY MICROCHIP "AS IS". MICROCHIP MAKES NO REPRESENTATIONS
OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY
OR OTHERWISE, RELATED TO THE INFORMATION INCLUDING BUT NOT LIMITED TO ANY IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE,
OR WARRANTIES RELATED TO ITS CONDITION, QUALITY, OR PERFORMANCE.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR
CONSEQUENTIAL LOSS, DAMAGE, COST, OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
INFORMATION OR ITS USE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW,
MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THE INFORMATION OR ITS USE
WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
THE INFORMATION.
Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees
to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting
from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights
unless otherwise stated.
Trademarks
The Microchip name and logo, the Microchip logo, Adaptec, AnyRate, AVR, AVR logo, AVR Freaks, BesTime,
BitCloud, CryptoMemory, CryptoRF, dsPIC, flexPWR, HELDO, IGLOO, JukeBlox, KeeLoq, Kleer, LANCheck,
LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi, Microsemi logo, MOST, MOST logo, MPLAB,
OptoLyzer, PIC, picoPower, PICSTART, PIC32 logo, PolarFire, Prochip Designer, QTouch, SAM-BA, SenGenuity,
SpyNIC, SST, SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon, TimeSource, tinyAVR, UNI/O, Vectron,
and XMEGA are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
AgileSwitch, APT, ClockWorks, The Embedded Control Solutions Company, EtherSynch, Flashtec, Hyper Speed
Control, HyperLight Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3, Precision Edge, ProASIC, ProASIC
Plus, ProASIC Plus logo, Quiet- Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub, TimePictra,
TimeProvider, TrueTime, WinPath, and ZL are registered trademarks of Microchip Technology Incorporated in the
U.S.A.
Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, Augmented Switching,
BlueSky, BodyCom, CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController,
dsPICDEM, dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, Espresso T1S, EtherGREEN, GridTime,
IdealBridge, In-Circuit Serial Programming, ICSP, INICnet, Intelligent Paralleling, Inter-Chip Connectivity,
JitterBlocker, Knob-on-Display, maxCrypto, maxView, memBrain, Mindi, MiWi, MPASM, MPF, MPLAB Certified
logo, MPLIB, MPLINK, MultiTRAK, NetDetach, NVM Express, NVMe, Omniscient Code Generation, PICDEM,
PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE, Ripple Blocker, RTAX, RTG4, SAM-
ICE, Serial Quad I/O, simpleMAP, SimpliPHY, SmartBuffer, SmartHLS, SMART-I.S., storClad, SQI, SuperSwitcher,
SuperSwitcher II, Switchtec, SynchroPHY, Total Endurance, TSHARC, USBCheck, VariSense, VectorBlox, VeriPHY,
ViewSpan, WiperLock, XpressConnect, and ZENA are trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.
The Adaptec logo, Frequency on Demand, Silicon Storage Technology, Symmcom, and Trusted Time are registered
trademarks of Microchip Technology Inc. in other countries.
GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip
Technology Inc., in other countries.
All other trademarks mentioned herein are property of their respective companies.
© 2020-2022, Microchip Technology Incorporated and its subsidiaries. All Rights Reserved.
ISBN: 978-1-6683-0336-8