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 the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
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 M icrochip’s prod ucts as critical components in
life support systems is not authorized except with express
written approval by Microchip. No licenses are conveyed,
implicitly or otherwise, under any Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, 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, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programmin g, IC SP, ICEPIC, MPASM, MPLIB, MPLI N K ,
MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail,
PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartTel and Total
Endurance 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 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial 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) .......................................................................................... 79
12.0 Special Features of the CPU......................... ........................... ........................................ ........................................................ 111
13.0 Instruction Set Summary.......................................................................................................................................................... 131
14.0 Development Support............................................................................................................................................................... 141
16.0 DC and AC Characteristics Graphs and Tables....................................................................................................................... 173
Systems Information and Upgrade Hot Line..................................................................................................................................... 185
Worldwide Sales and Service ............................................. ........................................ ...................................................................... 19
4
TO OUR VALUED CUSTOMERS
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.
This document contains device specific information for
the PIC12F635/PIC16F636/639 devices. Additional
information may be found in the “PICmicro® Mid-Range
MCU Family Reference Manual” (DS33023), which m ay
be obtained from your local Microchip Sales
Representative or downloaded from the Microchip web
site. The reference manual should be considered a
complementary document to this data sheet and is
highly recommended reading for a better understanding
of the device architecture and operation of the peripheral
modules.
FIGURE 1-1:PIC12F635 BLOCK DIAGRAM
Program
Bus
Configuration
Flash
1K x 14
Program
Memory
14
Instruction reg
13
Program Counter
8-level Stack
(13-bit)
Direct Addr
RAM Addr
7
The PIC12F635/PIC16F636/639 devices are covered
by this data sh eet. Figure 1-1 shows a block diagram of
the PIC12F635/PIC16F636/639 devices. Table 1-1
shows the pinout description.
DDTVDDTD—P owe r supply for Analog Front-End. In this document, VDDT is treated
V
LCZLCZAN—125 kHz analog Z channel input
LCYLCYAN—125 kHz analog Y channel input
LCXLCXAN—125 kHz analog X channel input
LCCOMLCCOMAN—Common reference for analog inputs
SSTVSSTD—Ground reference for Analog Front-End. In this document, VSST is
LFDATA—CMOSDigital output representation of analog input signal to LC pins.
RSSI—Current Received signal strength indicator. Analog current that is proportional
CCLK——Carrier clock output
SDIOTTLCMOSInput/Output for SPI communication
RC2TTLCMOSGeneral purpose I/O
SCLKTTL—Digital clock input for SPI communica tion
ALERT
RC1TTLCMOS
C2IN-AN—
CS
C2IN+AN—
T0CKIST—External clock fo r Timer0
INTST—External Interrupt
C1OUT—CMOSComparator1 output
C1IN-AN—Comparator1 input – negative
ICSPCLKST—Serial Programming Clock
C1IN+AN—Comparator1 inpu t – positive
ICSPDATTTLCMOSSerial Programming Data IO
ULPWUAN—Ultra Low-Power Wake-up input
Input
Type
TTL—
Output
Type
Individually enabled pull-up/pull-down.
OSC/4 reference clock
Individually enabled pull-up/pull-down.
ST—Timer1 gate
General purpose input. Individually controlled interrupt-on-change.
—
ST—
—OD
Master Clear Reset. Pull-up enabled when configured as MCLR
to input amplitude.
the same as VDD, un less otherwis e stated.
treated the same as V
Output with internal pull-up resistor for AFE error signal
General purpose I/O
Comparator1 input - negative
Chip select input for SPI communication with internal pull-up resistor
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 wrap around 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 70h7Fh in Bank 0. All other RAM is unimplemented and
returns ‘0’ when read. RP0 (STATUS<5>) is the bank
select bit.
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 related registers and require the execution of the “KEELOQ
Encoder License Agreem ent” regarding im plement ation of the modu le and access to related registe rs. Th
“KEELOQ® Encoder License Agreement” may be accessed through the Microchip web site located a
www.microchip.com/KEELOQ or by contacting your local Microchip Sales Representative.
The Status register, shown in Register 2-1, contains:
• the arithmetic status of the ALU
• the Reset status
• the bank select bits for data memory (SRAM)
The Status register can be the destination for any
instruction, like any other register . If the S tatus register is
the destination for an instruction that affects the Z, D C or
C bits, then the write to these three bits is disabled.
These bits are set or cleared according to the device
logic. Furthermore, the TO
Therefore, the result of an instruction with the Status
register as destination may be different than intended.
and PD bits are not writable.
For example, CLRF STATUS, w ill c lear the upper three
bits and set the Z bit. Thi s leaves the Status regis ter as
000u u1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF, SWAPF
and MOVWF instructions are used to alter the Status
register, because these instructions do not affect any
Status bits. For other instructions not affecting any Status
bits, see Section 13.0 “Instruction Set Summary”.
Note 1: The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtraction. See the SUBLW and SUBWF
instructions for examples.
REGISTER 2-1:STATUS – STATUS REGISTER (ADDRESS: 03h OR 83h)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TO
bit 7bit 0
bit 7IRP: Register Bank Select bit (used for indire ct 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)
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 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit Carry/B
bit 0C: Carry/Borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
: 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
orrow 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
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
PDZDCC
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-order or low-order bit of the source register.
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
The INTCON register is a readable and writable
register which co nta ins th e vari ous e nable and fl ag bit s
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 (INTCON<7>).
User software should ensu re the appropriate interrupt flag bits are clear prior to
enabling an interrupt.
REGISTER 2-3:INTCON – INTERRUPT CONTROL REGISTER (ADDRESS: 0Bh OR 8Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
GIEPEIET0IEINTERAIE
bit 7bit 0
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: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 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: TMR0 Overflow Interrupt Flag bit
1 = TMR0 regis ter has over flowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interru pt 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 <5:0> pins changed state (must be cleared in software)
0 = None of the PORTA <5:0> pins have changed state
(2)
(3)
(1)
(1)
T0IF
(2)
INTFRAIF
(3)
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 clearing the T0IF bit.
3: MCLR
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 7EEIF: EEPROM Write Operation Interrupt Flag bit
1 = The write operation completed (must be cleared in software)
0 = The write operation has not completed or has not been started
bit 6LVDIF: Low-Voltage Detect Interrupt Flag bit
1 = The supply voltage has crossed selected LVD voltage (must be cleared in software)
0 = The supply voltage has not crossed selected LVD voltage
bit 5CRIF: Cryptographic Interrupt Flag bit
1 = The Cryptographic module has completed an operation (must be cleared in software)
0 = The Cryptographic module has not completed an operation or is Idle
bit 4C2IF: Comparator 2 Interrupt Flag bit
1 = Comparator output (C2OUT bit) has changed (must be cleared in software)
0 = Comparator output (C2OUT bit) has not changed
bit 3C1IF: Comparator 1 Interrupt Flag bit
1 = Comparator output (C1OUT bit) has changed (must be cleared in software)
0 = Comparator output (C1OUT bit) has not changed
bit 2OSFIF: Oscillator Fail Interrupt Flag bit
1 = System oscillator failed, clock input has changed INTOSC (must be cleared in software)
0 = System clock operating
bit 1Unimplemented: Read as ‘0’
bit 0TMR1IF: Timer1 Interrupt Flag bit
1 = Timer1 rolled ov er (must be cleared in software)
0 = Timer1 has not rolled over
Note:Interrupt flag bits are set when an interrupt
condition occurs, regar dless of the st ate of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE (INTCON<7>).
User software should ensure the
appropriate interrupt flag bits are clear
prior to enabling an interrupt.
(1)
(1)
C1IFOSFIF—TMR1IF
Note 1: PIC16F636/639 only.
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
The Program Counter (PC) is 13 bits wide. The low byte
comes from the PCL register, which is a readable and
writable register. The high byte (PC<12:8>) is not
directly readable or writable and comes from PCLATH.
On any Reset, the PC is cleared. Figure 2-5 shows the
two situations for the loading of the PC. The upper
example in Figure 2-5 shows how the PC is loaded on a
write to PCL (PCLATH<4:0> → PCH). The lower
example in Figure 2-5 shows how the PC is loaded
during a CALL or GOTO instruction (PCLATH<4:3> →
PCH).
FIGURE 2-5:LOADING OF PC IN
DIFFERENT SITUATIONS
PCHPCL
128 70
PC
PCLATH<4:0>
5
PCLATH
PCHPCL
12 11 100
PC
2
87
PCLATH<4:3>
PCLATH
11
Instruction with
PCL as
Destination
8
ALU Result
GOTO, CALL
Opcode<10:0>
2.3.1COMPUTED GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL). When
performing a table read using a computed GOTO
method, care should be exercised if the table location
crosses a PCL memory boundary (each 256-byte
block). Refer to the Application Note AN556,“Implementing a Table Read” (DS00556).
2.3.2STACK
The PIC12F635/PIC16F636/639 family has an 8level x 13-bit wide hardware stack (see Figure 2-1).
The stack space is not part of either program or data
space and the S ta ck Pointer i s not rea dable or writa ble.
The PC is PUSHed onto the stack when a CALL
instruction is execute d or an interrupt ca uses a branc h.
The stack is POP ed in the event of a RETURN, RETLW
or a RETFIE instruction execution. PCLATH is not
affected by a P USH or POP operation.
The stack operat es as a circular buf fer . This means th at
after the stack has been PUSHed eight times, the ninth
push overwrites the va lue tha t was s tored fro m the first
push. The tenth pus h ov erwr i tes the se co nd push (and
so on).
Note 1: There are no Status bits to indicate stack
overflow or stack underflow conditions.
2: There are no instructions/mnemonics
called PUSH or POP. These are actions
that occur from the exec ution of the CALL,RETURN, RETLW and RETFIE instru ction s
or the vectoring to an interrupt address.
The INDF register is not a physi cal register. Addres sing
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF
register. Any instruction using the INDF register
actually accesses data pointed to by the File Select
Register (FSR). Reading INDF itself indirectly will
produce 00h. Writing to the INDF register indirectly
results in a no operation (although Status bits may be
A simple program to clear RAM lo catio n 20h-2Fh usin g
indirect addressing is shown in Example 2-1.
EXAMPLE 2-1:INDIRECT ADDRESSING
MOVLW 0x20;initialize pointer
MOVWF FSR;to RAM
NEXTCLRFINDF;clear INDF register
INCFFSR;INC POINTER
BTFSS FSR,4;all done?
GOTONEXT;no clear next
CONTINUE;yes continue
affected). An effective 9-bit address is obtained by
concatenating the 8-bit FSR and the IRP bit
(STATUS<7>), as shown in Figure 2-6.