Post on 19-Apr-2020
transcript
1999 Microchip Technology Inc. Preliminary DS40300B-page 1
Devices included in this data sheet:
• PIC16F627 • PIC16F628
Referred to collectively as PIC16F62X .
High Performance RISC CPU:
• Only 35 instructions to learn• All single-cycle instructions (200 ns), except for
program branches which are two-cycle• Operating speed:
- DC - 20 MHz clock input
- DC - 200 ns instruction cycle
• Interrupt capability• 16 special function hardware registers• 8-level deep hardware stack• Direct, Indirect and Relative addressing modes
Peripheral Features:
• 15 I/O pins with individual direction control• High current sink/source for direct LED drive• Analog comparator module with:
- Two analog comparators- Programmable on-chip voltage reference
(VREF) module- Programmable input multiplexing from device
inputs and internal voltage reference- Comparator outputs are externally accessible
• Timer0: 8-bit timer/counter with 8-bit programmable prescaler
• Timer1: 16-bit timer/counter with external crystal/clock capability
• Timer2: 8-bit timer/counter with 8-bit period regis-ter, prescaler and postscaler
• Capture, Compare, PWM (CCP) module- Capture is 16-bit, max. resolution is 12.5 ns
- Compare is 16-bit, max. resolution is 200 ns- PWM max. resolution is 10-bit
• Universal Synchronous/Asynchronous Receiver/Transmitter USART/SCI
• 16 Bytes of common RAM
Device
Memory
FLASH Program
RAM Data
EEPROM Data
PIC16F627 1024 x 14 224 x 8 128 x 8
PIC16F628 2048 x 14 224 x 8 128 x 8
Special Microcontroller Features:
• Power-on Reset (POR)
• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
• Brown-out Detect (BOD)• Watchdog Timer (WDT) with its own on-chip RC
oscillator for reliable operation• Multiplexed MCLR-pin• Programmable weak pull-ups on PORTB
• Programmable code protection• Low voltage programming• Power saving SLEEP mode
• Selectable oscillator options- FLASH configuration bits for oscillator options- ER (External Resistor) oscillator
- Reduced part count- Dual speed INTRC
- Lower current consumption
- EC External Clock input- XT oscillator mode- HS oscillator mode
- LP oscillator mode• Serial in-circuit programming (via two pins)• Four user programmable ID locations
CMOS Technology:
• Low-power, high-speed CMOS FLASH technology• Fully static design• Wide operating voltage range
- PIC16F627 - 3.0V to 5.5V- PIC16F628 - 3.0V to 5.5V- PIC16LF627 - 2.0V to 5.5V
- PIC16LF628 - 2.0V to 5.5V• Commercial, industrial and extended temperature
range• Low power consumption
- < 2.0 mA @ 5.0V, 4.0 MHz- 15 µA typical @ 3.0V, 32 kHz- < 1.0 µA typical standby current @ 3.0V
FLASH-Based 8-Bit CMOS Microcontrollers
PIC16F62X
PIC16F62X
DS40300B-page 2 Preliminary 1999 Microchip Technology Inc.
Pin Diagrams
Device Differences
Note 1: If you change from this device to another device, please verify oscillator characteristics in your application.
DeviceVoltage Range
OscillatorProcess
Technology(Microns)
PIC16F627 3.0 - 5.5 See Note 1 0.7
PIC16F628 3.0 - 5.5 See Note 1 0.7
PIC16LF627 2.0 - 5.5 See Note 1 0.7
PIC16LF628 2.0 - 5.5 See Note 1 0.7
2 3 4 5 6 7 8 910
•1
2 3 4 5 6 7 8 9
•1
1918
161514131211
17
1817
151413121110
16
20
PDIP, SOIC
SSOP
PIC
16F62X
PIC
16F62X
RA6/OSC2/CLKOUTRA7/OSC1/CLKIN
VSS
VSS
VDD
VDD
RA1/AN1RA0/AN0
RB6/T1OSO/T1CKIRB7/T1OSI
RB1/RX/DTRB2/TX/CKRB3/CCP1 RB4/PGM
RB5
RA3/AN3/CMP1RA4/TOCKI/CMP2
RA5/MCLR/THV
RB0/INT
RA2/AN2/VREF
VSS
RB1/RX/DTRB2/TX/CKRB3/CCP1
RA3/AN3/CMP1RA4/TOCKI/CMP2
RA5/MCLR/THV
RB0/INT
RA2/AN2/VREF
RA6/OSC2/CLKOUTRA7/OSC1/CLKIN
VDD
RA1/AN1RA0/AN0
RB6/T1OSO/T1CKIRB7/T1OSI
RB4/PGMRB5
1999 Microchip Technology Inc. Preliminary DS40300B-page 3
PIC16F62X
Table of Contents1.0 General Description..................................................................................................................................................................... 52.0 PIC16F62X Device Varieties...................................................................................................................................................... 73.0 Architectural Overview ................................................................................................................................................................ 94.0 Memory Organization ................................................................................................................................................................ 135.0 I/O Ports .................................................................................................................................................................................... 276.0 Timer0 Module .......................................................................................................................................................................... 457.0 Timer1 Module .......................................................................................................................................................................... 508.0 Timer2 Module .......................................................................................................................................................................... 549.0 Comparator Module................................................................................................................................................................... 5710.0 Capture/Compare/PWM (CCP) Module .................................................................................................................................... 6311.0 Voltage Reference Module........................................................................................................................................................ 6912.0 Universal Synchronous Asynchronous Receiver Transmitter (USART).................................................................................... 7113.0 Data EEPROM Memory ............................................................................................................................................................ 9114.0 Special Features of the CPU..................................................................................................................................................... 9515.0 Instruction Set Summary ......................................................................................................................................................... 11316.0 Development Support.............................................................................................................................................................. 12517.0 Electrical Specifications........................................................................................................................................................... 13118.0 Device Characterization Information ....................................................................................................................................... 14519.0 Packaging Information............................................................................................................................................................. 147Index .................................................................................................................................................................................................. 151On-Line Support................................................................................................................................................................................. 155Reader Response .............................................................................................................................................................................. 156PIC16F62X Product Identification System........................................................................................................................................ 157
To Our Valued CustomersMost Current Data SheetTo 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 SystemRegister on our web site (www.microchip.com/cn) to receive the most current information on our products.
ErrataAn errata sheet may exist for current devices, describing minor operational differences (from the data sheet) and recommendedworkarounds. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revi-sion 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 specify which device, revision of silicon and data sheet (include liter-ature number) you are using.
Corrections to this Data SheetWe constantly strive to improve the quality of all our products and documentation. We have spent a great deal of time to ensurethat this document is correct. However, we realize that we may have missed a few things. If you find any information that is missingor 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.
PIC16F62X
DS40300B-page 4 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 5
PIC16F62X
1.0 GENERAL DESCRIPTIONThe PIC16F62X are 18-Pin FLASH-based members ofthe versatile PIC16CXX family of low-cost,high-performance, CMOS, fully-static, 8-bitmicrocontrollers.
All PICmicro® microcontrollers employ an advancedRISC architecture. The PIC16F62X have enhancedcore features, eight-level deep stack, and multiple inter-nal and external interrupt sources. The separateinstruction and data buses of the Harvard architectureallow a 14-bit wide instruction word with the separate8-bit wide data. The two-stage instruction pipelineallows all instructions to execute in a single-cycle,except for program branches (which require twocycles). A total of 35 instructions (reduced instructionset) are available. Additionally, a large register set givessome of the architectural innovations used to achieve avery high performance.
PIC16F62X microcontrollers typically achieve a 2:1code compression and a 4:1 speed improvement overother 8-bit microcontrollers in their class.
PIC16F62X devices have special features to reduceexternal components, thus reducing system cost,enhancing system reliability and reducing power con-sumption. There are eight oscillator configurations, ofwhich the single pin ER oscillator provides a low-costsolution. The LP oscillator minimizes power consump-tion, XT is a standard crystal, INTRC is a self-containedinternal oscillator and the HS is for High Speed crys-tals. The SLEEP (power-down) mode offers power sav-ings. The user can wake up the chip from SLEEPthrough several external and internal interrupts andreset.
A highly reliable Watchdog Timer with its own on-chipRC oscillator provides protection against softwarelock- up.
Table 1-1 shows the features of the PIC16F62Xmid-range microcontroller families.
A simplified block diagram of the PIC16F62X is shownin Figure 3-1.
The PIC16F62X series fits in applications ranging frombattery chargers to low-power remote sensors. TheFLASH technology makes customization of applicationprograms (detection levels, pulse generation, timers,etc.) extremely fast and convenient. The small footprintpackages make this microcontroller series ideal for allapplications with space limitations. Low-cost,low-power, high-performance, ease of use and I/O flex-ibility make the PIC16F62X very versatile.
1.1 Development Support
The PIC16F62X family is supported by a full-featuredmacro assembler, a software simulator, an in-circuitemulator, a low-cost development programmer and afull-featured programmer. A Third Party “C” compilersupport tool is also available.
PIC16F62X
DS40300B-page 6 Preliminary 1999 Microchip Technology Inc.
TABLE 1-1: PIC16F62X FAMILY OF DEVICES
PIC16F627 PIC16F628 PIC16LF627 PIC16LF628
Clock Maximum Frequency of Operation (MHz)
20 20 20 20
Memory
FLASH Program Memory (words) 1024 2048 1024 2048
RAM Data Memory (bytes) 224 224 224 224
EEPROM Data Memory (bytes) 128 128 128 128
Peripherals
Timer Module(s) TMR0, TMR1, TMR2 TMR0, TMR1, TMR2 TMR0, TMR1, TMR2 TMR0, TMR1, TMR2
Comparators(s) 2 2 2 2
Capture/Compare/PWM modules 1 1 1 1
Serial Communications USART USART USART USART
Internal Voltage Reference Yes Yes Yes Yes
Features
Interrupt Sources 10 10 10 10
I/O Pins 16 16 16 16
Voltage Range (Volts) 3.0-5.5 3.0-5.5 2.0-5.5 2.0-5.5
Brown-out Detect Yes Yes Yes Yes
Packages 18-pin DIP, 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
All PICmicro® Family devices have Power-on Reset, selectable Watchdog Timer, selectable code protect and high I/O current capability. All PIC16F62X Family devices use serial programming with clock pin RB6 and data pin RB7.
1999 Microchip Technology Inc. Preliminary DS40300B-page 7
PIC16F62X
2.0 PIC16F62X DEVICE VARIETIESA variety of frequency ranges and packaging options areavailable. Depending on application and productionrequirements the proper device option can be selectedusing the information in the PIC16F62X ProductIdentification System section at the end of this datasheet. When placing orders, please use this page of thedata sheet to specify the correct part number.
2.1 Flash Devices
These devices are offered in the lower cost plasticpackage, even though the device can be erased andreprogrammed. This allows the same device to be usedfor prototype development and pilot programs as wellas production.
A further advantage of the electrically-erasable Flashversion is that it can be erased and reprogrammedin-circuit, or by device programmers, such asMicrochip’s PICSTART® Plus or PRO MATE® IIprogrammers.
2.2 Quick-Turnaround-Production (QTP) Devices
Microchip offers a QTP Programming Service forfactory production orders. This service is madeavailable for users who chose not to program a mediumto high quantity of units and whose code patterns havestabilized. The devices are standard FLASH devicesbut with all program locations and configuration optionsalready programmed by the factory. Certain code andprototype verification procedures apply beforeproduction shipments are available. Please contactyour Microchip Technology sales office for more details.
2.3 Serialized Quick-Turnaround-Production (SQTPSM) Devices
Microchip offers a unique programming service wherea few user-defined locations in each device areprogrammed with different serial numbers. The serialnumbers may be random, pseudo-random orsequential.
Serial programming allows each device to have aunique number which can serve as an entry-code,password or ID number.
PIC16F62X
DS40300B-page 8 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 9
PIC16F62X
3.0 ARCHITECTURAL OVERVIEWThe high performance of the PIC16F62X family can beattributed to a number of architectural featurescommonly found in RISC microprocessors. To beginwith, the PIC16F62X uses a Harvard architecture, inwhich, program and data are accessed from separatememories using separate busses. This improvesbandwidth over traditional von Neumann architecturewhere program and data are fetched from the samememory. Separating program and data memory furtherallows instructions to be sized differently than 8-bit widedata word. Instruction opcodes are 14-bits wide makingit possible to have all single word instructions. A 14-bitwide program memory access bus fetches a 14-bitinstruction in a single cycle. A two-stage pipeline over-laps fetch and execution of instructions. Consequently,all instructions (35) execute in a single-cycle (200 ns @20 MHz) except for program branches.
The Table below lists program memory (Flash, Dataand EEPROM).
The PIC16F62X can directly or indirectly address itsregister files or data memory. All special functionregisters including the program counter are mapped inthe data memory. The PIC16F62X have an orthogonal(symmetrical) instruction set that makes it possible tocarry out any operation on any register using anyaddressing mode. This symmetrical nature and lack of‘special optimal situations’ make programming with thePIC16F62X simple yet efficient. In addition, thelearning curve is reduced significantly.
Device
Memory
FLASHProgram
RAMData
EEPROMData
PIC16F627 1024 x 14 224 x 8 128 x 8
PIC16F628 2048 x 14 224 x 8 128 x 8
PIC16LF627 1024 x 14 224 x 8 128 x 8
PIC16LF628 2048 x 14 224 x 8 128 x 8
The PIC16F62X devices contain an 8-bit ALU andworking register. The ALU is a general purposearithmetic unit. It performs arithmetic and Booleanfunctions between data in the working register and anyregister file.
The ALU is 8-bit wide and capable of addition,subtraction, shift and logical operations. Unlessotherwise mentioned, arithmetic operations are two'scomplement in nature. In two-operand instructions,typically one operand is the working register(W register). The other operand is a file register or animmediate constant. In single operand instructions, theoperand is either the W register or a file register.
The W register is an 8-bit working register used for ALUoperations. It is not an addressable register.
Depending on the instruction executed, the ALU mayaffect the values of the Carry (C), Digit Carry (DC), andZero (Z) bits in the STATUS register. The C and DC bitsoperate as a Borrow and Digit Borrow out bit,respectively, bit in subtraction. See the SUBLW andSUBWF instructions for examples.
A simplified block diagram is shown in Figure 3-1, witha description of the device pins in Table 3-1.
Two types of data memory are provided on thePIC16F62X devices. Non-volatile EEPROM datamemory is provided for long term storage of data suchas calibration values, look up table data, and any otherdata which may require periodic updating in the field.This data is not lost when power is removed. The otherdata memory provided is regular RAM data memory.Regular RAM data memory is provided for temporarystorage of data during normal operation. It is lost whenpower is removed.
PIC16F62X
DS40300B-page 10 Preliminary 1999 Microchip Technology Inc.
FIGURE 3-1: BLOCK DIAGRAM
Note 1: Higher order bits are from the STATUS register.
Device
Memory
FLASHProgram
RAMData
EEPROMData
PIC16F627 1024 x 14 224 x 8 128 x 8
PIC16F628 2048 x 14 224 x 8 128 x 8
PIC16LF627 1024 x 14 224 x 8 128 x 8
PIC16LF628 2048 x 14 224 x 8 128 x 8
FLASH
ProgramMemory
13 Data Bus 8
14ProgramBus
Instruction reg
Program Counter
8 Level Stack(13-bit)
RAMFile
Registers
Direct Addr 7
RAM Addr (1) 9
Addr MUX
IndirectAddr
FSR reg
STATUS reg
MUX
ALU
W reg
Power-upTimer
OscillatorStart-up Timer
Power-onReset
WatchdogTimer
InstructionDecode &
Control
TimingGeneration
OSC1/CLKINOSC2/CLKOUT
MCLR VDD, VSS
PORTA
PORTB
RA4/T0CK1/CMP2RA5/MCLR/THV
RB0/INT
8
8
Brown-outDetect
USARTCCP1
Timer0 Timer1 Timer2
RA3/AN3/CMP1RA2/AN2/VREF
RA1/AN1RA0/AN0
8
3
Data EEPROM
RB1/RX/DTRB2/TX/CKRB3/CCP1RB4/PGMRB5RB6/T1OSO/T1CKIRB7/T1OSI
Low-VoltageProgramming
RA6/OSC2/CLKOUTRA7/OSC1/CLKIN
VREF
Comparator
1999 Microchip Technology Inc. Preliminary DS40300B-page 11
PIC16F62X
TABLE 3-1: PIC16F62X PINOUT DESCRIPTION
NameDIP/SOICPin #
SSOPPin #
I/O/PType
BufferType
Description
RA0/AN0 17 19 I/O ST Bi-directional I/O port/Analog comparator input
RA1/AN1 18 20 I/O ST Bi-directional I/O port/Analog comparator input
RA2/AN2/VREF 1 1 I/O ST Bi-directional I/O port/Analog comparator input/VREF out-put
RA3/AN3/CMP1 2 2 I/O ST Bi-directional I/O port/Analog comparator input/compara-tor output
RA4/T0CKI/CMP2 3 3 I/O ST Bi-directional I/O port/Can be configured as T0CKI/com-parator output
RA5/MCLR/THV 4 4 I ST Input port/master clear (reset input/programming voltageinput. When configured as MCLR, this pin is an active lowreset to the device. Voltage on MCLR/THV must notexceed VDD during normal device operation.
RA6/OSC2/CLKOUT 15 17 I/O ST Bi-directional I/O port/Oscillator crystal output. Connectsto crystal or resonator in crystal oscillator mode. In ERmode, OSC2 pin outputs CLKOUT which has 1/4 the fre-quency of OSC1, and denotes the instruction cycle rate.
RA7/OSC1/CLKIN 16 18 I/O ST Bi-directional I/O port/Oscillator crystal input/externalclock source input. ER biasing pin.
RB0/INT 6 7 I/O TTL/ST(1) Bi-directional I/O port/external interrupt. Can be softwareprogrammed for internal weak pull-up.
RB1/RX/DT 7 8 I/O TTL/ST(3) Bi-directional I/O port/ USART receive pin/synchronousdata I/O. Can be software programmed for internal weakpull-up.
RB2/TX/CK 8 9 I/O TTL/ST(3) Bi-directional I/O port/ USART transmit pin/synchronousclock I/O. Can be software programmed for internal weakpull-up.
RB3/CCP1 9 10 I/O TTL/ST(4) Bi-directional I/O port/Capture/Compare/PWM I/O. Canbe software programmed for internal weak pull-up.
RB4/PGM 10 11 I/O TTL/ST(5) Bi-directional I/O port/Low voltage programming input pin.Wake-up from SLEEP on pin change. Can be softwareprogrammed for internal weak pull-up. When low voltageprogramming is enabled, the interrupt on pin change andweak pull-up resistor are disabled.
RB5 11 12 I/O TTL Bi-directional I/O port/Wake-up from SLEEP on pinchange. Can be software programmed for internal weakpull-up.
RB6/T1OSO/T1CKI 12 13 I/O TTL/ST(2) Bi-directional I/O port/Timer1 oscillator output/Timer1clock input. Wake up from SLEEP on pin change. Can besoftware programmed for internal weak pull-up.
RB7/T1OSI 13 14 I/O TTL/ST(2) Bi-directional I/O port/Timer1 oscillator input. Wake upfrom SLEEP on pin change. Can be software programmedfor internal weak pull-up.
VSS 5 5,6 P — Ground reference for logic and I/O pins.
VDD 14 15,16 P — Positive supply for logic and I/O pins.
Legend: O = output I/O = input/output P = power— = Not used I = Input ST = Schmitt Trigger inputTTL = TTL input I/OD =input/open drain output
Note 1: This buffer is a Schmitt Trigger input when configured 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.
PIC16F62X
DS40300B-page 12 Preliminary 1999 Microchip Technology Inc.
3.1 Clocking Scheme/Instruction Cycle
The clock input (OSC1/CLKIN/RA7 pin) is internallydivided by four to generate four non-overlappingquadrature clocks namely Q1, Q2, Q3 and Q4. Inter-nally, the program counter (PC) is incremented everyQ1, the instruction is fetched from the program memoryand latched into the instruction register in Q4. Theinstruction is decoded and executed during thefollowing Q1 through Q4. The clocks and instructionexecution flow is shown in Figure 3-2.
3.2 Instruction Flow/Pipelining
An “Instruction Cycle” consists of four Q cycles (Q1,Q2, Q3 and Q4). The instruction fetch and execute arepipelined such that fetch takes one instruction cyclewhile decode and execute takes another instructioncycle. However, due to the pipelining, each instructioneffectively executes in one cycle. If an instructioncauses the program counter to change (e.g., GOTO)then two cycles are required to complete the instruction(Example 3-1).
A fetch cycle begins with the program counter (PC)incrementing in Q1.
In the execution cycle, the fetched instruction is latchedinto the “Instruction Register (IR)” in cycle Q1. Thisinstruction is then decoded and executed during theQ2, Q3, and Q4 cycles. Data memory is read during Q2(operand read) and written during Q4 (destinationwrite).
FIGURE 3-2: CLOCK/INSTRUCTION CYCLE
EXAMPLE 3-1: INSTRUCTION PIPELINE FLOW
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT(ER mode)
PC PC+1 PC+2
Fetch INST (PC)Execute INST (PC-1) Fetch INST (PC+1)
Execute INST (PC) Fetch INST (PC+2)Execute INST (PC+1)
Internalphaseclock
All instructions are single cycle, except for any program branches. These take two cycles since the fetchinstruction is “flushed” from the pipeline while the new instruction is being fetched and then executed.
1. MOVLW 55h Fetch 1 Execute 1
2. MOVWF PORTB Fetch 2 Execute 2
3. CALL SUB_1 Fetch 3 Execute 3
4. BSF PORTA, BIT3 Fetch 4 Flush
Fetch SUB_1 Execute SUB_1
1999 Microchip Technology Inc. Preliminary DS40300B-page 13
PIC16F62X4.0 MEMORY ORGANIZATION
4.1 Program Memory Organization
The PIC16F62X has a 13-bit program counter capableof addressing an 8K x 14 program memory space. Onlythe first 1K x 14 (0000h - 03FFh) for the PIC16F627and 2K x 14 (0000h - 07FFh) for the PIC16F628 arephysically implemented. Accessing a location abovethese boundaries will cause a wrap-around within thefirst 1K x 14 space (PIC16F627) or 2K x 14 space(PIC16F628). The reset vector is at 0000h and theinterrupt vector is at 0004h (Figure 4-1 and Figure 4-2).
FIGURE 4-1: PROGRAM MEMORY MAP AND STACK FOR THE PIC16F627
PC<12:0>
13
000h
00040005
03FFh
0400h
1FFFh
Stack Level 1
Stack Level 8
Reset Vector
Interrupt Vector
On-chip ProgramMemory
CALL, RETURNRETFIE, RETLW
Stack Level 2
FIGURE 4-2: PROGRAM MEMORY MAP AND STACK FOR THE PIC16F628
4.2 Data Memory Organization
The data memory (Figure 4-3) is partitioned into fourBanks which contain the general purpose registers andthe special function registers. The Special FunctionRegisters are located in the first 32 locations of eachBank. Register locations 20-7Fh, A0h-FFh, 120h-14Fh,170h-17Fh and 1F0h-1FFh are general purpose regis-ters implemented as static RAM.
The Table below lists how to access the four banks ofregisters:
Addresses F0h-FFh, 170h-17Fh and 1F0h-1FFh areimplemented as common RAM and mapped back toaddresses 70h-7Fh.
4.2.1 GENERAL PURPOSE REGISTER FILE
The register file is organized as 224 x 8 in thePIC16F62X. Each is accessed either directly or indi-rectly through the File Select Register FSR(Section 4.4).
RP1 RP0
Bank0 0 0
Bank1 0 1
Bank2 1 0
Bank3 1 1
PC<12:0>
13
000h
00040005
07FFh
0800h
1FFFh
Stack Level 1
Stack Level 8
Reset Vector
Interrupt Vector
On-chip ProgramMemory
CALL, RETURNRETFIE, RETLW
Stack Level 2
PIC16F62X
DS40300B-page 14 Preliminary 1999 Microchip Technology Inc.
FIGURE 4-3: DATA MEMORY MAP OF THE PIC16F627 AND PIC16F628
Indirect addr.(*)
TMR0
PCL
STATUS
FSR
PORTA
PORTB
PCLATH
INTCON
PIR1
TMR1L
TMR1H
T1CON
TMR2
T2CON
CCPR1L
CCPR1H
CCP1CON
OPTION
PCL
STATUS
FSR
TRISA
TRISB
PCLATH
INTCON
PIE1
PCON
PR2
00h
01h
02h
03h
04h
05h
06h
07h
08h
09h
0Ah
0Bh
0Ch
0Dh
0Eh
0Fh
10h
11h
12h
13h
14h
15h
16h
17h
18h
19h
1Ah
1Bh
1Ch
1Dh
1Eh
1Fh
80h
81h
82h
83h
84h
85h
86h
87h
88h
89h
8Ah
8Bh
8Ch
8Dh
8Eh
8Fh
90h
91h
92h
93h
94h
95h
96h
97h
98h
99h
9Ah
9Bh
9Ch
9Dh
9Eh
9Fh
20h A0h
7Fh FFhBank 0 Bank 1
Unimplemented data memory locations, read as ’0’. * Not a physical register.
FileAddress
Indirect addr.(*) Indirect addr.(*)
PCL
STATUS
FSR
PCLATH
INTCON
PCL
STATUS
FSR
PCLATH
INTCON
100h
101h
102h
103h
104h
105h
106h
107h
108h
109h
10Ah
10Bh
10Ch
10Dh
10Eh
10Fh
180h
181h
182h
183h
184h
185h
186h
187h
188h
189h
18Ah
18Bh
18Ch
18Dh
18Eh
18Fh
17Fh 1FFhBank 2 Bank 3
Indirect addr.(*)
TMR0 OPTION
RCSTA
TXREG
RCREG
CMCON
TXSTA
SPBRG
VRCON
GeneralPurposeRegister
1EFh1F0h
accesses70h - 7Fh
EFhF0h
accesses70h-7Fh
16Fh170h
accesses70h-7Fh
TRISBPORTB
96 Bytes
EEDATA
EEADR
EECON1
EECON2*
GeneralPurposeRegister80 Bytes
GeneralPurposeRegister48 Bytes
11Fh120h
14Fh150h
1999 Microchip Technology Inc. Preliminary DS40300B-page 15
PIC16F62X
4.2.2 SPECIAL FUNCTION REGISTERS
The special function registers are registers used by theCPU and Peripheral functions for controlling thedesired operation of the device (Table 4-1). Theseregisters are static RAM.
The special registers can be classified into two sets(core and peripheral). The special function registersassociated with the “core” functions are described inthis section. Those related to the operation of theperipheral features are described in the section of thatperipheral feature.
TABLE 4-1: SPECIAL REGISTERS SUMMARY BANK0
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR Reset
Value on all other
Resets(1)
Bank 000h INDF Addressing this location uses contents of FSR to address data memory (not a physical register) xxxx xxxx xxxx xxxx
01h TMR0 Timer0 Module’s Register xxxx xxxx uuuu uuuu
02h PCL Program Counter's (PC) Least Significant Byte 0000 0000 0000 0000
03h STATUS IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu
04h FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu
05h PORTA RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0 xxxx 0000 xxxx 0000
06h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 xxxx xxxx uuuu uuuu
07h Unimplemented — —
08h Unimplemented — —
09h Unimplemented — —
0Ah PCLATH — — — Write buffer for upper 5 bits of program counter ---0 0000 ---0 0000
0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
0Dh Unimplemented — —
0Eh TMR1L Holding register for the least significant byte of the 16-bit TMR1 xxxx xxxx uuuu uuuu
0Fh TMR1H Holding register for the most significant byte of the 16-bit TMR1 xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
11h TMR2 TMR2 module’s register 0000 0000 0000 0000
12h T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -uuu uuuu
13h Unimplemented — —
14h Unimplemented — —
15h CCPR1L Capture/Compare/PWM register (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM register (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
19h TXREG USART Transmit data register 0000 0000 0000 0000
1Ah RCREG USART Receive data register 0000 0000 0000 0000
1Bh Unimplemented — —
1Ch Unimplemented — —
1Dh Unimplemented — —
1Eh Unimplemented — —
1Fh CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0000 0000 0000
Legend: — = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1: Other (non power-up) resets include MCLR Reset, Brown-out Detect and Watchdog Timer Reset duringnormal operation.
PIC16F62X
DS40300B-page 16 Preliminary 1999 Microchip Technology Inc.
TABLE 4-2: SPECIAL FUNCTION REGISTERS SUMMARY BANK1
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR Reset
Value on all other resets(1)
Bank 1
80h INDF Addressing this location uses contents of FSR to address data memory (not a physical reg-ister)
xxxx xxxx xxxx xxxx
81h OPTION RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
82h PCL Program Counter’s (PC) Least Significant Byte 0000 0000 0000 0000
83h STATUS IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu
84h FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu
85h TRISA TRISA7 TRISA6 — TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 11-1 1111 11-1 1111
86h TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 1111 1111 1111 1111
87h Unimplemented — —
88h Unimplemented — —
89h Unimplemented — —
8Ah PCLATH — — — Write buffer for upper 5 bits of program counter ---0 0000 ---0 0000
8Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
8Dh Unimplemented — —
8Eh PCON — — — — OSCF — POR BOD ---- 1-0x ---- 1-uq
8Fh Unimplemented
90h Unimplemented — —
91h Unimplemented — —
92h PR2 Timer2 Period Register 11111111 11111111
93h Unimplemented — —
94h Unimplemented — —
95h Unimplemented — —
96h Unimplemented — —
97h Unimplemented — —
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
9Ah EEDATA EEPROM data register xxxx xxxx uuuu uuuu
9Bh EEADR — EEPROM address register xxxx xxxx uuuu uuuu
9Ch EECON1 — — — — WRERR WREN WR RD ---- x000 ---- q000
9Dh EECON2 EEPROM control register 2 (not a physical register) -------- --------
9Eh Unimplemented — —
9Fh VRCON VREN VROE VRR — VR3 VR2 VR1 VR0 000- 0000 000- 0000
Legend: : — = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1: Other (non power-up) resets include MCLR Reset, Brown-out Detect and Watchdog Timer Reset duringnormal operation.
1999 Microchip Technology Inc. Preliminary DS40300B-page 17
PIC16F62X
TABLE 4-3: SPECIAL FUNCTION REGISTERS SUMMARY BANK2
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR Reset
Value on all other resets(1)
Bank 1
100h INDF Addressing this location uses contents of FSR to address data memory (not a physical reg-ister)
xxxx xxxx xxxx xxxx
101h TMR0 RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
102h PCL Program Counter’s (PC) Least Significant Byte 0000 0000 0000 0000
103h STATUS IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu
104h FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu
105h Unimplemented — —
106h PORTB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 1111 1111 1111 1111
107h Unimplemented — —
108h Unimplemented — —
109h Unimplemented — —
10Ah PCLATH — — — Write buffer for upper 5 bits of program counter ---0 0000 ---0 0000
10Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
10Ch — —
10Dh Unimplemented — —
10Eh — —
10Fh Unimplemented
110h Unimplemented — —
111h Unimplemented — —
112h
113h Unimplemented — —
114h Unimplemented — —
115h Unimplemented — —
116h Unimplemented — —
117h Unimplemented — —
118h — —
119h — —
11Ah — —
11Bh — —
11Ch — —
11Dh — —
11Eh Unimplemented — —
11Fh — —
Legend: — = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1: Other (non power-up) resets include MCLR Reset, Brown-out Detect and Watchdog Timer Reset duringnormal operation.
PIC16F62X
DS40300B-page 18 Preliminary 1999 Microchip Technology Inc.
TABLE 4-4: SPECIAL FUNCTION REGISTERS SUMMARY BANK3
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR Reset
Value on all other resets(1)
Bank 1
180h INDF Addressing this location uses contents of FSR to address data memory (not a physical reg-ister)
xxxx xxxx xxxx xxxx
181h OPTION RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
182h PCL Program Counter’s (PC) Least Significant Byte 0000 0000 0000 0000
183h STATUS IRP RP1 RP0 TO PD Z DC C 0001 1xxx 000q quuu
184h FSR Indirect data memory address pointer xxxx xxxx uuuu uuuu
185h Unimplemented — —
186h TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 1111 1111 1111 1111
187h Unimplemented — —
188h Unimplemented — —
189h Unimplemented — —
18Ah PCLATH — — — Write buffer for upper 5 bits of program counter ---0 0000 ---0 0000
18Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
18Ch
18Dh
18Eh
18Fh
190h
191h
192h
193h
194h
195h
196h
197h
198h
199h
19Ah
19Bh
19Ch
19Dh
19Eh
19Fh
Legend: — = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1: Other (non power-up) resets include MCLR Reset, Brown-out Detect and Watchdog Timer Reset duringnormal operation.
1999 Microchip Technology Inc. Preliminary DS40300B-page 19
PIC16F62X
4.2.2.1 STATUS REGISTER
The STATUS register, shown in Register 4-1, containsthe arithmetic status of the ALU, the RESET status andthe bank select bits for data memory (SRAM).
The STATUS register can be the destination for anyinstruction, like any other register. If the STATUSregister is the destination for an instruction that affectsthe Z, DC or C bits, then the write to these three bits isdisabled. These bits are set or cleared according to thedevice logic. Furthermore, the TO and PD bits are notwritable. Therefore, the result of an instruction with theSTATUS register as destination may be different thanintended.
For example, CLRF STATUS will clear the upper-threebits and set the Z bit. This leaves the status register as000uu1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter theSTATUS register because these instructions do notaffect any status bit. For other instructions, not affectingany status bits, see the “Instruction Set Summary”.
Note 1: The C and DC bits operate as a Borrowand Digit Borrow out bit, respectively, insubtraction. See the SUBLW and SUBWFinstructions for examples.
REGISTER 4-1: STATUS REGISTER (ADDRESS 03H OR 83H)
R/W-0 R/W-0 R/W-0 R-1 R-1 R/W-x R/W-x R/W-xIRP RP1 RP0 TO PD Z DC C R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset-x = Unknown at POR reset
bit7 bit0
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: Time-out bit1 = After power-up, CLRWDT instruction, or SLEEP instruction0 = A WDT time-out occurred
bit 3: PD: Power-down bit1 = After power-up or by the CLRWDT instruction0 = By execution of the SLEEP instruction
bit 2: Z: Zero bit1 = The result of an arithmetic or logic operation is zero0 = The result of an arithmetic or logic operation is not zero
bit 1: DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)(for borrow the polarity is reversed)1 = A carry-out from the 4th low order bit of the result occurred0 = No carry-out from the 4th low order bit of the result
bit 0: C: Carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)1 = A carry-out from the most significant bit of the result occurred0 = No carry-out from the most significant bit of the result occurredNote: For borrow the polarity is reversed. A subtraction is executed by adding the two’s complement of thesecond operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low order bit ofthe source register.
PIC16F62X
DS40300B-page 20 Preliminary 1999 Microchip Technology Inc.
4.2.2.2 OPTION REGISTER
The OPTION register is a readable and writableregister which contains various control bits to configurethe TMR0/WDT prescaler, the external RB0/INTinterrupt, TMR0, and the weak pull-ups on PORTB.
Note: To achieve a 1:1 prescaler assignment forTMR0, assign the prescaler to the WDT(PSA = 1). See Section 6.3.1
REGISTER 4-2: OPTION REGISTER (ADDRESS 81H)
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 R = Readable bit
W = Writable bit-n = Value at POR reset
bit7 bit0
bit 7: RBPU: PORTB Pull-up Enable bit1 = PORTB pull-ups are disabled0 = PORTB pull-ups are enabled by individual port latch values
bit 6: INTEDG: Interrupt Edge Select bit1 = Interrupt on rising edge of RB0/INT pin0 = Interrupt on falling edge of RB0/INT pin
bit 5: T0CS: TMR0 Clock Source Select bit1 = Transition on RA4/T0CKI pin0 = Internal instruction cycle clock (CLKOUT)
bit 4: T0SE: TMR0 Source Edge Select bit1 = Increment on high-to-low transition on RA4/T0CKI pin0 = Increment on low-to-high transition on RA4/T0CKI pin
bit 3: PSA: Prescaler Assignment bit1 = Prescaler is assigned to the WDT0 = Prescaler is assigned to the Timer0 module
bit 2-0: PS2:PS0: Prescaler Rate Select bits
000001010011100101110111
1 : 21 : 41 : 81 : 161 : 321 : 641 : 1281 : 256
1 : 11 : 21 : 41 : 81 : 161 : 321 : 641 : 128
Bit Value TMR0 Rate WDT Rate
1999 Microchip Technology Inc. Preliminary DS40300B-page 21
PIC16F62X
4.2.2.3 INTCON REGISTER
The INTCON register is a readable and writableregister which contains the various enable and flag bitsfor all interrupt sources except the comparator module.See Section 4.2.2.4 and Section 4.2.2.5 for adescription of the comparator enable and flag bits.
Note: Interrupt flag bits get set when an interruptcondition occurs regardless of the state ofits corresponding enable bit or the globalenable bit, GIE (INTCON<7>).
REGISTER 4-3: INTCON REGISTER (ADDRESS 0BH OR 8BH)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-xGIE PEIE T0IE INTE RBIE T0IF INTF RBIF R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset-x = Unknown at POR reset
bit7 bit0
bit 7: GIE: Global Interrupt Enable bit1 = Enables all un-masked interrupts0 = Disables all interrupts
bit 6: PEIE: Peripheral Interrupt Enable bit1 = Enables all un-masked peripheral interrupts0 = Disables all peripheral interrupts
bit 5: T0IE: TMR0 Overflow Interrupt Enable bit1 = Enables the TMR0 interrupt0 = Disables the TMR0 interrupt
bit 4: INTE: RB0/INT External Interrupt Enable bit1 = Enables the RB0/INT external interrupt0 = Disables the RB0/INT external interrupt
bit 3: RBIE: RB Port Change Interrupt Enable bit1 = Enables the RB port change interrupt0 = Disables the RB port change interrupt
bit 2: T0IF: TMR0 Overflow Interrupt Flag bit1 = TMR0 register has overflowed (must be cleared in software)0 = TMR0 register did not overflow
bit 1: INTF: RB0/INT External Interrupt Flag bit1 = 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 bit1 = 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
PIC16F62X
DS40300B-page 22 Preliminary 1999 Microchip Technology Inc.
4.2.2.4 PIE1 REGISTER
This register contains interrupt enable bits.
REGISTER 4-4: PIE1 REGISTER (ADDRESS 8CH)
R/W-0 R/W-0 R/W-0 R/W-0 U R/W-0 R/W-0 R/W-0EEIE CMIE RCIE TXIE - CCP1IE TMR2IE TMR1IE R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7: EEIE: EE Write Complete Interrupt Enable Bit1 = Enables the EE write complete interrupt0 = Disables the EE write complete interrupt
bit 6: CMIE: Comparator Interrupt Enable bit1 = Enables the comparator interrupt0 = Disables the comparator interrupt
bit 5: RCIE: USART Receive Interrupt Enable bit1 = Enables the USART receive interrupt0 = Disables the USART receive interrupt
bit 4: TXIE: USART Transmit Interrupt Enable bit1 = Enables the USART transmit interrupt0 = Disables the USART transmit interrupt
bit 3: Unimplemented: Read as ‘0’
bit 2: CCP1IE: CCP1 Interrupt Enable bit1 = Enables the CCP1 interrupt0 = Disables the CCP1 interrupt
bit 1: TMR2IE: TMR2 to PR2 Match Interrupt Enable bit1 = Enables the TMR2 to PR2 match interrupt0 = Disables the TMR2 to PR2 match interrupt
bit 0: TMR1IE: TMR1 Overflow Interrupt Enable bit1 = Enables the TMR1 overflow interrupt0 = Disables the TMR1 overflow interrupt
1999 Microchip Technology Inc. Preliminary DS40300B-page 23
PIC16F62X
4.2.2.5 PIR1 REGISTER
This register contains interrupt flag bits. Note: Interrupt flag bits get set when an interrupt
condition occurs regardless of the state ofits corresponding enable bit or the globalenable bit, GIE (INTCON<7>). Usersoftware should ensure the appropriateinterrupt flag bits are clear prior to enablingan interrupt.
REGISTER 4-5: PIR1 REGISTER (ADDRESS 0CH)
R/W-0 R/W-0 R-0 R-0 U R/W-0 R/W-0 R/W-0
EEIF CMIF RCIF TXIF - CCP1IF TMR2IF TMR1IF R = Readable bitW = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7: EEIF: EEPROM Write Operation Interrupt Flag bit1 = 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 bit1 = Comparator input has changed0 = Comparator input has not changed
bit 5: RCIF: USART Receive Interrupt Flag bit1 = The USART receive buffer is full0 = The USART receive buffer is empty
bit 4: TXIF: USART Transmit Interrupt Flag bit1 = The USART transmit buffer is empty0 = The USART transmit buffer is full
bit 3: Unimplemented: Read as ‘0’
bit 2: CCP1IF: CCP1 Interrupt Flag bitCapture Mode
1 = A TMR1 register capture occurred (must be cleared in software)0 = No TMR1 register capture occurred
Compare Mode1 = A TMR1 register compare match occurred (must be cleared in software)0 = No TMR1 register compare match occurred
PWM ModeUnused in this mode
bit 1: TMR2IF: TMR2 to PR2 Match Interrupt Flag bit1 = TMR2 to PR2 match occurred (must be cleared in software)0 = No TMR2 to PR2 match occurred
bit 0: TMR1IF: TMR1 Overflow Interrupt Flag bit1 = TMR1 register overflowed (must be cleared in software)0 = TMR1 register did not overflow
PIC16F62X
DS40300B-page 24 Preliminary 1999 Microchip Technology Inc.
4.2.2.6 PCON REGISTER
The PCON register contains flag bits to differentiatebetween a Power-on Reset, an external MCLR reset,WDT reset or a Brown-out Detect.
Note: BOD is unknown on Power-on Reset. Itmust then be set by the user and checkedon subsequent resets to see if BOD iscleared, indicating a brown-out hasoccurred. The BOD status bit is a "don’tcare" and is not necessarily predictable ifthe brown-out circuit is disabled (byprogramming BOREN bit in theConfiguration word).
REGISTER 4-6: PCON REGISTER (ADDRESS 8Eh)
U-0 U-0 U-0 U-0 R/W-1 U-0 R/W-q R/W-q— — — — OSCF — POR BOD R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7-4,2:Unimplemented: Read as '0'
bit 3: OSCF: INTRC/ER oscillator speed1 = 4 MHz typical(1)
0 = 37 KHz typical
bit 1: POR: Power-on Reset Status bit1 = No Power-on Reset occurred0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
bit 0: BOD: Brown-out Detect Status bit1 = No Brown-out Reset occurred0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)
Note 1: When in ER oscillator mode, setting OSCF = 1 will cause the oscillator speed to change to the speedspecified by the external resistor.
1999 Microchip Technology Inc. Preliminary DS40300B-page 25
PIC16F62X
4.3 PCL and PCLATH
The program counter (PC) is 13-bits wide. The low bytecomes from the PCL register, which is a readable andwritable register. The high byte (PC<12:8>) is not directlyreadable or writable and comes from PCLATH. On anyreset, the PC is cleared. Figure 4-7 shows the twosituations for the loading of the PC. The upper example inthe figure shows how the PC is loaded on a write to PCL(PCLATH<4:0> → PCH). The lower example in the figureshows how the PC is loaded during a CALL or GOTOinstruction (PCLATH<4:3> → PCH).
FIGURE 4-7: LOADING OF PC IN DIFFERENT SITUATIONS
4.3.1 COMPUTED GOTO
A computed GOTO is accomplished by adding an offsetto the program counter (ADDWF PCL). When doing atable read using a computed GOTO method, careshould be exercised if the table location crosses a PCLmemory boundary (each 256 byte block). Refer to theapplication note “Implementing a Table Read" (AN556).
PC
12 8 7 0
5PCLATH<4:0>
PCLATH
Instruction with
ALU result
GOTO, CALL
Opcode <10:0>
8
PC
12 11 10 0
11PCLATH<4:3>
PCH PCL
8 7
2
PCLATH
PCH PCL
PCL as Destination
4.3.2 STACK
The PIC16F62X family has an 8 level deep x 13-bitwide hardware stack (Figure 4-1 and Figure 4-2). Thestack space is not part of either program or data spaceand the stack pointer is not readable or writable. ThePC is PUSHed onto the stack when a CALL instructionis executed or an interrupt causes a branch. The stackis POPed in the event of a RETURN, RETLW or a RET-FIE instruction execution. PCLATH is not affected by aPUSH or POP operation.
The stack operates as a circular buffer. This means thatafter the stack has been PUSHed eight times, the ninthpush overwrites the value that was stored from the firstpush. The tenth push overwrites the second push (andso on).
Note 1: There are no STATUS bits toindicate stack overflow or stackunderflow conditions.
Note 2: There are no instructions/mnemonicscalled PUSH or POP. These are actionsthat occur from the execution of theCALL, RETURN, RETLW and RETFIEinstructions, or the vectoring to aninterrupt address.
PIC16F62X
DS40300B-page 26 Preliminary 1999 Microchip Technology Inc.
4.4 Indirect Addressing, INDF and FSR Registers
The INDF register is not a physical register. Addressingthe INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF register.Any instruction using the INDF register actually accessesdata pointed to by the file select register (FSR). ReadingINDF itself indirectly will produce 00h. Writing to the INDFregister indirectly results in a no-operation (although sta-tus bits may be affected). An effective 9-bit address isobtained by concatenating the 8-bit FSR register and theIRP bit (STATUS<7>), as shown in Figure 4-8.
A simple program to clear RAM location 20h-2Fh usingindirect addressing is shown in Example 4-1.
EXAMPLE 4-1: INDIRECT ADDRESSING
movlw 0x20 ;initialize pointer
movwf FSR ;to RAM
NEXT clrf INDF ;clear INDF register
incf FSR ;inc pointer
btfss FSR,4 ;all done?
goto NEXT ;no clear next
;yes continueCONTINUE:
FIGURE 4-8: DIRECT/INDIRECT ADDRESSING PIC16F62X
For memory map detail see Figure 4-3.
DataMemory
Indirect AddressingDirect Addressing
bank select location select
RP1 RP0 6 0from opcode IRP FSR register7 0
bank select location select
00 01 10 11180h
1FFh
00h
7Fh
Bank 0 Bank 1 Bank 2 Bank 3
1999 Microchip Technology Inc. Preliminary DS40300B-page 27
PIC16F62X
5.0 I/O PORTSThe PIC16F62X have two ports, PORTA and PORTB.Some pins for these I/O ports are multiplexed with analternate function for the peripheral features on thedevice. In general, when a peripheral is enabled, thatpin may not be used as a general purpose I/O pin.
5.1 PORTA and TRISA Registers
PORTA is an 8-bit wide latch. RA4 is a Schmitt Triggerinput and an open drain output. Port RA4 is multiplexedwith the T0CKI clock input. RA5 is a Schmitt Trigger inputonly and has no output drivers. All other RA port pins haveSchmitt Trigger input levels and full CMOS output drivers.All pins have data direction bits (TRIS registers) which canconfigure these pins as input or output.
A ’1’ in the TRISA register puts the corresponding outputdriver in a hi- impedance mode. A ’0’ in the TRISA registerputs the contents of the output latch on the selected pin(s).
Reading the PORTA register reads the status of the pinswhereas writing to it will write to the port latch. All writeoperations are read-modify-write operations. So a writeto a port implies that the port pins are first read, then thisvalue is modified and written to the port data latch.
The PORTA pins are multiplexed with comparator andvoltage reference functions. The operation of thesepins are selected by control bits in the CMCON(comparator control register) register and the VRCON(voltage reference control register) register. Whenselected as a comparator input, these pins will readas ’0’s.
TRISA controls the direction of the RA pins, even whenthey are being used as comparator inputs. The usermust make sure to keep the pins configured as inputswhen using them as comparator inputs.
The RA2 pin will also function as the output for thevoltage reference. When in this mode, the VREF pin is avery high impedance output. The user must configureTRISA<2> bit as an input and use high impedanceloads.
In one of the comparator modes defined by theCMCON register, pins RA3 and RA4 become outputsof the comparators. The TRISA<4:3> bits must becleared to enable outputs to use this function.
EXAMPLE 5-1: INITIALIZING PORTA
Note 1: On reset, the TRISA register is set to allinputs. The digital inputs are disabled andthe comparator inputs are forced toground to reduce excess current con-sumption.
Note 2: When RA6/OSC2/CLKOUT is configuredas CLKOUT, the corresponding TRIS bit isoverridden and the pin is configured as anoutput. The PORTA data bit reads 0, andthe PORTA TRIS bit reads 0.
CLRF PORTA ;Initialize PORTA by setting;output data latches
MOVLW 0X07 ;Turn comparators off andMOVWF CMCON ;enable pins for I/O
;functionsBCF STATUS, RP1BSF STATUS, RP0 ;Select Bank1MOVLW 0x1F ;Value used to initialize
;data directionMOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<7:5> are always ;read as ’0’.
PIC16F62X
DS40300B-page 28 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-1: BLOCK DIAGRAM OF RA0/AN0:RA1/AN1 PINS
DataBus QD
QCKP
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
AnalogVSS
VDD
I/O PinQD
QCK
Input Mode
DQ
EN
To Comparator
Schmitt TriggerInput Buffer
VDD
VSS
FIGURE 5-2: BLOCK DIAGRAM OF RA2/VREF PIN
DataBus QD
QCKP
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
AnalogVSS
VDD
RA2 PinQD
QCK
Input Mode
DQ
EN
To Comparator
Schmitt TriggerInput Buffer
VROE
VREF
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 29
PIC16F62X
FIGURE 5-3: BLOCK DIAGRAM OF THE RA3/AN3 PIN
FIGURE 5-4: BLOCK DIAGRAM OF RA4/T0CKI PIN
DataBus QD
QCKP
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
AnalogVSS
VDD
RA3 PinQD
QCK
DQ
EN
To Comparator
Schmitt TriggerInput Buffer
Input Mode
Comparator Output
Comparator Mode = 110
1
0
VDD
VSS
DataBus QD
QCK
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
VSS
RA4 PinQD
QCK
DQ
EN
TMR0 Clock Input
Schmitt TriggerInput Buffer
Comparator Output
Comparator Mode = 110
1
0
VSS
PIC16F62X
DS40300B-page 30 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-5: BLOCK DIAGRAM OF THE RA5/MCLR/THV PIN
DQ
EN
HV Detect
MCLR Filter(1)
RA5/MCLR/THV
RD Port
MCLR circuit
Program mode
MCLRE
DataBus
QD
QCK P
N
WRPORT
WRTRIS
Data Latch
TRIS Latch
RD TRIS
VSS
VDD
QD
QCK
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 31
PIC16F62X
FIGURE 5-6: BLOCK DIAGRAM OF RA6/OSC2/CLKOUT PIN
DataBus
QD
QCK P
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
VSS
VDDRA6/OSC2/CLKOUT Pin
QD
QCK
DQ
EN
Schmitt TriggerInput Buffer
Oscillator Circuit
From OSC1
(Fosc=100, 101, 110, 111)
(Fosc=110, 100)
1
0
CLKOUT (FOSC/4)
(Fosc=101,111)
CLKOUT is 1/4 of the Fosc frequency.
VDD
VSS
PIC16F62X
DS40300B-page 32 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-7: BLOCK DIAGRAM OF RA7/OSC1/CLKIN PIN
DataBus
QD
QCK P
N
WRPORTA
WRTRISA
Data Latch
TRIS Latch
RD TRISA
RD PORTA
VSS
VDD
RA7/OSC1/CLKIN Pin
QD
QCK
DQ
EN
Schmitt TriggerInput Buffer
Oscillator Circuit
To OSC2
(Fosc=101, 100)
(Fosc=101, 100)
Schmitt Trigger
CLKIN to core
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 33
PIC16F62X
TABLE 5-1: PORTA FUNCTIONS
TABLE 5-2: SUMMARY OF REGISTERS ASSOCIATED WITH PORTA
Name Bit #Buffer Type
Function
RA0/AN0 bit0 ST Bi-directional I/O port/comparator inputRA1/AN1 bit1 ST Bi-directional I/O port/comparator input
RA2/AN2/VREF bit2 ST Bi-directional I/O port/analog/comparator input or VREF outputRA3/AN3 bit3 ST Bi-directional I/O port/analog/comparator input/comparator outputRA4/T0CKI bit4 ST Bi-directional I/O port/external clock input for TMR0 or comparator output.
Output is open drain type.RA5/MCLR/THV bit5 ST Input port/master clear (reset input/programming voltage input. When
configured as MCLR, this pin is an active low reset to the device. Voltage on MCLR/THV must not exceed VDD during normal device operation.
RA6/OSC2/CLK-OUT
bit6 ST Bi-directional I/O port/Oscillator crystal output. Connects to crystal or res-onator 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.
RA7/OSC1/CLKIN bit7 ST Bi-directional I/O port/oscillator crystal input/external clock source input.
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value on All OtherResets
05h PORTA RA7 RA6 RA5 RA4 RA3 RA2 RA1 RA0 xxxx 0000 xxxu 0000
85h TRISA TRISA7 TRISA6 — TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 11-1 1111 11-1 1111
1Fh CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0000 0000 0000
9Fh VRCON VREN VROE VRR — VR3 VR2 VR1 VR0 000- 0000 000- 0000
Legend: — = Unimplemented locations, read as ‘0’, u = unchanged, x = unknown
Note: Shaded bits are not used by PORTA.
PIC16F62X
DS40300B-page 34 Preliminary 1999 Microchip Technology Inc.
5.2 PORTB and TRISB Registers
PORTB is an 8-bit wide bi-directional port. Thecorresponding data direction register is TRISB. A ’1’ inthe TRISB register puts the corresponding output driverin a high impedance mode. A ’0’ in the TRISB registerputs the contents of the output latch on the selectedpin(s).
PORTB is multiplexed with the interrupt, USART, CCPmodule and the TMR1 clock input/output. The standardport functions and the alternate port functions areshown in Table 5-3.
Reading PORTB register reads the status of the pins,whereas writing to it will write to the port latch. All writeoperations are read-modify-write operations. So a writeto a port implies that the port pins are first read, thenthis value is modified and written to the port data latch.
Each of the PORTB pins has a weak internal pull-up(≈200 µA typical). A single control bit can turn on all thepull-ups. This is done by clearing the RBPU(OPTION<7>) bit. The weak pull-up is automaticallyturned off when the port pin is configured as an output.The pull-ups are disabled on Power-on Reset.
Four of PORTB’s pins, RB7:RB4, have an interrupt onchange feature. Only pins configured as inputs cancause this interrupt to occur (i.e., any RB7:RB4 pinconfigured as an output is excluded from the interrupton change comparison). The input pins (of RB7:RB4)are compared with the old value latched on the lastread of PORTB. The “mismatch” outputs of RB7:RB4are OR’ed together to generate the RBIF interrupt (flaglatched in INTCON<0>).
This interrupt can wake the device from SLEEP. Theuser, in the interrupt service routine, can clear theinterrupt in the following manner:
a) Any read or write of PORTB. This will end themismatch condition.
b) Clear flag bit RBIF.
A mismatch condition will continue to set flag bit RBIF.Reading PORTB will end the mismatch condition, andallow flag bit RBIF to be cleared.
This interrupt on mismatch feature, together withsoftware configurable pull-ups on these four pins alloweasy interface to a key pad and make it possible forwake-up on key-depression. (See AN552 in theMicrochip Embedded Control Handbook.)
The interrupt on change feature is recommended forwake-up on key depression operation and operationswhere PORTB is only used for the interrupt on changefeature. Polling of PORTB is not recommended whileusing the interrupt on change feature.
Note: If a change on the I/O pin should occurwhen the read operation is being executed(start of the Q2 cycle), then the RBIF inter-rupt flag may not get set.
1999 Microchip Technology Inc. Preliminary DS40300B-page 35
PIC16F62X
FIGURE 5-8: BLOCK DIAGRAM OF RB0/INT PIN
Data Bus
WR PORTB
WR TRISB
RD PORTB
Data Latch
TRIS Latch
RB0/INT pin
INT input
QD
CK
QD
CK
EN
Q D
EN
RD TRISB
RBPUP
VDD
weakpull-up
Schmitt TriggerBuffer
TTLinputbuffer
VDD
VSS
PIC16F62X
DS40300B-page 36 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-9: BLOCK DIAGRAM OF RB1/TX/DT PIN
Data Latch
TRIS Latch
RD TRISB
P
VSS
QD
QCK
QD
QCK N
VDD
0
1
RD PORTB
WR PORTB
WR TRISB
SchmittTrigger
Peripheral OE(2)
Data Bus
PORT/PERIPHERAL Select(1)
USART data output
RD PORTB
RB1/RX/DT
USART receive input
RBPUVDD
weak pull-up
TTLinputbuffer
P
pin
Note 1: Port/Peripheral select signal selects between port data and peripheral output.Note 2: Peripheral OE( output enable) is only active if peripheral select is active.
EN
Q D
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 37
PIC16F62X
FIGURE 5-10: BLOCK DIAGRAM OF RB2/TX/CK PIN
Data Latch
TRIS Latch
RD TRISB
P
Vss
QD
QCK
QD
QCK
EN
Q D
EN
N
VDD
0
1
RD PORTB
WR PORTB
WR TRISB
SchmittTrigger
Peripheral OE(2)
Data Bus
PORT/PERIPHERAL Select(1)
USART TX/CK output
RD PORTB
RB2/TX/CK
USART Slave Clock in
RBPUVDD
weak pull-up
TTLinputbuffer
P
Note 1: Port/Peripheral select signal selects between port data and peripheral output.Note 2: Peripheral OE( output enable) is only active if peripheral select is active.
pin
VDD
VSS
PIC16F62X
DS40300B-page 38 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-11: BLOCK DIAGRAM OF THE RB3/CCP1 PIN
Data Latch
TRIS Latch
RD TRISB
P
Vss
QD
QCK
QD
QCK
EN
Q D
EN
N
VDD
0
1
RD PORTB
WR PORTB
WR TRISB
SchmittTrigger
Data Bus
Port/Peripheral Select(1)
PWM/Compare output
RD PORTB
RB3/CCP1
CCP input
RBPUVDD
weak pull-upP
TTLinputbuffer
pin
Note 1: Peripheral Select is defined by CCP1M3:CCP1M0. (CCP1CON<3:0>)
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 39
PIC16F62X
FIGURE 5-12: BLOCK DIAGRAM OF RB4/PGM PIN
Data Latch
TRIS Latch
RD TRISB
P
VSS
QD
QCK
QD
QCK N
VDD
RD PORTB
WR PORTB
WR TRISB
SchmittTrigger
PGM input
LVP
Data Bus
RB4/PGM
RBPUVDD
weak pull-upP
From other Q D
EN
Q D
ENSet RBIF
RB<7:4> pinsRD Port
Q3
Q1
TTLinputbuffer
VDD
VSS
Note: The low voltage programming disables the interrupt on change and the weak pullups on RB4.
PIC16F62X
DS40300B-page 40 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-13: BLOCK DIAGRAM OF RB5 PIN
Data Bus
WR PORTB
WR TRISB
RD PORTB
Data Latch
TRIS Latch
RB5 pin
QD
CK
QD
CK
TTLinputbuffer
RD TRISB
RBPUP
VDD
weakpull-up
From other Q D
EN
Q D
ENSet RBIF
RB<7:4> pinsRD Port
Q3
Q1
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 41
PIC16F62X
FIGURE 5-14: BLOCK DIAGRAM OF RB6/T1OSO/T1CKI PIN
Data Latch
TRIS Latch
RD TRISB
P
VSS
QD
QCK
QD
QCK N
VDD
RD PORTB
WR PORTB
WR TRISB
SchmittTrigger
T1OSCEN
Data Bus
RB6/
TMR1 Clock
RBPUVDD
weak pull-upP
From RB7
T1OSO/T1CKIpin
From other Q D
EN
Set RBIF
RB<7:4> pinsRD Port
Q3
Q1
Serial programming clock
TTLinputbuffer
TMR1 oscillator
Q D
EN
VDD
VSS
PIC16F62X
DS40300B-page 42 Preliminary 1999 Microchip Technology Inc.
FIGURE 5-15: BLOCK DIAGRAM OF THE RB7/T1OSI PIN
Data Latch
TRIS Latch
RD TRISB
P
Vss
QD
QCK
QD
QCK N
VDD
RD PORTB
WR PORTB
WR TRISB
T10SCEN
Data Bus
RB7/T1OSI
T1OSCEN
To RB6
RBPUVDD
weak pull-upP
pin
TTLinputbuffer
From other Q D
EN
Q D
ENSet RBIF
RB<7:4> pinsRD Port
Q3
Q1
Serial programming input
SchmittTrigger
TMR1 oscillator
VDD
VSS
1999 Microchip Technology Inc. Preliminary DS40300B-page 43
PIC16F62X
TABLE 5-3: PORTB FUNCTIONS
TABLE 5-4: SUMMARY OF REGISTERS ASSOCIATED WITH PORT
Name Bit #Buffer Type
Function
RB0/INT bit0 TTL/ST(1) Bi-directional I/O port/external interrupt. Can be software programmed for internal weak pull-up.
RB1/RX/DT bit1 TTL/ST(3) Bi-directional I/O port/ USART receive pin/synchronous data I/O. Can be software programmed for internal weak pull-up.
RB2/TX/CK bit2 TTL/ST(3) Bi-directional I/O port/ USART transmit pin/synchronous clock I/O. Can be software programmed for internal weak pull-up.
RB3/CCP1 bit3 TTL/ST(4) Bi-directional I/O port/Capture/Compare/PWM I/O. Can be software pro-grammed for internal weak pull-up.
RB4/PGM bit4 TTL/ST(5) 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.
RB5 bit5 TTL Bi-directional I/O port/Wake-up from SLEEP on pin change. Can be soft-ware programmed for internal weak pull-up.
RB6/T1OSO/T1CKI bit6 TTL/ST(2) 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.
RB7/T1OSI bit7 TTL/ST(2) Bi-directional I/O port/Timer1 oscillator input. Wake up from SLEEP on pin change. Can be software programmed for internal weak pull-up.
Legend: ST = Schmitt Trigger, TTL = TTL inputNote 1: This buffer is a Schmitt Trigger input when configured 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.
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onAll Other Resets
06h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 xxxx xxxx uuuu uuuu
86h TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 1111 1111 1111 1111
81h OPTION RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
Legend: u = unchanged, x = unknown
Note: Shaded bits are not used by PORTB.
PIC16F62X
DS40300B-page 44 Preliminary 1999 Microchip Technology Inc.
5.3 I/O Programming Considerations
5.3.1 BI-DIRECTIONAL I/O PORTS
Any instruction which writes, operates internally as aread followed by a write operation. The BCF and BSFinstructions, for example, read the register into theCPU, execute the bit operation and write the result backto the register. Caution must be used when theseinstructions are applied to a port with both inputs andoutputs defined. For example, a BSF operation on bit5of PORTB will cause all eight bits of PORTB to be readinto the CPU. Then the BSF operation takes place onbit5 and PORTB is written to the output latches. Ifanother bit of PORTB is used as a bidirectional I/O pin(e.g., bit0) and it is defined as an input at this time, theinput signal present on the pin itself would be read intothe CPU and re-written to the data latch of thisparticular pin, overwriting the previous content. As longas the pin stays in the input mode, no problem occurs.However, if bit0 is switched into output mode later on,the content of the data latch may now be unknown.
Reading a port register, reads the values of the portpins. Writing to the port register writes the value to theport latch. When using read modify write instructions(ex. BCF, BSF, etc.) on a port, the value of the port pinsis read, the desired operation is done to this value, andthis value is then written to the port latch.
Example 5-2 shows the effect of two sequentialread-modify-write instructions (ex., BCF, BSF, etc.) onan I/O port.
A pin actively outputting a Low or High should not bedriven from external devices at the same time in orderto change the level on this pin (“wired-or”, “wired-and”).The resulting high output currents may damagethe chip.
EXAMPLE 5-2: READ-MODIFY-WRITE INSTRUCTIONS ON AN I/O PORT
5.3.2 SUCCESSIVE OPERATIONS ON I/O PORTS
The actual write to an I/O port happens at the end of aninstruction cycle, whereas for reading, the data must bevalid at the beginning of the instruction cycle(Figure 5-16). Therefore, care must be exercised if awrite followed by a read operation is carried out on thesame I/O port. The sequence of instructions should besuch to allow the pin voltage to stabilize (loaddependent) before the next instruction which causesthat file to be read into the CPU is executed. Otherwise,the previous state of that pin may be read into the CPUrather than the new state. When in doubt, it is better toseparate these instructions with a NOP or anotherinstruction not accessing this I/O port.
;;Initial PORT settings: PORTB<7:4> Inputs
; PORTB<3:0> Outputs;;PORTB<7:6> have external pull-up and are notconnected to other circuitry
;; PORT latch PORT pins; ---------- ----------
BDF STATUS,RPO ;BCF PORTB, 7 ; 01pp pppp 11pp ppppBCF PORTB, 6 ; 10pp pppp 11pp ppppBSF STATUS,RP0 ;BCF TRISB, 7 ; 10pp pppp 11pp ppppBCF TRISB, 6 ; 10pp pppp 10pp pppp
;; Note that the user may have expected the pin; values to be 00pp pppp. The 2nd BCF caused ; RB7 to be latched as the pin value (High).
FIGURE 5-16: SUCCESSIVE I/O OPERATION
Note:
This example shows write to PORTBfollowed by a read from PORTB.
Note that:
data setup time = (0.25 TCY - TPD)where TCY = instruction cycle andTPD = propagation delay of Q1 cycle to output valid.
Therefore, at higher clock frequencies,a write followed by a read may beproblematic.
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
RB <7:0>
Port pin
sampled here
PC PC + 1 PC + 2 PC + 3
NOPNOPMOVF PORTB, W
Read PORTB
MOVWF PORTB
Write to
PORTB
PC
Instruction
fetched
TPD
Execute
MOVWF
PORTB
Execute
MOVF
PORTB, W
Execute
NOP
RB<7:0>
PCInstruction
fetchedMOWF PORTBWrite to PORTB
MOVF PORTB, WRead to PORTB
NOP NOP
Execute MOVWF PORTB
Execute MOVWF PORTB
Execute NOP
TPD
Port pin sampled here
PC + 1 PC + 2 PC + 3PC
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1999 Microchip Technology Inc. Preliminary DS40300B-page 45
PIC16F62X
6.0 TIMER0 MODULEThe Timer0 module timer/counter has the followingfeatures:
• 8-bit timer/counter• Readable and writable• 8-bit software programmable prescaler
• Internal or external clock select• Interrupt on overflow from FFh to 00h• Edge select for external clock
Figure 6-1 is a simplified block diagram of the Timer0module.
Timer mode is selected by clearing the T0CS bit(OPTION<5>). In timer mode, the TMR0 will incrementevery instruction cycle (without prescaler). If Timer0 iswritten, the increment is inhibited for the following twocycles (Figure 6-2 and Figure 6-3). The user can workaround this by writing an adjusted value to TMR0.
Counter mode is selected by setting the T0CS bit. Inthis mode Timer0 will increment either on every risingor falling edge of pin RA4/T0CKI. The incrementingedge is determined by the source edge (T0SE) control
bit (OPTION<4>). Clearing the T0SE bit selects therising edge. Restrictions on the external clock input arediscussed in detail in Section 6.2.
The prescaler is shared between the Timer0 moduleand the Watchdog Timer. The prescaler assignment iscontrolled in software by the control bit PSA(OPTION<3>). Clearing the PSA bit will assign theprescaler to Timer0. The prescaler is not readable orwritable. When the prescaler is assigned to the Timer0module, prescale value of 1:2, 1:4, ..., 1:256 areselectable. Section 6.3 details the operation of theprescaler.
6.1 TIMER0 Interrupt
Timer0 interrupt is generated when the TMR0 registertimer/counter overflows from FFh to 00h. This overflowsets the T0IF bit. The interrupt can be masked byclearing the T0IE bit (INTCON<5>). The T0IF bit(INTCON<2>) must be cleared in software by theTimer0 module interrupt service routine beforere-enabling this interrupt. The Timer0 interrupt cannotwake the processor from SLEEP since the timer is shutoff during SLEEP. See Figure 6-4 for Timer0 interrupttiming.
FIGURE 6-1: TIMER0 BLOCK DIAGRAM
FIGURE 6-2: TIMER0 (TMR0) TIMING: INTERNAL CLOCK/NO PRESCALER
Note 1: Bits T0SE, T0CS, PS2, PS1, PS0 and PSA are located in the OPTION register.2: The prescaler is shared with Watchdog Timer (Figure 6-6)
RA4/T0CKI
T0SE
0
1
1
0
pin
T0CS
FOSC/4
ProgrammablePrescaler
Sync withInternalclocks
TMR0
PSout
(2 TCY delay)
PSout
Data bus
8
Set Flag bit T0IFon OverflowPSAPS2:PS0
PC-1
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 Q4PC(ProgramCounter)
InstructionFetch
TMR0
PC PC+1 PC+2 PC+3 PC+4 PC+5 PC+6
T0 T0+1 T0+2 NT0 NT0+1 NT0+2 T0
MOVWF TMR0 MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W
Write TMR0executed
Read TMR0reads NT0
Read TMR0reads NT0
Read TMR0reads NT0
Read TMR0reads NT0 + 1
Read TMR0reads NT0 + 2
InstructionExecuted
PIC16F62X
DS40300B-page 46 Preliminary 1999 Microchip Technology Inc.
FIGURE 6-3: TIMER0 TIMING: INTERNAL CLOCK/PRESCALE 1:2
FIGURE 6-4: TIMER0 INTERRUPT TIMING
PC-1
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 Q4PC(ProgramCounter)
InstructionFetch
TMR0
PC PC+1 PC+2 PC+3 PC+4 PC+5 PC+6
T0 NT0+1
MOVWF TMR0 MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W MOVF TMR0,W
Write TMR0executed
Read TMR0reads NT0
Read TMR0reads NT0
Read TMR0reads NT0
Read TMR0reads NT0
Read TMR0reads NT0 + 1
T0+1 NT0
InstructionExecute
Q2Q1 Q3 Q4Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4
1 1
OSC1
CLKOUT(3)
TMR0 timer
T0IF bit(INTCON<2>)
FEh
GIE bit(INTCON<7>)
INSTRUCTION FLOW
PC
Instructionfetched
PC PC +1 PC +1 0004h 0005h
Instructionexecuted
Inst (PC)
Inst (PC-1)
Inst (PC+1)
Inst (PC)
Inst (0004h) Inst (0005h)
Inst (0004h)Dummy cycle Dummy cycle
FFh 00h 01h 02h
Note 1: T0IF interrupt flag is sampled here (every Q1).2: Interrupt latency = 3TCY, where TCY = instruction cycle time.3: CLKOUT is available only in ER and INTRC (with clockout) oscillator modes.
Interrupt Latency Time
1999 Microchip Technology Inc. Preliminary DS40300B-page 47
PIC16F62X
6.2 Using Timer0 with External Clock
When an external clock input is used for Timer0, it mustmeet certain requirements. The external clockrequirement is due to internal phase clock (TOSC)synchronization. Also, there is a delay in the actualincrementing of Timer0 after synchronization.
6.2.1 EXTERNAL CLOCK SYNCHRONIZATION
When no prescaler is used, the external clock input isthe same as the prescaler output. The synchronizationof T0CKI with the internal phase clocks isaccomplished by sampling the prescaler output on theQ2 and Q4 cycles of the internal phase clocks(Figure 6-5). Therefore, it is necessary for T0CKI to behigh for at least 2TOSC (and a small RC delay of 20 ns)and low for at least 2TOSC (and a small RC delay of20 ns). Refer to the electrical specification of thedesired device.
When a prescaler is used, the external clock input isdivided by the asynchronous ripple-counter typeprescaler so that the prescaler output is symmetrical.For the external clock to meet the samplingrequirement, the ripple-counter must be taken intoaccount. Therefore, it is necessary for T0CKI to have aperiod of at least 4TOSC (and a small RC delay of 40 ns)divided by the prescaler value. The only requirement onT0CKI high and low time is that they do not violate theminimum pulse width requirement of 10 ns. Refer toparameters 40, 41 and 42 in the electrical specificationof the desired device.
6.2.2 TIMER0 INCREMENT DELAY
Since the prescaler output is synchronized with theinternal clocks, there is a small delay from the time theexternal clock edge occurs to the time the TMR0 isactually incremented. Figure 6-5 shows the delay fromthe external clock edge to the timer incrementing.
FIGURE 6-5: TIMER0 TIMING WITH EXTERNAL CLOCK
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
External Clock Input orPrescaler output (2)
External Clock/PrescalerOutput after sampling
Increment Timer0 (Q4)
Timer0 T0 T0 + 1 T0 + 2
Small pulsemisses sampling
(3)
(1)
Note 1: Delay from clock input change to Timer0 increment is 3Tosc to 7Tosc. (Duration of Q = Tosc). Therefore, the error in measuring the interval between two edges on Timer0 input = ±4Tosc max.
2: External clock if no prescaler selected, Prescaler output otherwise.3: The arrows indicate the points in time where sampling occurs.
PIC16F62X
DS40300B-page 48 Preliminary 1999 Microchip Technology Inc.
6.3 Prescaler
An 8-bit counter is available as a prescaler for theTimer0 module, or as a postscaler for the WatchdogTimer, respectively (Figure 6-6). For simplicity, thiscounter is being referred to as “prescaler” throughoutthis data sheet. Note that there is only one prescaleravailable which is mutually exclusive between theTimer0 module and the Watchdog Timer. Thus, aprescaler assignment for the Timer0 module meansthat there is no prescaler for the Watchdog Timer, andvice-versa.
The PSA and PS2:PS0 bits (OPTION<3:0>) determinethe prescaler assignment and prescale ratio.
When assigned to the Timer0 module, all instructionswriting to the TMR0 register (e.g., CLRF 1,MOVWF 1, BSF 1, x....etc.) will clear the pres-caler. When assigned to WDT, a CLRWDT instructionwill clear the prescaler along with the Watchdog Timer.The prescaler is not readable or writable.
FIGURE 6-6: BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER
T0CKI
T0SE
pin
MUX
CLKOUT (=Fosc/4)
SYNC2
CyclesTMR0 reg
8-bit Prescaler
8-to-1MUX
MUX
M U X
WatchdogTimer
PSA
0 1
0
1
WDTTime-out
PS0 - PS2
8
Note: T0SE, T0CS, PSA, PS0-PS2 are bits in the OPTION register.
PSA
WDT Enable bit
MUX
0
1 0
1
Data Bus
Set flag bit T0IFon Overflow
8
PSAT0CS
1999 Microchip Technology Inc. Preliminary DS40300B-page 49
PIC16F62X
6.3.1 SWITCHING PRESCALER ASSIGNMENT
The prescaler assignment is fully under softwarecontrol (i.e., it can be changed “on the fly” duringprogram execution). To avoid an unintended deviceRESET, the following instruction sequence(Example 6-1) must be executed when changing theprescaler assignment from Timer0 to WDT.
EXAMPLE 6-1: CHANGING PRESCALER (TIMER0→WDT)
1.BCF STATUS, RP0 ;Skip if already in ; Bank 0
2.CLRWDT ;Clear WDT 3.CLRF TMR0 ;Clear TMR0 & Prescaler 4.BSF STATUS, RP0 ;Bank 1 5.MOVLW '00101111’b ;These 3 lines (5, 6, 7) 6.MOVWF OPTION ; are required only if
; desired PS<2:0> are 7.CLRWDT ; 000 or 001 8.MOVLW '00101xxx’b ;Set Postscaler to 9.MOVWF OPTION ; desired WDT rate10.BCF STATUS, RP0 ;Return to Bank 0
To change prescaler from the WDT to the TMR0module use the sequence shown in Example 6-2. Thisprecaution must be taken even if the WDT is disabled.
EXAMPLE 6-2: CHANGING PRESCALER (WDT→TIMER0)
CLRWDT ;Clear WDT and ;prescaler
BSF STATUS, RP0 MOVLW b'xxxx0xxx' ;Select TMR0, new
;prescale value and;clock source
MOVWF OPTION_REG BCF STATUS, RP0
TABLE 6-1: REGISTERS ASSOCIATED WITH TIMER0
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onAll OtherResets
01h TMR0 Timer0 module register xxxx xxxx uuuu uuuu
0Bh/8Bh/10Bh/18Bh
INTCON GIE — T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
81h OPTION RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
85h TRISA TRISA7 TRISA6 — TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 11-1 1111 11-1 1111
Legend: — = Unimplemented locations, read as ‘0’, u = unchanged, x = unknown
Note: Shaded bits are not used by TMR0 module.
PIC16F62X
DS40300B-page 50 Preliminary 1999 Microchip Technology Inc.
7.0 TIMER1 MODULEThe Timer1 module is a 16-bit timer/counter consistingof two 8-bit registers (TMR1H and TMR1L) which arereadable and writable. The TMR1 Register pair(TMR1H:TMR1L) increments from 0000h to FFFFhand rolls over to 0000h. The TMR1 Interrupt, if enabled,is generated on overflow which is latched in interruptflag bit TMR1IF (PIR1<0>). This interrupt can beenabled/disabled by setting/clearing TMR1 interruptenable bit TMR1IE (PIE1<0>).
Timer1 can operate in one of two modes:
• As a timer
• As a counter
The operating mode is determined by the clock selectbit, TMR1CS (T1CON<1>).
In timer mode, Timer1 increments every instructioncycle. In counter mode, it increments on every risingedge of the external clock input.
Timer1 can be enabled/disabled by setting/clearingcontrol bit TMR1ON (T1CON<0>).
Timer1 also has an internal “reset input”. This reset canbe generated by the CCP module (Section 10.0).Register 7-1 shows the Timer1 control register.
For the PIC16F627 and PIC16F628, when the Timer1oscillator is enabled (T1OSCEN is set), the RB7/T1OSIand RB6/T1OSO/T1CKI pins become inputs. That is,the TRISB<7:6> value is ignored.
REGISTER 7-1: T1CON: TIMER1 CONTROL REGISTER (ADDRESS 10h)
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON R = Readable bitW = Writable bitU = Unimplemented bit,
read as ‘0’- n = Value at POR reset
bit7 bit0
bit 7-6: Unimplemented: Read as '0'
bit 5-4: T1CKPS1:T1CKPS0: Timer1 Input Clock Prescale Select bits11 = 1:8 Prescale value10 = 1:4 Prescale value01 = 1:2 Prescale value00 = 1:1 Prescale value
bit 3: T1OSCEN: Timer1 Oscillator Enable Control bit1 = Oscillator is enabled0 = Oscillator is shut offNote: The oscillator inverter and feedback resistor are turned off to eliminate power drain
bit 2: T1SYNC: Timer1 External Clock Input Synchronization Control bit
TMR1CS = 11 = Do not synchronize external clock input0 = Synchronize external clock input
TMR1CS = 0This bit is ignored. Timer1 uses the internal clock when TMR1CS = 0.
bit 1: TMR1CS: Timer1 Clock Source Select bit1 = External clock from pin RB6/T1OSO/T1CKI (on the rising edge)0 = Internal clock (FOSC/4)
bit 0: TMR1ON: Timer1 On bit1 = Enables Timer10 = Stops Timer1
1999 Microchip Technology Inc. Preliminary DS40300B-page 51
PIC16F62X
7.1 Timer1 Operation in Timer Mode
Timer mode is selected by clearing the TMR1CS(T1CON<1>) bit. In this mode, the input clock to thetimer is FOSC/4. The synchronize control bit T1SYNC(T1CON<2>) has no effect since the internal clock isalways in sync.
7.2 Timer1 Operation in Synchronized Counter Mode
Counter mode is selected by setting bit TMR1CS. Inthis mode the timer increments on every rising edge ofclock input on pin RB7/T1OSI when bit T1OSCEN isset or pin RB6/T1OSO/T1CKI when bit T1OSCEN iscleared.
If T1SYNC is cleared, then the external clock input issynchronized with internal phase clocks. The synchro-nization is done after the prescaler stage. The pres-caler stage is an asynchronous ripple-counter.
In this configuration, during SLEEP mode, Timer1 willnot increment even if the external clock is present,since the synchronization circuit is shut off. The pres-caler however will continue to increment.
7.2.1 EXTERNAL CLOCK INPUT TIMING FOR SYNCHRONIZED COUNTER MODE
When an external clock input is used for Timer1 in syn-chronized counter mode, it must meet certain require-ments. The external clock requirement is due to
internal phase clock (Tosc) synchronization. Also, thereis a delay in the actual incrementing of TMR1 after syn-chronization.
When the prescaler is 1:1, the external clock input isthe same as the prescaler output. The synchronizationof T1CKI with the internal phase clocks is accom-plished by sampling the prescaler output on the Q2 andQ4 cycles of the internal phase clocks. Therefore, it isnecessary for T1CKI to be high for at least 2Tosc (anda small RC delay of 20 ns) and low for at least 2Tosc(and a small RC delay of 20 ns). Refer to the appropri-ate electrical specifications, parameters 45, 46, and 47.
When a prescaler other than 1:1 is used, the externalclock input is divided by the asynchronous rip-ple-counter type prescaler so that the prescaler outputis symmetrical. In order for the external clock to meetthe sampling requirement, the ripple-counter must betaken into account. Therefore, it is necessary for T1CKIto have a period of at least 4Tosc (and a small RC delayof 40 ns) divided by the prescaler value. The onlyrequirement on T1CKI high and low time is that they donot violate the minimum pulse width requirements of10 ns). Refer to the appropriate electrical specifica-tions, parameters 40, 42, 45, 46, and 47.
FIGURE 7-1: TIMER1 BLOCK DIAGRAM
TMR1H TMR1L
T1OSCT1SYNC
TMR1CST1CKPS1:T1CKPS0
SLEEP input
T1OSCENEnableOscillator(1)
FOSC/4InternalClock
TMR1ONon/off
Prescaler1, 2, 4, 8
Synchronize
det
1
0
0
1
Synchronizedclock input
2
RB6/T1OSO/T1CKI
RB7/T1OSI
Note 1: When the T1OSCEN bit is cleared, the inverter and feedback resistor are turned off. This eliminates power drain.
Set flag bitTMR1IF onOverflow
TMR1
PIC16F62X
DS40300B-page 52 Preliminary 1999 Microchip Technology Inc.
FIGURE 7-2: TIMER1 INCREMENTING EDGE
T1CKI
(Default high)
T1CKI
(Default low)
Note: Arrows indicate counter increments.
7.3 Timer1 Operation in Asynchronous Counter Mode
If control bit T1SYNC (T1CON<2>) is set, the externalclock input is not synchronized. The timer continues toincrement asynchronous to the internal phase clocks.The timer will continue to run during SLEEP and cangenerate an interrupt on overflow which will wake-upthe processor. However, special precautions in soft-ware are needed to read/write the timer (Section 7.3.2).
In asynchronous counter mode, Timer1 can not beused as a time-base for capture or compare operations.
7.3.1 EXTERNAL CLOCK INPUT TIMING WITH UNSYNCHRONIZED CLOCK
If control bit T1SYNC is set, the timer will incrementcompletely asynchronously. The input clock must meetcertain minimum high time and low time requirements.Refer to the appropriate Electrical Specifications Sec-tion, timing parameters 45, 46, and 47.
7.3.2 READING AND WRITING TIMER1 IN ASYNCHRONOUS COUNTER MODE
Reading TMR1H or TMR1L while the timer is running,from an external asynchronous clock, will guarantee avalid read (taken care of in hardware). However, theuser should keep in mind that reading the 16-bit timerin two 8-bit values itself poses certain problems sincethe timer may overflow between the reads.
For writes, it is recommended that the user simply stopthe timer and write the desired values. A write conten-tion may occur by writing to the timer registers while theregister is incrementing. This may produce an unpre-dictable value in the timer register.
Reading the 16-bit value requires some care.Example 7-1 is an example routine to read the 16-bittimer value. This is useful if the timer cannot bestopped.
EXAMPLE 7-1: READING A 16-BIT FREE-RUNNING TIMER
; All interrupts are disabled MOVF TMR1H, W ;Read high byte MOVWF TMPH ; MOVF TMR1L, W ;Read low byte MOVWF TMPL ; MOVF TMR1H, W ;Read high byte SUBWF TMPH, W ;Sub 1st read ; with 2nd read BTFSC STATUS,Z ;Is result = 0 GOTO CONTINUE ;Good 16-bit read;; TMR1L may have rolled over between the read; of the high and low bytes. Reading the high; and low bytes now will read a good value.; MOVF TMR1H, W ;Read high byte MOVWF TMPH ; MOVF TMR1L, W ;Read low byte MOVWF TMPL ;; Re-enable the Interrupt (if required)CONTINUE ;Continue with your code
7.4 Timer1 Oscillator
A crystal oscillator circuit is built in between pins T1OSI(input) and T1OSO (amplifier output). It is enabled bysetting control bit T1OSCEN (T1CON<3>). The oscilla-tor is a low power oscillator rated up to 200 kHz. It willcontinue to run during SLEEP. It is primarily intendedfor a 32 kHz crystal. Table 7-1 shows the capacitorselection for the Timer1 oscillator.
The Timer1 oscillator is identical to the LP oscillator.The user must provide a software time delay to ensureproper oscillator start-up.
TABLE 7-1: CAPACITOR SELECTION FOR THE TIMER1 OSCILLATOR
Osc Type Freq C1 C2
LP 32 kHz 33 pF 33 pF
100 kHz 15 pF 15 pF200 kHz 15 pF 15 pF
These values are for design guidance only.
1999 Microchip Technology Inc. Preliminary DS40300B-page 53
PIC16F62X
7.5 Resetting Timer1 using a CCP Trigger Output
If the CCP1 module is configured in compare mode togenerate a “special event trigger" (CCP1M3:CCP1M0= 1011), this signal will reset Timer1.
Timer1 must be configured for either timer or synchro-nized counter mode to take advantage of this feature. IfTimer1 is running in asynchronous counter mode, thisreset operation may not work.
In the event that a write to Timer1 coincides with a spe-cial event trigger from CCP1, the write will take prece-dence.
In this mode of operation, the CCPRxH:CCPRxL regis-ters pair effectively becomes the period register forTimer1.
Note: The special event triggers from the CCP1module will not set interrupt flag bitTMR1IF (PIR1<0>).
7.6 Resetting of Timer1 Register Pair (TMR1H, TMR1L)
TMR1H and TMR1L registers are not reset to 00h on aPOR or any other reset except by the CCP1 specialevent triggers.
T1CON register is reset to 00h on a Power-on Reset ora Brown-out Reset, which shuts off the timer andleaves a 1:1 prescale. In all other resets, the register isunaffected.
7.7 Timer1 Prescaler
The prescaler counter is cleared on writes to theTMR1H or TMR1L registers.
TABLE 7-2: REGISTERS ASSOCIATED WITH TIMER1 AS A TIMER/COUNTER
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value on all other
resets
0Bh/8Bh/10Bh/18Bh
INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
0Eh TMR1L Holding register for the Least Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding register for the Most Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by the Timer1 module.
PIC16F62X
DS40300B-page 54 Preliminary 1999 Microchip Technology Inc.
8.0 TIMER2 MODULETimer2 is an 8-bit timer with a prescaler and apostscaler. It can be used as the PWM time-base forPWM mode of the CCP module. The TMR2 register isreadable and writable, and is cleared on any devicereset.
The input clock (FOSC/4) has a prescale option of 1:1,1:4 or 1:16, selected by control bitsT2CKPS1:T2CKPS0 (T2CON<1:0>).
The Timer2 module has an 8-bit period register PR2.Timer2 increments from 00h until it matches PR2 andthen resets to 00h on the next increment cycle. PR2 isa readable and writable register. The PR2 register is ini-tialized to FFh upon reset.
The match output of TMR2 goes through a 4-bitpostscaler (which gives a 1:1 to 1:16 scaling inclusive)to generate a TMR2 interrupt (latched in flag bitTMR2IF, (PIR1<1>)).
Timer2 can be shut off by clearing control bit TMR2ON(T2CON<2>) to minimize power consumption.
Register 8-1 shows the Timer2 control register.
8.1 Timer2 Prescaler and Postscaler
The prescaler and postscaler counters are clearedwhen any of the following occurs:
• a write to the TMR2 register• a write to the T2CON register
• any device reset (Power-on Reset, MCLR reset, Watchdog Timer reset, or Brown-out Reset)
TMR2 is not cleared when T2CON is written.
8.2 Output of TMR2
The output of TMR2 (before the postscaler) is fed to theSynchronous Serial Port module which optionally usesit to generate shift clock.
FIGURE 8-1: TIMER2 BLOCK DIAGRAM
Comparator
TMR2Sets flag
TMR2 reg
output (1)
Reset
Postscaler
Prescaler
PR2 reg
2
FOSC/4
1:1 1:16
1:1, 1:4, 1:16
EQ
4
bit TMR2IF
Note 1: TMR2 register output can be software selected by the SSP Module as a baud clock.
to
1999 Microchip Technology Inc. Preliminary DS40300B-page 55
PIC16F62X
REGISTER 8-1: T2CON: TIMER2 CONTROL REGISTER (ADDRESS 12h)
TABLE 8-1: REGISTERS ASSOCIATED WITH TIMER2 AS A TIMER/COUNTER
U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 R = Readable bitW = Writable bitU = Unimplemented bit,
read as ‘0’- n = Value at POR reset
bit7 bit0
bit 7: Unimplemented: Read as '0'
bit 6-3: TOUTPS3:TOUTPS0: Timer2 Output Postscale Select bits0000 = 1:1 Postscale0001 = 1:2 Postscale•••1111 = 1:16 Postscale
bit 2: TMR2ON: Timer2 On bit1 = Timer2 is on0 = Timer2 is off
bit 1-0: T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits00 = Prescaler is 101 = Prescaler is 41x = Prescaler is 16
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value onPOR
Value on all other
resets
0Bh/8Bh/10Bh/18Bh
INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
11h TMR2 Timer2 module’s register 0000 0000 0000 0000
12h T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000
92h PR2 Timer2 Period Register 1111 1111 1111 1111
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by the Timer2 module.
PIC16F62X
DS40300B-page 56 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 57
PIC16F62X
9.0 COMPARATOR MODULEThe comparator module contains two analogcomparators. The inputs to the comparators aremultiplexed with the RA0 through RA3 pins. Theon-chip Voltage Reference (Section 11.0) can also bean input to the comparators.
The CMCON register, shown in Register 9-1, controlsthe comparator input and output multiplexers. A blockdiagram of the comparator is shown in Figure 9-1.
REGISTER 9-1: CMCON REGISTER (ADDRESS 01Fh)
R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 R = Readable bitW = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7: C2OUT: Comparator 2 outputWhen C2INV=0;1 = C2 VIN+ > C2 VIN–0 = C2 VIN+ < C2 VIN–
When C2INV=1;0 = C2 VIN+ > C2 VIN–1 = C2 VIN+ < C2 VIN–
bit 6: C1OUT: Comparator 1 outputWhen C1INV=0;1 = C1 VIN+ > C1 VIN–0 = C1 VIN+ < C1 VIN–
When C1INV=1;0 = C1 VIN+ > C1 VIN–1 = C1 VIN+ < C1 VIN–
bit 5: C2INV: Comparator 2 output inversion1 = C2 Output inverted0 = C2 Output not inverted
bit 4: C1INV: Comparator 1 output inversion1 = C1 Output inverted0 = C1 Output not inverted
bit 3: CIS: Comparator Input Switch
When CM2:CM0: = 001:Then:1 = C1 VIN– connects to RA30 = C1 VIN– connects to RA0
When CM2:CM0 = 010:Then:1 = C1 VIN– connects to RA3 C2 VIN– connects to RA20 = C1 VIN– connects to RA0 C2 VIN– connects to RA1
bit 2-0: CM2:CM0: Comparator modeFigure 9-1 shows the comparator modes and CM2:CM0 bit settings.
PIC16F62X
DS40300B-page 58 Preliminary 1999 Microchip Technology Inc.
9.1 Comparator Configuration
There are eight modes of operation for thecomparators. The CMCON register is used to selectthe mode. Figure 9-1 shows the eight possible modes.The TRISA register controls the data direction of thecomparator pins for each mode. If the comparator
mode is changed, the comparator output level may notbe valid for the specified mode change delay shownin Table 12-2.
Note: Comparator interrupts should be disabledduring a comparator mode change other-wise a false interrupt may occur.
FIGURE 9-1: COMPARATOR I/O OPERATING MODES
C1
RA0/AN0 Vin-
Vin+RA3/AN3/C10 Off (Read as ’0’)
Comparators Reset (POR Default Value)
A
A
CM2:CM0 = 000
C2RA1/AN1 Vin-
Vin+RA2/AN2 Off (Read as ’0’)
A
A
C1RA0/AN0 Vin-
Vin+RA3/AN3/C10C1OUT
Two Independent Comparators
A
A
CM2:CM0 = 100
C2
RA1/AN1 Vin-
Vin+RA2/AN2 C2OUT
A
A
C1RA0/AN0 Vin-
Vin+RA3/AN3/C10
C1OUT
Two Common Reference Comparators
A
D
CM2:CM0 = 011
C2RA1/AN1 Vin-
Vin+RA2/AN2 C2OUT
A
A
C1RA0/AN0 Vin-
Vin+RA3/AN3/C10Off (Read as ’0’)
One Independent Comparator
D
D
CM2:CM0 = 101
C2RA1/AN1 Vin-
Vin+RA2/AN2C2OUT
A
A
C1RA0/AN0 Vin-
Vin+RA3/AN3/C10Off (Read as ’0’)
Comparators Off
D
D
CM2:CM0 = 111
C2RA1/AN1 Vin-
Vin+RA2/AN2Off (Read as ’0’)
D
D
C1
RA0/AN0Vin-
Vin+RA3/AN3/C10 C1OUT
Four Inputs Multiplexed to Two Comparators
A
A
CM2:CM0 = 010
C2
RA1/AN1Vin-
Vin+RA2/AN2 C2OUT
A
A
From Vref Module
CIS = 0CIS = 1
CIS = 0CIS = 1
C1RA0/AN0 Vin-
Vin+RA3/AN3/C10C1OUT
Two Common Reference Comparators with Outputs
A
D
CM2:CM0 = 110
C2RA1/AN1 Vin-
Vin+RA2/AN2C2OUT
A
A
Open Drain
A = Analog Input, port reads zeros always.D = Digital Input.CIS (CMCON<3>) is the Comparator Input Switch.
RA4/T0CKI/C20
C1
RA0/AN0 Vin-
Vin+RA3/AN3/C10 C1OUT
Three Inputs Multiplexed to Two Comparators
A
A
CM2:CM0 = 001
C2RA1/AN1 Vin-
Vin+RA2/AN2C2OUT
A
A
CIS = 0CIS = 1
1999 Microchip Technology Inc. Preliminary DS40300B-page 59
PIC16F62X
The code example in Example 9-1 depicts the stepsrequired to configure the comparator module. RA3 andRA4 are configured as digital output. RA0 and RA1 areconfigured as the V- inputs and RA2 as the V+ input toboth comparators.
EXAMPLE 9-1: INITIALIZING COMPARATOR MODULE
9.2 Comparator Operation
A single comparator is shown in Figure 9-2 along withthe relationship between the analog input levels andthe digital output. When the analog input at VIN+ is lessthan the analog input VIN–, the output of thecomparator is a digital low level. When the analog inputat VIN+ is greater than the analog input VIN–, the outputof the comparator is a digital high level. The shadedareas of the output of the comparator in Figure 9-2represent the uncertainty due to input offsets andresponse time.
FLAG_REG EQU 0X20CLRF FLAG_REG ;Init flag registerCLRF PORTA ;Init PORTAMOVF CMCON, W ;Load comparator bitsANDLW 0xC0 ;Mask comparator bitsIORWF FLAG_REG,F ;Store bits in flag registerMOVLW 0x03 ;Init comparator modeMOVWF CMCON ;CM<2:0> = 011 BSF STATUS,RP0 ;Select Bank1MOVLW 0x07 ;Initialize data directionMOVWF TRISA ;Set RA<2:0> as inputs
;RA<4:3> as outputs;TRISA<7:5> always read ‘0’
BCF STATUS,RP0 ;Select Bank 0CALL DELAY 10 ;10 µs delayMOVF CMCON,F ;Read CMCON to end change conditionBCF PIR1,CMIF ;Clear pending interruptsBSF STATUS,RP0 ;Select Bank 1BSF PIE1,CMIE ;Enable comparator interruptsBCF STATUS,RP0 ;Select Bank 0BSF INTCON,PEIE ;Enable peripheral interruptsBSF INTCON,GIE ;Global interrupt enable
9.3 Comparator Reference
An external or internal reference signal may be useddepending on the comparator operating mode. Theanalog signal that is present at VIN– is compared to thesignal at VIN+, and the digital output of the comparatoris adjusted accordingly (Figure 9-2).
FIGURE 9-2: SINGLE COMPARATOR
9.3.1 EXTERNAL REFERENCE SIGNAL
When external voltage references are used, thecomparator module can be configured to have the com-parators operate from the same or different referencesources. However, threshold detector applications mayrequire the same reference. The reference signal mustbe between VSS and VDD, and can be applied to eitherpin of the comparator(s).
9.3.2 INTERNAL REFERENCE SIGNAL
The comparator module also allows the selection of aninternally generated voltage reference for thecomparators. Section 13, Instruction Sets, contains adetailed description of the Voltage Reference Modulethat provides this signal. The internal reference signalis used when the comparators are in modeCM<2:0>=010 (Figure 9-1). In this mode, the internalvoltage reference is applied to the VIN+ pin of bothcomparators.
–+VIN+
VIN–Output
VIN–
VIN+
Output
PIC16F62X
DS40300B-page 60 Preliminary 1999 Microchip Technology Inc.
9.4 Comparator Response Time
Response time is the minimum time, after selecting anew reference voltage or input source, before thecomparator output is guaranteed to have a valid level.If the internal reference is changed, the maximum delayof the internal voltage reference must be consideredwhen using the comparator outputs. Otherwise themaximum delay of the comparators should be used(Table 12-2 ).
9.5 Comparator Outputs
The comparator outputs are read through the CMCONregister. These bits are read only. The comparatoroutputs may also be directly output to the RA3 and RA4I/O pins. When the CM<2:0> = 110 or 001, multiplexorsin the output path of the RA3 and RA4/T0CK1 pins willswitch and the output of each pin will be the unsynchro-nized output of the comparator. The uncertainty of eachof the comparators is related to the input offset voltageand the response time given in the specifications.Figure 9-3 shows the comparator output block diagram.
The TRISA bits will still function as an outputenable/disable for the RA3 and RA4/T0CK1 pins whilein this mode.
Note 1: When reading the PORT register, all pinsconfigured as analog inputs will read asa ‘0’. Pins configured as digital inputs willconvert an analog input according to theSchmitt Trigger input specification.
2: Analog levels on any pin that is definedas a digital input may cause the inputbuffer to consume more current than isspecified.
FIGURE 9-3: MODIFIED COMPARATOR OUTPUT BLOCK DIAGRAM
DQ
EN
To RA3 or RA4/T0CK1 pin
RD CMCON
Set CMIF bit
MULTIPLEX
DQ
EN
CL
Port Pins
Q3 * RD CMCON
NRESETFrom other Comparator
To Data Bus
Q1
CnINV
1999 Microchip Technology Inc. Preliminary DS40300B-page 61
PIC16F62X
9.6 Comparator Interrupts
The comparator interrupt flag is set whenever there isa change in the output value of either comparator.Software will need to maintain information about thestatus of the output bits, as read from CMCON<7:6>, todetermine the actual change that has occurred. TheCMIF bit, PIR1<6>, is the comparator interrupt flag.The CMIF bit must be reset by clearing ‘0’. Since it isalso possible to write a '1' to this register, a simulatedinterrupt may be initiated.
The CMIE bit (PIE1<6>) and the PEIE bit(INTCON<6>) must be set to enable the interrupt. Inaddition, the GIE bit must also be set. If any of thesebits are clear, the interrupt is not enabled, though theCMIF bit will still be set if an interrupt condition occurs.
The user, in the interrupt service routine, can clear theinterrupt in the following manner:
a) Any read or write of CMCON. This will end themismatch condition.
b) Clear flag bit CMIF.
A mismatch condition will continue to set flag bit CMIF.Reading CMCON will end the mismatch condition, andallow flag bit CMIF to be cleared.
9.7 Comparator Operation During SLEEP
When a comparator is active and the device is placedin SLEEP mode, the comparator remains active andthe interrupt is functional if enabled. This interrupt will
Note: If a change in the CMCON register(C1OUT or C2OUT) should occur when aread operation is being executed (start ofthe Q2 cycle), then the CMIF (PIR1<6>)interrupt flag may not get set.
wake up the device from SLEEP mode when enabled.While the comparator is powered-up, higher sleepcurrents than shown in the power down currentspecification will occur. Each comparator that isoperational will consume additional current as shown inthe comparator specifications. To minimize powerconsumption while in SLEEP mode, turn off thecomparators, CM<2:0> = 111, before entering sleep. Ifthe device wakes-up from sleep, the contents of theCMCON register are not affected.
9.8 Effects of a RESET
A device reset forces the CMCON register to its resetstate. This forces the comparator module to be in thecomparator reset mode, CM2:CM0 = 000. Thisensures that all potential inputs are analog inputs.Device current is minimized when analog inputs arepresent at reset time. The comparators will bepowered-down during the reset interval.
9.9 Analog Input Connection Considerations
A simplified circuit for an analog input is shown inFigure 9-4. Since the analog pins are connected to adigital output, they have reverse biased diodes to VDD
and VSS. The analog input therefore, must be betweenVSS and VDD. If the input voltage deviates from thisrange by more than 0.6V in either direction, one of thediodes is forward biased and a latch-up may occur. Amaximum source impedance of 10 kΩ isrecommended for the analog sources. Any externalcomponent connected to an analog input pin, such asa capacitor or a Zener diode, should have very littleleakage current.
FIGURE 9-4: ANALOG INPUT MODEL
VA
RS < 10K
AIN
CPIN5 pF
VDD
VT = 0.6V
VT = 0.6V
RIC
ILEAKAGE±500 nA
VSS
Legend CPIN = Input CapacitanceVT = Threshold VoltageILEAKAGE = Leakage Current At The Pin Due To Various JunctionsRIC = Interconnect ResistanceRS = Source ImpedanceVA = Analog Voltage
PIC16F62X
DS40300B-page 62 Preliminary 1999 Microchip Technology Inc.
TABLE 9-1: REGISTERS ASSOCIATED WITH COMPARATOR MODULE
Legend: x = unknown, u = unchanged, - = unimplemented, read as "0"
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onAll OtherResets
1Fh CMCON C2OUT C1OUT C2INV C1NV CIS CM2 CM1 CM0 0000 0000 0000 0000
9Fh VRCON VREN VROE VRR — VR3 VR2 VR1 VR0 000- 0000 000- 0000
0Bh/8Bh/10Bh/18Bh
INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
85h TRISA TRISA7 TRISA6 — TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 11-1 1111 11-1 1111
PIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 63
10.0 CAPTURE/COMPARE/PWM (CCP) MODULE
The CCP (Capture/Compare/PWM) module contains a16-bit register which can operate as a 16-bit captureregister, as a 16-bit compare register or as a PWMmaster/slave Duty Cycle register. Table 10-1 shows thetimer resources of the CCP module modes.
CCP1 Module
Capture/Compare/PWM Register1 (CCPR1) is com-prised of two 8-bit registers: CCPR1L (low byte) andCCPR1H (high byte). The CCP1CON register controlsthe operation of CCP1. All are readable and writable.
Additional information on the CCP module is availablein the PICmicro™ Mid-Range Reference Manual,(DS33023).
TABLE 10-1 CCP MODE - TIMER RESOURCE
REGISTER 10-1: CCP1CON REGISTER (ADDRESS 17h)
CCP Mode Timer Resource
CaptureCompare
PWM
Timer1Timer1Timer2
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 R = Readable bitW = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7-6: Unimplemented: Read as '0'
bit 5-4: CCP1X:CCP1Y: PWM Least Significant bitsCapture Mode: UnusedCompare Mode: UnusedPWM Mode: These bits are the two LSbs of the PWM duty cycle. The eight MSbs are found in CCPRxL.
bit 3-0: CCP1M3:CCP1M0: CCPx Mode Select bits0000 = Capture/Compare/PWM off (resets CCP1 module)0100 = Capture mode, every falling edge0101 = Capture mode, every rising edge0110 = Capture mode, every 4th rising edge0111 = Capture mode, every 16th rising edge1000 = Compare mode, set output on match (CCP1IF bit is set)1001 = Compare mode, clear output on match (CCP1IF bit is set)1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin is unaffected)1011 = Compare mode, trigger special event (CCP1IF bit is set; CCP1 resets TMR111xx = PWM mode
PIC16F62X
DS40300B-page 64 Preliminary 1999 Microchip Technology Inc.
10.1 Capture Mode
In Capture mode, CCPR1H:CCPR1L captures the16-bit value of the TMR1 register when an event occurson pin RB3/CCP1. An event is defined as:
• every falling edge• every rising edge
• every 4th rising edge• every 16th rising edge
An event is selected by control bits CCP1M3:CCP1M0(CCP1CON<3:0>). When a capture is made, the inter-rupt request flag bit CCP1IF (PIR1<2>) is set. It mustbe cleared in software. If another capture occurs beforethe value in register CCPR1 is read, the old capturedvalue will be lost.
10.1.1 CCP PIN CONFIGURATION
In Capture mode, the RB3/CCP1 pin should be config-ured as an input by setting the TRISB<3> bit.
FIGURE 10-1: CAPTURE MODE OPERATION BLOCK DIAGRAM
10.1.2 TIMER1 MODE SELECTION
Timer1 must be running in timer mode or synchronizedcounter mode for the CCP module to use the capturefeature. In asynchronous counter mode, the captureoperation may not work.
10.1.3 SOFTWARE INTERRUPT
When the Capture mode is changed, a false captureinterrupt may be generated. The user should keep bitCCP1IE (PIE1<2>) clear to avoid false interrupts andshould clear the flag bit CCP1IF following any suchchange in operating mode.
10.1.4 CCP PRESCALER
There are four prescaler settings, specified by bitsCCP1M3:CCP1M0. Whenever the CCP module isturned off, or the CCP module is not in capture mode,the prescaler counter is cleared. This means that anyreset will clear the prescaler counter.
Switching from one capture prescaler to another maygenerate an interrupt. Also, the prescaler counter willnot be cleared, therefore the first capture may be froma non-zero prescaler. Example 10-1 shows the recom-mended method for switching between capture pres-calers. This example also clears the prescaler counterand will not generate the “false” interrupt.
EXAMPLE 10-1: CHANGING BETWEEN CAPTURE PRESCALERS
CLRF CCP1CON ;Turn CCP module offMOVLW NEW_CAPT_PS ;Load the W reg with ; the new prescaler ; mode value and CCP ONMOVWF CCP1CON ;Load CCP1CON with this ; value
Note: If the RB3/CCP1 is configured as an out-put, a write to the port can cause a capturecondition.
CCPR1H CCPR1L
TMR1H TMR1L
Set flag bit CCP1IF(PIR1<2>)
CaptureEnable
Q’sCCP1CON<3:0>
RB3/CCP1
Prescaler³ 1, 4, 16
andedge detect
Pin
PIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 65
10.2 Compare Mode
In Compare mode, the 16-bit CCPR1 register value isconstantly compared against the TMR1 register pairvalue. When a match occurs, the RB3/CCP1 pin is:
• driven High
• driven Low• remains Unchanged
The action on the pin is based on the value of controlbits CCP1M3:CCP1M0 (CCP1CON<3:0>). At thesame time, interrupt flag bit CCP1IF is set.
FIGURE 10-2: COMPARE MODE OPERATION BLOCK DIAGRAM
10.2.1 CCP PIN CONFIGURATION
The user must configure the RB3/CCP1 pin as an out-put by clearing the TRISB<3> bit.
10.2.2 TIMER1 MODE SELECTION
Timer1 must be running in Timer mode or Synchro-nized Counter mode if the CCP module is using thecompare feature. In Asynchronous Counter mode, thecompare operation may not work.
10.2.3 SOFTWARE INTERRUPT MODE
When generate software interrupt is chosen the CCP1pin is not affected. Only a CCP interrupt is generated (ifenabled).
10.2.4 SPECIAL EVENT TRIGGER
In this mode, an internal hardware trigger is generatedwhich may be used to initiate an action.
The special event trigger output of CCP1 resets theTMR1 register pair. This allows the CCPR1 register toeffectively be a 16-bit programmable period register forTimer1.
TABLE 10-2 REGISTERS ASSOCIATED WITH CAPTURE, COMPARE, AND TIMER1
CCPR1H CCPR1L
TMR1H TMR1L
ComparatorQ S
R
OutputLogic
Special Event Trigger (CCP2 only)
Set flag bit CCP1IF(PIR1<2>)
matchRB3/CCP1
TRISB<3>CCP1CON<3:0>Mode Select
Output Enable
Pin
Special event trigger will reset Timer1, but notset interrupt flag bit TMR1IF (PIR1<0>)
Note: Clearing the CCP1CON register will forcethe RB3/CCP1 compare output latch to thedefault low level. This is not the data latch.
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onall otherresets
0Bh/8Bh/10Bh/18Bh
INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIF RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
87h TRISB PORTB Data Direction Register 1111 1111 1111 1111
0Eh TMR1L Holding register for the Least Significant Byte of the 16-bit TMR1 register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding register for the Most Significant Byte of the 16-bit TMR1register xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
15h CCPR1L Capture/Compare/PWM register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by Capture and Timer1.
PIC16F62X
DS40300B-page 66 Preliminary 1999 Microchip Technology Inc.
10.3 PWM Mode
In Pulse Width Modulation (PWM) mode, the CCP1 pinproduces up to a 10-bit resolution PWM output. Sincethe CCP1 pin is multiplexed with the PORTC data latch,the TRISB<3> bit must be cleared to make the CCP1pin an output.
Figure 10-3 shows a simplified block diagram of theCCP module in PWM mode.
For a step by step procedure on how to set up the CCPmodule for PWM operation, see Section 10.3.3.
FIGURE 10-3: SIMPLIFIED PWM BLOCK DIAGRAM
A PWM output (Figure 10-4) has a time base (period)and a time that the output stays high (duty cycle). Thefrequency of the PWM is the inverse of the period(1/period).
FIGURE 10-4: PWM OUTPUT
10.3.1 PWM PERIOD
The PWM period is specified by writing to the PR2 reg-ister. The PWM period can be calculated using the fol-lowing formula:
PWM period = [(PR2) + 1] • 4 • TOSC • (TMR2 prescale value)
PWM frequency is defined as 1 / [PWM period].
When TMR2 is equal to PR2, the following three eventsoccur on the next increment cycle:
• TMR2 is cleared
• The CCP1 pin is set (exception: if PWM duty cycle = 0%, the CCP1 pin will not be set)
• The PWM duty cycle is latched from CCPR1L into CCPR1H
10.3.2 PWM DUTY CYCLE
The PWM duty cycle is specified by writing to theCCPR1L register and to the CCP1CON<5:4> bits. Upto 10-bit resolution is available: the CCPR1L containsthe eight MSbs and the CCP1CON<5:4> contains thetwo LSbs. This 10-bit value is represented byCCPR1L:CCP1CON<5:4>. The following equation isused to calculate the PWM duty cycle in time:
PWM duty cycle = (CCPR1L:CCP1CON<5:4>) • Tosc • (TMR2 prescale value)
CCPR1L and CCP1CON<5:4> can be written to at anytime, but the duty cycle value is not latched intoCCPR1H until after a match between PR2 and TMR2occurs (i.e., the period is complete). In PWM mode,CCPR1H is a read-only register.
The CCPR1H register and a 2-bit internal latch areused to double buffer the PWM duty cycle. This doublebuffering is essential for glitchless PWM operation.
When the CCPR1H and 2-bit latch match TMR2 con-catenated with an internal 2-bit Q clock or 2 bits of theTMR2 prescaler, the CCP1 pin is cleared.
Maximum PWM resolution (bits) for a given PWMfrequency:
For an example PWM period and duty cycle calcula-tion, see the PICmicro™ Mid-Range Reference Manual(DS33023).
Note: Clearing the CCP1CON register will forcethe CCP1 PWM output latch to the defaultlow level. This is not the PORTB I/O datalatch.
CCPR1L
CCPR1H (Slave)
Comparator
TMR2
Comparator
PR2
(Note 1)
R Q
S
Duty cycle registers CCP1CON<5:4>
Clear Timer,CCP1 pin and latch D.C.
TRISB<3>
RB3/CCP1
Note 1: 8-bit timer is concatenated with 2-bit internal Q clockor 2 bits of the prescaler to create 10-bit time-base.
Period
Duty Cycle
TMR2 = PR2
TMR2 = Duty Cycle
TMR2 = PR2
Note: The Timer2 postscaler (see Section 8.0) isnot used in the determination of the PWMfrequency. The postscaler could be used tohave a servo update rate at a different fre-quency than the PWM output.
Note: If the PWM duty cycle value is longer thanthe PWM period the CCP1 pin will not becleared.
log ( Fpwm
log (2)
Fosc )bits=
PIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 67
10.3.3 SET-UP FOR PWM OPERATION
The following steps should be taken when configuringthe CCP module for PWM operation:
1. Set the PWM period by writing to the PR2 regis-ter.
2. Set the PWM duty cycle by writing to theCCPR1L register and CCP1CON<5:4> bits.
3. Make the CCP1 pin an output by clearing theTRISB<3> bit.
4. Set the TMR2 prescale value and enable Timer2by writing to T2CON.
5. Configure the CCP1 module for PWM operation.
TABLE 10-3 EXAMPLE PWM FREQUENCIES AND RESOLUTIONS AT 20 MHz
TABLE 10-4 REGISTERS ASSOCIATED WITH PWM AND TIMER2
PWM Frequency 1.22 kHz 4.88 kHz 19.53 kHz 78.12 kHz 156.3 kHz 208.3 kHz
Timer Prescaler (1, 4, 16) 16 4 1 1 1 1
PR2 Value 0xFF 0xFF 0xFF 0x3F 0x1F 0x17Maximum Resolution (bits) 10 10 10 8 7 5.5
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value on all otherresets
0Bh/8Bh/10Bh/18Bh
INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
87h TRISB PORTB Data Direction Register 1111 1111 1111 1111
11h TMR2 Timer2 module’s register 0000 0000 0000 0000
92h PR2 Timer2 module’s period register 1111 1111 1111 1111
12h T2CON — TOUTPS3
TOUTPS2
TOUTPS1
TOUTPS0
TMR2ON T2CKPS1
T2CKPS0
-000 0000 uuuu uuuu
15h CCPR1L Capture/Compare/PWM register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by PWM and Timer2.
PIC16F62X
DS40300B-page 68 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 69
PIC16F62X
11.0 VOLTAGE REFERENCE MODULE
The Voltage Reference is a 16-tap resistor laddernetwork that provides a selectable voltage reference.The resistor ladder is segmented to provide two rangesof VREF values and has a power-down function toconserve power when the reference is not being used.The VRCON register controls the operation of thereference as shown in Figure 11-1. The block diagramis given in Figure 11-2.
11.1 Configuring the Voltage Reference
The Voltage Reference can output 16 distinct voltagelevels for each range.
The equations used to calculate the output of theVoltage Reference are as follows:
if VRR = 1: VREF = (VR<3:0>/24) x VDD
if VRR = 0: VREF = (VDD x 1/4) + (VR<3:0>/32) x VDD
The setting time of the Voltage Reference must beconsidered when changing the VREF output(Table 12-2). Example 11-1 shows an example of howto configure the Voltage Reference for an output volt-age of 1.25V with VDD = 5.0V.
FIGURE 11-1: VRCON REGISTER(ADDRESS 9Fh)
FIGURE 11-2: VOLTAGE REFERENCE BLOCK DIAGRAM
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0VREN VROE VRR — VR3 VR2 VR1 VR0 R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7: VREN: VREF Enable1 = VREF circuit powered on0 = VREF circuit powered down, no IDD drain
bit 6: VROE: VREF Output Enable1 = VREF is output on RA2 pin0 = VREF is disconnected from RA2 pin
bit 5: VRR: VREF Range selection1 = Low Range0 = High Range
bit 4: Unimplemented: Read as '0'
bit 3-0: VR<3:0>: VREF value selection 0 ≤ VR [3:0] ≤ 15when VRR = 1: VREF = (VR<3:0>/ 24) * VDD
when VRR = 0: VREF = 1/4 * VDD + (VR<3:0>/ 32) * VDD
Note: R is defined in Table 12-3.
VRR8R
VR3
VR0(From VRCON<3:0>)16-1 Analog Mux
8R R R R RVREN
VREF
16 Stages
PIC16F62X
DS40300B-page 70 Preliminary 1999 Microchip Technology Inc.
EXAMPLE 11-1: VOLTAGE REFERENCE CONFIGURATION
11.2 Voltage Reference Accuracy/Error
The full range of VSS to VDD cannot be realized due tothe construction of the module. The transistors on thetop and bottom of the resistor ladder network(Figure 11-2) keep VREF from approaching VSS or VDD.The Voltage Reference is VDD derived and therefore,the VREF output changes with fluctuations in VDD. Thetested absolute accuracy of the Voltage Reference canbe found in Table 17-2.
11.3 Operation During Sleep
When the device wakes up from sleep through aninterrupt or a Watchdog Timer time-out, the contents ofthe VRCON register are not affected. To minimizecurrent consumption in SLEEP mode, the VoltageReference should be disabled.
MOVLW 0x02 ; 4 Inputs Muxed
MOVWF CMCON ; to 2 comps.
BSF STATUS,RP0 ; go to Bank 1
MOVLW 0x07 ; RA3-RA0 are
MOVWF TRISA ; outputs
MOVLW 0xA6 ; enable VREF
MOVWF VRCON ; low range
; set VR<3:0>=6
BCF STATUS,RP0 ; go to Bank 0
CALL DELAY10 ; 10µs delay
11.4 Effects of a Reset
A device reset disables the Voltage Reference by clear-ing bit VREN (VRCON<7>). This reset also disconnectsthe reference from the RA2 pin by clearing bit VROE
(VRCON<6>) and selects the high voltage range byclearing bit VRR (VRCON<5>). The VREF value selectbits, VRCON<3:0>, are also cleared.
11.5 Connection Considerations
The Voltage Reference Module operatesindependently of the comparator module. The output ofthe reference generator may be connected to the RA2pin if the TRISA<2> bit is set and the VROE bit,VRCON<6>, is set. Enabling the Voltage Referenceoutput onto the RA2 pin with an input signal present willincrease current consumption. Connecting RA2 as adigital output with VREF enabled will also increasecurrent consumption.
The RA2 pin can be used as a simple D/A output withlimited drive capability. Due to the limited drivecapability, a buffer must be used in conjunction with theVoltage Reference output for external connections toVREF. Figure 11-3 shows an example bufferingtechnique.
FIGURE 11-3: VOLTAGE REFERENCE OUTPUT BUFFER EXAMPLE
TABLE 11-1: REGISTERS ASSOCIATED WITH VOLTAGE REFERENCE
Note: - = Unimplemented, read as "0"
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value On
POR
Value OnAll OtherResets
9Fh VRCON VREN VROE VRR — VR3 VR2 VR1 VR0 000- 0000 000- 0000
1Fh CMCON C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0 0000 0000 0000 0000
85h TRISA TRISA7 TRISA6 — TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 11-1 1111 11-1 1111
VREF Output+– ••
VREF Module
Voltage Reference
Output Impedance
R(1) RA2
Note 1: R is dependent upon the Voltage Reference Configuration VRCON<3:0> and VRCON<5>.
1999 Microchip Technology Inc. Preliminary DS40300B-page 71
PIC16F62X
12.0 UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)
The Universal Synchronous Asynchronous ReceiverTransmitter (USART) module is one of the two serialI/O modules. (USART is also known as a Serial Com-munications Interface or SCI). The USART can be con-figured as a full duplex asynchronous system that cancommunicate with peripheral devices such as CRT ter-minals and personal computers, or it can be configured
as a half duplex synchronous system that can commu-nicate with peripheral devices such as A/D or D/A inte-grated circuits, Serial EEPROMs etc.
The USART can be configured in the following modes:
• Asynchronous (full duplex)
• Synchronous - Master (half duplex)• Synchronous - Slave (half duplex)
Bit SPEN (RCSTA<7>), and bits TRISB<2:1>, haveto be set in order to configure pins RB2/TX/CK andRB1/RX/DT as the Universal Synchronous Asyn-chronous Receiver Transmitter.
REGISTER 12-1: TXSTA: TRANSMIT STATUS AND CONTROL REGISTER (ADDRESS 98h)
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 R-1 R/W-0
CSRC TX9 TXEN SYNC — BRGH TRMT TX9D R = Readable bitW = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR reset
bit7 bit0
bit 7: CSRC: Clock Source Select bit
Asynchronous modeDon’t care
Synchronous mode1 = Master mode (Clock generated internally from BRG)0 = Slave mode (Clock from external source)
bit 6: TX9: 9-bit Transmit Enable bit1 = Selects 9-bit transmission0 = Selects 8-bit transmission
bit 5: TXEN: Transmit Enable bit1 = Transmit enabled0 = Transmit disabledNote: SREN/CREN overrides TXEN in SYNC mode.
bit 4: SYNC: USART Mode Select bit1 = Synchronous mode0 = Asynchronous mode
bit 3: Unimplemented: Read as '0'
bit 2: BRGH: High Baud Rate Select bit
Asynchronous mode1 = High speed0 = Low speed
Synchronous modeUnused in this mode
bit 1: TRMT: Transmit Shift Register Status bit1 = TSR empty0 = TSR full
bit 0: TX9D: 9th bit of transmit data. Can be parity bit.
PIC16F62X
DS40300B-page 72 Preliminary 1999 Microchip Technology Inc.
REGISTER 12-2: RCSTA: RECEIVE STATUS AND CONTROL REGISTER (ADDRESS 18h)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R-0 R-0 R-xSPEN RX9 SREN CREN ADEN FERR OERR RX9D R = Readable bit
W = Writable bitU = Unimplemented bit, read as ’0’-n = Value at POR resetx = unknown
bit7 bit0
bit 7: SPEN: Serial Port Enable bit(Configures RB1/RX/DT and RB2/TX/CK pins as serial port pins when bits TRISB<2:17> are set)1 = Serial port enabled 0 = Serial port disabled
bit 6: RX9: 9-bit Receive Enable bit1 = Selects 9-bit reception0 = Selects 8-bit reception
bit 5: SREN: Single Receive Enable bitAsynchronous mode:
Don’t careSynchronous mode - master:
1 = Enables single receive0 = Disables single receiveThis bit is cleared after reception is complete.
Synchronous mode - slave:Unused in this mode
bit 4: CREN: Continuous Receive Enable bitAsynchronous mode:
1 = Enables continuous receive0 = Disables continuous receive
Synchronous mode:1 = Enables continuous receive until enable bit CREN is cleared (CREN overrides SREN)0 = Disables continuous receive
bit 3: ADEN: Address Detect Enable bitAsynchronous mode 9-bit (RX9 = 1):
1 = Enables address detection, enable interrupt and load of the receive buffer when RSR<8> is set0 = Disables address detection, all bytes are received, and ninth bit can be used as parity bit
Asynchronous mode 8-bit (RX9=0):Unused in this modeSynchronous modeUnused in this mode
bit 2: FERR: Framing Error bit1 = Framing error (Can be updated by reading RCREG register and receive next valid byte)0 = No framing error
bit 1: OERR: Overrun Error bit1 = Overrun error (Can be cleared by clearing bit CREN)0 = No overrun error
bit 0: RX9D: 9th bit of received data (Can be parity bit)
1999 Microchip Technology Inc. Preliminary DS40300B-page 73
PIC16F62X
12.1 USART Baud Rate Generator (BRG)
The BRG supports both the Asynchronous and Syn-chronous modes of the USART. It is a dedicated 8-bitbaud rate generator. The SPBRG register controls theperiod of a free running 8-bit timer. In asynchronousmode bit BRGH (TXSTA<2>) also controls the baudrate. In synchronous mode bit BRGH is ignored.Table 12-1 shows the formula for computation of thebaud rate for different USART modes which only applyin master mode (internal clock).
Given the desired baud rate and Fosc, the nearest inte-ger value for the SPBRG register can be calculatedusing the formula in Table 12-1. From this, the error inbaud rate can be determined.
Example 12-1 shows the calculation of the baud rateerror for the following conditions:
FOSC = 16 MHzDesired Baud Rate = 9600BRGH = 0SYNC = 0
EXAMPLE 12-1: CALCULATING BAUD RATE ERROR
It may be advantageous to use the high baud rate(BRGH = 1) even for slower baud clocks. This isbecause the FOSC/(16(X + 1)) equation can reduce thebaud rate error in some cases.
Writing a new value to the SPBRG register, causes theBRG timer to be reset (or cleared), this ensures theBRG does not wait for a timer overflow before output-ting the new baud rate.
Desired Baud rate = Fosc / (64 (X + 1))
9600 = 16000000 /(64 (X + 1))
X = Î25.042° = 25
Calculated Baud Rate=16000000 / (64 (25 + 1))
= 9615
Error = (Calculated Baud Rate - Desired Baud Rate) Desired Baud Rate
= (9615 - 9600) / 9600
= 0.16%
TABLE 12-1: BAUD RATE FORMULA
TABLE 12-2: REGISTERS ASSOCIATED WITH BAUD RATE GENERATOR
SYNC BRGH = 0 (Low Speed) BRGH = 1 (High Speed)
01
(Asynchronous) Baud Rate = FOSC/(64(X+1))(Synchronous) Baud Rate = FOSC/(4(X+1))
Baud Rate= FOSC/(16(X+1))NA
X = value in SPBRG (0 to 255)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
PORValue on allother resets
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented read as '0'. Shaded cells are not used by the BRG.
PIC16F62X
DS40300B-page 74 Preliminary 1999 Microchip Technology Inc.
TABLE 12-3: BAUD RATES FOR SYNCHRONOUS MODE
TABLE 12-4: BAUD RATES FOR ASYNCHRONOUS MODE (BRGH = 0)
BAUDRATE
(K)
FOSC = 20 MHzSPBRGvalue
(decimal)
16 MHzSPBRGvalue
(decimal)
10 MHzSPBRGvalue
(decimal)
7.15909 MHzSPBRGvalue
(decimal)KBAUD %ERROR KBAUD %
ERROR KBAUD %ERROR KBAUD %
ERROR
0.3 NA - - NA - - NA - - NA - -1.2 NA - - NA - - NA - - NA - -2.4 NA - - NA - - NA - - NA - -9.6 NA - - NA - - 9.766 +1.73 255 9.622 +0.23 18519.2 19.53 +1.73 255 19.23 +0.16 207 19.23 +0.16 129 19.24 +0.23 9276.8 76.92 +0.16 64 76.92 +0.16 51 75.76 -1.36 32 77.82 +1.32 2296 96.15 +0.16 51 95.24 -0.79 41 96.15 +0.16 25 94.20 -1.88 18
300 294.1 -1.96 16 307.69 +2.56 12 312.5 +4.17 7 298.3 -0.57 5500 500 0 9 500 0 7 500 0 4 NA - -
HIGH 5000 - 0 4000 - 0 2500 - 0 1789.8 - 0LOW 19.53 - 255 15.625 - 255 9.766 - 255 6.991 - 255
BAUDRATE
(K)
FOSC = 5.0688 MHz 4 MHz
SPBRGvalue
(decimal)
3.579545 MHz
SPBRGvalue
(decimal)
1 MHz
SPBRGvalue
(decimal)
32.768 kHz
SPBRGvalue
(decimal)KBAUD %
ERROR
SPBRGvalue
(decimal)KBAUD %
ERRORKBAUD %
ERRORKBAUD %
ERRORKBAUD %
ERROR
0.3 NA - - NA - - NA - - NA - - 0.303 +1.14 261.2 NA - - NA - - NA - - 1.202 +0.16 207 1.170 -2.48 62.4 NA - - NA - - NA - - 2.404 +0.16 103 NA - -9.6 9.6 0 131 9.615 +0.16 103 9.622 +0.23 92 9.615 +0.16 25 NA - -19.2 19.2 0 65 19.231 +0.16 51 19.04 -0.83 46 19.24 +0.16 12 NA - -76.8 79.2 +3.13 15 76.923 +0.16 12 74.57 -2.90 11 83.34 +8.51 2 NA - -96 97.48 +1.54 12 1000 +4.17 9 99.43 +3.57 8 NA - - NA - -
300 316.8 +5.60 3 NA - - 298.3 -0.57 2 NA - - NA - -500 NA - - NA - - NA - - NA - - NA - -
HIGH 1267 - 0 100 - 0 894.9 - 0 250 - 0 8.192 - 0LOW 4.950 - 255 3.906 - 255 3.496 - 255 0.9766 - 255 0.032 - 255
BAUDRATE
(K)
FOSC = 20 MHzSPBRGvalue
(decimal)
16 MHzSPBRGvalue
(decimal)
10 MHzSPBRGvalue
(decimal)
7.15909 MHzSPBRGvalue
(decimal)KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR
0.3 NA - - NA - - NA - - NA - -1.2 1.221 +1.73 255 1.202 +0.16 207 1.202 +0.16 129 1.203 +0.23 922.4 2.404 +0.16 129 2.404 +0.16 103 2.404 +0.16 64 2.380 -0.83 469.6 9.469 -1.36 32 9.615 +0.16 25 9.766 +1.73 15 9.322 -2.90 1119.2 19.53 +1.73 15 19.23 +0.16 12 19.53 +1.73 7 18.64 -2.90 576.8 78.13 +1.73 3 83.33 +8.51 2 78.13 +1.73 1 NA - -96 104.2 +8.51 2 NA - - NA - - NA - -
300 312.5 +4.17 0 NA - - NA - - NA - -500 NA - - NA - - NA - - NA - -
HIGH 312.5 - 0 250 - 0 156.3 - 0 111.9 - 0LOW 1.221 - 255 0.977 - 255 0.6104 - 255 0.437 - 255
BAUDRATE
(K)
FOSC = 5.0688 MHz 4 MHz
SPBRGvalue
(decimal)
3.579545 MHz
SPBRGvalue
(decimal)
1 MHz
SPBRGvalue
(decimal)
32.768 kHz
SPBRGvalue
(decimal)KBAUD%
ERROR
SPBRGvalue
(decimal) KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR
0.3 0.31 +3.13 255 0.3005 -0.17 207 0.301 +0.23 185 0.300 +0.16 51 0.256 -14.67 11.2 1.2 0 65 1.202 +1.67 51 1.190 -0.83 46 1.202 +0.16 12 NA - -2.4 2.4 0 32 2.404 +1.67 25 2.432 +1.32 22 2.232 -6.99 6 NA - -9.6 9.9 +3.13 7 NA - - 9.322 -2.90 5 NA - - NA - -19.2 19.8 +3.13 3 NA - - 18.64 -2.90 2 NA - - NA - -76.8 79.2 +3.13 0 NA - - NA - - NA - - NA - -96 NA - - NA - - NA - - NA - - NA - -
300 NA - - NA - - NA - - NA - - NA - -500 NA - - NA - - NA - - NA - - NA - -
HIGH 79.2 - 0 62.500 - 0 55.93 - 0 15.63 - 0 0.512 - 0LOW 0.3094 - 255 3.906 - 255 0.2185 - 255 0.0610 - 255 0.0020 - 255
1999 Microchip Technology Inc. Preliminary DS40300B-page 75
PIC16F62X
TABLE 12-5: BAUD RATES FOR ASYNCHRONOUS MODE (BRGH = 1)
BAUDRATE
(K)
FOSC = 20 MHzSPBRGvalue
(decimal)
16 MHzSPBRGvalue
(decimal)
10 MHzSPBRGvalue
(decimal)
7.16 MHzSPBRGvalue
(decimal)KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR
9.6 9.615 +0.16 129 9.615 +0.16 103 9.615 +0.16 64 9.520 -0.83 4619.2 19.230 +0.16 64 19.230 +0.16 51 18.939 -1.36 32 19.454 +1.32 2238.4 37.878 -1.36 32 38.461 +0.16 25 39.062 +1.7 15 37.286 -2.90 1157.6 56.818 -1.36 21 58.823 +2.12 16 56.818 -1.36 10 55.930 -2.90 7115.2 113.636 -1.36 10 111.111 -3.55 8 125 +8.51 4 111.860 -2.90 3250 250 0 4 250 0 3 NA - - NA - -625 625 0 1 NA - - 625 0 0 NA - -1250 1250 0 0 NA - - NA - - NA - -
BAUDRATE
(K)
FOSC = 5.068 MHzSPBRGvalue
(decimal)
4 MHzSPBRGvalue
(decimal)
3.579 MHzSPBRGvalue
(decimal)
1 MHzSPBRGvalue
(decimal)
32.768 kHzSPBRGvalue
(decimal)KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR KBAUD%
ERROR
9.6 9.6 0 32 NA - - 9.727 +1.32 22 8.928 -6.99 6 NA - -19.2 18.645 -2.94 16 1.202 +0.17 207 18.643 -2.90 11 20.833 +8.51 2 NA - -
38.4 39.6 +3.12 7 2.403 +0.13 103 37.286 -2.90 5 31.25 -18.61 1 NA - -57.6 52.8 -8.33 5 9.615 +0.16 25 55.930 -2.90 3 62.5 +8.51 0 NA - -115.2 105.6 -8.33 2 19.231 +0.16 12 111.860 -2.90 1 NA - - NA - -250 NA - - NA - - 223.721 -10.51 0 NA - - NA - -625 NA - - NA - - NA - - NA - - NA - -1250 NA - - NA - - NA - - NA - - NA - -
PIC16F62X
DS40300B-page 76 Preliminary 1999 Microchip Technology Inc.
12.1.1 SAMPLING
The data on the RB1/RX/DT pin is sampled three timesby a majority detect circuit to determine if a high or alow level is present at the RX pin. If bit BRGH(TXSTA<2>) is clear (i.e., at the low baud rates), thesampling is done on the seventh, eighth and ninth fall-ing edges of a x16 clock (Figure 12-3). If bit BRGH isset (i.e., at the high baud rates), the sampling is doneon the 3 clock edges preceding the second rising edgeafter the first falling edge of a x4 clock (Figure 12-4 andFigure 12-5).
FIGURE 12-1: RX PIN SAMPLING SCHEME. BRGH = 0
FIGURE 12-2: RX PIN SAMPLING SCHEME, BRGH = 1
RX
baud CLK
x16 CLK
Start bit Bit0
Samples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3
Baud CLK for all but start bit(RB1/RX/DT pin)
RX pin
baud clk
x4 clk
Q2, Q4 clk
Start Bit bit0 bit1
First falling edge after RX pin goes lowSecond rising edge
Samples Samples Samples
1 2 3 4 1 2 3 4 1 2
1999 Microchip Technology Inc. Preliminary DS40300B-page 77
PIC16F62X
FIGURE 12-3: RX PIN SAMPLING SCHEME, BRGH = 1
FIGURE 12-4: RX PIN SAMPLING SCHEME, BRGH = 0 OR BRGH = 1
RX pin
Baud CLK
x4 CLK
Q2, Q4 CLK
Start Bit bit0
First falling edge after RX pin goes lowSecond rising edge
Samples
1 2 3 4
Baud CLK for all but start bit
RX
Baud CLK
x16 CLK
Start bit Bit0
Samples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3
Baud CLK for all but start bit(RB1/RX/DT pin)
PIC16F62X
DS40300B-page 78 Preliminary 1999 Microchip Technology Inc.
12.2 USART Asynchronous Mode
In this mode, the USART uses standard nonreturn-to-zero (NRZ) format (one start bit, eight or nine data bitsand one stop bit). The most common data format is8-bits. An on-chip dedicated 8-bit baud rate generatorcan be used to derive standard baud rate frequenciesfrom the oscillator. The USART transmits and receivesthe LSb first. The USART’s transmitter and receiver arefunctionally independent but use the same data formatand baud rate. The baud rate generator produces aclock either x16 or x64 of the bit shift rate, dependingon bit BRGH (TXSTA<2>). Parity is not supported bythe hardware, but can be implemented in software (andstored as the ninth data bit). Asynchronous mode isstopped during SLEEP.
Asynchronous mode is selected by clearing bit SYNC(TXSTA<4>).
The USART Asynchronous module consists of the fol-lowing important elements:
• Baud Rate Generator
• Sampling Circuit• Asynchronous Transmitter• Asynchronous Receiver
12.2.1 USART ASYNCHRONOUS TRANSMITTER
The USART transmitter block diagram is shown inFigure 12-5. The heart of the transmitter is the transmit(serial) shift register (TSR). The shift register obtains itsdata from the read/write transmit buffer, TXREG. TheTXREG register is loaded with data in software. TheTSR register is not loaded until the STOP bit has beentransmitted from the previous load. As soon as theSTOP bit is transmitted, the TSR is loaded with newdata from the TXREG register (if available). Once theTXREG register transfers the data to the TSR register(occurs in one TCY), the TXREG register is empty andflag bit TXIF (PIR1<4>) is set. This interrupt can beenabled/disabled by setting/clearing enable bit TXIE( PIE1<4>). Flag bit TXIF will be set regardless of the
state of enable bit TXIE and cannot be cleared in soft-ware. It will reset only when new data is loaded into theTXREG register. While flag bit TXIF indicated the sta-tus of the TXREG register, another bit TRMT(TXSTA<1>) shows the status of the TSR register. Sta-tus bit TRMT is a read only bit which is set when theTSR register is empty. No interrupt logic is tied to thisbit, so the user has to poll this bit in order to determineif the TSR register is empty.
Transmission is enabled by setting enable bit TXEN(TXSTA<5>). The actual transmission will not occuruntil the TXREG register has been loaded with dataand the baud rate generator (BRG) has produced ashift clock (Figure 12-5). The transmission can also bestarted by first loading the TXREG register and thensetting enable bit TXEN. Normally when transmissionis first started, the TSR register is empty, so a transferto the TXREG register will result in an immediate trans-fer to TSR resulting in an empty TXREG. A back-to-back transfer is thus possible (Figure 12-7). Clearingenable bit TXEN during a transmission will cause thetransmission to be aborted and will reset the transmit-ter. As a result the RB2/TX/CK pin will revert to hi-impedance.
In order to select 9-bit transmission, transmit bit TX9(TXSTA<6>) should be set and the ninth bit should bewritten to TX9D (TXSTA<0>). The ninth bit must bewritten before writing the 8-bit data to the TXREG reg-ister. This is because a data write to the TXREG regis-ter can result in an immediate transfer of the data to theTSR register (if the TSR is empty). In such a case, anincorrect ninth data bit maybe loaded in the TSR regis-ter.
Note 1: The TSR register is not mapped in datamemory so it is not available to the user.
Note 2: Flag bit TXIF is set when enable bit TXENis set.
FIGURE 12-5: USART TRANSMIT BLOCK DIAGRAM
TXIFTXIE
Interrupt
TXEN Baud Rate CLK
SPBRG
Baud Rate Generator
TX9D
MSb LSb
Data Bus
TXREG register
TSR register
(8) 0
TX9
TRMT SPEN
RB2/TX/CK pin
Pin Bufferand Control
8
• • •
1999 Microchip Technology Inc. Preliminary DS40300B-page 79
PIC16F62X
Steps to follow when setting up an AsynchronousTransmission:
1. Initialize the SPBRG register for the appropriatebaud rate. If a high speed baud rate is desired,set bit BRGH. (Section 12.1)
2. Enable the asynchronous serial port by clearingbit SYNC and setting bit SPEN.
3. If interrupts are desired, then set enable bitTXIE.
4. If 9-bit transmission is desired, then set transmitbit TX9.
5. Enable the transmission by setting bit TXEN,which will also set bit TXIF.
6. If 9-bit transmission is selected, the ninth bitshould be loaded in bit TX9D.
7. Load data to the TXREG register (starts trans-mission).
FIGURE 12-6: ASYNCHRONOUS MASTER TRANSMISSION
FIGURE 12-7: ASYNCHRONOUS MASTER TRANSMISSION (BACK TO BACK)
TABLE 12-6: REGISTERS ASSOCIATED WITH ASYNCHRONOUS TRANSMISSION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onall otherResets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
19h TXREG USART Transmit Register 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented locations read as '0'. Shaded cells are not used for Asynchronous Transmission.
WORD 1Stop Bit
WORD 1Transmit Shift Reg
Start Bit Bit 0 Bit 1 Bit 7/8
Write to TXREGWord 1
BRG output(shift clock)
RB2/TX/CK (pin)
TXIF bit(Transmit bufferreg. empty flag)
TRMT bit(Transmit shiftreg. empty flag)
Transmit Shift Reg.
Write to TXREG
BRG output(shift clock)
RB2/TX/CK (pin)
TXIF bit(interrupt reg. flag)
TRMT bit(Transmit shiftreg. empty flag)
Word 1 Word 2
WORD 1 WORD 2
Start Bit Stop Bit Start Bit
Transmit Shift Reg.
WORD 1 WORD 2Bit 0 Bit 1 Bit 7/8 Bit 0
Note: This timing diagram shows two consecutive transmissions.
PIC16F62X
DS40300B-page 80 Preliminary 1999 Microchip Technology Inc.
12.2.2 USART ASYNCHRONOUS RECEIVER
The receiver block diagram is shown in Figure 12-8.The data is received on the RB1/RX/DT pin and drivesthe data recovery block. The data recovery block isactually a high speed shifter operating at x16 times thebaud rate, whereas the main receive serial shifter oper-ates at the bit rate or at FOSC.
Once Asynchronous mode is selected, reception isenabled by setting bit CREN (RCSTA<4>).
The heart of the receiver is the receive (serial) shift reg-ister (RSR). After sampling the STOP bit, the receiveddata in the RSR is transferred to the RCREG register (ifit is empty). If the transfer is complete, flag bit RCIF(PIR1<5>) is set. The actual interrupt can be enabled/disabled by setting/clearing enable bit RCIE (PIE1<5>).Flag bit RCIF is a read only bit which is cleared by thehardware. It is cleared when the RCREG register hasbeen read and is empty. The RCREG is a double buff-
ered register, i.e. it is a two deep FIFO. It is possible fortwo bytes of data to be received and transferred to theRCREG FIFO and a third byte begin shifting to the RSRregister. On the detection of the STOP bit of the thirdbyte, if the RCREG register is still full then overrun errorbit OERR (RCSTA<1>) will be set. The word in the RSRwill be lost. The RCREG register can be read twice toretrieve the two bytes in the FIFO. Overrun bit OERRhas to be cleared in software. This is done by resettingthe receive logic (CREN is cleared and then set). If bitOERR is set, transfers from the RSR register to theRCREG register are inhibited, so it is essential to clearerror bit OERR if it is set. Framing error bit FERR(RCSTA<2>) is set if a stop bit is detected as clear. BitFERR and the 9th receive bit are buffered the sameway as the receive data. Reading the RCREG, will loadbits RX9D and FERR with new values, therefore it isessential for the user to read the RCSTA register beforereading RCREG register in order not to lose the oldFERR and RX9D information.
FIGURE 12-8: USART RECEIVE BLOCK DIAGRAM
x64 Baud Rate CLK
SPBRG
Baud Rate Generator
RB1/RX/DT
Pin Bufferand Control
SPEN
DataRecovery
CRENOERR FERR
RSR registerMSb LSb
RX9D RCREG registerFIFO
Interrupt RCIF
RCIE
Data Bus
8
÷ 64
÷ 16or
Stop Start(8) 7 1 0
RX9
• • •
RX9
ADEN
RX9ADEN
RSR<8>
EnableLoad of
ReceiveBuffer
8
8
RCREG registerRX9D
1999 Microchip Technology Inc. Preliminary DS40300B-page 81
PIC16F62X
FIGURE 12-9: ASYNCHRONOUS RECEPTION WITH ADDRESS DETECT
FIGURE 12-10: ASYNCHRONOUS RECEPTION WITH ADDRESS BYTE FIRST
FIGURE 12-11: ASYNCHRONOUS RECEPTION WITH ADDRESS BYTE FIRST FOLLOWED BY VALID DATA BYTE
Startbit bit1bit0 bit8 bit0Stop
bit
Startbit bit8 Stop
bit
RC7/RX/DT (pin)
Rcv buffer reg
Rcv shift reg
Read Rcvbuffer regRCREG
RCIF(interrupt flag)
WORD 1RCREG
Note: This timing diagram shows a data byte followed by an address byte. The data byte is not read into the RCREG (receive buffer)
Bit8 = 0, Data Byte Bit8 = 1, Address Byte
because ADEN = 1 and bit8 = 0.
ADEN = 1(address match enable)
’1’ ’1’
Startbit bit1bit0 bit8 bit0Stop
bit
Startbit bit8 Stop
bit
RC7/RX/DT (pin)
regRcv buffer reg
Rcv shift
Read Rcvbuffer regRCREG
RCIF(interrupt flag)
WORD 1RCREG
Bit8 = 1, Address Byte Bit8 = 0, Data Byte
Note: This timing diagram shows an address byte followed by an data byte. The data byte is not read into the RCREG (receive buffer) because ADEN was not updated (still = 1) and bit8 = 0.
ADEN = 1(address match enable)
’1’ ’1’
Startbit bit1bit0 bit8 bit0Stop
bit
Startbit bit8 Stop
bit
RC7/RX/DT (pin)
regRcv buffer reg
Rcv shift
Read Rcvbuffer regRCREG
RCIF(interrupt flag)
WORD 2RCREG
Bit8 = 1, Address Byte Bit8 = 0, Data Byte
Note: This timing diagram shows an address byte followed by an data byte. The data byte is read into the RCREG (receive buffer) because ADEN was updated after an address match, and was cleared to a ‘0’, so the contents of the receive shift register (RSR) are read into the receive buffer regardless of the value of bit8.
ADEN(address match enable)
WORD 1RCREG
PIC16F62X
DS40300B-page 82 Preliminary 1999 Microchip Technology Inc.
Steps to follow when setting up an AsynchronousReception:
1. Initialize the SPBRG register for the appropriatebaud rate. If a high speed baud rate is desired,set bit BRGH. (Section 12.1).
2. Enable the asynchronous serial port by clearingbit SYNC, and setting bit SPEN.
3. If interrupts are desired, then set enable bitRCIE.
4. If 9-bit reception is desired, then set bit RX9.
5. Enable the reception by setting bit CREN.
6. Flag bit RCIF will be set when reception is com-plete and an interrupt will be generated if enablebit RCIE was set.
7. Read the RCSTA register to get the ninth bit (ifenabled) and determine if any error occurredduring reception.
8. Read the 8-bit received data by reading theRCREG register.
9. If any error occurred, clear the error by clearingenable bit CREN.
TABLE 12-7: REGISTERS ASSOCIATED WITH ASYNCHRONOUS RECEPTION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onall otherResets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
1Ah RCREG USART Receive Register 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented locations read as '0'. Shaded cells are not used for Asynchronous Reception.
1999 Microchip Technology Inc. Preliminary DS40300B-page 83
PIC16F62X
12.3 USART Function
The USART function is similar to that on thePIC16C74B, which includes the BRGH = 1 fix.
12.3.1 USART 9-BIT RECEIVER WITH ADDRESS DETECT
When the RX9 bit is set in the RCSTA register, 9-bitsare received and the ninth bit is placed in the RX9D bitof the RCSTA register. The USART module has a spe-cial provision for multi-processor communication. Mul-tiprocessor communication is enabled by setting theADEN bit (RCSTA<3>) along with the RX9 bit. The portis now programmed such that when the last bit isreceived, the contents of the receive shift register(RSR) are transferred to the receive buffer, the ninth bitof the RSR (RSR<8>) is transferred to RX9D, and thereceive interrupt is set if and only if RSR<8> = 1. Thisfeature can be used in a multi-processor system as fol-lows:
A master processor intends to transmit a block of datato one of many slaves. It must first send out an addressbyte that identifies the target slave. An address byte isidentified by setting the ninth bit (RSR<8>) to a ’1’(instead of a ’0’ for a data byte). If the ADEN and RX9bits are set in the slave’s RCSTA register, enabling mul-tiprocessor communication, all data bytes will beignored. However, if the ninth received bit is equal to a‘1’, indicating that the received byte is an address, theslave will be interrupted and the contents of the RSRregister will be transferred into the receive buffer. Thisallows the slave to be interrupted only by addresses, sothat the slave can examine the received byte to see if itis being addressed. The addressed slave will thenclear its ADEN bit and prepare to receive data bytesfrom the master.
When ADEN is enabled (='1'), all data bytes areignored. Following the STOP bit, the data will not beloaded into the receive buffer, and no interrupt willoccur. If another byte is shifted into the RSR register,the previous data byte will be lost.
The ADEN bit will only take effect when the receiver isconfigured in 9-bit mode (RX9 = '1'). When ADEN isdisabled (='0'), all data bytes are received and the 9thbit can be used as the parity bit.
The receive block diagram is shown in Figure 12-8.
Reception is enabled by setting bit CREN (RCSTA<4>).
12.3.1.1 SETTING UP 9-BIT MODE WITH ADDRESS DETECT
Steps to follow when setting up an Asynchronous orSynchronous Reception with Address Detect Enabled:
1. Initialize the SPBRG register for the appropriatebaud rate. If a high speed baud rate is desired,set bit BRGH.
2. Enable asynchronous or synchronous commu-nication by setting or clearing bit SYNC and set-ting bit SPEN.
3. If interrupts are desired, then set enable bitRCIE.
4. Set bit RX9 to enable 9-bit reception.5. Set ADEN to enable address detect.
6. Enable the reception by setting enable bit CRENor SREN.
7. Flag bit RCIF will be set when reception is com-plete, and an interrupt will be generated ifenable bit RCIE was set.
8. Read the 8-bit received data by reading theRCREG register to determine if the device isbeing addressed.
9. If any error occurred, clear the error by clearingenable bit CREN if it was already set.
10. If the device has been addressed (RSR<8> = 1with address match enabled), clear the ADENand RCIF bits to allow data bytes and addressbytes to be read into the receive buffer and inter-rupt the CPU.
PIC16F62X
DS40300B-page 84 Preliminary 1999 Microchip Technology Inc.
TABLE 12-1: REGISTERS ASSOCIATED WITH ASYNCHRONOUS RECEPTION
Addr Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
POR
Value onall otherResets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
1Ah RCREG RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented locations read as '0'. Shaded cells are not used for Asynchronous Reception.
12.4 USART Synchronous Master Mode
In Synchronous Master mode, the data is transmitted ina half-duplex manner, i.e. transmission and receptiondo not occur at the same time. When transmitting data,the reception is inhibited and vice versa. Synchronousmode is entered by setting bit SYNC (TXSTA<4>). Inaddition enable bit SPEN (RCSTA<7>) is set in order toconfigure the RB2/TX/CK and RB1/RX/DT I/O pins toCK (clock) and DT (data) lines respectively. The Mastermode indicates that the processor transmits the masterclock on the CK line. The Master mode is entered bysetting bit CSRC (TXSTA<7>).
12.4.1 USART SYNCHRONOUS MASTER TRANSMISSION
The USART transmitter block diagram is shown inFigure 12-5. The heart of the transmitter is the transmit(serial) shift register (TSR). The shift register obtains itsdata from the read/write transmit buffer registerTXREG. The TXREG register is loaded with data insoftware. The TSR register is not loaded until the lastbit has been transmitted from the previous load. Assoon as the last bit is transmitted, the TSR is loadedwith new data from the TXREG (if available). Once theTXREG register transfers the data to the TSR register(occurs in one Tcycle), the TXREG is empty and inter-rupt bit, TXIF (PIR1<4>) is set. The interrupt can beenabled/disabled by setting/clearing enable bit TXIE(PIE1<4>). Flag bit TXIF will be set regardless of thestate of enable bit TXIE and cannot be cleared in soft-ware. It will reset only when new data is loaded into theTXREG register. While flag bit TXIF indicates the statusof the TXREG register, another bit TRMT (TXSTA<1>)shows the status of the TSR register. TRMT is a readonly bit which is set when the TSR is empty. No inter-rupt logic is tied to this bit, so the user has to poll thisbit in order to determine if the TSR register is empty.The TSR is not mapped in data memory so it is notavailable to the user.
Transmission is enabled by setting enable bit TXEN(TXSTA<5>). The actual transmission will not occuruntil the TXREG register has been loaded with data.The first data bit will be shifted out on the next availablerising edge of the clock on the CK line. Data out is sta-
ble around the falling edge of the synchronous clock(Figure 12-12). The transmission can also be startedby first loading the TXREG register and then setting bitTXEN (Figure 12-13). This is advantageous when slowbaud rates are selected, since the BRG is kept in resetwhen bits TXEN, CREN, and SREN are clear. Settingenable bit TXEN will start the BRG, creating a shiftclock immediately. Normally when transmission is firststarted, the TSR register is empty, so a transfer to theTXREG register will result in an immediate transfer toTSR resulting in an empty TXREG. Back-to-back trans-fers are possible.
Clearing enable bit TXEN, during a transmission, willcause the transmission to be aborted and will reset thetransmitter. The DT and CK pins will revert to hi-imped-ance. If either bit CREN or bit SREN is set, during atransmission, the transmission is aborted and the DTpin reverts to a hi-impedance state (for a reception).The CK pin will remain an output if bit CSRC is set(internal clock). The transmitter logic however is notreset although it is disconnected from the pins. In orderto reset the transmitter, the user has to clear bit TXEN.If bit SREN is set (to interrupt an on-going transmissionand receive a single word), then after the single word isreceived, bit SREN will be cleared and the serial portwill revert back to transmitting since bit TXEN is still set.The DT line will immediately switch from hi-impedancereceive mode to transmit and start driving. To avoidthis, bit TXEN should be cleared.
In order to select 9-bit transmission, the TX9(TXSTA<6>) bit should be set and the ninth bit shouldbe written to bit TX9D (TXSTA<0>). The ninth bit mustbe written before writing the 8-bit data to the TXREGregister. This is because a data write to the TXREG canresult in an immediate transfer of the data to the TSRregister (if the TSR is empty). If the TSR was empty andthe TXREG was written before writing the “new” TX9D,the “present” value of bit TX9D is loaded.
1999 Microchip Technology Inc. Preliminary DS40300B-page 85
PIC16F62X
Steps to follow when setting up a Synchronous MasterTransmission:
1. Initialize the SPBRG register for the appropriatebaud rate (Section 12.1).
2. Enable the synchronous master serial port bysetting bits SYNC, SPEN, and CSRC.
3. If interrupts are desired, then set enable bitTXIE.
4. If 9-bit transmission is desired, then set bit TX9.5. Enable the transmission by setting bit TXEN.
6. If 9-bit transmission is selected, the ninth bitshould be loaded in bit TX9D.
7. Start transmission by loading data to theTXREG register.
TABLE 12-2: REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER TRANSMISSION
FIGURE 12-12: SYNCHRONOUS TRANSMISSION
FIGURE 12-13: SYNCHRONOUS TRANSMISSION (THROUGH TXEN)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
PORValue on all
other Resets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
19h TXREG USART Transmit Register 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Master Transmission.
Bit 0 Bit 1 Bit 7
WORD 1
Q1Q2 Q3Q4 Q1 Q2Q3 Q4Q1 Q2Q3 Q4Q1 Q2Q3 Q4Q1 Q2 Q3Q4 Q3Q4 Q1Q2 Q3Q4 Q1Q2 Q3Q4 Q1Q2 Q3 Q4Q1 Q2Q3 Q4Q1 Q2Q3 Q4Q1 Q2Q3 Q4
Bit 2 Bit 0 Bit 1 Bit 7RB1/RX/DT pin
RB2/TX/CK pin
Write toTXREG reg
TXIF bit(Interrupt flag)
TRMT
TXEN bit’1’ ’1’
Note: Sync master mode; SPBRG = ’0’. Continuous transmission of two 8-bit words
WORD 2
TRMT bit
Write word1 Write word2
RB1/RX/DT pin
RB2/TX/CK pin
Write toTXREG reg
TXIF bit
TRMT bit
bit0 bit1 bit2 bit6 bit7
TXEN bit
PIC16F62X
DS40300B-page 86 Preliminary 1999 Microchip Technology Inc.
12.4.2 USART SYNCHRONOUS MASTER RECEPTION
Once Synchronous mode is selected, reception isenabled by setting either enable bit SREN (RCSTA<5>)or enable bit CREN (RCSTA<4>). Data is sampled onthe RB1/RX/DT pin on the falling edge of the clock. Ifenable bit SREN is set, then only a single word isreceived. If enable bit CREN is set, the reception iscontinuous until CREN is cleared. If both bits are setthen CREN takes precedence. After clocking the lastbit, the received data in the Receive Shift Register(RSR) is transferred to the RCREG register (if it isempty). When the transfer is complete, interrupt flag bitRCIF (PIR1<5>) is set. The actual interrupt can beenabled/disabled by setting/clearing enable bit RCIE(PIE1<5>). Flag bit RCIF is a read only bit which isreset by the hardware. In this case it is reset when theRCREG register has been read and is empty. TheRCREG is a double buffered register, i.e. it is a twodeep FIFO. It is possible for two bytes of data to bereceived and transferred to the RCREG FIFO and athird byte to begin shifting into the RSR register. On theclocking of the last bit of the third byte, if the RCREGregister is still full then overrun error bit OERR(RCSTA<1>) is set. The word in the RSR will be lost.The RCREG register can be read twice to retrieve thetwo bytes in the FIFO. Bit OERR has to be cleared insoftware (by clearing bit CREN). If bit OERR is set,transfers from the RSR to the RCREG are inhibited, soit is essential to clear bit OERR if it is set. The 9th
receive bit is buffered the same way as the receivedata. Reading the RCREG register, will load bit RX9Dwith a new value, therefore it is essential for the user toread the RCSTA register before reading RCREG inorder not to lose the old RX9D information.
Steps to follow when setting up a Synchronous MasterReception:
1. Initialize the SPBRG register for the appropriatebaud rate. (Section 12.1)
2. Enable the synchronous master serial port bysetting bits SYNC, SPEN, and CSRC.
3. Ensure bits CREN and SREN are clear.
4. If interrupts are desired, then set enable bitRCIE.
5. If 9-bit reception is desired, then set bit RX9.6. If a single reception is required, set bit SREN.
For continuous reception set bit CREN.7. Interrupt flag bit RCIF will be set when reception
is complete and an interrupt will be generated ifenable bit RCIE was set.
8. Read the RCSTA register to get the ninth bit (ifenabled) and determine if any error occurredduring reception.
9. Read the 8-bit received data by reading theRCREG register.
10. If any error occurred, clear the error by clearingbit CREN.
TABLE 12-3: REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER RECEPTION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on:
PORValue on all other Resets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
1Ah RCREG USART Receive Register 0000 0000 0000 0000
8Ch PIE1 EEPIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE -000 0000 -000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented read as '0'. Shaded cells are not used for Synchronous Master Reception.
1999 Microchip Technology Inc. Preliminary DS40300B-page 87
PIC16F62X
FIGURE 12-14: SYNCHRONOUS RECEPTION (MASTER MODE, SREN)
CREN bit
RB1/RX/DT pin
RB2/TX/CK pin
Write tobit SREN
SREN bit
RCIF bit(interrupt)
Read RXREG
Note: Timing diagram demonstrates SYNC master mode with bit SREN = ’1’ and bit BRG = ’0’.
Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4Q2 Q1 Q2 Q3 Q4Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
’0’
bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7
’0’
Q1 Q2 Q3 Q4
PIC16F62X
DS40300B-page 88 Preliminary 1999 Microchip Technology Inc.
12.5 USART Synchronous Slave Mode
Synchronous slave mode differs from the Master modein the fact that the shift clock is supplied externally atthe RB2/TX/CK pin (instead of being supplied internallyin master mode). This allows the device to transfer orreceive data while in SLEEP mode. Slave mode isentered by clearing bit CSRC (TXSTA<7>).
12.5.1 USART SYNCHRONOUS SLAVE TRANSMIT
The operation of the synchronous master and slavemodes are identical except in the case of the SLEEPmode.
If two words are written to the TXREG and then theSLEEP instruction is executed, the following will occur:
a) The first word will immediately transfer to theTSR register and transmit.
b) The second word will remain in TXREG register. c) Flag bit TXIF will not be set. d) When the first word has been shifted out of TSR,
the TXREG register will transfer the secondword to the TSR and flag bit TXIF will now beset.
e) If enable bit TXIE is set, the interrupt will wakethe chip from SLEEP and if the global interruptis enabled, the program will branch to the inter-rupt vector (0004h).
Steps to follow when setting up a Synchronous SlaveTransmission:
1. Enable the synchronous slave serial port by set-ting bits SYNC and SPEN and clearing bitCSRC.
2. Clear bits CREN and SREN.3. If interrupts are desired, then set enable bit
TXIE.4. If 9-bit transmission is desired, then set bit TX9.
5. Enable the transmission by setting enable bitTXEN.
6. If 9-bit transmission is selected, the ninth bitshould be loaded in bit TX9D.
7. Start transmission by loading data to theTXREG register.
12.5.2 USART SYNCHRONOUS SLAVE RECEPTION
The operation of the synchronous master and slavemodes is identical except in the case of the SLEEPmode. Also, bit SREN is a don’t care in slave mode.
If receive is enabled, by setting bit CREN, prior to theSLEEP instruction, then a word may be received duringSLEEP. On completely receiving the word, the RSRregister will transfer the data to the RCREG registerand if enable bit RCIE bit is set, the interrupt generatedwill wake the chip from SLEEP. If the global interrupt isenabled, the program will branch to the interrupt vector(0004h).
Steps to follow when setting up a Synchronous SlaveReception:
1. Enable the synchronous master serial port bysetting bits SYNC and SPEN and clearing bitCSRC.
2. If interrupts are desired, then set enable bitRCIE.
3. If 9-bit reception is desired, then set bit RX9.
4. To enable reception, set enable bit CREN.5. Flag bit RCIF will be set when reception is com-
plete and an interrupt will be generated, ifenable bit RCIE was set.
6. Read the RCSTA register to get the ninth bit (ifenabled) and determine if any error occurredduring reception.
7. Read the 8-bit received data by reading theRCREG register.
8. If any error occurred, clear the error by clearingbit CREN.
1999 Microchip Technology Inc. Preliminary DS40300B-page 89
PIC16F62X
TABLE 12-4: REGISTERS ASSOCIATED WITH SYNCHRONOUS SLAVE TRANSMISSION
TABLE 12-5: REGISTERS ASSOCIATED WITH SYNCHRONOUS SLAVE RECEPTION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
PORValue on all
other Resets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
19h TXREG USART Transmit Register 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented read as '0'. Shaded cells are not used for Synchronous Slave Transmission.
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on
PORValue on all other Resets
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
18h RCSTA SPEN RX9 SREN CREN ADEN FERR OERR RX9D 0000 -00x 0000 -00x
1Ah RCREG USART Receive Register 0000 0000 0000 0000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
98h TXSTA CSRC TX9 TXEN SYNC — BRGH TRMT TX9D 0000 -010 0000 -010
99h SPBRG Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, - = unimplemented read as '0'. Shaded cells are not used for Synchronous Slave Reception.
PIC16F62X
DS40300B-page 90 Preliminary 1999 Microchip Technology Inc.
NOTES:
PIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 91
13.0 DATA EEPROM MEMORYThe EEPROM data memory is readable and writableduring normal operation (full VDD range). This memoryis not directly mapped in the register file space. Insteadit is indirectly addressed through the Special FunctionRegisters. There are four SFRs used to read and writethis memory. These registers are:
• EECON1• EECON2 (Not a physically implemented register)• EEDATA• EEADR
EEDATA holds the 8-bit data for read/write, and EEADRholds the address of the EEPROM location beingaccessed. PIC16F62X devices have 128 bytes of dataEEPROM with an address range from 0h to 7Fh.
The EEPROM data memory allows byte read and write.A byte write automatically erases the location andwrites the new data (erase before write). The EEPROMdata memory is rated for high erase/write cycles. Thewrite time is controlled by an on-chip timer. The write-time will vary with voltage and temperature as well asfrom chip to chip. Please refer to AC specifications forexact limits.
When the device is code protected, the CPU maycontinue to read and write the data EEPROM memory.The device programmer can no longer accessthis memory.
Additional information on the Data EEPROM is avail-able in the PICmicro™ Mid-Range Reference Manual,(DS33023).
REGISTER 13-1: EEADR REGISTER (ADDRESS 9Bh)
13.1 EEADR
The EEADR register can address up to a maximum of256 bytes of data EEPROM. Only the first 128 bytes ofdata EEPROM are implemented and only seven of theeight bits in the register (EEADR<6:0>) are required.
The upper bit is address decoded. This means thatthis bit should always be ’0’ to ensure that the addressis in the 128 byte memory space.
U R/W R/W R/W R/W R/W R/W R/W— EADR6 EADR5 EADR4 EADR3 EADR2 EADR1 EADR0 R = Readable bit
W = Writable bitS = Settable bitU = Unimplemented bit, read as ‘0’-n = Value at POR reset
bit7 bit0
bit 7 Unimplemented Address: Must be set to '0'
bit 6:0 EEADR: Specifies one of 128 locations for EEPROM Read/Write Operation
PIC16F62X
DS40300B-page 92 Preliminary 1999 Microchip Technology Inc.
13.2 EECON1 AND EECON2 REGISTERS
EECON1 is the control register with five low order bitsphysically implemented. The upper-three bits are non-existent and read as ’0’s.
Control bits RD and WR initiate read and write,respectively. These bits cannot be cleared, only set, insoftware. They are cleared in hardware at completionof the read or write operation. The inability to clear theWR bit in software prevents the accidental, prematuretermination of a write operation.
The WREN bit, when set, will allow a write operation.On power-up, the WREN bit is clear. The WRERR bitis set when a write operation is interrupted by a MCLRreset or a WDT time-out reset during normal opera-tion. In these situations, following reset, the user cancheck the WRERR bit and rewrite the location. Thedata and address will be unchanged in the EEDATAand EEADR registers.
Interrupt flag bit EEIF in the PIR1 register is set whenwrite is complete. This bit must be cleared in software.
EECON2 is not a physical register. Reading EECON2will read all ’0’s. The EECON2 register is usedexclusively in the Data EEPROM write sequence.
REGISTER 13-2: EECON1 REGISTER (ADDRESS 9Ch) DEVICES
U U U U R/W-x R/W-0 R/S-0 R/S-x
— — — — WRERR WREN WR RD R = Readable bitW = Writable bitS = Settable bitU = Unimplemented bit, read as ‘0’-n = Value at POR reset
bit7 bit0
bit 7:4 Unimplemented: Read as '0'
bit 3 WRERR: EEPROM Error Flag bit1 = A write operation is prematurely terminated (any MCLR reset, any WDT reset during normal operation or BOD detect)0 = The write operation completed
bit 2 WREN: EEPROM Write Enable bit1 = Allows write cycles0 = Inhibits write to the data EEPROM
bit 1 WR: Write Control bit1 = initiates a write cycle. (The bit is cleared by hardware once write is complete. The WR bit can only be set (not cleared) in software.0 = Write cycle to the data EEPROM is complete
bit 0 RD: Read Control bit1 = Initiates an EEPROM read (read takes one cycle. RD is cleared in hardware. The RD bit can only be set (not cleared) in software).0 = Does not initiate an EEPROM read
PIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 93
13.3 READING THE EEPROM DATA MEMORY
To read a data memory location, the user must writethe address to the EEADR register and then set con-trol bit RD (EECON1<0>). The data is available, in thevery next cycle, in the EEDATA register; therefore itcan be read in the next instruction. EEDATA will holdthis value until another read or until it is written to bythe user (during a write operation).
EXAMPLE 13-1: DATA EEPROM READ
BCF STATUS, RP0 ; Bank 0 MOVLW CONFIG_ADDR ; 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
13.4 WRITING TO THE EEPROM DATA MEMORY
To write an EEPROM data location, the user must firstwrite the address to the EEADR register and the datato the EEDATA register. Then the user must follow aspecific sequence to initiate the write for each byte.
EXAMPLE 13-2: DATA EEPROM WRITE
BSF STATUS, RP0 ; Bank 1 BSF EECON1, WREN ; Enable write BCF INTCON, GIE ; Disable INTs. MOVLW 55h ; MOVWF EECON2 ; Write 55h MOVLW AAh ; MOVWF EECON2 ; Write AAh BSF EECON1,WR ; Set WR bit ; begin write BSF INTCON, GIE ; Enable INTs.
The write will not initiate if the above sequence is notexactly followed (write 55h to EECON2, write AAh toEECON2, then set WR bit) for each byte. We stronglyrecommend that interrupts be disabled during thiscode segment. A cycle count is executed during therequired sequence. Any number what is not equal tothe required cycles to execute the required sequencewill cause the data not to be written into the EEPROM.
Additionally, the WREN bit in EECON1 must be set toenable write. This mechanism prevents accidentalwrites to data EEPROM due to errant (unexpected)code execution (i.e., lost programs). The user shouldkeep the WREN bit clear at all times, except whenupdating EEPROM. The WREN bit is not clearedby hardware
After a write sequence has been initiated, clearing theWREN bit will not affect this write cycle. The WR bitwill be inhibited from being set unless the WREN bit isset.
At the completion of the write cycle, the WR bit iscleared in hardware and the EE Write CompleteInterrupt Flag bit (EEIF) is set. The user can eitherenable this interrupt or poll this bit. The EEIF bit in thePIR1 registers must be cleared by software.
13.5 WRITE VERIFY
Depending on the application, good programmingpractice may dictate that the value written to the DataEEPROM should be verified (Example 13-3) to thedesired value to be written. This should be used inapplications where an EEPROM bit will be stressednear the specification limit.
EXAMPLE 13-3: WRITE VERIFY
BCF STATUS, RP0 ; Bank 0 : ; Any code can go here : ; MOVF EEDATA, W ; Must be in Bank 0 BSF STATUS, RP0 ; Bank 1 READ BSF EECON1, RD ; YES, Read the ; value written BCF STATUS, RP0 ; Bank 0 ; ; Is the value written (in W reg) and ; read (in EEDATA) the same? ; SUBWF EEDATA, W ; BTFSS STATUS, Z ; Is difference 0? GOTO WRITE_ERR ; NO, Write error : ; YES, Good write : ; Continue program
13.6 PROTECTION AGAINST SPURIOUS WRITE
There are conditions when the device may not want towrite to the data EEPROM memory. To protect againstspurious EEPROM writes, various mechanisms havebeen built in. On power-up, WREN is cleared. Also,the Power-up Timer (72 ms duration) preventsEEPROM write.
The write initiate sequence and the WREN bit togetherhelp prevent an accidental write during brown-out,power glitch, or software malfunction.
13.7 DATA EEPROM OPERATION DURING CODE PROTECT
When the device is code protected, the CPU is able toread and write unscrambled data to the DataEEPROM.
Req
uire
dS
eque
nce
PIC16F62X
DS40300B-page 94 Preliminary 1999 Microchip Technology Inc.
TABLE 13-1 REGISTERS/BITS ASSOCIATED WITH DATA EEPROM
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on Power-on
Reset
Value on all other resets
9Ah EEDATA EEPROM data register xxxx xxxx uuuu uuuu
9Bh EEADR EEPROM address register xxxx xxxx uuuu uuuu
9Ch EECON1 — — — — WRERR WREN WR RD ---- x000 ---- q000
9Dh EECON2(1) EEPROM control register 2 ---- ---- ---- ----
Legend: x = unknown, u = unchanged, - = unimplemented read as ’0’, q = value depends upon condition. Shaded cells are not used by data EEPROM.
Note 1: EECON2 is not a physical register
1999 Microchip Technology Inc. Preliminary DS40300B-page 95
PIC16F62X
14.0 SPECIAL FEATURES OF THE CPU
Special circuits to deal with the needs of real time appli-cations are what sets a microcontroller apart from otherprocessors. The PIC16F62X family has a host of suchfeatures intended to maximize system reliability, mini-mize cost through elimination of external components,provide power saving operating modes and offer codeprotection.
These are:
1. OSC selection2. Reset
Power-on Reset (POR)Power-up Timer (PWRT)Oscillator Start-Up Timer (OST)Brown-out Reset (BOD)
3. Interrupts4. Watchdog Timer (WDT)5. SLEEP
6. Code protection7. ID Locations8. In-circuit serial programming
The PIC16F62X has a Watchdog Timer which iscontrolled by configuration bits. It runs off its own RCoscillator for added reliability. There are two timers thatoffer necessary delays on power-up. One is theOscillator Start-up Timer (OST), intended to keep thechip in reset until the crystal oscillator is stable. Theother is the Power-up Timer (PWRT), which provides afixed delay of 72 ms (nominal) on power-up only,designed to keep the part in reset while the powersupply stabilizes. There is also circuitry to reset thedevice if a brown-out occurs which provides at least a72 ms reset. With these three functions on-chip, mostapplications need no external reset circuitry.
The SLEEP mode is designed to offer a very lowcurrent power-down mode. The user can wake-up fromSLEEP through external reset, Watchdog Timerwake-up or through an interrupt. Several oscillatoroptions are also made available to allow the part to fitthe application. The ER oscillator option saves systemcost while the LP crystal option saves power. A set ofconfiguration bits are used to select various options.
PIC16F62X
DS40300B-page 96 Preliminary 1999 Microchip Technology Inc.
14.1 Configuration Bits
The configuration bits can be programmed (read as ’0’)or left unprogrammed (read as ’1’) to select variousdevice configurations. These bits are mapped inprogram memory location 2007h.
The user will note that address 2007h is beyond the user program memory space. In fact, it belongsto the special configuration memory space (2000h– 3FFFh), which can be accessed only during program-ming.
FIGURE 14-1: CONFIGURATION WORD
CP1 CP0 CP1 CP0 - CPD LVP BODEN MCLRE FOSC2 PWRTE WDTE F0SC1 F0SC0 Register:CONFIGAddress2007hbit13 bit0
bit 13-10:CP1:CP0: Code Protection bits (2)
Code protection for 2K program memory11 = Program memory code protection off10 = 0400h-07FFh code protected01 = 0200h-07FFh code protected00 = 0000h-07FFhcode protectedCode protection for 1K program memory11 = Program memory code protection off10 = Program memory code protection off01 = 0200h-03FFh code protected00 = 0000h-03FFh code protected
bit 8: CPD: Data Code Protection bit(3)
1 = Data memory code protection off0 = Data memory code protected
bit 7: LVP: Low Voltage Programming Enable1 = RB4/PGM pin has PGM function, low voltage programming enabled0 = RB4/PGM is digital I/O, HV on MCLR must be used for programming
bit 6: BODEN: Brown-out Detect Enable bit (1)
1 = BOD enabled0 = BOD disabled
bit 5: MCLRE: RA5/MCLR pin function select1 = RA5/MCLR pin function is MCLR 0 = RA5/MCLR pin function is digital I/O, MCLR internally tied to VDD
bit 3: PWRTE: Power-up Timer Enable bit (1)
1 = PWRT disabled0 = PWRT enabled
bit 2: WDTE: Watchdog Timer Enable bit1 = WDT enabled0 = WDT disabled
bit 4,1-0:FOSC2:FOSC0: Oscillator Selection bits(4)
111 = ER oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN110 = ER oscillator: I/O function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN101 = INTRC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN100 = INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN011 = EC: I/O function on RA6/OSC2/CLKOUT pin, CLKIN on RA7/OSC1/CLKIN010 = HS oscillator: High speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN001 = XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN000 = LP oscillator: Low power crystal on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
Note 1: Enabling Brown-out Reset automatically enables Power-up Timer (PWRT) regardless of the value of bit PWRTE. Ensure the Power-up Timer is enabled anytime Brown-out Reset is enabled.
2: All of the CP1:CP0 pairs have to be given the same value to enable the code protection scheme listed.3: The entire data EEPROM will be erased when the code protection is turned off. 4: When MCLR is asserted in INTRC or ER mode, the internal clock oscillator is disabled.
1999 Microchip Technology Inc. Preliminary DS40300B-page 97
PIC16F62X
14.2 Oscillator Configurations
14.2.1 OSCILLATOR TYPES
The PIC16F62X can be operated in eight differentoscillator options. The user can program threeconfiguration bits (FOSC2 thru FOSC0) to select one ofthese eight modes:
• LP Low Power Crystal• XT Crystal/Resonator
• HS High Speed Crystal/Resonator• ER External Resistor (2 modes)• INTRC Internal Resistor/Capacitor (2 modes)
• EC External Clock In
14.2.2 CRYSTAL OSCILLATOR / CERAMIC RESONATORS
In XT, LP or HS modes a crystal or ceramic resonatoris connected to the OSC1 and OSC2 pins to establishoscillation (Figure 14-2). The PIC16F62X oscillatordesign requires the use of a parallel cut crystal. Use ofa series cut crystal may give a frequency out of thecrystal manufacturers specifications. When in XT, LP orHS modes, the device can have an external clocksource to drive the OSC1 pin (Figure 14-3).
FIGURE 14-2: CRYSTAL OPERATION (OR CERAMIC RESONATOR) (HS, XT OR LP OSC CONFIGURATION)
FIGURE 14-3: EXTERNAL CLOCK INPUT OPERATION (HS, XT OR LP OSC CONFIGURATION)
See Table 14-1 and Table 14-2 for recommended values of C1 and C2.
Note: A series resistor may be required for AT strip cut crystals.
C1
C2
XTAL
OSC2
RS
OSC1
RFSLEEP
To internal logic
PIC16F62Xsee Note
Clock fromext. system
PIC16F62X
OSC1
OSC2Open
TABLE 14-1: CAPACITOR SELECTION FOR CERAMIC RESONATORS
TABLE 14-2: CAPACITOR SELECTION FOR CRYSTAL OSCILLATOR
Ranges Characterized:
Mode Freq OSC1(C1) OSC2(C2)
XT455 kHz2.0 MHz4.0 MHz
22 - 100 pF15 - 68 pF15 - 68 pF
22 - 100 pF15 - 68 pF15 - 68 pF
HS 8.0 MHz16.0 MHz
10 - 68 pF10 - 22 pF
10 - 68 pF10 - 22 pF
Higher capacitance increases the stability of the oscillatorbut also increases the start-up time. These values are fordesign guidance only. Since each resonator has its owncharacteristics, the user should consult the resonator man-ufacturer for appropriate values of external components.
Mode Freq OSC1(C1) OSC2(C2)
LP 32 kHz200 kHz
68 - 100 pF15 - 30 pF
68 - 100 pF15 - 30 pF
XT 100 kHz2 MHz4 MHz
68 - 150 pF15 - 30 pF15 - 30 pF
150 - 200 pF15 - 30 pF15 - 30 pF
HS 8 MHz10 MHz20 MHz
15 - 30 pF15 - 30 pF15 - 30 pF
15 - 30 pF15 - 30 pF15 - 30 pF
Higher capacitance increases the stability of the oscillatorbut also increases the start-up time. These values are fordesign guidance only. Rs may be required in HS mode aswell as XT mode to avoid overdriving crystals with low drivelevel specification. Since each crystal has its owncharacteristics, the user should consult the crystal manu-facturer for appropriate values of external components.
PIC16F62X
DS40300B-page 98 Preliminary 1999 Microchip Technology Inc.
14.2.3 EXTERNAL CRYSTAL OSCILLATOR CIRCUIT
Either a prepackaged oscillator can be used or a simpleoscillator circuit with TTL gates can be built.Prepackaged oscillators provide a wide operatingrange and better stability. A well-designed crystaloscillator will provide good performance with TTLgates. Two types of crystal oscillator circuits can beused; one with series resonance, or one with parallelresonance.
Figure 14-4 shows implementation of a parallel reso-nant oscillator circuit. The circuit is designed to use thefundamental frequency of the crystal. The 74AS04inverter performs the 180° phase shift that a paralleloscillator requires. The 4.7 kΩ resistor provides thenegative feedback for stability. The 10 kΩpotentiometers bias the 74AS04 in the linear region.This could be used for external oscillator designs.
FIGURE 14-4: EXTERNAL PARALLEL RESONANT CRYSTAL OSCILLATOR CIRCUIT
Figure 14-5 shows a series resonant oscillator circuit.This circuit is also designed to use the fundamentalfrequency of the crystal. The inverter performs a 180°phase shift in a series resonant oscillator circuit. The330 kΩ resistors provide the negative feedback to biasthe inverters in their linear region.
FIGURE 14-5: EXTERNAL SERIES RESONANT CRYSTAL OSCILLATOR CIRCUIT
20 pF
+5V
20 pF
10k4.7k
10k
74AS04
XTAL
10k
74AS04 PIC16F62X
CLKIN
To otherDevices
330 kΩ
74AS04 74AS04
PIC16F62X
CLKIN
To otherDevices
XTAL
330 kΩ
74AS04
0.1 µF
14.2.4 EXTERNAL CLOCK IN
For applications where a clock is already available else-where, users may directly drive the PIC16F62X pro-vided that this external clock source meets the AC/DCtiming requirements listed in Section 17.4. Figure 14-6below shows how an external clock circuit should beconfigured.
FIGURE 14-6: EXTERNAL CLOCK INPUT OPERATION (HS, XT OR LP OSC CONFIGURATION)
14.2.5 ER OSCILLATOR
For timing insensitive applications, the ER (ExternalResistor) clock mode offers additional cost savings.Only one external component, a resistor to VSS, isneeded to set the operating frequency of the internaloscillator. The resistor draws a DC bias current whichcontrols the oscillation frequency. In addition to theresistance value, the oscillator frequency will vary fromunit to unit, and as a function of supply voltage and tem-perature. Since the controlling parameter is a DC cur-rent and not a capacitance, the particular package typeand lead frame will not have a significant effect on theresultant frequency.
Figure 14-7 shows how the controlling resistor is con-nected to the PIC16F62X. For Rext values below 38k,the oscillator operation may become unstable, or stopcompletely. For very high Rext values (e.g. 1M), theoscillator becomes sensitive to noise, humidity andleakage. Thus, we recommend keeping Rext between38k and 1M.
FIGURE 14-7: EXTERNAL RESISTOR
The Electrical Specification section shows the relation-ship between the resistance value and the operatingfrequency as well as frequency variations due to oper-ating temperature for given R and VDD values.
The ER oscillator mode has two options that control theunused OSC2 pin. The first allows it to be used as ageneral purpose I/O port. The other configures the pinas an output providing the Fosc signal (internal clockdivided by 4) for test or external synchronization pur-poses.
Clock fromext. system
PIC16F62X
OSC1/RA7
OSC2/RA6RA6
RA7/OSC1/CLKIN
RA6/OSC2/CLKOUT
1999 Microchip Technology Inc. Preliminary DS40300B-page 99
PIC16F62X
14.2.6 INTERNAL 4 MHZ OSCILLATOR
The internal RC oscillator provides a fixed 4 MHz (nom-inal) system clock at Vdd = 5V and 25°C, see “ElectricalSpecifications” section for information on variation overvoltage and temperature.
14.2.7 CLKOUT
The PIC16F62X can be configured to provide a clockout signal by programming the configuration word. Theoscillator frequency, divided by 4 can be used for testpurposes or to synchronize other logic.
14.3 Special Feature: Dual Speed Oscillator Modes
A software programmable dual speed oscillator modeis provided when the PIC16F62X is configured in eitherER or INTRC oscillator modes. This feature allowsusers to dynamically toggle the oscillator speedbetween 4MHz and 37kHz. In ER mode, the 4MHz set-ting will vary depending on the size of the externalresistor. Also in ER mode, the 37kHz operation is fixedand does not vary with resistor size. Applications thatrequire low current power savings, but cannot tolerateputting the part into sleep, may use this mode.
The OSCF bit in the PCON register is used to controldual speed mode. See Section 4.2.2.6, Figure 4-9.
14.4 Reset
The PIC16F62X differentiates between various kindsof reset:
a) Power-on reset (POR)
b) MCLR reset during normal operationc) MCLR reset during SLEEP d) WDT reset (normal operation)
e) WDT wake-up (SLEEP)f) Brown-out Detect (BOD)
Some registers are not affected in any reset condition;their status is unknown on POR and unchanged in anyother reset. Most other registers are reset to a “resetstate” on Power-on reset, MCLR reset, WDT reset andMCLR reset during SLEEP. They are not affected by aWDT wake-up, since this is viewed as the resumptionof normal operation. TO and PD bits are set or cleareddifferently in different reset situations as indicated inTable 14-4. These bits are used in software to deter-mine the nature of the reset. See Table 14-7 for a fulldescription of reset states of all registers.
A simplified block diagram of the on-chip reset circuit isshown in Figure 14-8.
The MCLR reset path has a noise filter to detect andignore small pulses. See Table 12-6 for pulse widthspecification.
PIC16F62X
DS40300B-page 100 Preliminary 1999 Microchip Technology Inc.
FIGURE 14-8: SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
S
R Q
ExternalReset
MCLR/
VDD
OSC1/
WDTModule
VDD risedetect
OST/PWRT
On-chip(1) ER OSC
WDTTime-out
Power-on Reset
OST
PWRT
Chip_Reset
10-bit Ripple-counter
Reset
Enable OST
Enable PWRT
SLEEP
See Table 14-3 for time-out situations.
Note 1: This is a separate oscillator from the INTRC/EC oscillator.
Brown-outdetect BODEN
CLKINPin
VPP Pin
10-bit Ripple-counter
Q
1999 Microchip Technology Inc. Preliminary DS40300B-page 101
PIC16F62X
14.5 Power-on Reset (POR), Power-up Timer (PWRT), Oscillator Start-up Timer (OST) and Brown-out Detect (BOD)
14.5.1 POWER-ON RESET (POR)
The on-chip POR circuit holds the chip in reset untilVDD has reached a high enough level for proper opera-tion. To take advantage of the POR, just tie the MCLRpin through a resistor to VDD. This will eliminate exter-nal RC components usually needed to create Power-onReset. A maximum rise time for VDD is required. SeeElectrical Specifications for details.
The POR circuit does not produce an internal resetwhen VDD declines.
When the device starts normal operation (exits thereset condition), device operating parameters (voltage,frequency, temperature, etc.) must be met to ensureoperation. If these conditions are not met, the devicemust be held in reset until the operating conditions aremet.
For additional information, refer to Application NoteAN607 “Power-up Trouble Shooting”.
14.5.2 POWER-UP TIMER (PWRT)
The Power-up Timer provides a fixed 72 ms (nominal)time-out on power-up only, from POR or Brown-outReset. The Power-up Timer operates on an internal RCoscillator. The chip is kept in reset as long as PWRT isactive. The PWRT delay allows the VDD to rise to anacceptable level. A configuration bit, PWRTE candisable (if set) or enable (if cleared or programmed) thePower-up Timer. The Power-up Timer should always beenabled when Brown-out Reset is enabled.
The Power-Up Time delay will vary from chip to chipand due to VDD, temperature and process variation.See DC parameters for details.
14.5.3 OSCILLATOR START-UP TIMER (OST)
The Oscillator Start-Up Timer (OST) provides a 1024oscillator cycle (from OSC1 input) delay after thePWRT delay is over. This ensures that the crystaloscillator or resonator has started and stabilized.
The OST time-out is invoked only for XT, LP and HSmodes and only on power-on reset or wake-up fromSLEEP.
14.5.4 BROWN-OUT DETECT (BOD)
The PIC16F62X members have on-chip Brown-outDetect circuitry. A configuration bit, BODEN, can dis-able (if clear/programmed) or enable (if set) theBrown-out Detect circuitry. If VDD falls below 4.0V, referto VBOD parameter D005(VBOD) for greater thanparameter (TBOD) in Table 17.1, the brown-out situa-tion will reset the chip. A reset is not guaranteed tooccur if VDD falls below 4.0V for less than parameter(TBOD).
On any reset (Power-on, Brown-out, Watchdog, etc.)the chip will remain in Reset until VDD rises aboveBVDD. The Power-up Timer will now be invoked and willkeep the chip in reset an additional 72 ms.
If VDD drops below BVDD while the Power-up Timer isrunning, the chip will go back into a Brown-out Resetand the Power-up Timer will be re-initialized. Once VDD
rises above BVDD, the Power-Up Timer will execute a72 ms reset. The Power-up Timer should always beenabled when Brown-out Detect is enabled.Figure 14-9 shows typical Brown-out situations.
FIGURE 14-9: BROWN-OUT SITUATIONS
72 ms
BVDD VDD
InternalReset
BVDD VDD
InternalReset 72 ms
<72 ms
72 ms
BVDD VDD
InternalReset
PIC16F62X
DS40300B-page 102 Preliminary 1999 Microchip Technology Inc.
14.5.5 TIME-OUT SEQUENCE
On power-up the time-out sequence is as follows: FirstPWRT time-out is invoked after POR has expired. ThenOST is activated. The total time-out will vary based onoscillator configuration and PWRTE bit status. Forexample, in ER mode with PWRTE bit erased (PWRTdisabled), there will be no time-out at all. Figure 14-10,Figure 14-11 and Figure 14-12 depict time-outsequences.
Since the time-outs occur from the POR pulse, if MCLRis kept low long enough, the time-outs will expire. Thenbringing MCLR high will begin execution immediately(see Figure 14-11). This is useful for testing purposesor to synchronize more than one PIC16F62X deviceoperating in parallel.
Table 14-6 shows the reset conditions for some specialregisters, while Table 14-7 shows the reset conditionsfor all the registers.
14.5.6 POWER CONTROL (PCON)/STATUS REGISTER
The power control/status register, PCON (address8Eh) has two bits.
Bit0 is BOD (Brown-out). BOD is unknown onpower-on-reset. It must then be set by the user andchecked on subsequent resets to see if BOD = 0indicating that a brown-out has occurred. The BODstatus bit is a don’t care and is not necessarilypredictable if the brown-out circuit is disabled (bysetting BODEN bit = 0 in the Configuration word).
Bit1 is POR (Power-on-reset). It is a ‘0’ onpower-on-reset and unaffected otherwise. The usermust write a ‘1’ to this bit following a power-on-reset.On a subsequent reset if POR is ‘0’, it will indicate thata power-on-reset must have occurred (VDD may havegone too low).
TABLE 14-3: TIME-OUT IN VARIOUS SITUATIONS
TABLE 14-4: STATUS/PCON BITS AND THEIR SIGNIFICANCE
Legend: u = unchanged, x = unknown
Oscillator ConfigurationPower-up
Brown-out ResetWake-up
from SLEEPPWRTE = 0 PWRTE = 1
XT, HS, LP 72 ms + 1024 TOSC 1024 TOSC 72 ms + 1024 TOSC 1024 TOSC
ER 72 ms — 72 ms —
POR BOD TO PD
0 X 1 1 Power-on-reset
0 X 0 X Illegal, TO is set on POR
0 X X 0 Illegal, PD is set on POR
1 0 X X Brown-out Detect
1 1 0 u WDT Reset
1 1 0 0 WDT Wake-up
1 1 u u MCLR reset during normal operation
1 1 1 0 MCLR reset during SLEEP
TABLE 14-5: SUMMARY OF REGISTERS ASSOCIATED WITH BROWN-OUT
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR Reset
Value on all other resets(1)
03h STATUS IRP RP1 RPO TO PD Z DC C 0001 1xxx 000q quuu
8Eh PCON — — — — OSCF — POR BOD ---- 1-0x ---- u-uq
Note 1: Other (non power-up) resets include MCLR reset, Brown-out Detect and Watchdog Timer Reset during normal operation.
1999 Microchip Technology Inc. Preliminary DS40300B-page 103
PIC16F62X
TABLE 14-6: INITIALIZATION CONDITION FOR SPECIAL REGISTERS
ConditionProgramCounter
STATUSRegister
PCONRegister
Power-on Reset 000h 0001 1xxx ---- 1-0x
MCLR reset during normal operation 000h 000u uuuu ---- 1-uu
MCLR reset during SLEEP 000h 0001 0uuu ---- 1-uu
WDT reset 000h 0000 uuuu ---- 1-uu
WDT Wake-up PC + 1 uuu0 0uuu ---- --uu
Brown-out Detect 000h 000x xuuu ---- 1-u0
Interrupt Wake-up from SLEEP PC + 1(1) uuu1 0uuu ---- --uu
Legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ‘0’.Note 1: When the wake-up is due to an interrupt and global enable bit, GIE is set, the PC is loaded with the interrupt vector
(0004h) after execution of PC+1.
PIC16F62X
DS40300B-page 104 Preliminary 1999 Microchip Technology Inc.
TABLE 14-7: INITIALIZATION CONDITION FOR REGISTERS
Register Address Power-on Reset
• MCLR Reset during normal operation
• MCLR Reset during SLEEP
• WDT Reset
• Brown-out Detect (1)
• Wake up from SLEEP through interrupt
• Wake up from SLEEP through WDT time-out
W - xxxx xxxx uuuu uuuu uuuu uuuu
INDF 00h - - -
TMR0 01h xxxx xxxx uuuu uuuu uuuu uuuu
PCL 02h 0000 0000 0000 0000 PC + 1(3)
STATUS 03h 0001 1xxx 000q quuu(4) uuuq quuu(4)
FSR 04h xxxx xxxx uuuu uuuu uuuu uuuu
PORTA 05h xxxx 0000 xxxx u000 xxxx 0000
PORTB 06h xxxx xxxx uuuu uuuu uuuu uuuu
T1CON 10h --00 0000 --uu uuuu
T2CON 12h -000 0000 -000 0000
CCP1CON 17h --00 0000 --00 0000
RCSTA 18h 0000 -00x 0000 -00x
CMCON 1Fh 0000 0000 0000 0000 uu-- uuuu
PCLATH 0Ah ---0 0000 ---0 0000 ---u uuuu
INTCON 0Bh 0000 000x 0000 000u uuuu uqqq(2)
PIR1 0Ch 0000 -000 0000 -000 -q-- ----(2,5)
OPTION 81h 1111 1111 1111 1111 uuuu uuuu
TRISA 85h 11-1 1111 11-- 1111 uu-u uuuu
TRISB 86h 1111 1111 1111 1111 uuuu uuuu
PIE1 8Ch 0000 -000 0000 -000 uuuu -uuu
PCON 8Eh ---- 1-0x ---- 1-uq(1,6) ---- --uu
TXSTA 98h 0000 -010 0000 -010
EECON1 9Ch ---- x000 ---- q000
VRCON 9Fh 000- 0000 000- 0000 uuu- uuuu
Legend: u = unchanged, x = unknown, - = unimplemented bit, reads as ‘0’, q = value depends on condition.Note 1: If VDD goes too low, Power-on Reset will be activated and registers will be affected differently.
2: One or more bits in INTCON, PIR1 and/or PIR2 will be affected (to cause wake-up).3: When the wake-up is due to an interrupt and the GIE bit is set, the PC is loaded with the interrupt vector (0004h).4: See Table 14-6 for reset value for specific condition.5: If wake-up was due to comparator input changing, then bit 6 = 1. All other interrupts generating a wake-up will cause
bit 6 = u.6: If reset was due to brown-out, then bit 0 = 0. All other resets will cause bit 0 = u.
1999 Microchip Technology Inc. Preliminary DS40300B-page 105
PIC16F62X
FIGURE 14-10: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 1
FIGURE 14-11: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 2
FIGURE 14-12: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD)
TPWRT
TOST
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-OUT
INTERNAL RESET
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-OUT
INTERNAL RESET
TPWRT
TOST
TPWRT
TOST
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-OUT
INTERNAL RESET
PIC16F62X
DS40300B-page 106 Preliminary 1999 Microchip Technology Inc.
FIGURE 14-13: EXTERNAL POWER-ON RESET CIRCUIT (FOR SLOW VDD POWER-UP)
Note 1: External power-on reset circuit is required only if VDD power-up slope is too slow. The diode D helps discharge the capacitor quickly when VDD powers down.
2: < 40 kΩ is recommended to make sure that voltage drop across R does not violate the device’s electrical specification.
3: R1 = 100Ω to 1 kΩ will limit any current flowing into MCLR from external capacitor C in the event of MCLR/VPP pin breakdown due to Electrostatic Discharge (ESD) or Electrical Overstress (EOS).
C
R1
RD
VDD
MCLR
PIC16F62X
VDD
FIGURE 14-14: EXTERNAL BROWN-OUT PROTECTION CIRCUIT 1
FIGURE 14-15: EXTERNAL BROWN-OUT PROTECTION CIRCUIT 2
Note 1: This circuit will activate reset when VDD goes below (Vz + 0.7V) where Vz = Zener voltage.
2: Internal Brown-out Reset circuitry should be disabled when using this circuit.
VDD
33k
10k
40k
VDD
MCLR
PIC16F62X
Note 1: This brown-out circuit is less expensive, albeit less accurate. Transistor Q1 turns off when VDD is below a certain level such that:
2: Internal brown-out reset should be disabled when using this circuit.
3: Resistors should be adjusted for the charac-teristics of the transistor.
VDD xR1
R1 + R2= 0.7 V
VDD
R2 40k
VDD
MCLR
PIC16F62X
R1
Q1
1999 Microchip Technology Inc. Preliminary DS40300B-page 107
PIC16F62X
14.6 Interrupts
The PIC16F62X has 10 sources of interrupt:
• External Interrupt RB0/INT• TMR0 Overflow Interrupt• PortB Change Interrupts (pins RB7:RB4)
• Comparator Interrupt• USART Interrupt• CCP Interrupt
• TMR1 Overflow Interrupt• TMR2 Match Interrupt
The interrupt control register (INTCON) recordsindividual interrupt requests in flag bits. It also hasindividual and global interrupt enable bits.
A global interrupt enable bit, GIE (INTCON<7>)enables (if set) all un-masked interrupts or disables (ifcleared) all interrupts. Individual interrupts can bedisabled through their corresponding enable bits inINTCON register. GIE is cleared on reset.
The “return from interrupt” instruction, RETFIE, exitsinterrupt routine as well as sets the GIE bit, whichre-enable RB0/INT interrupts.
The INT pin interrupt, the RB port change interrupt andthe TMR0 overflow interrupt flags are contained in theINTCON register.
The peripheral interrupt flag is contained in the specialregister PIR1. The corresponding interrupt enable bit iscontained in special registers PIE1.
When an interrupt is responded to, the GIE is clearedto disable any further interrupt, the return address ispushed into the stack and the PC is loaded with 0004h.Once in the interrupt service routine the source(s) ofthe interrupt can be determined by polling the interruptflag bits. The interrupt flag bit(s) must be cleared in soft-ware before re-enabling interrupts to avoid RB0/INTrecursive interrupts.
For external interrupt events, such as the INT pin orPORTB change interrupt, the interrupt latency will bethree or four instruction cycles. The exact latencydepends when the interrupt event occurs(Figure 14-17). The latency is the same for one or twocycle instructions. Once in the interrupt service routinethe source(s) of the interrupt can be determined by poll-ing the interrupt flag bits. The interrupt flag bit(s) mustbe cleared in software before re-enabling interrupts toavoid multiple interrupt requests. Individual interruptflag bits are set regardless of the status of theircorresponding mask bit or the GIE bit.
Note 1: Individual interrupt flag bits are setregardless of the status of theircorresponding mask bit or the GIE bit.
2: When an instruction that clears the GIEbit is executed, any interrupts that werepending for execution in the next cycleare ignored. The CPU will execute aNOP in the cycle immediately followingthe instruction which clears the GIE bit.The interrupts which were ignored arestill pending to be serviced when the GIEbit is set again.
FIGURE 14-16: INTERRUPT LOGIC
TMR2IFTMR2IE
CCP1IFCCP1IE
CMIFCMIETXIFTXIERCIFRCIE
T0IFT0IE
INTFINTE
RBIFRBIE
GIE
PEIE
Wake-up (If in SLEEP mode)
Interrupt to CPU
EEIEEEIF
TMR1IFTMR1IE
PIC16F62X
DS40300B-page 108 Preliminary 1999 Microchip Technology Inc.
14.6.1 RB0/INT INTERRUPT
External interrupt on RB0/INT pin is edge triggered:either rising if INTEDG bit (OPTION<6>) is set, or fall-ing, if INTEDG bit is clear. When a valid edge appearson the RB0/INT pin, the INTF bit (INTCON<1>) is set.This interrupt can be disabled by clearing the INTEcontrol bit (INTCON<4>). The INTF bit must be clearedin software in the interrupt service routine beforere-enabling this interrupt. The RB0/INT interrupt canwake-up the processor from SLEEP, if the INTE bit wasset prior to going into SLEEP. The status of the GIE bitdecides whether or not the processor branches to theinterrupt vector following wake-up. See Section 14.9 fordetails on SLEEP and Figure 14-19 for timing ofwake-up from SLEEP through RB0/INT interrupt.
14.6.2 TMR0 INTERRUPT
An overflow (FFh → 00h) in the TMR0 register willset the T0IF (INTCON<2>) bit. The interrupt canbe enabled/disabled by setting/clearing T0IE(INTCON<5>) bit. For operation of the Timer0 module,see Section 6.0.
14.6.3 PORTB INTERRUPT
An input change on PORTB <7:4> sets the RBIF(INTCON<0>) bit. The interrupt can be enabled/dis-abled by setting/clearing the RBIE (INTCON<4>) bit.For operation of PORTB (Section 5.2).
14.6.4 COMPARATOR INTERRUPT
See Section 9.6 for complete description of comparatorinterrupts.
Note: If a change on the I/O pin should occurwhen the read operation is being executed(start of the Q2 cycle), then the RBIF inter-rupt flag may not get set.
FIGURE 14-17: INT PIN INTERRUPT TIMING
TABLE 14-8: SUMMARY OF INTERRUPT REGISTERS
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR Reset
Value on all other resets(1)
0Bh INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
0Ch PIR1 EEIF CMIF RCIF TXIF — CCP1IF TMR2IF TMR1IF 0000 -000 0000 -000
8Ch PIE1 EEIE CMIE RCIE TXIE — CCP1IE TMR2IE TMR1IE 0000 -000 0000 -000
Note 1: Other (non power-up) resets include MCLR reset, Brown-out Reset and Watchdog Timer Reset during normal operation.
Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4
OSC1
CLKOUT
INT pin
INTF flag(INTCON<1>)
GIE bit(INTCON<7>)
INSTRUCTION FLOW
PC
Instructionfetched
Instructionexecuted
Interrupt Latency
PC PC+1 PC+1 0004h 0005h
Inst (0004h) Inst (0005h)
Dummy Cycle
Inst (PC) Inst (PC+1)
Inst (PC-1) Inst (0004h)Dummy CycleInst (PC)
—
1
4
5
1
2
3
Note 1: INTF flag is sampled here (every Q1).2: Asynchronous interrupt latency = 3-4 Tcy. Synchronous latency = 3 Tcy, where Tcy = instruction cycle time. Latency
is the same whether Inst (PC) is a single cycle or a 2-cycle instruction.3: CLKOUT is available only in ER oscillator mode.4: For minimum width of INT pulse, refer to AC specs.5: INTF is enabled to be set anytime during the Q4-Q1 cycles.
1999 Microchip Technology Inc. Preliminary DS40300B-page 109
PIC16F62X
14.7 Context Saving During Interrupts
During an interrupt, only the return PC value is savedon the stack. Typically, users may wish to save key reg-isters during an interrupt e.g. W register and STATUSregister. This will have to be implemented in software.
Example 14-1 stores and restores the STATUS and Wregisters. The user register, W_TEMP, must be definedin both banks and must be defined at the same offsetfrom the bank base address (i.e., W_TEMP is definedat 0x20 in Bank 0 and it must also be defined at 0xA0in Bank 1). The user register, STATUS_TEMP, must bedefined in Bank 0. The Example 14-1:
• Stores the W register• Stores the STATUS register in Bank 0• Executes the ISR code
• Restores the STATUS (and bank select bitregister)
• Restores the W register
EXAMPLE 14-1: SAVING THE STATUS AND W REGISTERS IN RAM
MOVWF W_TEMP ;copy W to temp register, ;could be in either bank
SWAPF STATUS,W ;swap status to be saved into W
BCF STATUS,RP0 ;change to bank 0 regardless;of current bank
MOVWF STATUS_TEMP ;save status to bank 0 ;register
:
: (ISR)
:
SWAPF STATUS_TEMP,W ;swap STATUS_TEMP register;into W, sets bank to original;state
MOVWF STATUS ;move W into STATUS register
SWAPF W_TEMP,F ;swap W_TEMP
SWAPF W_TEMP,W ;swap W_TEMP into W
14.8 Watchdog Timer (WDT)
The watchdog timer is a free running on-chip RC oscil-lator which does not require any external components.This RC oscillator is separate from the ER oscillator ofthe CLKIN pin. That means that the WDT will run, evenif the clock on the OSC1 and OSC2 pins of the devicehas been stopped, for example, by execution of aSLEEP instruction. During normal operation, a WDTtime-out generates a device RESET. If the device is inSLEEP mode, a WDT time-out causes the device towake-up and continue with normal operation. The WDTcan be permanently disabled by programming the con-figuration bit WDTE as clear (Section 14.1).
14.8.1 WDT PERIOD
The WDT has a nominal time-out period of 18 ms, (withno prescaler). The time-out periods vary with tempera-ture, VDD and process variations from part to part (seeDC specs). If longer time-out periods are desired, aprescaler with a division ratio of up to 1:128 can beassigned to the WDT under software control by writingto the OPTION register. Thus, time-out periods up to2.3 seconds can be realized.
The CLRWDT and SLEEP instructions clear the WDTand the postscaler, if assigned to the WDT, and preventit from timing out and generating a device RESET.
The TO bit in the STATUS register will be cleared upona Watchdog Timer time-out.
14.8.2 WDT PROGRAMMING CONSIDERATIONS
It should also be taken in account that under worst caseconditions (VDD = Min., Temperature = Max., max.WDT prescaler) it may take several seconds before aWDT time-out occurs.
PIC16F62X
DS40300B-page 110 Preliminary 1999 Microchip Technology Inc.
FIGURE 14-18: WATCHDOG TIMER BLOCK DIAGRAM
TABLE 14-9: SUMMARY OF WATCHDOG TIMER REGISTERS
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Value on POR
Reset
Value on all other Resets
2007h Config. bits LVP BOREN MCLRE FOSC2 PWRTE WDTE FOSC1 FOSC0 uuuu uuuu uuuu uuuu
81h OPTION RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0 1111 1111 1111 1111
Legend: Shaded cells are not used by the Watchdog Timer.
Note: _ = Unimplemented location, read as “0”+ = Reserved for future use
From TMR0 Clock Source(Figure 6-6)
To TMR0 (Figure 6-6)
PostscalerWatchdog
Timer
MUX
PSA
8 - to -1 MUX
PSA
WDT Time-out
10
0
1
WDT Enable Bit
PS<2:0>
•
•
Note: T0SE, T0CS, PSA, PS0-PS2 are bits in the OPTION register.
8
MUX
1999 Microchip Technology Inc. Preliminary DS40300B-page 111
PIC16F62X
14.9 Power-Down Mode (SLEEP)
The Power-down mode is entered by executing aSLEEP instruction.
If enabled, the Watchdog Timer will be cleared butkeeps running, the PD bit in the STATUS register iscleared, the TO bit is set, and the oscillator driver isturned off. The I/O ports maintain the status they had,before SLEEP was executed (driving high, low, orhi-impedance).
For lowest current consumption in this mode, all I/Opins should be either at VDD, or VSS, with no externalcircuitry drawing current from the I/O pin and the com-parators and VREF should be disabled. I/O pins that arehi-impedance inputs should be pulled high or low exter-nally to avoid switching currents caused by floatinginputs. The T0CKI input should also be at VDD or VSS
for lowest current consumption. The contribution fromon chip pull-ups on PORTB should be considered.
The MCLR pin must be at a logic high level (VIHMC).
14.9.1 WAKE-UP FROM SLEEP
The device can wake-up from SLEEP through one ofthe following events:
1. External reset input on MCLR pin2. Watchdog Timer Wake-up (if WDT was enabled)3. Interrupt from RB0/INT pin, RB Port change, or
the Peripheral Interrupt (Comparator).
Note: It should be noted that a RESET generatedby a WDT time-out does not drive MCLRpin low.
The first event will cause a device reset. The two latterevents are considered a continuation of program exe-cution. The TO and PD bits in the STATUS register canbe used to determine the cause of device reset. PDbit, which is set on power-up is cleared when SLEEP isinvoked. TO bit is cleared if WDT Wake-up occurred.
When the SLEEP instruction is being executed, thenext instruction (PC + 1) is pre-fetched. For the deviceto wake-up through an interrupt event, the correspond-ing interrupt enable bit must be set (enabled). Wake-upis regardless of the state of the GIE bit. If the GIE bit isclear (disabled), the device continues execution at theinstruction after the SLEEP instruction. If the GIE bit isset (enabled), the device executes the instruction afterthe SLEEP instruction and then branches to the inter-rupt address (0004h). In cases where the execution ofthe instruction following SLEEP is not desirable, theuser should have an NOP after the SLEEP instruction.
The WDT is cleared when the device wakes-up fromsleep, regardless of the source of wake-up.
Note: If the global interrupts are disabled (GIE iscleared), but any interrupt source has bothits interrupt enable bit and the correspond-ing interrupt flag bits set, the device willimmediately wakeup from sleep. The sleepinstruction is completely executed.
FIGURE 14-19: WAKE-UP FROM SLEEP THROUGH INTERRUPT
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)
INT pin
INTF flag(INTCON<1>)
GIE bit(INTCON<7>)
INSTRUCTION FLOW
PC
Instructionfetched
Instructionexecuted
PC PC+1 PC+2
Inst(PC) = SLEEP
Inst(PC - 1)
Inst(PC + 1)
SLEEP
Processor in
SLEEP
Interrupt Latency
(Note 2)
Inst(PC + 2)
Inst(PC + 1)
Inst(0004h) Inst(0005h)
Inst(0004h)Dummy cycle
PC + 2 0004h 0005h
Dummy cycle
TOST(2)
PC+2
Note 1: XT, HS or LP oscillator mode assumed.2: TOST = 1024TOSC (drawing not to scale). Approximately 1 µs delay will be there for ER osc mode.3: GIE = ’1’ assumed. In this case after wake- up, the processor jumps to the interrupt routine. If GIE = ’0’, execution will continue in-line.4: CLKOUT is not available in these osc modes, but shown here for timing reference.
PIC16F62X
DS40300B-page 112 Preliminary 1999 Microchip Technology Inc.
14.10 Code Protection
If the code protection bit(s) have not beenprogrammed, the on-chip program memory can beread out for verification purposes.
14.11 ID Locations
Four memory locations (2000h-2003h) are designatedas ID locations where the user can store checksum orother code-identification numbers. These locations arenot accessible during normal execution but arereadable and writable during program/verify. Only theleast significant 4 bits of the ID locations are used.
14.12 In-Circuit Serial Programming
The PIC16F62X microcontrollers can be seriallyprogrammed while in the end application circuit. This issimply done with two lines for clock and data, and threeother lines for power, ground, and the programmingvoltage. This allows customers to manufacture boardswith unprogrammed devices, and then program themicrocontroller just before shipping the product. Thisalso allows the most recent firmware or a customfirmware to be programmed.
The device is placed into a program/verify mode byholding the RB6 and RB7 pins low while raising theMCLR (VPP) pin from VIL to VIHH (see programmingspecification). RB6 becomes the programming clockand RB7 becomes the programming data. Both RB6and RB7 are Schmitt Trigger inputs in this mode.
After reset, to place the device into programming/verifymode, the program counter (PC) is at location 00h. A6-bit command is then supplied to the device.Depending on the command, 14-bits of program dataare then supplied to or from the device, depending if thecommand was a load or a read. For complete details ofserial programming, please refer to the ProgrammingSpecifications.
A typical in-circuit serial programming connection isshown in Figure 14-20.
Note: The entire data EEPROM and FLASHprogram memory will be erased when thecode protection is turned off. The INTRCcalibration data is not erased.
FIGURE 14-20: TYPICAL IN-CIRCUIT SERIAL PROGRAMMING CONNECTION
14.13 Low Voltage Programming
The LVP bit of the configuration word, enables the lowvoltage programming. This mode allows the microcon-troller to be programmed via ICSP using only a 5Vsource. This mode removes the requirement of VIHH tobe placed on the MCLR pin. The LVP bit is normallyerased to ’1’ which enables the low voltage program-ming. In this mode, the RB4/PGM pin is dedicated tothe programming function and ceases to be a generalpurpose I/O pin. The device will enter programmingmode when a ’1’ is placed on the RB4/PGM pin. TheHV programming mode is still available by placing VIHH
on the MCLR pin.
If Low-voltage programming mode is not used, the LVPbit can be programmed to a ’0’ and RB4/PGM becomesa digital I/O pin. To program the device, VIHH must beplaced onto MCLR during programming. The LVP bitmay only be programmed when programming isentered with VIHH on MCLR. The LVP bit cannot beprogrammed when programming is entered withRB4/PGM.
It should be noted, that once the LVP bit is programmedto 0, only the high voltage programming mode is avail-able and only high voltage programming mode can beused to program the device.
Note 1: While in this mode the RB4 pin can nolonger be used as a general purpose I/Opin.
2: VDD must be 5.0V +10% during erase/pro-gram operations while in low voltage pro-gramming mode.
ExternalConnectorSignals
To NormalConnections
To NormalConnections
PIC16F62X
VDD
VSS
RA5/MCLR/THV
RB6
RB7
+5V
0V
VPP
CLK
Data I/O
VDD
1999 Microchip Technology Inc. Preliminary DS40300B-page 113
PIC16F62X
15.0 INSTRUCTION SET SUMMARYEach PIC16F62X instruction is a 14-bit word dividedinto an OPCODE which specifies the instruction typeand one or more operands which further specify theoperation of the instruction. The PIC16F62X instruc-tion set summary in Table 15-2 lists byte-oriented,bit-oriented, and literal and control operations.Table 15-1 shows the opcode field descriptions.
For byte-oriented instructions, ’f’ represents a fileregister designator and ’d’ represents a destinationdesignator. The file register designator specifies whichfile register is to be used by the instruction.
The destination designator specifies where the result ofthe operation is to be placed. If ’d’ is zero, the result isplaced in the W register. If ’d’ is one, the result is placedin the file register specified in the instruction.
For bit-oriented instructions, ’b’ represents a bit fielddesignator which selects the number of the bit affectedby the operation, while ’f’ represents the number of thefile in which the bit is located.
For literal and control operations, ’k’ represents aneight or eleven bit constant or literal value.
TABLE 15-1: OPCODE FIELD DESCRIPTIONS
Field Description
f Register file address (0x00 to 0x7F)
W Working register (accumulator)
b Bit address within an 8-bit file register
k Literal field, constant data or label
x Don’t care location (= 0 or 1) The assembler will generate code with x = 0. It is the recommended form of use for compatibility with all Microchip software tools.
d Destination select; d = 0: store result in W,d = 1: store result in file register f. Default is d = 1
label Label name
TOS Top of Stack
PC Program CounterPCLATH Program Counter High Latch
GIE Global Interrupt Enable bit
WDT Watchdog Timer/Counter
TO Time-out bit
PD Power-down bit
dest Destination either the W register or the specified register file location
[ ] Options
( ) Contents
→ Assigned to
< > Register bit field
∈ In the set of
italics User defined term (font is courier)
The instruction set is highly orthogonal and is groupedinto three basic categories:
• Byte-oriented operations• Bit-oriented operations• Literal and control operations
All instructions are executed within one singleinstruction cycle, unless a conditional test is true or theprogram counter is changed as a result of aninstruction. In this case, the execution takes twoinstruction cycles with the second cycle executed as aNOP. One instruction cycle consists of four oscillatorperiods. Thus, for an oscillator frequency of 4 MHz, thenormal instruction execution time is 1 µs. If aconditional test is true or the program counter ischanged as a result of an instruction, the instructionexecution time is 2 µs.
Table 15-1 lists the instructions recognized by theMPASM assembler.
Figure 15-1 shows the three general formats that theinstructions can have.
All examples use the following format to represent ahexadecimal number:
0xhh
where h signifies a hexadecimal digit.
FIGURE 15-1: GENERAL FORMAT FOR INSTRUCTIONS
Note: To maintain upward compatibility withfuture PICmicro® products, do not use theOPTION and TRIS instructions.
Byte-oriented file register operations13 8 7 6 0
d = 0 for destination W
OPCODE d f (FILE #)
d = 1 for destination ff = 7-bit file register address
Bit-oriented file register operations13 10 9 7 6 0
OPCODE b (BIT #) f (FILE #)
b = 3-bit bit addressf = 7-bit file register address
Literal and control operations
13 8 7 0
OPCODE k (literal)
k = 8-bit immediate value
13 11 10 0
OPCODE k (literal)
k = 11-bit immediate value
General
CALL and GOTO instructions only
PIC16F62X
DS40300B-page 114 Preliminary 1999 Microchip Technology Inc.
TABLE 15-2: PIC16F62X INSTRUCTION SET
Mnemonic,Operands
Description Cycles 14-Bit Opcode StatusAffected
Notes
MSb LSb
BYTE-ORIENTED FILE REGISTER OPERATIONS
ADDWFANDWFCLRFCLRWCOMFDECFDECFSZINCFINCFSZIORWFMOVFMOVWFNOPRLFRRFSUBWFSWAPFXORWF
f, df, df-f, df, df, df, df, df, df, df-f, df, df, df, df, d
Add W and fAND W with fClear fClear WComplement fDecrement fDecrement f, Skip if 0Increment fIncrement f, Skip if 0Inclusive OR W with fMove fMove W to fNo OperationRotate Left f through CarryRotate Right f through CarrySubtract W from fSwap nibbles in fExclusive OR W with f
111111
1(2)1
1(2)111111111
000000000000000000000000000000000000
011101010001000110010011101110101111010010000000000011011100001011100110
dfffdffflfff0000dfffdfffdfffdfffdfffdfffdffflfff0xx0dfffdfffdfffdfffdfff
ffffffffffff0011ffffffffffffffffffffffffffffffff0000ffffffffffffffffffff
C,DC,ZZZZZZ
Z
ZZ
CCC,DC,Z
Z
1,21,22
1,21,21,2,31,21,2,31,21,2
1,21,21,21,21,2
BIT-ORIENTED FILE REGISTER OPERATIONS
BCFBSFBTFSCBTFSS
f, bf, bf, bf, b
Bit Clear fBit Set fBit Test f, Skip if ClearBit Test f, Skip if Set
11
1 (2)1 (2)
01010101
00bb01bb10bb11bb
bfffbfffbfffbfff
ffffffffffffffff
1,21,233
LITERAL AND CONTROL OPERATIONS
ADDLWANDLWCALLCLRWDTGOTOIORLWMOVLWRETFIERETLWRETURNSLEEPSUBLWXORLW
kkk-kkk-k--kk
Add literal and WAND literal with WCall subroutineClear Watchdog TimerGo to addressInclusive OR literal with WMove literal to WReturn from interruptReturn with literal in W Return from SubroutineGo into standby modeSubtract W from literalExclusive OR literal with W
1121211222111
11111000101111001100001111
111x10010kkk00001kkk100000xx000001xx00000000110x1010
kkkkkkkkkkkk0110kkkkkkkkkkkk0000kkkk00000110kkkkkkkk
kkkkkkkkkkkk0100kkkkkkkkkkkk1001kkkk10000011kkkkkkkk
C,DC,ZZ
TO,PD
Z
TO,PDC,DC,ZZ
Note 1: When an I/O register is modified as a function of itself ( e.g., MOVF PORTB, 1), the value used will be that value present on the pins themselves. For example, if the data latch is ’1’ for a pin configured as input and is driven low by an external device, the data will be written back with a ’0’.
2: If this instruction is executed on the TMR0 register (and, where applicable, d = 1), the prescaler will be cleared if assigned to the Timer0 Module.
3: If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.
1999 Microchip Technology Inc. Preliminary DS40300B-page 115
PIC16F62X
15.1 Instruction Descriptions
ADDLW Add Literal and W
Syntax: [ label ] ADDLW k
Operands: 0 ≤ k ≤ 255
Operation: (W) + k → (W)
Status Affected: C, DC, Z
Encoding: 11 111x kkkk kkkk
Description: The contents of the W register are added to the eight bit literal ’k’ and the result is placed in the W register.
Words: 1
Cycles: 1
Example ADDLW 0x15
Before InstructionW = 0x10
After InstructionW = 0x25
ADDWF Add W and f
Syntax: [ label ] ADDWF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (W) + (f) → (dest)
Status Affected: C, DC, Z
Encoding: 00 0111 dfff ffff
Description: Add the contents of the W register with register ’f’. If ’d’ is 0 the result is stored in the W register. If ’d’ is 1 the result is stored back in register ’f’.
Words: 1
Cycles: 1
Example ADDWF FSR, 0
Before InstructionW = 0x17FSR = 0xC2
After InstructionW = 0xD9FSR = 0xC2
ANDLW AND Literal with W
Syntax: [ label ] ANDLW k
Operands: 0 ≤ k ≤ 255
Operation: (W) .AND. (k) → (W)
Status Affected: Z
Encoding: 11 1001 kkkk kkkk
Description: The contents of W register are AND’ed with the eight bit literal 'k'. The result is placed in the W register.
Words: 1
Cycles: 1
Example ANDLW 0x5F
Before InstructionW = 0xA3
After InstructionW = 0x03
ANDWF AND W with f
Syntax: [ label ] ANDWF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (W) .AND. (f) → (dest)
Status Affected: Z
Encoding: 00 0101 dfff ffff
Description: AND the W register with register 'f'. If 'd' is 0 the result is stored in the W register. If 'd' is 1 the result is stored back in register 'f'.
Words: 1
Cycles: 1
Example ANDWF FSR, 1
Before Instruction W = 0x17FSR = 0xC2
After InstructionW = 0x17FSR = 0x02
PIC16F62X
DS40300B-page 116 Preliminary 1999 Microchip Technology Inc.
BCF Bit Clear f
Syntax: [ label ] BCF f,b
Operands: 0 ≤ f ≤ 1270 ≤ b ≤ 7
Operation: 0 → (f<b>)
Status Affected: None
Encoding: 01 00bb bfff ffff
Description: Bit ’b’ in register ’f’ is cleared.
Words: 1
Cycles: 1
Example BCF FLAG_REG, 7
Before InstructionFLAG_REG = 0xC7
After InstructionFLAG_REG = 0x47
BSF Bit Set f
Syntax: [ label ] BSF f,b
Operands: 0 ≤ f ≤ 1270 ≤ b ≤ 7
Operation: 1 → (f<b>)
Status Affected: None
Encoding: 01 01bb bfff ffff
Description: Bit ’b’ in register ’f’ is set.
Words: 1
Cycles: 1
Example BSF FLAG_REG, 7
Before InstructionFLAG_REG = 0x0A
After InstructionFLAG_REG = 0x8A
BTFSC Bit Test, Skip if Clear
Syntax: [ label ] BTFSC f,b
Operands: 0 ≤ f ≤ 1270 ≤ b ≤ 7
Operation: skip if (f<b>) = 0
Status Affected: None
Encoding: 01 10bb bfff ffff
Description: If bit ’b’ in register ’f’ is ’0’ then the next instruction is skipped.If bit ’b’ is ’0’ then the next instruction fetched during the current instruction execution is discarded, and a NOP is executed instead, making this a two-cycle instruction.
Words: 1
Cycles: 1(2)
Example HEREFALSETRUE
BTFSCGOTO•••
FLAG,1PROCESS_CODE
Before InstructionPC = address HERE
After Instructionif FLAG<1> = 0,PC = address TRUEif FLAG<1>=1,PC = address FALSE
1999 Microchip Technology Inc. Preliminary DS40300B-page 117
PIC16F62X
BTFSS Bit Test f, Skip if Set
Syntax: [ label ] BTFSS f,b
Operands: 0 ≤ f ≤ 1270 ≤ b < 7
Operation: skip if (f<b>) = 1
Status Affected: None
Encoding: 01 11bb bfff ffff
Description: If bit ’b’ in register ’f’ is ’1’ then the next instruction is skipped.If bit ’b’ is ’1’, then the next instruction fetched during the current instruction execution, is discarded and a NOP is executed instead, making this a two-cycle instruction.
Words: 1
Cycles: 1(2)
Example HEREFALSETRUE
BTFSSGOTO•••
FLAG,1PROCESS_CODE
Before InstructionPC = address HERE
After Instructionif FLAG<1> = 0,PC = address FALSEif FLAG<1> = 1,PC = address TRUE
CALL Call Subroutine
Syntax: [ label ] CALL k
Operands: 0 ≤ k ≤ 2047
Operation: (PC)+ 1→ TOS,k → PC<10:0>,(PCLATH<4:3>) → PC<12:11>
Status Affected: None
Encoding: 10 0kkk kkkk kkkk
Description: Call Subroutine. First, return address (PC+1) is pushed onto the stack. The eleven bit immediate address is loaded into PC bits <10:0>. The upper bits of the PC are loaded from PCLATH. CALL is a two-cycle instruction.
Words: 1
Cycles: 2
Example HERE CALL THERE
Before InstructionPC = Address HERE
After InstructionPC = Address THERETOS = Address HERE+1
CLRF Clear f
Syntax: [ label ] CLRF f
Operands: 0 ≤ f ≤ 127
Operation: 00h → (f)1 → Z
Status Affected: Z
Encoding: 00 0001 1fff ffff
Description: The contents of register ’f’ are cleared and the Z bit is set.
Words: 1
Cycles: 1
Example CLRF FLAG_REG
Before InstructionFLAG_REG = 0x5A
After InstructionFLAG_REG = 0x00Z = 1
CLRW Clear W
Syntax: [ label ] CLRW
Operands: None
Operation: 00h → (W)1 → Z
Status Affected: Z
Encoding: 00 0001 0000 0011
Description: W register is cleared. Zero bit (Z) is set.
Words: 1
Cycles: 1
Example CLRW
Before InstructionW = 0x5A
After InstructionW = 0x00Z = 1
PIC16F62X
DS40300B-page 118 Preliminary 1999 Microchip Technology Inc.
CLRWDT Clear Watchdog Timer
Syntax: [ label ] CLRWDT
Operands: None
Operation: 00h → WDT0 → WDT prescaler,1 → TO1 → PD
Status Affected: TO, PD
Encoding: 00 0000 0110 0100
Description: CLRWDT instruction resets the Watchdog Timer. It also resets the prescaler of the WDT. Status bits TO and PD are set.
Words: 1
Cycles: 1
Example CLRWDT
Before InstructionWDT counter = ?
After InstructionWDT counter = 0x00WDT prescaler= 0TO = 1PD = 1
COMF Complement f
Syntax: [ label ] COMF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) → (dest)
Status Affected: Z
Encoding: 00 1001 dfff ffff
Description: The contents of register ’f’ are complemented. If ’d’ is 0 the result is stored in W. If ’d’ is 1 the result is stored back in register ’f’.
Words: 1
Cycles: 1
Example COMF REG1,0
Before InstructionREG1 = 0x13
After InstructionREG1 = 0x13W = 0xEC
DECF Decrement f
Syntax: [ label ] DECF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) - 1 → (dest)
Status Affected: Z
Encoding: 00 0011 dfff ffff
Description: Decrement register ’f’. If ’d’ is 0 the result is stored in the W register. If ’d’ is 1 the result is stored back in register ’f’.
Words: 1
Cycles: 1
Example DECF CNT, 1
Before InstructionCNT = 0x01Z = 0
After InstructionCNT = 0x00Z = 1
DECFSZ Decrement f, Skip if 0
Syntax: [ label ] DECFSZ f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) - 1 → (dest); skip if result = 0
Status Affected: None
Encoding: 00 1011 dfff ffff
Description: The contents of register ’f’ are decremented. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is placed back in register ’f’. If the result is 0, the next instruction, which is already fetched, is discarded. A NOP is executed instead making it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Example HERE DECFSZ CNT, 1 GOTO LOOPCONTINUE • • •
Before InstructionPC = address HERE
After InstructionCNT = CNT - 1if CNT = 0,PC = address CONTINUEif CNT ≠ 0,PC = address HERE+1
1999 Microchip Technology Inc. Preliminary DS40300B-page 119
PIC16F62X
GOTO Unconditional Branch
Syntax: [ label ] GOTO k
Operands: 0 ≤ k ≤ 2047
Operation: k → PC<10:0>PCLATH<4:3> → PC<12:11>
Status Affected: None
Encoding: 10 1kkk kkkk kkkk
Description: GOTO is an unconditional branch. The eleven bit immediate value is loaded into PC bits <10:0>. The upper bits of PC are loaded from PCLATH<4:3>. GOTO is a two-cycle instruction.
Words: 1
Cycles: 2
Example GOTO THERE
After InstructionPC = Address THERE
INCF Increment f
Syntax: [ label ] INCF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) + 1 → (dest)
Status Affected: Z
Encoding: 00 1010 dfff ffff
Description: The contents of register ’f’ are incremented. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is placed back in register ’f’.
Words: 1
Cycles: 1
Example INCF CNT, 1
Before InstructionCNT = 0xFFZ = 0
After InstructionCNT = 0x00Z = 1
INCFSZ Increment f, Skip if 0
Syntax: [ label ] INCFSZ f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) + 1 → (dest), skip if result = 0
Status Affected: None
Encoding: 00 1111 dfff ffff
Description: The contents of register ’f’ are incremented. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is placed back in register ’f’.If the result is 0, the next instruction, which is already fetched, is discarded. A NOP is executed instead making it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Example HERE INCFSZ CNT, 1 GOTO LOOPCONTINUE • • •
Before InstructionPC = address HERE
After InstructionCNT = CNT + 1if CNT= 0,PC = address CONTINUEif CNT≠ 0,PC = address HERE +1
IORLW Inclusive OR Literal with W
Syntax: [ label ] IORLW k
Operands: 0 ≤ k ≤ 255
Operation: (W) .OR. k → (W)
Status Affected: Z
Encoding: 11 1000 kkkk kkkk
Description: The contents of the W register is OR’ed with the eight bit literal 'k'. The result is placed in the W register.
Words: 1
Cycles: 1
Example IORLW 0x35
Before InstructionW = 0x9A
After InstructionW = 0xBFZ = 1
PIC16F62X
DS40300B-page 120 Preliminary 1999 Microchip Technology Inc.
IORWF Inclusive OR W with f
Syntax: [ label ] IORWF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (W) .OR. (f) → (dest)
Status Affected: Z
Encoding: 00 0100 dfff ffff
Description: Inclusive OR the W register with register ’f’. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is placed back in register ’f’.
Words: 1
Cycles: 1
Example IORWF RESULT, 0
Before InstructionRESULT = 0x13W = 0x91
After InstructionRESULT = 0x13W = 0x93Z = 1
MOVLW Move Literal to W
Syntax: [ label ] MOVLW k
Operands: 0 ≤ k ≤ 255
Operation: k → (W)
Status Affected: None
Encoding: 11 00xx kkkk kkkk
Description: The eight bit literal ’k’ is loaded into W register. The don’t cares will assemble as 0’s.
Words: 1
Cycles: 1
Example MOVLW 0x5A
After InstructionW = 0x5A
MOVF Move f
Syntax: [ label ] MOVF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) → (dest)
Status Affected: Z
Encoding: 00 1000 dfff ffff
Description: The contents of register f is moved to a destination dependent upon the status of d. If d = 0, destination is W register. If d = 1, the destination is file register f itself. d = 1 is useful to test a file register since status flag Z is affected.
Words: 1
Cycles: 1
Example MOVF FSR, 0
After InstructionW = value in FSR registerZ = 1
MOVWF Move W to f
Syntax: [ label ] MOVWF f
Operands: 0 ≤ f ≤ 127
Operation: (W) → (f)
Status Affected: None
Encoding: 00 0000 1fff ffff
Description: Move data from W register to register 'f'.
Words: 1
Cycles: 1
Example MOVWF OPTION
Before InstructionOPTION = 0xFFW = 0x4F
After InstructionOPTION = 0x4FW = 0x4F
1999 Microchip Technology Inc. Preliminary DS40300B-page 121
PIC16F62X
NOP No Operation
Syntax: [ label ] NOP
Operands: None
Operation: No operation
Status Affected: None
Encoding: 00 0000 0xx0 0000
Description: No operation.
Words: 1
Cycles: 1
Example NOP
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 compatibility 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 PICmicro® products, do not use this instruction.
RETFIE Return from Interrupt
Syntax: [ label ] RETFIE
Operands: None
Operation: TOS → PC,1 → GIE
Status Affected: None
Encoding: 00 0000 0000 1001
Description: Return from Interrupt. Stack is POPed and Top of Stack (TOS) is loaded in the PC. Interrupts are enabled by setting Global Interrupt Enable bit, GIE (INTCON<7>). This is a two-cycle instruction.
Words: 1
Cycles: 2
Example RETFIE
After InterruptPC = TOSGIE = 1
RETLW Return with Literal in W
Syntax: [ label ] RETLW k
Operands: 0 ≤ k ≤ 255
Operation: k → (W); TOS → PC
Status Affected: None
Encoding: 11 01xx kkkk kkkk
Description: The W register is loaded with the eight bit literal ’k’. The program counter is loaded from the top of the stack (the return address). This is a two-cycle instruction.
Words: 1
Cycles: 2
Example
TABLE
CALL TABLE ;W contains table ;offset value• ;W now has table value••ADDWF PC ;W = offsetRETLW k1 ;Begin tableRETLW k2 ;•••RETLW kn ; End of table
Before InstructionW = 0x07
After InstructionW = value of k8
PIC16F62X
DS40300B-page 122 Preliminary 1999 Microchip Technology Inc.
RETURN Return from Subroutine
Syntax: [ label ] RETURN
Operands: None
Operation: TOS → PC
Status Affected: None
Encoding: 00 0000 0000 1000
Description: Return from subroutine. The stack is POPed and the top of the stack (TOS) is loaded into the program counter. This is a two cycle instruction.
Words: 1
Cycles: 2
Example RETURN
After InterruptPC = TOS
RLF Rotate Left f through Carry
Syntax: [ label ] RLF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: See description below
Status Affected: C
Encoding: 00 1101 dfff ffff
Description: The contents of register ’f’ are rotated one bit to the left through the Carry Flag. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is stored back in register ’f’.
Words: 1
Cycles: 1
Example RLF REG1,0
Before InstructionREG1 = 1110 0110C = 0
After InstructionREG1 = 1110 0110W = 1100 1100C = 1
Register fC
RRF Rotate Right f through Carry
Syntax: [ label ] RRF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: See description below
Status Affected: C
Encoding: 00 1100 dfff ffff
Description: The contents of register ’f’ are rotated one bit to the right through the Carry Flag. If ’d’ is 0 the result is placed in the W register. If ’d’ is 1 the result is placed back in register ’f’.
Words: 1
Cycles: 1
Example RRF REG1,0
Before InstructionREG1 = 1110 0110C = 0
After InstructionREG1 = 1110 0110W = 0111 0011C = 0
SLEEP
Syntax: [ label ] SLEEP
Operands: None
Operation: 00h → WDT,0 → WDT prescaler,1 → TO,0 → PD
Status Affected: TO, PD
Encoding: 00 0000 0110 0011
Description: The power-down status bit, PD is cleared. Time-out status bit, TO is set. Watchdog Timer and its prescaler are cleared.The processor is put into SLEEP mode with the oscillator stopped. See Section 14.9 for more details.
Words: 1
Cycles: 1
Example: SLEEP
Register fC
1999 Microchip Technology Inc. Preliminary DS40300B-page 123
PIC16F62X
SUBLW Subtract W from Literal
Syntax: [ label ] SUBLW k
Operands: 0 ≤ k ≤ 255
Operation: k - (W) → (W)
Status Affected:
C, DC, Z
Encoding: 11 110x kkkk kkkk
Description: The W register is subtracted (2’s com-plement method) from the eight bit literal 'k'. The result is placed in the W register.
Words: 1
Cycles: 1
Example 1: SUBLW 0x02
Before Instruction
W = 1C = ?
After Instruction
W = 1C = 1; result is positive
Example 2: Before Instruction
W = 2C = ?
After Instruction
W = 0C = 1; result is zero
Example 3: Before Instruction
W = 3C = ?
After Instruction
W = 0xFFC = 0; result is nega-tive
SUBWF Subtract W from f
Syntax: [ label ] SUBWF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f) - (W) → (dest)
Status Affected:
C, DC, Z
Encoding: 00 0010 dfff ffff
Description: Subtract (2’s complement method) W register from register 'f'. If 'd' is 0 the result is stored in the W register. If 'd' is 1 the result is stored back in register 'f'.
Words: 1
Cycles: 1
Example 1: SUBWF REG1,1
Before Instruction
REG1 = 3W = 2C = ?
After Instruction
REG1 = 1W = 2C = 1; result is positive
Example 2: Before Instruction
REG1 = 2W = 2C = ?
After Instruction
REG1 = 0W = 2C = 1; result is zero
Example 3: Before Instruction
REG1 = 1W = 2C = ?
After Instruction
REG1 = 0xFFW = 2C = 0; result is negative
PIC16F62X
DS40300B-page 124 Preliminary 1999 Microchip Technology Inc.
SWAPF Swap Nibbles in f
Syntax: [ label ] SWAPF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (f<3:0>) → (dest<7:4>),(f<7:4>) → (dest<3:0>)
Status Affected: None
Encoding: 00 1110 dfff ffff
Description: The upper and lower nibbles of register ’f’ are exchanged. If ’d’ is 0 the result is placed in W register. If ’d’ is 1 the result is placed in register ’f’.
Words: 1
Cycles: 1
Example SWAPF REG, 0
Before Instruction
REG1 = 0xA5
After Instruction
REG1 = 0xA5W = 0x5A
TRIS Load TRIS Register
Syntax: [ label ] TRIS f
Operands: 5 ≤ f ≤ 7
Operation: (W) → TRIS register f;
Status Affected: None
Encoding: 00 0000 0110 0fff
Description: The instruction is supported for code compatibility with the PIC16C5X products. Since TRIS registers are readable and writable, the user can directly address them.
Words: 1
Cycles: 1
Example
To maintain upward compatibility
with future PICmicro® products, do not use this instruction.
XORLW Exclusive OR Literal with W
Syntax: [ label ] XORLW k
Operands: 0 ≤ k ≤ 255
Operation: (W) .XOR. k → (W)
Status Affected: Z
Encoding: 11 1010 kkkk kkkk
Description: The contents of the W register are XOR’ed with the eight bit literal 'k'. The result is placed in the W register.
Words: 1
Cycles: 1
Example: XORLW 0xAF
Before Instruction
W = 0xB5
After Instruction
W = 0x1A
XORWF Exclusive OR W with f
Syntax: [ label ] XORWF f,d
Operands: 0 ≤ f ≤ 127d ∈ [0,1]
Operation: (W) .XOR. (f) → (dest)
Status Affected: Z
Encoding: 00 0110 dfff ffff
Description: Exclusive OR the contents of the W register with register 'f'. If 'd' is 0 the result is stored in the W register. If 'd' is 1 the result is stored back in register 'f'.
Words: 1
Cycles: 1
Example XORWF REG 1
Before Instruction
REG = 0xAFW = 0xB5
After Instruction
REG = 0x1AW = 0xB5
1999 Microchip Technology Inc. Preliminary DS40300B-page 125
PIC16F62X
16.0 DEVELOPMENT SUPPORTThe PICmicro® microcontrollers are supported with afull range of hardware and software development tools:
• Integrated Development Environment- MPLAB™ IDE Software
• Assemblers/Compilers/Linkers
- MPASM Assembler- MPLAB-C17 and MPLAB-C18 C Compilers- MPLINK/MPLIB Linker/Librarian
• Simulators- MPLAB-SIM Software Simulator
• Emulators
- MPLAB-ICE Real-Time In-Circuit Emulator- PICMASTER®/PICMASTER-CE In-Circuit
Emulator- ICEPIC™
• In-Circuit Debugger
- MPLAB-ICD for PIC16F877• Device Programmers
- PRO MATE II Universal Programmer
- PICSTART Plus Entry-Level PrototypeProgrammer
• Low-Cost Demonstration Boards- SIMICE- PICDEM-1
- PICDEM-2- PICDEM-3- PICDEM-17
- SEEVAL
- KEELOQ
16.1 MPLAB Integrated Development Environment Software
- The MPLAB IDE software brings an ease of software development previously unseen in the 8-bit microcontroller market. MPLAB is a Windows-based application which contains:
• Multiple functionality
- editor- simulator- programmer (sold separately)
- emulator (sold separately)• A full featured editor• A project manager
• Customizable tool bar and key mapping• A status bar• On-line help
MPLAB allows you to:
• Edit your source files (either assembly or ‘C’)• One touch assemble (or compile) and download
to PICmicro tools (automatically updates all project information)
• Debug using:- source files
- absolute listing file- object code
The ability to use MPLAB with Microchip’s simulator,MPLAB-SIM, allows a consistent platform and the abil-ity to easily switch from the cost-effective simulator tothe full featured emulator with minimal retraining.
16.2 MPASM Assembler
MPASM is a full featured universal macro assembler forall PICmicro MCU’s. It can produce absolute codedirectly in the form of HEX files for device program-mers, or it can generate relocatable objects forMPLINK.
MPASM has a command line interface and a Windowsshell and can be used as a standalone application on aWindows 3.x or greater system. MPASM generatesrelocatable object files, Intel standard HEX files, MAPfiles to detail memory usage and symbol reference, anabsolute LST file which contains source lines and gen-erated machine code, and a COD file for MPLABdebugging.
MPASM features include:
• MPASM and MPLINK are integrated into MPLAB projects.
• MPASM allows user defined macros to be created for streamlined assembly.
• MPASM allows conditional assembly for multi pur-pose source files.
• MPASM directives allow complete control over the assembly process.
16.3 MPLAB-C17 and MPLAB-C18 C Compilers
The MPLAB-C17 and MPLAB-C18 Code DevelopmentSystems are complete ANSI ‘C’ compilers and inte-grated development environments for Microchip’sPIC17CXXX and PIC18CXXX family of microcontrol-lers, respectively. These compilers provide powerfulintegration capabilities and ease of use not found withother compilers.
For easier source level debugging, the compilers pro-vide symbol information that is compatible with theMPLAB IDE memory display.
PIC16F62X
DS40300B-page 126 Preliminary 1999 Microchip Technology Inc.
16.4 MPLINK/MPLIB Linker/Librarian
MPLINK is a relocatable linker for MPASM andMPLAB-C17 and MPLAB-C18. It can link relocatableobjects from assembly or C source files along with pre-compiled libraries using directives from a linker script.
MPLIB is a librarian for pre-compiled code to be usedwith MPLINK. When a routine from a library is calledfrom another source file, only the modules that containsthat routine will be linked in with the application. Thisallows large libraries to be used efficiently in many dif-ferent applications. MPLIB manages the creation andmodification of library files.
MPLINK features include:
• MPLINK works with MPASM and MPLAB-C17 and MPLAB-C18.
• MPLINK allows all memory areas to be defined as sections to provide link-time flexibility.
MPLIB features include:
• MPLIB makes linking easier because single librar-ies can be included instead of many smaller files.
• MPLIB helps keep code maintainable by grouping related modules together.
• MPLIB commands allow libraries to be created and modules to be added, listed, replaced, deleted, or extracted.
16.5 MPLAB-SIM Software Simulator
The MPLAB-SIM Software Simulator allows codedevelopment in a PC host environment by simulatingthe PICmicro series microcontrollers on an instructionlevel. On any given instruction, the data areas can beexamined or modified and stimuli can be applied froma file or user-defined key press to any of the pins. Theexecution can be performed in single step, execute untilbreak, or trace mode.
MPLAB-SIM fully supports symbolic debugging usingMPLAB-C17 and MPLAB-C18 and MPASM. The Soft-ware Simulator offers the flexibility to develop anddebug code outside of the laboratory environment mak-ing it an excellent multi-project software developmenttool.
16.6 MPLAB-ICE High Performance Universal In-Circuit Emulator with MPLAB IDE
The MPLAB-ICE Universal In-Circuit Emulator isintended to provide the product development engineerwith a complete microcontroller design tool set forPICmicro microcontrollers (MCUs). Software control ofMPLAB-ICE is provided by the MPLAB IntegratedDevelopment Environment (IDE), which allows editing,“make” and download, and source debugging from asingle environment.
Interchangeable processor modules allow the systemto be easily reconfigured for emulation of different pro-cessors. The universal architecture of the MPLAB-ICEallows expansion to support new PICmicro microcon-trollers.
The MPLAB-ICE Emulator System has been designedas a real-time emulation system with advanced fea-tures that are generally found on more expensive devel-opment tools. The PC platform and Microsoft® Windows3.x/95/98 environment were chosen to best make thesefeatures available to you, the end user.
MPLAB-ICE 2000 is a full-featured emulator systemwith enhanced trace, trigger, and data monitoring fea-tures. Both systems use the same processor modulesand will operate across the full operating speed rangeof the PICmicro MCU.
16.7 PICMASTER/PICMASTER CE
The PICMASTER system from Microchip Technology isa full-featured, professional quality emulator system.This flexible in-circuit emulator provides a high-quality,universal platform for emulating Microchip 8-bitPICmicro microcontrollers (MCUs). PICMASTER sys-tems are sold worldwide, with a CE compliant modelavailable for European Union (EU) countries.
16.8 ICEPIC
ICEPIC is a low-cost in-circuit emulation solution for the Microchip Technology PIC16C5X, PIC16C6X, PIC16C7X, and PIC16CXXX families of 8-bit one-time-programmable (OTP) microcontrollers. The modular system can support different subsets of PIC16C5X or PIC16CXXX products through the use of interchangeable personality modules or daughter boards. The emulator is capable of emulating without target application circuitry being present.
16.9 MPLAB-ICD In-Circuit Debugger
Microchip’s In-Circuit Debugger, MPLAB-ICD, is a pow-erful, low-cost run-time development tool. This tool isbased on the flash PIC16F877 and can be used todevelop for this and other PICmicro microcontrollersfrom the PIC16CXXX family. MPLAB-ICD utilizes theIn-Circuit Debugging capability built into thePIC16F87X. This feature, along with Microchip’s In-Cir-cuit Serial Programming protocol, offers cost-effectivein-circuit flash programming and debugging from thegraphical user interface of the MPLAB IntegratedDevelopment Environment. This enables a designer todevelop and debug source code by watching variables,single-stepping and setting break points. Running atfull speed enables testing hardware in real-time. TheMPLAB-ICD is also a programmer for the flashPIC16F87X family.
1999 Microchip Technology Inc. Preliminary DS40300B-page 127
PIC16F62X
16.10 PRO MATE II Universal Programmer
The PRO MATE II Universal Programmer is a full-fea-tured programmer capable of operating in stand-alonemode as well as PC-hosted mode. PRO MATE II is CEcompliant.
The PRO MATE II has programmable VDD and VPP
supplies which allows it to verify programmed memoryat VDD min and VDD max for maximum reliability. It hasan LCD display for instructions and error messages,keys to enter commands and a modular detachablesocket assembly to support various package types. Instand-alone mode the PRO MATE II can read, verify orprogram PICmicro devices. It can also set code-protectbits in this mode.
16.11 PICSTART Plus Entry Level Development System
The PICSTART programmer is an easy-to-use, low-cost prototype programmer. It connects to the PC viaone of the COM (RS-232) ports. MPLAB IntegratedDevelopment Environment software makes using theprogrammer simple and efficient.
PICSTART Plus supports all PICmicro devices with upto 40 pins. Larger pin count devices such as thePIC16C92X, and PIC17C76X may be supported withan adapter socket. PICSTART Plus is CE compliant.
16.12 SIMICE Entry-Level Hardware Simulator
SIMICE is an entry-level hardware development sys-tem designed to operate in a PC-based environmentwith Microchip’s simulator MPLAB-SIM. Both SIMICEand MPLAB-SIM run under Microchip Technology’sMPLAB Integrated Development Environment (IDE)software. Specifically, SIMICE provides hardware sim-ulation for Microchip’s PIC12C5XX, PIC12CE5XX, andPIC16C5X families of PICmicro 8-bit microcontrollers.SIMICE works in conjunction with MPLAB-SIM to pro-vide non-real-time I/O port emulation. SIMICE enablesa developer to run simulator code for driving the targetsystem. In addition, the target system can provide inputto the simulator code. This capability allows for simpleand interactive debugging without having to manuallygenerate MPLAB-SIM stimulus files. SIMICE is a valu-able debugging tool for entry-level system develop-ment.
16.13 PICDEM-1 Low-Cost PICmicroDemonstration Board
The PICDEM-1 is a simple board which demonstratesthe capabilities of several of Microchip’s microcontrol-lers. The microcontrollers supported are: PIC16C5X(PIC16C54 to PIC16C58A), PIC16C61, PIC16C62X,PIC16C71, PIC16C8X, PIC17C42, PIC17C43 andPIC17C44. All necessary hardware and software isincluded to run basic demo programs. The users canprogram the sample microcontrollers provided with
the PICDEM-1 board, on a PRO MATE II orPICSTART-Plus programmer, and easily test firm-ware. The user can also connect the PICDEM-1board to the MPLAB-ICE emulator and download thefirmware to the emulator for testing. Additional proto-type area is available for the user to build some addi-tional hardware and connect it to the microcontrollersocket(s). Some of the features include an RS-232interface, a potentiometer for simulated analog input,push-button switches and eight LEDs connected toPORTB.
16.14 PICDEM-2 Low-Cost PIC16CXX Demonstration Board
The PICDEM-2 is a simple demonstration board thatsupports the PIC16C62, PIC16C64, PIC16C65,PIC16C73 and PIC16C74 microcontrollers. All thenecessary hardware and software is included torun the basic demonstration programs. The usercan program the sample microcontrollers providedwith the PICDEM-2 board, on a PRO MATE II pro-grammer or PICSTART-Plus, and easily test firmware.The MPLAB-ICE emulator may also be used with thePICDEM-2 board to test firmware. Additional prototypearea has been provided to the user for adding addi-tional hardware and connecting it to the microcontrollersocket(s). Some of the features include a RS-232 inter-face, push-button switches, a potentiometer for simu-lated analog input, a Serial EEPROM to demonstrateusage of the I2C bus and separate headers for connec-tion to an LCD module and a keypad.
16.15 PICDEM-3 Low-Cost PIC16CXXX Demonstration Board
The PICDEM-3 is a simple demonstration board thatsupports the PIC16C923 and PIC16C924 in the PLCCpackage. It will also support future 44-pin PLCCmicrocontrollers with a LCD Module. All the neces-sary hardware and software is included to run thebasic demonstration programs. The user can pro-gram the sample microcontrollers provided withthe PICDEM-3 board, on a PRO MATE II program-mer or PICSTART Plus with an adapter socket, andeasily test firmware. The MPLAB-ICE emulator mayalso be used with the PICDEM-3 board to test firm-ware. Additional prototype area has been provided tothe user for adding hardware and connecting it to themicrocontroller socket(s). Some of the features includean RS-232 interface, push-button switches, a potenti-ometer for simulated analog input, a thermistor andseparate headers for connection to an external LCDmodule and a keypad. Also provided on the PICDEM-3board is an LCD panel, with 4 commons and 12 seg-ments, that is capable of displaying time, temperatureand day of the week. The PICDEM-3 provides an addi-tional RS-232 interface and Windows 3.1 software forshowing the demultiplexed LCD signals on a PC. A sim-ple serial interface allows the user to construct a hard-ware demultiplexer for the LCD signals.
PIC16F62X
DS40300B-page 128 Preliminary 1999 Microchip Technology Inc.
16.16 PICDEM-17
The PICDEM-17 is an evaluation board that demon-strates the capabilities of several Microchip microcon-trollers, including PIC17C752, PIC17C756,PIC17C762, and PIC17C766. All necessary hardwareis included to run basic demo programs, which are sup-plied on a 3.5-inch disk. A programmed sample isincluded, and the user may erase it and program it withthe other sample programs using the PRO MATE II orPICSTART Plus device programmers and easily debugand test the sample code. In addition, PICDEM-17 sup-ports down-loading of programs to and executing out ofexternal FLASH memory on board. The PICDEM-17 isalso usable with the MPLAB-ICE or PICMASTER emu-lator, and all of the sample programs can be run andmodified using either emulator. Additionally, a gener-ous prototype area is available for user hardware.
16.17 SEEVAL Evaluation and Programming System
The SEEVAL SEEPROM Designer’s Kit supports allMicrochip 2-wire and 3-wire Serial EEPROMs. The kitincludes everything necessary to read, write, erase orprogram special features of any Microchip SEEPROMproduct including Smart Serials and secure serials.The Total Endurance Disk is included to aid in trade-off analysis and reliability calculations. The total kit cansignificantly reduce time-to-market and result in anoptimized system.
16.18 KEELOQ Evaluation and Programming Tools
KEELOQ evaluation and programming tools supportMicrochips HCS Secure Data Products. The HCS eval-uation kit includes an LCD display to show changingcodes, a decoder to decode transmissions, and a pro-gramming interface to program test transmitters.
1999 Microchip Technology Inc. Preliminary DS40300B-page 129
PIC16F62X
TABLE 16-1: DEVELOPMENT TOOLS FROM MICROCHIP
PIC12CXXX
PIC14000
PIC16C5X
PIC16C6X
PIC16CXXX
PIC16F62X
PIC16C7X
PIC16C7XX
PIC16C8X
PIC16F8XX
PIC16C9XX
PIC17C4X
PIC17C7XX
PIC18CXX2
24CXX/25CXX/93CXX
HCSXXX
MCRFXXX
MCP2510
Software Tools
MP
LA
B
Inte
gra
ted
Dev
elo
pm
ent
En
viro
nm
ent
á
á
á
á
á
á
á
á
á
á
á
á
á
á
MP
LA
B
C17
Co
mp
iler
á
á
MP
LA
B
C18
Co
mp
iler
á
MP
AS
M/M
PL
INK
á
á
á
á
á
á
á
á
á
á
á
á
á
á
á
á
Emulators
MP
LA
B™
-IC
E
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
PIC
MA
ST
ER
/PIC
MA
ST
ER
-CE
á
á
á
á
á
á
á
á
á
á
á
ICE
PIC
L
ow-C
ost
In-C
ircui
t Em
ulat
or
á
á
á
á
á
á
á
á
Debugger
MP
LAB
-IC
D In
-Circ
uit D
ebug
ger
á
*
á
*
á
Programmers
PIC
ST
AR
T
Plu
s Lo
w-C
ost U
nive
rsal
Dev
. Kit
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
PR
O M
AT
E
II
Uni
vers
al P
rogr
amm
er
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
á
á
Demo Boards and Eval Kits
SIM
ICE
á
á
PIC
DE
M-1
á
á
á
†á
á
PIC
DE
M-2
á
†
á
†
á
PIC
DE
M-3
á
PIC
DE
M-1
4A
á
PIC
DE
M-1
7
á
KE
EL
OQ
® E
valu
atio
n K
it
á
KE
EL
OQ
Tra
nsp
on
der
Kit
á
mic
roID
™ P
rogr
amm
er’s
Kit
á
125
kHz
mic
roID
Dev
elop
er’s
Kit
á
125
kHz
Ant
icol
lisio
n m
icro
ID
Dev
elop
er’s
Kit
á
13.5
6 M
Hz
Ant
icol
lisio
n m
icro
ID
Dev
elop
er’s
Kit
á
MC
P25
10 C
AN
Dev
elop
er’s
Kit
á
*C
onta
ct th
e M
icro
chip
Tec
hnol
ogy
Inc.
web
site
at w
ww
.mic
roch
ip.c
om fo
r in
form
atio
n on
how
to u
se th
e M
PLA
B-I
CD
In-C
ircui
t Deb
ugge
r (D
V16
4001
) w
ith P
IC16
C62
, 63,
64,
65,
72,
73,
74,
76,
77
**C
onta
ct M
icro
chip
Tec
hnol
ogy
Inc.
for
avai
labi
lity
date
.†
Dev
elop
men
t too
l is
avai
labl
e on
sel
ect d
evic
es.
PIC16F62X
DS40300B-page 130 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 131
PIC16F62X
17.0 ELECTRICAL SPECIFICATIONSAbsolute Maximum Ratings †
Ambient temperature under bias................................................................................................................. -40 to +125°C
Storage temperature .............................................................................................................................. -65°C to +150°C
Voltage on VDD with respect to VSS ........................................................................................................... -0.3 to +6.5V
Voltage on MCLR and RA4 with respect to VSS ..........................................................................................-0.3 to +14V
Voltage on all other pins with respect to VSS ....................................................................................-0.3V to VDD + 0.3V
Total power dissipation (Note 1)...........................................................................................................................800 mW
Maximum current out of VSS pin ...........................................................................................................................300 mA
Maximum current into VDD pin ..............................................................................................................................250 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 ....................................................................................................25 mA
Maximum current sunk by PORTA and PORTB....................................................................................................200 mA
Maximum current sourced by PORTA and PORTB ..............................................................................................200 mA
Note 1: Power dissipation is calculated as follows: Pdis = VDD x IDD - ∑ IOH + ∑ (VDD-VOH) x IOH + ∑(VOl x IOL)
† 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.
Note: 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 ratherthan pulling this pin directly to VSS.
PIC16F62X
DS40300B-page 132 Preliminary 1999 Microchip Technology Inc.
FIGURE 17-1: PIC16F62X VOLTAGE-FREQUENCY GRAPH, 0°C ≤ TA ≤ +70°C
FIGURE 17-2: PIC16F62X VOLTAGE-FREQUENCY GRAPH, -40°C ≤ TA < 0°C, +70°C < TA ≤ 85°C
6.0
2.5
4.0
3.0
0
3.5
4.5
5.0
5.5
4 10
Frequency (MHz)
VDD
20
(Volts)
25
Note 1: The shaded region indicates the permissible combinations of voltage and frequency.
6.0
2.5
4.0
3.0
0
3.5
4.5
5.0
5.5
4 10
Frequency (MHz)
VDD
20
(Volts)
25
2.0
Note 1: The shaded region indicates the permissible combinations of voltage and frequency.
1999 Microchip Technology Inc. Preliminary DS40300B-page 133
PIC16F62X
FIGURE 17-3: PIC16LF62X VOLTAGE-FREQUENCY GRAPH, 0°C ≤ TA ≤ +70°C
FIGURE 17-4: PIC16LF62X VOLTAGE-FREQUENCY GRAPH, -40°C ≤ TA < 0°C, +70°C < TA ≤ 85°C
6.0
2.5
4.0
3.0
0
3.5
4.5
5.0
5.5
4 10
Frequency (MHz)
VDD
20
(Volts)
25
2.0
Note 1: The shaded region indicates the permissible combinations of voltage and frequency.
6.0
2.5
4.0
3.0
0
3.5
4.5
5.0
5.5
4 10
Frequency (MHz)
VDD
20
(Volts)
25
2.0
Note 1: The shaded region indicates the permissible combinations of voltage and frequency.
PIC16F62X
DS40300B-page 134 Preliminary 1999 Microchip Technology Inc.
17.1 DC CHARACTERISTICS: PIC16F62X-04 (Commercial, Industrial, Extended)PIC16F62X-20 (Commercial, Industrial, Extended)
Standard Operating Conditions (unless otherwise stated)Operating temperature –40°C ≤ TA ≤ +85°C for industrial and
0°C ≤ TA ≤ +70°C for commercial and–40°C ≤ TA ≤ +125°C for extended
ParamNo.
Sym Characteristic Min Typ† Max Units Conditions
D001 VDD Supply Voltage 3.0 - 5.5 V
D002 VDR RAM Data RetentionVoltage (Note 1)
– 1.5* – V Device in SLEEP mode
D003 VPOR VDD start voltage toensure Power-on Reset
– Vss – V See section on power-on reset for details
D004 SVDD VDD rise rate to ensure Power-on Reset
0.05* – – V/ms See section on power-on reset for details
D005 VBOD Brown-out Detect Voltage 3.73.7
4.04.0
4.34.4
V BODEN configuration bit is cleared(Extended)
D010
D013
IDD Supply Current (Note 2, 5) –
–––
–
4.0––
0.7
7.06.02.0
mA
mAmAmA
FOSC = 4.0 MHZ, VDD = 3.0
FOSC = 20.0 MHz, VDD = 5.5FOSC = 20.0 MHz, VDD = 4.5FOSC = 10.0 MHz, VDD = 3.0
D020 IPD Power Down Current (Note 3) ––––
––––
2.25.09.015.0
µAµAµAµA
VDD = 3.0VDD = 4.5VDD = 5.5VDD = 5.5 Extended
D023
∆IWDT
∆IBOD
∆ICOMP
∆IVREF
WDT Current (Note 4)
Brown-out Detect Current (Note 4)Comparator Current for each Comparator (Note 4)VREF Current (Note 4)
–
––
–
6.0
7530
202512550
135
µAµAµAµA
µA
VDD=4.0V(125°C)BOD enabled, VDD = 5.0VVDD = 4.0V
VDD = 4.0V
1A FOSC LP Oscillator Operating FrequencyINTRC Oscillator Operating FrequencyXT Oscillator Operating FrequencyHS Oscillator Operating Frequency
0–00
––––
20044
20
KHzMHzMHzMHz
All temperaturesAll temperaturesAll temperaturesAll temperatures
* These parameters are characterized but not tested.† Data in "Typ" column is at 5.0V, 25°C, unless otherwise stated. These parameters are for design guidance only and are
not tested.Note 1: This is the limit to which VDD can be lowered in SLEEP mode without losing RAM data.
2: The supply current is mainly a function of the operating voltage and frequency. Other factors such as I/O pin loading and switching rate, oscillator type, internal code execution pattern, and temperature also have an impact on the current con-sumption.The test conditions for all IDD measurements in active operation mode are: OSC1 = external square wave, from rail to rail; all I/O pins tri-stated, pulled to VDD, MCLR = VDD; WDT enabled/disabled as specified.
3: The power down current in SLEEP mode does not depend on the oscillator type. Power down current is measured with the part in SLEEP mode, with all I/O pins in hi-impedance state and tied to VDD or VSS.
4: The ∆ current is the additional current consumed when this peripheral is enabled. This current should be added to the base IDD or IPD measurement.
5: For RC osc configuration, current through Rext is not included. The current through the resistor can be estimated by the formula Ir = VDD/2Rext (mA) with Rext in kΩ.
1999 Microchip Technology Inc. Preliminary DS40300B-page 135
PIC16F62X
17.2 DC CHARACTERISTICS: PIC16LF62X-04 (Commercial, Industrial, Extended)
Standard Operating Conditions (unless otherwise stated)Operating temperature –40°C ≤ TA ≤ +85°C for industrial and
0°C ≤ TA ≤ +70°C for commercial and–40°C ≤ TA ≤ +125°C for extended
Operating voltage VDD range as described in DC spec Table 17.1 and Table 12-2Param
No.Sym Characteristic Min Typ† Max Units Conditions
D001 VDD Supply Voltage 2.0 - 5.5 V
D002 VDR RAM Data RetentionVoltage (Note 1)
– 1.5* – V Device in SLEEP mode
D003 VPOR VDD start voltage toensure Power-on Reset
– VSS – V See section on Power-on Reset for details
D004 SVDD VDD rise rate to ensure Power-on Reset
0.05* – – V/ms See section on Power-on Reset for details
D005 VBOD Brown-out Detect Voltage 3.7 4.0 4.3 V BODEN configuration bit is cleared
D010
D013
IDD Supply Current (Note 2, 5) –
–––
–
4.0––
0.6
7.06.02.0
mA
mAmAmA
FOSC = 4.0 MHZ, VDD = 2.5
FOSC = 20.0 MHz, VDD = 5.5FOSC = 20.0 MHz, VDD = 4.5FOSC = 10.0 MHz, VDD = 3.0
D020 IPD Power Down Current (Note 2) ––––
––––
2.02.25.09.015.0
µAµAµAµAµA
VDD = 2.5VDD = 3.0VDD = 4.5VDD = 5.5VDD = 5.5 Extended
D023∆IWDT
∆IBOD
∆ICOMP
∆IVREF
WDT Current (Note 4)Brown-out Detect Current (Note 4)Comparator Current for each Comparator (Note 4)VREF Current (Note 4)
––
––
6.075
30
15125
50135
µAµA
µAµA
VDD=3.0VBOD enabled, VDD = 5.0V
VDD = 3.0VVDD = 3.0V
1A FOSC LP Oscillator Operating FrequencyINTRC Oscillator Operating FrequencyXT Oscillator Operating FrequencyHS Oscillator Operating Frequency
0–00
––––
20044
20
KHzMHzMHzMHz
All temperaturesAll temperaturesAll temperaturesAll temperatures
* These parameters are characterized but not tested.† Data in "Typ" column is at 5.0V, 25°C, unless otherwise stated. These parameters are for design guidance only and are not
tested.Note 1: This is the limit to which VDD can be lowered in SLEEP mode without losing RAM data.
2: The supply current is mainly a function of the operating voltage and frequency. Other factors such as I/O pin loading and switching rate, oscillator type, internal code execution pattern, and temperature also have an impact on the current consump-tion.The test conditions for all IDD measurements in active operation mode are: OSC1=external square wave, from rail to rail; all I/O pins tristated, pulled to VDD, MCLR = VDD; WDT enabled/disabled as specified.
3: The power down current in SLEEP mode does not depend on the oscillator type. Power down current is measured with the part in SLEEP mode, with all I/O pins in hi-impedance state and tied to VDD to VSS.
4: The ∆ current is the additional current consumed when this peripheral is enabled. This current should be added to the base IDD or IPD measurement.
5: For RC osc configuration, current through Rext is not included. The current through the resistor can be estimated by the for-mula Ir = VDD/2Rext (mA) with Rext in kΩ.
PIC16F62X
DS40300B-page 136 Preliminary 1999 Microchip Technology Inc.
17.3 DC CHARACTERISTICS: PIC16F62X (Commercial, Industrial, Extended)
PIC16LF62X (Commercial, Industrial, Extended)
Standard Operating Conditions (unless otherwise stated)Operating temperature –40°C ≤ TA ≤ +85°C for industrial and
0°C ≤ TA ≤ +70°C for commercial and–40°C ≤ TA ≤ +125°C for extended
Operating voltage VDD range as described in DC spec Table 17.1 and Table 12-2
Param.No.
Sym Characteristic Min Typ† Max Unit Conditions
VIL Input Low VoltageI/O ports
D030 with TTL buffer VSS - 0.8V0.15VDD
V VDD = 4.5V to 5.5Votherwise
D031 with Schmitt Trigger input VSS 0.2VDD VD032 MCLR, RA4/T0CKI,OSC1 (in ER
mode)Vss - 0.2VDD V Note1
D033 OSC1 (in XT and HS) Vss - 0.3VDD VOSC1 (in LP) Vss - 0.6VDD-1.0 V
VIH Input High VoltageI/O ports -
D040 with TTL buffer 2.0V.25VDD + 0.8V
- VDD
VDD
V VDD = 4.5V to 5.5Votherwise
D041 with Schmitt Trigger input 0.8VDD VDD
D042 MCLR RA4/T0CKI 0.8VDD - VDD VD043D043A
OSC1 (XT, HS and LP)OSC1 (in ER mode)
0.7VDD
0.9VDD
- VDD VNote1
D070 IPURB PORTB weak pull-up current 50 200 400 µA VDD = 5.0V, VPIN = VSS
IILInput Leakage Current (Notes 2, 3)I/O ports (Except PORTA) ±1.0 µA VSS ≤ VPIN ≤ VDD, pin at hi-impedance
D060 PORTA - - ±0.5 µA Vss ≤ VPIN ≤ VDD, pin at hi-impedanceD061 RA4/T0CKI - - ±1.0 µA Vss ≤ VPIN ≤ VDD
D063 OSC1, MCLR - - ±5.0 µA Vss ≤ VPIN ≤ VDD, XT, HS and LP osc configuration
VOL Output Low VoltageD080 I/O ports - - 0.6 V IOL=8.5 mA, VDD=4.5V, -40° to +85°C
- - 0.6 V IOL=7.0 mA, VDD=4.5V, +125°CD083 OSC2/CLKOUT (ER only) - - 0.6 V IOL=1.6 mA, VDD=4.5V, -40° to +85°C
- - 0.6 V IOL=1.2 mA, VDD=4.5V, +125°CVOH Output High Voltage (Note 3)
D090 I/O ports (Except RA4) VDD-0.7 - - V IOH=-3.0 mA, VDD=4.5V, -40° to +85°CVDD-0.7 - - V IOH=-2.5 mA, VDD=4.5V, +125°C
D092 OSC2/CLKOUT (ER only) VDD-0.7 - - V IOH=-1.3 mA, VDD=4.5V, -40° to +85°CVDD-0.7 - - V IOH=-1.0 mA, VDD=4.5V, +125°C
*D150 VOD Open-Drain High Voltage - 8.5* V RA4 pin PIC16F62X, PIC16LF62XCapacitive Loading Specs on Output Pins
D100 COSC2 OSC2 pin - 15 pF In XT, HS and LP modes when external clock used to drive OSC1.
D101 Cio All I/O pins/OSC2 (in ER mode) - 50 pF* These parameters are characterized but not tested.† Data in “Typ” column is at 5.0V, 25°C unless otherwise stated. These parameters are for design guidance only and are not tested.
Note 1: In ER oscillator configuration, the OSC1 pin is a Schmitt Trigger input. It is not recommended that the PIC16F62X be driven with external clock in ER mode.
2: The leakage current on the MCLR pin is strongly dependent on applied voltage level. The specified levels represent normal operat-ing conditions. Higher leakage current may be measured at different input voltages.
3: Negative current is defined as coming out of the pin.
1999 Microchip Technology Inc. Preliminary DS40300B-page 137
PIC16F62X
TABLE 17-1: COMPARATOR SPECIFICATIONS
TABLE 17-2: VOLTAGE REFERENCE SPECIFICATIONS
Operating Conditions: 3.0V < VDD <5.5V, -40°C < TA < +125°C, unless otherwise stated.
ParamNo.
Characteristics Sym Min Typ Max Units Comments
D300 Input offset voltage VIOFF - ± 5.0 ± 10 mV
D301 Input common mode voltage* VICM 0 - VDD - 1.5 V
D302 Common Mode Rejection Ratio* CMRR 55 - - db
300300A
Response Time(1)* TRESP - 150 400600
nsns
16F62X16LF62X
301 Comparator Mode Change to Output Valid*
TMC2OV - - 10 µs
* These parameters are characterized but not tested.Response time measured with one comparator input at (VDD - 1.5)/2 while the other input transitions from VSS to VDD.
Operating Conditions: 3.0V < VDD < 5.5V, -40°C < TA < +125°C, unless otherwise stated.
SpecNo.
Characteristics Sym Min Typ Max Units Comments
D310 Resolution VRES VDD/24 - VDD/32 LSb
D311 Absolute Accuracy VRAA --
--
1/41/2
LSbLSb
Low Range (VRR = 1)High Range (VRR = 0)
D312 Unit Resistor Value (R)* VRUR - 2k - Ω310 Settling Time(1)* TSET - - 10 µs
* These parameters are characterized but not tested.Settling time measured while VRR = 1 and VR<3:0> transitions from 0000 to 1111.
PIC16F62X
DS40300B-page 138 Preliminary 1999 Microchip Technology Inc.
17.4 Timing Parameter Symbology
The timing parameter symbols have been created with one of the following formats:
FIGURE 17-5: LOAD CONDITIONS
TABLE 17-3: DC CHARACTERISTICS: PIC16F62X, PIC16LF62X
1. TppS2ppS2. TppS
TF Frequency T TimeLowercase subscripts (pp) and their meanings:
ppck CLKOUT osc OSC1io I/O port t0 T0CKI
mc MCLRUppercase letters and their meanings:
SF Fall P PeriodH High R RiseI Invalid (Hi-impedance) V Valid
L Low Z Hi-Impedance
DC Characteristics Standard Operating Conditions (unless otherwise stated)
ParameterNo.
Sym Characteristic Min Typ† Max Units Conditions
Data EEPROM MemoryD120 Ed Endurance 1M* 10M — E/W 25°C at 5VD121 Vdrw VDD for read/write VMIN — 5.5 V VMIN = Minimum operating
voltageD122 Tdew Erase/Write cycle time — 4 8* ms
Program Flash MemoryD130 Ep Endurance 1000* 10000 — E/WD131 Vpr VDD for read Vmin — 5.5 V VMIN = Minimum operating
voltageD132 Vpew VDD for erase/write 4.5 — 5.5 VD133 Tpew Erase/Write cycle time — 4 8* ms
* These parameters are characterized but not tested.† Data in “Typ” column is at 5.0V, 25°C unless otherwise stated. These parameters are for design guidance only and are not
tested.
VDD/2
CL
RL
Pin Pin
VSS VSS
CL
RL = 464Ω
CL = 50 pF for all pins except OSC2
15 pF for OSC2 output
Load condition 1 Load condition 2
1999 Microchip Technology Inc. Preliminary DS40300B-page 139
PIC16F62X
17.5 Timing Diagrams and Specifications
FIGURE 17-6: EXTERNAL CLOCK TIMING
TABLE 17-4: EXTERNAL CLOCK TIMING REQUIREMENTS
Parameter No.
Sym Characteristic Min Typ† Max Units Conditions
Fosc External CLKIN Frequency (Note 1)
DC — 4 MHz XT and ER osc mode, VDD=5.0V
DC — 20 MHz HS osc mode DC — 200 kHz LP osc mode
Oscillator Frequency (Note 1)
— 4 MHz ER osc mode, VDD=5.0V 0.1 — 4 MHz XT osc mode 1 —
—20200
MHzkHz
HS osc mode LP osc mode
4 MHz INTRC mode (fast)
37 kHz INTRC mode (slow)1 Tosc External CLKIN Period
(Note 1)250 — — ns XT and ER osc mode50 — — ns HS osc mode
5 — — µs LP osc mode
Oscillator Period(Note 1)
250 — — ns ER osc mode 250 — 10,000 ns XT osc mode 50 — 1,000 ns HS osc mode
5 µs LP osc mode250 ns INTRC mode (fast)27 µs INTRC mode (slow)
2 Tcy Instruction Cycle Time (Note 1) 1.0 TCY DC ns TCY = 4/FOSC 3 TosL,
TosHExternal CLKIN (OSC1) HighExternal CLKIN Low
100 * — — ns XT oscillator, TOSC L/H duty cycle
4 INTRC Internal Calibrated ER 3.65 4.00 4.28 MHz VDD = 5.0V5 ER External Biased ER Frequency 10kHz 8MHz VDD = 5.0V
OSC1
CLKOUT
Q4 Q1 Q2 Q3 Q4 Q1
1 3 34 4
2
PIC16F62X
DS40300B-page 140 Preliminary 1999 Microchip Technology Inc.
FIGURE 17-7: CLKOUT AND I/O TIMING
TABLE 17-5: CLKOUT AND I/O TIMING REQUIREMENTS
Parameter No.
Sym Characteristic Min Typ† Max Units
10 TosH2ckL OSC1↑ to CLKOUT↓ 16F62X — 75 200 ns
10A 16LF62X — — 400 ns
11 TosH2ckH OSC1↑ to CLKOUT↑ 16F62X — 75 200 ns
11A 16LF62X — — 400 ns
12 TckR CLKOUT rise time 16F62X — 35 100 ns
12A 16LF62X — — 200 ns
13 TckF CLKOUT fall time 16F62X — 35 100 ns
13A 16LF62X — — 200 ns
14 TckL2ioV CLKOUT ↓ to Port out valid — — 20 ns
15 TioV2ckH Port in valid before 16F62X Tosc+200
ns
— — ns
CLKOUT ↑ 16LF62X Tosc=400
ns
— — ns
16 TckH2ioI Port in hold after CLKOUT ↑ 0 — — ns
17 TosH2ioV OSC1↑ (Q1 cycle) to 16F62X — 50 150 * ns
Port out valid 16LF62X — — 300 ns
18 TosH2ioI OSC1↑ (Q2 cycle) to Port input invalid(I/O in hold time)
100200
— — ns
OSC1
CLKOUT
I/O Pin(input)
I/O Pin(output)
Q4 Q1 Q2 Q3
10
13
14
17
20, 21
22
23
19 18
15
11
12
16
old value new value
1999 Microchip Technology Inc. Preliminary DS40300B-page 141
PIC16F62X
FIGURE 17-8: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP TIMER TIMING
FIGURE 17-9: BROWN-OUT DETECT TIMING
TABLE 17-6: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP TIMER REQUIREMENTS
Parameter No.
Sym Characteristic Min Typ† MaxUnit
sConditions
30 TmcL MCLR Pulse Width (low) 2000 TBD
—TBD
—TBD
nsms
VDD = 5V, -40°C to +85°CExtended temperature
31 Twdt Watchdog Timer Time-out Period (No Prescaler)
7TBD
18TBD
33TBD
msms
VDD = 5V, -40°C to +85°CExtended temperature
32 Tost Oscillation Start-up Timer Period — 1024TOSC — — TOSC = OSC1 period
33* Tpwrt Power up Timer Period 28TBD
72TBD
132TBD
msms
VDD = 5V, -40°C to +85°C
34 TIOZ I/O Hi-impedance from MCLR Low or Watchdog Timer Reset
— — 2.0 µs
35 TBOD Brown-out Detect pulse width 100 — — µs VDD ≤ BVDD (D005)
VDD
MCLR
InternalPOR
PWRTTimeout
OSCTimeout
InternalRESET
WatchdogTimer
RESET
33
32
30
3134
I/O Pins
34
VDD BVDD
35
PIC16F62X
DS40300B-page 142 Preliminary 1999 Microchip Technology Inc.
FIGURE 17-10: TIMER0 AND TIMER1 EXTERNAL CLOCK TIMINGS
46
47
45
48
41
42
40
RA4/T0CKI
RB6/T1OSO/T1CKI
TMR0 orTMR1
1999 Microchip Technology Inc. Preliminary DS40300B-page 143
PIC16F62X
TABLE 17-7: TIMER0 AND TIMER1 EXTERNAL CLOCK REQUIREMENTS
FIGURE 17-11: CAPTURE/COMPARE/PWM TIMINGS
Param No.
Sym Characteristic Min Typ† Max Units Conditions
40* Tt0H T0CKI High Pulse Width No Prescaler 0.5TCY + 20 — — nsWith Prescaler 10 — — ns
41* Tt0L T0CKI Low Pulse Width No Prescaler 0.5TCY + 20 — — ns With Prescaler 10 — — ns
42* Tt0P T0CKI Period Greater of: TCY + 40
N
— — ns N = prescale value (2, 4, ..., 256)
45* Tt1H T1CKI High Time
Synchronous, No Prescaler 0.5TCY + 20 — — ns Synchronous, with Prescaler
16F62X 15 — — ns 16LF62X 25 — — ns
Asynchronous 16F62X 30 — — ns 16LF62X 50 — — ns
46* Tt1L T1CKI Low Time
Synchronous, No Prescaler 0.5TCY + 20 — — ns Synchronous, with Prescaler
16F62X 15 — — ns 16LF62X 25 — — ns
Asynchronous 16F62X 30 — — ns 16LF62X 50 — — ns
47* Tt1P T1CKI input period
Synchronous 16F62X Greater of: TCY + 40
N
— — ns N = prescale value (1, 2, 4, 8)
16LF62X Greater of:TCY + 40
N
— — —
Asynchronous 16F62X 60 — — ns 16LF62X 100 — — ns
Ft1 Timer1 oscillator input frequency range (oscillator enabled by setting bit T1OSCEN)
DC — 200 kHz
48 TCKEZtmr1 Delay from external clock edge to timer increment
2Tosc — 7Tosc
—
* These parameters are characterized but not tested.†Data in "Typ" column is at 5V, 25°C unless otherwise stated. These parameters are for design guidance only and are not tested.
(Capture Mode)
50 51
52
53 54
RB3/CCP1
(Compare or PWM Mode)
RB3/CCP1
PIC16F62X
DS40300B-page 144 Preliminary 1999 Microchip Technology Inc.
TABLE 17-8: CAPTURE/COMPARE/PWM REQUIREMENTS
FIGURE 17-12: TIMER0 CLOCK TIMING
TABLE 17-9: TIMER0 CLOCK REQUIREMENTS
Param No.
Sym Characteristic Min Typ† Max Units Conditions
50* TccL CCP input low time
No Prescaler 0.5TCY + 20 — — ns
With Prescaler16F62X 10 — — ns
16LF62X 20 — — ns
51* TccH CCPinput high time
No Prescaler 0.5TCY + 20 — — ns
With Prescaler16F62X 10 — — ns
16LF62X 20 — — ns
52* TccP CCP input period 3TCY + 40N
— — ns N = prescale value (1,4 or 16)
53* TccR CCP output rise time 16F62X 10 25 ns
16LF62X 25 45 ns
54* TccF CCP output fall time 16F62X 10 25 ns
16LF62X 25 45 ns
* These parameters are characterized but not tested.†Data in "Typ" column is at 5V, 25°C unless otherwise stated. These parameters are for design guidance only and are not tested.
Parameter No.
Sym Characteristic Min Typ† Max Units Conditions
40 Tt0H T0CKI High Pulse Width No Prescaler 0.5 TCY + 20* — — ns
With Prescaler 10* — — ns
41 Tt0L T0CKI Low Pulse Width No Prescaler 0.5 TCY + 20* — — ns
With Prescaler 10* — — ns
42 Tt0P T0CKI Period TCY + 40*N
— — ns N = prescale value (1, 2, 4, ..., 256)
* These parameters are characterized but not tested.† Data in "Typ" column is at 5.0V, 25°C unless otherwise stated. These parameters are for design guidance only and are
not tested.
41
42
40
RA4/T0CKI
TMR0
1999 Microchip Technology Inc. Preliminary DS40300B-page 145
PIC16F62X
18.0 DEVICE CHARACTERIZATION INFORMATION
Not Available at this time.
PIC16F62X
DS40300B-page 146 Preliminary 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 147
PIC16F62X
19.0 PACKAGING INFORMATION
19.1 Package Marking Information
20-Lead SSOP
XXXXXXXXXXAABBCDE
XXXXXXXXXX
18-Lead SOIC (.300")
XXXXXXXXXXXX
AABBCDEXXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
AABBCDE
18-Lead PDIP
Example
-04I / 2189951 CBP
PIC16F627
Example
-04I / S0218
9918 CDK
PIC16F627
PIC16F627-04I / P456
9923 CBA
Example
Legend: MM...M Microchip part number informationXX...X Customer specific information*AA Year code (last 2 digits of calendar year)BB Week code (week of January 1 is week ‘01’)C Facility code of the plant at which wafer is manufactured
O = Outside VendorC = 5” Line S = 6” LineH = 8” Line
D Mask revision numberE Assembly code of the plant or country of origin in which
part was assembled
Note: In the event the full Microchip part number cannot be marked on one line, it willbe carried over to the next line thus limiting the number of available charactersfor customer specific information.
* Standard OTP marking consists of Microchip part number, year code, week code, facility code, maskrev#, and assembly code. For OTP marking beyond this, certain price adders apply. Please check withyour Microchip Sales Office. For QTP devices, any special marking adders are included in QTP price.
PIC16F62X
DS40300B-page 148 Preliminary 1999 Microchip Technology Inc.
Package Type: K04-007 18-Lead Plastic Dual In-line (P) – 300 mil
* Controlling Parameter.† Dimension “B1” does not include dam-bar protrusions. Dam-bar protrusions shall not exceed 0.003”
(0.076 mm) per side or 0.006” (0.152 mm) more than dimension “B1.”‡ Dimensions “D” and “E” do not include mold flash or protrusions. Mold flash or protrusions shall not
exceed 0.010” (0.254 mm) per side or 0.020” (0.508 mm) more than dimensions “D” or “E.”
Units INCHES* MILLIMETERSDimension Limits MIN NOM MAX MIN NOM MAXPCB Row Spacing 0.300 7.62Number of Pins n 18 18Pitch p 0.100 2.54Lower Lead Width B 0.013 0.018 0.023 0.33 0.46 0.58Upper Lead Width B1† 0.055 0.060 0.065 1.40 1.52 1.65Shoulder Radius R 0.000 0.005 0.010 0.00 0.13 0.25Lead Thickness c 0.005 0.010 0.015 0.13 0.25 0.38Top to Seating Plane A 0.110 0.155 0.155 2.79 3.94 3.94Top of Lead to Seating Plane A1 0.075 0.095 0.115 1.91 2.41 2.92Base to Seating Plane A2 0.000 0.020 0.020 0.00 0.51 0.51Tip to Seating Plane L 0.125 0.130 0.135 3.18 3.30 3.43Package Length D‡ 0.890 0.895 0.900 22.61 22.73 22.86Molded Package Width E‡ 0.245 0.255 0.265 6.22 6.48 6.73Radius to Radius Width E1 0.230 0.250 0.270 5.84 6.35 6.86Overall Row Spacing eB 0.310 0.349 0.387 7.87 8.85 9.83Mold Draft Angle Top α 5 10 15 5 10 15Mold Draft Angle Bottom β 5 10 15 5 10 15
R
n
2
1
D
E
c
eB
β
E1
α
p
A1
L
B1
B
A
A2
1999 Microchip Technology Inc. Preliminary DS40300B-page 149
PIC16F62X
Package Type: K04-051 18-Lead Plastic Small Outline (SO) – Wide, 300 mil
0.0140.0090.010
0.0110.0050.0050.0100.3940.2920.4500.0040.0480.093
MIN
nNumber of Pins
Mold Draft Angle BottomMold Draft Angle TopLower Lead Width
Chamfer DistanceOutside DimensionMolded Package WidthMolded Package Length
Overall Pack. Height
Lead ThicknessRadius CenterlineFoot AngleFoot LengthGull Wing RadiusShoulder Radius
StandoffShoulder Height
βα
R2R1
E1
A2A1
X
φ
B†cL1
L
E‡D‡
A
Dimension LimitsPitch
Units
p1818
00
1212
1515
4
0.020
0
0.0170.0110.015
0.0160.0050.005
0.4070.2960.4560.0080.0580.099
0.029
0.0190.0120.020
0.0210.0100.010
8
0.4190.2990.4620.0110.0680.104
00
1212
1515
0.420.270.38
0.410.130.130.50
10.337.51
11.580.191.472.50
0.25
0
0.360.230.25
0.280.130.13
10.017.42
11.430.101.222.36
0.74
4 8
0.480.300.51
0.530.250.25
10.647.59
11.730.281.732.64
INCHES*
0.050NOM MAX
1.27
MILLIMETERSMIN NOM MAX
n
2
1
R2
R1
L1
L
β
c
φ
X
45 °
D
p
B
E
E1
α
A1
A2
A
* Controlling Parameter.† Dimension “B” does not include dam-bar protrusions. Dam-bar protrusions shall not exceed 0.003”
(0.076 mm) per side or 0.006” (0.152 mm) more than dimension “B.”‡ Dimensions “D” and “E” do not include mold flash or protrusions. Mold flash or protrusions shall not
exceed 0.010” (0.254 mm) per side or 0.020” (0.508 mm) more than dimensions “D” or “E.”
PIC16F62X
DS40300B-page 150 Preliminary 1999 Microchip Technology Inc.
Package Type: K04-072 20-Lead Plastic Shrink Small Outline (SS) – 5.30 mm
MINpPitch
Mold Draft Angle BottomMold Draft Angle TopLower Lead Width
Radius Centerline
Gull Wing RadiusShoulder RadiusOutside DimensionMolded Package WidthMolded Package Length
Shoulder HeightOverall Pack. Height
Lead Thickness
Foot AngleFoot Length
Standoff
Number of Pins
βα
c
φ
A2A1An
E1
B†
L1
R2L
R1
E‡D‡
Dimension LimitsUnits
0.650.026
8
00
55 10
100.0120.0070.005
0.0200.0050.0050.3060.2080.2830.0050.0360.073
20
0.301
0
0.0100.0050.000
0.0150.0050.005
0.2050.2780.0020.0260.068
0.311
0.0150.0090.010
0.0250.0100.010
4 8
0.2120.2890.0080.0460.078
00 5
5 1010
7.65
0.250.130.00
0.380.130.13
0
5.207.070.050.661.73
7.907.78
4
0.320.180.13
0.130.51
0.13
0.380.220.25
0.250.64
0.25
5.297.200.13
201.860.91
5.387.330.21
1.991.17
NOMINCHES
MAX NOMMILLIMETERS*
MIN MAX
n 12
R1
R2
D
p
B
E1
E
L1
L
c
β
φ
α
A1A
A2
* Controlling Parameter.† Dimension “B” does not include dam-bar protrusions. Dam-bar protrusions shall not exceed 0.003”
(0.076 mm) per side or 0.006” (0.152 mm) more than dimension “B.”‡ Dimensions “D” and “E” do not include mold flash or protrusions. Mold flash or protrusions shall not
exceed 0.010” (0.254 mm) per side or 0.020” (0.508 mm) more than dimensions “D” or “E.”
1999 Microchip Technology Inc. Preliminary DS40300B-page 151
PIC16F62X
INDEX AA/D
Special Event Trigger (CCP)....................................... 65Absolute Maximum Ratings .............................................. 131ADDLW Instruction ........................................................... 115ADDWF Instruction ........................................................... 115ANDLW Instruction ........................................................... 115ANDWF Instruction ........................................................... 115Architectural Overview .......................................................... 9Assembler
MPASM Assembler................................................... 125
BBaud Rate Error .................................................................. 73Baud Rate Formula ............................................................. 73Baud Rates
Asynchronous Mode ................................................... 74Synchronous Mode ..................................................... 74
BCF Instruction ................................................................. 116Block Diagram
TIMER0....................................................................... 45TMR0/WDT PRESCALER .......................................... 48
Block DiagramsComparator I/O Operating Modes............................... 58Comparator Output ..................................................... 60RA3:RA0 and RA5 Port Pins ...................................... 35Timer1......................................................................... 51Timer2......................................................................... 54USART Receive.......................................................... 80USART Transmit......................................................... 78
BRGH bit ............................................................................. 73Brown-Out Detect (BOD) .................................................. 101BSF Instruction ................................................................. 116BTFSC Instruction............................................................. 116BTFSS Instruction............................................................. 117
CCALL Instruction ............................................................... 117Capture (CCP Module) ....................................................... 64
Block Diagram............................................................. 64CCP Pin Configuration................................................ 64CCPR1H:CCPR1L Registers...................................... 64Changing Between Capture Prescalers...................... 64Software Interrupt ....................................................... 64Timer1 Mode Selection ............................................... 64
Capture/Compare/PWM (CCP)........................................... 63CCP1 .......................................................................... 63
CCP1CON Register ............................................ 63CCPR1H Register............................................... 63CCPR1L Register ............................................... 63
CCP2 .......................................................................... 63Timer Resources......................................................... 63
CCP1CON Register ............................................................ 63CCP1M3:CCP1M0 Bits............................................... 63CCP1X:CCP1Y Bits .................................................... 63
CCP2CON RegisterCCP2M3:CCP2M0 Bits............................................... 63CCP2X:CCP2Y Bits .................................................... 63
Clocking Scheme/Instruction Cycle .................................... 12CLRF Instruction ............................................................... 117CLRW Instruction.............................................................. 117CLRWDT Instruction ......................................................... 118CMCON Register ................................................................ 57Code Protection ................................................................ 112COMF Instruction.............................................................. 118Comparator Configuration................................................... 58
Comparator Interrupts......................................................... 61Comparator Module............................................................ 57Comparator Operation........................................................ 59Comparator Reference ....................................................... 59Compare (CCP Module) ..................................................... 65
Block Diagram ............................................................ 65CCP Pin Configuration ............................................... 65CCPR1H:CCPR1L Registers ..................................... 65Software Interrupt ....................................................... 65Special Event Trigger ................................................. 65Timer1 Mode Selection............................................... 65
Configuration Bits ............................................................... 96Configuring the Voltage Reference..................................... 69Crystal Operation................................................................ 97
DDATA .................................................................................. 93Data .................................................................................... 93Data EEPROM Memory...................................................... 91
EECON1 Register ...................................................... 91EECON2 Register ...................................................... 91
Data Memory Organization................................................. 13DECF Instruction .............................................................. 118DECFSZ Instruction.......................................................... 118Development Support ....................................................... 125
EEECON1............................................................................. 92Errata .................................................................................... 3External Crystal Oscillator Circuit ....................................... 98
GGeneral purpose Register File............................................ 13GOTO Instruction.............................................................. 119
II/O Ports ............................................................................. 27I/O Programming Considerations ....................................... 44ID Locations...................................................................... 112INCF Instruction................................................................ 119INCFSZ Instruction ........................................................... 119In-Circuit Serial Programming........................................... 112Indirect Addressing, INDF and FSR Registers ................... 26Instruction Flow/Pipelining.................................................. 12Instruction Set
ADDLW..................................................................... 115ADDWF .................................................................... 115ANDLW..................................................................... 115ANDWF .................................................................... 115BCF .......................................................................... 116BSF........................................................................... 116BTFSC...................................................................... 116BTFSS ...................................................................... 117CALL......................................................................... 117CLRF ........................................................................ 117CLRW ....................................................................... 117CLRWDT .................................................................. 118COMF ....................................................................... 118DECF........................................................................ 118DECFSZ ................................................................... 118GOTO ....................................................................... 119INCF ......................................................................... 119INCFSZ..................................................................... 119IORLW...................................................................... 119IORWF...................................................................... 120MOVF ....................................................................... 120MOVLW .................................................................... 120MOVWF.................................................................... 120
PIC16F62X
DS40300B-page 152 Preliminary 1999 Microchip Technology Inc.
NOP .......................................................................... 121OPTION .................................................................... 121RETFIE ..................................................................... 121RETLW ..................................................................... 121RETURN ................................................................... 122RLF ........................................................................... 122RRF........................................................................... 122SLEEP ...................................................................... 122SUBLW ..................................................................... 123SUBWF ..................................................................... 123SWAPF ..................................................................... 124TRIS.......................................................................... 124XORLW..................................................................... 124XORWF..................................................................... 124
Instruction Set Summary................................................... 113INT Interrupt ...................................................................... 108INTCON Register ................................................................ 21Interrupt Sources
Capture Complete (CCP)............................................ 64Compare Complete (CCP).......................................... 65TMR2 to PR2 Match (PWM) ....................................... 66
Interrupts ........................................................................... 107Interrupts, Enable Bits
CCP1 Enable (CCP1IE Bit)......................................... 64Interrupts, Flag Bits
CCP1 Flag (CCP1IF Bit) ....................................... 64, 65IORLW Instruction............................................................. 119IORWF Instruction............................................................. 120
KKeeLoq Evaluation and Programming Tools.................. 128
MMemory Organization
Data EEPROM Memory.............................................. 91MOVF Instruction .............................................................. 120MOVLW Instruction ........................................................... 120MOVWF Instruction........................................................... 120MPLAB Integrated Development Environment Software .. 125
NNOP Instruction................................................................. 121
OOPTION Instruction........................................................... 121OPTION Register ................................................................ 20Oscillator Configurations ..................................................... 97Oscillator Start-up Timer (OST) ........................................ 101Output of TMR2................................................................... 54
PPackage Marking Information ........................................... 147Packaging Information ...................................................... 147PCL and PCLATH ............................................................... 25PCON Register ................................................................... 24PICDEM-1 Low-Cost PICmicro Demo Board.................... 127PICDEM-2 Low-Cost PIC16CXX Demo Board ................. 127PICDEM-3 Low-Cost PIC16CXXX Demo Board............... 127PICSTART Plus Entry Level Development System ....... 127PIE1 Register ...................................................................... 22Pin Functions
RC6/TX/CK ...........................................................71–88RC7/RX/DT ........................................................... 71–88
Pinout Description ............................................................... 11PIR1 Register...................................................................... 23Port RB Interrupt ............................................................... 108PORTA................................................................................ 27PORTB................................................................................ 34Power Control/Status Register (PCON) ............................ 102
Power-Down Mode (SLEEP) ............................................ 111Power-On Reset (POR) .................................................... 101Power-up Timer (PWRT) .................................................. 101PR2 Register ...................................................................... 54Prescaler............................................................................. 48Prescaler, Capture.............................................................. 64Prescaler, Timer2 ............................................................... 66PRO MATE II Universal Programmer ............................ 127Program Memory Organization........................................... 13PROTECTION .................................................................... 93PWM (CCP Module) ........................................................... 66
Block Diagram ............................................................ 66CCPR1H:CCPR1L Registers...................................... 66Duty Cycle .................................................................. 66Example Frequencies/Resolutions ............................. 67Output Diagram .......................................................... 66Period ......................................................................... 66Set-Up for PWM Operation......................................... 67TMR2 to PR2 Match ................................................... 66
QQ-Clock............................................................................... 66Quick-Turnaround-Production (QTP) Devices...................... 7
RRC Oscillator....................................................................... 98READING ........................................................................... 93Registers
MapsPIC16C76 ........................................................... 14PIC16C77 ........................................................... 14
RCSTADiagram .............................................................. 72
Reset .................................................................................. 99RETFIE Instruction ........................................................... 121RETLW Instruction............................................................ 121RETURN Instruction ......................................................... 122RLF Instruction ................................................................. 122RRF Instruction................................................................. 122
SSEEVAL Evaluation and Programming System............. 128Serialized Quick-Turnaround-Production (SQTP) Devices.................................................................... 7SLEEP Instruction............................................................. 122Software Simulator (MPLAB-SIM) .................................... 126Special ................................................................................ 99Special Features of the CPU .............................................. 95Special Function Registers ................................................. 15Stack................................................................................... 25Status Register ................................................................... 19SUBLW Instruction ........................................................... 123SUBWF Instruction ........................................................... 123SWAPF Instruction ........................................................... 124
TT1CKPS0 bit ....................................................................... 50T1CKPS1 bit ....................................................................... 50T1CON Register ................................................................. 50T1OSCEN bit ...................................................................... 50T1SYNC bit......................................................................... 50T2CKPS0 bit ....................................................................... 55T2CKPS1 bit ....................................................................... 55T2CON Register ................................................................. 55
1999 Microchip Technology Inc. Preliminary DS40300B-page 153
PIC16F62X
Timer0TIMER0....................................................................... 45TIMER0 (TMR0) Interrupt ........................................... 45TIMER0 (TMR0) Module............................................. 45TMR0 with External Clock........................................... 47
Timer1Special Event Trigger (CCP)....................................... 65Switching Prescaler Assignment................................. 49
Timer2PR2 Register............................................................... 66TMR2 to PR2 Match Interrupt ..................................... 66
TimersTimer1
Asynchronous Counter Mode ............................. 52Block Diagram .................................................... 51Capacitor Selection............................................. 52External Clock Input............................................ 51External Clock Input Timing ................................ 52Operation in Timer Mode .................................... 51Oscillator ............................................................. 52Prescaler....................................................... 51, 53Resetting of Timer1 Registers ............................ 53Resetting Timer1 using a CCP Trigger Output ... 53Synchronized Counter Mode .............................. 51T1CON................................................................ 50TMR1H ............................................................... 52TMR1L ................................................................ 52
Timer2Block Diagram .................................................... 54Module ................................................................ 54Postscaler ........................................................... 54Prescaler............................................................. 54T2CON................................................................ 55
Timing DiagramsTimer0....................................................................... 142Timer1....................................................................... 142USART Asynchronous Master Transmission.............. 79USART RX Pin Sampling...................................... 76, 77USART Synchronous Reception................................. 87USART Synchronous Transmission ........................... 85USART, Asynchronous Reception.............................. 81
Timing Diagrams and Specifications................................. 139TMR0 Interrupt .................................................................. 108TMR1CS bit ........................................................................ 50TMR1ON bit ........................................................................ 50TMR2ON bit ........................................................................ 55TOUTPS0 bit....................................................................... 55TOUTPS1 bit....................................................................... 55TOUTPS2 bit....................................................................... 55TOUTPS3 bit....................................................................... 55TRIS Instruction ................................................................ 124TRISA ................................................................................. 27TRISB ................................................................................. 34TXSTA Register .................................................................. 71
UUniversal Synchronous Asynchronous Receiver Transmitter (USART) .......................................................... 71
Asynchronous ReceiverSetting Up Reception.......................................... 83Timing Diagram .................................................. 81
Asynchronous Receiver ModeBlock Diagram .................................................... 83Section................................................................ 83
USARTAsynchronous Mode................................................... 78Asynchronous Receiver.............................................. 80Asynchronous Reception............................................ 82Asynchronous Transmission ...................................... 79Asynchronous Transmitter.......................................... 78Baud Rate Generator (BRG) ...................................... 73Sampling..................................................................... 76Synchronous Master Mode......................................... 84Synchronous Master Reception ................................. 86Synchronous Master Transmission ............................ 84Synchronous Slave Mode........................................... 88Synchronous Slave Reception ................................... 88Synchronous Slave Transmit...................................... 88Transmit Block Diagram ............................................. 78
VVoltage Reference Module ................................................. 69VRCON Register ................................................................ 69
WWatchdog Timer (WDT).................................................... 109WRITE ................................................................................ 93WRITING ............................................................................ 93WWW, On-Line Support ....................................................... 3
XXORLW Instruction ........................................................... 124XORWF Instruction........................................................... 124
PIC16F62X
DS40300B-page 154 Preliminary 1999 Microchip Technology Inc.
1999 Microchip Technology Inc. Preliminary DS40300B-page 155
PIC16F62X
Systems Information and Upgrade Hot Line
The Systems Information and Upgrade Line providessystem users a listing of the latest versions of all ofMicrochip’s development systems software products.Plus, this line provides information on how customerscan receive any currently available upgrade kits.TheHot Line Numbers are:
1-800-755-2345 for U.S. and most of Canada, and
1-602-786-7302 for the rest of the world.
Trademarks: The Microchip name, logo, PIC, PICmicro, PICSTART, PICMASTER and PRO MATE are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. FlexROM, MPLAB and fuzzy-LAB are trademarks and SQTP is a service mark of Micro-chip in the U.S.A.
All other trademarks mentioned herein are the property of their respective companies.
ON-LINE SUPPORT
Microchip provides on-line support on the MicrochipWorld Wide Web (WWW) site.
The web site is used by Microchip as a means to makefiles and information easily available to customers. Toview the site, the user must have access to the Internetand a web browser, such as Netscape or MicrosoftExplorer. Files are also available for FTP downloadfrom our FTP site.
Connecting to the Microchip Internet Web Site
The Microchip web site is available by using yourfavorite Internet browser to attach to:
www.microchip.com
The file transfer site is available by using an FTP ser-vice to connect to:
ftp://ftp.microchip.com
The web site and file transfer site provide a variety ofservices. Users may download files for the latestDevelopment Tools, Data Sheets, Application Notes,User’s Guides, Articles and Sample Programs. A vari-ety of Microchip specific business information is alsoavailable, including listings of Microchip sales offices,distributors and factory representatives. Other dataavailable for consideration is:
• Latest Microchip Press Releases• Technical Support Section with Frequently Asked
Questions • Design Tips• Device Errata
• Job Postings• Microchip Consultant Program Member Listing• Links to other useful web sites related to
Microchip Products• Conferences for products, Development Sys-
tems, technical information and more• Listing of seminars and events
981103
PIC16F62X
DS40300B-page 156 Preliminary 1999 Microchip Technology Inc.
READER RESPONSE
It is our intention to provide you with the best documentation possible to ensure successful use of your Microchip prod-uct. If you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentationcan better serve you, please FAX your comments to the Technical Publications Manager at (602) 786-7578.
Please list the following information, and use this outline to provide us with your comments about this Data Sheet.
1. What are the best features of this document?
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?
6. Is there any incorrect or misleading information (what and where)?
7. How would you improve this document?
8. How would you improve our software, systems, and silicon products?
To: Technical Publications Manager
RE: Reader Response
Total Pages Sent
From: Name
Company
Address
City / State / ZIP / Country
Telephone: (_______) _________ - _________
Application (optional):
Would you like a reply? Y N
Device: Literature Number:
Questions:
FAX: (______) _________ - _________
DS40300BPIC16F62X
1999 Microchip Technology Inc. Preliminary DS40300B-page 157
PIC16F62X
PIC16F62X PRODUCT IDENTIFICATION SYSTEM
To order or to obtain information, e.g., on pricing or delivery, please use the listed part numbers, and refer to the factory or the listedsales offices.
Sales and Support
Data SheetsProducts supported by a preliminary Data Sheet may have an errata sheet describing minor operational differences and recom-mended workarounds. To determine if an errata sheet exists for a particular device, please contact one of the following:
1. Your local Microchip sales office2. The Microchip Corporate Literature Center U.S. FAX: (602) 786-72773. The Microchip Worldwide Site (www.microchip.com)
Please specify which device, revision of silicon and Data Sheet (include Literature #) you are using.
New Customer Notification SystemRegister on our web site (www.microchip.com/cn) to receive the most current information on our products.
Pattern: 3-Digit Pattern Code for QTP (blank otherwise)
Package: P = PDIPSO = SOIC (Gull Wing, 300 mil body)SS = SSOP (209 mil)
Temperature - = 0°C to +70°CRange: I = –40°C to +85°C
E = –40°C to +125°C
Frequency 04 = 200kHz (LP osc)Range: 04 = 4 MHz (XT and ER osc)
20 = 20 MHz (HS osc)
Device: PIC16F62X :VDD range 3.0V to 5.5VPIC16F62XT:VDD range 3.0V to 5.5V (Tape and Reel)PIC16LF62X:VDD range 2.0V to 5.5VPIC16LF62XT:VDD range 2.0V to 5.5V (Tape and Reel)
Examples:g) PIC16F627 - 04/P 301 =
Commercial temp., PDIP pack-age, 4 MHz, normal VDD limits, QTP pattern #301.
h) PIC16LF627- 04I/SO = Industrial temp., SOIC pack-age, 200kHz, extended VDD limits.
PART NO. -XX X /XX XXX
PIC16F62X
DS40300B-page 158 1999 Microchip Technology Inc.
NOTES:
1999 Microchip Technology Inc. Preliminary DS40300B-page 159
PIC16F62X
NOTES:
2002 Microchip Technology Inc.
Information contained in this publication regarding deviceapplications and the like is intended through suggestion onlyand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.No representation or warranty is given and no liability isassumed by Microchip Technology Incorporated with respectto the accuracy or use of such information, or infringement ofpatents or other intellectual property rights arising from suchuse or otherwise. Use of Microchip’s products as critical com-ponents in life support systems is not authorized except withexpress written approval by Microchip. No licenses are con-veyed, implicitly or otherwise, under any intellectual propertyrights.
Trademarks
The Microchip name and logo, the Microchip logo, FilterLab,KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER,PICSTART, PRO MATE, SEEVAL and The Embedded ControlSolutions Company are registered trademarks of Microchip Tech-nology Incorporated in the U.S.A. and other countries.
dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,In-Circuit Serial Programming, ICSP, ICEPIC, microPort,Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,MXDEV, PICC, PICDEM, PICDEM.net, rfPIC, Select Modeand Total Endurance are trademarks of Microchip TechnologyIncorporated in the U.S.A.
Serialized Quick Turn Programming (SQTP) is a service markof Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of theirrespective companies.
© 2002, Microchip Technology Incorporated, Printed in theU.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999. The Company’s quality system processes and procedures are QS-9000 compliant for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs and microperipheral products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001 certified.
Note the following details of the code protection feature on PICmicro® MCUs.
• 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.
2002 Microchip Technology Inc.
MAMERICASCorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200 Fax: 480-792-7277Technical Support: 480-792-7627Web Address: http://www.microchip.comRocky Mountain2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7966 Fax: 480-792-7456
Atlanta500 Sugar Mill Road, Suite 200BAtlanta, GA 30350Tel: 770-640-0034 Fax: 770-640-0307Boston2 Lan Drive, Suite 120Westford, MA 01886Tel: 978-692-3848 Fax: 978-692-3821Chicago333 Pierce Road, Suite 180Itasca, IL 60143Tel: 630-285-0071 Fax: 630-285-0075Dallas4570 Westgrove Drive, Suite 160Addison, TX 75001Tel: 972-818-7423 Fax: 972-818-2924DetroitTri-Atria Office Building 32255 Northwestern Highway, Suite 190Farmington Hills, MI 48334Tel: 248-538-2250 Fax: 248-538-2260Kokomo2767 S. Albright Road Kokomo, Indiana 46902Tel: 765-864-8360 Fax: 765-864-8387Los Angeles18201 Von Karman, Suite 1090Irvine, CA 92612Tel: 949-263-1888 Fax: 949-263-1338New York150 Motor Parkway, Suite 202Hauppauge, NY 11788Tel: 631-273-5305 Fax: 631-273-5335San JoseMicrochip Technology Inc.2107 North First Street, Suite 590San Jose, CA 95131Tel: 408-436-7950 Fax: 408-436-7955Toronto6285 Northam Drive, Suite 108Mississauga, Ontario L4V 1X5, CanadaTel: 905-673-0699 Fax: 905-673-6509
ASIA/PACIFICAustraliaMicrochip Technology Australia Pty LtdSuite 22, 41 Rawson StreetEpping 2121, NSWAustraliaTel: 61-2-9868-6733 Fax: 61-2-9868-6755China - BeijingMicrochip Technology Consulting (Shanghai)Co., Ltd., Beijing Liaison OfficeUnit 915Bei Hai Wan Tai Bldg.No. 6 Chaoyangmen Beidajie Beijing, 100027, No. ChinaTel: 86-10-85282100 Fax: 86-10-85282104China - ChengduMicrochip Technology Consulting (Shanghai)Co., Ltd., Chengdu Liaison OfficeRm. 2401, 24th Floor, Ming Xing Financial TowerNo. 88 TIDU StreetChengdu 610016, ChinaTel: 86-28-6766200 Fax: 86-28-6766599China - FuzhouMicrochip Technology Consulting (Shanghai)Co., Ltd., Fuzhou Liaison OfficeUnit 28F, World Trade PlazaNo. 71 Wusi RoadFuzhou 350001, ChinaTel: 86-591-7503506 Fax: 86-591-7503521China - ShanghaiMicrochip Technology Consulting (Shanghai)Co., Ltd.Room 701, Bldg. BFar East International PlazaNo. 317 Xian Xia RoadShanghai, 200051Tel: 86-21-6275-5700 Fax: 86-21-6275-5060China - ShenzhenMicrochip Technology Consulting (Shanghai)Co., Ltd., Shenzhen Liaison OfficeRm. 1315, 13/F, Shenzhen Kerry Centre,Renminnan LuShenzhen 518001, ChinaTel: 86-755-2350361 Fax: 86-755-2366086Hong KongMicrochip Technology Hongkong Ltd.Unit 901-6, Tower 2, Metroplaza223 Hing Fong RoadKwai Fong, N.T., Hong KongTel: 852-2401-1200 Fax: 852-2401-3431IndiaMicrochip Technology Inc.India Liaison OfficeDivyasree Chambers1 Floor, Wing A (A3/A4)No. 11, O’Shaugnessey RoadBangalore, 560 025, IndiaTel: 91-80-2290061 Fax: 91-80-2290062
JapanMicrochip Technology Japan K.K.Benex S-1 6F3-18-20, ShinyokohamaKohoku-Ku, Yokohama-shiKanagawa, 222-0033, JapanTel: 81-45-471- 6166 Fax: 81-45-471-6122KoreaMicrochip Technology Korea168-1, Youngbo Bldg. 3 FloorSamsung-Dong, Kangnam-KuSeoul, Korea 135-882Tel: 82-2-554-7200 Fax: 82-2-558-5934SingaporeMicrochip Technology Singapore Pte Ltd.200 Middle Road#07-02 Prime CentreSingapore, 188980Tel: 65-334-8870 Fax: 65-334-8850TaiwanMicrochip Technology Taiwan11F-3, No. 207Tung Hua North RoadTaipei, 105, TaiwanTel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPEDenmarkMicrochip Technology Nordic ApSRegus Business CentreLautrup hoj 1-3Ballerup DK-2750 DenmarkTel: 45 4420 9895 Fax: 45 4420 9910FranceMicrochip Technology SARLParc d’Activite du Moulin de Massy43 Rue du Saule TrapuBatiment A - ler Etage91300 Massy, FranceTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79GermanyMicrochip Technology GmbHGustav-Heinemann Ring 125D-81739 Munich, GermanyTel: 49-89-627-144 0 Fax: 49-89-627-144-44ItalyMicrochip Technology SRLCentro Direzionale Colleoni Palazzo Taurus 1 V. Le Colleoni 120041 Agrate BrianzaMilan, Italy Tel: 39-039-65791-1 Fax: 39-039-6899883United KingdomArizona Microchip Technology Ltd.505 Eskdale RoadWinnersh TriangleWokingham Berkshire, England RG41 5TUTel: 44 118 921 5869 Fax: 44-118 921-5820
01/18/02
WORLDWIDE SALES AND SERVICE