Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications. No
representation or warranty is given and no liability is assumed by
Microchip Technology Incorporated with respect to the accuracy
or use of such information, or infringement of patents or other
intellectual property rights arising from such use or otherwise.
Use of Microchip’s products as critical components in life
support systems is not authorized except with express written
approval by Microchip. No licenses are conveyed, implicitly or
otherwise, under any intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, K
EELOQ,
MPLAB, PIC, PICmicro, PICSTART, PRO MATE and
PowerSmart are registered trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
FilterLab, microID, MXDEV, MXLAB, PICMASTER, SEEVAL
and The Embedded Control Solutions Company are registered
trademarks of Microchip Technology Incorporated in the U.S.A.
Accuron, dsPIC, dsPICDEM.net, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming,
ICSP, ICEPIC, microPort, Migratable Memory, MPASM, MPLIB,
MPLINK, MPSIM, PICC, PICkit, PICDEM, PICDEM.net,
PowerCal, PowerInfo, PowerTool, rfPIC, rfLAB, Select Mode,
SmartSensor, SmartShunt, SmartTel and Total Endurance are
trademarks of Microchip Technology Incorporated in the U.S.A.
and other countries.
Serialized Quick Turn Programming (SQTP) is a service mark of
Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received QS-9000 quality system
certification for its worldwide headquarters,
design and wafer fabrication facilities in
Chandler and Tempe, Arizona in July 1999
and Mountain View, California in March 2002.
The Company’s quality system processes and
procedures are QS-9000 compliant for its
PICmicro
devices, Serial EEPROMs, microperipherals,
non-volatile memory and analog products. In
addition, Microchip’s quality system for the
design and manufacture of development
systems is ISO 9001 certified.
®
8-bit MCUs, KEELOQ
®
code hopping
DS40039C - page ii 2003 Microchip Technology Inc.
PIC16F630/676
14-Pin FLASH-Based 8-Bit CMOS Microcontroller
High Performance RISC CPU:
• Only 35 instructions to learn
- All single cycle instructions except branches
• Operating speed:
- DC - 20 MHz oscillator/clock input
- DC - 200 ns instruction cycle
• Interrupt capability
• 8-level deep hardware stack
• Direct, Indirect, and Relative Addressing modes
Low Power Features:
• Standby Current:
- 1 nA @ 2.0V, typical
• Operating Current:
-8.5µA @ 32 kHz, 2.0V, typical
-100µA @ 1 MHz, 2.0V, typical
• Watchdog Timer Current
- 300 nA @ 2.0V, typical
• Timer1 oscillator current:
-4µA @ 32 kHz, 2.0V, typical
Special Microcontroller Features:
• Internal and external oscillator options
- Precision Internal 4 MHz oscillator factory
calibrated to ±1%
- External Oscillator support for crystals and
resonators
-5µs wake-up from SLEEP, 3.0V, typical
• Power saving SLEEP mode
• Wide operating voltage range - 2.0V to 5.5V
• Industrial and Extended temperature range
• Low power Power-on Reset (POR)
• Power-up Timer (PWRT) and Oscillator Start-up
Timer (OST)
• Brown-out Detect (BOD)
• Watchdog Timer (WDT) with independent
oscillator for reliable operation
• Multiplexed MCLR
• Interrupt-on-pin change
• Individual programmable weak pull-ups
• Programmable code protection
• High Endurance FLASH/EEPROM Cell
- 100,000 write FLASH endurance
- 1,000,000 write EEPROM endurance
- FLASH/Data EEPROM Retention: > 40 years
Device
PIC16F63010246412812–11/1
PIC16F67610246412812811/1
/Input-pin
Program
Memory
FLASH
(words)
Data Memory
SRAM
(bytes)
EEPROM
(bytes)
Peripheral Features:
• 12 I/O pins with individual direction control
• High current sink/source for direct LED drive
• Analog comparator module with:
- One analog comparator
- Programmable on-chip comparator voltage
(ch)
REF) module
Comparators
TM
(ICSPTM) via
reference (CV
- Programmable input multiplexing from device
inputs
- Comparator output is externally accessible
• Analog-to-Digital Converter module (PIC16F676):
- 10-bit resolution
- Programmable 8-channel input
- Voltage reference input
• Timer0: 8-bit timer/counter with 8-bit
programmable prescaler
3.0Ports A and C ............................................................................................................................................................................ 19
5.0Timer1 Module with Gate Control ............................................................................................................................................. 32
9.0Special Features of the CPU .................................................................................................................................................... 53
10.0 Instruction Set Summary ........................................................................................................................................................... 71
11.0 Development Support ............................................................................................................................................................... 79
13.0 DC and AC Characteristics Graphs and Tables ..................................................................................................................... 107
14.0 Packaging Information ............................................................................................................................................................ 117
Appendix A: Data Sheet Revision History ......................................................................................................................................... 121
Index ................................................................................................................................................................................................. 123
On-Line Support ................................................................................................................................................................................ 127
Systems Information and Upgrade Hot Line ..................................................................................................................................... 127
Product Identification System ........................................................................................................................................................... 129
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-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.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
2003 Microchip Technology Inc.DS40039C-page 3
PIC16F630/676
NOTES:
DS40039C-page 4 2003 Microchip Technology Inc.
PIC16F630/676
1.0DEVICE OVERVIEW
This document contains device specific information for
the PIC16F630/676. Additional information may be
found in the PICmicro
(DS33023), which may be obtained from your local
Microchip Sales Representative or downloaded from
the Microchip web site. The Reference Manual should
be considered a complementary document to this Data
FIGURE 1-1:PIC16F630/676 BLOCK DIAGRAM
OSC1/CLKIN
OSC2/CLKOUT
TM
Mid-Range Reference Manual
Configuration
FLASH
1K x 14
Program
Memory
Program
Oscillator
Bus
Internal
14
Instruction reg
Instruction
Decode &
Control
Timing
Generation
8
INT
13
Program Counter
8-Level Stack
(13-bit)
Direct Addr
Power-up
Time r
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Time r
Brown-out
Detect
RAM Addr
7
8
Sheet and is highly recommended reading for a better
understanding of the device architecture and operation
of the peripheral modules.
The PIC16F630 and PIC16F676 devices are covered
by this Data Sheet. They are identical, except the
PIC16F676 has a 10-bit A/D converter. They come in
14-pin PDIP, SOIC and TSSOP packages. Figure 1-1
shows a block diagram of the PIC16F630/676 devices.
Table 1-1 shows the pinout description.
Data Bus
Registers
Addr MUX
3
RAM
64
bytes
File
8
FSR reg
STATUS reg
ALU
W reg
9
MUX
Indirect
Addr
8
PORTA
RA0
RA1
RA2
RA3
RA4
RA5
PORTC
RC0
RC1
RC2
RC3
RC4
RC5
T1G
T1CKI
T0CKI
VREF
AN0 AN1 AN2 AN3
Timer0Timer1
Analog to Digital Converter
(PIC16F676 only)
AN4 AN5 AN6 AN7
MCLR
V
DD
VSS
Comparator
and reference
CIN- CIN+ COUT
Analog
EEDATA
128 bytes
8
EEPROM
EEADDR
DATA
2003 Microchip Technology Inc.DS40039C-page 5
PIC16F630/676
TABLE 1-1:PIC16F630/676 PINOUT DESCRIPTION
NameFunction
RA0/AN0/CIN+/ICSPDATRA0TTLCMOSBi-directional I/O w/ programmable pull-up and
AN0AN—A/D Channel 0 input
CIN+ANComparator input
ICSPDATTTLCMOSSerial Programming Data I/O
RA1/AN1/CIN-/V
ICSPCLK
RA2/AN2/COUT/T0CKI/INTRA2STCMOSBi-directional I/O w/ programmable pull-up and
The PIC16F630/676 devices have a 13-bit program
counter capable of addressing an 8K x 14 program
memory space. Only the first 1K x 14 (0000h - 03FFh)
for the PIC16F630/676 devices is physically implemented. Accessing a location above these boundaries
will cause a wrap around within the first 1K x 14 space.
The RESET vector is at 0000h and the interrupt vector
is at 0004h (see Figure 2-1).
FIGURE 2-1:PROGRAM MEMORY MAP
AND STACK FOR THE
PIC16F630/676
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
13
2.2Data Memory Organization
The data memory (see Figure 2-2) is partitioned into
two banks, which contain the General Purpose registers and the Special Function registers. The Special
Function registers are located in the first 32 locations of
each bank. Register locations 20h-5Fh are General
Purpose registers, implemented as static RAM and are
mapped across both banks. All other RAM is
unimplemented and returns ‘0’ when read. RP0
(STATUS<5>) is the bank select bit.
• RP0 = 0 Bank 0 is selected
• RP0 = 1 Bank 1 is selected
Note:The IRP and RP1 bits STATUS<7:6> are
reserved and should always be maintained
as ‘0’s.
2.2.1GENERAL PURPOSE REGISTER
FILE
The register file is organized as 64 x 8 in the
PIC16F630/676 devices. Each register is accessed,
either directly or indirectly, through the File Select
Register FSR (see Section 2.4).
RESET Vector
Interrupt Vector
On-chip Program
Memory
000h
0004
0005
03FFh
0400h
1FFFh
2003 Microchip Technology Inc.DS40039C-page 7
PIC16F630/676
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function registers are registers used by
the CPU and peripheral functions for controlling the
desired operation of the device (see Table 2-1). These
registers are static RAM.
The special registers can be classified into two sets:
core and peripheral. The Special Function registers
associated with the “core” are described in this section.
Those related to the operation of the peripheral
features are described in the section of that peripheral
feature.
TABLE 2-1:PIC16F630/676 SPECIAL REGISTERS SUMMARY BANK 0
Value on
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
Bank 0
00hINDFAddressing this location uses contents of FSR to address data memory (not a physical register)xxxx xxxx18,61
01hTMR0Timer0 Module’s Registerxxxx xxxx29
02hPCLProgram Counter's (PC) Least Significant Byte0000 000017
03hSTATUS
04hFSRIndirect data memory address pointerxxxx xxxx18
0ChPIR1
0Dh—Unimplemented——
0EhTMR1LHolding register for the Least Significant Byte of the 16-bit TMR1xxxx xxxx32
0FhTMR1HHolding register for the Most Significant Byte of the 16-bit TMR1xxxx xxxx32
Least Significant 2 bits of the left shifted result or 8 bits of the right shifted resultxxxx xxxx44
(3)
—ADCS2ADCS1ADCS0————-000 ----45,61
INTEDGT0CST0SEPSAPS2PS1PS0
(2)
(2)
RP1
—VRR—VR3VR2VR1VR00-0- 000042
RP0TOPDZDCC
——CMIE——TMR1IE00-- 0--014
WPUA5WPUA4
Reset, Brown-out Detect and Watchdog Timer Reset during normal operation.
—
WPUA2WPUA1WPUA0
——
POR,
Page
BOD
1111 111112,30
0001 1xxx11
---- --qq16
1000 00--16
--11 -11120
DS40039C-page 10 2003 Microchip Technology Inc.
PIC16F630/676
2.2.2.1STATUS Register
The STATUS register, shown in Register 2-1, contains:
• the arithmetic status of the ALU
• the RESET status
• the bank select bits for data memory (SRAM)
The STATUS register can be the destination for any
instruction, like any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bits are set or cleared according to the
device logic. Furthermore, the TO
writable. Therefore, the result of an instruction with the
STATUS register as destination may be different than
intended.
For example, CLRF STATUS will clear the upper three
bits and set the Z bit. This leaves the STATUS register
as 000u u1uu (where u = unchanged).
and PD bits are not
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
STATUS register, because these instructions do not
affect any STATUS bits. For other instructions not
affecting any STATUS bits, see the “Instruction Set
Summary”.
Note 1: Bits IRP and RP1 (STATUS<7:6>) are not
used by the PIC16F630/676 and should
be maintained as clear. Use of these bits
is not recommended, since this may affect
upward compatibility with future products.
2: The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtraction. See the SUBLW and SUBWF
instructions for examples.
REGISTER 2-1:STATUS — STATUS REGISTER (ADDRESS: 03h OR 83h)
Reserved ReservedR/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TOPDZDCC
bit 7bit 0
bit 7IRP: This bit is reserved and should be maintained as ‘0’
bit 6RP1: This bit is reserved and should be maintained as ‘0’
bit 5RP0: Register Bank Select bit (used for direct addressing)
1 = Bank 1 (80h - FFh)
0 = Bank 0 (00h - 7Fh)
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow
bit 0C: Carry/borrow
: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (ADDWF, ADDLW,SUBLW,SUBWF instructions)
For borrow,
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note:For borrow
the polarity is reversed.
bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
the polarity is reversed. A subtraction is executed by adding the two’s
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low order bit of the source register
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS40039C-page 11
PIC16F630/676
2.2.2.2OPTION Register
The OPTION register is a readable and writable
register, which contains various control bits to
configure:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS40039C-page 12 2003 Microchip Technology Inc.
PIC16F630/676
2.2.2.3INTCON Register
The INTCON register is a readable and writable
register, which contains the various enable and flag bits
for TMR0 register overflow, PORTA change and
external RA2/INT pin interrupts.
Note:Interrupt flag bits are set when an interrupt
condition occurs, regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to enabling
an interrupt.
REGISTER 2-3:INTCON — INTERRUPT CONTROL REGISTER (ADDRESS: 0Bh OR 8Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
GIEPEIET0IEINTERAIET0IFINTFRAIF
bit 7bit 0
bit 7GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5T0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4INTE: RA2/INT External Interrupt Enable bit
1 = Enables the RA2/INT external interrupt
0 = Disables the RA2/INT external interrupt
bit 3RAIE: Port Change Interrupt Enable bit
1 = Enables the PORTA change interrupt
0 = Disables the PORTA change interrupt
bit 2T0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 register has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interrupt occurred (must be cleared in software)
0 = The RA2/INT external interrupt did not occur
bit 0RAIF: Port Change Interrupt Flag bit
1 = When at least one of the PORTA <5:0> pins changed state (must be cleared in software)
0 = None of the PORTA <5:0> pins have changed state
(1)
(2)
Note 1: IOCA register must also be enabled.
2: T0IF bit is set when Timer0 rolls over. Timer0 is unchanged on RESET and should
be initialized before clearing T0IF bit.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS40039C-page 13
PIC16F630/676
2.2.2.4PIE1 Register
The PIE1 register contains the interrupt enable bits, as
shown in Register 2-4.
bit 7EEIF: EEPROM Write Operation Interrupt Flag bit
1 = The write operation completed (must be cleared in software)
0 = The write operation has not completed or has not been started
bit 6ADIF: A/D Converter Interrupt Flag bit (PIC16F676 only)
1 = The A/D conversion is complete (must be cleared in software)
0 = The A/D conversion is not complete
bit 5-4Unimplemented: Read as ‘0’
bit 3CMIF: Comparator Interrupt Flag bit
1 = Comparator input has changed (must be cleared in software)
0 = Comparator input has not changed
bit 2-1Unimplemented: Read as ‘0’
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = TMR1 register overflowed (must be cleared in software)
0 = TMR1 register did not overflow
——CMIF——TMR1IF
Note:Interrupt flag bits are set when an interrupt
condition occurs, regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to enabling
an interrupt.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS40039C-page 15
PIC16F630/676
2.2.2.6PCON Register
The Power Control (PCON) register contains flag bits
to differentiate between a:
• Power-on Reset (POR)
• Brown-out Detect (BOD)
• Watchdog Timer Reset (WDT)
• External MCLR
The PCON Register bits are shown in Register 2-6.
REGISTER 2-6:PCON — POWER CONTROL REGISTER (ADDRESS: 8Eh)
Reset
U-0U-0U-0U-0U-0U-0R/W-0R/W-x
——————PORBOD
bit 7bit 0
bit 7-2Unimplemented: Read as '0'
bit 1POR
bit 0BOD
: Power-on Reset STATUS bit
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Detect STATUS bit
1 = No Brown-out Detect occurred
0 = A Brown-out Detect occurred (must be set in software after a Brown-out Detect occurs)
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2.2.2.7OSCCAL Register
The Oscillator Calibration register (OSCCAL) is used to
calibrate the internal 4 MHz oscillator. It contains 6 bits
to adjust the frequency up or down to achieve 4 MHz.
The OSCCAL register bits are shown in Register 2-7.
bit 7-2CAL5:CAL0: 6-bit Signed Oscillator Calibration bits
111111 = Maximum frequency
100000 = Center frequency
000000 = Minimum frequency
bit 1-0Unimplemented: Read as '0'
——
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS40039C-page 16 2003 Microchip Technology Inc.
PIC16F630/676
2.3PCL and PCLATH
The program counter (PC) is 13-bits wide. The low byte
comes from the PCL register, which is a readable and
writable register. The high byte (PC<12:8>) is not
directly readable or writable and comes from PCLATH.
On any RESET, the PC is cleared. Figure 2-3 shows the
two situations for the loading of the PC. The upper
example in Figure 2-3 shows how the PC is loaded on
a write to PCL (PCLATH<4:0> → PCH). The lower
example in Figure 2-3 shows how the PC is loaded
during a CALL or GOTO instruction (PCLATH<4:3> →
PCH).
FIGURE 2-3:LOADING OF PC IN
DIFFERENT SITUATIONS
PCHPCL
128 70
PC
PCLATH<4:0>
5
PCLATH
PCHPCL
12 11 100
PC
2
87
PCLATH<4:3>
11
8
Instruction with
PCL as
Destination
ALU result
GOTO, CALL
Opcode <10:0>
2.3.2STACK
The PIC16F630/676 family has an 8-level x 13-bit wide
hardware stack (see Figure 2-1). The stack space is
not part of either program or data space and the stack
pointer is not readable or writable. The PC is PUSHed
onto the stack when a CALL instruction is executed or
an interrupt causes a branch. The stack is POPed in
the event of a RETURN, RETLW or a RETFIE
instruction execution. PCLATH is not affected by a
PUSH or POP operation.
The stack operates as a circular buffer. This means that
after the stack has been PUSHed eight times, the ninth
push overwrites the value that was stored from the first
push. The tenth push overwrites the second push (and
so on).
Note 1: There are no STATUS bits to indicate
stack overflow or stack underflow
conditions.
2: There are no instructions/mnemonics
called PUSH or POP. These are actions
that occur from the execution of the
CALL, RETURN, RETLW and RETFIE
instructions or the vectoring to an
interrupt address.
PCLATH
2.3.1COMPUTED GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL). When perform-
ing a table read using a computed GOTO method, care
should be exercised if the table location crosses a PCL
memory boundary (each 256-byte block). Refer to the
Application Note “Implementing a Table Read"
(AN556).
2003 Microchip Technology Inc.DS40039C-page 17
PIC16F630/676
2.4Indirect Addressing, INDF and
FSR Registers
The INDF register is not a physical register. Addressing
A simple program to clear RAM location 20h-2Fh using
indirect addressing is shown in Example 2-1.
EXAMPLE 2-1:INDIRECT ADDRESSING
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF
register. Any instruction using the INDF register
actually accesses data pointed to by the File Select
register (FSR). Reading INDF itself indirectly will
produce 00h. Writing to the INDF register indirectly
results in a no operation (although STATUS bits may be
affected). An effective 9-bit address is obtained by
NEXTclrfINDF;clear INDF register
CONTINUE;yes continue
movlw0x20;initialize pointer
movwfFSR;to RAM
incfFSR;inc pointer
btfssFSR,4 ;all done?
gotoNEXT;no clear next
concatenating the 8-bit FSR register and the IRP bit
(STATUS<7>), as shown in Figure 2-4.
Note 1: The RP1 and IRP bits are reserved; always maintain these bits clear.
Not Used
1FFh
DS40039C-page 18 2003 Microchip Technology Inc.
PIC16F630/676
3.0PORTS A AND C
There are as many as twelve general purpose I/O pins
available. Depending on which peripherals are
enabled, some or all of the pins may not be available as
general purpose I/O. In general, when a peripheral is
enabled, the associated pin may not be used as a
general purpose I/O pin.
Note:Additional information on I/O ports may be
found in the PICmicro™ Mid-Range Reference Manual, (DS33023)
3.1PORTA and the TRISA Registers
PORTA is an 6-bit wide, bi-directional port. The corresponding data direction register is TRISA. Setting a
TRISA bit (= 1) will make the corresponding PORTA pin
an input (i.e., put the corresponding output driver in a
Hi-impedance mode). Clearing a TRISA bit (= 0) will
make the corresponding PORTA pin an output (i.e., put
the contents of the output latch on the selected pin).
The exception is RA3, which is input only and its TRIS
bit will always read as ‘1’. Example 3-1 shows how to
initialize PORTA.
Reading the PORTA register reads the status of the
pins, whereas writing to it will write to the port latch. All
write operations are read-modify-write operations.
Therefore, a write to a port implies that the port pins are
read, this value is modified and then written to the port
data latch. RA3 reads ‘0’ when MCLREN = 1.
The TRISA register controls the direction of the
PORTA pins, even when they are being used as analog
inputs. The user must ensure the bits in the TRISA
register are maintained set when using them as analog
inputs. I/O pins configured as analog input always read
‘0’.
Note:The ANSEL (9Fh) and CMCON (19h)
registers must be initialized to configure an
analog channel as a digital input. Pins
configured as analog inputs will read ‘0’.
The ANSEL register is defined for the
PIC16F676.
EXAMPLE 3-1:INITIALIZING PORTA
bcfSTATUS,RP0;Bank 0
clrfPORTA;Init PORTA
movlw05h;Set RA<2:0> to
movwfCMCON;digital I/O
bsfSTATUS,RP0;Bank 1
clrf ANSEL;digital I/O
movlw0Ch;Set RA<3:2> as inputs
movwfTRISA;and set RA<5:4,1:0>
;as outputs
bcfSTATUS,RP0;Bank 0
3.2Additional Pin Functions
Every PORTA pin on the PIC16F630/676 has an
interrupt-on-change option and every PORTA pin,
except RA3, has a weak pull-up option. The next two
sections describe these functions.
3.2.1WEAK PULL-UP
Each of the PORTA pins, except RA3, has an individually configurable weak internal pull-up. Control bits
WPUAx enable or disable each pull-up. Refer to
Register 3-3. Each weak pull-up is automatically turned
off when the port pin is configured as an output. The
pull-ups are disabled on a Power-on Reset by the
bit (OPTION<7>).
RAPU
REGISTER 3-1:PORTA — PORTA REGISTER (ADDRESS: 05h)
U-0U-0R/W-xR/W-xR/W-xR/W-xR/W-xR/W-x
——
bit 7bit 0
bit 7-6:Unimplemented: Read as ’0’
bit 5-0:PORTA<5:0>: PORTA I/O pin
1 = Port pin is >V
0 = Port pin is <VIL
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS40039C-page 19
IH
RA5RA4RA3RA2RA1RA0
PIC16F630/676
REGISTER 3-2:TRISA — PORTA TRISTATE REGISTER (ADDRESS: 85h)
U-0U-0R/W-xR/W-xR-1R/W-xR/W-xR/W-x
——
bit 7bit 0
bit 7-6:Unimplemented: Read as ’0’
bit 5-0:TRISA<5:0>: PORTA Tri-State Control bit
1 = PORTA pin configured as an input (tri-stated)
0 = PORTA pin configured as an output
Note:TRISA<3> always reads 1.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2: The weak pull-up device is automatically disabled if the pin is in Output mode
(TRISA = 0).
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
must be enabled for individual pull-ups to be enabled.
3.2.2INTERRUPT-ON-CHANGE
Each of the PORTA pins is individually configurable as
an interrupt-on-change pin. Control bits IOCAx enable
or disable the interrupt function for each pin. Refer to
Register 3-4. The interrupt-on-change is disabled on a
Power-on Reset.
For enabled interrupt-on-change pins, the values are
compared with the old value latched on the last read of
PORTA. The ‘mismatch’ outputs of the last read are
OR'd together to set, the PORTA Change Interrupt flag
bit (RAIF) in the INTCON register.
This interrupt can wake the device from SLEEP. The
user, in the Interrupt Service Routine, can clear the
interrupt in the following manner:
a)Any read or write of PORTA. This will end the
mismatch condition.
b) Clear the flag bit RAIF.
A mismatch condition will continue to set flag bit RAIF.
Reading PORTA will end the mismatch condition and
allow flag bit RAIF to be cleared.
Note:If a change on the I/O pin should occur
when the read operation is being executed
(start of the Q2 cycle), then the RAIF
interrupt flag may not get set.
DS40039C-page 20 2003 Microchip Technology Inc.
PIC16F630/676
REGISTER 3-4:IOCA — INTERRUPT-ON-CHANGE PORTA REGISTER (ADDRESS: 96h)
U-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
——IOCA5IOCA4IOCA3IOCA2IOCA1IOCA0
bit 7bit 0
bit 7-6Unimplemented: Read as ‘0’
bit 5-0IOCA<5:0>: Interrupt-on-Change PORTA Control bit
Note: Global interrupt enable (GIE) must be enabled for individual interrupts to be
recognized.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
2003 Microchip Technology Inc.DS40039C-page 21
PIC16F630/676
3.2.3PIN DESCRIPTIONS AND
DIAGRAMS
Each PORTA pin is multiplexed with other functions.
The pins and their combined functions are briefly
described here. For specific information about individual functions such as the comparator or the A/D, refer
to the appropriate section in this Data Sheet.
3.2.3.1RA0/AN0/CIN+
Figure 3-1 shows the diagram for this pin. The RA0 pin
is configurable to function as one of the following:
• a general purpose I/O
• an analog input for the A/D (PIC16F676 only)
• an analog input to the comparator
3.2.3.2RA1/AN1/CIN-/VREF
Figure 3-1 shows the diagram for this pin. The RA1 pin
is configurable to function as one of the following:
• as a general purpose I/O
• an analog input for the A/D (PIC16F676 only)
• an analog input to the comparator
• a voltage reference input for the A/D (PIC16F676
only)
FIGURE 3-1:BLOCK DIAGRAM OF RA0
AND RA1 PINS
Analog
Data Bus
WR
WPUA
RD
WPUA
WR
PORTA
WR
TRISA
RD
TRISA
RD
PORTA
WR
IOCA
RD
IOCA
D
CK
D
CK
D
CK
D
CK
Input Mode
Q
Q
RAPU
Q
Q
Q
Q
Analog
Input Mode
Q
Q
Q
Q
VDD
Weak
VDD
I/O pin
VSS
D
EN
D
Interrupt-on-Change
To Comparator
To A/D Converter
EN
RD PORTA
DS40039C-page 22 2003 Microchip Technology Inc.
PIC16F630/676
3.2.3.3RA2/AN2/T0CKI/INT/COUT
Figure 3-2 shows the diagram for this pin. The RA2 pin
is configurable to function as one of the following:
• a general purpose I/O
• an analog input for the A/D (PIC16F676 only)
• a digital output from the comparator
• the clock input for TMR0
• an external edge triggered interrupt
FIGURE 3-2:BLOCK DIAGRAM OF RA2
Analog
Data Bus
WR
WPUA
RD
WPUA
WR
PORTA
WR
TRISA
RD
TRISA
D
CK
D
CK
D
CK
Input Mode
Q
Q
RAPU
COUT
Enable
Q
Q
Q
Q
COUT
1
0
Analog
Input Mode
Analog
Input
Mode
VDD
Weak
VDD
I/O pin
VSS
3.2.3.4RA3/MCLR
/VPP
Figure 3-3 shows the diagram for this pin. The RA3 pin
is configurable to function as one of the following:
• a general purpose input
• as Master Clear Reset
FIGURE 3-3:BLOCK DIAGRAM OF RA3
Data Bus
RD
TRISA
RD
PORTA
D
WR
IOCA
RD
IOCA
Interrupt-on-Change
CK
RESET
VSS
Q
Q
MCLRE
MCLRE
Q
EN
Q
EN
RD PORTA
I/O pin
V
SS
D
D
RD
PORTA
D
WR
IOCA
RD
IOCA
Interrupt-on-Change
CK
To TMR0
To I N T
To A/D Converter
Q
D
Q
Q
EN
Q
EN
RD PORTA
D
2003 Microchip Technology Inc.DS40039C-page 23
PIC16F630/676
3.2.3.5RA4/AN3/T1G/OSC2/CLKOUT
Figure 3-4 shows the diagram for this pin. The RA4 pin
is configurable to function as one of the following:
• a general purpose I/O
• an analog input for the A/D (PIC16F676 only)
• a TMR1 gate input
• a crystal/resonator connection
• a clock output
FIGURE 3-4:BLOCK DIAGRAM OF RA4
Analog
Data Bus
WPUA
WPUA
PORTA
TRISA
TRISA
PORTA
IOCA
IOCA
Interrupt-on-Change
WR
RD
WR
WR
RD
RD
WR
RD
D
CK
D
CK
D
CK
D
CK
Input Mode
Q
Q
OSC1
F
Q
Q
Q
Q
Q
Q
OSC/4
CLKOUT
Enable
INTOSC/
RC/EC
CLKOUT
Enable
Input Mode
CLK
Modes
RAPU
Oscillator
Circuit
CLKOUT
Enable
1
0
(2)
Analog
Q
Q
(1)
VDD
Weak
VDD
I/O pin
VSS
D
EN
D
EN
3.2.3.6RA5/T1CKI/OSC1/CLKIN
Figure 3-5 shows the diagram for this pin. The RA5 pin
is configurable to function as one of the following:
• a general purpose I/O
• a TMR1 clock input
• a crystal/resonator connection
• a clock input
FIGURE 3-5:BLOCK DIAGRAM OF RA5
INTOSC
Data Bus
WPUA
WPUA
PORTA
TRISA
TRISA
PORTA
IOCA
IOCA
Interrupt-on-Change
WR
RD
WR
WR
RD
RD
WR
RD
D
CK
D
CK
D
CK
D
CK
Mode
Q
Q
Q
Q
Q
Q
Q
Q
RAPU
OSC2
INTOSC
Mode
RD PORTA
TMR1LPEN
Oscillator
Circuit
Q
Q
(1)
VDD
Weak
VDD
I/O pin
VSS
(1)
D
EN
D
EN
To TMR1 T1G
To A/D Converter
Note 1: CLK modes are XT, HS, LP, LPTMR1 and CLKOUT
Enable.
2: With CLKOUT option.
RD PORTA
To TMR1 or CLKGEN
Note 1: Timer1 LP Oscillator enabled
2: When using Timer1 with LP oscillator, the Schmitt
Trigger is by-passed.
DS40039C-page 24 2003 Microchip Technology Inc.
PIC16F630/676
TABLE 3-1:SUMMARY OF REGISTERS ASSOCIATED WITH PORTA
PORTC is a general purpose I/O port consisting of 6 bidirectional pins. The pins can be configured for either
digital I/O or analog input to A/D converter. For specific
information about individual functions such as the
comparator or the A/D, refer to the appropriate section
in this Data Sheet.
Note:The ANSEL register (9Fh) must be clear to
configure an analog channel as a digital
input. Pins configured as analog inputs will
read ‘0’. The ANSEL register is defined for
the PIC16F676.
EXAMPLE 3-2:INITIALIZING PORTC
bcfSTATUS,RP0;Bank 0
clrfPORTC;Init PORTC
bsfSTATUS,RP0;Bank 1
clrf ANSEL;digital I/O
movlw0Ch;Set RC<3:2> as inputs
movwfTRISC;and set RC<5:4,1:0>
;as outputs
bcfSTATUS,RP0;Bank 0
3.3.1RC0/AN4, RC1/AN5, RC2/AN6, RC3/
AN7
3.3.2RC4 AND RC5
The RC4 and RC5 pins are configurable to function as
a general purpose I/Os.
FIGURE 3-7:BLOCK DIAGRAM OF RC4
AND RC5 PINS
Data bus
VDD
I/O Pin
VSS
WR
PORTC
WR
TRISC
RD
TRISC
RD
PORTC
D
Q
CK
Q
D
Q
CK
Q
The RC0/RC1/RC2/RC3 pins are configurable to
function as one of the following: