14.0 Special Features of the CPU..................................................................................................................................................... 95
15.0 Instruction Set Summary......................................................................................................................................................... 113
16.0 Development Support.............................................................................................................................................................. 125
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.
New Customer Notification System
Register on our web site (www.microchip.com/cn) to receive the most current information on our products.
Errata
An errata sheet may exist for current devices, des cribing minor operational differences (from the data sheet) a nd recommended
workarounds. 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: (602) 786-7277
When contacting a sales office or the literature center , please speci fy which device, revision of silicon and data sheet (include liter-
ature number) you are using.
Corrections to this Data Sheet
We constantly strive to improve the quality of all our products and documentation. We have spent a great deal of time to ensure
that this document is correct. However, we realize that we may have missed a few things. If you find any information that is missing
or appears in error, please:
• Fill out and mail in the reader response form in the back of this data sheet.
• E-mail us at webmaster@microchip.com.
We appreciate your assistance in making this a better document.
DS40300B-page 4Preliminary 1999 Microchip Technology Inc.
PIC16F62X
1.0GENERAL DESCRIPTION
The PIC16F62X are 18-Pin FLASH-based mem bers of
the versatile PIC16CXX family of low-cost,
high-performance, CMOS, fully-static, 8-bit
microcontrollers.
®
All PICmicro
RISC architecture. The PIC16F62X have enhanced
core features, eight- level deep stack, and multi ple internal and external interrupt sources. The separate
instruction and data buses of the Harvard architec ture
allow a 14-bit wide instruction word with the separate
8-bit wide data. The two-stage instruction pipeline
allows all instructions to execute in a single-cycle,
except for program branches (which require two
cycles). A total of 35 instructions (reduced instruction
set) are available . Additionally , a large register set gives
some of the architectural in novation s used to achieve a
very high performance.
PIC16F62X microcontrollers typically achieve a 2:1
code compression and a 4:1 speed improvement over
other 8-bit microcontrollers in their class.
PIC16F62X de vices have spec ial features to r educe
external components, thus reducing system cost,
enhancing system reliability and reducing power consumption. There are eight oscillator configurations, of
which the single pin ER oscillator provides a low-cost
solution. The LP os ci ll ator minimizes power consumption, XT is a standard crystal, INTRC is a self-contained
internal oscillator and the HS is for High Speed crystals. The SLEEP (power-down) mode offers power savings. The user can wake up the chip from SLEEP
through several external and internal interrupts and
reset.
A highly reliable Watchdog Timer with its own on-chip
RC oscillator provides protection against software
lock- up.
Table 1-1 shows the features of the PIC16F62X
mid-range mic r o c on t r o l l e r fa m ilies.
A simplified block d iagram of the PIC16F62 X is shown
in Figure 3-1.
The PIC16F62X series fits in applica tions ranging fro m
battery chargers to low-power remote sensors. The
FLASH technology makes customization of applicatio n
programs (detection levels, pulse generation, timers,
etc.) extremely fas t and conv enient. The small foo tprint
packages make this microcontroller series ideal for all
applications with space limitations. Low-cost,
low-power , high-p erformance, eas e of use and I/O flexibility make the PIC16F62X ve ry versatile.
microcontrollers employ an advanced
1.1Development Support
The PIC16F62X family is supported by a full-featured
macro assembler, a software simulator, an in-circuit
emulator, a low-cost development programmer and a
full-featured programmer. A Third Party “C” compiler
FLASH Program Memory (words) 1024204810242048
RAM Data Memory (bytes)224224224224
EEPROM Data Memory (bytes)128128128128
Timer Module(s)TMR0, TMR1, TMR2 TMR0, TMR1, TMR2 TMR0, TMR1, TMR2TMR0, TMR1, TMR2
Comparators(s)2222
Capture/Compare/PWM modules 1111
Serial CommunicationsUSARTUSARTUSARTUSART
Internal Voltage ReferenceYesYesYesYes
Interrupt Sources10101010
I/O Pins16161616
Voltage Range (Volts)3.0-5.53.0-5.52.0-5.52.0-5.5
Brown-out DetectYesYesYesYes
Packages18-pin DIP ,
All PICmicro® Family devices have Power-on Reset, selectable Watchdog Timer, selectable code protect and high I/O current
capability. All P IC 16F62X Family devices use serial programming with clock pin RB6 and data pin RB7.
20202020
SOIC;
20-pin SSOP
18-pin DIP,
SOIC;
20-pin SSOP
18-pin DIP,
SOIC;
20-pin SSOP
18-pin DIP,
SOIC;
20-pin SSOP
DS40300B-page 6Preliminary 1999 Microchip Technology Inc.
2.0PIC16F62X DEVICE VARIETIES
A variety of frequency ranges and packaging options are
available. Depending on application and production
requirements the proper device option can be selected
using the information in the PIC16F62X Product
Identification System section at the end of this data
sheet. When placing orders, please use this page of the
data sheet to specify the correct part number.
2.1Flash Devices
These devices are offered in the lower cost plastic
package, even though the device can be erased and
reprogrammed. This al lows the same device to be used
for prototype development and pilot programs as well
as production.
A further advantage of the electrically-erasable Flash
version is that it can be erased and reprogrammed
in-circuit, or by device programmers, such as
Microchip’s PICSTART
programmers.
®
Plus or PRO MATE® II
PIC16F62X
2.2Quick-Turnaround-Production (QTP)
Devices
Microchip offers a QTP Programming Service for
factory production orders. This service is made
available for users who chose not to program a medium
to high quantity of un its a nd whose code patterns have
stabilized. The devices are standard FLASH devices
but with all progr am locations and configu ration option s
already pro gramme d by th e fact ory. Certain code and
prototype verification procedures apply before
production shipments are available. Please contact
your Microchip T ec hnology sal es office for more deta ils.
Microchip offers a unique programming service where
a few user-defined locations in each device are
programmed with different serial numbers. The serial
numbers may be random, pseudo-random or
sequential.
Serial programming allows each device to have a
unique number which can serve as an entry-code,
password or ID number.
DS40300B-page 8Preliminary 1999 Microchip Technology Inc.
PIC16F62X
3.0ARCHITECTURAL OVERVIEW
The high performance of the PIC1 6F62X family can be
attributed to a number of architectural features
commonly found in RISC microprocessors. To begin
with, the PIC16F62X uses a Harvard architecture, in
which, program and data are accessed from separate
memories using separate busses. This improves
bandwidth over traditional von Neumann architecture
where program and data are fetched from the same
memory . Separa ting prog ram and data memory furth er
allows instructi ons to be si zed differe ntly than 8-bit wide
data word. Instruction op codes are 14-bits w ide making
it possible to have all single word instructions. A 14-bit
wide program memory access bus fetches a 14-bit
instruction in a single cycle. A two-stage pipeline overlaps fetch and exec ution of instructions. Consequently,
all instructions (3 5) execute in a sing le-cycle (200 ns @
20 MHz) except for program branches.
The Table below lists program memory (Flash, Data
and EEPROM).
Memory
Device
PIC16F6271024 x 14224 x 8128 x 8
PIC16F6282048 x 14224 x 8128 x 8
PIC16LF6271024 x 14224 x 8128 x 8
PIC16LF6282048 x 14224 x 8128 x 8
The PIC16F62X can directly or indirectly address its
register files or data memory. All special function
registers including the program counter are mapped in
the data memory. The PIC16F62X have an orthog onal
(symmetrica l) instruct ion set that m akes it possib le to
carry out any operation on any register using any
addressing mode. This symmetrical nature and lack of
‘special optimal situations’ make programming with the
PIC16F62X simple yet efficient. In addition, the
learning curve is reduced significantly.
FLASH
Program
RAM
Data
EEPROM
Data
The PIC16F62X devices contain an 8-bit ALU and
working register. The ALU is a general purpose
arithmetic unit. It performs arithmetic and Boolean
functions between d ata i n t he w ork ing re gi ste r a nd any
register file.
The ALU is 8-bit wide and capable of addition,
subtraction, shift and logical operations. Unless
otherwise mentioned, arithmetic operations are two's
complement in nature. In two-operand instructions,
typically one operand is the working register
(W register). The other operand is a file register or an
immediate constant . In sin gle ope rand in structi ons, th e
operand is either the W register or a file register.
The W register is an 8-bit working regi ster used for ALU
operations. It is not an addressable register.
Depending on the instruction executed, the ALU may
affect the values of the Carry (C), Digit Carry (DC), and
Zero (Z) bits in the STATUS regi ster . The C and D C bits
operate as a Bo
respectively, bit in subtraction. See the SUBLW and
SUBWF instructions for examples.
A simplified block diagram is shown in Figure 3-1, with
a description of the device pins in Table 3-1.
Two types of data memory are provided on the
PIC16F62X devices. Non-volatile EEPROM data
memory is provided for long term storage of data such
as calibration value s, look up table da ta, and any oth er
data which may require periodic updating in the field.
This data is not lost when po wer is removed. Th e other
data memory provided is regular RAM data memory.
Regular RAM data memory is provide d for tempo rary
storage of data during norm al operati on. It is lost when
power is removed.
Note 1: This buffer is a Schmitt Trigger input when config ured as the external interrupt.
Note 2: This buffer is a Schmitt Trigger input when used in serial programming mode.
Note 3: This buffer is a Schmitt Trigger I/O when used in USART/Synchronous mode.
Note 4: This buffer is a Schmitt Trigger I/O when used in CCP mode.
Note 5: This buffer is a Schmitt Trigger input when used in low voltage program mode.
I/O/P
Type
Buffer
Type
TTL/ST
(3)
(3)
(4)
(5)
(2)
(2)
Description
put
tor output
parator output
input. When configured as MCLR
reset to the device. Voltage on MCLR
exceed V
to crystal or resonator in crystal oscillator mode. In ER
mode, OSC2 pin outputs CLKOUT which has 1/4 the frequency of OSC1, and denotes the instruction cycle rate.
clock source input. ER biasing pin.
(1)
Bi-directional I/O port/external interrupt. Can be software
programmed for internal weak pull-up.
Bi-directional I/O port/ USART receive pin/synchronous
data I/O. Can be software programmed for internal weak
pull-up.
Bi-directional I/O port/ USART transmit pin/synchronous
clock I/O. Can be software programmed for internal weak
pull-up.
Bi-directional I/O port/Capture/Compare/PWM I/O. Can
be software programmed for internal weak pull-up.
Bi-directional I/O port/Low voltage programming input pin.
Wake-up from SLEEP on pin change. Can be software
programmed for internal weak pull-up. When low voltage
programming is enabled, the interrupt on pin change and
weak pull-up resistor are disabled.
change. Can be software programmed for internal weak
pull-up.
Bi-directional I/O port/Timer1 oscillator output/Timer1
clock input. Wake up from SLEEP on pin change. Can be
software programmed for internal weak pull-up.
Bi-directional I/O port/Timer1 oscillator input. Wake up
from SLEEP on pin change. Can be software programmed
for internal weak pull-up.
The clock input (OSC1/CLKIN/RA7 pin) is internally
divided by four to generate four non-overlapping
quadrature clocks namely Q 1, Q2, Q3 and Q4. Internally, the program coun ter (PC) is inc remented ever y
Q1, the instruction is fetched from the program memo ry
and latched into the instruction register in Q4. The
instruction is decoded and executed during the
following Q1 through Q4. The clocks and instruction
execution flow is shown in Figure 3-2.
FIGURE 3-2:CLOCK/INSTRUCTION CYCLE
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(ER mode)
Q1
PCPC+1PC+2
Fetch INST (PC)
Execute INST (PC-1)Fetch INST (PC+1)
Q1
3.2Instruction Flow/Pipelining
An “Instructi on Cycle” consists of four Q cy cles (Q1,
Q2, Q3 and Q4). The instruc tio n fe tch and ex ecu te a r e
pipelined such that fetch takes one instruction cycle
while decode and execute takes another instruction
cycle. However, due to the pipelining, each instruction
effectively executes in one cycle. If an instruction
causes the program counter to change (e.g., GOTO)
then two cycles a re required to c omplete the i nstruction
(Example 3-1).
A fetch cycle begins with the program counter (PC)
incrementing in Q1.
In the execution cy cle, the fetched instruction i s latched
into the “Instruction Register (IR)” in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3, and Q4 cycles. Data memory is read duri ng Q2
(operand read) and written during Q4 (destination
write).
Q2Q3Q4
Execute INST (PC)Fetch INST (PC+2)
Q2Q3Q4
Q1
Execute INST (PC+1)
Internal
phase
clock
EXAMPLE 3-1:INSTRUCTION PIPELINE FLOW
1. MOVLW 55h
2. MOVWF PORTB
3. CALL SUB_1
4. BSF PORTA, BIT3
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.
DS40300B-page 12Preliminary 1999 Microchip Technology Inc.
Fetch 1Execute 1
Fetch 2Execute 2
Fetch 3Execute 3
Fetch 4Flush
Fetch SUB_1 Execute SUB_1
PIC16F62X
4.0MEMORY ORGANIZATION
4.1Program Memory Organization
The PIC16F62X has a 13-bi t program c ounter capabl e
of addressing an 8K x 14 program memory space . Only
the first 1K x 14 (0000h - 03FFh) for the PIC16F627
and 2K x 14 (0000h - 07FFh) for the PIC16F628 are
physically implemented. Accessing a location above
these boundaries will cause a wrap-around within the
first 1K x 14 space (PIC16F627) or 2K x 14 space
(PIC16F628). The reset vector is at 0000h and the
interrupt vector is at 0004h (Figu re 4-1 and Figure 4-2).
FIGURE 4-1:PROGRAM MEMORY MAP
AND STACK FOR THE
PIC16F627
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
13
000h
FIGURE 4-2: PROGRAM MEMORY MAP AND
STACK FOR THE PIC16F628
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
Interrupt Vector
On-chip Program
Memory
13
000h
0004
0005
07FFh
0800h
1FFFh
4.2Data Memory Organization
Interrupt Vector
On-chip Program
Memory
0004
0005
03FFh
0400h
1FFFh
The data memory (Figure4-3) is partitioned into four
Banks which contain the general purpos e registers and
the special function registers. The Special Function
Registers are located in the first 32 locations of ea ch
Bank. Register l ocations 20-7 Fh, A0h-FF h, 120h-14F h,
170h-17Fh and 1F0h-1FFh are general purpose registers implem ented as static RAM.
The Table below lists how to access the four banks of
registers:
RP1RP0
Bank000
Bank101
Bank210
Bank311
Addresses F0h-FFh, 170h-17Fh and 1F0h-1FFh are
implemented as common RAM and mapped back to
addresses 70h-7Fh.
4.2.1GENERAL PURPOSE REGISTER FILE
The register file is organized as 224 x 8 in the
PIC16F62X. Each is accessed either directly or indirectly through the File Select Register FSR
(Section 4.4).
DS40300B-page 14Preliminary 1999 Microchip Technology Inc.
PIC16F62X
4.2.2SPECIAL FUNCTION REGISTERS
The special fu nctio n regi sters are re gisters us ed by the
CPU and Peripheral functions for controlling the
desired operation of the device (Table 4-1). These
registers are static RAM.
The special registers can be classified into two sets
(core and peripheral). The special function registers
associated with the “core” functions are described in
this section. Those related to the operation of the
peripheral features are described in the section of that
peripheral feature.
TABLE 4-1:SPECIAL REGISTERS SUMMARY BANK0
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
POR
Reset
Bank 0
Value on
00hINDFAddressing this location uses contents of FSR to address data memory (not a physical register)xxxx xxxx xxxx xxxx
01hTMR0Timer0 Module’s Registerxxxx xxxx uuuu uuuu
02hPCLProgram Counter's (PC) Least Significant Byte0000 0000 0000 0000
03hSTATUS
04hFSRIndirect data memory address pointerxxxx xxxx uuuu uuuu
05hPORTA
06hPORTBRB7RB6RB5RB4RB3RB2RB1RB0xxxx xxxx uuuu uuuu
07hUnimplemented——
08hUnimplemented——
09hUnimplemented——
0AhPCLATH———Write buffer for upper 5 bits of program counter---0 0000 ---0 0000
0BhINTCONGIE PEIET0IEINTERBIET0IFINTFRBIF0000 000x 0000 000u
0ChPIR1
0DhUnimplemented——
0EhTMR1LHolding register for the least significant byte of the 16-bit TMR1xxxx xxxx uuuu uuuu
0FhTMR1HHolding register for the most significant byte of the 16-bit TMR1xxxx xxxx uuuu uuuu
10hT1CON
11hTMR2TMR2 module’s register0000 0000 0000 0000
12hT2CON
13hUnimplemented——
14hUnimplemented——
15hCCPR1LCapture/Compare/PWM register (LSB)xxxx xxxx uuuu uuuu
16hCCPR1HCapture/Compare/PWM register (MSB)xxxx xxxx uuuu uuuu
17hCCP1CON
18hRCSTASPENRX9SRENCRENADENFERROERRRX9D0000 -00x 0000 -00x
19hTXREGUSART Transmit data register0000 0000 0000 0000
1AhRCREGUSART Receive data register0000 0000 0000 0000
1BhUnimplemented——
1ChUnimplemented——
1DhUnimplemented——
1EhUnimplemented——
1FhCMCONC2OUT C1OUT
———Write buffer for upper 5 bits of program counter---0 0000---0 0000
xxxx xxxxxxxx xxxx
Value on
all other
resets
Legend: — = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition,
shaded = unimplemented
Note 1: Other (non pow e r-up) res ets in cl ude M C LR R eset, Brown-out Detect and Watchdog Timer Reset during
normal operation.
(1)
DS40300B-page 18Preliminary 1999 Microchip Technology Inc.
PIC16F62X
4.2.2.1STATUS REGISTER
The STATUS register, shown in Register 4-1, contains
the arithmetic status o f the ALU, the RESET status and
the bank select bits for data memory (SRAM).
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 bits ar e set or cl eared acco rding to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
STATUS regis ter as destina tion may be differen t than
intended.
For example, CLRF STATUS will clear the upper-three
bits and set the Z bi t. This lea ves the status register as
000uu1uu (where u = unchanged).
and PD bits are not
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 stat us bit. For other instructi ons, not affectin g
any status bits, see the “Instruction Set Summary”.
Note 1:The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtractio n. See the SUBLW and SUBWF
instructi ons for examples.
REGISTER 4-1: STATUS REGISTER (ADDRESS 03H OR 83H)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TOPDZDCCR = Readable bit
bit7bit0
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)
bit 4:TO
bit 3:PD
bit 2:Z: Zero bit
bit 1:DC: Digit carry/borrow
bit 0:C: 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
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 (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 si gnificant bit of the result occurred
Note: For borrow
second operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low or der bit of
the source register.
the polarity is re versed. A subtraction is executed by add in g th e two’s complement of the
W = Writable bit
U = Unimplemented bit,
read as ’0’
4.2.2.2OPTION REGISTER
The OPTION register is a readable and writable
register which conta ins vario us control bits to conf igure
the TMR0/WDT prescaler, the external RB0/INT
interrupt, TMR0, and the weak pull-ups on PORTB.
REGISTER 4-2: OPTION REGISTER (ADDRESS 81H)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
RBPUINTEDG T0CST0SEPSAPS2PS1PS0R = Readable bit
bit7bit0
bit 7:RBPU
bit 6:INTEDG: Interrupt Edge Select bit
bit 5:T0CS: TMR0 Clock Source Select bit
bit 4:T0SE: TMR0 Source Edge Select bit
bit 3:PSA: Prescaler Assignment bit
bit 2-0: PS2:PS0: Prescaler Rate Select bits
: PORTB Pull-up Enable bit
1 = PORTB pull-ups are disabled
0 = PORTB pull-ups are enabled by individual port latch values
1 = Interrupt on rising edge of RB0/INT pin
0 = Interrupt on falling edge of RB0/INT pin
1 = Transition on RA4/T0CKI pin
0 = Internal in struction cycle clock (CLKOUT)
1 = Increment on high-to-low transition on RA4/T0CKI pin
0 = Increment on low-to-high transition on RA4/T0CKI pin
1 = Prescaler is assigned to the WDT
0 = Prescaler is assigned to the Timer0 module
TMR0, assign the prescaler to the WDT
(PSA = 1). See Section 6.3.1
W = Writable bit
-n = Value at POR reset
DS40300B-page 20Preliminary 1999 Microchip Technology Inc.
PIC16F62X
4.2.2.3INTCON REGISTER
The INTCON register is a readable and writable
register which cont ains the v arious enable and flag bits
for all interrupt sourc es e xcept the com parator modul e.
See Section 4.2.2.4 and Section 4.2.2.5 for a
description of the co mparator enable and flag bits.
Note:Interrupt flag bits get set when an interrupt
condition occurs regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>).
REGISTER 4-3: INTCON REGISTER (ADDRESS 0BH OR 8BH)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIEPEIET0IEINTERBIET0IFINTFRBIFR = Readable bit
bit7bit0
bit 7:GIE: Global Interrupt Enable bit
1 = Enables all un-masked interrupts
0 = Disables all interrupts
bit 6:PEIE: Peripheral Interrupt Enable bit
1 = Enables all un-masked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5:T0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4:INTE: RB0/INT External Interrupt Enable bit
1 = Enables the RB0/INT external interrupt
0 = Disables the RB0/INT external interrupt
bit 3:RBIE: RB Port Change Interrupt Enable bit
1 = Enables the RB port change interrupt
0 = Disables the RB port change inter rupt
bit 2:T0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 register has over flowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1:INTF: RB0/INT External Interrupt Flag bit
1 = The RB0/INT external interrupt occurred (must be cleared in software)
0 = The RB0/INT external interrupt did not occur
bit 0:RBIF: RB Port Change Interrupt Flag bit
1 = When at least one of the RB7:RB4 pins changed state (must be cleared in software)
0 = None of the RB7:RB4 pins have changed state
4.2.2.4PIE1 REGISTER
This register contains interrupt enable bits.
REGISTER 4-4: PIE1 REGISTER (ADDRESS 8CH)
R/W-0R/W-0R/W-0R/W-0UR/W-0R/W-0R/W-0
EEIECMIERCIETXIE-CCP1IETMR2IE TMR1IER = Readable bit
bit7bit0
bit 7:EEIE: EE Write Complete Interrupt Enable Bit
1 = Enables the EE write complete interrupt
0 = Disables the EE write complete interrupt
bit 6:CMIE: Comparator Interrupt Enable bit
1 = Enables the comparator interrupt
0 = Disables the comparator interrupt
bit 5:RCIE: USART Receive Interrupt Enable bit
1 = Enables the USART receive interrupt
0 = Disables the USART receive interrupt
bit 4:TXIE: USART Transmit Interrupt Enable bit
1 = Enables the USART transmit interrupt
0 = Disables the USART transmit interrupt
bit 3:Unimplemented: Read as ‘0’
bit 2:CCP1IE: CCP1 Interrupt Enable bit
1 = Enables the CCP1 interrupt
0 = Disables the CCP1 interrupt
bit 1:TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
1 = Enables the TMR2 to PR2 match interrupt
0 = Disables the TMR2 to PR2 match interrupt
bit 0:TMR1IE: TMR1 Overflow Interrupt Enable bit
1 = Enables the TMR1 overfl ow interrupt
0 = Disables the TMR1 overflow interrupt
W = Writable bit
U = Unimplemented bit, read
as ’0’
-n = Value at POR reset
DS40300B-page 22Preliminary 1999 Microchip Technology Inc.
PIC16F62X
4.2.2.5PIR1 REGISTER
This register contains interrupt flag bits.
Note:Interrupt flag bits get set when an interrupt
condition occurs regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to enabling
an interrupt.
REGISTER 4-5: PIR1 REGISTER (ADDRESS 0CH)
R/W-0R/W-0R-0R-0UR/W-0R/W-0R/W-0
EEIFCMIFRCIFTXIF-CCP1IFTMR2IF TMR1IFR = Readable bit
bit7bit0
bit 7:EEIF: 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 6:CMIF: Comparator Interrupt Flag bit
1 = Comparator input has changed
0 = Comparator input has not changed
bit 5:RCIF: USART Receive Interrupt Flag bit
1 = The USART receive buffer is full
0 = The USART receive buffer is empty
bit 4:TXIF: USART Transmit Interrupt Flag bit
1 = The USART transmit buffer is empty
0 = The USART transmit buffer is full
bit 3:Unimplemented: Read as ‘0’
bit 2:CCP1IF: CCP1 Interrupt Flag bit
Capture Mode
1 = A TMR1 register capture occurred (must be cleared in software)
0 = No TMR1 register capture occurred
Compare Mode
1 = A TMR1 register compare match occurred (must be cleared in software)
0 = No TMR1 register compare match occurred
PWM Mode
Unused in this mode
bit 1:TMR2IF: TMR2 to PR2 Match Interrupt Flag bit
1 = TMR2 to PR2 match occurred (must be cleared in so ftware)
0 = No TMR2 to PR2 match occurred
bit 0:TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = TMR1 register overflowed (must be cleared in software)
0 = TMR1 register did not overflow
4.2.2.6PCON REGISTER
The PCON register contains flag bits to differentiate
between a Power-on Reset, an external MCLR
WDT reset or a Brown-out Detec t.
Note: BOD is unknown on Power-on Reset. It
must then be set by the user and checked
on subsequent resets to see if BOD
cleared, indicating a brown-out has
occurred. The BOD status bit is a "don’t
care" and is not necessarily predictable if
the brown-out circuit is disabled (by
programming BOREN bit in the
Configuration word).
REGISTER 4-6: PCON REGISTER (ADDRESS 8Eh)
U-0U-0U-0U-0R/W-1U-0R/W-qR/W-q
————OSCF—PORBODR = Readable bit
bit7bit0
bit 7-4,2:Unimplemented: Read as '0'
bit 3:OSCF: INTRC/ER oscillator speed
1 = 4 MHz typical
0 = 37 KHz typical
bit 1:POR
bit 0:BOD
: Power-on Reset Status bit
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Detect Status bit
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)
(1)
reset,
is
W = Writable bit
U = Unimplemented bit, read
as ’0’
-n = Value at POR reset
Note 1: When in ER o scillator mode, setting OSCF = 1 w ill cause the osc illator speed to c hange to the spee d
specified by the external resistor.
DS40300B-page 24Preliminary 1999 Microchip Technology Inc.
PIC16F62X
4.3PCL and PCLATH
The program counter (PC) is 13-bits wide. Th e low byte
comes from the PCL register, which is a readable a nd
writable register. The high byte (PC<12:8>) is not directly
readable or writable and co mes from PCLATH. On any
reset, the PC is cleared. Figure 4-7 shows the two
situations for the loading of the PC. The upper example in
the figure shows how the PC is loaded on a write to PCL
(PCLATH<4:0> → PCH). The lower example in the figure
shows how the PC is loaded during a CALL or GOTO
instruction (PCLATH<4:3> → PCH).
FIGURE 4-7: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>
11
8
Instruction with
PCL as
Destination
ALU result
GOTO, CALL
Opcode <10:0>
4.3.2STACK
The PIC16F62X family has an 8 level deep x 13-bit
wide hardware stack (Figure 4-1 and Figure 4-2). The
stack space is not part of either program or data space
and the stack pointer is not readable or writable. The
PC is PUSHed onto the stac k when a CALL instruction
is executed or an interrupt causes a branch. The stack
is POPed in the event of a RETURN, RETLW or a RET-FIE instruction execution. PCLATH is not affected by a
PUSH or POP operation.
The stack operates as a circular buf fer . This means th at
after the stack has been PUSH ed eight times , the ninth
push overwrites th e valu e that was s tored fro m the firs t
push. The tenth pus h ov erwr i tes the se cond push (and
so on).
Note 1:There are no STATUS bits to
indicate stack overflow or stack
underflow conditions.
Note 2:There are no instructions/mnemonics
called PUSH or POP. These are actions
that occur from the execution of the
CALL, RETURN, RETLW and RETFIE
instructions, or the vectoring to an
interrupt address.
PCLATH
4.3.1COMPUTED GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL). When doing a
table read using a computed GOTO method, care
should be exercised if the tab le locati on cro sses a PCL
memory boundary (each 256 byte block). Refer to the
application note
The INDF register is not a physical register. Addressing
the INDF register will cause indirect addressing.
Indirect address ing is possible by using the INDF register .
Any instruction u sing the I NDF regis ter actuall y accesse s
data pointed to by the file select register (FSR). Reading
INDF itself indire ctly will pro duce 00h. W riting t o the INDF
register indirectly results in a no-operation (although status bits 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 4-8.
A simple program to clear RAM location 20h-2Fh using
indirect addressing is shown in Example 4-1.
NEXTclrfINDF;clear INDF register
CONTINUE:
FIGURE 4-8:DIRECT/INDIRECT ADDRESSING PIC16F62X
RP1 RP06
from opcode
0
movlw 0x20;initialize pointer
movwf FSR;to RAM
incfFSR;inc pointer
btfss FSR,4;all done?
gotoNEXT;no clear next
;yes continue
Indirect AddressingDirect Addressing
IRPFSR register
7
0
bank selectlocation select
00h
Data
Memory
7Fh
Bank 0Bank 1Bank 2Bank 3
For memory map detail see Figure 4-3.
00011011
bank select
180h
1FFh
location select
DS40300B-page 26Preliminary 1999 Microchip Technology Inc.
PIC16F62X
5.0I/O PORTS
The PIC1 6F6 2X have two ports, PORTA and PORTB.
Some pins for these I/O ports are multiplexed with an
alternate function for the peripheral features on the
device. In general, when a peripheral is enabled, that
pin may not be used as a general purpose I/O pin.
5.1PORTA and TR ISA Registers
PORTA is an 8-bit wide latch. RA4 i s a Schmitt Trigger
input and an open drain o utput. Port RA4 is multiplexed
with the T0CKI clock input. RA5 is a Schmitt Trigger input
only and has no output drivers. All other RA port pins have
Schmitt Trigger input levels and full CMOS output drivers.
All pins have data direction bits (TRIS registers) which can
configure these pins as input or output.
A ’1’ in the TRISA register p uts the cor responding o utput
driver in a hi- impedance mode. A ’0’ in the TRISA register
puts the contents of the output latch on the selected pin(s).
Reading the PORT A register reads the status of the pins
whereas writing to it will write to the port latch. All write
operations are read-modify-write operations. So a write
to a port implies that the port pins are first read, then this
value is modified and written to the port data latch.
The PORTA pins are multiplexed with comparator and
voltage reference functions. The operation of these
pins are selected by control bits in the CMCON
(comparator control register) register and the VRCON
(voltage reference control register) register. When
selected as a comparator input, these pins will read
as ’0 ’s.
Note 1: On reset, the TRISA register is set to all
inputs. The digi tal in puts are disabled and
the comparator inputs are forced to
ground to reduce excess current consumption.
Note 2: When RA6/OSC2/CLKOUT is configured
as CLKOUT , the corresponding TRI S bit is
overridden and the p in is conf igured as a n
output. The PORTA data bit reads 0, and
the PORTA TRIS bit reads 0.
TRISA controls the di rection of the RA pins , even whe n
they are being used as comparator inputs. The user
must make sure to keep the pins configured as inputs
when using them as comparator inputs.
The RA2 pin will also function as the output for the
voltage reference. W hen in th is mode, th e V
very high impedance output. The user must configure
TRISA<2> bit as an input and use high impedance
loads.
In one of the comparator modes defined by the
CMCON register, pins RA3 and RA4 become outputs
of the comparators. The TRISA<4:3> bits must be
cleared to enable outputs to use this function.
REF pin is a
EXAMPLE 5-1:INITIALIZING PORTA
CLRF PORTA;Initialize PORTA by setting
MOVLW 0X07;Turn comparators off and
MOVWF CMCON;enable pins for I/O
BCFSTATUS, RP1
BSFSTATUS, RP0 ;Select Bank1
MOVLW 0x1F;Value used to initialize