9.0Special Features of the CPU..........................................................................................................................55
10.0Instruction Set Summary ................................................................................................................................73
Appendix C: What’s New ..........................................................................................................................................116
Index ...........................................................................................................................................................................127
List of Examples.......................................................................................................................................................... 129
List of Figures..............................................................................................................................................................129
List of Tables...............................................................................................................................................................130
We constantly strive to improve the quality of all our products and documentation. We have spent an exceptional
amount of time to ensure that these documents are correct. However, we realize that we may have missed a few
things. If you find any information that is missing or appears in error, please use the reader response form in the
back of this data sheet to inform us. We appreciate your assistance in making this a better document.
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 3
PIC16C64X & PIC16C66X
NOTES:
DS30559A-page 4
Preliminary
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
1.0GENERAL DESCRIPTION
PIC16C64X & PIC16C66X devices are 28-pin and
40-pin EPROM-based members of the versatile
PIC16CXXX family of low-cost, high-performance,
CMOS, fully-static, 8-bit microcontrollers.
All PIC16/17 microcontrollers employ an advanced
RISC architecture. The PIC16CXXX family has
enhanced core features, eight-level deep stack, and
multiple internal and external interrupt sources. The
separate instruction and data buses of the Harvard
architecture allow a 14-bit wide instruction word with
the separate 8-bit wide data. The two-stage instruction
pipeline allows all instructions to execute in a single-cycle, except for program branches (which require
two cycles). A total of 35 instructions (reduced instruction set) are available. Additionally, a large register set
gives some of the architectural innovations used to
achieve a very high performance.
PIC16CXXX microcontrollers typically achieve a 2:1
code compression and a 4:1 speed improvement over
other 8-bit microcontrollers in its class.
The PIC16C641 has 128 bytes of RAM and the
PIC16C642 has 176 bytes of RAM. Both devices have
22 I/O pins, and an 8-bit timer/counter with an 8-bit programmable prescaler. In addition, they have two analog
comparators with a programmable on-chip voltage reference module. Program Memory has internal parity
error detection circuitry with a Parity Error Reset. The
comparator module is ideally suited for applications
requiring a low-cost analog interface (e.g., battery
chargers, threshold detectors, white goods
controllers, etc.).
The PIC16C661 has 128 bytes of RAM and the
PIC16C662 has 176 bytes of RAM. Both devices have
33 I/O pins, and an 8-bit timer/counter with an 8-bit programmable prescaler. They also have an 8-bit Parallel
Slave Port. In addition, the devices have two analog
comparators with a programmable on-chip voltage reference module. Program Memory has internal parity
error detection circuitry with a Parity Error Reset. The
comparator module is ideally suited for applications
requiring a low-cost analog interface (e.g., battery
chargers, threshold detectors, white goods
controllers, etc.).
PIC16CXXX devices have special features to reduce
external components, thus reducing cost, enhancing
system reliability and reducing power consumption.
There are four oscillator options, of which the single pin
RC oscillator provides a low-cost solution, the LP
oscillator minimizes power consumption, XT is a
standard crystal, and the HS is for High Speed crystals.
The SLEEP (power-down) mode offers power saving.
The user can wake-up the chip from SLEEP through
several external and internal interrupts and resets.
A highly reliable Watchdog Timer (WDT) with its own
on-chip RC oscillator provides protection against software lock-up.
A UV-erasable CERDIP-packaged version is ideal for
code development while the cost-effective One-Time
Programmable (OTP) version is suitable for production
in any volume.
The PIC16CXXX series fit perfectly in applications
ranging from battery chargers to low-power remote
sensors. The EPROM technology makes
customization of application programs (detection
levels, pulse generation, timers, etc.) extremely fast
and convenient. The small footprint packages make
this microcontroller series perfect for all applications
with space limitations. Low-cost, low-power,
high-performance, ease of use, and I/O flexibility make
the PIC16C64X & PIC16C66X very versatile.
1.1F
Those users familiar with the PIC16C5X family of
microcontrollers will realize that this is an enhanced
version of the PIC16C5X architecture. Please refer to
Appendix A for a detailed list of enhancements. Code
written for PIC16C5X can be easily ported to the
PIC16C64X & PIC16C66X (Appendix B).
1.2De
PIC16C64X & PIC16C66X devices are supported by
the complete line of Microchip Development tools,
including:
• MPLAB Integrated Development Environment
including MPLAB-Simulator.
• MPASM Universal Assembler and MPLAB-C Universal C compiler.
• PRO MATE II and PICSTART Plus device programmers.
• PICMASTER In-circuit Emulator System
•
fuzzy
• DriveWay Visual Programming Tool
Please refer to Section 11.0 for more details about
these and other Microchip development tools.
All PIC16/17 Family devices have Power-on Reset, selectable Watchdog T imer, selectable code protect, and high I/O current
capability.
All PIC16CXXX Family devices use serial programming with clock pin RB6 and data pin RB7.
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
2.0PIC16C64X & PIC16C66X
DEVICE V ARIETIES
A variety of frequency ranges and packaging options
are available. Depending on application and production
requirements the proper device option can be selected
using the information in the Product Identification System page at the end of this data sheet. When placing
orders, please use that page of the data sheet to specify the correct part number.
2.1UV Erasab
The UV erasable version, offered in CERDIP package
is optimal for prototype development and pilot
programs. This version can be erased and
reprogrammed to any of the oscillator modes.
Microchip's PICSTART
programmers both support programming of the
PIC16C64X & PIC16C66X.
2.2One-Time-Pr
Devices
The availability of OTP devices is especially useful for
customers who need flexibility for frequent code
updates and small volume applications. In addition to
the program memory, the configuration bits must also
be programmed.
le Devices
Plus and PRO MATE
ogrammable (OTP)
2.3Quic
k-Turnaround-Production (QTP)
Devices
Microchip offers a QTP Programming Service for
factory production orders. This service is made
available for users who choose not to program a
medium to high quantity of units and whose code patterns have stabilized. The devices are identical to the
OTP devices but with all EPROM locations and configuration options already programmed by the factory.
Certain code and prototype verification procedures
apply before production shipments are available.
Please contact your Microchip Technology sales office
for more details.
2.4Serializ
Production (SQTP
II
Microchip offers a unique programming service where
a few user-defined locations in each device are
programmed with different serial numbers. The serial
numbers may be random, pseudo-random or
sequential.
Serial programming allows each device to have a
unique number which can serve as an entry-code,
password or ID number.
ed Quick-Turnaround-
SM
vices
) De
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 7
PIC16C64X & PIC16C66X
NOTES:
DS30559A-page 8
Preliminary
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
3.0ARCHITECTURAL OVERVIEW
The high performance of the PIC16C64X &
PIC16C66X devices can be attributed to a number of
architectural features commonly found in RISC microprocessors. To begin with, the PIC16C64X &
PIC16C66X use a Harvard architecture in which program and data are accessed from separate memories
using separate buses. This improves bandwidth over
traditional von Neumann architecture where program
and data are fetched from the same memory. Separating program and data memory further allows instructions to be sized differently than an 8-bit wide data
word. Instruction opcodes are 14-bits wide making it
possible to have all single word instructions. A 14-bit
wide program memory access bus fetches a 14-bit
instruction in a single cycle. A two-stage pipeline overlaps fetch and execution of instructions. Consequently,
all instructions (35) execute in a single cycle (200 ns @
20 MHz) except for program branches, which require
two cycles.
The PIC16C641 and PIC16C661 both address 2K x 14
on-chip program memory while the PIC16C642 and
PIC16C662 address 4K x 14. All program memory is
internal.
PIC16C64X & PIC16C66X devices can directly or indirectly address their register files or data memory. All
special function registers including the program
counter are mapped in the data memory. These
devices have an orthogonal (symmetrical) instruction
set that makes it possible to carry out any operation on
any register using any addressing mode. This symmetrical nature and lack of ‘special optimal situations’
make programming with the PIC16C64X & PIC16C66X
simple yet efficient. In addition, the learning curve is
reduced significantly.
PIC16C64X & PIC16C66X devices contain an 8-bit
ALU and working register. The ALU is a general purpose arithmetic unit. It performs arithmetic and Boolean functions between data in the working register and
any register file.
The ALU is 8-bits wide and capable of addition,
subtraction, shift, and logical operations. Unless
otherwise mentioned, arithmetic operations are two's
complement in nature. In two-operand instructions,
typically one operand is the working register
(W register). The other operand is a file register or an
immediate constant. In single operand instructions, the
operand is either the W register or a file register.
The W register is an 8-bit working register used for ALU
operations. It is not an addressable register.
Depending on the instruction executed, the ALU may
affect the values of the Carry (C), Digit Carry (DC), and
Zero (Z) bits in the STATUS register. The C and DC bits
operate as a Bo
respectively, bit in subtraction. See the SUBLW and
SUBWF instructions for examples.
rrow and Digit Borrow out bit,
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 9
PIC16C64X & PIC16C66X
FIGURE 3-1:PIC16C641/642 BLOCK DIAGRAM
PIC16C641 has 2K x 14 Program Memory and 128 x 8 RAM
PIC16C642 has 4K x 14 Program Memory and 176 x 8 RAM
Program
Bus
OSC1/CLKIN
OSC2/CLKOUT
EPROM
Program
Memory
14
Instruction reg
Instruction
Decode &
Control
Timing
Generation
13
Program Counter
8 Level Stack
Direct Addr
Power-up
Oscillator
Start-up Timer
Power-on
Watchdog
Brown-out
Parity Error
MCLR
(13-bit)
Timer
Reset
Timer
Reset
Reset
VDD, VSS
RAM Bank
Select
7
Data Bus
RAM
File
Registers
Addr MUX
STATUS reg
3
ALU
W reg
9
8
FSR reg
MUX
8
Indirect
Addr
Voltage
Reference
Comparator
-
+
-
+
Timer0
PORTA
PORTB
RA0/AN0
RA1/AN1
RA2/AN2/VREF
RA3/AN3
RA4/T0CKI
RA5
RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6
RB7
DS30559A-page 10
Preliminary
PORTC
RC0
RC1
RC2
RC3
RC4
RC5
RC6
RC7
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
FIGURE 3-2:PIC16C661/662 BLOCK DIAGRAM
PIC16C661 has 2K x 14 Program Memory and 128 x 8 RAM
PIC16C662 has 4K x 14 Program Memory and 176 x 8 RAM
OSC1/CLKIN9IST/CMOS Oscillator crystal input or external clock source input.
OSC2/CLKOUT10O—Oscillator crystal output. Connects to crystal or resonator in crystal
oscillator mode. In RC mode, OSC2 pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the instruction cycle rate.
MCLR
/V
PP
1I/PSTMaster clear (reset) input or programming voltage input. This pin is
an active low reset to the device.
PORTA is a bi-directional I/O port.
RA0/AN02I/OSTAnalog comparator input.
RA1/AN13I/OSTAnalog comparator input.
RA2/AN2/V
REF
4I/OSTAnalog comparator input or V
REF
output.
RA3/AN35I/OSTAnalog comparator input or comparator output.
RA4/T0CKI6I/OSTCan be selected to be the clock input to the Timer0 timer/counter
or a comparator output. Output is open drain type.
RA57I/OST
PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-ups on all inputs.
RB0/INT21I/O
TTL/ST
(1)
RB0 can also be selected as an external interrupt pin.
RB122I/OTTL
RB223I/OTTL
RB324I/OTTL
RB425I/OTTLInterrupt on change pin.
RB526I/OTTLInterrupt on change pin.
RB627I/O
RB728I/O
TTL/ST
TTL/ST
(2)
(2)
Interrupt on change pin. Serial programming clock.
Interrupt on change pin. Serial programming data.
PORTC is a bi-directional I/O port.
RC011I/OST
RC112I/OST
RC213I/OST
RC314I/OST
RC415I/OST
RC516I/OST
RC617I/OST
RC718I/OST
V
SS
V
DD
8,19P—Ground reference for logic and I/O pins.
20P—Positive supply for logic and I/O pins.
Legend:O = outputI/O = input/outputP = power
I = input— = not usedST = Schmitt Trigger input
TTL = TTL input
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in serial programming mode.
DS30559A-page 12
Preliminary
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
TABLE 3-2: PIC16C661/662 PINOUT DESCRIPTION
Name
OSC1/CLKIN133014IST/CMOS Oscillator crystal input or external clock source
OSC2/CLKOUT143115O—Oscillator crystal output. Connects to crystal or reso-
MCLR
/V
PP
RA0/AN02193I/OSTAnalog comparator input.
RA1/AN13204I/OSTAnalog comparator input.
RA2/AN2/V
RA3/AN35226I/OSTAnalog comparator input or comparator output.
RA4/T0CKI6237I/OSTCan be selected to be the clock input to the
RA57248I/OST
RB0/INT33836I/O
RB134937I/OTTL
RB2351038I/OTTL
RB3361139I/OTTL
RB4371441I/OTTLInterrupt on change pin.
RB5381542I/OTTLInterrupt on change pin.
RB6391643I/O
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in serial programming mode.
3: This buffer is a Schmitt Trigger input when configured as a general purpose I/O and a TTL input when used
in the Parallel Slave Port Mode (for interfacing to a microprocessor port).
DIP
Pin #
REF
QFP
Pin #
1182I/PSTMaster clear (reset) input or programming voltage
4215I/OSTAnalog comparator input or V
I = input— = not usedST = Schmitt Trigger input
TTL = TTL input
PLCC
Pin #
I/O/P
Type
Buffer
Type
TTL/ST
TTL/ST
TTL/ST
Description
input.
nator in crystal oscillator mode. In RC mode, OSC2
pin outputs CLKOUT which has 1/4 the frequency of
OSC1, and denotes the instruction cycle rate.
input. This pin is an active low reset to the device.
PORTA is a bi-directional I/O port.
output.
REF
Timer0 timer/counter or a comparator output.
Output is open drain type.
PORTB is a bi-directional I/O port. PORTB can be
software programmed for internal weak pull-ups on
all inputs.
(1)
(2)
(2)
RB0 can also be selected as an external
interrupt pin.
Interrupt on change pin. Serial programming
clock.
Interrupt on change pin. Serial programming
data.
PORTC is a bi-directional I/O port.
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 13
PIC16C64X & PIC16C66X
Name
DIP
Pin #
QFP
Pin #
PLCC
Pin #
I/O/P
Type
Buffer
Type
Description
PORTD can be a bi-directional I/O port or parallel
slave port for interfacing to a microprocessor bus.
RD0/PSP0193821I/OST/TTL
RD1/PSP1203922I/OST/TTL
RD2/PSP2214023I/OST/TTL
RD3/PSP3224124I/OST/TTL
RD4/PSP427230I/OST/TTL
RD5/PSP528331I/OST/TTL
RD6/PSP629432I/OST/TTL
RD7/PSP730533I/OST/TTL
(3)
(3)
(3)
(3)
(3)
(3)
(3)
(3)
PORTE is a bi-directional I/O port.
RE0/RD
RE1/WR
RE2/CS
V
SS
V
DD
8259I/OST/TTL
92610I/OST/TTL
102711I/OST/TTL
12,316,2913,34P—Ground reference for logic and I/O pins.
11,327,2812,35P—Positive supply for logic and I/O pins.
NC—12,13,
33,34
1,17
28,40
——Not Connected.
(3)
(3)
(3)
RE0/RD
read control for parallel slave port.
RE1/WR write control for parallel slave port.
RE2/CS
select control for parallel slave port.
Legend:O = outputI/O = input/outputP = power
I = input— = not usedST = Schmitt Trigger input
TTL = TTL input
Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.
2: This buffer is a Schmitt Trigger input when used in serial programming mode.
3: This buffer is a Schmitt Trigger input when configured as a general purpose I/O and a TTL input when used
in the Parallel Slave Port Mode (for interfacing to a microprocessor port).
DS30559A-page 14
Preliminary
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
3.1Cloc
king Scheme/Instruction Cycle
The clock input (from OSC1) is internally divided by
four to generate four non-overlapping quadrature
clocks namely Q1, Q2, Q3, and Q4. Internally, the
program counter (PC) is incremented every Q1, the
instruction is fetched from the program memory and
latched into the instruction register in Q4. The
instruction is decoded and executed during the
following Q1 through Q4. The clocks and instruction
execution flow is shown in Figure 3-3.
FIGURE 3-3:CLOCK/INSTRUCTION CYCLE
Q2Q3Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(RC mode)
Q1
PCPC+1PC+2
Fetch INST (PC)
Execute INST (PC-1)Fetch INST (PC+1)
Q1
3.2Instruction Flo
w/Pipelining
An “Instruction Cycle” consists of four Q cycles (Q1,
Q2, Q3, and Q4). The instruction fetch and execute are
pipelined such that fetch takes one instruction cycle
while decode and execute takes another instruction
cycle. However, due to the pipelining, each instruction
effectively executes in one cycle. If an instruction
causes the program counter to change (e.g., GOTO )
then two cycles 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 latched
into the “Instruction Register (IR)” in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3, and Q4 cycles. Data memory is read during Q2
(operand read) and written during Q4 (destination
write).
Q2Q3Q4
Execute INST (PC)Fetch INST (PC+2)
Q2Q3Q4
Q1
Execute INST (PC+1)
Internal
phase
clock
EXAMPLE 3-1:INSTRUCTION PIPELINE FLOW
Tcy0Tcy1Tcy2Tcy3Tcy4Tcy5
1. MOVLW 55h
2. MOVWF PORTB
3. CALL SUB_1
4. BSF PORTA, BIT3 (Forced NOP)
5. Instruction @ address SUB_1
All instructions are single cycle, except for any program branches. These take two cycles since the fetch
instruction is “flushed” from the pipeline while the new instruction is being fetched and then executed.
1996 Microchip Technology Inc.
Fetch 1Execute 1
Fetch 2Execute 2
Preliminary
Fetch 3Execute 3
Fetch 4Flush
Fetch SUB_1 Execute SUB_1
DS30559A-page 15
PIC16C64X & PIC16C66X
NOTES:
DS30559A-page 16
Preliminary
1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
4.0MEMORY ORGANIZATION
4.1Pr
The PIC16C64X & PIC16C66X have a 13-bit program
counter capable of addressing an 8K x 14 program
memory space. For the PIC16C641 and PIC16C661
only the first 2K x 14 (0000h - 07FFh) is physically
implemented. For the PIC16C642 and PIC16C662 only
the first 4K x 14 (0000h - 0FFh) is physically implemented. Accessing a location above the 2K or 4K
boundary will cause a wrap-around. The reset vector is
at 0000h and the interrupt vector is at 0004h (Figure 41 and Figure 4-2). See Section 4.4 for Program Memory paging.
FIGURE 4-1:PIC16C641/661 PROGRAM
CALL, RETURN
RETFIE, RETLW
ogram Memory Organization
MEMORY MAP AND STACK
PC<12:0>
13
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
0000h
FIGURE 4-2:PIC16C642/662 PROGRAM
MEMORY MAP AND STACK
PC<12:0>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 2
Stack Level 8
Reset Vector
Interrupt Vector
On-chip Program
Memory
Page0
User Memory Space
On-chip Program
Memory
Page1
13
0000h
0004h
0005h
07FFh
0800h
0FFFh
1000h
Interrupt Vector
User Memory Space
On-chip Program
Memory
TEST
Configuration Word
TEST
0004h
0005h
07FFh
0800h
1FFFh
2000h
2007h
3FFFh
TEST
Configuration Word
TEST
1FFFh
2000h
2007h
3FFFh
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 17
PIC16C64X & PIC16C66X
4.2D
The data memory (Figure 4-4) is partitioned into two
banks which contain the general purpose registers and
the special function registers. Bank 0 is selected when
bit RP0 (STATUS<5>) is cleared. Bank 1 is selected
when the RP0 bit is set. The Special Function Registers are located in the first 32 locations of each Bank.
Register locations A0h-EFh (Bank 1) are general purpose registers implemented as static RAM. Some special function registers are mapped in Bank 1.
4.2.1GENERAL PURPOSE REGISTER FILE
The register file is organized as 176 x 8 for the
PIC16C642/662, and 128 x8 for the PIC16C641/661.
Each is accessed either directly, or indirectly through
the File Select Register FSR (Section 4.5).
4.2.2SPECIAL FUNCTION REGISTERS
The special function registers are registers used by the
CPU and Peripheral Modules for controlling the desired
operation of the device (T able 4-1). These registers are
static RAM.
The special function registers can be classified into two
sets (core and peripheral). The special function registers associated with the “core” functions are described
in this section. Those related to the operation of the
peripheral features are described in the section of that
peripheral feature.
00hINDFAddressing this location uses contents of FSR to address data memory (not a physical register) xxxx xxxx xxxx xxxx
01hTMR0Timer0 Module’s Register
02hPCLProgram Counter's (PC) Least Significant Byte
03hSTATUSIRP
04hFSRIndirect data memory address pointer
05hPORTA
06hPORTBPORTB Data Latch when written: PORTB pins when read
06hPORTCPORTC Data Latch when written: PORTC pins when read
06hPORTD
06hPORTE
0AhPCLATH
0BhINTCONGIE PEIE T0IEINTERBIET0IFINTFRBIF
0ChPIR1PSPIF
0Dh-1Eh
1FhCMCONC2OUTC1OUT
Bank 1
80hINDFAddressing this location uses contents of FSR to address data memory (not a physical register) xxxx xxxx xxxx xxxx
81hOPTIONRBPU
82hPCLProgram Counter's (PC) Least Significant Byte
83hSTATUSIRP
84hFSRIndirect data memory address pointer
85hTRISA
86hTRISBPORTB Data Direction Register
86hTRISCPORTC Data Direction Register
86hTRISD
86hTRISE
8AhPCLATH
8BhINTCONGIEPEIET0IEINTERBIET0IFINTFRBIF 0000 000x 0000 000x
8ChPIE1PSPIE
8Dh
8EhPCONMPEEN
8Fh-9Eh
9FhVRCONVRENVROEVRR
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
2: The IRP and RP1 bits are reserved, always maintain these bits clear.
3: The PORTD, PORTE, TRISD, and TRISE registers are not implemented on the PIC16C641/642.
4: Bits PSPIE and PSPIF are reserved on the PIC16C641/642, always maintain these bits clear.
(3)
(3)
Unimplemented
(3)
(3)
Unimplemented
Unimplemented
(2)
——PORTA Data Latch when written: PORTA pins when read
PORTD Data Latch when written: PORTD pins when read
—
———Write buffer for upper 5 bits of program counter
(4)
(2)
——PORTA Data Direction Register
PORTD Data Direction Register
IBFOBFIBOVPSPMODE
———Write buffer for upper 5 bits of program counter
(4)
(2)
RP1
————RE2RE1RE0 ---- -xxx ---- -uuu
CMIF
INTEDGT0CST0SEPSAPS2PS1PS0 1111 1111 1111 1111
RP1
CMIE
————PERPORBOR
RP0T
—————— 00-- ---- 00-- ----
——CISCM2CM1CM0 00-- 0000 00-- 0000
(2)
RP0TOPDZDCC
—————— 00-- ---- 00-- ----
Reset and Watchdog Timer Reset during normal operation.
4.2.2.1STATUS REGISTER
The STATUS register, shown in Figure 4-5, contains
the arithmetic status of the ALU, the RESET status, and
the bank select bits for data memory.
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 T
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 000uu1uu (where u = unchanged).
O 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 bit. For other instructions, not affecting
any status bits, see the “Instruction Set Summary.”
Note 1: The IRP and RP1 bits (ST A TUS<7:6>) are
reserved on the PIC16C64X &
PIC16C66X and should be maintained
clear. Use of these bits as general purpose R/W bits is NOT recommended,
since this may affect upward compatibility
with future products.
Note 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.
FIGURE 4-5:STATUS REGISTER (ADDRESS 03h, 83h)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TOPDZDCCR = Readable bit
bit7bit0
bit 7: IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh)
0 = Bank 0, 1 (00h - FFh)
Bit IRP is reserved on the PIC16C64X & PIC16C66X, always maintain this bit clear.
bit 6-5: RP1:RP0 : Register Bank Select bits (used for direct addressing)
= Bank 3 (180h - 1FFh)
= Bank 2 (100h - 17Fh)
= Bank 1 (80h - FFh)
= Bank 0 (00h - 7Fh)
Each bank is 128 bytes. Bit RP1 is reserved on the PIC16C64X & PIC16C66X, always maintain this bit
clear.
bit 4: T
bit 3: PD
bit 2:Z: Zero bit
bit 1:DC: Digit carry/borrow
bit 0:C: Carry/borrow
O
: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (ADDWF , ADDLW,SUBLW,SUBWF instructions) (for borrow the polarity is reversed)
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
bit (ADDWF , ADDLW,SUBLW,SUBWF instructions)
1 = A carry-out from the most significant bit of the result occurred
0 = No carry-out from the most significant bit of the result occurred
Note: For borrow
second operand. For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low order bit of
the source register.
the polarity is reversed. A subtraction is executed by adding the two’s complement of the
W = Writable bit
U = Unimplemented bit,
read as ‘0’
- n = Value at POR reset
1996 Microchip Technology Inc.
Preliminary
DS30559A-page 21
PIC16C64X & PIC16C66X
4.2.2.2OPTION REGISTER
The OPTION register is a readable and writable
register which contains various control bits to configure
the TMR0/WDT prescaler, the external RB0/INT
interrupt, TMR0, and the weak pull-ups on PORTB.
FIGURE 4-6:OPTION REGISTER (ADDRESS 81h)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
RBPU
bit7bit0
bit 7:RBPU
bit 6:INTEDG: Interrupt Edge Select bit
bit 5:T0CS: TMR0 Clock Source Select bit
bit 4:T0SE: TMR0 Source Edge Select bit
bit 3:PSA: Prescaler Assignment bit
bit 2-0: PS2:PS0: Prescaler Rate Select bits
INTEDGT0CST0SEPSAPS2PS1PS0R= Readable bit
: PORTB Pull-up Enable bit
1 = PORTB pull-ups are disabled
0 = PORTB pull-ups are enabled by individual port latch values
1 = Interrupt on rising edge of RB0/INT pin
0 = Interrupt on falling edge of RB0/INT pin
4.2.2.4PIE1 REGISTER
This register contains the individual enable bits for the
comparator and Parallel Slave Port interrupts.
FIGURE 4-8:PIE1 REGISTER (ADDRESS 8Ch)
R/W-0R/W-0U-0U-0U-0U-0U-0U-0
(1)
PSPIE
bit7bit0
bit 7:PSPIE
bit 6:CMIE: Comparator Interrupt Enable bit
bit 5-0: Unimplemented: Read as '0'
CMIE——————R= Readable bit
(1)
: Parallel Slave Port Read/Write Interrupt Enable bit
1 = Enables the PSP read/write interrupt
0 = Disables the PSP read/write interrupt
1 = Enables the Comparator interrupt
0 = Disables the Comparator interrupt
W= Writable bit
U= Unimplemented bit,
read as ‘0’
- n= Value at POR reset
Note 1: Bit PSPIE is reserved on the PIC16C641/642, always maintain this bit clear.
DS30559A-page 24Preliminary 1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
4.2.2.5PIR1 REGISTER
This register contains the individual flag bits for the
comparator and Parallel Slave Port interrupts.
Note:Interrupt flag bits get set when an interrupt
FIGURE 4-9:PIR1 REGISTER (ADDRESS 0Ch)
R/W-0R/W-0U-0U-0U-0U-0U-0U-0
(1)
PSPIF
bit7bit0
bit 7:PSPIF
bit 6:CMIF: Comparator Interrupt Flag bit
bit 5-0: Unimplemented: Read as '0'
CMIF——————R= Readable bit
(1)
: Parallel Slave Port Interrupt Flag bit
1 = A read or write operation has taken place (must be cleared in software)
0 = No read or write operation has taken place
1 = Comparator input has changed (must be cleared in software)
0 = Comparator input has not changed
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.
W= Writable bit
U= Unimplemented bit,
read as ‘0’
- n= Value at POR reset
Note 1: Bit PSPIF is reserved on the PIC16C641/642, always maintain this bit clear.
4.2.2.6PCON REGISTER
The PCON register contains flag bits to differentiate
between a Power-on Reset (POR), an external MCLR
reset, WDT reset, Brown-out Reset (BOR), and Parity
Error Reset (PER). The PCON register also contains a
status bit, MPEEN, which reflects the value of the
MPEEN bit in Configuration Word. See Table 9-4 for
status of these bits on various resets.
Note:BOR is unknown on Power-on Reset. It
FIGURE 4-10: PCON REGISTER (ADDRESS 8Eh)
R-UU-0U-0U-0U-0R/W-1R/W-0R/W-u
MPEEN
bit7bit0
bit 7:MPEEN: Memory Parity Error Circuitry Status bit
bit 6-3: Unimplemented: Read as '0'
bit 2:PER
bit 1:POR
bit 0:BOR
————PERPORBORR= Readable bit
Reflects the value of Configuration Word bit, MPEEN
: Memory Parity Error Reset Status bit
1 = No error occurred
0 = Program memory fetch parity error occurred
(must be set in software after a Parity Error Reset occurs)
: 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 Reset Status bit
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred (must be set in software after a Brown-out Reset occurs)
must then be set by the user and checked
on subsequent resets to see if BOR
cleared, indicating a brown-out has
occurred. The BOR
care” and is not necessarily predictable if
the brown-out circuit is disabled (by
programming the BODEN bit in the
Configuration word).
W= Writable bit
U= Unimplemented bit,
read as ‘0’
- n= Value at POR reset
status bit is a “don't
is
DS30559A-page 26Preliminary 1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
4.3PCL and PCLATH
The program counter (PC) is 13-bits wide. The low byte
comes from the PCL register, which is readable and
writable. The high byte (PC<12:8>) is not directly readable or writable and comes from PCLATH. On any
reset, the PC is cleared. Figure 4-11 shows the two
situations for the loading of the PC. The upper example
in the figure shows how the PC is loaded on a write to
PCL (PCLATH<4:0> → PCH). The lower example in
the figure shows how the PC is loaded during a CALL
or GOTO instruction (PCLATH<4:3> → PCH).
FIGURE 4-11: LOADING OF PC IN
DIFFERENT SITUATIONS
PCHPCL
128 70
PC
PCLATH<4:0>
5
PCLATH
PCHPCL
12 11 100
PC
2
87
PCLATH<4:3>
PCLATH
11
4.3.1COMPUTED GOTO
A computed GOTO is accomplished by adding an
offset to the program counter (ADDWF PCL). When
doing a table read using a computed GOTO method,
care should be exercised if the table location crosses a
PCL memory boundary (each 256 byte block). Refer to
the application note
“Implementing a Table Read”
(AN556).
8
Instruction with
PCL as
Destination
ALU result
GOTO, CALL
Opcode <10:0>
4.3.2STACK
PIC16C64X & PIC16C66X devices have an 8 level
deep x 13-bit wide hardware stack (Figure 4-2). The
stack space is not part of either program or data space
and the stack pointer is not readable or writable. The
PC is PUSHed onto the 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.
Note 2: There are no instructions mnemonics
called PUSH or POP. These are actions
that occur from the execution of the CALL,RETURN, RETLW, and RETFIE instructions, or the vectoring to an interrupt
address.
4.4Program Memory Paging
PIC16C642 and PIC16C662 devices have 4K of program memory, but the CALL and GOTO instructions only
have an 11-bit address range. This 11-bit address
range allows a branch within a 2K program memory
page size. To allow CALL and GOTO instructions to
address the entire 4K program memory address range,
there must be another bit to specify the program memory page. This paging bit comes from the PCLATH<3>
bit (Figure 4-11). When doing a CALL or GOTO instruction, the user must ensure that this page select bit
(PCLATH<3>) is programmed so that the desired program memory page is addressed. If a return from a
CALL instruction (or interrupt) is executed, the entire
13-bit PC is pushed onto the stack. Therefore, manipulation of the PCLATH<3> bit is not required for the
return instructions (which POPs the address from the
stack).
Note:The PIC16C64X & PIC16C66X ignore the
PCLATH<4> bit, which is used for program
memory pages 2 and 3 (1000h - 1FFFh).
The use of PCLATH<4> as a general purpose read/write bit is not recommended
since this may affect upward compatibility
with future products.
The INDF register is not a physical register. 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 nooperation (although status bits may be affected). An
effective 9-bit address is obtained by concatenating the
8-bit FSR register and the IRP bit (STATUS<7>), as
shown in Figure 4-12. However, bit IRP is not used in
the PIC16C64X & PIC16C66X.
FIGURE 4-12: DIRECT/INDIRECT ADDRESSING
(1)
RP1 RP06
bank selectlocation select
from opcode
00h
0
00011011
A simple program to clear RAM location 20h-2Fh using
indirect 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 goto next
;yes continue
CONTINUE:
Indirect AddressingDirect Addressing
(1)
IRP
bank select
00h
7
FSR register
location select
0
Data
not used
Memory
7Fh
Bank 0Bank 1Bank 2Bank 3
For memory map detail see Figure 4-3 and Figure 4-4.
Note 1: Bits RP1 and IRP are reserved, always maintain these bits clear.
7Fh
DS30559A-page 28Preliminary 1996 Microchip Technology Inc.
PIC16C64X & PIC16C66X
5.0I/O PORTS
The PIC16C641 and PIC16C642 have three ports,
PORTA, PORTB, and PORTC. PIC16C661 and
PIC16C662 devices have five ports, PORTA through
PORTE. Some pins for these I/O ports are multiplexed
with alternate functions for the peripheral features on
the device. In general, when a peripheral is enabled,
that pin may not be used as a general purpose I/O pin.
5.1POR
PORTA is a 6-bit wide latch. RA4 is a Schmitt Trigger
input and an open drain output. Pin RA4 is multiplexed
with the T0CKI clock input. All other RA port pins have
Schmitt Trigger input levels and full CMOS output drivers. All pins have data direction bits (TRIS registers)
which can configure these pins as input or output.
Setting a bit in the TRISA register puts the corresponding output driver in a hi-impedance mode. Clearing a bit
in the TRISA register puts the contents of the output
latch on the selected pin.
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.
The PORTA pins are multiplexed with comparator and
voltage reference functions. The operation of these
pins are selected by control bits in the CMCON
(comparator control register) register and the VRCON
(voltage reference control) register. When selected as
comparator inputs, these pins will read as '0's.
TA and TRISA Registers
FIGURE 5-1:BLOCK DIAGRAM OF
RA1:RA0 PINS
Data
bus
WR
Port
Data Latch
WR
TRIS
TRIS Latch
RD PORT
To Comparator
Note: I/O pins have protection diodes to VDD and VSS.
Note: On reset, the TRISA register is set to all
TRISA controls the direction of the RA pins, even when
they are being used as comparator inputs. The user
must make sure to keep the pins configured as inputs
when using them as comparator inputs.
The RA2 pin will also function as the output for the
voltage reference. When in this mode, the V
a very hi-impedance output. The user must set the
TRISA<2> bit and use hi-impedance loads.
In one of the comparator modes defined by the
CMCON register, pins RA3 and RA4 become outputs
of the comparators. The TRISA<4:3> bits must be
cleared to enable outputs to use this function.
QD
VDD
CK
Q
QD
CK
Q
Analog
Input Mode
Schmitt Trigger
RD TRIS
inputs. The digital inputs are disabled and
the comparator inputs are forced to ground
to reduce excess current consumption.
P
N
VSS
Input Buffer
DQ
EN
I/O Pin
pin is
REF
1996 Microchip Technology Inc.
EXAMPLE 5-1:INITIALIZING PORTA
CLRF PORTA ;Initialize PORTA by
;clearing output latches
MOVLW 0x07 ;Turn comparators off,
MOVWF CMCON ;enable pins for I/O
BSF STATUS, RP0 ;Select bank1
MOVLW 0x1F ;Value to initialize
;data direction
MOVWF TRISA ;Set RA<4:0> as inputs
;TRISA<7:5> are clear
Preliminary
DS30559A-page 29
PIC16C64X & PIC16C66X
FIGURE 5-2:BLOCK DIAGRAM OF RA2 PIN
Data
bus
WR
Port
Data Latch
WR
TRIS
TRIS Latch
CK
CK
RD TRIS
QD
Q
QD
Q
Analog
Input Mode
Schmitt Trigger
Input Buffer
EN
VDD
P
N
VSS
DQ
RA2 Pin
RD PORT
To Comparator
VROE
VREF
Note: I/O pin has protection diodes to VDD and VSS.
FIGURE 5-3:BLOCK DIAGRAM OF RA3 PIN
Data
bus
WR
Port
WR
TRIS
CK
Data Latch
CK
TRIS Latch
RD TRIS
QD
Comparator Output
Q
QD
Q
Comparator Mode = 110
Analog
Input Mode
Schmitt Trigger
Input Buffer
VDD
P
N
VSS
RA3 Pin
RD PORT
To Comparator
DS30559A-page 30
Preliminary
DQ
EN
1996 Microchip Technology Inc.
Loading...
+ 106 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.