Professional Documents
Culture Documents
Data Sheet
28/40/44-Pin Enhanced Flash
Microcontrollers
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in
the intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's
Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does
not mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such
acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
MCLR/VPP 1
28 RB7/PGD
RA0/AN0 2
27 RB6/PGC
RA1/AN1 3
26 RB5
RA2/AN2/VREF-/CVREF 4
25 RB4
RA3/AN3/VREF+ 5
24 RB3/PGM
RA4/T0CKI/C1OUT 6
23 RB2
PIC16F873A/
RA5/AN4/SS/C2OUT 7
22 RB1
VSS 8
21 RB0/INT
OSC1/CLKI 9
20 VDD
OSC2/CLKO 10
19 VSS
RC0/T1OSO/T1CKI 11
18 RC7/RX/DT
RC1/T1OSI/CCP2 12
17 RC6/TX/CK
RC2/CCP1 13
16 RC5/SDO
RC3/SCK/SCL 14 15 RC4/SDI/SDA
RB7/PG
RA0/AN
28-Pin QFN
MCLR/
RA1/
AN1
VPP
0
2
8
2
7
2
6
2
5
2
4
2
RA2/AN2/VREF-/CVREF 1 21 RB3/PGM
RA3/AN3/VREF+ 2 20 RB2
3 19
RA4/T0CKI/C1OUT PIC16F873A RB1
RA5/AN4/SS/C2OUT 4 18 RB0/INT
VSS 5 PIC16F876A 17 VDD
OSC1/CLKI 6 16 VSS
OSC2/CLKO 7 1 15 RC7/RX/DT
0
1
1
1
2
1
8
9
CCP1
RC0/T1OSO/
T1CKI
RC2/
P2
RC1/T1OSI/CC
RC3/SCK/S
44-Pin QFN
RC1/T1OSI/CC
RC3/SCK/SCL
RC4/SDI/SDA
RC6/TX/CK
RC2/CCP1
RD2/PSP2
RD0/PSP0
RD3/PSP3
RD1/PSP1
RC5/SDO
P2
4
4
4
3
4
2
4
1
4
0
3
9
3
8
3
RC7/RX/DT
RD4/PSP4 1 33 OSC2/CLKO
RD5/PSP5 2 32 OSC1/CLKI
RD6/PSP6 3 31 VSS
RD7/PSP7 4 30 VSS
5 PIC16F874A 29 VDD
VSS 6 28 VDD
VDD 7 PIC16F877A 27 RE2/CS/AN7
VDD 8 26 RE1/WR/AN6
RB0/INT 9 25 RE0/RD/AN5
RB1 10 24 RA5/AN4/SS/C2OUT
RB2 11 23 RA4/T0CKI/C1OUT
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
N
RB6/PGC
RB7/PGD
RB3/PGM
C
R
R
B
B
4
PIC16F874A/
RE1/WR/AN6 10 31 VDD
RE2/CS/AN7 11 30 VSS
VDD 12 29 RD7/PSP7
VSS 13 28 RD6/PSP6
OSC1/CLKI 14 27 RD5/PSP5
15 26 RD4/PSP4
OSC2/CLKO
16 25
RA2/AN2/VREF-/CV
RC0/T1OSO/T1CKI RC7/RX/DT
17 24
RA3/AN3/VREF+
RC1/T1OSI/CCP2 18 23 RC6/TX/CK
REF RA1/AN1
RC2/CCP1 19 22 RC5/SDO
RA0/AN0
RC3/SCK/SCL 20 21 RC4/SDI/SDA
RB7/PG
RB6/PG
VPP NC
MCLR/
C RB5
RD0/PSP0 RD3/PSP3
RD1/PSP1 RD2/PSP2
R
44-Pin PLCC
6
5
4
3
2
1
4
4
RA4/T0CKI/C1OUT 39 RB3/PGM
7
RA5/AN4/SS/C2OUT 38 RB2
RE0/RD/AN5 8
37 RB1
RE1/WR/AN6 9 RB0/INT
36
10 VDD
RE2/CS/AN7 11PIC16F874A 35
VDD 34 VSS
12 PIC16F877A
VSS 33 RD7/PSP7
OSC1/CLKI 1 RD6/PSP6
3 32
OSC2/CLKO RD5/PSP5
RC0/T1OSO/T1CK1 1 31 RD4/PSP4
NC 4 30 RC7/RX/DT
29
1
8
1
9
2
0
2
1
2
2
2
3
2
4
RC3/SCK/SCL
RC1/T1OSI/CC
RC4/SDI/SDA
RC6/TX/CK
RC2/CCP1
RD3/PSP3
RD1/PSP1
RD2/PSP2
RD0/PSP0
RC5/SDO
P2 NC
CCP1
RD1/PSP1
RD3/PSP3
RC2/
CL
RD0/PSP0
RD2/PSP2
RC1/T1OSI/
RC3/SCK/S
CCP2
44-Pin TQFP
4
4
4
3
4
2
4
1
4
0
3
9
3
8
3
RC7/RX/DT 1 33 NC
RD4/PSP4 2 32 RC0/T1OSO/T1CKI
RD5/PSP5 3 31 OSC2/CLKO
RD6/PSP6 4 30 OSC1/CLKI
RD7/PSP7 5 PIC16F874A 29 VSS
VSS 28 VDD
VDD
6 PIC16F877A 27 RE2/CS/AN7
RB0/INT 7 RE1/WR/AN6
8 26
RB1 9 25 RE0/RD/AN5
RB2 10 24 RA5/AN4/SS/C2OUT
RB3/PGM 11 23 RA4/T0CKI/C1OUT
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
N
RB6/PGC
C
N
C
R
R
B
B
4
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for
current devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the
revision of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include liter-
ature number) you are using.
Synchronous Voltag
Data CCP1,2 USART Comparator e
Serial Port
EEPROM
Device Program Flash Data Memory Data EEPROM
PIC16F873A 4K words 192 Bytes 128 Bytes
PIC16F876A 8K words 368 Bytes 256 Bytes
PORTE
RE0/RD/AN5
MCLR VDD, VSS
RE1/WR/AN6
RE2/CS/AN7
Timer2 Parall
Timer0 Timer1 10-bit A/D el Slave
Synchronous Voltage
Data CCP1,2 USART Comparator Reference
Serial Port
EEPROM Device Program Flash Data Memory Data EEPROM
PIC16F874A 4K words 192 Bytes 128 Bytes
PIC16F877A 8K words 368 Bytes 256 Bytes
PC<12:0>
PC<12:0>
13
CALL, RETURN RETFIE, RETLW
13 CALL, RETURN RETFIE, RETLW
Page 0 Page 0
07FFh On-Chip Program
0800h Memory 07FFh
0800h
Page 1 Page 1
On-Chip Program 0FFFh
Memory 0FFFh
1000h 1000h
Page 2
17FFh
1800h
Page 3
1FFFh 1FFFh
16Fh 1EFh
170h 1F0h
bit 7 IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
bit 6-5 RP1:RP0: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h-1FFh)
10 = Bank 2 (100h-17Fh)
01 = Bank 1 (80h-FFh)
00 = Bank 0 (00h-7Fh)
Each bank is 128 bytes.
bit 4 TO: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
bit 3 PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
bit 2 Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
(for borrow, the polarity is reversed)
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
bit 0 C: Carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note: For borrow, the polarity is reversed. A subtraction is executed by adding the two’s
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high, or low order bit of the source register.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: When using Low-Voltage ICSP Programming (LVP) and the pull-ups on PORTB
are enabled, bit 3 in the TRISB register must be cleared to disable the pull-up
on RB3 and ensure the proper operation of the device
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Data Memory(1)
The write time is controlled by an on-chip timer. The Note: The self-programming mechanism for Flash
write/erase voltages are generated by an on-chip program memory has been changed. On
charge pump, rated to operate over the voltage range previous PIC16F87X devices, Flash pro-
of the device for byte or word operations. gramming was done in single-word
When the device is code-protected, the CPU may erase/ write cycles. The newer
continue to read and write the data EEPROM PIC18F87XA devices use a four-word
memory. Depending on the settings of the write- erase/write cycle. See Section 3.6
protect bits, the device may or may not be able to “Writing to Flash Program Memory”
write certain blocks of the program memory; however,
reads of the program memory are allowed. When
code-protected, the device programmer can no longer
access data or program memory; this does NOT
inhibit internal reads or writes.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
MOVLW AAh ;
MOVWF EECON2 ;Write AAh
BSF EECON1,WR ;Set WR bit to
;begin write
BSF INTCON,GIE ;Enable INTs.
BCF EECON1,WREN ;Disable writes
NOP
ed
14 14 14 14
EEADR<1:0> = 00
EEADR<1:0> = 01 EEADR<1:0> = 10 EEADR<1:0> = 11
Program Memory
Data Latch DQ
Data Bus 1
I/O pin(1)
WR PORTA N
CK Q 0
TRIS Latch
VSS
DQ
RD TRISA
QD
EN E
RD PORTA
TMR0 Clock Input
Data Latch DQ
Data Bus 1 VDD
WR PORTA P
CK Q 0
TRIS Latch DQ
I/O pin(1)
N
Analog IIP Mode
WR TRISA
CK Q VSS TTL
Input Buffer
RD TRISA
QD
EN
E
RD PORTA
Note: When using the SSP module in SPI Slave mode and SS enabled, the A/D converter must be set to one
of the following modes, where PCFG3:PCFG0 = 0100, 0101, 011x, 1101, 1110, 1111.
QD
WR TRIS TTL
RD Port CK
Input
EN
BufferST Buffer
RB0/INT RB3/PGM
RD TRIS
Latch
Schmitt Trigger Buffer RD Port QD
RD Port
Note 1: I/O pins have diode protection to VDD and VSS. EN Q1
Set RBIF
2: To enable weak pull-ups, set the appropriate TRIS bit(s) and clear the RBPU bit (OPTION_REG<7>).
QD
Four of the PORTB pins, RB7:RB4, have an interrupt- From other RB7:RB4 pins RD Port
on-change feature. Only pins configured as inputs can EN
Q3
cause this interrupt to occur (i.e., any RB7:RB4 pin RB7:RB6
configured as an output is excluded from the interrupt- In Serial Programming Mode
on-change comparison). The input pins (of RB7:RB4)
are compared with the old value latched on the last Note 1: I/O pins have diode protection to VDD and VSS.
read of PORTB. The “mismatch” outputs of RB7:RB4 2: To enable weak pull-ups, set the appropriate TRIS bit(s) and clear the RBPU bit (OPTIO
are OR’ed together to generate the RB port change
interrupt with flag bit RBIF (INTCON<0>).
Port/Peripheral Select(2)
I/O pin(1)
DQ
WR TRIS CKQ N
TRIS Latch
VSS
RD TRIS
Schmitt Trigger
Peripheral OE(3)
QD
EN
RD Port Peripheral Input
Note 1: I/O pins have diode protection to VDD and VSS.
2: Port/Peripheral Select signal selects between port data and peripheral output.
3: Peripheral OE (Output Enable) is only activated if Peripheral Select is active.
WR TRIS
CK Schmitt Trigger Input Buffer
RD TRIS
E
QD
EN
RD Port
Note: On a Power-on Reset, these pins are Note 1: I/O pins have protection diodes to VDD and VSS.
configured as analog inputs and read
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
PORTD operates as an 8-bit wide Parallel Slave Port, An interrupt is generated and latched into flag bit
or microprocessor port, when control bit PSPMODE PSPIF when a read or write operation is completed.
(TRISE<4>) is set. In Slave mode, it is PSPIF must be cleared by the user in firmware and
asynchronously readable and writable by the external the interrupt can be disabled by clearing the interrupt
world through RD control input pin, RE0/RD/AN5, and enable bit PSPIE (PIE1<7>).
WR control input pin, RE1/WR/AN6.
FIGURE 4-10: PORTD AND PORTE
The PSP can directly interface to an 8-bit
microprocessor data bus. The external BLOCK DIAGRAM
microprocessor can read or write the PORTD latch as (PARALLEL SLAVE PORT)
an 8-bit latch. Setting bit PSPMODE enables port pin
RE0/RD/AN5 to be the RD input, RE1/WR/AN6 to be Data Bus
the WR input and RE2/CS/AN7 to be the CS (Chip DQ
Select) input. For this functionality, the corresponding WR RDx pin
data direction bits of the TRISE register (TRISE<2:0>) Port CK
must be configured as inputs (set). The A/D port
configuration bits, PCFG3:PCFG0 (ADCON1<3:0>), TTL
CS WR RD
PORTD<7:0>
IBF
OBF PSPIF
CS
WR RD
PORTD<7:0>
IBF
OBF PSPIF
CLKO (= FOSC/4)
Data Bus
8
MUX 1
0
RA4/T0CKI MUX Sync 2
pin Cycles TMR0 Reg
1 0
T0SE
T0CS
PSA Set Flag bit TMR0IF on Overflow
PRESCALER
0
MU 8-bit Prescaler
Watchdog Timer 1X
8
0 1
WDT Enable bit
MUX PSA
WDT
Time-out
bit 7 RBPU
bit 6 INTEDG
bit 5 T0CS: TMR0 Clock Source Select bit
1 = Transition on T0CKI pin
0 = Internal instruction cycle clock
(CLKO) bit 4 T0SE: TMR0 Source Edge Select bit
1 = Increment on high-to-low transition on T0CKI pin
0 = Increment on low-to-high transition on T0CKI
pin bit 3 PSA: Prescaler Assignment bit
1 = Prescaler is assigned to the WDT
0 = Prescaler is assigned to the Timer0
module bit 2-0PS2:PS0: Prescaler Rate Select bits
Bit Value TMR0 Rate WDT Rate
000 1:2 1:1
001 1:4 1:2
010 1:8 1:4
011 1 : 16 1:8
100 1 : 32 1 : 16
101 1 : 64 1 : 32
110 1 : 128 1 : 64
111 1 : 256 1 : 128
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: To avoid an unintended device Reset, the instruction sequence shown in the
PICmicro® Mid-Range MCU Family Reference Manual (DS33023) must be exe-
cuted when changing the prescaler assignment from Timer0 to the WDT. This
sequence must be followed even if the WDT is disabled.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
T1CKI
(Default High)
T1CKI
(Default Low)
6.3 Timer1 Operation in Synchronized If T1SYNC is cleared, then the external clock input is
Counter Mode synchronized with internal phase clocks. The synchro-
nization is done after the prescaler stage. The
Counter mode is selected by setting bit TMR1CS. In prescaler stage is an asynchronous ripple counter.
this mode, the timer increments on every rising edge
In this configuration, during Sleep mode, Timer1 will
of clock input on pin RC1/T1OSI/CCP2 when bit
not increment even if the external clock is present
T1OSCEN is set, or on pin RC0/T1OSO/T1CKI when
since the synchronization circuit is shut-off. The
bit T1OSCEN is cleared.
prescaler, however, will continue to increment.
Note 1: When the T1OSCEN bit is cleared, the inverter is turned off. This eliminates power drain.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
CCP1CON<3:0>
Qs
CLRF MOVLW
CCP1CON ; Turn CCP module off
NEW_CAPT_PS ; Load the W reg with
; the new prescaler
; move value and CCP ON
MOVWFCCP1CON; Load CCP1CON with this
; value
Output Enable
CCP1CON<3:0>
8.2.1 CCP PIN CONFIGURATION
Mode Select
The user must configure the RC2/CCP1 pin as an
output by clearing the TRISC<2> bit.
EQUATION 8-1:
Duty Cycle
Resolution = Flog (
FOSC
PWM bits )
log(2)
TMR2 = PR2
TMR2 = PR2
REGISTER 9-1: SSPSTAT: MSSP STATUS REGISTER (SPI MODE) (ADDRESS 94h)
R/W-0 R/W-0 R-0 R-0 R-0 R-0 R-0 R-0
SMP CKE D/A P S R/W UA BF
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
SDOSDI
MSbLSbMSbLSb
Serial Clock
SCKSCK
PROCESSOR 1PROCESSOR 2
4 Clock Modes
SCK (CKP = 1
CKE = 1)
SDO (CKE = 0)
SDO (CKE = 1)
bit 7 bit 6bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
SDI
(SMP = 0)
Input Sample (SMP = bit
0) 7 bit 0
SDI
(SMP = 1)
bit 7 bit 0
Input Sample (SMP = 1)
SSPIF
Next Q4 Cycle
SSPSR to
after Q2
SSPBUF
SS
SCK (CKP = 0
CKE = 0)
SCK (CKP = 1
CKE = 0)
Write to SSPBUF
SDI bit 0
(SMP = 0)
bit 7 bit 7
Input
Sample (SMP = 0)
SSPIF
Interrupt Flag
Next Q4 Cycle
SS
Optional
SCK (CKP = 0
CKE = 0)
SCK (CKP = 1
CKE = 0)
Write to SSPBUF
SDI
(SMP = 0) bit 0
bit 7
Input
Sample (SMP = 0)
SSPIF
Interrupt Flag
Next Q4 Cycle
SSPSR toafter Q2
SSPBUF
SS
Not Optional
SCK
(CKP = 0
CKE = 1)
SCK (CKP = 1
CKE = 1)
Write to SSPBUF
SDI
(SMP = 0) bit 0
bit 7
Input
Sample (SMP = 0)
SSPIF
Interrupt Flag
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle
mode, this bit may not be set (no spooling) and the SSPBUF may not be written
(or writes to the SSPBUF are disabled).
PIC16F87X
FIGURE 9-
I2C SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 7-BIT
Receiving Address R/W = 0 Receiving ACK Receiving Data ACK
Data
SDA A7
A6 A5 A4 A3 A2 A1 ACK D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
S 1
SCL
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
P
SSPIF
(PIR1<3>) Bus master
terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
2003 Microchip Technology
FIGURE 9-
2003 Microchip Technology
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
S
Data in SCL held low P
sampled while CPU
responds to SSPIF
SSPIF (PIR1<3>)
BF (SSPSTAT<0>)
Cleared in software Cleared in software
From SSPIF ISR From SSPIF ISR
SSPBUF is written in SSPBUF is written in software
software
CKP
PIC16F87X
CKP is set in software CKP is set in software
DS39582B-page
DS39582B-page
FIGURE 9-
PIC16F87X
Clock is held low until Clock is held low until
update of SSPADD has update of SSPADD has
taken place taken place
SCL
S 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 P
Bus master
terminates
SSPIF transfer
(PIR1<3>)
Cleared in software Cleared in software
Cleared in software Cleared in software
BF (SSPSTAT<0>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
UA (SSPSTAT<1>)
CKP
(CKP does not reset to ‘0’ when SEN = 0)
FIGURE 9-
2003 Microchip Technology
Bus master
SCL
S 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
Sr P
SSPIF
(PIR1<3>)
BF (SSPSTAT<0>)
PIC16F87X
SSPADD needs to be
updated
CKP (SSPCON<4>)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
SDA DX DX-1
SCL
WR SSPCON
PIC16F87X
FIGURE 9-
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT
Clock is not held low
because buffer full bit is
clear prior to falling edge
Clock is held low until Clock is not held low
of 9th clock
CKP is set to ‘1’ because ACK = 1
SCL
S 1 2 3 4 5 6 7 8 9 12345678 9 1 2 3 4 5 6 7 8 9 P
SSPIF
Bus master
(PIR1<3>) terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
CKP
2003 Microchip Technology
CKP
If BF is cleared written
prior to the falling to ‘1’ in
edge of the 9th clock, software
CKP will not be reset BF is set after falling
to ‘0’ and no clock edge of the 9th clock,
stretching will occur CKP is reset to ‘0’ and
clock stretching occurs
FIGURE 9-
2003 Microchip Technology
SCL
S 1 2 3 4 5 6 7 8 9 12345678 9 123456789 1 2 3 4 5 6 7 8 9 P
SSPIF
Bus master
(PIR1<3>) terminates
Cleared in software Cleared in software Cleared in software transfer
Cleared in software
BF (SSPSTAT<0>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
UA (SSPSTAT<1>)
PIC16F87X
UA is set indicating that
SSPADD needs to be
updated
CKP
Note: An update of the SSPADD register
before the falling edge of the ninth
clock will have no effect on UA and UA CKP written to ‘1’
will remain set. in software
DS39582B-page
SCL
123456789123456789
S
SSPIF
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON<6>) ‘0’
2
FIGURE 9-16: MSSP BLOCK DIAGRAM (I C MASTER MODE)
SDA Shift
SDA In Clock
SSPSR
Detect (hold off clock
Clock Arbitrate/WCOL
MSb LSb
Receive
Clock
SCL
SSPM3:SSPM0 SSPADD<6:0>
SDA DX DX-1
SCL deasserted but slave holds SCL low (clockSCL allowed to transition high
arbitration)
SCL
BRG
03h 02h 01h 00h (hold off) 03h 02h
Value
SCL is sampled high, reload takes place and BRG starts its count
BRG
Reload
SCL
TBRG
S
Set S (SSPSTAT<3>)
Write to SSPCON2 occurs here,
SDA = 1,
SDA = 1, At completion of Start bit, hardware clears RSEN bit
SCL = 1
SCL (no change) and sets SSPIF
TBRGTBRGTBRG
1st Bit
SDA
Falling edge of ninth clock, Write to SSPBUF occurs here
end of Xmit TBRG
SCL TBRG
Sr = Repeated Start
After the write to the SSPBUF, each bit of address will 9.4.11.1 BF Status Flag
be shifted out on the falling edge of SCL, until all
In receive operation, the BF bit is set when an
seven address bits and the R/W bit are completed. On
address or data byte is loaded into SSPBUF from
the fall- ing edge of the eighth clock, the master will
SSPSR. It is cleared when the SSPBUF register is
deassert the SDA pin, allowing the slave to respond
read.
with an Acknowledge. On the falling edge of the ninth
clock, the master will sample the SDA pin to see if the
9.4.11.2 SSPOV Status Flag
address was recognized by a slave. The status of the
ACK bit is loaded into the ACKSTAT status bit In receive operation, the SSPOV bit is set when 8 bits
(SSPCON2<6>). Following the falling edge of the are received into the SSPSR and the BF flag bit is
ninth clock transmis- sion of the address, the SSPIF is already set from a previous reception.
set, the BF flag is cleared and the Baud Rate
Generator is turned off until another write to the 9.4.11.3 WCOL Status Flag
SSPBUF takes place, holding SCL low and allowing If the user writes the SSPBUF when a receive is
SDA to float. already in progress (i.e., SSPSR is still shifting in a
data byte), the WCOL bit is set and the contents of
9.4.10.1 BF Status Flag the buffer are unchanged (the write doesn’t occur).
In Transmit mode, the BF bit (SSPSTAT<0>) is set
when the CPU writes to SSPBUF and is cleared when
all eight bits are shifted out.
FIGURE 9-
PIC16F87X
Write SSPCON2<0> SEN = 1 ACKSTAT in
SSPIF
Cleared in software service routine from SSP interrupt
Cleared in software
Cleared in software
BF (SSPSTAT<0>)
PEN
2003 Microchip Technology
R/W
FIGURE 9-
2003 Microchip Technology
Write to SSPCON2<4>
to start Acknowledge sequence,
SDA = ACKDT (SSPCON2<5>) = 0
Write to SSPCON2<0> (SEN = 1),
Bus master
terminates
ACK is not sent transfer
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
S P
Data shifted in on falling edge of CLK Set SSPIF at end
of receive Set SSPIF interrupt
Set SSPIF interrupt at end of Acknow-
Set SSPIF interrupt ledge sequence
at end of receive at end of Acknowledge
SSPIF sequence
Set P bit
SDA = 0, SCL = 1 Cleared in software Cleared in software Cleared in software Cleared in software Cleared in (SSPSTAT<4>)
while CPU software and SSPIF
responds to SSPIF
BF
(SSPSTAT<0>) Last bit is shifted into SSPSR and contents are unloaded into SSPBUF
PIC16F87X
SSPOV
ACKEN
PIC16F87X
9.4.12 ACKNOWLEDGE SEQUENCE 9.4.13 STOP CONDITION TIMING
TIMING
A Stop bit is asserted on the SDA pin at the end of a
An Acknowledge sequence is enabled by setting the receive/transmit by setting the Stop Sequence Enable
Acknowledge Sequence Enable bit, ACKEN bit, PEN (SSPCON2<2>). At the end of a receive/
(SSPCON2<4>). When this bit is set, the SCL pin is transmit, the SCL line is held low after the falling edge
pulled low and the contents of the Acknowledge data of the ninth clock. When the PEN bit is set, the master
bit are presented on the SDA pin. If the user wishes to will assert the SDA line low. When the SDA line is
gen- erate an Acknowledge, then the ACKDT bit sam- pled low, the Baud Rate Generator is reloaded
should be cleared. If not, the user should set the and counts down to 0. When the Baud Rate
ACKDT bit before starting an Acknowledge sequence. Generator times out, the SCL pin will be brought high
The Baud Rate Generator then counts for one rollover and one TBRG (Baud Rate Generator rollover count)
period (TBRG) and the SCL pin is deasserted (pulled later, the SDA pin will be deasserted. When the SDA
high). When the SCL pin is sampled high (clock pin is sam- pled high while SCL is high, the P bit
arbitration), the Baud Rate Generator counts for TBRG. (SSPSTAT<4>) is set. A TBRG later, the PEN bit is
The SCL pin is then pulled low. Following this, the cleared and the SSPIF bit is set (Figure 9-24).
ACKEN bit is automatically cleared, the baud rate
generator is turned off and the MSSP module then 9.4.13.1 WCOL Status Flag
goes into Idle mode (Figure 9-23).
If the user writes the SSPBUF when a Stop sequence
9.4.12.1 WCOL Status Flag is in progress, then the WCOL bit is set and the con-
tents of the buffer are unchanged (the write doesn’t
If the user writes the SSPBUF when an Acknowledge occur).
sequence is in progress, then WCOL is set and the
contents of the buffer are unchanged (the write
doesn’t occur).
TBRGTBRG
SDA D0 ACK
SCL 8 9
SSPIF
Write to SSPCON2, SCL = 1 for TBRG, followed by SDA = 1 for TBRG after SDA sampled high. P bit (SSPSTAT<4>)
set PEN
Falling edge of 9th clock
PEN bit (SSPCON2<2>) is cleared by hardware and the SSPIF bit is set
TBRG
SCL
SDA ACK
P
TBRG TBRG TBRG
SCL brought high after TBRG
SDA asserted low before rising edge of clock to setup Stop condition
Note: TBRG = one Baud Rate Generator period.
SDA
BCLIF
SDA goes low before the SEN bit is set. Set BCLIF,
S bit and SSPIF set because SDA = 0, SCL = 1.
SDA
SCL
Set SEN, enable Start condition if SDA = 1, SCL = SEN
1 cleared automatically because of bus collision. SSP module reset into Idl
SEN
SSPIF
SDA = 0, SCL = 1
TBRG TBRG
SDA
BCLIF
Interrupt cleared in software
‘0’
S ‘0’
FIGURE 9-28: BRG RESET DUE TO SDA ARBITRATION DURING START CONDITION
SDA = 0, SCL = 1
Set S Set SSPIF
Less than TBRG TBRG
SCL S
SCL pulled low after BRG time-out
SEN
Set SEN, enable Start sequence if SDA = 1, SCL = 1
BCLIF ‘0’
SSPIF
SDA = 0, SCL = 1, Interrupts cleared in software
set SSPIF
When the user deasserts SDA and the pin is allowed If at the end of the BRG time-out, both SCL and SDA
to float high, the BRG is loaded with SSPADD<6:0> are still high, the SDA pin is driven low and the BRG
and counts down to 0. The SCL pin is then is reloaded and begins counting. At the end of the
deasserted and when sampled high, the SDA pin is count, regardless of the status of the SCL pin, the
sampled. SCL pin is driven low and the Repeated Start
condition is complete.
If SDA is low, a bus collision has occurred (i.e.,
another master is attempting to transmit a data ‘0’,
see Figure 9-29). If SDA is sampled high, the BRG is
SDA
SCL
Sample SDA when SCL goes high.
If SDA = 0, set BCLIF and release SDA and SCL.
RSEN
BCLIF
Cleared in software
‘0’
S
SSPIF ‘0’
TBRG TBRG
SDA
SCL
set BCLIF
SDA
PEN
BCLIF
P ‘0’
SSPIF ‘0’
SDA
Assert SDA SCL goes low before SDA goes high, set BCLIF
SCL
PEN BCLIF
P‘0’
SSPIF ‘0’
REGISTER 10-1: TXSTA: TRANSMIT STATUS AND CONTROL REGISTER (ADDRESS 98h)
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 R-1 R/W-0
CSRC TX9 TXEN SYNC — BRGH TRMT TX9D
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
WordEmpty
1
TRMT bit (Transmit Shift Reg. Flag)
Transmit Shift Reg
Start Bit Bit 0 Bit 1 Bit 7/8Stop Bit Start Bit Bit 0
Word 1 Word 2
TXIF bit
(Interrupt Reg. Flag)
WordEmpty
TRMT bit (Transmit Shift Reg. 1 Flag) Word 2
Transmit Shift Reg. Transmit Shift Reg.
RC7/RX/DT
Pin Buffer and Control Data
ecover RX9
Ry
8
Interrupt RCIF
Data Bus
RCIE
RCIF
(Interrupt Flag)
Note: This timing diagram shows three words appearing on the RX input. The RCREG (Receive Buffer) is read after the third word, causing the OERR (Overrun Error) bit to
RC7/RX/DT
Pin Buffer and Control Data Recovery
RX9
SPEN
Interrupt RCIF
Data Bus
RCIE
Load RSR
Bit 8 = 0, Data Byte Bit 8 = 1, Address Byte Word 1 RCREG
Read
RCIF
Note: This timing diagram shows a data byte followed by an address byte. The data byte is not read into the RCREG (Receive Buffer) because ADDEN = 1.
Read
RCIF
Note: This timing diagram shows a data byte followed by an address byte. The data byte is not read into the RCREG (Receive Buffer) because ADDEN was not updated a
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1Q2 Q3 Q4 Q1Q2Q3 Q4Q1 Q2 Q3 Q4Q3 Q4 Q1Q2 Q3 Q4 Q1Q2 Q3Q4 Q1Q2 Q3 Q4Q1 Q2 Q3Q4 Q1 Q2 Q3 Q4 Q1 Q2Q3 Q4
TRMT bit
Note: Sync Master mode; SPBRG = 0. Continuous transmission of two 8-bit words.
RC6/TX/CK pin
TXIF bit
TRMT bit
TXEN bit
RC7/RX/DT
bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7
pin
RC6/TX/CK pin
Write to bit SREN
SREN bit
‘0’
Note: Timing diagram demonstrates Sync Master mode with bit SREN = 1 and bit BRG = 0.
10.4 USART Synchronous Slave Mode When setting up a Synchronous Slave Transmission,
follow these steps:
Synchronous Slave mode differs from the Master
mode in the fact that the shift clock is supplied 1. Enable the synchronous slave serial port by
externally at the RC6/TX/CK pin (instead of being set- ting bits SYNC and SPEN and clearing bit
supplied internally in Master mode). This allows the CSRC.
device to transfer or receive data while in Sleep 2. Clear bits CREN and SREN.
mode. Slave mode is entered by clearing bit, CSRC 3. If interrupts are desired, then set enable bit
(TXSTA<7>). TXIE.
4. If 9-bit transmission is desired, then set bit TX9.
10.4.1 USART SYNCHRONOUS SLAVE
5. Enable the transmission by setting enable bit
TRANSMIT TXEN.
The operation of the Synchronous Master and Slave 6. If 9-bit transmission is selected, the ninth bit
modes is identical, except in the case of the Sleep mode. should be loaded in bit TX9D.
If two words are written to the TXREG and then the 7. Start transmission by loading data to the
SLEEP instruction is executed, the following will TXREG register.
occur: 8. If using interrupts, ensure that GIE and PEIE
a) The first word will immediately transfer to the (bits 7 and 6) of the INTCON register are set.
TSR register and transmit.
b) The second word will remain in TXREG register.
c) Flag bit TXIF will not be set.
d) When the first word has been shifted out of
TSR, the TXREG register will transfer the
second word to the TSR and flag bit TXIF will
now be set.
e) If enable bit TXIE is set, the interrupt will wake
the chip from Sleep and if the global interrupt is
enabled, the program will branch to the
interrupt vector (0004h).
bit 7-6 ADCS1:ADCS0: A/D Conversion Clock Select bits (ADCON0 bits in bold)
ADCON1 ADCON0
Clock Conversion
<ADCS2> <ADCS1:ADCS0>
0 00 FOSC/2
0 01 FOSC/8
0 10 FOSC/32
0 11 FRC (clock derived from the internal A/D RC oscillator)
1 00 FOSC/4
1 01 FOSC/16
1 10 FOSC/64
1 11 FRC (clock derived from the internal A/D RC oscillator)
bit 5-3 CHS2:CHS0: Analog Channel Select bits
000 = Channel 0 (AN0)
001 = Channel 1 (AN1)
010 = Channel 2 (AN2)
011 = Channel 3 (AN3)
100 = Channel 4 (AN4)
101 = Channel 5 (AN5)
110 = Channel 6 (AN6)
111 = Channel 7 (AN7)
Note: The PIC16F873A/876A devices only implement A/D channels 0 through 4; the
unimplemented selections are reserved. Do not select any unimplemented
channels with these devices.
bit 2 GO/DONE: A/D Conversion Status bit
When ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D conversion which is automatically
cleared by hardware when the A/D conversion is complete)
0 = A/D conversion not in
progress bit 1 Unimplemented: Read as
‘0’
bit 0 ADON: A/D On bit
1 = A/D converter module is powered up
0 = A/D converter module is shut-off and consumes no operating current
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Note: On any device Reset, the port pins that are multiplexed with analog functions
(ANx) are forced to be an analog input.
111
RE2/AN7(1)
110
RE1/AN6(1)
101
RE0/AN5(1)
100
RA5/AN4
VAIN
(Input Voltage) 011
RA3/AN3/VREF+
001
VDD RA1/AN1
000
VREF+ RA0/AN0
(Reference Voltage)
PCFG3:PCFG0
VREF-
(Reference Voltage)
VSS
PCFG3:PCFG0
TACQ = Amplifier Settling Time + Hold Capacitor Charging Time + Temperature Coefficient
= TAMP + TC + TCOFF
FIGURE 11-2:
= 2 s + TC ANALOG INPUT
+ [(Temperature MODEL
– 25°C)(0.05
s/°C)] TC = CHOLD (RIC + RSS + RS) In(1/2047)
VDD
= - 120 pF (1 k + 7 k + 10 k) In(0.0004885) Sampling Switch
= 16.47 s RIC 1K SS RSS
VT = 0.6V
TACQ = 2 s + 16.47Rs
S +ANx
[(50°C – 25C)(0.05 s/C)
= 19.72 s
CHOLD
VA CPIN ILEAKAGE = DAC Capacitance
5 pF VT = 0.6V
± 500 nA = 120 pF
Note 1: The reference voltage (VREF) has no effect on the equation since it cancels itself
out. VSS
2: The chargeCholding
Legend: PIN= inputcapacitor (CHOLD
capacitance ) is not discharged
VT= threshold voltage after each conversion.
ILEAKAGE = leakage current at the pin due to various junctions 6V
3: The
RIC=maximum recommended
interconnect resistance impedance for analog sources5V
is V
2.5
DD k.
4V This is required to meet the pin
SS= sampling switch 3V
CHOLD= sample/hold capacitance (from DAC) 2V
5 6 7 8 9 10 11
Sampling Switch (k)
TABLE 11-1: TAD vs. MAXIMUM DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (F))
AD Clock Source (TAD)
Maximum Device Frequency
Operation ADCS2:ADCS1:ADCS0
2 TOSC 000 1.25 MHz
4 TOSC 100 2.5 MHz
8 TOSC 001 5 MHz
16 TOSC 101 10 MHz
32 TOSC 010 20 MHz
64 TOSC 110 20 MHz
RC (1, 2, 3) x11 (Note 1)
Note 1: The RC source has a typical TAD time of 4 s but can vary between 2-6 s.
2: When the device frequencies are greater than 1 MHz, the RC A/D conversion clock source is
only recommended for Sleep operation.
3: For extended voltage devices (LF), please refer to Section 17.0 “Electrical Characteristics”.
TCY to TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11
b9b8b7b6b5b4b3b2b1b0 Conversion starts
Holding capacitor is disconnected from analog input (typically 100 ns)
Set GO bit
ADRES is loaded GO bit is cleared ADIF bit is set
Holding capacitor is connected to analog input
11.4.1 A/D RESULT REGISTERS Format Select bit (ADFM) controls this justification.
Figure 11-4 shows the operation of the A/D result
The ADRESH:ADRESL register pair is the location
justification. The extra bits are loaded with ‘0’s. When
where the 10-bit A/D result is loaded at the completion
of the A/D conversion. This register pair is 16 bits an A/D result will not overwrite these locations (A/D
wide. The A/D module gives the flexibility to left or dis- able), these registers may be used as two general
right justify the 10-bit result in the 16-bit result purpose 8-bit registers.
register. The A/D
10-bit Result
ADFM = 1 ADFM = 0
7 2107 0 7 0765 0
0000 00 0000 00
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
A VIN- D VIN-
RA1/AN1 RA1/AN1
A VIN+ C2 Off (Read as ‘0’) D VIN+ C2 Off (Read as ‘0’)
RA2/AN2 RA2/AN2
RA4/T0CKI/C1OUT
A VIN-
RA1/AN1 A VIN-
C2OUT RA1/AN1
A VIN+ C2 C2OUT
RA2/AN2 A VIN+ C2
RA2/AN2
RA5/AN4/SS/C2OUT
Two Common Reference Comparators Two Common Reference Comparators with Outputs
CM2:CM0 = 100 CM2:CM0 = 101
A VIN- A VIN-
RA0/AN0 RA0/AN0
A VIN+ C1 C1OUT A VIN+ C1 C1OUT
RA3/AN3 RA3/AN3
RA4/T0CKI/C1OUT
A VIN-
RA1/AN1
C2 C2OUT A VIN-
D VIN+ RA1/AN1 D VIN+ C2 C2OUT
RA2/AN2 RA2/AN2
RA5/AN4/SS/C2OUT
One Independent Comparator with Output Four Inputs Multiplexed to Two Comparators
CM2:CM0 = 001 CM2:CM0 = 110
A
A VIN- RA0/AN0
RA0/AN0 CIS = 0 VIN-
A VIN+ C1 C1OUT A CIS = 1
RA3/AN3 RA3/AN3 C1 C1OUT
V IN+
RA4/T0CKI/C1OUT A
RA1/AN1
CIS = 0 VIN-
A CIS = 1
D VIN- RA2/AN2 C2 C2OUT
RA1/AN1 VIN+
MULTIPLEX
+-
CxINV
Q D
Read CMCON EN
Set CMIF QD
bit EN CL
From Other
Comparator
Read CMCON
Reset
VDD
VT = 0.6 V RIC
RS < 10K
AIN
CPIN ILEAKAGE
VA VT = 0.6 V
5 pF ±500 nA
VSS
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
VDD
16 Stages
CVREN
8R R R R R
8R CVRR
RA2/AN2/VREF-/CVREF
CVROE
CVR3 CVR2 CVR1 CVR0
CVREF
16:1 Analog MUX
Input to
Comparator
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
14.2.2 CRYSTAL
OSCILLATOR/CERAMIC TABLE 14-1: CERAMIC RESONATORS
RESONATORS
Ranges Tested:
In XT, LP or HS modes, a crystal or ceramic resonator
is connected to the OSC1/CLKI and OSC2/CLKO pins Mode Freq. OSC1 OSC2
to establish oscillation (Figure 14-1). The XT 455 kHz 68-100 pF 68-100 pF
PIC16F87XA oscillator design requires the use of a 2.0 MHz 15-68 pF 15-68 pF
parallel cut crys- tal. Use of a series cut crystal may 4.0 MHz 15-68 pF 15-68 pF
give a frequency out of the crystal manufacturer’s
HS 8.0 MHz 10-68 pF 10-68 pF
specifications. When in XT, LP or HS modes, the
16.0 MHz 10-22 pF 10-22 pF
device can have an external clock source to drive the
OSC1/CLKI pin (Figure 14-2). These values are for design guidance only.
See notes following Table 14-2.
FIGURE 14-1: CRYSTAL/CERAMIC Resonators Used:
RESONATOR OPERATION 2.0 MHz Murata Erie CSA2.00MG 0.5%
(HS, XT OR LP 4.0 MHz Murata Erie CSA4.00MG 0.5%
OSC CONFIGURATION)
8.0 MHz Murata Erie CSA8.00MT 0.5%
C1(1) OSC1 16.0 MHz Murata Erie CSA16.00MX 0.5%
All resonators used did not have built-in capacitors.
To Internal Logic
XTAL RF(3)
OSC2
Sleep
Rs(2)
C2(1) PIC16F87XA
External Reset
MCLR
Sleep
WDT WDT
ModuleTime-out
Reset
VDD Rise Detect
Power-on Reset
VDD
Brown-out Reset
S
BODEN
OST/PWRT
OST
Chip_Reset
10-bit Ripple Counter R Q
OSC1
(1) PWRT
On-chip RC OSC
10-bit Ripple Counter
Enable PWRT
Enable OST
Note 1: This is a separate oscillator from the RC oscillator of the CLKI pin.
through an RC network, as described in Section 14.4 On power-up, the time-out sequence is as follows: the
“MCLR”. A maximum rise time for VDD is specified. PWRT delay starts (if enabled) when a POR Reset
See Section 17.0 “Electrical Characteristics” for occurs. Then, OST starts counting 1024 oscillator
details. cycles when PWRT ends (LP, XT, HS). When the OST
When the device starts normal operation (exits the ends, the device comes out of Reset.
Reset condition), device operating parameters (volt- If MCLR is kept low long enough, the time-outs will
age, frequency, temperature, etc.) must be met to expire. Bringing MCLR high will begin execution
ensure operation. If these conditions are not met, the immediately. This is useful for testing purposes or to
device must be held in Reset until the operating synchronize more than one PIC16F87XA device
condi- tions are met. Brown-out Reset may be used to operating in parallel.
meet the start-up conditions. For additional
Table 14-5 shows the Reset conditions for the Status,
information, refer to application note, AN607, “Power-
PCON and PC registers, while Table 14-6 shows the
up Trouble Shooting” (DS00607).
Reset conditions for all the registers.
FIGURE 14-6: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD VIA RC NETWORK)
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
FIGURE 14-8: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 2
VDD
MCLR
Internal POR
TPWRT
OST Time-out
Internal Reset
FIGURE 14-9: SLOW RISE TIME (MCLR TIED TO VDD VIA RC NETWORK)
5V
VDD 0V 1V
MCLR
Internal POR
TPWRT
PWRT Time-out
TOST
OST Time-out
Internal Reset
The “return from interrupt” instruction, RETFIE, exits For external interrupt events, such as the INT pin or
the interrupt routine, as well as sets the GIE bit, which PORTB change interrupt, the interrupt latency will be
re-enables interrupts. three or four instruction cycles. The exact latency
depends when the interrupt event occurs. The latency
is the same for one or two-cycle instructions.
Individual interrupt flag bits are set regardless of the
status of their corresponding mask bit, PEIE bit or GIE
bit.
EEIF EEIE
PSPIF(1) PSPIE(1)
ADIF ADIE
RCIF RCIE
Wake-up (If in Sleep mode)
TMR0IF TMR0IE
INTF INTE
TXIF TXIE
RBIF RBIE
Interrupt to CPU
SSPIF SSPIE
GIE
TMR2IF TMR2IE
TMR1IF TMR1IE
CCP2IF CCP2IE
BCLIF BCLIE
CMIF CMIE
0
1
MUX Postscaler
WDT Timer
8
8-to-1 MUX
PS2:PS0
PSA
WDT
Enable Bit
To TMR0 (F-1)
0 1
MUX
PSA
WDT
Time-out
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1 CLKO(4)
INT pin TOST(2)
INTF Flag (INTCON<1>)
Processor in
Sleep
INSTRUCTION FLOW PC
Instruction Fetched
PC PC+1 PC+2 PC+2 PC + 2 0004h0005h
Instruction Executed
Inst(PC + 1) Inst(PC + 2) Inst(0004h)Inst(0005h)
Inst(PC) = Sleep
Note: Additional information on the mid-range instruction set is available in the PICmicro® Mid-Range MCU
Family Reference Manual (DS33023).
CLRF Clear f
COMF Complement f
Syntax: [ label ] CLRF f
Syntax: [ label ] COMF f,d
Operands: 0 f 127
Operands: 0 f 127
Operation: 00h (f) d [0,1]
1Z
Operation: (f) (destination)
Status Affected: Z
Status Affected: Z
Description: The contents of register ‘f’ are
Description: The contents of register ‘f’ are
cleared and the Z bit is set.
complemented. If ‘d’ is ‘0’, the
result is stored in W. If ‘d’ is ‘1’,
the result is stored back in
register ‘f’.
CLRW Clear W
DECF Decrement f
Syntax: [ label ] CLRW
Syntax: [ label ] DECF f,d
Operands: None
Operands: 0 f 127
Operation: 00h (W) d [0,1]
1Z
Operation: (f) - 1 (destination)
Status Affected: Z Status Affected: Z
Description: W register is cleared. Zero bit (Z)
Description: Decrement register ‘f’. If ‘d’ is ‘0’,
is set. the result is stored in the W
register. If ‘d’ is ‘1’, the result is
stored back in register ‘f’.
† NOTICE: Stresses above those listed under “Absolute Maximum Ratings” may cause permanent damage to the
device. This is a stress rating only and functional operation of the device at those or any other conditions above
those indicated in the operation listings of this specification is not implied. Exposure to maximum rating conditions
for extended periods may affect device reliability.
6.0V
5.5V
5.0V
4.5V
4.0V PIC16F87XA
3.5V
Volta
3.0V
2.5V
2.0V
20 MHz
Frequency
6.0V
5.5V
5.0V
4.5V
4.0V
3.5V
PIC16LF87XA
Volta
3.0V
2.5V
2.0V
4 MHz 10 MHz
Frequency
FMAX = (6.0 MHz/V) (VDDAPPMIN – 2.0V) + 4 MHz
Note 1: VDDAPPMIN is the minimum voltage of the PICmicro® device in the application.
2: FMAX has a maximum frequency of 10 MHz.
RL
CL CL
Pin Pin
VSS VSS
RL = 464
CL = 50 pF for all pins except OSC2, but including PORTD and PORTE outputs as ports, 15 pF for OSC2 output
Note: PORTD and PORTE are not implemented on PIC16F873A/876A devices.
Q4 Q1 Q2 Q3 Q4 Q1
OSC1
1 3 3 4 4
2
CLKO
Q4 Q1 Q2 Q3
OSC1
10 11
CLKO
13 12
19 18
14 16
17 15
20, 21
Note: Refer to for load conditions.
VDD
MCLR
Internal POR 30
33
PWRT
Time-out 32
OSC
Time-out
Internal
Reset
Watchdog
Timer Reset
31
34
34
I/O pins
VDD VBOR
35
RA4/T0CKI
40 41
42
RC0/T1OSO/T1CKI
45 46
47 48
TMR0 or TMR1
RC1/T1OSI/CCP2
and RC2/CCP1 (Capture Mode)
50 51
52
RC1/T1OSI/CCP2
and RC2/CCP1 (Compare or PWM Mode)
53 54
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
62
64
63
Note: Refer to for load conditions.
SS
70
SCK (CKP = 0)
71 72
78 79
SCK (CKP = 1)
79 78
80
75, 76
SS
81
SCK (CKP = 0)
71 72
79
73
SCK (CKP = 1)
80
78
75, 76
74
SS
70
SCK (CKP = 0)
83
71 72
78 79
SCK (CKP = 1)
79 78
80
75, 76 77
74
73
Note: Refer to for load conditions.
82
SS
70
SCK (CKP = 0) 83
71 72
SCK (CKP = 1)
80
75, 76 77
SDI
MSb In Bit 61 LSb In
74
Note: Refer to for load conditions.
SCL
91 93
9092
SDA
SDA
Out
RC6/TX/CK
pin 121
RC7/RX/DT 121
pin
120
122
RC6/TX/CK
pin 125
RC7/RX/DT
pin
126
A/D DATA 9 8 7 2 1 0
ADIF
GODONE
Sampling Stopped
SAMPLE
Note: If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts. This allows the SLEEP
instruction to be executed.
5 5.0V
4 4.5V
4.0V
IDD
3 3.5V
3.0V
2
2.5V
2.0V
0
4 6 8 10 12 14 16 18 20
FOSC (MHz)
FIGURE 18-2: MAXIMUM IDD vs. FOSC OVER VDD (HS MODE)
8
4.5V
5
4.0V
4
3.5V
3 3.0V
2.5V
2
IDD
2.0V
0
4 6 8 10 12 14 16 18 20
FOSC (MHz)
Typical:statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
1.6
5.5V
1.4
5.0V
1.2 4.5V
4.0V
1.0
3.5V
0.8
3.0V
2.5V
0.6
2.0V
0.4
0.2
FIGURE 18-4: MAXIMUM IDD vs. FOSC OVER VDD (XT MODE)
2.5
Typical:statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
2.0
5.5V
5.0V
1.5
4.5V
4.0V
1.0 3.5V
3.0V
2.5V
2.0V
0.5
0.0
0 500 1000 1500 2000 2500 3000 3500 4000
FOSC (MHz)
50 5.0V
4.5V
40
4.0V
3.5V
30
3.0V
2.5V
20
2.0V
10
0
20 30 40 50 60 70 80 90 100
FOSC (kHz)
FIGURE 18-6: MAXIMUM IDD vs. FOSC OVER VDD (LP MODE)
120
Typical:statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
5.5V
100
5.0V
4.5V
80
4.0V
60 3.5V
3.0V
2.5V
402.0V
20
0
20 30 40 50 60 70 80 90 100
FOSC (kHz)
4.5
4.0
5.1 kOhm
3.5
3.0
10 kOhm
2.5
Freq
2.0
1.5
1.0
100 kOhm
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
2.5
2.0
3.3 kOhm
1.5
5.1 kOhm
Freq
1.0
10 kOhm
0.5
100 kOhm
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
0.9
0.8
3.3 kOhm
0.7
0.6
5.1 kOhm
0.5
Freq
0.4
10 kOhm
0.3
0.2
100 kOhm
0.1
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 18-10: IPD vs. VDD, -40C TO +125C (SLEEP MODE, ALL PERIPHERALS DISABLED)
100
Max (125°C)
10
Max (85°C)
0.1
0.01
Typ (25°C)
Typical:statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C
0.001
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
Max (+70°C)
10 Max
Typ (+25°C)
IIPPD
Typ
0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 18-12: TYPICAL AND MAXIMUM IWDT vs. VDD OVER TEMPERATURE (WDT ENABLED)
100
Typical:statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
10 Max (+125°C)
0.1
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
1,000
Max (125°C)
Typ (25°C)
Device in Sleep
Indeterminant State
Device in Reset
100
IDD
Note:Device current in Reset depends on oscillator mode, frequency and circuit. Max (125°C)
Typical: statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3Typ
(-40°C to +125°C)
(25°C)
10
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 18-14: TYPICAL, MINIMUM AND MAXIMUM WDT PERIOD vs. VDD (-40C TO +125C)
50
40
35
Max (125°C)
30
WDT Period
25 Typ (25°C)
20 Min
15 (-40°C)
10
50
125°C
40
35
85°C
30
WDT Period
25°C
25
20 -40°C
15
10
FIGURE 18-16: TYPICAL, MINIMUM AND MAXIMUM VOH vs. IOH (VDD = 5V, -40C TO +125C)
5.5
5.0
4.5
Max
3.5
4.0
Typ (25°C)
3.0
2.5 Min
2.0
Typical: statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
1.5
1.0
0.5
0 5 10 15 20 25
0.0 IOH (-mA)
3.5
2.5
Max
2.0
Typ (25°C)
1.5
Min
1.0
0.5
0.0
0 5 10 15 20 25
IOH (-mA)
FIGURE 18-18: TYPICAL, MINIMUM AND MAXIMUM VOL vs. IOL (VDD = 5V, -40C TO +125C)
1.0
0.7
Max (85°C)
0.6
0.5
Typ (25°C)
0.4
0.2
0.1
0 5 10 15 20 25
0.0
IOL (-mA)
3.0
Max (125°C)
2.5 Typical: statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
2.0
1.5
Max (85°C)
1.0
Typ (25°C)
0.5
Min (-40°C)
0.0
0 5 10 15 20 25
IOL (-mA)
FIGURE 18-20: MINIMUM AND MAXIMUM VIN vs. VDD (TTL INPUT, -40C TO +125C)
1.5
1.4 Typical: statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
1.0
0.8
0.7
0.6
4.0
Typical: statistical mean @ 25°C Maximum: mean + 3 (-40°C to +125°C) Minimum: mean – 3 (-40°C to +125°C)
3.5
2.5
2.0
VIN
1.5
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
FIGURE 18-22: MINIMUM AND MAXIMUM VIN vs. VDD (I2C INPUT, -40C TO +125C)
3.5
VIH Max
Typical:statistical mean @ 25°C
3.0 Maximum: mean + 3 (-40°C to +125°C)
Minimum: mean – 3 (-40°C to +125°C)
2.5
2.0
VIL Max
VIL
VIN
VIH Min
1.5
1.0
VIL Min
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
3.5
-40°C
-
3
Differential or Integral Nonlinearity
+25°C
2
2.5
+85°C
8
2
1.5
0.5
+125°C
12
0
2 2.5 3 3.5 4 4.5 5 5.5
VDD and VREFH (V)
FIGURE 18-24: A/D NONLINEARITY vs. VREFH (VDD = 5V, -40C TO +125C)
3
2.5
Differential or Integral Nonlinearilty
1.5
Typ (+25°C)
Typ
0.5
0
2 2.5 3 3.5 4 4.5 5 5.5
VREFH (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
* Standard PICmicro device marking consists of Microchip part number, year code, week code, and
traceability code. For PICmicro device marking beyond this, certain price adders apply. Please check
with your Microchip Sales Office. For QTP devices, any special marking adders are included in QTP
price.
XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
PIC16F876A/SO
XXXXXXXXXXXXXXXXXXXX
YYWWNNN 0310017
E1
2
n 1
A A2
c L
B1
A1 B
eB p
E E1
#leads=n1
D1 D
2
1
B
n
CH x 45
A
A1 A2
L
(F)
E E1
#leads=n1
D1 D
n12
CH2 x 45 CH1 x 45
A3
A2 A
35
B1
c B A1
p
E2 D2
EXPOSED
E METAL
PAD
D D2
B
2
1
n
OPTIONAL PIN 1 PIN 1
INDEX ON E2
INDEX ON
TOP EXPOSED PAD L
MARKING
BOTTOM VIEW
TOP VIEW
A
A1
A3
2
1
n
E A2
c L
B1
A1
B
eB p
E
E1
p
B
2
n 1
h
45
c
A A2
L A1
E
E1
B
2
n 1
A
c
A2
A1
L
E EXPOSED
METAL PADS
E1
D1 D D2
p
2
1
B
n
R E2
CH X 45° L
TOP VIEW BOTTOM VIEW
α
A2 A
A1
A3
042003
Connecting to the Microchip Internet
Web Site
The Microchip web site is available at the following
URL:
www.microchip.com
The file transfer site is available by using an FTP
service to connect to:
ftp://ftp.microchip.com
The web site and file transfer site provide a variety of
services. Users may download files for the latest
Development Tools, Data Sheets, Application Notes,
User's Guides, Articles and Sample Programs. A vari-
ety of Microchip specific business information is also
available, including listings of Microchip sales offices,
distributors and factory representatives. Other data
available for consideration is:
• Latest Microchip Press Releases
• Technical Support Section with Frequently Asked
Questions
• Design Tips
• Device Errata
• Job Postings
• Microchip Consultant Program Member Listing
• Links to other useful web sites related
to Microchip Products
• Conferences for products, Development
Systems, technical information and more
• Listing of seminars and events
Questions:
2. How does this document meet your hardware and software development needs?
3. Do you find the organization of this document easy to follow? If not, why?
4. What additions to the document do you think would enhance the structure and subject?
5. What deletions from the document could be made without affecting the overall usefulness?