Pic16f8x PDF
Pic16f8x PDF
Pic16f8x PDF
PIC16CR8X
PIC16F8X
(PIC16LF8X, PIC16LCR8X) MCLR 4 15 OSC2/CLKOUT
VSS 5 14 VDD
High Performance RISC CPU Features: RB0/INT 6 13 RB7
Only 35 single word instructions to learn RB1 7 12 RB6
All instructions single cycle except for program RB2 8 11 RB5
branches which are two-cycle RB3 9 10 RB4
The PIC16F8X has up to 68 bytes of RAM, 64 bytes of 1.1 Family and Upward Compatibility
Data EEPROM memory, and 13 I/O pins. A timer/
counter is also available. Those users familiar with the PIC16C5X family of
microcontrollers will realize that this is an enhanced
The PIC16CXX family has special features to reduce
version of the PIC16C5X architecture. Please refer to
external components, thus reducing cost, enhancing
Appendix A for a detailed list of enhancements. Code
system reliability and reducing power consumption.
written for PIC16C5X devices can be easily ported to
There are four oscillator options, of which the single pin
PIC16F8X devices (Appendix B).
RC oscillator provides a low-cost solution, the LP
oscillator minimizes power consumption, XT is a 1.2 Development Support
standard crystal, and the HS is for High Speed crystals.
The SLEEP (power-down) mode offers power saving. The PIC16CXX family is supported by a full-featured
The user can wake the chip from sleep through several macro assembler, a software simulator, an in-circuit
external and internal interrupts and resets. emulator, a low-cost development programmer and a
A highly reliable Watchdog Timer with its own on-chip full-featured programmer. A C compiler and fuzzy
RC oscillator provides protection against software lock- logic support tools are also available.
up.
The devices with Flash program memory allow the
same device package to be used for prototyping and
production. In-circuit reprogrammability allows the
code to be updated without the device being removed
from the end application. This is useful in the
development of many applications where the device
may not be easily accessible, but the prototypes may
require code updates. This is also useful for remote
applications where the code may need to be updated
(such as rate information).
All PICmicro Family devices have Power-on Reset, selectable Watchdog Timer, selectable code protect and high I/O current capa-
bility. All PIC16F8X Family devices use serial programming with clock pin RB6 and data pin RB7.
When discussing memory maps and other architectural For information on submitting a ROM code, please
features, the use of F and CR also implies the LF and contact your Microchip Regional Sales Office.
LCR versions.
13 Data Bus 8
Flash/ROM Program Counter EEPROM Data Memory
Program
Memory
PIC16F83/CR83 RAM
512 x 14 File Registers EEPROM
8 Level Stack EEDATA Data Memory
PIC16F84/CR84 PIC16F83/CR83
(13-bit) 36 x 8 64 x 8
1K x 14
PIC16F84/CR84
68 x 8
Program
Bus 14
7 RAM Addr EEADR
Addr Mux
Instruction reg
MUX
Power-up
Timer I/O Ports
8
Instruction Oscillator
Decode & Start-up Timer
Control ALU
Power-on RA3:RA0
Reset
Timing Watchdog RB7:RB1
Timer W reg
Generation
RB0/INT
MCLR 4 4 I/P ST Master clear (reset) input/programming voltage input. This pin is an
active low reset to the device.
PORTA is a bi-directional I/O port.
RA0 17 17 I/O TTL
RA1 18 18 I/O TTL
RA2 1 1 I/O TTL
RA3 2 2 I/O TTL
RA4/T0CKI 3 3 I/O ST Can also be selected to be the clock input to the TMR0 timer/
counter. Output is open drain type.
PORTB is a bi-directional I/O port. PORTB can be software pro-
grammed for internal weak pull-up on all inputs.
RB0/INT 6 6 I/O TTL/ST (1) RB0/INT can also be selected as an external interrupt pin.
RB1 7 7 I/O TTL
RB2 8 8 I/O TTL
RB3 9 9 I/O TTL
RB4 10 10 I/O TTL Interrupt on change pin.
RB5 11 11 I/O TTL Interrupt on change pin.
RB6 12 12 I/O TTL/ST (2) Interrupt on change pin. Serial programming clock.
RB7 13 13 I/O TTL/ST (2) Interrupt on change pin. Serial programming data.
VSS 5 5 P Ground reference for logic and I/O pins.
VDD 14 14 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.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Q1
Q2 Internal
phase
Q3 clock
Q4
PC PC PC+1 PC+2
OSC2/CLKOUT
(RC mode)
Fetch INST (PC)
Execute INST (PC-1) Fetch INST (PC+1)
Execute INST (PC) Fetch INST (PC+2)
Execute INST (PC+1)
All instructions are single cycle, except for any program branches. These take two cycles since the fetch
instruction is flushed from the pipeline while the new instruction is being fetched and then executed.
section discussing each individual peripheral module. Peripheral Interrupt Vector 0004h
User Memory
The data memory area also contains the data
Space
EEPROM memory. This memory is not directly mapped
into the data memory, but is indirectly mapped. That is,
an indirect address pointer specifies the address of the
data EEPROM memory to read/write. The 64 bytes of
data EEPROM memory have the address range
1FFh
0h-3Fh. More details on the EEPROM memory can be
found in Section 7.0.
The reset vector is at 0000h and the interrupt vector is Stack Level 8
at 0004h. Reset Vector 0000h
3FFh
1FFFh
The data memory is partitioned into two areas. The first All devices have some amount of General Purpose
is the Special Function Registers (SFR) area, while the Register (GPR) area. Each GPR is 8 bits wide and is
second is the General Purpose Registers (GPR) area. accessed either directly or indirectly through the FSR
The SFRs control the operation of the device. (Section 4.5).
Portions of data memory are banked. This is for both The GPR addresses in bank 1 are mapped to
the SFR area and the GPR area. The GPR area is addresses in bank 0. As an example, addressing loca-
banked to allow greater than 116 bytes of general tion 0Ch or 8Ch will access the same GPR.
purpose RAM. The banked areas of the SFR are for the
registers that control the peripheral functions. Banking 4.2.2 SPECIAL FUNCTION REGISTERS
requires the use of control bits for bank selection. The Special Function Registers (Figure 4-1, Figure 4-2
These control bits are located in the STATUS Register. and Table 4-1) are used by the CPU and Peripheral
Figure 4-1 and Figure 4-2 show the data memory map functions to control the device operation. These
organization. registers are static RAM.
Instructions MOVWF and MOVF can move values from The special function registers can be classified into two
the W register to any location in the register file (F), sets, core and peripheral. Those associated with the
and vice-versa. core functions are described in this section. Those
The entire data memory can be accessed either related to the operation of the peripheral features are
directly using the absolute address of each register file described in the section for that specific feature.
or indirectly through the File Select Register (FSR)
(Section 4.5). Indirect addressing uses the present
value of the RP1:RP0 bits for access into the banked
areas of data memory.
Data memory is partitioned into two banks which
contain the general purpose registers and the special
function registers. Bank 0 is selected by clearing the
RP0 bit (STATUS<5>). Setting the RP0 bit selects Bank
1. Each Bank extends up to 7Fh (128 bytes). The first
twelve locations of each Bank are reserved for the
Special Function Registers. The remainder are Gen-
eral Purpose Registers implemented as static RAM.
4Fh CFh
50h D0h
Bank 0
00h INDF Uses contents of FSR to address data memory (not a physical register) ---- ---- ---- ----
01h TMR0 8-bit real-time clock/counter xxxx xxxx uuuu uuuu
02h PCL Low order 8 bits of the Program Counter (PC) 0000 0000 0000 0000
(2) TO
03h STATUS IRP RP1 RP0 PD Z DC C 0001 1xxx 000q quuu
04h FSR Indirect data memory address pointer 0 xxxx xxxx uuuu uuuu
05h PORTA RA4/T0CKI RA3 RA2 RA1 RA0 ---x xxxx ---u uuuu
06h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0/INT xxxx xxxx uuuu uuuu
07h Unimplemented location, read as '0' ---- ---- ---- ----
08h EEDATA EEPROM data register xxxx xxxx uuuu uuuu
09h EEADR EEPROM address register xxxx xxxx uuuu uuuu
0Ah PCLATH Write buffer for upper 5 bits of the PC (1) ---0 0000 ---0 0000
0Bh INTCON GIE EEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
Bank 1
80h INDF Uses contents of FSR to address data memory (not a physical register) ---- ---- ---- ----
83h STATUS (2) IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu
84h FSR Indirect data memory address pointer 0 xxxx xxxx uuuu uuuu
85h TRISA PORTA data direction register ---1 1111 ---1 1111
86h TRISB PORTB data direction register 1111 1111 1111 1111
89h EECON2 EEPROM control register 2 (not a physical register) ---- ---- ---- ----
0Ah PCLATH Write buffer for upper 5 bits of the PC (1) ---0 0000 ---0 0000
0Bh INTCON GIE EEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
Legend: x = unknown, u = unchanged. - = unimplemented read as 0, q = value depends on condition.
Note 1: The upper byte of the program counter is not directly accessible. PCLATH is a slave register for PC<12:8>. The contents
of PCLATH can be transferred to the upper byte of the program counter, but the contents of PC<12:8> is never transferred
to PCLATH.
2: The TO and PD status bits in the STATUS register are not affected by a MCLR reset.
3: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
The INDF register is not a physical register. Address- EXAMPLE 4-2: HOW TO CLEAR RAM
ing INDF actually addresses the register whose USING INDIRECT
address is contained in the FSR register (FSR is a
ADDRESSING
pointer). This is indirect addressing. movlw 0x20 ;initialize pointer
movwf FSR ; to RAM
EXAMPLE 4-1: INDIRECT ADDRESSING NEXT clrf INDF ;clear INDF register
Register file 05 contains the value 10h incf FSR ;inc pointer
Register file 06 contains the value 0Ah btfss FSR,4 ;all done?
Load the value 05 into the FSR register goto NEXT ;NO, clear next
A read of the INDF register will return the value of CONTINUE
: ;YES, continue
10h
Increment the value of the FSR register by one An effective 9-bit address is obtained by concatenating
(FSR = 06) the 8-bit FSR register and the IRP bit (STATUS<7>), as
A read of the INDF register now will return the shown in Figure 4-1. However, IRP is not used in the
value of 0Ah. PIC16F8X.
Reading INDF itself indirectly (FSR = 0) will produce
00h. Writing to the INDF register indirectly results in a
no-operation (although STATUS bits may be affected).
00 01 10 11
00h 00h
not used not used
0Bh
0Ch
Addresses
Data 2Fh (1) map back
Memory (3) 30h (1) to Bank 0
4Fh (2)
50h (2)
7Fh 7Fh
Bank 0 Bank 1 Bank 2 Bank 3
RD TRIS
Q D
EN
RD PORT
Latch Q D
RD TRIS
Q D RD Port EN
RD Port
EN
Set RBIF RB0/INT
Schmitt Trigger
Buffer RD Port
From other Q D
RB7:RB4 pins
Note 1: TRISB = 1 enables weak pull-up
EN (if RBPU = 0 in the OPTION_REG register).
2: I/O pins have diode protection to VDD and VSS.
RD Port
Note 1: TRISB = 1 enables weak pull-up
(if RBPU = 0 in the OPTION_REG register).
2: I/O pins have diode protection to VDD and VSS.
Value on
Value on all
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Power-on
other resets
Reset
06h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0/INT xxxx xxxx uuuu uuuu
86h TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 1111 1111 1111 1111
OPTION_ 1111 1111 1111 1111
81h RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0
REG
Legend: x = unknown, u = unchanged. Shaded cells are not used by PORTB.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Note:
PC PC PC + 1 PC + 2 PC + 3 This example shows a write to PORTB
Instruction followed by a read from PORTB.
fetched MOVWF PORTB MOVF PORTB,W
write to NOP NOP
PORTB Note that:
RB7:RB0 data setup time = (0.25TCY - TPD)
where TCY = instruction cycle
Port pin
sampled here TPD = propagation delay
TPD Therefore, at higher clock frequencies,
Instruction
executed NOP
a write followed by a read may be prob-
MOVWF PORTB MOVF PORTB,W
write to lematic.
PORTB
Data bus
FOSC/4 0
PSout 8
1
Sync with
1 Internal TMR0 register
RA4/T0CKI clocks
Programmable 0 PSout
pin Prescaler
T0SE (2 cycle delay)
3
Set bit T0IF
PS2, PS1, PS0 PSA on Overflow
T0CS
Note 1: Bits T0CS, T0SE, PS2, PS1, PS0 and PSA are located in the OPTION_REG register.
2: The prescaler is shared with the Watchdog Timer (Figure 6-6)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Instruction MOVWF TMR0 MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W
Fetch
Instruction
Executed Write TMR0 Read TMR0 Read TMR0 Read TMR0 Read TMR0 Read TMR0
executed reads NT0 reads NT0 reads NT0 reads NT0 + 1 reads NT0 + 2
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Instruction MOVWF TMR0 MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W
Fetch
Instruction
Execute Write TMR0 Read TMR0 Read TMR0 Read TMR0 Read TMR0 Read TMR0
executed reads NT0 reads NT0 reads NT0 reads NT0 reads NT0 + 1
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
CLKOUT(3)
GIE bit
(INTCON<7>)
PC PC PC +1 PC +1 0004h 0005h
Instruction
fetched Inst (PC) Inst (PC+1) Inst (0004h) Inst (0005h)
Instruction
Inst (PC-1) Inst (PC) Dummy cycle Dummy cycle Inst (0004h)
executed
When an external clock input is used for TMR0, it must Since the prescaler output is synchronized with the
meet certain requirements. The external clock internal clocks, there is a small delay from the time the
requirement is due to internal phase clock (TOSC) external clock edge occurs to the time the Timer0
synchronization. Also, there is a delay in the actual Module is actually incremented. Figure 6-5 shows the
incrementing of the TMR0 register after delay from the external clock edge to the timer
synchronization. incrementing.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Ext. Clock Input or
Prescaler Out (Note 2)
(Note 3)
Ext. Clock/Prescaler
Output After Sampling
TMR0 T0 T0 + 1 T0 + 2
Note 1: Delay from clock input change to TMR0 increment is 3Tosc to 7Tosc. (Duration of Q = Tosc).
Therefore, the error in measuring the interval between two edges on TMR0 input = 4Tosc max.
2: External clock if no prescaler selected, Prescaler output otherwise.
3: The arrows indicate where sampling occurs. A small clock pulse may be missed by sampling.
M 8
0 1
RA4/T0CKI U M
X SYNC
pin U 2 TMR0 register
1 0
X Cycles
T0SE
T0CS
PSA Set bit T0IF
on overflow
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
Note: T0CS, T0SE, PSA, PS2:PS0 are bits in the OPTION_REG register.
Value on
Value on all
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Power-on
other resets
Reset
0Bh INTCON GIE EEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 0000
85h TRISA TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 ---1 1111 ---1 1111
Legend: x = unknown, u = unchanged. - = unimplemented read as 0. Shaded cells are not associated with Timer0.
Sequence
MOVLW AAh ;
Required
set when a write operation is interrupted by a MCLR MOVWF EECON2 ; Write AAh
reset or a WDT time-out reset during normal operation. BSF EECON1,WR ; Set WR bit
In these situations, following reset, the user can check ; begin write
the WRERR bit and rewrite the location. The data and BSF INTCON, GIE ; Enable INTs.
address will be unchanged in the EEDATA and
The write will not initiate if the above sequence is not
EEADR registers.
exactly followed (write 55h to EECON2, write AAh to
Interrupt flag bit EEIF is set when write is complete. It EECON2, then set WR bit) for each byte. We strongly
must be cleared in software. recommend that interrupts be disabled during this
EECON2 is not a physical register. Reading EECON2 code segment.
will read all 0s. The EECON2 register is used Additionally, the WREN bit in EECON1 must be set to
exclusively in the Data EEPROM write sequence. enable write. This mechanism prevents accidental
writes to data EEPROM due to errant (unexpected)
7.3 Reading the EEPROM Data Memory code execution (i.e., lost programs). The user should
keep the WREN bit clear at all times, except when
To read a data memory location, the user must write the
updating EEPROM. The WREN bit is not cleared
address to the EEADR register and then set control bit
by hardware
RD (EECON1<0>). The data is available, in the very
next cycle, in the EEDATA register; therefore it can be After a write sequence has been initiated, clearing the
read in the next instruction. EEDATA will hold this value WREN bit will not affect this write cycle. The WR bit will
until another read or until it is written to by the user be inhibited from being set unless the WREN bit is set.
(during a write operation). At the completion of the write cycle, the WR bit is
cleared in hardware and the EE Write Complete
EXAMPLE 7-1: DATA EEPROM READ Interrupt Flag bit (EEIF) is set. The user can either
BCF STATUS, RP0 ; Bank 0
enable this interrupt or poll this bit. EEIF must be
MOVLW CONFIG_ADDR ; cleared by software.
MOVWF EEADR ; Address to read
BSF STATUS, RP0 ; Bank 1
BSF EECON1, RD ; EE Read
BCF STATUS, RP0 ; Bank 0
MOVF EEDATA, W ; W = EEDATA
Legend: x = unknown, u = unchanged, - = unimplemented read as 0, q = value depends upon condition. Shaded cells are not
used by Data EEPROM.
R-u R-u R-u R-u R-u R-u R/P-u R-u R-u R-u R-u R-u R-u R-u
CP CP CP CP CP CP DP CP CP CP PWRTE WDTE FOSC1 FOSC0
bit13 bit0
R = Readable bit
P = Programmable bit
- n = Value at POR reset
u = unchanged
bit 13:8 CP: Program Memory Code Protection bit
1 = Code protection off
0 = Program memory is code protected
bit 7 DP: Data Memory Code Protection bit
1 = Code protection off
0 = Data memory is code protected
bit 6:4 CP: Program Memory Code Protection bit
1 = Code protection off
0 = Program memory is code protected
bit 3 PWRTE: Power-up Timer Enable bit
1 = Power-up timer is disabled
0 = Power-up timer is enabled
bit 2 WDTE: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 1:0 FOSC1:FOSC0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator
R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u R/P-u
CP CP CP CP CP CP CP CP CP CP PWRTE WDTE FOSC1 FOSC0
bit13 bit0
R = Readable bit
P = Programmable bit
- n = Value at POR reset
u = unchanged
bit 13:4 CP: Code Protection bit
1 = Code protection off
0 = All memory is code protected
bit 3 PWRTE: Power-up Timer Enable bit
1 = Power-up timer is disabled
0 = Power-up timer is enabled
bit 2 WDTE: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 1:0 FOSC1:FOSC0: Oscillator Selection bits
11 = RC oscillator
10 = HS oscillator
01 = XT oscillator
00 = LP oscillator
8.2.2 CRYSTAL OSCILLATOR / CERAMIC Note1: See Table 8-1 for recommended values of
RESONATORS C1 and C2.
2: A series resistor (RS) may be required for
In XT, LP or HS modes a crystal or ceramic resonator
AT strip cut crystals.
is connected to the OSC1/CLKIN and OSC2/CLKOUT
3: RF varies with the crystal chosen.
pins to establish oscillation (Figure 8-3).
External
Reset
MCLR
SLEEP
WDT WDT
Module Time_Out
Reset
VDD rise
detect S
Power_on_Reset
VDD
OST/PWRT
OST
Chip_Reset
10-bit Ripple counter R Q
OSC1/
CLKIN
PWRT
On-chip
RC OSC(1) 10-bit Ripple counter
Enable PWRT
VDD
MCLR
INTERNAL POR
TPWRT
OST TIME-OUT
INTERNAL RESET
FIGURE 8-11: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 2
VDD
MCLR
INTERNAL POR
TPWRT
OST TIME-OUT
INTERNAL RESET
VDD
MCLR
INTERNAL POR
TPWRT
OST TIME-OUT
INTERNAL RESET
FIGURE 8-13: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD): SLOW VDD RISE TIME
V1
VDD
MCLR
INTERNAL POR
TPWRT
OST TIME-OUT
INTERNAL RESET
When VDD rises very slowly, it is possible that the TPWRT time-out and TOST time-out will expire before VDD
has reached its final value. In this example, the chip will reset properly if, and only if, V1 VDD min.
R1
VDD = 0.7V
R1 + R2
Wake-up
T0IF (If in SLEEP mode)
T0IE
INTF
INTE
Interrupt to CPU
RBIF
RBIE
EEIF
EEIE
GIE
CLKOUT 3
4
INT pin
1
1
INTF flag 5 Interrupt Latency 2
(INTCON<1>)
GIE bit
(INTCON<7>)
INSTRUCTION FLOW
PC PC PC+1 PC+1 0004h 0005h
Instruction
fetched Inst (PC) Inst (PC+1) Inst (0004h) Inst (0005h)
External interrupt on RB0/INT pin is edge triggered: An input change on PORTB<7:4> sets flag bit RBIF
either rising if INTEDG bit (OPTION_REG<6>) is set, (INTCON<0>). The interrupt can be enabled/disabled
or falling, if INTEDG bit is clear. When a valid edge by setting/clearing enable bit RBIE (INTCON<3>)
appears on the RB0/INT pin, the INTF bit (Section 5.2).
(INTCON<1>) is set. This interrupt can be disabled by
Note 1: For a change on the I/O pin to be
clearing control bit INTE (INTCON<4>). Flag bit INTF
recognized, the pulse width must be at
must be cleared in software via the interrupt service
least TCY wide.
routine before re-enabling this interrupt. The INT
interrupt can wake the processor from SLEEP
(Section 8.12) only if the INTE bit was set prior to going
into SLEEP. The status of the GIE bit decides whether
the processor branches to the interrupt vector
following wake-up.
0
M Postscaler
WDT Timer 1 U
X 8
8 - to -1 MUX PS2:PS0
PSA
WDT
Enable Bit
To TMR0 (Figure 6-6)
0 1
MUX PSA
WDT
Time-out
2007h Config. bits (2) (2) (2) (2) PWRTE(1) WDTE FOSC1 FOSC0 (2)
A device may be powered down (SLEEP) and later The device can wake-up from SLEEP through one of
powered up (Wake-up from SLEEP). the following events:
1. External reset input on MCLR pin.
8.12.1 SLEEP
2. WDT Wake-up (if WDT was enabled).
The Power-down mode is entered by executing the 3. Interrupt from RB0/INT pin, RB port change, or
SLEEP instruction. data EEPROM write complete.
If enabled, the Watchdog Timer is cleared (but keeps Peripherals cannot generate interrupts during SLEEP,
running), the PD bit (STATUS<3>) is cleared, the TO bit since no on-chip Q clocks are present.
(STATUS<4>) is set, and the oscillator driver is turned
The first event (MCLR reset) will cause a device reset.
off. The I/O ports maintain the status they had before
The two latter events are considered a continuation of
the SLEEP instruction was executed (driving high, low,
program execution. The TO and PD bits can be used to
or hi-impedance).
determine the cause of a device reset. The PD bit,
For the lowest current consumption in SLEEP mode, which is set on power-up, is cleared when SLEEP is
place all I/O pins at either at VDD or VSS, with no invoked. The TO bit is cleared if a WDT time-out
external circuitry drawing current from the I/O pins, and occurred (and caused wake-up).
disable external clocks. I/O pins that are hi-impedance
While the SLEEP instruction is being executed, the next
inputs should be pulled high or low externally to avoid
instruction (PC + 1) is pre-fetched. For the device to
switching currents caused by floating inputs. The
wake-up through an interrupt event, the corresponding
T0CKI input should also be at VDD or VSS. The
interrupt enable bit must be set (enabled). Wake-up
contribution from on-chip pull-ups on PORTB should be
occurs regardless of the state of the GIE bit. If the GIE
considered.
bit is clear (disabled), the device continues execution at
The MCLR pin must be at a logic high level (VIHMC). the instruction after the SLEEP instruction. If the GIE bit
It should be noted that a RESET generated by a WDT is set (enabled), the device executes the instruction
time-out does not drive the MCLR pin low. after the SLEEP instruction and then branches to the
interrupt address (0004h). In cases where the
execution of the instruction following SLEEP is not
desirable, the user should have a NOP after the
SLEEP instruction.
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
(Note 2)
GIE bit Processor in
(INTCON<7>)
SLEEP
INSTRUCTION FLOW
PC PC PC+1 PC+2 PC+2 PC + 2 0004h 0005h
Instruction
Inst(PC) = SLEEP Inst(PC + 1) Inst(PC + 2) Inst(0004h) Inst(0005h)
fetched
Instruction Dummy cycle Dummy cycle
Inst(PC - 1) SLEEP Inst(PC + 1) Inst(0004h)
executed
Description: The contents of the W register are Description: The contents of W register are
added to the eight bit literal k and the ANDed with the eight bit literal 'k'. The
result is placed in the W register. result is placed in the W register.
Words: 1 Words: 1
Cycles: 1 Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Q Cycle Activity: Q1 Q2 Q3 Q4
Decode Read Process Write to Decode Read Process Write to
literal k data W literal "k" data W
Example CLRWDT
Before Instruction
WDT counter = ?
After Instruction
WDT counter = 0x00
WDT prescaler= 0
TO = 1
PD = 1
Description: GOTO is an unconditional branch. The Description: The contents of register f are incre-
eleven bit immediate value is loaded mented. If d is 0 the result is placed in
into PC bits <10:0>. The upper bits of the W register. If d is 1 the result is
PC are loaded from PCLATH<4:3>.
GOTO is a two cycle instruction. placed back in register f.
Words: 1 Words: 1
Cycles: 2 Cycles: 1
Cycles: 1(2)
Example IORLW 0x35
Q Cycle Activity: Q1 Q2 Q3 Q4
Before Instruction
Decode Read Process Write to
W = 0x9A
register f data destination
After Instruction
If Skip: (2nd Cycle) W = 0xBF
Z = 1
Q1 Q2 Q3 Q4
No-Opera No-Opera No-Operati
No-Operat tion tion on
ion
MOVWF Move W to f
MOVF Move f
Syntax: [ label ] MOVWF f
Syntax: [ label ] MOVF f,d
Operands: 0 f 127
Operands: 0 f 127
d [0,1] Operation: (W) (f)
Operation: (f) (destination) Status Affected: None
Status Affected: Z Encoding: 00 0000 1fff ffff
Encoding: 00 1000 dfff ffff Description: Move data from W register to register
'f'.
Description: The contents of register f is moved to a
destination dependant upon the status Words: 1
of d. If d = 0, destination is W register. If
Cycles: 1
d = 1, the destination is file register f
itself. d = 1 is useful to test a file regis- Q Cycle Activity: Q1 Q2 Q3 Q4
ter since status flag Z is affected. Decode Read Process Write
Words: 1 register data register f
f
Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Example MOVWF OPTION_REG
Decode Read Process Write to Before Instruction
register data destination
OPTION = 0xFF
f
W = 0x4F
After Instruction
Example MOVF FSR, 0 OPTION = 0x4F
After Instruction W = 0x4F
W = value in FSR register
Z =1
Example RETFIE
After Interrupt
PC = TOS
GIE = 1
OPTION Load Option Register
Syntax: [ label ] OPTION
Operands: None
Operation: (W) OPTION
Status Affected: None
Encoding: 00 0000 0110 0010
Description: The contents of the W register are
loaded in the OPTION register. This
instruction is supported for code com-
patibility with PIC16C5X products.
Since OPTION is a readable/writable
register, the user can directly address
it.
Words: 1
Cycles: 1
Example
To maintain upward compatibility
with future PIC16CXX products,
do not use this instruction.
1st Cycle Decode Read No-Opera Write to 2nd Cycle No-Opera No-Opera No-Opera
literal k tion W, Pop No-Operat tion tion tion
from the ion
Stack
Before Instruction
W = 0x07
After Instruction
W = value of k8
RLF Rotate Left f through Carry RRF Rotate Right f through Carry
Syntax: [ label ] RLF f,d Syntax: [ label ] RRF f,d
Operands: 0 f 127 Operands: 0 f 127
d [0,1] d [0,1]
Operation: See description below Operation: See description below
Status Affected: C Status Affected: C
Encoding: 00 1101 dfff ffff Encoding: 00 1100 dfff ffff
Description: The contents of register f are rotated Description: The contents of register f are rotated
one bit to the left through the Carry one bit to the right through the Carry
Flag. If d is 0 the result is placed in the Flag. If d is 0 the result is placed in the
W register. If d is 1 the result is stored W register. If d is 1 the result is placed
back in register f. back in register f.
C Register f C Register f
Words: 1 Words: 1
Cycles: 1 Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Q Cycle Activity: Q1 Q2 Q3 Q4
Decode Read Process Write to Decode Read Process Write to
register data destination register data destination
f f
TABLE 10-1:
PIC16F8X
24CXX HCS200
PIC12C5XX PIC14000 PIC16C5X PIC16CXXX PIC16C6X PIC16C7XX PIC16C8X PIC16C9XX PIC17C4X PIC17C75X 25CXX HCS300
93CXX HCS301
PICMASTER/
Emulator Products
PICMASTER-CE
In-Circuit Emulator
Compiler
fuzzyTECH-MP
Explorer/Edition
Fuzzy Logic
Dev. Tool
MP-DriveWay
Applications
Code Generator
Total Endurance
Software Model
PICSTARTPlus
Low-Cost
Programmers
Designers Kit
Demo Boards
PICDEM-1
PICDEM-2
PICDEM-3
KEELOQ
Evaluation Kit
PIC16F83/84 PIC16F8X
11.0 ELECTRICAL CHARACTERISTICS FOR PIC16F83 AND PIC16F84
Absolute Maximum Ratings
Ambient temperature under bias.............................................................................................................-55C to +125C
Storage temperature .............................................................................................................................. -65C to +150C
Voltage on VDD with respect to VSS ........................................................................................................... -0.3 to +7.5V
Voltage on MCLR with respect to VSS(2) .......................................................................................................-0.3 to +14V
Voltage on any pin with respect to VSS (except VDD and MCLR).................................................... -0.6V to (VDD + 0.6V)
Total power dissipation(1) .....................................................................................................................................800 mW
Maximum current out of VSS pin ...........................................................................................................................150 mA
Maximum current into VDD pin ..............................................................................................................................100 mA
Input clamp current, IIK (VI < 0 or VI > VDD)..................................................................................................................... 20 mA
Output clamp current, IOK (VO < 0 or VO > VDD) ............................................................................................................. 20 mA
Maximum output current sunk by any I/O pin..........................................................................................................25 mA
Maximum output current sourced by any I/O pin ....................................................................................................20 mA
Maximum current sunk by PORTA ..........................................................................................................................80 mA
Maximum current sourced by PORTA .....................................................................................................................50 mA
Maximum current sunk by PORTB........................................................................................................................150 mA
Maximum current sourced by PORTB...................................................................................................................100 mA
Note 1: Power dissipation is calculated as follows: Pdis = VDD x {IDD - IOH} + {(VDD-VOH) x IOH} + (VOl x IOL)
Note 2: Voltage spikes below VSS at the MCLR pin, inducing currents greater than 80 mA, may cause latch-up. Thus,
a series resistor of 50-100 should be used when applying a low level to the MCLR pin rather than pulling
this pin directly to VSS.
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.
1. TppS2ppS
2. TppS
T
F Frequency T Time
Lowercase symbols (pp) and their meanings:
pp
2 to os,osc OSC1
ck CLKOUT ost oscillator start-up timer
cy cycle time pwrt power-up timer
io I/O port rbt RBx pins
inp INT pin t0 T0CKI
mc MCLR wdt watchdog timer
Uppercase symbols and their meanings:
S
F Fall P Period
H High R Rise
I Invalid (Hi-impedance) V Valid
L Low Z High Impedance
VDD/2
RL Pin CL
CL VSS
Pin
VSS
RL = 464
CL = 50 pF for all pins except OSC2.
15 pF for OSC2 output.
OSC1
1 3 3 4 4
2
CLKOUT
OSC1
11
10
22
CLKOUT 23
13 12
19 18
14 16
I/O Pin
(input)
17 15
FIGURE 11-5: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP
TIMER TIMING
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
RESET
Watchdog
Timer
RESET
31
34 34
I/O Pins
TABLE 11-5 RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP
TIMER REQUIREMENTS
Parameter
No. Sym Characteristic Min Typ Max Units Conditions
30 TmcL MCLR Pulse Width (low) 1000 * ns 2.0V VDD 6.0V
31 Twdt Watchdog Timer Time-out Period 7* 18 33 * ms VDD = 5.0V
(No Prescaler)
32 Tost Oscillation Start-up Timer Period 1024TOSC ms TOSC = OSC1 period
33 Tpwrt Power-up Timer Period 28 * 72 132 * ms VDD = 5.0V
34 TIOZ I/O Hi-impedance from MCLR Low 100 * ns
or reset
* These parameters are characterized but not tested.
Data in "Typ" column is at 5V, 25C unless otherwise stated. These parameters are for design guidance only and are not
tested.
RA4/T0CKI
40 41
42
NOTES:
1. TppS2ppS
2. TppS
T
F Frequency T Time
Lowercase symbols (pp) and their meanings:
pp
2 to os,osc OSC1
ck CLKOUT ost oscillator start-up timer
cy cycle time pwrt power-up timer
io I/O port rbt RBx pins
inp INT pin t0 T0CKI
mc MCLR wdt watchdog timer
Uppercase symbols and their meanings:
S
F Fall P Period
H High R Rise
I Invalid (Hi-impedance) V Valid
L Low Z High Impedance
VDD/2
RL Pin CL
CL VSS
Pin
VSS
RL = 464
CL = 50 pF for all pins except OSC2.
15 pF for OSC2 output.
OSC1
1 3 3 4 4
2
CLKOUT
OSC1
11
10
22
CLKOUT 23
13 12
19 18
14 16
I/O Pin
(input)
17 15
FIGURE 12-5: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP
TIMER TIMING
VDD
MCLR
30
Internal
POR
33
PWRT
Time-out
32
OSC
Time-out
Internal
RESET
Watchdog
Timer
RESET
31
34 34
I/O Pins
TABLE 12-5 RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP
TIMER REQUIREMENTS
Parameter
No. Sym Characteristic Min Typ Max Units Conditions
30 TmcL MCLR Pulse Width (low) 1000 * ns 2.0V VDD 6.0V
31 Twdt Watchdog Timer Time-out Period 7* 18 33 * ms VDD = 5.0V
(No Prescaler)
32 Tost Oscillation Start-up Timer Period 1024TOSC ms TOSC = OSC1 period
33 Tpwrt Power-up Timer Period 28 * 72 132 * ms VDD = 5.0V
34 TIOZ I/O Hi-impedance from MCLR Low 100 * ns
or reset
* These parameters are characterized but not tested.
Data in "Typ" column is at 5V, 25C unless otherwise stated. These parameters are for design guidance only and are not
tested.
RA4/T0CKI
40 41
42
NOTES:
1.20
Rext = 10 k
1.16
Cext = 100 pF
1.12
1.08
1.04
1.00
0.84
-40 -20 0 20 25 40 60 70 80 85 100
T(C)
Average
Cext Rext Fosc @ 5V, 25C
Part to Part Variation
20 pF 5k 4.61 MHz 25%
10 k 2.66 MHz 24%
100 k 311 kHz 39%
100 pF 5k 1.34 MHz 21%
10 k 756 kHz 18%
100 k 82.8 kHz 28%
300 pF 5k 428 kHz 13%
10 k 243 kHz 13%
100 k 26.2 kHz 23%
* Measured on DIP packages. The percentage variation indicated here is part-to-part variation due to normal process
distribution. The variation indicated is 3 standard deviation from average value for full VDD range.
5.5
5.0
R = 5k
4.5
4.0
3.5
Fosc (MHz)
R = 10k
3.0
2.5
2.0
1.5
1.0
0.5 R = 100k
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
R = 5k
1.6
1.4
1.2
Fosc (MHz)
1.0
R = 10k
0.8
0.6
0.4
0.2
R = 100k
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
R = 5k
0.5
FOSC (MHz)
0.4
R = 10k
0.3
0.2
0.1
R = 100k
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
6.0 10
5.0 8
T = 25C T = 25C
7
4.0 6
IPD (A)
5
IPD (A)
3.0 4
2.0 2
1.0 0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
FIGURE 13-7: VTH (INPUT THRESHOLD VOLTAGE) OF I/O PINS vs. VDD
1.40
1.30
1.20
VTH (Volts)
C )
( +25
1.10 Typ
1.00
0.90
0.80
0.70
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
3.0
2.8
2.6
2.4
2.2
VTH (Volts)
2.0 C)
( +25
1.8 Typ
1.6
1.4
1.2
1.0
0.8
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
Note: This input pin is CMOS input.
FIGURE 13-9: VIH, VIL OF MCLR, T0CKI AND OSC1 (IN RC MODE) vs. VDD
5.0
4.5
4.0
3.5
3.0 25C
VIH, VIL (Volts)
ty p +
V IH
2.5
2.0
1.5
VIL typ +25C
1.0
0.5
0.0
2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
VDD (Volts)
10000
1000
6.0V
5.5V
5.0V
4.5V
4.0V
3.5V
100 3.0V
2.5V
2.0V
10
100000 1000000 10000000
FREQ (Hz)
10000
1000
6.0V
5.5V
100 5.0V
4.5V
4.0V
3.5V
3.0V
2.5V
2.0V
10
10000 100000 1000000 10000000
FREQ (Hz)
1000
6.0V
5.5V
100 5.0V
4.5V
4.0V
3.5V
3.0V
2.5V
2.0V
10
10000 100000 1000000
FREQ (Hz)
45 8000
40 7000
35 6000
WDT period (ms)
30 5000
gm (A/V)
Typ +25C
25 Typ +25C 4000
20 3000
15 2000
10 100
5 0
2.0 3.0 4.0 5.0 6.0 2.0 3.0 4.0 5.0 6.0
VDD (Volts) VDD (Volts)
40
2000
35
30
1500
25 Typ +25C
gm (A/V)
gm (A/V)
20 1000
Typ +25C
15
500
10
5
0
2.0 3.0 4.0 5.0 6.0
0 VDD (Volts)
2.0 3.0 4.0 5.0 6.0
VDD (Volts)
40
5 35
30
10
Typ +25C
IOH (mA)
25 Typ +25C
IOL (mA)
20
15
15
20 10
5
25
0.0 0.5 1.0 1.5 2.0 2.5 3.0
0
VOH (Volts) 0.0 0.5 1.0 1.5 2.0 2.5 3.0
VOL (Volts)
FIGURE 13-18: IOH vs. VOH, VDD = 5 V FIGURE 13-20: IOL vs. VOL, VDD = 5 V
90
0
80
5
70
10
60
15
Typ +25C
IOH (mA)
50
IOL (mA)
20
Typ +25C
40
25
30
30
20
35
10
40
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
0
VOH (Volts) 0.0 0.5 1.0 1.5 2.0 2.5 3.0
VOL (Volts)
7
DMEM Typ. E/W Cycle Time (ms)
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5
VDD (Volts)
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 OTP marking consists of Microchip part number, year code, week
code, facility code, mask rev# and assembly code. For OTP 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.
n 1
E1
A1
R
c L
A2
B1
B p
eB
E1
p
E
2
B n 1
45
L
R2
c
A
A1
R1
L1 A2
The MCLR pin now has an on-chip MCLR pulse width (low) MCLR pulse width (low)
filter. The input signal on the MCLR = 350ns; 2.0V VDD 3.0V = 1000ns; 2.0V VDD 6.0V
pin will require a longer low pulse to = 150ns; 3.0V VDD 6.0V
generate an interrupt.
Some electrical specifications have IPD (typ @ 2V) = 26A IPD (typ @ 2V) < 1A
been improved (see IPD example).
Compare the electrical specifica- IPD (max @ 4V, WDT disabled) IPD (max @ 4V, WDT disabled)
tions of the two devices to ensure =100A (PIC16C84) =14A (PIC16F84)
that this will not cause a compatibil- =100A (PIC16LC84) =7A (PIC16LF84)
ity issue.
PORTA and crystal oscillator values For crystal oscillator configurations N/A
less than 500kHz operating below 500kHz, the device
may generate a spurious internal
Q-clock when PORTA<0> switches
state.
GIE bit unintentional enable If an interrupt occurs while the Glo- N/A
bal Interrupt Enable (GIE) bit is
being cleared, the GIE bit may unin-
tentionally be re-enabled by the
users Interrupt Service Routine (the
RETFIE instruction).
R
RBIF bit ........................................................................ 23, 48
RC Oscillator ...................................................................... 46
Read-Modify-Write ............................................................. 25
Register File ....................................................................... 12
Reset ............................................................................ 37, 41
Reset on Brown-Out ........................................................... 46
S
Saving W Register and STATUS in RAM .......................... 49
SEEVAL Evaluation and Programming System .............. 71
SLEEP .................................................................... 37, 41, 51
Software Simulator (MPLAB-SIM) ...................................... 71
Special Features of the CPU .............................................. 37
Special Function Registers ................................................ 12
Stack .................................................................................. 18
Overflows ................................................................... 18
Underflows ................................................................. 18
STATUS ................................................................... 7, 15, 42
T
time-out .............................................................................. 42
Timer0
Switching Prescaler Assignment ................................ 31
T0IF ............................................................................ 48
Timer0 Module ........................................................... 27
TMR0 Interrupt ........................................................... 48
TMR0 with External Clock .......................................... 29
Timing Diagrams
Time-out Sequence .................................................... 44
Timing Diagrams and Specifications ............................ 80, 92
TRISA ................................................................................. 21
TRISB ........................................................................... 23, 42
W
W ........................................................................................ 42
Wake-up from SLEEP .................................................. 42, 51
Watchdog Timer (WDT) ................................... 37, 41, 42, 50
WDT ................................................................................... 42
Period ......................................................................... 50
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?
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.
01/18/02
www.datasheetcatalog.com