*8-bit, 8-pin Devices Protecte d by Microchip’ s Low Pin Coun t Patent: U. S. Patent N o. 5,847,450. Additi onal U.S. and
foreign patents and applications may be issued or pending.
Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and t he lik e is provided only for your convenience
and may be su perseded by upda t es . It is y our responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life supp ort and/or safety ap plications is entir ely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless M icrochip from any and all dama ges, claims,
suits, or expenses re sulting from such use. No licens es are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, KEELOQ logo, microID, MPLAB, PIC,
PICmicro, PICSTART, PRO MATE, PowerSmart, rfP IC, and
SmartShunt are registered trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
AmpLab, FilterLab, Linear Active Thermistor, Migratable
Memory, MX DEV, MXLAB, PS logo, SEEVAL, SmartSensor
and The Embedded Control Solutions Company are
registered trademarks of Microchip Technology Incorporated
in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi,
MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit,
PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal,
PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartT el, Total
Endurance, UNI/O, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona, Gresham, Oregon and Mountain View, California. The
Company’s quality system processes and procedures are for its PIC
MCUs and dsPIC® DSCs, KEELOQ
EEPROMs, microperipherals, nonvolatile memory and analog
products. In addition, Microchip’s quality system for the design and
manufacture of development systems is ISO 9001:2000 certified.
11.0 Analog Front-End (AFE) Functional Description (PIC16F639 Only) .......................................................................................... 97
12.0 Special Features of the CPU......................... ........................... ........................................ ........................................................ 129
13.0 Instruction Set Summary.......................................................................................................................................................... 149
14.0 Development Support............................................................................................................................................................... 159
16.0 DC and AC Characteristics Graphs and Tables.......................................................................................................................191
Systems Information and Upgrade Hot Line..................................................................................................................................... 223
Worldwide Sales and Service ...................................................... ........................... .......................................................................... 232
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding t his publication, p lease c ontact the M arket ing Co mmunications Department via
E-mail at docerrors@microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150. We
welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
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)
When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are
using.
Customer Notification System
Register on our web site at www.microchip.com to receive the most current information on all of our products.
LCCOMLCCOMAN—Common reference for analog inputs.
LCXLCXAN—125 kHz analog X channel input.
LCYLCYAN—125 kHz analog Y channel input.
LCZLCZAN—125 kHz analog Z channel input.
RA0/C1IN+/ICSPDAT/ULPWURA0TTL—General purpose I/O. Individually controlled interrupt-on-change.
C1IN+AN—Comparator1 input – positive.
ICSPDATTTLCMOS Serial Programming Data IO.
ULPWUAN—Ultra Low-Power Wake-up input.
RA1/C1IN-/V
RA2/T0CKI/INT/C1OUTRA2STCMOS General purpose I/O. Individually controlled interrupt-on-change.
RA3/MCLR
RA4/T1G
RA5/T1CKI/OSC1/CLKINRA5TTLCMOS General purpose I/O. Individually controlled interrupt-on-change.
RC0/C2IN+RC0TTLCMOS General purpose I/O.
RC1/C2IN-/CS
RC2/SCLK/ALERT
Legend:AN = Analog input or outputCMOS = CMOS compatible input or outputD= Direct
REF/ICSPCLKRA1TTLCMOS General purpose I/O. Individually controlled interrupt-on-change.
C1IN-AN—Comparator1 input – negative.
REFAN—External voltage reference
V
ICSPCLKST—Serial Programming Clock.
T0CKIST—External clock for Timer0.
INTST—External Interrupt.
C1OUT—CMOS Comparator1 output.
/VPP
/OSC2/CLKOUT
HV = High VoltageST= Schmitt Trigger input with CMOS levelsOD = Open Drain
TTL = TTL compatible inputXTAL = Crystal
RA3TTL
MCLR
V
PPHV—Programming voltage.
RA4TTLCMOS General purpose I/O. Individually controlled interrupt-on-change.
T1G
OSC2—XTALXTAL connection.
CLKOUT—CMOS T
T1CKIST—Timer1 clock.
OSC1XTAL—XTAL connection.
CLKINST—T
C2IN+AN—Comparator1 input – positive.
RC1TTLCMOS General purpose I/O.
C2IN-AN—Comparator1 input – negative.
CS
RC2TTLCMOS General purpose I/O.
SCLKTTL—Digital clock input for SPI communication.
The PIC12F635/PIC16F636/639 devices have a 13-bit
program counter capable of addressing an 8K x 14
program memory space. Only the first 1K x 14
(0000h-03FFh, for the PIC12F635) and 2K x 14
(0000h-07FFh, for the PIC16F636/639) is physically
implemented. Accessing a location above these
boundaries will cause a wraparound within the first
2K x 14 space. The Reset vector is at 0000h and the
interrupt vector is at 0004h (see Figure 2-1).
2.2Data Memory Organization
The data memory (see Figure 2-2) is partitioned into
two banks, which contain the General Purpose
Registers (GPR) and the Special Function Registers
(SFR). The Special Function Registers are located in
the first 32 locations of each bank. Register locations
20h-7Fh in Bank 0 and A0h-BFh in Bank 1 are GPRs,
implemented as static RAM for the PIC16F636/639.
For the PIC12F635, reg ister locat ions 4 0h throug h 7Fh
are GPRs implemented as static RAM. Register
locations F0h-FFh in Bank 1 point to addresses
70h-7Fh in Bank 0. All other RAM is unimplemented
and returns ‘0’ when read. RP0 of the STATUS register
is the bank select bit.
RP1
RP0
00→Bank 0 is selected
01→Bank 1 is selected
10→Bank 2 is selected
11→Bank 3 is selected
The register file is organized as 64 x 8 for the
PIC12F635 and 128 x 8 for the PIC16F636/639. Each
register is accessed, either directly or indirectly,
through the File Select R egister, FSR (see Section 2.4“Indirect Addressing, INDF and FSR Registers”).
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers (SFRs) are registers
used by the CPU and peripheral functions for controlling
the desired operation of the device (see Figure 2-1).
These registers are static RAM.
The special re gisters can be classifi ed into two sets:
core and peripheral. The Special Function Registers
associated with the “c ore” are des cribed in this sect ion.
Those related to the operation of the peripheral
features are described in the section of that peripheral
feature.
EELOQ hardware peripheral rel ated reg is ters and require the execution o f the
®
Encoder License Agreement” may be accessed through the Microchip web site
EELOQ or by contacting your local Microchip Sales Representative.
PIC12F635/PIC16F636/639
TABLE 2-1:PIC12F635 SPECIAL FUNCTION REGISTERS SUMMARY BANK 0
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 0
00hINDFAddressing this location uses contents of FSR to address data memory
01hTMR0T imer0 Module Registerxxxx xxxx61,137
02hPCLProgram Counter’s (PC) Least Significant Byte0000 000032,137
03hSTATUSIRPRP1RP0TO
04hFSRIndirect Data Me mory Address Pointerxxxx xxxx32,137
05hGPIO
06h—Unimplemented——
07h—Unimplemented——
08h—Unimplemented——
09h—Unimplemented——
0AhPCLATH
0BhINTCONGIE PEIET0IEINTERAIET0IFINTFRAIF
0Ch PIR1
0Dh—Unimplemented——
0EhTMR1LHolding Register for the Least Significant Byte of the 16-bit TMR1xxxx xxxx64,137
0FhTMR1HHolding Register for the Most Significant Byte of the 16-bit TMR1xxxx xxxx64,137
Legend:– = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition,
Note 1:Other (non Power-up) Resets include MCLR
2:MCLR
(not a physical register)
PDZDC C0001 1xxx26,137
——GP5GP4GP3GP2GP1GP0--xx xx0047,137
———Write Buffer for upper 5 bits of Program Counter---0 000032,137
Legend:– = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition,
Note 1:Other (non Power-up) Resets include MCLR
2:CRDAT<3:0> registers are K
(2)
Cryptographic Data Register 00000 0000 0000 0000
(2)
Cryptographic Data Register 10000 0000 0000 0000
(2)
Cryptographic Data Register 20000 0000 0000 0000
(2)
Cryptographic Data Register 30000 0000 0000 0000
shaded = unimplemented
Encoder License Agreement” regarding implementation of the module and access to related registers. The “K
Encoder License Agreement” may be accessed through the Microchip web site located at www.microchip.com/K
or by contacting your local Microchip Sales Representative.
ENC/DEC————CRREG1 CRREG0 00-- --00 00-- --00
Reset and Watchdog Timer Reset during normal operation.
hardware peripheral related registers and require the execution of the “KEELOQ
The STATUS register, shown i n Re gis t er2-1, contains:
• the arithmetic status of the ALU
• the Reset status
• the bank select bits for data memory (GPR and
SFR)
The STATUS register can be the destination for any
instruction, like any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bit s are set or cleared ac cording to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
STATUS register as destin ation may be di fferent than
intended.
and PD bits are not
For example, CLRF STATUS, will clear the upper three
bits and set the Z bit. This leaves the STATUS register
as ‘000u u1uu’ (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
STATUS register, because these instructions do not
affect any Status bits. For other instructions not affecting any Status bit s , s ee Section13.0 “Instruction Set
Summary”
Note 1: The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtraction.
REGISTER 2-1:STATUS: STATUS REGISTER
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TOPDZDC
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
(1)
(1)
C
bit 7IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
bit 6-5RP<1:0>: Register Bank Select bits (used for direct addressing)
00 = Bank 0 (00h-7Fh)
01 = Bank 1 (80h-FFh)
10 = Bank 2 (100h-17Fh)
11 = Bank 3 (180h-1FFh)
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit Carry/Borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
bit 0C: Carry/Borrow
: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
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
(1)
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
(1)
(1)
Note 1: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, t his bit i s loaded with eithe r the high -order or low -order
bit of the source register.
The INTCON register is a readable and writable
register which co nt ains th e vari ous e nable and fl ag bits
for TMR0 register overflow, PORTA change and
external RA2/INT pin interrupts.
Note:Interrupt flag bits are set when an interrupt
condition occurs, regard less of the state of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE of the INTCON
register. User software should ensure the
appropriate interrupt flag bits are clear
prior to enabling an interrupt.
REGISTER 2-3:INTCON: INTERRUPT CONTROL REGISTER
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIEPEIET0IEINTERAIE
bit 7bit 0
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5T0IE: Timer0 Overflow Interrupt Enab le bit
1 = Enables the Timer0 interrupt
0 = Disables the Timer0 interrupt
bit 4INTE: RA2/INT External Interrupt Enable bit
1 = Enables the RA2/INT external interrupt
0 = Disables the RA2/INT external interrupt
bit 3RAIE: PORTA Change Interrupt Enable bit
1 = Enables the PORTA change interrupt
0 = Disables the PORTA change interrupt
bit 2T0IF: Timer0 Overflow Interrupt Flag bit
1 = TMR0 register has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interrupt occurred (must be cleared in software)
0 = The RA2/INT external interrupt did not occur
bit 0RAIF: PORTA Change Interrupt Flag bit
1 = When at least one of the PORTA general purpose I/O pins changed state (must be cleared in
software)
0 = None of the PORTA general purpose I/O pins have changed state
(2)
(1,3)
(1,3)
T0IF
(2)
INTFRAIF
Note 1:IOCA register must also be enabled.
2:T0IF bit is set when Timer0 rolls over. Timer0 is unchanged on Reset and should be initialized before