Professional Documents
Culture Documents
PIC16F87XA
Data Sheet
28/40-pin Enhanced FLASH
Microcontrollers
• The PICmicro family meets the specifications contained in the Microchip Data Sheet.
• Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today,
when used in the intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowl-
edge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.
The person doing so may be engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable”.
• Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of
our product.
If you have any further questions about this matter, please contact the local sales office nearest to you.
MCLR/VPP 1 28 RB7/PGD
RA0/AN0 2 27 RB6/PGC
RA1/AN1 3 26 RB5
PIC16F876A/873A
RA2/AN2/VREF-/CVREF 4 25 RB4
RA3/AN3/VREF+ 5 24 RB3/PGM
RA4/T0CKI/C1OUT 6 23 RB2
RA5/AN4/SS/C2OUT 7 22 RB1
VSS 8 21 RB0/INT
OSC1/CLKIN 9 20 VDD
OSC2/CLKOUT 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
MLF
MCLR/VPP
RB7/PGD
RB6/PGC
RA1/AN1
RA0/AN0
RB5
RB4
28 27 26 25 24 23 22
RA2/AN2/VREF-/CVREF 1 21 RB3/PGM
RA3/AN3/VREF+ 2 20 RB2
RA4/T0CKI/C1OUT 3 PIC16F873A 19 RB1
RA5/AN4/SS/C2OUT 4 18 RB0/INT
VSS 5 PIC16F876A 17 VDD
OSC1/CLKIN 6 16 VSS
OSC2/CLKOUT 7 15 RC7/RX/DT
8 9 10 11 12 13 14
RC0/T1OSO/T1CKI
RC5/SDO
RC4/SDI/SDA
RC6/TX/CK
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
PIC16F87A7/874A
RA5/AN4/SS/C2OUT 7 34 RB1
RE0/RD/AN5 8 33 RB0/INT
RE1/WR/AN6 9 32 VDD
RE2/CS/AN7 10 31 VSS
VDD 11 30 RD7/PSP7
VSS 12 29 RD6/PSP6
RA2/AN2/VREF-/CVREF
OSC1/CLKIN 13 28 RD5/PSP5
OSC2/CLKOUT 14 27 RD4/PSP4
RA3/AN3/VREF+
RC0/T1OSO/T1CKI 15 26 RC7/RX/DT
RC1/T1OSI/CCP2 16 25 RC6/TX/CK
MCLR/VPP
RC2/CCP1 17 24 RC5/SDO
RB7/PGD
RB6/PGC
RA1/AN1
RA0/AN0
RC3/SCK/SCL 18 23 RC4/SDI/SDA
RD0/PSP0 RD3/PSP3
RB5
RB4
19 22
NC
NC
RD1/PSP1 20 21 RD2/PSP2
PLCC
6
5
4
3
2
1
44
43
42
41
40
RA4/T0CKI/C1OUT 39 RB3/PGM
7
RA5/AN4/SS/C2OUT 8 38 RB2
RE0/RD/AN5 9 37 RB1
RE1/WR/AN6 10 36 RB0/INT
RE2/CS/AN7 11 PIC16F877A 35 VDD
VDD 12 34 VSS
VSS 13
PIC16F874A 33 RD7/PSP7
OSC1/CLKIN 14 32 RD6/PSP6
OSC2/CLKOUT 15 31 RD5/PSP5
RC0/T1OSO/T1CK1 16 30 RD4/PSP4
NC 17 9 RC7/RX/DT
RC1/T1OSI/CCP2
18
19
20
21
22
23
24
25
26
27
282
RC3/SCK/SCL
RC4/SDI/SDA
RC6/TX/CK
RC2/CCP1
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC5/SDO
NC
RC4/SDI/SDA
RC6/TX/CK
RC2/CCP1
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC1/T1OSI/CCP2
RC3/SCK/SCL
RC5/SDO
NC
QFP
44
43
42
41
40
39
38
37
36
35
34
RC7/RX/DT 1 33 NC
RD4/PSP4 2 32 RC0/T1OSO/T1CKI
RD5/PSP5 3 31 OSC2/CLKOUT
RD6/PSP6 4 30 OSC1/CLKIN
RD7/PSP7 5 PIC16F877A 29 VSS
VSS 6 28 VDD
VDD 7
PIC16F874A 27 RE2/AN7/CS
RB0/INT 8 26 RE1/AN6/WR
RB1 9 25 RE0/AN5/RD
RB2 10 24 RA5/AN4/SS/C2OUT
RB3/PGM 11 23 RA4/T0CKI/C1OUT
12
13
14
15
16
17
18
19
20
21
22 RA3/AN3/VREF+
RA2/AN2/VREF-/CVREF
RB4
RB5
RA0/AN0
RA1/AN1
NC
NC
RB6/PGC
RB7/PGD
MCLR/VPP
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 Voltage
Data EEPROM CCP1,2 USART Comparator Reference
Serial Port
PORTE
RE1/AN6/WR
RE2/AN7/CS
Synchronous Voltage
Data EEPROM CCP1,2 USART Comparator Reference
Serial Port
I/O/P Buffer
Pin Name Pin# Description
Type Type
I/O/P Buffer
Pin Name Pin# Description
Type Type
PORTB is a bi-directional I/O port. PORTB can be software
programmed for internal weak pull-up on all inputs.
RB0/INT 21 TTL/ST(1)
RB0 I/O Digital I/O.
INT I External interrupt.
RB1 22 I/O TTL Digital I/O.
RB2 23 I/O TTL Digital I/O.
RB3/PGM 24 TTL
RB3 I/O Digital I/O.
PGM I/O Low voltage ICSP programming enable pin.
RB4 25 I/O TTL Digital I/O.
RB5 26 I/O TTL Digital I/O.
(2)
RB6/PGC 27 TTL/ST
RB6 I/O Digital I/O.
PGC I/O In-Circuit Debugger and ICSP programming clock.
RB7/PGD 28 TTL/ST(2)
RB7 I/O Digital I/O.
PGD I/O In-Circuit Debugger and ICSP programming data.
PORTC is a bi-directional I/O port.
RC0/T1OSO/T1CKI 11 ST
RC0 I/O Digital I/O.
T1OSO O Timer1 oscillator output.
T1CKI I Timer1 external clock input.
RC1/T1OSI/CCP2 12 ST
RC1 I/O Digital I/O.
T1OSI I Timer1 oscillator input.
CCP2 I/O Capture2 input, Compare2 output, PWM2 output.
RC2/CCP1 13 ST
RC2 I/O Digital I/O.
CCP1 I/O Capture1 input/Compare1 output/PWM1 output.
RC3/SCK/SCL 14 ST
RC3 I/O Digital I/O.
SCK I/O Synchronous serial clock input/output for SPI mode.
SCL I/O Synchronous serial clock input/output for I2C mode.
RC4/SDI/SDA 15 ST
RC4 I/O Digital I/O.
SDI I SPI data in.
SDA I/O I2C data I/O.
RC5/SDO 16 ST
RC5 I/O Digital I/O.
SDO O SPI data out.
RC6/TX/CK 17 ST
RC6 I/O Digital I/O.
TX O USART asynchronous transmit.
CK I/O USART 1 synchronous clock.
RC7/RX/DT 18 ST
RC7 I/O Digital I/O.
RX I USART asynchronous receive.
DT I/O USART synchronous data.
VSS 8, 19 P — Ground reference for logic and I/O pins.
VDD 20 P — Positive supply for logic and I/O pins.
Legend: I = input O = output I/O = input/output P = power
— = Not used TTL = TTL input ST = Schmitt Trigger input
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in Serial Programming mode.
3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.
PC<12:0> PC<12:0>
0005h 0005h
Page 0 Page 0
On-Chip
07FFh 07FFh
Program
0800h Memory 0800h
Page 1 Page 1
On-Chip
0FFFh 0FFFh
Program
1000h 1000h
Memory
Page 2
17FFh
1800h
Page 3
1FFFh 1FFFh
Indirect addr.(*) 00h Indirect addr.(*) 80h Indirect addr.(*) 100h Indirect addr.(*) 180h
TMR0 01h OPTION_REG 81h TMR0 101h OPTION_REG 181h
PCL 02h PCL 82h PCL 102h PCL 182h
STATUS 03h STATUS 83h STATUS 103h STATUS 183h
FSR 04h FSR 84h FSR 104h FSR 184h
PORTA 05h TRISA 85h 105h 185h
PORTB 06h TRISB 86h PORTB 106h TRISB 186h
PORTC 07h TRISC 87h 107h 187h
PORTD(1) 08h TRISD(1) 88h 108h 188h
PORTE(1) 09h TRISE(1) 89h 109h 189h
PCLATH 0Ah PCLATH 8Ah PCLATH 10Ah PCLATH 18Ah
INTCON 0Bh INTCON 8Bh INTCON 10Bh INTCON 18Bh
PIR1 0Ch PIE1 8Ch EEDATA 10Ch EECON1 18Ch
PIR2 0Dh PIE2 8Dh EEADR 10Dh EECON2 18Dh
TMR1L 0Eh PCON 8Eh EEDATH 10Eh Reserved(2) 18Eh
TMR1H 0Fh 8Fh EEADRH 10Fh Reserved(2) 18Fh
T1CON 10h 90h 110h 190h
TMR2 11h SSPCON2 91h 111h 191h
T2CON 12h PR2 92h 112h 192h
SSPBUF 13h SSPADD 93h 113h 193h
SSPCON 14h SSPSTAT 94h 114h 194h
CCPR1L 15h 95h 115h 195h
CCPR1H 16h 96h 116h 196h
CCP1CON 17h 97h General 117h General 197h
Purpose Purpose
RCSTA 18h TXSTA 98h Register 118h Register 198h
TXREG 19h SPBRG 99h 16 Bytes 119h 16 Bytes 199h
RCREG 1Ah 9Ah 11Ah 19Ah
CCPR2L 1Bh 9Bh 11Bh 19Bh
CCPR2H 1Ch CMCON 9Ch 11Ch 19Ch
CCP2CON 1Dh CVRCON 9Dh 11Dh 19Dh
ADRESH 1Eh ADRESL 9Eh 11Eh 19Eh
ADCON0 1Fh ADCON1 9Fh 11Fh 19Fh
20h A0h 120h 1A0h
Indirect addr.(*) 00h Indirect addr.(*) 80h Indirect addr.(*) 100h Indirect addr.(*) 180h
TMR0 01h OPTION_REG 81h TMR0 101h OPTION_REG 181h
PCL 02h PCL 82h PCL 102h PCL 182h
STATUS 03h STATUS 83h STATUS 103h STATUS 183h
FSR 04h FSR 84h FSR 104h FSR 184h
PORTA 05h TRISA 85h 105h 185h
PORTB 06h TRISB 86h PORTB 106h TRISB 186h
PORTC 07h TRISC 87h 107h 187h
PORTD(1) 08h TRISD(1) 88h 108h 188h
PORTE(1) 09h TRISE(1) 89h 109h 189h
PCLATH 0Ah PCLATH 8Ah PCLATH 10Ah PCLATH 18Ah
INTCON 0Bh INTCON 8Bh INTCON 10Bh INTCON 18Bh
PIR1 0Ch PIE1 8Ch EEDATA 10Ch EECON1 18Ch
PIR2 0Dh PIE2 8Dh EEADR 10Dh EECON2 18Dh
TMR1L 0Eh PCON 8Eh EEDATH 10Eh Reserved(2) 18Eh
TMR1H 0Fh 8Fh EEADRH 10Fh Reserved(2) 18Fh
T1CON 10h 90h 110h 190h
TMR2 11h SSPCON2 91h
T2CON 12h PR2 92h
SSPBUF 13h SSPADD 93h
SSPCON 14h SSPSTAT 94h
CCPR1L 15h 95h
CCPR1H 16h 96h
CCP1CON 17h 97h
RCSTA 18h TXSTA 98h
TXREG 19h SPBRG 99h
RCREG 1Ah 9Ah
CCPR2L 1Bh 9Bh
CCPR2H 1Ch CMCON 9Ch
CCP2CON 1Dh CVRCON 9Dh
ADRESH 1Eh ADRESL 9Eh
ADCON0 1Fh ADCON1 9Fh
120h 1A0h
20h A0h
General General
Purpose Purpose accesses accesses
Register Register
20h-7Fh A0h - FFh
96 Bytes 96 Bytes 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
The INDF register is not a physical register. Addressing EXAMPLE 2-2: INDIRECT ADDRESSING
the INDF register will cause indirect addressing. MOVLW 0x20 ;initialize pointer
Indirect addressing is possible by using the INDF reg- MOVWF FSR ;to RAM
ister. Any instruction using the INDF register actually NEXT CLRF INDF ;clear INDF register
accesses the register pointed to by the File Select Reg- INCF FSR,F ;inc pointer
ister, FSR. Reading the INDF register itself, indirectly BTFSS FSR,4 ;all done?
GOTO NEXT ;no clear next
(FSR = ’0’) will read 00h. Writing to the INDF register
CONTINUE
indirectly results in a no operation (although status bits : ;yes continue
may be affected). An effective 9-bit address is obtained
by concatenating the 8-bit FSR register and the IRP bit
(STATUS<7>), as shown in Figure 2-6.
Data
Memory(1)
• EECON1 If the device contains less memory than the full address
reach of the address register pair, the Most Significant
• EECON2
bits of the registers are not implemented. For example,
• EEDATA if the device has 128 bytes of data EEPROM, the Most
• EEDATH Significant bit of EEADR is not implemented on access
• EEADR to data EEPROM.
• EEADRH
3.2 EECON1 and EECON2 Registers
When interfacing to the data memory block, EEDATA
holds the 8-bit data for read/write, and EEADR holds EECON1 is the control register for memory accesses.
the address of the EEPROM location being accessed. Control bit EEPGD determines if the access will be a
These devices have 128 or 256 bytes of data EEPROM program or data memory access. When clear, as it is
(depending on the device), with an address range from when reset, any subsequent operations will operate on
00h to FFh. On devices with 128 bytes, addresses from the data memory. When set, any subsequent opera-
80h to FFh are unimplemented and will wrap around to tions will operate on the program memory.
the beginning of data EEPROM memory. When writing
to unimplemented locations, the on-chip charge pump Control bits RD and WR initiate read and write or erase,
will be turned off. respectively. These bits cannot be cleared, only set, in
software. They are cleared in hardware at completion
When interfacing the program memory block, the of the read or write operation. The inability to clear the
EEDATA and EEDATH registers form a two-byte word WR bit in software prevents the accidental, premature
that holds the 14-bit data for read/write, and the termination of a write operation.
EEADR and EEADRH registers form a two-byte word
that holds the 13-bit address of the program memory The WREN bit, when set, will allow a write or erase
location being accessed. These devices have 4 or 8K operation. On power-up, the WREN bit is clear. The
words of program FLASH with an address range from WRERR bit is set when a write (or erase) operation is
0000h to 0FFFh for the PIC16F873A/874A, and 0000h interrupted by a MCLR or a WDT Time-out Reset dur-
to 1FFFh for the PIC16F876A/877A. Addresses above ing normal operation. In these situations, following
the range of the respective device will wrap around to RESET, the user can check the WRERR bit and rewrite
the beginning of program memory. the location. The data and address will be unchanged
in the EEDATA and EEADR registers.
The EEPROM data memory allows single byte read
and write. The FLASH program memory allows single Interrupt flag bit EEIF in the PIR2 register is set when
word reads and four-word block writes. Program mem- write is complete. It must be cleared in software.
ory write operations automatically perform an erase- EECON2 is not a physical register. Reading EECON2
before-write on blocks of four words. A byte write in will read all '0's. The EECON2 register is used
data EEPROM memory automatically erases the loca- exclusively in the EEPROM write sequence.
tion and writes the new data (erase before write).
The write time is controlled by an on-chip timer. The
Note: The self-programming mechanism for
write/erase voltages are generated by an on chip
FLASH program memory has been
charge pump, rated to operate over the voltage range
changed. On previous PIC16F87X
of the device for byte or word operations.
devices, FLASH programming was done in
When the device is code protected, the CPU may single word erase/write cycles. The newer
continue to read and write the data EEPROM memory. PIC16F87XA devices use a four-word
Depending on the settings of the write protect bits, the erase/write cycle. See Section 3.6 for
device may or may not be able to write certain blocks more information.
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
To read a data memory location, the user must write the 1. If step 10 is not implemented, check the WR bit
address to the EEADR register, clear the EEPGD con- to see if a write is in progress.
trol bit (EECON1<7>), and then set control bit RD 2. Write the address to EEADR. Make sure that the
(EECON1<0>). The data is available in the very next address is not larger than the memory size of
cycle, in the EEDATA register; therefore, it can be read the device.
in the next instruction (see Example 3-1). EEDATA will 3. Write the 8-bit data value to be programmed in
hold this value until another read, or until it is written to the EEDATA register.
by the user (during a write operation). 4. Clear the EEPGD bit to point to EEPROM data
The steps to reading the EEPROM data memory are: memory.
1. Write the address to EEADR. Make sure that the 5. Set the WREN bit to enable program operations.
address is not larger than the memory size of 6. Disable interrupts (if enabled).
the device. 7. Execute the special five instruction sequence:
2. Clear the EEPGD bit to point to EEPROM data • Write 55h to EECON2 in two steps (first to W,
memory. then to EECON2)
3. Set the RD bit to start the read operation. • Write AAh to EECON2 in two steps (first to W,
4. Read the data from the EEDATA register. then to EECON2)
• Set the WR bit
EXAMPLE 3-1: DATA EEPROM READ 8. Enable interrupts (if using interrupts).
BSF STATUS,RP1 ; 9. Clear the WREN bit to disable program
BCF STATUS,RP0 ; Bank 2 operations.
MOVF DATA_EE_ADDR,W ; Data Memory
10. At the completion of the write cycle, the WR bit
MOVWF EEADR ; Address to read
is cleared and the EEIF interrupt flag bit is set.
BSF STATUS,RP0 ; Bank 3
BCF EECON1,EEPGD ; Point to Data (EEIF must be cleared by firmware.) If step 1 is
; memory not implemented, then firmware should check
BSF EECON1,RD ; EE Read for EEIF to be set, or WR to clear, to indicate the
BCF STATUS,RP0 ; Bank 2 end of the program cycle.
MOVF EEDATA,W ; W = EEDATA
EXAMPLE 3-2: DATA EEPROM WRITE
BSF STATUS,RP1 ;
3.4 Writing to Data EEPROM Memory BSF STATUS,RP0
To write an EEPROM data location, the user must first BTFSC EECON,WR1 ;Wait for write
write the address to the EEADR register and the data to GOTO $-1 ;to complete
BCF STATUS, RP0 ;Bank 2
the EEDATA register. Then the user must follow a spe-
MOVF DATA_EE_ADDR,W ;Data Memory
cific write sequence to initiate the write for each byte. MOVWF EEADR ;Address to write
The write will not initiate if the write sequence is not MOVF DATA_EE_DATA,W ;Data Memory Value
exactly followed (write 55h to EECON2, write AAh to MOVWF EEDATA ;to write
EECON2, then set WR bit) for each byte. We strongly BSF STATUS,RP0 ;Bank 3
recommend that interrupts be disabled during this BCF EECON1,EEPGD ;Point to DATA
;memory
code segment (see Example 3-2).
BSF EECON1,WREN ;Enable writes
Additionally, the WREN bit in EECON1 must be set to
enable write. This mechanism prevents accidental BCF INTCON,GIE ;Disable INTs.
writes to data EEPROM due to errant (unexpected) MOVLW 55h ;
Sequence
code execution (i.e., lost programs). The user should MOVWF EECON2 ;Write 55h
Required
keep the WREN bit clear at all times, except when MOVLW AAh ;
MOVWF EECON2 ;Write AAh
updating EEPROM. The WREN bit is not cleared
BSF EECON1,WR ;Set WR bit to
by hardware ;begin write
After a write sequence has been initiated, clearing the BSF INTCON,GIE ;Enable INTs.
WREN bit will not affect this write cycle. The WR bit will BCF EECON1,WREN ;Disable writes
be inhibited from being set unless the WREN bit is set.
At the completion of the write cycle, the WR bit is
cleared in hardware and the EE Write Complete
Interrupt Flag bit (EEIF) is set. The user can either
enable this interrupt or poll this bit. EEIF must be
cleared by software.
;
NOP
NOP ; Any instructions here are ignored as program
; memory is read in second cycle after BSF EECON1,RD
;
BCF STATUS, RP0 ;
MOVF EEDATA, W ; W = LS Byte of Program EEDATA
MOVWF DATAL ;
MOVF EEDATH, W ; W = MS Byte of Program EEDATA
MOVWF DATAH ;
14 14 14 14
Program Memory
10Ch EEDATA EEPROM/FLASH Data Register Low Byte xxxx xxxx uuuu uuuu
10Dh EEADR EEPROM/FLASH Address Register Low Byte xxxx xxxx uuuu uuuu
10Eh EEDATH — — EEPROM/FLASH Data Register High Byte xxxx xxxx ---0 q000
10Fh EEADRH — — — EEPROM/FLASH Address Register High Byte xxxx xxxx ---- ----
18Ch EECON1 EEPGD — — — WRERR WREN WR RD x--- x000 ---0 q000
18Dh EECON2 EEPROM Control Register2 (not a physical register) ---- ---- ---- ----
0Dh PIR2 — CMIF — EEIF BCLIF — — CCP2IF -0-0 0--0 -0-0 0--0
8Dh PIE2 — CMIE — EEIE BCLIE — — CCP2IE -0-0 0--0 -0-0 0--0
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0', q = value depends upon condition.
Shaded cells are not used by Data EEPROM or FLASH Program Memory.
Data Latch
Data Bus D Q 1
N I/O pin(1)
WR PORTA
CK Q 0
WR TRISA Schmitt
CK Q
Trigger
Input
Buffer
RD TRISA
Q D
ENEN
RD PORTA
Data Latch
Data Bus 1 VDD
D Q
WR PORTA P
CK Q 0
TRIS Latch
N I/O pin(1)
D Q
WR TRISA
CK Q VSS Schmitt
Trigger
Input
Buffer
RD TRISA
Q D
ENEN
RD PORTA
05h PORTA — — RA5 RA4 RA3 RA2 RA1 RA0 --0x 0000 --0u 0000
85h TRISA — — PORTA Data Direction Register --11 1111 --11 1111
9Ch CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0111 0000 0111
9Dh CVRCON CVREN CVROE CVRR — CVR3 CVR2 CVR1 CVR0 000- 0000 000- 0000
9Fh ADCON1 ADFM ADCS2 — — PCFG3 PCFG2 PCFG1 PCFG0 --0- 0000 --0- 0000
Legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. Shaded cells are not used by 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.
Q D WR TRIS TTL
CK Input
RD Port
Buffer ST
EN Buffer
RB0/INT RD TRIS
RB3/PGM Latch
Q D
Schmitt Trigger RD Port
Buffer RD Port
EN Q1
Note 1: I/O pins have diode protection to VDD and VSS. Set RBIF
2: To enable weak pull-ups, set the appropriate TRIS
bit(s) and clear the RBPU bit (OPTION_REG<7>).
Q D
From other RD Port
Four of the PORTB pins, RB7:RB4, have an interrupt- RB7:RB4 pins EN
on-change feature. Only pins configured as inputs can 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) Note 1: I/O pins have diode protection to VDD and VSS.
are compared with the old value latched on the last 2: To enable weak pull-ups, set the appropriate TRIS
read of PORTB. The “mismatch” outputs of RB7:RB4 bit(s) and clear the RBPU bit (OPTION_REG<7>).
are OR’ed together to generate the RB Port Change
Interrupt with flag bit RBIF (INTCON<0>).
06h, 106h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 xxxx xxxx uuuu uuuu
86h, 186h TRISB PORTB Data Direction Register 1111 1111 1111 1111
81h, 181h OPTION_REG RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
Legend: x = unknown, u = unchanged. Shaded cells are not used by PORTB.
CKE
FIGURE 4-6: PORTC BLOCK DIAGRAM SSPSTAT<6>
(PERIPHERAL OUTPUT
Note 1: I/O pins have diode protection to VDD and VSS.
OVERRIDE) RC<2:0>, 2: Port/Peripheral Select signal selects between port data
RC<7:5> and peripheral output.
3: Peripheral OE (output enable) is only activated if
Peripheral Select is active.
Port/Peripheral Select(2)
Data Latch
D Q
WR
TRIS CK Q N
TRIS Latch
VSS
RD
TRIS
Schmitt
Trigger
Peripheral
OE(3) Q D
RD EN
Port
Peripheral Input
07h PORTC RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 xxxx xxxx uuuu uuuu
87h TRISC PORTC Data Direction Register 1111 1111 1111 1111
Legend: x = unknown, u = unchanged
RD
TRIS
Q D
ENEN
RD Port
RD0/PSP0 bit0 ST/TTL(1) Input/output port pin or parallel slave port bit0.
RD1/PSP1 bit1 ST/TTL(1) Input/output port pin or parallel slave port bit1.
RD2/PSP2 bit2 ST/TTL(1) Input/output port pin or parallel slave port bit2.
(1)
RD3/PSP3 bit3 ST/TTL Input/output port pin or parallel slave port bit3.
RD4/PSP4 bit4 ST/TTL(1) Input/output port pin or parallel slave port bit4.
(1)
RD5/PSP5 bit5 ST/TTL Input/output port pin or parallel slave port bit5.
RD6/PSP6 bit6 ST/TTL(1) Input/output port pin or parallel slave port bit6.
RD7/PSP7 bit7 ST/TTL(1) Input/output port pin or parallel slave port bit7.
Legend: ST = Schmitt Trigger input, TTL = TTL input
Note 1: Input buffers are Schmitt Triggers when in I/O mode and TTL buffers when in Parallel Slave Port mode.
08h PORTD RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 xxxx xxxx uuuu uuuu
88h TRISD PORTD Data Direction Register 1111 1111 1111 1111
89h TRISE IBF OBF IBOV PSPMODE — PORTE Data Direction Bits 0000 -111 0000 -111
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTD.
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
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
CS
WR
RD
PORTD<7:0>
IBF
OBF
PSPIF
08h PORTD Port Data Latch when written; Port pins when read xxxx xxxx uuuu uuuu
09h PORTE — — — — — RE2 RE1 RE0 ---- -xxx ---- -uuu
89h TRISE IBF OBF IBOV PSPMODE — PORTE Data Direction Bits 0000 -111 0000 -111
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
9Fh ADCON1 ADFM ADCS2 — — PCFG3 PCFG2 PCFG1 PCFG0 --0- 0000 --0- 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Parallel Slave Port.
Note 1: Bits PSPIE and PSPIF are reserved on the PIC16F873A/876A; always maintain these bits clear.
8
M 1
0
RA4/T0CKI U M
X SYNC
pin U 2 TMR0 Reg
1 0
X Cycles
T0SE
T0CS
PSA Set Flag Bit TMR0IF
on Overflow
PRESCALER
0
M 8-bit Prescaler
U
Watchdog 1 X 8
Timer
8 - to - 1MUX PS2:PS0
PSA
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 (CLKOUT)
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-0 PS2: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 of
In this configuration during SLEEP mode, Timer1 will
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.
Reading the 16-bit value requires some care. Note: The special event triggers from the CCP1
Examples 12-2 and 12-3 in the PICmicro™ Mid-Range and CCP2 modules will not set interrupt
MCU Family Reference Manual (DS33023) show how flag bit TMR1IF (PIR1<0>).
to read and write Timer1 when it is running in Timer1 must be configured for either Timer or Synchro-
Asynchronous mode. nized Counter mode to take advantage of this feature.
If Timer1 is running in Asynchronous Counter mode,
6.5 Timer1 Oscillator this RESET operation may not work.
A crystal oscillator circuit is built-in between pins T1OSI In the event that a write to Timer1 coincides with a spe-
(input) and T1OSO (amplifier output). It is enabled by cial event trigger from CCP1 or CCP2, the write will
setting control bit, T1OSCEN (T1CON<3>). The oscil- take precedence.
lator is a low power oscillator, rated up to 200 kHz. It will
In this mode of operation, the CCPRxH:CCPRxL regis-
continue to run during SLEEP. It is primarily intended
ter pair effectively becomes the period register for
for use with a 32 kHz crystal. Table 6-1 shows the
Timer1.
capacitor selection for the Timer1 oscillator.
The Timer1 oscillator is identical to the LP oscillator.
The user must provide a software time delay to ensure
proper oscillator start-up.
0Bh,8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF RBIF 0000 000x 0000 000u
10Bh, 18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
(1)
8Ch PIE1 PSPIE ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
0Eh TMR1L Holding Register for the Least Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding Register for the Most Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Timer1 module.
Note 1: Bits PSPIE and PSPIF are reserved on the 28-pin devices; always maintain these bits clear.
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
TMR1H TMR1L
CCP1CON<3:0>
Qs
TRISC<2>
PWM duty cycle =(CCPR1L:CCP1CON<5:4>) •
Comparator
Clear Timer, TOSC • (TMR2 prescale value)
CCP1 pin and
latch D.C. CCPR1L and CCP1CON<5:4> can be written to at any
PR2
time, but the duty cycle value is not latched into
CCPR1H until after a match between PR2 and TMR2
Note 1: The 8-bit timer is concatenated with 2-bit internal Q
occurs (i.e., the period is complete). In PWM mode,
clock, or 2 bits of the prescaler, to create 10-bit time-
base. CCPR1H is a read-only register.
The CCPR1H register and a 2-bit internal latch are
A PWM output (Figure 8-4) has a time-base (period)
used to double buffer the PWM duty cycle. This double
and a time that the output stays high (duty cycle). The
buffering is essential for glitch-free PWM operation.
frequency of the PWM is the inverse of the period
(1/period). When the CCPR1H and 2-bit latch match TMR2, con-
catenated with an internal 2-bit Q clock, or 2 bits of the
FIGURE 8-4: PWM OUTPUT TMR2 prescaler, the CCP1 pin is cleared.
The maximum PWM resolution (bits) for a given PWM
Period frequency is given by the formula:
(FOSC
log FPWM )
Duty Cycle
Resolution = bits
log(2)
TMR2 = PR2
Note: If the PWM duty cycle value is longer than
TMR2 = Duty Cycle
the PWM period, the CCP1 pin will not be
TMR2 = PR2 cleared.
PWM Frequency 1.22 kHz 4.88 kHz 19.53 kHz 78.12kHz 156.3 kHz 208.3 kHz
Timer Prescaler (1, 4, 16) 16 4 1 1 1 1
PR2 Value 0xFFh 0xFFh 0xFFh 0x3Fh 0x1Fh 0x17h
Maximum Resolution (bits) 10 10 10 8 7 5.5
0Bh,8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF RBIF 0000 000x 0000 000u
10Bh, 18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
0Dh PIR2 — — — — — — — CCP2IF ---- ---0 ---- ---0
(1)
8Ch PIE1 PSPIE ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
8Dh PIE2 — — — — — — — CCP2IE ---- ---0 ---- ---0
87h TRISC PORTC Data Direction Register 1111 1111 1111 1111
0Eh TMR1L Holding Register for the Least Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding Register for the Most Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
15h CCPR1L Capture/Compare/PWM Register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM Register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
1Bh CCPR2L Capture/Compare/PWM Register2 (LSB) xxxx xxxx uuuu uuuu
1Ch CCPR2H Capture/Compare/PWM Register2 (MSB) xxxx xxxx uuuu uuuu
1Dh CCP2CON — — CCP2X CCP2Y CCP2M3 CCP2M2 CCP2M1 CCP2M0 --00 0000 --00 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by Capture and Timer1.
Note 1: The PSP is not implemented on 28-pin devices; always maintain these bits clear.
0Bh,8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF RBIF 0000 000x 0000 000u
10Bh, 18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
0Dh PIR2 — — — — — — — CCP2IF ---- ---0 ---- ---0
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
8Dh PIE2 — — — — — — — CCP2IE ---- ---0 ---- ---0
87h TRISC PORTC Data Direction Register 1111 1111 1111 1111
11h TMR2 Timer2 Module’s Register 0000 0000 0000 0000
92h PR2 Timer2 Module’s Period Register 1111 1111 1111 1111
12h T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
15h CCPR1L Capture/Compare/PWM Register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM Register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
1Bh CCPR2L Capture/Compare/PWM Register2 (LSB) xxxx xxxx uuuu uuuu
1Ch CCPR2H Capture/Compare/PWM Register2 (MSB) xxxx xxxx uuuu uuuu
1Dh CCP2CON — — CCP2X CCP2Y CCP2M3 CCP2M2 CCP2M1 CCP2M0 --00 0000 --00 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PWM and Timer2.
Note 1: Bits PSPIE and PSPIF are reserved on 28-pin devices; always maintain these bits clear.
RC3/ SSPM3:SSPM0
9.2 Control Registers SCK/ SMP:CKE 4
The MSSP module has three associated registers.
SCL/
LVDIN 2 (
TMR2 output
2 )
These include a status register (SSPSTAT) and two Edge
Select Prescaler TOSC
control registers (SSPCON and SSPCON2). The uses
of these registers and their individual configuration bits 4, 16, 64
differ significantly, depending on whether the MSSP
Data to TX/RX in SSPSR
module is operated in SPI or I2C mode. TRIS bit
Additional details are provided under the individual
sections.
9.3 SPI Mode Note: When the SPI is in Slave mode with SS pin
control enabled (SSPCON<3:0> = 0100),
The SPI mode allows 8 bits of data to be synchronously the state of the SS pin can affect the state
transmitted and received simultaneously. All four read back from the TRISC<5> bit. The
modes of SPI are supported. To accomplish communi- Peripheral OE signal from the SSP module
cation, typically three pins are used: into PORTC, controls the state that is read
• Serial Data Out (SDO) - RC5/SDO back from the TRISC<5> bit (see
Section 4.3 for information on PORTC). If
• Serial Data In (SDI) - RC4/SDI/SDA
Read-Modify-Write instructions, such as
• Serial Clock (SCK) - RC3/SCK/SCL/LVDIN BSF, are performed on the TRISC register
Additionally a fourth pin may be used when in a Slave while the SS pin is high, this will cause the
mode of operation: TRISC<5> bit to be set, thus disabling the
• Slave Select (SS) - RA5/SS/AN4 SDO output.
REGISTER 9-1: SSPSTAT: MSSP STATUS REGISTER (SPI MODE) (ADDRESS 94h)
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
SDO SDI
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)
SSPIF
Next Q4 cycle
SSPSR to after Q2↓
SSPBUF
The SS pin allows a Synchronous Slave mode. The To emulate two-wire communication, the SDO pin can
SPI must be in Slave mode with SS pin control be connected to the SDI pin. When the SPI needs to
enabled (SSPCON<3:0> = 04h). The pin must not operate as a receiver, the SDO pin can be configured
be driven low for the SS pin to function as an input. as an input. This disables transmissions from the SDO.
The Data Latch must be high. When the SS pin is The SDI can always be left as an input (SDI function)
low, transmission and reception are enabled and since it cannot create a bus conflict.
the SDO pin is driven. When the SS pin goes high,
SS
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDI bit0
(SMP = 0) bit7 bit7
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
SSPSR to after Q2↓
SSPBUF
SS
optional
SCK
(CKP = 0
CKE = 0)
SCK
(CKP = 1
CKE = 0)
Write to
SSPBUF
SDI
(SMP = 0) bit7 bit0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
SSPSR to after Q2↓
SSPBUF
SS
not optional
SCK
(CKP = 0
CKE = 1)
SCK
(CKP = 1
CKE = 1)
Write to
SSPBUF
SDI
(SMP = 0) bit7 bit0
Input
Sample
(SMP = 0)
SSPIF
Interrupt
Flag
Next Q4 cycle
after Q2↓
SSPSR to
SSPBUF
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).
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR reset ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
DS39582A-page 84
PIC16F87XA
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
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
SSPIF
Bus Master
(PIR1<3>) terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
Advance Information
SSPOV (SSPCON<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
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 software SSPBUF is written in software
Advance Information
CKP
I2C SLAVE MODE TIMING (TRANSMISSION, 7-BIT ADDRESS)
DS39582A-page 85
PIC16F87XA
FIGURE 9-10:
DS39582A-page 86
Clock is held low until Clock is held low until
update of SSPADD has update of SSPADD has
taken place taken place
Receive First Byte of Address Receive Second Byte of Address Receive Data Byte Receive Data Byte
R/W = 0 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 3 4 5 6 7 8 9
S 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.
Advance Information
UA (SSPSTAT<1>)
Bus Master
terminates
Clock is held low until Clock is held low until transfer
update of SSPADD has update of SSPADD has Clock is held low until
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 Sr P
SSPIF
(PIR1<3>)
Cleared in software Cleared in software Cleared in software
BF (SSPSTAT<0>)
Advance Information
UA is set indicating that Cleared by hardware when Cleared by hardware when
the SSPADD needs to be SSPADD is updated with low SSPADD is updated with high
updated byte of address. byte of address.
DS39582A-page 87
PIC16F87XA
PIC16F87XA
9.4.4 CLOCK STRETCHING 9.4.4.3 Clock Stretching for 7-bit Slave
Transmit Mode
Both 7 and 10-bit Slave modes implement automatic
clock stretching during a transmit sequence. 7-bit Slave Transmit mode implements clock stretching
by clearing the CKP bit after the falling edge of the
The SEN bit (SSPCON2<0>) allows clock stretching to
ninth clock, if the BF bit is clear. This occurs regard-
be enabled during receives. Setting SEN will cause
less of the state of the SEN bit.
the SCL pin to be held low at the end of each data
receive sequence. The user’s ISR must set the CKP bit before transmis-
sion is allowed to continue. By holding the SCL line
9.4.4.1 Clock Stretching for 7-bit Slave low, the user has time to service the ISR and load the
Receive Mode (SEN = 1) contents of the SSPBUF before the master device can
In 7-bit Slave Receive mode, on the falling edge of the initiate another transmit sequence (see Figure 9-9).
ninth clock at the end of the ACK sequence, if the BF Note 1: If the user loads the contents of SSPBUF,
bit is set, the CKP bit in the SSPCON register is auto- setting the BF bit before the falling edge of
matically cleared, forcing the SCL output to be held the ninth clock, the CKP bit will not be
low. The CKP being cleared to ‘0’ will assert the SCL cleared and clock stretching will not occur.
line low. The CKP bit must be set in the user’s ISR
2: The CKP bit can be set in software
before reception is allowed to continue. By holding the
regardless of the state of the BF bit.
SCL line low, the user has time to service the ISR and
read the contents of the SSPBUF before the master 9.4.4.4 Clock Stretching for 10-bit Slave
device can initiate another receive sequence. This will
Transmit Mode
prevent buffer overruns from occurring (see
Figure 9-13). In 10-bit Slave Transmit mode, clock stretching is con-
trolled during the first two address sequences by the
Note 1: If the user reads the contents of the state of the UA bit, just as it is in 10-bit Slave Receive
SSPBUF before the falling edge of the mode. The first two addresses are followed by a third
ninth clock, thus clearing the BF bit, the address sequence, which contains the high order bits
CKP bit will not be cleared and clock of the 10-bit address and the R/W bit set to ‘1’. After
stretching will not occur. the third address sequence is performed, the UA bit is
2: The CKP bit can be set in software, not set, the module is now configured in Transmit
regardless of the state of the BF bit. The mode, and clock stretching is controlled by the BF flag
user should be careful to clear the BF bit as in 7-bit Slave Transmit mode (see Figure 9-11).
in the ISR before the next receive
sequence in order to prevent an overflow
condition.
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
Master device
CKP asserts clock
Master device
de-asserts clock
WR
SSPCON
DS39582A-page 90
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
PIC16F87XA
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
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
SSPIF
Bus Master
(PIR1<3>) terminates
transfer
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
Advance Information
SSPOV (SSPCON<6>)
SSPOV is set
because SSPBUF is
still full. ACK is not sent.
CKP
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
I2C SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESS)
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>)
Advance Information
UA is set indicating that Cleared by hardware when Cleared by hardware when
the SSPADD needs to be SSPADD is updated with low SSPADD is updated with high
updated byte of address after falling edge byte of address after falling edge
of ninth clock. of ninth clock.
DS39582A-page 91
PIC16F87XA
PIC16F87XA
9.4.5 GENERAL CALL ADDRESS If the general call address matches, the SSPSR is
SUPPORT transferred to the SSPBUF, the BF flag bit is set (eighth
bit), and on the falling edge of the ninth bit (ACK bit),
The addressing procedure for the I2C bus is such that the SSPIF interrupt flag bit is set.
the first byte after the START condition usually deter-
mines which device will be the slave addressed by the When the interrupt is serviced, the source for the inter-
master. The exception is the general call address, rupt can be checked by reading the contents of the
which can address all devices. When this address is SSPBUF. The value can be used to determine if the
used, all devices should, in theory, respond with an address was device specific or a general call address.
Acknowledge. In 10-bit mode, the SSPADD is required to be updated
The general call address is one of eight addresses for the second half of the address to match, and the UA
reserved for specific purposes by the I2C protocol. It bit is set (SSPSTAT<1>). If the general call address is
consists of all 0’s with R/W = 0. sampled when the GCEN bit is set, while the slave is
configured in 10-bit Address mode, then the second
The general call address is recognized when the Gen- half of the address is not necessary, the UA bit will not
eral Call Enable bit (GCEN) is enabled (SSPCON2<7> be set, and the slave will begin receiving data after the
set). Following a START bit detect, 8-bits are shifted Acknowledge (Figure 9-15).
into the SSPSR and the address is compared against
the SSPADD. It is also compared to the general call
address and fixed in hardware.
SCL
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
S
SSPIF
BF (SSPSTAT<0>)
Cleared in software
SSPBUF is read
SSPOV (SSPCON<6>) ’0’
Internal SSPM3:SSPM0
Data Bus SSPADD<6:0>
Read Write
SSPBUF Baud
Rate
Generator
SDA Shift
Clock Arbitrate/WCOL Detect
SDA In Clock
SSPSR
(hold off clock source)
MSb LSb
Receive Enable
Acknowledge
Generate
SCL
SSPM3:SSPM0 SSPADD<6:0>
FSCL
FCY FCY*2 BRG VALUE
(2 rollovers of BRG)
10 MHz 20 MHz 19h 400 kHz(1)
10 MHz 20 MHz 20h 312.5 kHz
10 MHz 20 MHz 3Fh 100 kHz
4 MHz 8 MHz 0Ah 400 kHz(1)
4 MHz 8 MHz 0Dh 308 kHz
4 MHz 8 MHz 28h 100 kHz
1 MHz 2 MHz 03h 333 kHz(1)
1 MHz 2 MHz 0Ah 100 kHz
1 MHz 2 MHz 00h 1 MHz(1)
Note 1: The I2C interface does not conform to the 400 kHz I2C specification (which applies to rates greater than
100 kHz) in all details, but may be used with care where higher rates are required by the application.
SDA DX DX-1
BRG decrements on
Q2 and Q4 cycles
BRG
03h 02h 01h 00h (hold off) 03h 02h
Value
SCL
TBRG
S
Set S (SSPSTAT<3>)
Write to SSPCON2
SDA = 1,
occurs here. At completion of START bit,
SDA = 1, SCL = 1
hardware clear RSEN bit
SCL (no change) and set SSPIF
1st Bit
SDA
Falling edge of ninth clock Write to SSPBUF occurs here.
End of Xmit
TBRG
SCL TBRG
Sr = Repeated START
DS39582A-page 100
Write SSPCON2<0> SEN = 1 ACKSTAT in
START condition begins SSPCON2 = 1
From Slave, clear ACKSTAT bit SSPCON2<6>
SEN = 0
Transmitting Data or Second Half
PIC16F87XA
SDA A7 A6 A5 A4 A3 A2 A1 ACK = 0 D7 D6 D5 D4 D3 D2 D1 D0
BF (SSPSTAT<0>)
Advance Information
SEN
PEN
R/W
I 2C MASTER MODE WAVEFORM (TRANSMISSION, 7 OR 10-BIT ADDRESS)
Write to SSPCON2<4>
to start Acknowledge sequence
SDA = ACKDT (SSPCON2<5>) = 0
Write to SSPCON2<0> (SEN = 1)
Begin START Condition ACK from Master Set ACKEN, start Acknowledge sequence
Master configured as a receiver SDA = ACKDT = 0 SDA = ACKDT = 1
SEN = 0 by programming SSPCON2<3>, (RCEN = 1)
Bus Master
ACK is not sent terminates
transfer
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
SCL 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
Cleared in software Cleared in software Cleared in software Cleared in software (SSPSTAT<4>)
SDA = 0, SCL = 1 Cleared in
while CPU software and SSPIF
responds to SSPIF
Advance Information
BF
(SSPSTAT<0>) Last bit is shifted into SSPSR and
contents are unloaded into SSPBUF
SSPOV
ACKEN
I 2C MASTER MODE WAVEFORM (RECEPTION, 7-BIT ADDRESS)
DS39582A-page 101
PIC16F87XA
PIC16F87XA
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 bit of the ninth clock. When the PEN bit is set, the master
is presented on the SDA pin. If the user wishes to gen- will assert the SDA line low. When the SDA line is sam-
erate an Acknowledge, then the ACKDT bit should be pled low, the baud rate generator is reloaded and
cleared. If not, the user should set the ACKDT bit before counts down to 0. When the baud rate generator times
starting an Acknowledge sequence. The baud rate gen- out, the SCL pin will be brought high, and one TBRG
erator then counts for one rollover period (TBRG) and (baud rate generator rollover count) later, the SDA pin
the SCL pin is de-asserted (pulled high). When the SCL will be de-asserted. When the SDA pin is sampled high
pin is sampled high (clock arbitration), the baud rate while SCL is high, the P bit (SSPSTAT<4>) is set. A
generator counts for TBRG. The SCL pin is then pulled TBRG later, the PEN bit is cleared and the SSPIF bit is
low. Following this, the ACKEN bit is automatically set (Figure 9-24).
cleared, the baud rate generator is turned off and the
MSSP module then goes into IDLE mode (Figure 9-23). 9.4.13.1 WCOL Status Flag
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-
If the user writes the SSPBUF when an Acknowledge tents of the buffer are unchanged (the write doesn’t
sequence is in progress, then WCOL is set and the occur).
contents of the buffer are unchanged (the write doesn’t
occur).
SCL 8 9
SSPIF
Cleared in
Set SSPIF at the end Cleared in
software
of receive software
Set SSPIF at the end
of Acknowledge sequence
Note: TBRG = one baud rate generator period.
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.
Data changes SDA line pulled low Sample SDA. While SCL is high
while SCL = 0 by another source data doesn’t match what is driven
by the master. Bus collision has occurred.
SDA released
by master
SDA
BCLIF
SDA
SCL
Set SEN, enable START SEN cleared automatically because of bus collision.
condition if SDA = 1, SCL=1 SSP module reset into IDLE state.
SEN
SDA sampled low before
START condition. Set BCLIF.
S bit and SSPIF set because
BCLIF SDA = 0, SCL = 1.
SSPIF and BCLIF are
cleared in software.
SSPIF
SDA = 0, SCL = 1
TBRG TBRG
SDA
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
Set SSPIF in software.
SDA
SCL
RSEN
BCLIF
Cleared in software
S '0'
SSPIF '0'
TBRG TBRG
SDA
SCL
S ’0’
SSPIF
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
Word 1
TRMT bit Transmit Shift Reg
(Transmit Shift
Reg. Empty Flag)
RC7/RX/DT
Pin Buffer Data
and Control Recovery RX9
Interrupt RCIF
Data Bus
RCIE
RCIF
(Interrupt Flag)
OERR bit
CREN
Note: This timing diagram shows three words appearing on the RX input. The RCREG (receive buffer) is read after the third word,
causing the OERR (overrun) bit to be set.
When setting up an Asynchronous Reception, follow 6. Flag bit RCIF will be set when reception is com-
these steps: plete and an interrupt will be generated if enable
1. Initialize the SPBRG register for the appropriate bit RCIE is set.
baud rate. If a high speed baud rate is desired, 7. Read the RCSTA register to get the ninth bit (if
set bit BRGH (Section 10.1). enabled) and determine if any error occurred
2. Enable the asynchronous serial port by clearing during reception.
bit SYNC and setting bit SPEN. 8. Read the 8-bit received data by reading the
3. If interrupts are desired, then set enable bit RCREG register.
RCIE. 9. If any error occurred, clear the error by clearing
4. If 9-bit reception is desired, then set bit RX9. enable bit CREN.
5. Enable the reception by setting bit CREN. 10. If using interrupts, ensure that GIE and PEIE
(bits 7 and 6) of the INTCON register are set.
RC7/RX/DT
Pin Buffer Data
and Control Recovery RX9
SPEN
RX9 Enable
ADDEN Load of
RX9 Receive
Buffer
ADDEN
RSR<8> 8
Interrupt RCIF
Data Bus
RCIE
Load RSR
Bit8 = 0, Data Byte Bit8 = 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.
Load RSR
Bit8 = 1, Address Byte Bit8 = 0, Data 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 was not updated and still = 0.
Write to
TXREG reg
Write Word 1 Write Word 2
TXIF bit
(Interrupt Flag)
TRMT bit
’1’ ’1’
TXEN bit
Note: Sync Master mode; SPBRG = ’0’. Continuous transmission of two 8-bit words.
RC6/TX/CK pin
Write to
TXREG Reg
TXIF bit
TRMT bit
TXEN bit
Value on
Value on:
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 all other
POR, BOR
RESETS
0Bh, 8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF R0IF 0000 000x 0000 000u
10Bh,18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
18h RCSTA SPEN RX9 SREN CREN — FERR OERR RX9D 0000 -00x 0000 -00x
1Ah RCREG USART Receive Register 0000 0000 0000 0000
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for synchronous master reception.
Note 1: Bits PSPIE and PSPIF are reserved on 28-pin devices; always maintain these bits clear.
RC7/RX/DT pin bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7
RC6/TX/CK pin
Write to
bit SREN
SREN bit
RCIF bit
(Interrupt)
Read
RXREG
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 externally at 1. Enable the synchronous slave serial port by set-
the RC6/TX/CK pin (instead of being supplied internally ting bits SYNC and SPEN and clearing bit
in Master mode). This allows the device to transfer or CSRC.
receive data while in SLEEP mode. Slave mode is 2. Clear bits CREN and SREN.
entered by clearing bit CSRC (TXSTA<7>). 3. If interrupts are desired, then set enable bit
TXIE.
10.4.1 USART SYNCHRONOUS SLAVE 4. If 9-bit transmission is desired, then set bit TX9.
TRANSMIT 5. Enable the transmission by setting enable bit
The operation of the Synchronous Master and Slave TXEN.
modes is identical, except in the case of the SLEEP mode. 6. If 9-bit transmission is selected, the ninth bit
If two words are written to the TXREG and then the should be loaded in bit TX9D.
SLEEP instruction is executed, the following will occur: 7. Start transmission by loading data to the TXREG
register.
a) The first word will immediately transfer to the
TSR register and transmit. 8. If using interrupts, ensure that GIE and PEIE
(bits 7 and 6) of the INTCON register are set.
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 inter-
rupt vector (0004h).
Value on
Value on:
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 all other
POR, BOR
RESETS
0Bh, 8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF R0IF 0000 000x 0000 000u
10Bh,18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
18h RCSTA SPEN RX9 SREN CREN ADDEN FERR OERR RX9D 0000 000x 0000 000x
19h TXREG USART Transmit Register 0000 0000 0000 0000
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for synchronous slave transmission.
Note 1: Bits PSPIE and PSPIF are reserved on 28-pin devices; always maintain these bits clear.
10.4.2 USART SYNCHRONOUS SLAVE When setting up a Synchronous Slave Reception, fol-
RECEPTION low these steps:
The operation of the Synchronous Master and Slave 1. Enable the synchronous master serial port by
modes is identical, except in the case of the SLEEP setting bits SYNC and SPEN and clearing bit
mode. Bit SREN is a “don't care” in Slave mode. CSRC.
2. If interrupts are desired, set enable bit RCIE.
If receive is enabled by setting bit CREN prior to the
SLEEP instruction, then a word may be received during 3. If 9-bit reception is desired, set bit RX9.
SLEEP. On completely receiving the word, the RSR 4. To enable reception, set enable bit CREN.
register will transfer the data to the RCREG register 5. Flag bit RCIF will be set when reception is com-
and if enable bit RCIE bit is set, the interrupt generated plete and an interrupt will be generated, if
will wake the chip from SLEEP. If the global interrupt is enable bit RCIE was set.
enabled, the program will branch to the interrupt vector 6. Read the RCSTA register to get the ninth bit (if
(0004h). enabled) and determine if any error occurred
during reception.
7. Read the 8-bit received data by reading the
RCREG register.
8. If any error occurred, clear the error by clearing
bit CREN.
9. If using interrupts, ensure that GIE and PEIE
(bits 7 and 6) of the INTCON register are set.
Value on
Value on:
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 all other
POR, BOR
RESETS
0Bh, 8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF R0IF 0000 000x 0000 000u
10Bh,18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
18h RCSTA SPEN RX9 SREN CREN ADDEN FERR OERR RX9D 0000 000x 0000 000x
1Ah RCREG USART Receive Register 0000 0000 0000 0000
(1)
8Ch PIE1 PSPIE ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for synchronous slave reception.
Note 1: Bits PSPIE and PSPIF are reserved on 28-pin devices, always maintain these bits clear.
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)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR reset ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
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)
PCFG
AN7 AN6 AN5 AN4 AN3 AN2 AN1 AN0 VREF+ VREF- C/R
<3:0>
0000 A A A A A A A A VDD VSS 8/0
0001 A A A A VREF+ A A A AN3 VSS 7/1
0010 D D D A A A A A VDD VSS 5/0
0011 D D D A VREF+ A A A AN3 VSS 4/1
0100 D D D D A D A A VDD VSS 3/0
0101 D D D D VREF+ D A A AN3 VSS 2/1
011x D D D D D D D D — — 0/0
1000 A A A A VREF+ VREF- A A AN3 AN2 6/2
1001 D D A A A A A A VDD VSS 6/0
1010 D D A A VREF+ A A A AN3 VSS 5/1
1011 D D A A VREF+ VREF- A A AN3 AN2 4/2
1100 D D D A VREF+ VREF- A A AN3 AN2 3/2
1101 D D D D VREF+ VREF- A A AN3 AN2 2/2
1110 D D D D D D D A VDD VSS 1/0
1111 D D D D VREF+ VREF- D A AN3 AN2 1/2
A = Analog input D = Digital I/O
C / R = # of analog input channels / # of A/D voltage references
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR reset ’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+
A/D 010
Converter RA2/AN2/VREF-
001
VDD RA1/AN1
000
VREF+ RA0/AN0
(Reference
Voltage)
PCFG3:PCFG0
VREF-
(Reference
Voltage)
VSS
PCFG3:PCFG0
= TAMP + TC + TCOFF
= 2µs + TC + [(Temperature -25°C)(0.05µs/°C)]
TC = CHOLD (RIC + RSS + RS) In(1/2047)
= - 120pF (1kΩ + 7kΩ + 10kΩ) In(0.0004885)
= 16.47µs
TACQ = 2µs + 16.47µs + [(50°C -25°C)(0.05µs/°C)
= 19.72µs
Note 1: The reference voltage (VREF) has no effect on the equation, since it cancels itself out.
2: The charge holding capacitor (CHOLD) is not discharged after each conversion.
3: The maximum recommended impedance for analog sources is 10 kΩ. This is required to meet the pin
leakage specification.
CHOLD
VA CPIN I LEAKAGE = DAC capacitance
5 pF VT = 0.6V ± 500 nA = 120 pF
VSS
TABLE 11-1: TAD vs. MAXIMUM DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (C))
TCY to TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0
Conversion starts
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 justi-
The ADRESH:ADRESL register pair is the location fication. The extra bits are loaded with ’0’s’. When an
where the 10-bit A/D result is loaded at the completion A/D result will not overwrite these locations (A/D dis-
of the A/D conversion. This register pair is 16-bits wide. able), these registers may be used as two general
The A/D module gives the flexibility to left or right justify purpose 8-bit registers.
the 10-bit result in the 16-bit result register. The A/D
10-bit Result
ADFM = 1 ADFM = 0
7 2107 0 7 0765 0
0000 00 0000 00
Value on Value on
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 POR, MCLR,
BOR WDT
0Bh,8Bh, INTCON GIE PEIE TMR0IE INTE RBIE TMR0IF INTF RBIF 0000 000x 0000 000u
10Bh,18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
1Eh ADRESH A/D Result Register High Byte xxxx xxxx uuuu uuuu
9Eh ADRESL A/D Result Register Low Byte xxxx xxxx uuuu uuuu
1Fh ADCON0 ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON 0000 00-0 0000 00-0
9Fh ADCON1 ADFM ADCS2 — — PCFG3 PCFG2 PCFG1 PCFG0 00-- 0000 00-- 0000
85h TRISA — — PORTA Data Direction Register --11 1111 --11 1111
05h PORTA — — PORTA Data Latch when written: PORTA pins when read --0x 0000 --0u 0000
89h(1) TRISE IBF OBF IBOV PSPMODE — PORTE Data Direction bits 0000 -111 0000 -111
09h(1) PORTE — — — — — RE2 RE1 RE0 ---- -xxx ---- -uuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used for A/D conversion.
Note 1: These registers are not available on 28-pin devices.
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
A VIN- A
RA1/AN1 VIN-
RA1/AN1
A VIN+ C2 C2OUT C2OUT
RA2/AN2 A VIN+ C2
RA2/AN2
RA5/SS/AN4/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
RA2/AN2
D VIN+ C2 C2OUT
RA2/AN2
RA5/SS/AN4/C2OUT
One Independent Comparator with Output Four Inputs Multiplexed to Two Comparators
CM2:CM0 = 001 CM2:CM0 = 110
A VIN- A
RA0/AN0 RA0/AN0 CIS = 0 VIN-
A VIN+ C1 C1OUT RA3/AN3 A CIS = 1
RA3/AN3 VIN+ C1 C1OUT
RA4/T0CKI/C1OUT A
RA1/AN1 CIS = 0 VIN-
A CIS = 1
RA2/AN2 VIN+ C2 C2OUT
D VIN-
RA1/AN1
D VIN+ C2 Off (Read as ’0’)
RA2/AN2 CVREF From Comparator
VREF Module
A = Analog Input, port reads zeros always. D = Digital Input. CIS (CMCON<3>) is the Comparator Input Switch.
MULTIPLEX
+ -
CxINV
To RA4 or
RA5 Pin
Bus Q D
Data
Read CMCON EN
Set
CMIF Q D
bit From
Other EN
Comparator
CL Read CMCON
RESET
VDD
VT = 0.6 V RIC
RS < 10K
AIN
CPIN ILEAKAGE
VA VT = 0.6 V ±500 nA
5 pF
VSS
Value on
Value on
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 All Other
POR
RESETS
9Ch CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0111 0000 0111
9Dh CVRCON CVREN CVROE CVRR — CVR3 CVR2 CVR1 CVR0 000- 0000 000- 0000
0Bh, 8Bh, INTCON GIE/ PEIE/ TMR0IE INTIE RBIE TMR0IF INTIF RBIF 0000 000x 0000 000u
10Bh,18Bh GIEH GIEL
0Dh PIR2 — CMIF — — BCLIF LVDIF TMR3IF CCP2IF -0-- 0000 -0-- 0000
8Dh PIE2 — CMIE — — BCLIE LVDIE TMR3IE CCP2IE -0-- 0000 -0-- 0000
05h PORTA — — RA5 RA4 RA3 RA2 RA1 RA0 --0x 0000 --0u 0000
85h TRISA — — PORTA Data Direction Register --11 1111 --11 1111
Legend: x = unknown, u = unchanged, - = unimplemented, read as “0”. Shaded cells are unused by the comparator module.
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
CVREF CVR2
16:1 Analog MUX
Input to CVR1
Comparator CVR0
Value On
Value On
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 All Other
POR
RESETS
9Dh CVRCON CVREN CVROE CVRR — CVR3 CVR2 CVR1 CVR0 000- 0000 000- 0000
9Ch CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0111 0000 0111
Legend: x = unknown, u = unchanged, - = unimplemented, read as “0”.
Shaded cells are not used with the comparator voltage reference.
Legend:
R = Readable bit P = Programmable bit U = Unimplemented bit, read as ‘0’
- n = Value when device is unprogrammed u = Unchanged from programmed state
External
Reset
MCLR
SLEEP
WDT WDT
Module Time-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 CLKIN pin.
POR BOR TO PD
0 x 1 1 Power-on Reset
0 x 0 x Illegal, TO is set on POR
0 x x 0 Illegal, PD is set on POR
1 0 1 1 Brown-out Reset
1 1 0 1 WDT Reset
1 1 0 0 WDT Wake-up
1 1 u u MCLR Reset during normal operation
1 1 1 0 MCLR Reset during SLEEP or interrupt wake-up from SLEEP
Legend: x = don’t care, u = unchanged
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
EEIF
EEIE
PSPIF(1)
PSPIE(1)
ADIF
ADIE
Wake-up (If in SLEEP mode)
RCIF TMR0IF
RCIE TMR0IE
INTF
TXIF
INTE
TXIE Interrupt to CPU
RBIF
SSPIF RBIE
SSPIE
CCP1IF PEIE
CCP1IE
GIE
TMR2IF
TMR2IE
TMR1IF
TMR1IE
CCP2IF
CCP2IE
BCLIF
BCLIE
CMIF
CMIE
0
M Postscaler
1 U
WDT Timer
X 8
8 - to - 1 MUX PS2:PS0
PSA
WDT
Enable Bit
To TMR0 (Figure 5-1)
0 1
MUX PSA
WDT
Time-out
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
2007h Config. bits (1) BODEN(1) CP1 CP0 PWRTE(1) WDTE FOSC1 FOSC0
81h,181h OPTION_REG RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0
Legend: Shaded cells are not used by the Watchdog Timer.
Note 1: See Register 14-1 for operation of these bits.
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
CLKOUT(4) TOST(2)
INT pin
INTF Flag
(INTCON<1>) Interrupt Latency(2)
GIE bit
(INTCON<7>) Processor in
SLEEP
INSTRUCTION FLOW
PC PC PC+1 PC+2 PC+2 PC + 2 0004h 0005h
Instruction Inst(0004h)
Fetched Inst(PC) = SLEEP Inst(PC + 1) Inst(PC + 2) Inst(0005h)
Instruction SLEEP Inst(PC + 1) Dummy cycle Dummy cycle
Executed Inst(PC - 1) Inst(0004h)
Note: Additional information on the mid-range instruction set is available in the PICmicro™ Mid-Range MCU
Family Reference Manual (DS33023).
The PRO MATE II device programmer has program- 16.12 PICDEM 2 Low Cost PIC16CXX
mable VDD and VPP supplies, which allow it to verify Demonstration Board
programmed memory at VDD min and VDD max for max-
imum reliability. It has an LCD display for instructions The PICDEM 2 demonstration board is a simple dem-
and error messages, keys to enter commands and a onstration board that supports the PIC16C62,
modular detachable socket assembly to support various PIC16C64, PIC16C65, PIC16C73 and PIC16C74
package types. In stand-alone mode, the PRO MATE II microcontrollers. All the necessary hardware and soft-
device programmer can read, verify, or program ware is included to run the basic demonstration pro-
PICmicro devices. It can also set code protection in this grams. The user can program the sample
mode. microcontrollers provided with the PICDEM 2 demon-
stration board on a PRO MATE II device programmer,
16.10 PICSTART Plus Entry Level or a PICSTART Plus development programmer, and
Development Programmer easily test firmware. The MPLAB ICE in-circuit emula-
tor may also be used with the PICDEM 2 demonstration
The PICSTART Plus development programmer is an board to test firmware. A prototype area has been pro-
easy-to-use, low cost, prototype programmer. It con- vided to the user for adding additional hardware and
nects to the PC via a COM (RS-232) port. MPLAB connecting it to the microcontroller socket(s). Some of
Integrated Development Environment software makes the features include a RS-232 interface, push button
using the programmer simple and efficient. switches, a potentiometer for simulated analog input, a
The PICSTART Plus development programmer sup- serial EEPROM to demonstrate usage of the I2CTM bus
ports all PICmicro devices with up to 40 pins. Larger pin and separate headers for connection to an LCD
count devices, such as the PIC16C92X and module and a keypad.
PIC17C76X, may be supported with an adapter socket.
The PICSTART Plus development programmer is CE
compliant.
24CXX/
25CXX/
HCSXXX
PIC14000
MCP2510
PIC16C5X
PIC16C6X
PIC16C7X
PIC16C8X
PIC17C4X
MCRFXXX
PIC16F62X
PIC16F8XX
PIC16C7XX
PIC16C9XX
PIC17C7XX
PIC18CXX2
PIC18FXXX
PIC12CXXX
PIC16CXXX
MPLAB® Integrated
TABLE 16-1:
Development Environment
9
9
9
9
9
9
9
9
9
9
9
9
9
MPLAB® C17 C Compiler
9 9
9 9
MPLAB® C18 C Compiler
MPASMTM Assembler/
Software Tools
MPLINKTM Object Linker
9
9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9 9
9 9 9
ICEPICTM In-Circuit Emulator
9
9
9
9
9
9
9
9
MPLAB® ICD In-Circuit
* *
Debugger
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
PRO MATE® II
Universal Device Programmer **
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
PICDEMTM 2 Demonstration † †
Board
9
9
9
9
DEVELOPMENT TOOLS FROM MICROCHIP
PICDEMTM 3 Demonstration
Advance Information
Board
9
9
PICDEMTM 17 Demonstration
Board
9
* Contact the Microchip Technology Inc. web site at www.microchip.com for information on how to use the MPLAB® ICD In-Circuit Debugger (DV164001) with PIC16C62, 63, 64, 65, 72, 73, 74, 76, 77.
** Contact Microchip Technology Inc. for availability date.
DS39582A-page 169
PIC16F87XA
6.0 V
5.5 V
5.0 V
PIC16F87XA
4.5 V
Voltage
4.0 V
3.5 V
3.0 V
2.5 V
2.0 V
20 MHz
Frequency
6.0 V
5.5 V
5.0 V
4.5 V
Voltage
4.0 V PIC16LF87XA
3.5 V
3.0 V
2.5 V
2.0 V
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.
Note 2: FMAX has a maximum frequency of 10 MHz.
Param
Characteristics Sym Min Typ Max Units Comments
No.
D300 Input Offset Voltage VIOFF — ± 5.0 ± 10 mV
D301 Input Common Mode Voltage* VICM 0 - VDD - 1.5 V
D302 Common Mode Rejection Ratio* CMRR 55 - — dB
300 Response Time (1)* TRESP — 150 400 ns PIC16F87XA
300A 600 ns PIC16LF87XA
301 Comparator Mode Change to TMC2OV — — 10 µs
Output Valid*
* These parameters are characterized but not tested.
Note: Response time measured with one comparator input at (VDD - 1.5)/2 while the other input transitions from
VSS to VDD.
Spec
Characteristics Sym Min Typ Max Units Comments
No.
D310 Resolution VRES VDD/24 — VDD/32 LSb
D311 Absolute Accuracy VRAA — — 1/4 LSb Low Range (VRR = ‘1’)
— — 1/2 LSb High Range (VRR = ‘0’)
D312 Unit Resistor Value (R)* VRUR — 2k — Ω
310 Settling Time (1)* TSET — — 10 µs
* These parameters are characterized but not tested.
Note: Settling time measured while VRR = 1 and VR<3:0> transitions from 0000 to 1111.
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.
OSC1
1 3 3 4 4
2
CLKOUT
Parameter
Sym Characteristic Min Typ† Max Units Conditions
No.
Q4 Q1 Q2 Q3
OSC1
10 11
CLKOUT
13 12
19 18
14 16
I/O Pin
(Input)
17 15
20, 21
Note: Refer to Figure 17-3 for load conditions.
Param
Symbol Characteristic Min Typ† Max Units Conditions
No.
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
31
34
34
I/O Pins
VDD VBOR
35
TABLE 17-5: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER,
AND BROWN-OUT RESET REQUIREMENTS
Parameter
Symbol Characteristic Min Typ† Max Units Conditions
No.
RA4/T0CKI
40 41
42
RC0/T1OSO/T1CKI
45 46
47 48
TMR0 or
TMR1
40* Tt0H T0CKI High Pulse Width No Prescaler 0.5TCY + 20 — — ns Must also meet
With Prescaler 10 — — ns parameter 42
41* Tt0L T0CKI Low Pulse Width No Prescaler 0.5TCY + 20 — — ns Must also meet
With Prescaler 10 — — ns parameter 42
42* Tt0P T0CKI Period No Prescaler TCY + 40 — — ns
With Prescaler Greater of: — — ns N = prescale value
20 or TCY + 40 (2, 4,..., 256)
N
45* Tt1H T1CKI High Time Synchronous, Prescaler = 1 0.5TCY + 20 — — ns Must also meet
Synchronous, Standard(F) 15 — — ns parameter 47
Prescaler = 2,4,8 Extended(LF) 25 — — ns
Asynchronous Standard(F) 30 — — ns
Extended(LF) 50 — — ns
46* Tt1L T1CKI Low Time Synchronous, Prescaler = 1 0.5TCY + 20 — — ns Must also meet
Synchronous, Standard(F) 15 — — ns parameter 47
Prescaler = 2,4,8 Extended(LF) 25 — — ns
Asynchronous Standard(F) 30 — — ns
Extended(LF) 50 — — ns
47* Tt1P T1CKI input Synchronous Standard(F) Greater of: — — ns N = prescale value
period 30 OR TCY + 40 (1, 2, 4, 8)
N
Extended(LF) Greater of: N = prescale value
50 OR TCY + 40 (1, 2, 4, 8)
N
Asynchronous Standard(F) 60 — — ns
Extended(LF) 100 — — ns
Ft1 Timer1 Oscillator Input Frequency Range DC — 200 kHz
(oscillator enabled by setting bit T1OSCEN)
48 TCKEZtmr1 Delay from external clock edge to timer increment 2TOSC — 7TOSC —
* These parameters are characterized but not tested.
† Data in "Typ" column is at 5V, 25°C unless otherwise stated. These parameters are for design guidance only and are
not tested.
RC1/T1OSI/CCP2
and RC2/CCP1
(Capture Mode)
50 51
52
RC1/T1OSI/CCP2
and RC2/CCP1
(Compare or PWM Mode)
53 54
Param
Sym Characteristic Min Typ† Max Units Conditions
No.
RE2/CS
RE0/RD
RE1/WR
65
RD7:RD0
62
64
63
Note: Refer to Figure 17-3 for load conditions.
Parameter
Symbol Characteristic Min Typ† Max Units Conditions
No.
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
82
SS
70
SCK
83
(CKP = 0)
71 72
SCK
(CKP = 1)
80
75, 76 77
SDI
MSb IN BIT6 - - - -1 LSb IN
74
Param
Symbol Characteristic Min Typ† Max Units Conditions
No.
SCL
91 93
90 92
SDA
START STOP
Condition Condition
Parameter
Symbol Characteristic Min Typ Max Units Conditions
No.
90 Tsu:sta START condition 100 kHz mode 4700 — — ns Only relevant for Repeated
START condition
Setup time 400 kHz mode 600 — —
91 Thd:sta START condition 100 kHz mode 4000 — — ns After this period, the first clock
Hold time 400 kHz mode 600 — — pulse is generated
SDA
Out
Param
Sym Characteristic Min Max Units Conditions
No.
100 THIGH Clock high time 100 kHz mode 4.0 — µs Device must operate at a
minimum of 1.5 MHz
400 kHz mode 0.6 — µs Device must operate at a
minimum of 10 MHz
SSP Module 0.5TCY —
101 TLOW Clock low time 100 kHz mode 4.7 — µs Device must operate at a
minimum of 1.5 MHz
400 kHz mode 1.3 — µs Device must operate at a
minimum of 10 MHz
SSP Module 0.5TCY —
102 TR SDA and SCL rise 100 kHz mode — 1000 ns
time
400 kHz mode 20 + 0.1Cb 300 ns Cb is specified to be from
10 to 400 pF
103 TF SDA and SCL fall time 100 kHz mode — 300 ns
400 kHz mode 20 + 0.1Cb 300 ns Cb is specified to be from
10 to 400 pF
90 Tsu:sta START condition 100 kHz mode 4.7 — µs Only relevant for Repeated
setup time µs
START condition
400 kHz mode 0.6 —
91 Thd:sta START condition hold 100 kHz mode 4.0 — µs After this period, the first clock
time pulse is generated
400 kHz mode 0.6 — µs
106 Thd:dat Data input hold time 100 kHz mode 0 — ns
400 kHz mode 0 0.9 µs
107 Tsu:dat Data input setup time 100 kHz mode 250 — ns (Note 2)
400 kHz mode 100 — ns
92 Tsu:sto STOP condition setup 100 kHz mode 4.7 — µs
time
400 kHz mode 0.6 — µs
109 TAA Output valid from 100 kHz mode — 3500 ns (Note 1)
clock 400 kHz mode — — ns
110 TBUF Bus free time 100 kHz mode 4.7 — µs Time the bus must be free
400 kHz mode 1.3 — µs
before a new transmission
can start
CB Bus capacitive loading — 400 pF
Note 1: As a transmitter, the device must provide this internal minimum delay time to bridge the undefined region (min. 300 ns) of
the falling edge of SCL to avoid unintended generation of START or STOP conditions.
2: A fast mode (400 kHz) I2C bus device can be used in a standard mode (100 kHz) I2C bus system, but the requirement that
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.
RC6/TX/CK
Pin 121
121
RC7/RX/DT
Pin
120
122
Note: Refer to Figure 17-3 for load conditions.
RC6/TX/CK
pin 125
RC7/RX/DT
pin
126
Parameter
Sym Characteristic Min Typ† Max Units Conditions
No.
Param
Sym Characteristic Min Typ† Max Units Conditions
No.
A50 IREF VREF input current (Note 2) 10 — 1000 µA During VAIN acquisition.
Based on differential of
VHOLD to VAIN to charge
CHOLD, see Section 11.1.
ADIF
GO DONE
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.
130 TAD A/D clock period Standard(F) 1.6 — — µs TOSC based, VREF ≥ 3.0V
Extended(LF) 3.0 — — µs TOSC based, VREF ≥ 2.0V
Standard(F) 2.0 4.0 6.0 µs A/D RC mode
Extended(LF) 3.0 6.0 9.0 µs A/D RC mode
131 TCNV Conversion time (not including S/H time) — 12 TAD
(Note 1)
132 TACQ Acquisition time (Note 2) 40 — µs
XXXXXXXXXX PIC16F877A
XXXXXXXXXX -/PT
XXXXXXXXXX
YYWWNNN 0111017
XXXXXXXXXX PIC16F877A
XXXXXXXXXX -20/L
XXXXXXXXXX
YYWWNNN 0103017
Note: In the event the full Microchip part number cannot be marked on one line, it will
be carried over to the next line thus limiting the number of available characters
for customer specific information.
* Standard PICmicro device marking consists of Microchip part number, year code, week code, and
traceability code. For PICmicro device marking beyond this, certain price adders apply. Please check
with your Microchip Sales Office. For QTP devices, any special marking adders are included in QTP
price.
XXXXXXXXXXXXXXXXX PIC16F876A-/SO
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
YYWWNNN 0110017
XXXXXXXXXXXX PIC16F876A
XXXXXXXXXXXX -/SO
YYWWNNN 0110017
1
XXXXXXXX
1
PIC16F873A
XXXXXXXX -I/ML
YYWWNNN 0112017
E1
2 α
n 1
A A2
L
c
β B1
A1
eB B 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
n 1 2
CH2 x 45 ° CH1 x 45 °
A3 α
A2 A
35°
B1
c
B A1
β
p
E2 D2
2
n 1 α
E A2
L
c
β A1 B1
eB B p
E
E1
p
B
2
n 1
h
α
45°
c
A A2
φ
β L A1
E1
p
B
2
n 1
α
A
c
A2
φ A1
L
β
D1 D D2
p
2
1 B
n
R
E2
CH x 45 L
TOP VIEW BOTTOM VIEW
A2 A
A1
A3
M B
PACKAGE
SOLDER EDGE
MASK
Timers 3 3 3
Interrupts 11 or 12 13 or 14 14 or 15
Communication PSP, USART, SSP PSP, USART, SSP PSP, USART, SSP
(SPI, I2C Slave) (SPI, I2C Master/Slave) (SPI, I2C Master/Slave)
CCP 2 2 2
Comparator — — 2
RAM 192, 368 bytes 192, 368 bytes 192, 368 bytes
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________ FAX: (______) _________ - _________
Application (optional):
Would you like a reply? Y N
Questions:
2. How does this document meet your hardware and software development needs?
3. Do you find the organization of this data sheet easy to follow? If not, why?
4. What additions to the data sheet do you think would enhance the structure and subject?
5. What deletions from the data sheet could be made without affecting the overall usefulness?
8. How would you improve our software, systems, and silicon products?
Please specify which device, revision of silicon and Data Sheet (include Literature #) you are using.
10/01/01