2000 Microchip Technology Inc. DS30289B-page 1
PIC17C7XX
Microcontroller Core Features:
Only 58 single word instructions to learn
All single cycle instructions (121 ns), except for
program branches and table reads/writes which
are two-cycle
Operati ng spe ed:
- DC - 33 MHz clock input
- DC - 121 ns instruction cycle
8 x 8 Single-Cycle Hardware Multiplier
Interrupt capability
16 level deep hardware stack
Direct, indirect, and relative addressing modes
Internal/external program memory execution,
cap able of addres sing 64 K x 16 prog ram memory
space
Peripheral Feat ures:
Up to 66 I/O pins with individual direction control
10-bit, multi-channel Analog-to-Digital converter
High current sink/source for direct LED drive
Four capture inpu t pins
- Captures are 16-bit, max resolution 121 ns
Three PWM outputs (resolution is 1 to 10-bits)
TMR0: 16-bit timer/counter with
8-bit programmable prescaler
TMR1: 8-bit timer/counter
TMR2: 8-bit timer/counter
TMR3: 16-bit timer/counter
Two Universal Synchronous Asynchronous
Receiver Transmitters (USART/SCI) with
independent baud rate generators
Synchronous Serial Port (SSP) with SPI™ and
I2C™ modes (including I2C Master mode)
Pin Diagrams
S pecial Microcontroller Featu res:
Power-on Reset (POR), Power-up Timer (PWRT)
and Oscillator Start-up Timer (OST)
Watchdog Timer (WDT) with its own on-chip RC
oscillator for reliable operation
Brown-out Reset
Code protection
Power saving SLEEP mode
Selectable oscillator opti ons
CMOS Technology:
Low power, high speed CMOS EPROM
technology
Fully static design
Wide operating voltage range (3.0V to 5.5V)
Commercial and Industrial temperature ranges
Low power consumption
- < 5 mA @ 5V, 4 MHz
- 100 µA typical @ 4.5V, 32 kHz
- < 1 µA typical standby current @ 5V
Device Memory
Program (x16) Data (x8)
PIC17C752 8 K 678
PIC17C756A 16 K 902
PIC17C762 8 K 678
PIC17C766 16 K 902
RF1/AN5
RF0/AN4
AVDD
AVSS
RG3/AN0/VREF+
RG2/AN1/VREF-
RG1/AN2
RG0/AN3
NC
VSS
VDD
RG4/CAP3
RG5/PWM3
RG7/TX2/CK2
RG6/RX2/DT2
RA4/RX1/DT1
RA5/TX1/CK1
RJ0
RJ1
RH6/AN14
RH7/AN15
RD1/AD9
RD0/AD8
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
MCLR/VPP
TEST
VSS
VDD
RF7/AN11
RF6/AN10
RF5/AN9
RF4/AN8
RF3/AN7
RF2/AN6
NC
RH2
RH3
RH4/AN12
RH5/AN13
1011
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 60
59
58
57
56
55
54
53525150494847464544
987654321
27
28
29
30
31
323334353637383940414243
PIC17C76X
RA0/INT
RB0/CAP1
RB1/CAP2
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB2/PWM1
VSS
NC
OSC2/CLKOUT
OSC1/CLKIN
VDD
RB7/SDO
RA3/SDI/SDA
RA2/SS/SCL
RA1/T0CKI
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RC0/AD0
VDD
NC
VSS
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RB6/SCK
RJ5
RJ4
RJ7
RJ6
RJ3
RJ2
RH1
RH0
67
66
65
64
63
62
61
68
74
73
72
71
70
767978778083828184 75
69
84 PLCC
High-Performance 8-bit CMOS EPROM Microcontr ollers with 10-bit A/D
PIC17C7XX
DS30289B-page 2 2000 Microchip Technology Inc.
Pin Diagrams cont.’d
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
9
8
7
6
5
4
3
2
1
68
67
66
65
64
63
62
61
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
RA0/INT
RB0/CAP1
RB1/CAP2
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB2/PWM1
VSS
NC
OSC2/CLKOUT
OSC1/CLKIN
VDD
RB7/SDO
RA3/SDI/SDA
RA2/SS/SCL
RA1/T0CKI
RD1/AD9
RD0/AD8
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
MCLR/VPP
TEST
VSS
VDD
RF7/AN11
RF6/AN10
RF5/AN9
RF4/AN8
RF3/AN7
RF2/AN6
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RC0/AD0
VDD
NC
VSS
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RF1/AN5
RF0/AN4
AVDD
AVSS
RG3/AN0/VREF+
RG2/AN1/VREF-
RG1/AN2
RG0/AN3
NC
VSS
VDD
RG4/CAP3
RG5/PWM3
RG7/TX2/CK2
RG6/RX2/DT2
RA4/RX1/DT1
RA5/TX1/CK1
NC
RB6/SCK
PIC17C75X
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RC0/AD0
VDD
VSS
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RD1/AD9
RD0/AD8
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
MCLR/VPP
TEST
VSS
VDD
RF7/AN11
RF6/AN10
RF5/AN9
RF4/AN8
RF3/AN7
RF2/AN6
RA0/INT
RB0/CAP1
RB1/CAP2
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB2/PWM1
VSS
OSC2/CLKOUT
OSC1/CLKIN
VDD
RB7/SDO
RA3/SDI/SDA
RA2/SS/SCL
RA1/T0CKI
RF1/AN5
RF0/AN4
AVDD
AVSS
RG3/AN0/VREF+
RG2/AN1/VREF-
RG1/AN2
RG0/AN3
VSS
VDD
RG4/CAP3
RG5/PWM3
RG7/TX2/CK2
RG6/RX2/DT2
RA4/RX1/DT1
RA5/TX1/CK1
RB6/SCK
PIC17C75X
68-Pin PLCC
64-Pin TQFP
2000 Microchip Technology Inc. DS30289B-page 3
PIC17C7XX
Pin Diagrams cont.d
RF1/AN5
RF0/AN4
AVDD
AVSS
RG3/AN0/VREF+
RG2/AN1/VREF-
RG1/AN2
RG0/AN3
NC
VSS
VDD
RG4/CAP3
RG5/PWM3
RG7/TX2/CK2
RG6/RX2/DT2
RA4/RX1/DT1
RA5/TX1/CK1
RJ0
RJ1
RH6/AN14
RH7/AN15
RD1/AD9
RD0/AD8
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
MCLR/VPP
TEST
VSS
VDD
RF7/AN11
RF6/AN10
RF5/AN9
RF4/AN8
RF3/AN7
RF2/AN6
NC
RH2
RH3
RH4/AN12
RH5/AN13
1011
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 60
59
58
57
56
55
54
5352
51
50
4948
47
4645
44
987654321
27
28
29
30
31
323334353637383940414243
PIC17C76X
RA0/INT
RB0/CAP1
RB1/CAP2
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB2/PWM1
VSS
NC
OSC2/CLKOUT
OSC1/CLKIN
VDD
RB7/SDO
RA3/SDI/SDA
RA2/SS/SCL
RA1/T0CKI
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RC0/AD0
VDD
NC
VSS
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RB6/SCK
RJ5
RJ4
RJ7
RJ6
RJ3
RJ2
RH1
RH0
67
66
65
64
63
62
61
68
74
73
72
71
70
767978778083828184 75
69
84-pin PLCC
3
4
5
6
7
8
9
10
11
12
13
14
15
16
48
47
46
45
44
43
42
41
40
39
64636261
212223242526272829303132
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RC0/AD0
VDD
VSS
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RD1/AD9
RD0/AD8
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
MCLR/VPP
TEST
VSS
VDD
RF7/AN11
RF6/AN10
RF5/AN9
RF4/AN8
RF3/AN7
RF2/AN6
RA0/INT
RB0/CAP1
RB1/CAP2
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB2/PWM1
VSS
OSC2/CLKOUT
OSC1/CLKIN
VDD
RB7/SDO
RA3/SDI/SDA
RA2/SS/SCL
RA1/T0CKI
RF1/AN5
RF0/AN4
AVDD
AVSS
RG3/AN0/VREF+
RG2/AN1/VREF-
RG1/AN2
RG0/AN3
VSS
VDD
RG4/CAP3
RG5/PWM3
RG7/TX2/CK2
RG6/RX2/DT2
RA4/RX1/DT1
RA5/TX1/CK1
RB6/SCK
RJ7
RJ6
RH1
RH0
1
2
RH2
RH3
17
18
RH4/AN12
RH5/AN13
RH6/AN14
RH7/AN15
RJ1
RJ0
37
RJ3
RJ2
50
49
RJ5
RJ4
19
20
33343536 38
58
57
56
55
54
53
52
51
60
59
68676665727170697473
78777675
7980
PIC17C76X
80-Pin TQFP
PIC17C7XX
DS30289B-page 4 2000 Microchip Technology Inc.
Table of Contents
1.0 Overview........................................................................................................................................................7
2.0 Device Varie tie s....................... ..... ...... ..... ................. ................. ................. ................. . .................................9
3.0 Architectural Overview.................................................................................................................................11
4.0 On-chip Oscillator Circuit.............................................................................................................................17
5.0 Reset............................................................................................................................................................23
6.0 Interrupts......................................................................................................................................................33
7.0 Memory Organization...................................................................................................................................43
8.0 Table Reads and Table Writes ....................................................................................................................59
9.0 Hardware Multiplier......................................................................................................................................67
10.0 I/O Ports.......................................................................................................................................................71
11.0 Overview of Timer Resources......................................................................................................................95
12.0 Timer0..........................................................................................................................................................97
13.0 Timer1, Timer2, Timer3, PWMs and Captures..........................................................................................101
14.0 Universal Synchronous Asynchronous Receiver Transmitter (USART) Modules......................................117
15.0 Master Synchronous Serial Port (MSSP) Module......................................................................................133
16.0 Analog-to-Digital Converter (A/D) Module .................................................................................................179
17.0 Special Features of the CPU .....................................................................................................................191
18.0 Instruction Set Summary............................................................................................................................197
19.0 Development Support................................................................................................................................233
20.0 PIC17C7XX Electri cal Charac teri sti cs............................ ................. ..... .................................. ... ................239
21.0 PIC17C7XX DC and AC Characteristics.............. ..... ...... ...... ..... ................. ...... ................ ...... ...................267
22.0 Packaging Information...............................................................................................................................281
Appendix A: Modifications.......................................................................................................................................287
Appendix B: Compatibility........................................................................................................................................287
Appendix C: Whats New.........................................................................................................................................288
Appendix D: Whats Changed..................................................................................................................................288
Index .......................................................................................................................................................................... 289
On-Line Support..........................................................................................................................................................299
Reader Response.......................................................................................................................................................300
Product Identification System......................................................................................................................................301
2000 Microchip Technology Inc. DS30289B-page 5
PIC17C7XX
TO OUR VALUED CUSTOMERS
It is our intention to provide our valued custome rs with the best docume ntation possible to ensure succ essful use of your Micro-
chip 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 fa x 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 errat a 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:
Microchips 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 dev ice, revision of silicon and data sheet (include lit-
erature number) you are using.
Customer Noti fic atio n Syst em
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
PIC17C7XX
DS30289B-page 6 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 7
PIC17C7XX
1.0 OVERVIEW
This data sheet covers the PIC17C7XX group of the
PIC17CXXX family of microcontrollers. The following
dev i ces are discussed in this data sheet:
PIC17C752
PIC17C756A
PIC17C762
PIC17C766
The PIC17C7XX devices are 68/84-pin, EPROM
based members of the versatile PIC17CXXX family of
low cost, high performance, CMOS, fully static, 8-bit
microcontrollers.
All PICmicro® microcontrollers employ an advanced
RISC architecture. The PIC17CXXX has enhanced
core features, 16-level d eep stack, a nd multiple int ernal
and external interrupt sources. The separate instruc-
tion and da t a buse s of the Harv ard arch itectu re allow a
16-b it wide instr uction word w ith a s eparate 8-bit w ide
data path. The two stage instruction pipeline allows all
instruc tions to execu te in a single cyc le, except for pro-
gram b ranc hes (which requi re two cy cles ). A to t al o f 58
instructions (reduced instruction set) are available.
Additionally, a large register set gives some of the
architectural innovations used to achieve a very high
perf orm an c e. F o r ma t h em ati ca l in t ensive ap pl i ca tio n s,
all devices have a single cycle 8 x 8 Hardware
Multiplier.
PIC17CXXX microcontrollers typically achieve a 2:1
code compression and a 4:1 speed improvement over
other 8-bit microcontrollers in their class.
PIC17C7XX de vic es h av e u p t o 9 02 by tes o f R AM an d
66 I/O pins. In addition, the PIC17C7XX adds several
peripheral features, useful in many high performance
applications, including:
Four timer/counters
Four capture inputs
Three PWM outputs
Two independent Universal Synchronous Asyn-
chronous Receiver Transmitters (USARTs)
An A/D converter (multi-channel, 10-bit resolution)
A Synchronous Serial Port
(SPI and I2C w/ Master mode)
These special features reduce external components,
thus reducing cost, enhancing system reliability and
reducing power cons umption.
There ar e four oscillator opti ons, of which the s ingle pin
RC osc il lat or p r ov ide s a l ow c os t s olution, the LF oscil-
lator is fo r lo w frequenc y cry stals and mi nim iz es po wer
consum ption, XT is a st andard crystal an d the EC is for
external clock input.
The SLEEP (power-down) mode offers additional
power saving. W ake-up from SLEEP can occur through
several external and internal interrupts and device
RESETS.
A highly reliable Watchdog Timer with its own on-chip
RC osci llator pro vides protec tion aga inst so f twar e mal-
function.
There are four configuration options for the device
operational mode:
Microprocessor
Microcontroller
Extende d microcontroller
Protected microcontroller
The microprocessor and extended microcontroller
modes allow up to 64K-words of external program
memory.
The device also has Brown-out Reset circuitry. This
allows a device RESET to occur if the device VDD falls
below the Brown-out voltage trip point (BV DD). The chip
will remain in Brown-out Reset until VDD rises above
BVDD.
A UV erasable, CERQUAD p ackaged version (compat-
ible with PLCC), is ideal for code development, while
the cost-e ff ect ive On e-T i me-P rogrammab le (OTP) ver-
sion is suitable for production in any volume.
The PIC17C7XX fits perfectly in applications that
require extremely fast execution of complex software
programs. These include applications ranging from
precise motor control and industrial process control to
automot ive, ins trumen tat ion , and telec om appl ications .
The EPROM technology makes custom ization of appli-
cation p rograms (with uniqu e secu rity co des, com bina-
tions, model numbers, parameter storage, etc.) fast
and convenient. Small footprint package options
(including die sales) make the PIC17C7XX ideal for
applications with space limitations that require high
performance.
High speed execution, powerful peripheral features,
flexible I/O, and low power consumption all at low cost
make th e PIC17C7X X ideal for a wide r ange of embe d-
ded control applications.
1.1 Family and Upward Compatibility
The PIC17CXXX family of microcontrollers have archi-
tectural enhancements over the PIC16C5X and
PIC16CXX families. These enhancements allow the
device to be more efficient in software and hardware
requirements. Refer to Appendix A for a detailed list of
enhancements and modifications. Code written for
PIC16C5X or PIC16CXX can be easily ported to
PIC17CXXX devices (Appendix B).
1.2 Development Support
The PIC17CXXX family is supported by a full featured
macro assembler, a software simulator, an in-circuit
emulator, a universal programmer, a C compiler and
fuzzy logic support tools. For additional information,
see Section 19.0.
PIC17C7XX
DS30289B-page 8 2000 Microchip Technology Inc.
TABLE 1-1: PIC17CXXX FAMILY OF DEVICES
Features PIC17C42A PIC17C43 PIC17C44 PIC17C752 PIC17C756A PIC17C762 PIC17C766
Maximum Frequency
of Operation 33 MHz 33 MHz 33 MHz 33 MHz 33 MHz 33 MHz 33 MHz
Operating Voltage Range 2.5 - 6.0V 2.5 - 6.0V 2.5 - 6.0V 3.0 - 5.5V 3.0 - 5.5V 3.0 - 5.5V 3.0 - 5.5V
Program
Memory ( x16) (EPROM) 2 K 4 K 8 K 8 K 16 K 8 K 16 K
(ROM)
Data Memory (bytes) 232 454 454 678 902 678 902
Hardware Multiplier (8 x 8) Yes Yes Yes Yes Yes Yes Yes
Timer0
(16-bit + 8-bit postscaler) Yes Yes Yes Yes Yes Yes Yes
Timer1 (8-bit) Yes Yes Yes Yes Yes Yes Yes
Timer2 (8-bit) Yes Yes Yes Yes Yes Yes Yes
Timer3 (16-bit) Yes Yes Yes Yes Yes Yes Yes
Capture inputs (16-bit) 2 2 24444
PWM outputs (up to 10-bit) 2 2 23333
USART/SCI 1 1 12222
A/D channels (10-bit) 12 12 16 16
SSP (SPI/ I2C w/Master
mode) Yes Yes Yes Yes
Power-on Reset Yes Yes Yes Yes Yes Yes Yes
Watchdog Timer Yes Yes Yes Yes Yes Yes Yes
External Interrupts Yes Yes Yes Yes Yes Yes Yes
Interrupt Sources 11 11 11 18 18 18 18
Code Protect Yes Yes Yes Yes Yes Yes Yes
Brown-out Reset Yes Yes Yes Yes
In-Circuit Serial
Programming Yes Yes Yes Yes
I/O Pins 33 33 33 50 50 66 66
I/O High
Current Capability Source 25 mA 25 mA 25 mA 25 mA 25 mA 25 mA 25 mA
Sink 25 mA(1) 25 mA(1) 25 mA(1) 25 mA(1) 25 mA(1) 25 mA(1) 25 mA(1)
Package Types 40-pin DIP
44-pin PLCC
44-pin MQFP
44-pin TQFP
40-pin DIP
44-pin PLCC
44-pin
MQFP
44-pin TQFP
40-pin DIP
44-pin PLCC
44-pin
MQFP
44-pin TQFP
64-pin TQFP
68-pin PLCC 64-pin TQFP
68-pin PLCC 80 - p i n T QFP
84-pin PLCC 80-pin TQFP
84-pin PLCC
Note 1: Pins RA2 and RA3 can sink up to 60 mA.
2000 Microchip Technology Inc. DS30289B-page 9
PIC17C7XX
2.0 DEVICE VARIETIES
Each device has a variety of frequency ranges and
packaging options. Depending on application and pro-
duction requirements, the proper device option can be
select ed using the i nformation in the PIC17C7XX Prod-
uct Selection System section at the end of this data
sheet. When placing orders, please use the
PIC17C7XX Product Identification System at the
back of this data sheet to specify the correct part num-
ber. When discussing the functionality of the device,
memory technolog y and vol tage rang e does not matter .
Ther e a re t wo mem ory type op tio ns. Th ese are spe ci-
fied in the middl e cha racters of the part numbe r.
1. C, as in PIC17C756A. These devices have
EPROM type memory.
2. CR, as in PIC17CR756A. These devices have
ROM type memory.
All these devices operate over the standard voltage
range. Devices are also offered wh ich operate ov er an
extended voltage range (and reduced frequency
range). Table 2-1 show s all possib le memory types and
voltage range designators for a particular device.
These designators are in bold typeface.
TABLE 2-1: DEVICE MEMORY VARIETIES
2.1 UV Erasable Devices
The UV erasable version, offered in CERQUAD pack-
age, is optimal for prototype development and pilot
programs.
The UV erasable version can be erased and repro-
grammed to any of the configuration modes. Third
party programmers also are available; refer t o the Third
Party Guide for a list of sources.
2.2 One-Time-Programmable (OTP)
Devices
The availability of OTP devices is especially useful for
customers expecting frequent code changes and
updates.
The OTP devi ces, packaged in pl astic packages, permit
the user to program them once. In addition to the program
memory, the configuration bits must be programmed.
2.3 Quick-Turnaround-Production
(QTP) Devices
Microchip offers a QTP Programming Service for fac-
tory 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 stabi-
lized. The devi ces ar e id enti ca l to the O TP d e vi ce s b ut
with all EPROM locations and configuration options
already programmed by the factory. Certain code and
prototype verification procedures apply before produc-
tion shipm en ts are available. Please conta ct you r loca l
Microchip Technology sales office for more details.
2.4 Serialized Quick-Turnaround
Production (SQTP
sm) Devices
Microchip offers a unique programming service, where
a few user defined locations in each device are pro-
grammed with diffe rent serial numbers. The serial num-
bers 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.
2.5 Read Only Memory (ROM) Devices
Microchip offers masked ROM versions of several of
the highest volume parts, thus giving customers a low
cost option for high volume, mature products.
ROM devices do not allow serialization information in
the program memory space.
For information on submitting ROM code, please con-
tact your regional sales office.
Memory Type Voltage Range
Standard Extended
EPROM PIC17CXXX PIC17LCXXX
ROM PIC17CRXXX PIC17LCRXXX
Note: Not all memory technologies are available
for a particular device. Note: Presently, NO ROM versions of the
PIC17C7XX devices are available.
PIC17C7XX
DS30289B-page 10 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 11
PIC17C7XX
3.0 ARCHITECTURAL OVERVIEW
The high performance of th e PIC17CXXX can be attrib-
uted to a number of architectural features, commonly
found in RISC microprocessors. To begin with, the
PIC17CXXX uses a modified Harvard architecture.
This architecture has the program and data accessed
from sep arate memorie s. So, the device h as a program
memory bus and a data memory bus. This improves
bandwidth over traditional von Neumann architecture,
where program and data are fetched from the same
memory (accesses over the same bus). Separating
program and data memory further allows instructions to
be sized differently than the 8-bit wide data word.
PIC17CXXX opc ode s ar e 16 -bi t s wide , en abl ing si ngl e
word ins tructions. Th e full 1 6-bit wide pro gram memo ry
bus fetc hes a 16-bit i nstruc tion i n a sin gle cy cle. A tw o-
stage pipeline overlaps fetch and execution of instruc-
tions. C onsequen tly, all instructi ons execu te in a singl e
cycle (121 ns @ 33 MHz), except for program branches
and two sp ec ial ins truc ti ons tha t transfer da ta between
program and data memory.
The PIC17CXXX can address up to 64K x 16 of pro-
gram memory space.
The PIC17C752 and PIC17C762 integrate 8K x 16 of
EPROM program memory on-chip.
The PIC17C756A and PIC17C766 integrate 16K x 16
EPROM program memory on-chip.
A simplified block diagram is shown in Figure 3-1. The
descriptions of the device pins are listed in Table 3-1.
Prog ram exec ution can b e inter nal only (Mic rocont rol-
ler or Protected Microcontroller mode), external only
(Microprocessor mode), or both (Extended Microcon-
troller m od e). Exte nde d M ic roc ont roll er m od e d oes n ot
allow code protection.
The PIC17CXXX can directly or indirectly address its
register files or data memory. All special function regis-
ters, including the Program Counter (PC) and Working
Register (WREG), are mapped in data memory. The
PIC17CXXX has an orthogonal (symmetrical) instruction
set that makes it possible to carry out any operation on
any register using any addressing mode. This symmetri-
cal nature and lack of special optimal situations make
programming with the PIC17CXXX simple, yet efficient.
In addition, the learning curve is reduc ed signi ficantly.
One of the PIC17CXXX family architectural enhance-
ment s fro m the PIC16CXX famil y, allows two file regis-
ters to be used in some two operand instructions. This
allow s dat a to be mov ed dire ctly b etween two re giste rs
without going throug h the WREG register , thus increas-
ing performance and decreasing program memory
usage.
The PIC17CXXX devices contain an 8-bit ALU and
working register. The ALU is a general purpose arith-
metic u nit. It performs arithmetic a nd Boolean funct ions
between data in the working register and any register
file.
The WR EG register is an 8-bit working regi ster used for
ALU operations .
All PIC17CXXX devices have an 8 x 8 hardware multi-
plier. Th is multipl ier generat es a 16-bi t result in a si ngle
cycle.
The ALU is 8-bits wide and capable of addition, sub-
traction, shift and logical operations. Unless otherwise
mentioned, arithmetic operations are two's comple-
ment in nature.
Depending on the instruction executed, the ALU may
affect the values of the Carry (C), Digit Carry (DC), Zero
(Z) and Overfl ow ( OV) bit s in the AL USTA register. The
C and DC bi ts opera te as a borro w and digit borrow out
bit, respectively, in subtraction. See the SUBLW and
SUBWF instructions for examples.
Signed arithmetic is comprised of a magnitude and a
sign bit. The overflow bit indicates if the magnitude
overflow s and caus es the s ign bit to change s tate. Th at
is, if the resu lt of 8-bit signed opera tions is grea ter than
127 (7Fh), or less than -128 (80h).
Signed math can have greater than 7-bit values (mag-
nitude), if mo re than one by te is used . The ove rflow bit
only operates on bit6 (MSb of magnitude) and bit7 (sign
bit) of each by te valu e in the ALU. That is , the overfl ow
bit is not useful if trying to implement signed math
where the magnitude, for example, is 11-bits.
If the signed math values are greater than 7-bits (such
as 15-, 24-, or 31-bit), the algorithm must ensure that
the low order bytes of th e signed v alue igno re the over-
flow status bit.
Example 3-1 shows two cases of doing signed arith-
metic. The Carry (C) bit and the Overflow (OV) bit are the
most import ant s t atus bit s for si gned math op era tions.
EXAMPLE 3-1: 8-BIT MATH ADDITION
Hex Value Signed Values Unsigned Values
FFh
+ 01h
= 00h
C bit = 1
OV bit = 0
DC bit = 1
Z bit = 1
-1
+ 1
= 0 (FEh)
C bit = 1
OV bit = 0
DC bit = 1
Z bit = 1
255
+ 1
= 256 00h
C bit = 1
OV bit = 0
DC bit = 1
Z bit = 1
Hex Value Signed Values Unsigned Values
7Fh
+ 01h
= 80h
C bit = 0
OV bit = 1
DC bit = 1
Z bit = 0
127
+ 1
= 128 00h
C bit = 0
OV bit = 1
DC bit = 1
Z bit = 0
127
+ 1
= 128
C bit = 0
OV bit = 1
DC bit = 1
Z bit = 0
PIC17C7XX
DS30289B-page 12 2000 Microchip Technology Inc.
FIGURE 3-1: PIC17C752/756A BLOCK DIAGRAM
RB0/CAP1
RB1/CAP2
RB2/PWM1
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB6/SCK
RB7/SDO
RA0/INT
RA1/T0CKI
RA2/SS/SCL
RA3/SDI/SDA
RA4/RX1/DT1
RA5/TX1/CK1
PORTA
RC0/AD0
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RD0/AD8
RD1/AD9
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
RF0/AN4
RF1/AN5
RF2/AN6
RF3/AN7
RF4/AN8
RF5/AN9
RF6/AN10
RF7/AN11
RG0/AN3
RG1/AN2
RG2/AN1/VREF-
RG3/AN0/VREF+
RG4/CAP3
RG5/PWM3
RG6/RX2/DT2
RG7/TX2/CK2
Timer0
Clock
Generator
Power-on
Reset
Watchdog
Timer
Test Mode
Select
VDD, VSS
OSC1,
MCLR, VPP
Test
Q1, Q2,
Chip_reset
& Other
Control
System Bus Interface
Decode
Data Latch
Address
Program
Memory
(EPROM)
Table Pointer<16>
Stack
16 x 16
Table
ROM Latch <16>
Instruction
Decode
Control Outputs
IR Latch <16>
F1
F9
16K x 16
PCH
PCLATH<8>
Literal
RAM
Data Latch
BSR
Data RAM
902 x 8
Latch
PCL
Read/Write
Decode
for
Mapped
in Data
Space
WREG<8> BITOP
ALU
Shifter
8 x 8 mult
PRODH PRODL
Registers
Latch <16>
Address
Buffer
USART1
Timer1 Timer3
Timer2 PWM1
PWM2
PWM3
Capture1 Capture3
Capture2
Interrupt
Module
10-bit
A/D
PORTB
PORTC
PORTD
PORTE
PORTF
PORTG
AD<15:0>
Signals
Q3, Q4 OSC2
Data Bus<8>
16
16
16
16
88
8
8
12
16
IR<16>
SSP
PORTC,
PORTD
ALE,
WR,
OE,
PORTE
IR <7:0>
BSR <7:4>
USART2 Capture4
Brown-out
Reset
17C756A
17C752
8K x 16
17C756A
17C752
678 x 8
2000 Microchip Technology Inc. DS30289B-page 13
PIC17C7XX
FIGURE 3-2: PIC17C762/766 BLOCK DIAGRAM
RB0/CAP1
RB1/CAP2
RB2/PWM1
RB3/PWM2
RB4/TCLK12
RB5/TCLK3
RB6/SCK
RB7/SDO
RA0/INT
RA1/T0CKI
RA2/SS/SCL
RA3/SDI/SDA
RA4/RX1/DT1
RA5/TX1/CK1
PORTA
RC0/AD0
RC1/AD1
RC2/AD2
RC3/AD3
RC4/AD4
RC5/AD5
RC6/AD6
RC7/AD7
RD0/AD8
RD1/AD9
RD2/AD10
RD3/AD11
RD4/AD12
RD5/AD13
RD6/AD14
RD7/AD15
RE0/ALE
RE1/OE
RE2/WR
RE3/CAP4
RF0/AN4
RF1/AN5
RF2/AN6
RF3/AN7
RF4/AN8
RF5/AN9
RF6/AN10
RF7/AN11
RG0/AN3
RG1/AN2
RG2/AN1/VREF-
RG3/AN0/VREF+
RG4/CAP3
RG5/PWM3
RG6/RX2/DT2
RG7/TX2/CK2
Timer0
Clock
Generator
Power-on
Reset
Watchdog
Timer
Test Mode
Select
VDD, VSS
OSC1,
MCLR, VPP
Test
Q1, Q2,
Chip_reset
& Other
Control
System Bus Interface
Decode
Data Latch
Address
Program
Memory
(EPROM)
Table Pointer<16>
Stack
16 x 16
Table
ROM Latch <16>
Instruction
Decode
Control Outputs
IR Latch <16>
FSR0
FSR1
16K x 16,
PCH
PCLATH<8>
Literal
RAM
Data Latch
BSR
Data RAM
902 x 8
Latch
PCL
Read/Write
Decode
for
Mapped
in Data
Space
WREG<8> BITOP
ALU
Shifter
8 x 8 mult
PRODH PRODL
Registers
Latch <16>
Address
Buffer
USART1
Timer1 Timer3
Timer2 PWM1
PWM2
PWM3
Capture1
Capture3Capture2
Interrupt
Module 10-bit
A/D
PORTB
PORTC
PORTD
PORTE
PORTF
PORTG
AD<15:0>
Signals
Q3, Q4 OSC2
Data Bus<8>
16
16
16
16
88
8
8
12
16
IR<16>
SSP
PORTC,
PORTD
ALE,
WR,
OE,
PORTE
IR <7:0>
BSR <7:4>
USART2
Capture4
RH0
RH1
RH2
RH3
RH4/AN12
RH5/AN13
RH6/AN14
RH7/AN15
PORTH
RJ0
RJ1
RJ2
RJ3
RJ4
RJ5
RJ6
RJ7
PORTJ
Brown-out
Reset
AVDD, AVSS
17C766
17C762
678 x 8
and
17C766
and
17C762
8K x 16
PIC17C7XX
DS30289B-page 14 2000 Microchip Technology Inc.
TABLE 3-1: PINOUT DESCRIPTIONS
Name
PIC17C75X PIC17C76X
Description
DIP
No. PLCC
No. TQFP
No. PLCC
No. QFP
No. I/O/P
Type Buffer
Type
OSC1/CLKIN 47 50 39 62 49 I ST Oscillator input in Crystal/Resonator or RC Oscillator
mode. External clock input in External Clock mode.
OSC2/CLKOUT4851406350OOscillator output. Connects to crystal or resonator in
Crystal Oscillator mode. In RC Oscillator or External
Clock modes, OSC2 pin outputs CLKOUT which has
one fourth the frequency (FOSC/4) of OSC1 and
denotes the instruction cycle rate.
MCLR/VPP 15 16 7 20 9 I/P ST Master clear (RESET) input or Programming V olt age
(VPP) input. This is the active low RESET input to the
device.
PORTA pins have individual differentiations that are
listed in the following descriptions:
RA0/INT 56 60 48 72 58 I ST RA0 can also be selected as an external inter-
rupt input. Interrupt can be configured to be on
positive or negative edge. Input only pin.
RA1/T0CKI 41 44 33 56 43 I ST RA1 can also be selected as an external inter-
rupt input and the interrupt can be configured to
be on positive or negative edge. RA1 can also
be selected to be the clock input to the Timer0
timer/counter. Input only pin.
RA2/SS/SCL 42 45 34 57 44 I/O(2) ST RA2 can also be used as the slave select input
for the SPI or the clock input for the I2C bus.
High voltage, high current, open drain port pin.
RA3/SDI/SDA4346355845I/O
(2) ST RA3 can also be used as the data input for the
SPI or the data for the I2C bus.
High voltage, high current, open drain port pin.
RA4/RX1/DT1 40 43 32 51 38 I/O(1) ST RA4 can also be selected as the USART1 (SCI)
Asynchronous Receive or USA RT1 (SCI)
Synchronous Data.
Output available from USART only.
RA5/TX1/CK13942315037I/O
(1) ST RA5 can also be selected as the USART1 (SCI)
Asynchronous Transmit or USART1 (SCI)
Synchronous Clock.
Output available from USART only.
PORTB is a bi-directional I/O Port with software
configurable weak pull-ups.
RB0/CAP1 55 59 47 71 57 I/O ST RB0 can also be the Capture1 input pin.
RB1/CAP2 54 58 46 70 56 I/O ST RB1 can also be the Capture2 input pin.
RB2/PWM1 50 54 42 66 52 I/O ST RB2 can also be the PWM1 output pin.
RB3/PWM2 53 57 45 69 55 I/O ST RB3 can also be the PWM2 output pin.
RB4/TCLK12 52 56 44 68 54 I /O ST RB4 can also be the external clock input to
Timer1 and Timer2.
RB5/TCLK3 51 55 43 67 53 I/O S T RB5 can also be the external clock input to
Timer3.
RB6/SCK 44 47 36 59 46 I/O ST RB6 can also be used as the master/slave clock
for the SPI.
RB7/SDO 45 48 37 60 47 I/O ST RB7 can also be used as the data output for the
SPI.
Legend: I = Input only; O = Output only; I/O = Input/Output;
P = Power; = Not Used; TTL = TTL input; ST = Schmitt Trigger input
Note 1: The output is only available by the peripheral operation.
2: Open drain input/output pin. Pin forced to input upon any device RESET.
2000 Microchip Technology Inc. DS30289B-page 15
PIC17C7XX
PORTC is a bi-directional I/O Port.
RC0/AD0 2 3 58 3 72 I/O T TL This is also the least significant byte (LSB) of
the 16-bit wide system bus in Microprocessor
mode or Extended Microcontroller mode. In
multiplexed system bus configuration, these
pins are address output as well as data input or
output.
RC1/AD1 63 67 55 83 69 I/O TTL
RC2/AD2 62 66 54 82 68 I/O TTL
RC3/AD3 61 65 53 81 67 I/O TTL
RC4/AD4 60 64 52 80 66 I/O TTL
RC5/AD5 58 63 51 79 65 I/O TTL
RC6/AD6 58 62 50 78 64 I/O TTL
RC7/AD7 57 61 49 77 63 I/O TTL PORTD is a bi-directional I/O Port.
RD0/AD8 10 11 2 15 4 I/O TTL This is also the most significant byte (MSB) of
the 16-bit system bus in Microprocessor mod e
or Extended Microcontroller mode. In multi-
plexed system bus configuration, these pins are
address output as well as data input or output.
RD1/AD9 9 10 1 14 3 I/O TTL
RD2/AD10 8 9 64 9 78 I/O TTL
RD3/AD11 7 8 63 8 77 I/O TTL
RD4/AD12 6 7 62 7 76 I/O TTL
RD5/AD13 5 6 61 6 75 I/O TTL
RD6/AD14 4 5 60 5 74 I/O TTL
RD7/AD15 3 4 59 4 73 I/O TTL PORTE is a bi-directional I/O Port.
RE0/ALE 11 12 3 16 5 I/O TTL In Microprocessor mode or Extended Microcon-
troller mode, RE0 is the Address Latch Enable
(ALE) output. Address should be latched on the
falling edge of ALE output.
RE1/OE 12 13 4 17 6 I/O TTL In Microprocessor or Extended Micro controller
mode, RE1 is the Output Enable (OE) cont rol
output (active low).
RE2/WR 13 14 5 18 7 I/O TTL In Microprocessor or Extended Microcontroller
mode, RE2 is the Write Enable (WR) cont rol
output (active low).
RE3/CAP4 14 15 6 19 8 I/O ST RE3 can also be the Capture4 input pin.
PORTF is a bi-directional I/O Port.
RF0/AN4 26 28 18 36 24 I/O ST RF0 can also be analog input 4.
RF1/AN5 25 27 17 35 23 I/O ST RF1 can also be analog input 5.
RF2/AN6 24 26 16 30 18 I/O ST RF2 can also be analog input 6.
RF3/AN7 23 25 15 29 17 I/O ST RF3 can also be analog input 7.
RF4/AN8 22 24 14 28 16 I/O ST RF4 can also be analog input 8.
RF5/AN9 21 23 13 27 15 I/O ST RF5 can also be analog input 9.
RF6/AN10 20 22 12 26 14 I/O ST RF6 can also be analog input 10.
RF7/AN11 19 21 11 25 13 I/O ST RF7 can also be analog input 11.
TABLE 3-1: PINOUT DESCRIPTIONS (CONTINUED)
Name
PIC17C75X PIC17C76X
Description
DIP
No. PLCC
No. TQFP
No. PLCC
No. QFP
No. I/O/P
Type Buffer
Type
Legend: I = Input only; O = Output only; I/O = Input/Output;
P = Power; = Not Used; TTL = TTL input; ST = Schmitt Trigger input
Note 1: The output is only available by the peripheral operation.
2: Open drain input/output pin. Pin forced to input upon any device RESET.
PIC17C7XX
DS30289B-page 16 2000 Microchip Technology Inc.
PORTG is a bi-directional I/O Port.
RG0/AN3 32 34 24 42 30 I/O ST RG0 can also be analog input 3.
RG1/AN2 31 33 23 41 29 I/O ST RG1 can also be analog input 2.
RG2/AN1/VREF- 30 32 22 40 28 I/O ST RG2 can also be analog input 1, or
the ground reference voltage.
RG3/AN0/VREF+ 29 31 21 39 27 I/O ST RG3 can also be analog input 0, or
the positive reference voltage.
RG4/CAP3 35 38 27 46 33 I/O ST RG4 can also be the Capture3 input pin.
RG5/PWM3 36 39 28 47 34 I/O ST RG5 can also be the PWM3 output pin.
RG6/RX2/DT2 38 41 30 49 36 I/O ST RG6 can also be selected as t he USART2 (SCI)
Asynchronous Receive or USA RT2 (SCI)
Synchronous Data.
RG7/TX2/CK2 37 40 29 48 35 I/O ST RG7 can also be selected as the USART 2 (SCI)
Asynchronous Transmit or USART2 (SCI)
Synchronous Clock.
PORTH is a bi-directional I/O Port. PORTH is only
available on the PIC17C76X devices.
RH0 ———10 79 I/O ST
RH1 ———11 80 I/O ST
RH2 ———12 1 I/O ST
RH3 ———13 2 I/O ST
RH4/AN12 ———31 19 I /O ST RH4 can also be analog input 12.
RH5/AN13 ———32 20 I /O ST RH5 can also be analog input 13.
RH6/AN14 ———33 21 I /O ST RH6 can also be analog input 14.
RH7/AN15 ———34 22 I /O ST RH7 can also be analog input 15.
PORTJ is a bi-directional I/O Port. PORTJ is only
available on the PIC17C76X devices.
RJ0 ———52 39 I/O ST
RJ1 ———53 40 I/O ST
RJ2 ———54 41 I/O ST
RJ3 ———55 42 I/O ST
RJ4 ———73 59 I/O ST
RJ5 ———74 60 I/O ST
RJ6 ———75 61 I/O ST
RJ7 ———76 62 I/O ST
TEST 16 17 8 21 10 I ST Test mode selection control input. Always tie to VSS
for normal operation.
VSS 17, 33,
49, 64 19, 36,
53, 68 9, 25,
41, 56 23, 44,
65, 84 11, 31,
51, 70 P Ground reference for logic and I/O pins.
VDD 1, 18,
34, 46 2, 20,
37, 49, 10, 26,
38, 57 24, 45,
61, 2 12, 32,
48, 71 P Positive supply for logic and I/O pins.
AVSS 28 30 20 38 26 P Ground reference for A/D converter.
This pin MUST be at the same potential as VSS.
AVDD 27 29 19 37 25 P Positive supply for A/D converter.
This pin MUST be at the same potential as VDD.
NC 1, 18,
35, 52 1, 22,
43, 64 No Connect. Leave these pins unconnected.
TABLE 3-1: PINOUT DESCRIPTIONS (CONTINUED)
Name
PIC17C75X PIC17C76X
Description
DIP
No. PLCC
No. TQFP
No. PLCC
No. QFP
No. I/O/P
Type Buffer
Type
Legend: I = Input only; O = Output only; I/O = Input/Output;
P = Power; = Not Used; TTL = TTL input; ST = Schmitt Trigger input
Note 1: The output is only available by the peripheral operation.
2: Open drain input/output pin. Pin forced to input upon any device RESET.
2000 Microchip Technology Inc. DS30289B-page 17
PIC17C7XX
4.0 ON-CHIP OSCILLATOR
CIRCUIT
The internal oscillator circuit is used to generate the
device clock. Four device clock periods generate an
internal instruction clock (TCY).
There ar e four modes that the osc illator can operate in.
They are selected by the device configuration bits dur-
ing device programming. These modes are:
LF Low Frequency (FOSC 2 MHz)
XT Standard Crystal/Resonator Frequency
(2 MHz FOSC 33 MHz)
EC External Clock Input
(Default oscillator configuration)
RC External Resi st or/C apacitor
(FOSC 4 MHz)
There are two timers that offer necessary delays on
power-up. One is the Os ci lla tor Star t-up Timer (OST),
intended to keep the chip in RESET until the crystal
oscillator is stable. The other is the Power-up Timer
(PWRT), which provides a fixed delay of 96 ms (nomi-
nal) on PO R and BOR . The PW R T is de signe d to kee p
the part in RESET while the power supply stabilizes.
With these two timers on-chip, most applications need
no external RESET circuitry.
SLEEP mode is designed to offer a very low current
power-down mode. The user can wake from SLEEP
through external RESET, Watchdog Timer Reset, or
through an interrupt.
Several oscillator options are made available to allow
the part to better fit the application. The RC oscillator
option saves system cost while the LF crystal option
saves power. Configuration bits are use d to selec t var-
ious options.
4.1 Oscillator Configurations
4.1.1 OSCILLATOR TYPES
The PIC17CXXX can be operated in four d ifferent oscil-
lator modes. The user can program two configuration
bits (FOSC1:FOSC0) to select one of these four
modes:
LF Low Power Crystal
XT Crystal/Resonator
EC External Clock Input
RC Resistor/Capacitor
The main difference between the LF and XT modes is
the gain of the internal inverter of the oscillator circ uit,
which allows the different frequency ranges.
For more details on the device configuration bits, see
Section 17.0.
4.1.2 CRYSTAL OSCILLATOR/CERAMIC
RESONATORS
In XT or LF modes, a cryst al or ceramic resonator is con-
nected to the OSC1/CLKIN and OSC2/CLKOUT pins to
establish osc illation (Figure 4-2). The PIC17CXXX oscil-
lator design requires the use of a parallel cut crystal. Use
of a series cut crystal may give a frequency out of the
crystal man ufacturers spec ifications.
For frequencies above 24 MHz, it is common for the
crystal to be an overtone mode crystal. Use of overtone
mode crystals require a tank circuit to attenuate the
gain at the fundamental frequency. Figure 4-3 shows
an example circuit.
4.1.3 OSCILLATOR/RESONATOR
START-UP
As the dev ice volt age increase s from Vss, the oscillator
will start its osci ll ati ons . Th e ti me require d fo r the osci l-
lator to start oscillating depends on many factors.
These include:
Crystal/resonator frequency
Capacitor values used (C1 and C2)
Device VDD rise time
System temperature
Series resistor value (and type) if used
Oscil lator mode s election of device (w hich sel ects
the gain of the internal oscillator inverter)
Figure 4-1 shows an example of a typical oscillator/
resonator start-up. The peak-to-peak voltage of the
oscill ato r wav efo rm ca n be qu ite lo w (less than 50% of
device VDD) when the waveform is centered at VDD/2
(refer to p ara meter #D 033 and p ara meter # D043 i n the
electrical specification section).
FIGURE 4-1: OSCILLATOR/
RESONATOR START-UP
CHARACTERISTICS
VDD
Crystal Start-up T ime
Time
PIC17C7XX
DS30289B-page 18 2000 Microchip Technology Inc.
FIGURE 4-2: CRYSTAL OR CERAMIC
RESONATOR OPERATION
(XT OR LF OSC
CONFIGURATION)
TABLE 4-1: CAPACITOR SELECTION FOR
CERAMIC RESONATORS
FIGURE 4-3: CRYSTAL OPERATION,
OVERTONE CRYSTALS
(XT OSC
CONFIGURATION)
T ABLE 4-2: CAPACITOR SELECTION FOR
CRYSTAL OSCILLATOR
Oscillator
Type Resonator
Frequency Capacitor Range
C1 = C2(1)
LF 455 kHz
2.0 MHz 15 - 68 pF
10 - 33 pF
XT 4.0 MHz
8.0 MHz
16.0 MHz
22 - 68 pF
33 - 100 pF
33 - 100 pF
Higher capacitance increases the stability of the oscillator,
but also increases the start-up time. These values are for
design guidance only. Since each resonator has its own
characteristics, the user should consult the resonator manu-
facturer for appropriate values of external components.
Note 1: These values include all board capacitances on
this pin. Actual capacitor value depends on
board capacitance.
Resonators Used:
455 kHz Panasonic EFO-A455K04B ± 0.3%
2.0 MHz Murata Erie CSA2.00MG ± 0.5%
4.0 MHz Murata Erie CSA4.00MG ± 0.5%
8.0 MHz Murata Erie CSA8.00MT ± 0.5%
16.0 MHz Murata Erie CSA16.00MX ± 0.5%
Resonators used did not have built-in capacitors.
See Table 4-1 and Table 4-2 for recommended values of C1
and C2.
Note 1: A series resistor (Rs) may be required for AT strip
cut crystals.
C1
C2
XTAL
OSC2
(Note 1)
OSC1
RF SLEEP
PIC17CXXX
To internal
logic
Osc
Type Freq C1(2) C2(2)
LF 32 kHz
1 MHz
2 MHz
100-150 pF
10-68 pF
10-68 pF
100-150 pF
10-68 pF
10-68 pF
XT 2 MHz
4 MHz
8 MHz
16 MHz
24 MHz(1)
32 MHz(1)
47-100 pF
15-68 pF
15-47 pF
15-47 pF
15-47 pF
10-47 pF
47-100 pF
15-68 pF
15-47 pF
15-47 pF
15-47 pF
10-47 pF
Higher capacitance increases the stability of the oscillator,
but also increases the start-up time and the oscillator cur-
rent. These values are for design guidance only. RS may be
required in XT mode to avoid overdriving the crystals with
low drive level specification. Since each crystal has its own
characteristics, the user should consult the crystal manufac-
turer for appropriate values for external components.
Note 1: Overtone crystals are used at 24 MHz and
higher. The circuit in Figure 4-3 should be used
to select the desired harmonic frequency.
2: These values include all board capacitances on
this pin. Actual capacitor value depends on
board capacitance.
Cryst als Used:
32.768 kHz Epson C-001R32.768K-A ± 20 PPM
1.0 MHz ECS-10-13- 1 ± 50 PPM
2.0 MHz ECS-20-20- 1 ± 50 PPM
4.0 MHz ECS-40-20- 1 ± 50 PPM
8.0 MHz ECS ECS- 80-S-4
ECS-80-18-1 ± 50 PPM
16.0 MHz ECS-160-20-1 ± 50 PPM
25 MHz CTS CTS25M ± 50 PPM
32 MHz CRYSTEK HF- 2 ± 50 PPM
C1
C2
0.1 µF
SLEEP
OSC2
OSC1
PIC17CXXX
To filter the fundamental frequency:
1
L1*C2=(2πf)2
Where f = tank circuit resonant frequency. This should be
midway between the fundamental and the 3rd overtone
frequencies of the crystal.
C3
C3 blocks DC current to ground.
L1
2000 Microchip Technology Inc. DS30289B-page 19
PIC17C7XX
4.1.4 EXTERNAL CLOCK OSCILLATOR
In the EC oscillator mode, the OSC1 input can be
driven by CMOS drivers. In this mode, the OSC1/
CLKIN pin is hi-imped ance and the OSC2/CLKOUT pin
is the CLKOUT output (4 TOSC).
FIGURE 4-4: EXTERNAL CLOCK INPUT
OPERATION (EC OSC
CONFIGURATION)
4.1.5 EXTERNAL CRYSTAL OSCILLATOR
CIRCUIT
Eith er a p repa ck ag ed o sc il l ato r can b e us e d, or a s i m-
ple oscillator circuit with TTL gates can be built. Pre-
packaged oscillators provide a wide operating range
and better stability. A well designed crystal oscillator
will provide good performance with TTL gates. Two
types o f crys tal oscil lator c ircuit s can be use d: one w ith
series resonance, or one with parallel resonance.
Figure 4- 5 shows implem entation of a p arallel resonant
oscillator circuit. The circuit is designed to use the fun-
dament al frequen cy of the c rystal. The 74AS04 in verter
performs the 180-degree phase shift that a parallel
oscillator requires. The 4.7 k resistor provides the
negative feedback for stability. The 10 k potentiome-
ter biases the 74AS04 in the linear region. This could
be used for external oscillator designs.
FIGURE 4-5: EXTERNAL PARALLEL
RESONANT CRYSTAL
OSCILLATOR CIRCUIT
Figure 4-6 shows a series resonant oscillator circuit.
This circ uit is also designe d to use the fundame ntal fre-
quency of the crystal. The inverter performs a 180-
degree phase shift in a series resonant oscillator cir-
cuit. T he 330 resistors provide the negative feedback
to bias the inverters in their linear region.
FIGURE 4-6: EXTERNAL SERIES
RESONANT CRYSTAL
OSCILLATOR CIRCUIT
Clock from
ext. system OSC1
OSC2
PIC17CXXX
CLKOUT
(FOSC/4)
20 pF
+5V
20 pF
10 k
4.7 k
10 k
74AS04
XTAL
10k
74AS04 PIC17CXXX
OSC1
To Other
Devices
330
74AS04 74AS04 PIC17CXXX
OSC1
To Other
Devices
XTAL
330
74AS04
0.1 µF
PIC17C7XX
DS30289B-page 20 2000 Microchip Technology Inc.
4.1.6 RC OSCILLATOR
For timing insensitive applications, the RC device
option offers additional cost savings. RC oscillator fre-
quency is a function of the supply voltage, the resistor
(REXT) and capacitor (CEXT) values, and the operating
tempera ture. In addition to this , oscillat or frequen cy will
vary from unit to unit due to normal process parameter
variation. Furthermore, the difference in lead frame
capacitance between package types will also affect
oscillation frequency, especially for low CEXT values.
The user also needs to take into account variation due
to tolerance of external R and C components used.
Figure 4-7 shows how the R/C combination is con-
nected to the PIC17CXXX. For REXT values below
2.2 k, the oscillator operation may become unstable,
or stop completely. For very high REXT values (e.g.
1M), the oscillator becomes sensitive to noise,
humidity and leakage. Thus, we recommend to keep
REXT between 3 k and 100 k.
Although the oscillator will operate with no external
capacitor (CEXT = 0 pF), we recomme nd using valu es
above 20 pF for noise and stability reasons. With little
or no external capacitance, oscillation frequency can
vary dramatically due to changes in external capaci-
tances, such as PCB trace capacitance or package
lead frame capacitance.
See Section 21.0 for RC frequency variation from part
to pa rt due to normal pro cess varia tion. Th e variation i s
larger for larger R (since leakage current variation will
affect RC frequency more for large R) and for smaller
C (since variation of input capacitance will affect RC
frequency more).
See Section 21.0 for variation of oscillator frequency
due to VDD for given REXT/CEXT values, as well as fre-
quency variation due to operating temperature for
given R, C, and VDD values.
The oscillator frequency, divided by 4, is available on
the OSC2/CLKOUT pin and can be used for test pur-
poses or to synchronize other logic (see Figure 4-8 for
waveform).
FIGURE 4-7: RC OSCILLATOR MODE
4.1.6.1 RC Start-up
As the device voltage increases, the RC will immedi-
ately start its oscillations once the pin voltage levels
meet the input threshold specifications (parameter
#D032 a nd parame ter #D042 in the el ectrical speci fica-
tion sec tion). The tim e required for th e RC to sta rt oscil-
lating de pend s on many factors. These include:
Resist or va lue used
Capacitor value used
Device VDD rise time
System temperature
VDD
REXT
CEXT
VSS
OSC1 Internal
Clock
OSC2/CLKOUT
FOSC/4
PIC17CXXX
2000 Microchip Technology Inc. DS30289B-page 21
PIC17C7XX
4.2 Clocking 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 pro-
gram counter (PC) is incremented every Q1 and the
instruction is fetched from the program memory and
latched into the instruction register in Q4. The instruc-
tion is decoded and executed during the following Q1
through Q4. The clocks and instruction execution flow
are shown in Figure 4-8.
4.3 Instruction Flow/Pipelining
An Instruction Cycle consists of four Q cycles (Q1,
Q2, Q3 and Q 4). The instruc tio n fe tch and ex ecu te 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 tw o cycles are req uired to com plete the ins truction
(Example 4-1).
A fetch cycle begins with the program counter incre-
menting in Q1.
In the execution cycle, the fetched instruction is latched
into the Instruction Register (IR) in cycle Q1. This
instruction is then de coded and executed during the Q2,
Q3 and Q4 cycles. Data memory is read during Q2
(operand read) and written during Q4 (destin ation write).
FIGURE 4-8: CLOCK/INSTRUCTION CYCLE
EXAMPLE 4-1: INSTRUCTION PIPELINE FLOW
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(RC 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)
Internal
Phase
Clock
All instruc tions are s ingle cycle , except fo r any program bra nches. The se take tw o cycles s ince the fetch ed instruc -
tion is flushed from the pipeline, while the new instruction is being fetched and then executed.
TCY0TCY1TCY2TCY3TCY4TCY5
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 (Forced NOP) Fetch 4 Flush
5. Instruction @ address SUB_1 Fetch SUB_1 Execute SUB_1
PIC17C7XX
DS30289B-page 22 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 23
PIC17C7XX
5.0 RESET
The PIC17CXXX differentiates between various kinds
of RESET:
Power-on Reset (POR)
Brown-out Reset
MCLR Reset
WDT R eset
Some registers are not affected in any RESET condi-
tion, the ir stat us is unk nown on POR and un changed i n
any other RESET. Most other registers are forced to a
RESET state. The TO and PD bits are set or cleared
diff erently in diffe rent RESET s ituations, as indicat ed in
Table 5-3. These bits, in conjunction with the POR and
BOR bits , are us ed in s oftware to determi ne the natu re
of the RESET. See Table 5-4 for a full descrip tion of th e
RESET states of all registers.
When the device enters the RESET state, the Data
Direction registers (DDR) are forced set, which will
make the I/O hi-impe dance input s. The RESET sta te of
some peripheral modules may force the I/O to other
operations, such as analog inputs or the system bus.
A simplif ied block diagra m of the On-Chip Rese t Circuit
is sh own in Figu re 5-1.
FIGURE 5-1: SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
Note: While the device is in a RESET state, the
internal phase clock is he ld in the Q1 stat e.
Any processor mode that allows external
execution will force the RE0/ALE pin as a
low output and the RE1/OE and RE2/WR
pins as high outputs.
S
RQ
External
Reset
MCLR
VDD
OSC1
WDT
Module
VDD Rise
Detect
OST/PWRT
On-chip
RC OSC
WDT
Time_Out
Power_On_Reset
OST
10-bit Ripple Counter
PWRT
Chip_Reset
10-bit Ripple Counter
(Enable the PWRT timer
only during POR or BOR)
(If PWRT is invoked, or a Wake-up from
SLEEP and OSC type is XT or LF)
Reset
Enable OST
Enable PWRT
This RC oscillator is shared with the WDT when not in a power-up sequence.
BOR
Module Brown-out
Reset
PIC17C7XX
DS30289B-page 24 2000 Microchip Technology Inc.
5.1 Power-on Reset (POR), Power-up
T imer (PWRT), Oscillat or Start-up
Timer (OST) and Brown-out Reset
(BOR)
5.1.1 POWER-ON RESET (POR)
The Power-on Reset circ uit hol ds the device in RESET
unti l VDD is above the trip point (in the range of 1.4V -
2.3V). The devices pro duce an internal RESET for both
rising and falling VDD. To take advantage of the POR,
just tie the MCLR/VPP pin directly (or thr ough a resistor)
to VDD. This will eliminate external RC components
usually needed to create Power-on Reset. A minimum
rise time for VDD is requ ired. S ee Elect rical Spec ifica-
tions for details.
Figure 5-2 and Figure 5-3 show two possible POR
circuits.
FIGURE 5-2: USING ON-CHIP POR
FIGURE 5-3: EXTERNAL POWER-ON
RESET CIRCUIT (FOR
SLOW VDD POWER-UP)
5.1.2 POWER-UP TIMER (PWRT)
The Power-up Timer provides a fixed 96 ms time-out
(nominal) on power-up. This occurs from the rising
edge of the internal POR signal if VDD and MCLR are
tied, or after the first rising edge of MCLR (detected
high). The Power-up Timer operates on an internal RC
oscillator. The chip is kept in RESET as long as the
PWRT is active. In most cases, the PWRT delay allows
VDD to rise to an acceptable level.
The pow er-up time de lay will v ary from chip to chip and
with VDD and temperature. See DC parameters for
details.
5.1.3 OSCILLATOR START-UP TIMER
(OST)
The Oscillator Start-up Timer (OST) provides a 1024
oscillator cycle (1024TOSC) delay whenever the PWRT
is invoked, or a wake-up from SLEEP event occurs in XT
or LF mode. The PWR T and OST operate in p aral lel.
The OST counts the oscillator pulses on the OSC1/
CLKIN pin. The counter only starts incrementing after
the amplitude of the signal reaches the oscillator input
thresholds. This delay allows the crystal oscillator or
resonator to stabilize before the device exits RESET.
The length of the time-out is a function of the crystal/
resonator frequency.
Figure 5-4 shows the operation of the OST circuit. In
this figu re, the oscil lator is o f such a lo w frequency th at
although enabled simultaneously, the OST does not
time-out until after the Power-up Timer time-out.
FIGURE 5-4: OSCILLATOR START-UP
TIME (LOW F RE QU EN CY)
VDD
MCLR
PIC17CXXX
VDD
Note 1: An external Power-on Reset circuit is
required only if VDD power-up time is too
slow. The diode D helps discharge the capac-
itor quickly when VDD powers down.
2: R < 40 k is recommended to ensure that the
voltage drop across R does not exceed 0.2V
(max. leakage current spec. on the MCLR/
VPP pin is 5 µA). A larger voltage drop will
degrade VIH level on the M CLR/VPP pin.
3: R1 = 100 to 1 k will limit any current flow-
ing into MCLR fro m exter nal ca pacitor C in
the event of MCLR/VPP pin breakdown due to
Electrostatic Discharge (ESD) or Electrical
Overstress (EOS).
C
R1
R
D
VDD
MCLR
PIC17CXXX
VDD
VDD
MCLR
OSC2
OST TIME_OUT
PWRT TIME_OUT
INTERNAL RESET
TOSC1TOST
TPWRT
POR or BOR Trip Point
This figure shows in greater detail the timings involved
with the oscillator start-up timer. In this example, the low
frequency crystal start-up time is larger than power-up
time (TPWRT).
TOSC1 = time for the crystal oscillator to react to an oscil-
lation level detectable by the Oscillator Start-up Timer
(OST).
TOST = 1024TOSC.
2000 Microchip Technology Inc. DS30289B-page 25
PIC17C7XX
5.1.4 TIME-OUT SEQUENCE
On power-up, the time-out sequence is as follows: First,
the internal POR signal goes high when the POR trip
point is reach ed. If MCLR is high, then both the OST and
PWRT timers start. In general, the PWRT time-out is
longer, except with low frequency crystals/resonators.
The total time-out also varies based on osci llator config-
uration. Table 5-1 shows the times that are associated
with the oscillator configuration. Figure 5-5 and Figure 5-
6 display these time-out s equences .
If the d evice v oltag e is not within electrical specif ication
at the end of a time-out, the MCLR/VPP pin must be
held low un til th e voltage is within the de vice spe ci fic a-
tion. The use of an external RC delay is sufficient for
many of these applications.
The time -out seque nce begins from the first risi ng edge
of MCLR.
Table 5-3 shows the RESET conditions for some spe-
cial registers, while Table 5-4 shows the initialization
conditions for all the registers.
TABLE 5-1: TIME-OUT IN VARIOUS SITUATIONS
TABLE 5-2: STATUS BITS AND THEIR SIGNIFICANCE
TABLE 5-3: RESET CONDITION FOR THE PROGRAM COUNTER AND THE CPUSTA REGISTER
Oscillator
Configuration POR, BOR Wake-up from
SLEEP MCLR Re s et
XT, LF Greater of: 96 ms or 1024TOSC 1024TOSC
EC, RC Greater of: 96 ms or 1024TOSC ——
POR BOR(1) TO PD Event
0011
Power-on Reset
1110
MCLR Reset during SLEEP or interrupt wake-up from SLEEP
1101
WDT Res et dur ing normal oper at i on
1100
WDT Wake-up during SLEEP
1111
MCLR Reset during norm al operation
1011
Bro w n-out Reset
000x
Illegal, TO is set on POR
00x0
Illegal, PD is set on POR
xx11
CLRWDT instruct i on executed
Note 1: When BO DE N i s enabled, else t he BO R status bit is unknown.
Event PCH:PCL CPUSTA(4) OST Active
Power-on Reset 0000h --11 1100 Yes
Brown-out Reset 0000h --11 1110 Yes
MCLR Reset during normal operation 0000h --11 1111 No
MCLR Reset during SLEEP 0000h --11 1011 Yes(2)
WDT Reset during normal operation 0000h --11 0111 No
WDT Reset during SLEEP(3) 0000h --11 0011 Yes(2)
Interrupt Wake-up from SLEEP GLINTD is set PC + 1 --11 1011 Yes(2)
GLINTD is clear PC + 1(1) --10 1011 Yes(2)
Legend: u = unchanged, x = unknown, - = unimplemented, read as '0'
Note 1: On wake-up, this instruction is executed. The instruction at the appropriate interrupt vector is fetched and
then execu ted.
2: The OST is only active (on wake-up) when the oscillator is configured for XT or LF modes.
3: The Program Counter = 0; that is, the device branches to the RESET vector and places SFRs in WDT
Reset states. This is different from the mid-range devices.
4: When BODEN is enabled, else the BOR status bit is unknown.
PIC17C7XX
DS30289B-page 26 2000 Microchip Technology Inc.
In Figure 5-5, Figure 5-6 and Figure 5-7, the TPWRT
timer time-out is greater then the TOST timer time-out,
as would be the case in higher frequency crystals. For
lower frequency crystals (i.e., 32 kHz), TOST may be
greater.
FIGURE 5-5: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED TO VDD)
FIGURE 5-6: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD)
FIGURE 5-7: SLOW RISE TIME (MCLR TIED TO VDD)
TPWRT
TOST
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-OUT
INTERNAL RE SET
TPWRT
TOST
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-OUT
INTERNAL RESET
VDD
MCLR
INTERNAL POR
PWRT TIME-OUT
OST TIME-O UT
INTERNAL RESET
0V 1V 5V
TPWRT
TOST
Minimum VDD Operating Voltage
2000 Microchip Technology Inc. DS30289B-page 27
PIC17C7XX
TABLE 5-4: INITIALIZATION CONDITIONS FOR SPECIAL FUNCTION REGISTERS
Register Address Power-on Reset
Brown-out Reset MCLR Reset
WDT R eset Wake-up from SLEEP
through Interrupt
Unbanked
INDF0 00h N/A N/A N/A
FSR0 01h xxxx xxxx uuuu uuuu uuuu uuuu
PCL 02h 0000h 0000h PC + 1(2)
PCLATH 03h 0000 0000 uuuu uuuu uuuu uuuu
ALUSTA 04h 1111 xxxx 1111 uuuu 1111 uuuu
T0STA 05h 0000 000- 0000 000- 0000 000-
CPUSTA(3) 06h --11 11qq --11 qquu --uu qquu
INTSTA 07h 0000 0000 0000 0000 uuuu uuuu(1)
INDF1 08h N/A N/A N/A
FSR1 09h xxxx xxxx uuuu uuuu uuuu uuuu
WREG 0Ah xxxx xxxx uuuu uuuu uuuu uuuu
TMR0L 0Bh xxxx xxxx uuuu uuuu uuuu uuuu
TMR0H 0Ch xxxx xxxx uuuu uuuu uuuu uuuu
TBLPTRL 0Dh 0000 0000 0000 0000 uuuu uuuu
TBLPTRH 0Eh 0000 0000 0000 0000 uuuu uuuu
BSR 0Fh 0000 0000 0000 0000 uuuu uuuu
Bank 0
PORTA(4,6) 10h 0-xx 11xx 0-uu 11uu u-uu uuuu
DDRB 11h 1111 1111 1111 1111 uuuu uuuu
PORTB(4) 12h xxxx xxxx uuuu uuuu uuuu uuuu
RCSTA1 13h 0000 -00x 0000 -00u uuuu -uuu
RCREG1 14h xxxx xxxx uuuu uuuu uuuu uuuu
TXSTA1 15h 0000 --1x 0000 --1u uuuu --uu
TXREG1 16h xxxx xxxx uuuu uuuu uuuu uuuu
SPBRG1 17h 0000 0000 0000 0000 uuuu uuuu
Legend: u = unchanged, x = unkn own, - = unimplemented, read as 0, q = value depends on condition
Note 1: One or more bits in INTSTA, PIR1, PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GLINTD bit is cleared, the PC is loaded with the interrupt
vector.
3: See Table 5-3 for RESET value of specific condition.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Microcontroller mode, the operation of this
port does not rely on these registers.
6: On any device RESET, these pins are configured as inputs .
PIC17C7XX
DS30289B-page 28 2000 Microchip Technology Inc.
Bank 1
DDRC(5) 10h 1111 1111 1111 1111 uuuu uuuu
PORTC(4,5) 11h xxxx xxxx uuuu uuuu uuuu uuuu
DDRD(5) 12h 1111 1111 1111 1111 uuuu uuuu
PORTD(4,5) 13h xxxx xxxx uuuu uuuu uuuu uuuu
DDRE(5) 14h ---- 1111 ---- 1111 ---- uuuu
PORTE(4,5) 15h ---- xxxx ---- uuuu ---- uuuu
PIR1 16h x000 0010 u000 0010 uuuu uuuu(1)
PIE1 17h 0000 0000 0000 0000 uuuu uuuu
Bank 2
TMR1 10h xxxx xxxx uuuu uuuu uuuu uuuu
TMR2 11h xxxx xxxx uuuu uuuu uuuu uuuu
TMR3L 12h xxxx xxxx uuuu uuuu uuuu uuuu
TMR3H 13h xxxx xxxx uuuu uuuu uuuu uuuu
PR1 14h xxxx xxxx uuuu uuuu uuuu uuuu
PR2 15h xxxx xxxx uuuu uuuu uuuu uuuu
PR3/CA1L 16h xxxx xxxx uuuu uuuu uuuu uuuu
PR3/CA1H 17h xxxx xxxx uuuu uuuu uuuu uuuu
Bank 3
PW1DCL 10h xx-- ---- uu-- ---- uu-- ----
PW2DCL 11h xx0- ---- uu0- ---- uuu- ----
PW1DCH 12h xxxx xxxx uuuu uuuu uuuu uuuu
PW2DCH 13h xxxx xxxx uuuu uuuu uuuu uuuu
CA2L 14h xxxx xxxx uuuu uuuu uuuu uuuu
CA2H 15h xxxx xxxx uuuu uuuu uuuu uuuu
TCON1 16h 0000 0000 0000 0000 uuuu uuuu
TCON2 17h 0000 0000 0000 0000 uuuu uuuu
TABLE 5-4: INITIALIZATION CONDITIONS FOR SPECIAL FUNCTION REGISTERS (CONTINUED)
Register Address Power-on Reset
Brown-out Reset MCLR Reset
WDT R eset Wake-up from SLEEP
through Interrupt
Legend: u = unchanged, x = unkn own, - = unimplemented, read as 0, q = value depends on condition
Note 1: One or more bits in INTSTA, PIR1, PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GLINTD bit is cleared, the PC is loaded with the interrupt
vector.
3: See Table 5-3 for RESET value of specific condition.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Microcontroller mode, the operation of this
port does not rely on these registers.
6: On any device RESET, these pins are configured as inputs .
2000 Microchip Technology Inc. DS30289B-page 29
PIC17C7XX
Bank 4
PIR2 10h 000- 0010 000- 0010 uuu- uuuu(1)
PIE2 11h 000- 0000 000- 0000 uuu- uuuu
Unimplemented 12h ---- ---- ---- ---- ---- ----
RCSTA2 13h 0000 -00x 0000 -00u uuuu -uuu
RCREG2 14h xxxx xxxx uuuu uuuu uuuu uuuu
TXSTA2 15h 0000 --1x 0000 --1u uuuu --uu
TXREG2 16h xxxx xxxx uuuu uuuu uuuu uuuu
SPBRG2 17h 0000 0000 0000 0000 uuuu uuuu
Bank 5
DDRF 10h 1111 1111 1111 1111 uuuu uuuu
PORTF(4) 11h 0000 0000 0000 0000 uuuu uuuu
DDRG 12h 1111 1111 1111 1111 uuuu uuuu
PORTG(4) 13h xxxx 0000 uuuu 0000 uuuu uuuu
ADCON0 14h 0000 -0-0 0000 -0-0 uuuu uuuu
ADCON1 15h 000- 0000 000- 0000 uuuu uuuu
ADRESL 16h xxxx xxxx uuuu uuuu uuuu uuuu
ADRESH 17h xxxx xxxx uuuu uuuu uuuu uuuu
Bank 6
SSPADD 10h 0000 0000 0000 0000 uuuu uuuu
SSPCON1 11h 0000 0000 0000 0000 uuuu uuuu
SSPCON2 12h 0000 0000 0000 0000 uuuu uuuu
SSPSTAT 13h 0000 0000 0000 0000 uuuu uuuu
SSPBUF 14h xxxx xxxx uuuu uuuu uuuu uuuu
Unimplemented 15h ---- ---- ---- ---- ---- ----
Unimplemented 16h ---- ---- ---- ---- ---- ----
Unimplemented 17h ---- ---- ---- ---- ---- ----
TABLE 5-4: INITIALIZATION CONDITIONS FOR SPECIAL FUNCTION REGISTERS (CONTINUED)
Register Address Power-on Reset
Brown-out Reset MCLR Reset
WDT R eset Wake-up from SLEEP
through Interrupt
Legend: u = unchanged, x = unkn own, - = unimplemented, read as 0, q = value depends on condition
Note 1: One or more bits in INTSTA, PIR1, PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GLINTD bit is cleared, the PC is loaded with the interrupt
vector.
3: See Table 5-3 for RESET value of specific condition.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Microcontroller mode, the operation of this
port does not rely on these registers.
6: On any device RESET, these pins are configured as inputs .
PIC17C7XX
DS30289B-page 30 2000 Microchip Technology Inc.
Bank 7
PW3DCL 10h xx0- ---- uu0- ---- uuu- ----
PW3DCH 11h xxxx xxxx uuuu uuuu uuuu uuuu
CA3L 12h xxxx xxxx uuuu uuuu uuuu uuuu
CA3H 13h xxxx xxxx uuuu uuuu uuuu uuuu
CA4L 14h xxxx xxxx uuuu uuuu uuuu uuuu
CA4H 15h xxxx xxxx uuuu uuuu uuuu uuuu
TCON3 16h -000 0000 -000 0000 -uuu uuuu
Unimplemented 17h ---- ---- ---- ---- ---- ----
Bank 8
DDRH 10h 1111 1111 1111 1111 uuuu uuuu
PORTH(4) 11h xxxx xxxx uuuu uuuu uuuu uuuu
DDRJ 12h 1111 1111 1111 1111 uuuu uuuu
PORTJ(4) 13h xxxx xxxx uuuu uuuu uuuu uuuu
Unbanked
PRODL 18h xxxx xxxx uuuu uuuu uuuu uuuu
PRODH 19h xxxx xxxx uuuu uuuu uuuu uuuu
TABLE 5-4: INITIALIZATION CONDITIONS FOR SPECIAL FUNCTION REGISTERS (CONTINUED)
Register Address Power-on Reset
Brown-out Reset MCLR Reset
WDT R eset Wake-up from SLEEP
through Interrupt
Legend: u = unchanged, x = unkn own, - = unimplemented, read as 0, q = value depends on condition
Note 1: One or more bits in INTSTA, PIR1, PIR2 will be affected (to cause wake-up).
2: When the wake-up is due to an interrupt and the GLINTD bit is cleared, the PC is loaded with the interrupt
vector.
3: See Table 5-3 for RESET value of specific condition.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Microcontroller mode, the operation of this
port does not rely on these registers.
6: On any device RESET, these pins are configured as inputs .
2000 Microchip Technology Inc. DS30289B-page 31
PIC17C7XX
5.1.5 BROWN-OUT RESET (BOR)
PIC17C7XX devices have on-chip Brown-out Reset
circuitry. This circuitry places the device into a RESET
when the d evice vol tag e f alls below a trip po int (BV DD).
This ensures that the device does not continue pro-
gram ex ecution outs ide the v alid operat ion ra nge of th e
dev ic e. B row n -o ut Re se ts are ty pi ca l ly us ed in A C li ne
applications, or large battery applications, where large
loads may be switched in (such as automotive).
The BODEN configuration bit can disable (if clear/
programmed), or enable (if set) the Brown-out Reset
circuitry. If VDD falls below BVDD (typically 4.0 V,
paramt er #D0 05 in elect rical s peci ficati on sec tion ), fo r
greater than parameter #35, the Brown-out situation
will res et the chip. A RESET is n ot guarant eed to occ ur
if VDD falls bel ow BVDD for less tha n paramter #3 5. The
chip will remain in Brown-out Reset until VDD rises
above BVDD. The Pow er-up Timer and Osc illator Sta rt-
up Timer will t hen be i nvoked. Thi s will k eep the chip i n
RESET the greater of 96 ms and 1024 TOSC. If VDD
drops below BVDD while the Power-up Timer/Oscillator
Start-up Timer is running, the chip will go back into a
Brown-ou t Reset. The Power-up Timer/Oscil lator S ta rt-
up Timer will be initialized. Once VDD rises above
BVDD, the Power-up Timer/Oscillator Start-up Timer
will start their time delays. Figure 5-10 shows typical
Brown-out situations.
In some applications, the Brown-out Reset trip point of
the de vice may n ot be at the desir ed level . Figure 5-8
and Figure 5-9 are two examples of external circuitry
that may be implemented. Each needs to be evaluated
to determine if they match the requirements of the
application.
FIGURE 5-8: EXTERNAL BROWN-OUT
PROTECTION CIRCUIT 1
FIGURE 5-9: EXTERNAL BROWN-OUT
PROTECTION CIRCUIT 2
FIGURE 5-10: BROWN-OUT SITUATIONS
Note: Before using the on-chip Brown-out for a
voltage supervisory function, please
review the electrical specifications to
ensure that they meet your requirements .
VDD
33k
10k
40 k
VDD
MCLR
PIC17CXXX
This circuit will activate RESET when VDD goes below
(Vz + 0.7V) where Vz = Zener voltage.
This brown-out circuit is less expensive, albeit less
accurate. Transistor Q1 turns off when VDD is below a
certain level such that:
VDD R1
R1 + R2 = 0.7V
R2 40 k
VDD
MCLR
PIC17CXXX
R1
Q1
VDD
Greater of 96 ms
BVDD Max.
BVDD Min.
VDD
Internal
RESET
BVDD Max.
BVDD Min.
VDD
Internal
RESET < 96 ms
BVDD Max.
BVDD Min.
VDD
Internal
RESET
and 1024 TOSC
Greater of 96 ms
and 1024 TOSC
Greater of 96 ms
and 1024 TOSC
PIC17C7XX
DS30289B-page 32 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 33
PIC17C7XX
6.0 INTERRUPTS
PIC17C7XX dev ic es have 18 source s of inte rrupt:
External int errup t from the RA0/INT pin
Change on RB7:RB0 pins
TMR0 Overfl ow
TMR1 Overfl ow
TMR2 Overfl ow
TMR3 Overfl ow
USART1 Transmit buffer empty
USART1 Receive buffer f ull
USART2 Transmit buffer empty
USART2 Receive buffer f ull
SSP Interrupt
SSP I2C bus collision interrupt
A/D con ve rsi on com pl ete
Capture1
Capture2
Capture3
Capture4
T0CKI edge occurred
There ar e six registe rs used in the contro l and sta tus of
interrupts. These are:
CPUSTA
INTSTA
PIE1
PIR1
PIE2
PIR2
The CPUSTA register contains the GLINTD bit. This is
the Global Interrupt Disable bit. When this bit is set, all
interrupts are disabled. This bit is part of the controller
core functionality and is described in the Section 6.4.
When an interrupt is responded to, the GLINTD bit is
automatically set to disable any further interrupts, the
return address is pushed onto the stack and the PC is
loaded w ith the interrupt ve ctor address. The re are four
interrupt vectors. Each vector address is for a specific
interrupt source (except the pe ripheral interrupts, which
all vector to the same address). These sources are:
External interrupt from the RA0/INT pin
TMR0 Overflow
T0CKI edge occurred
Any peripheral interrupt
When prog ram ex ecu tio n v ec tors to o ne o f the se inter-
rupt vector addresses (except for the peripheral inter-
rupts), the interrupt flag bit is automatically cleared.
Vectoring to the peripheral interrupt vector address
does no t automati cally cl ear the so urce of the interrupt.
In the peripheral Interrupt Service Routine, the
source(s) of the interrupt can be determined by testing
the i nterr upt flag bits. T he inte rrupt flag bi t(s) mu st be
cleared in software before re-enabling interrupts to
avoid infinite interrupt requests.
When an interrup t conditi on is met, that indivi dual int er-
rupt flag bit will be set, regardless of the status of its
corresponding mask bit or the GLINTD bit.
For external interrupt events, there will be an interrupt
latency. For two-cy cle instructi ons, the latency cou ld be
one instruction cycle longer.
The return from interrupt instruction, RETFIE, can be
used to mark the end of the Interrupt Service Routine.
When this instruction is executed, the stack is POPed
and the GLINTD bit is c leared (to re-enable interrupt s).
FIGURE 6-1: INTERRUP T LOGIC
RBIF
RBIETMR3IF
TMR3IE TMR2IF
TMR2IE
TMR1IF
TMR1IE CA2IF
CA2IE
CA1IF
CA1IE TX1IF
TX1IE RC1IF
RC1IE
T0IF
T0IE
INTF
INTE
T0CKIF
T0CKIE
GLINTD (CPUSTA<4>)
PEIE
Wa ke-up (If in SLEEP mode)
or terminate long write
Interrupt to CPU
PEIF
SSPIF
SSPIE BCLIF
BCLIE ADIF
ADIE
CA4IF
CA4IE CA3IF
CA3IE
TX2IF
TX2IE RC2IF
RC2IE
PIR1/PIE1
PIR2/PIE2
INTSTA
PIC17C7XX
DS30289B-page 34 2000 Microchip Technology Inc.
6.1 Interrupt Status Register (INTSTA)
The Inter rupt S tatus /Control regis ter (INTSTA) cont ains
the flag and enable bits for non-peripheral interrupts.
The PEIF bit is a read only , bit wise OR of all the periph-
eral flag bits in the PIR registers (Figure 6-4 and
Figure 6-5).
Care should be taken w hen clea ring any of the INTS TA
register enable bits when interrupts are enabled
(GLINTD is clear). If any of the INTSTA flag bits (T0IF,
INTF, T0CKIF, or PEIF) are set in the same instruction
cycle as the correspo nding interrupt enable bit is cleared,
the de vi ce wi ll v ecto r t o t he RESET a dd res s (0 x00).
Prior to disabling any of the INTSTA enable bits, the
GLINTD bit should be set (disabled).
REGISTER 6-1: INTSTA REGISTER (ADDRESS: 07h, UNBANKED)
Note: All interrupt flag bits get set by their speci-
fied condition, even if the corresponding
interrupt enable bit is clear (interrupt dis-
abled), or the GLINTD bit is set (all inter-
rupts disabled).
R-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE
bit 7 bit 0
bit 7 PEIF: Peripheral Interrupt Flag bi t
This bit is the OR o f all pe ripheral interru pt flag b its ANDed with t heir cor res pondin g enabl e bit s.
The interrupt logic forces program execution to address (20h) when a peripheral interrupt is
pending.
1 = A peripheral interrupt is pending
0 = No peripheral interrupt is pending
bit 6 T0CKIF: External Interrupt on T0CKI Pin Flag bit
This bit is cleared by hardware, when the interrupt logic forces program execution to address (18h).
1 = The software specified edge occurred on the RA1/T0CKI pin
0 = The software specified edge did not occur on the RA1/T0CKI pin
bit 5 T0IF: TMR0 Overflow Interrupt Flag bit
This bit is cleared by hardware, when the interrupt logic forces program execution to address (10h).
1 = TMR0 overflowed
0 = TMR0 did not overflow
bit 4 INTF: External Interrupt on INT Pin Flag bit
This bit is cleared by hardware, when the interrupt logic forces program execution to address (08h).
1 = The software specified edge occurred on the RA0/INT pin
0 = The software specified edge did not occur on the RA0/INT pin
bit 3 PEIE: Peripheral Interrupt Enable bit
This bit acts as a global enable bit for the peripheral interrupts that have their corresponding
enable bits set.
1 = Enable peripheral interrupts
0 = Disable peripheral interrupts
bit 2 T0CKIE: External Interrupt on T0CKI Pin Enable bit
1 = Enable software specified edge interrupt on the RA1/T0CKI pin
0 = Disable interrupt on the RA1/T0CKI pin
bit 1 T0IE: TMR0 Overflow Interrupt Enable bit
1 = Enable TMR0 overflow interrupt
0 = Disable TMR0 overflow interrupt
bit 0 INTE: External Interrupt on RA0/INT Pin Enable bit
1 = Enable software specified edge interrupt on the RA0/INT pin
0 = Disable software specified edge interrupt on the RA0/INT pin
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 35
PIC17C7XX
6.2 Peripheral Interrupt Enable
Register1 (PI E1 ) and Register2
(PIE2)
These registers contains the individual enable bits for
the peri phera l interru pts.
REGISTER 6-2: PIE1 REGISTER (ADDRESS: 17h, BANK 1)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE
bit 7 bit 0
bit 7 RBIE: PORTB Interrupt-on-Change Enable bit
1 = Enable PORTB interrupt-on-change
0 = Disable PORTB interrupt-on-change
bit 6 TMR3IE: TMR3 Interrupt Enable bit
1 = Enable TMR3 interrupt
0 = Disable TMR3 interrupt
bit 5 TMR2IE: TMR2 Interrupt Enable bit
1 = Enable TMR2 interrupt
0 = Disable TMR2 interrupt
bit 4 TMR1IE: TMR1 Interrupt Enable bit
1 = Enable TMR1 interrupt
0 = Disable TMR1 interrupt
bit 3 CA2IE: Capture2 Interrup t Enable bit
1 = Enable Capture2 interrupt
0 = Disable Capture2 interrupt
bit 2 CA1IE: Capture1 Interrup t Enable bit
1 = Enable Capture1 interrupt
0 = Disable Capture1 interrupt
bit 1 TX1IE: USART1 Transmit Interrupt Enable bit
1 = Enable USART1 Transmit buffer empty int e rrupt
0 = Disable USART1 Transmit buffer empty interrupt
bit 0 RC1IE: USART1 Rece iv e Interru pt Enab le bit
1 = Enable USART1 Receive buffer full interrupt
0 = Disable USART1 Receive buffer full interrupt
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 36 2000 Microchip Technology Inc.
REGISTER 6-3: PIE2 REGISTER (ADDRESS: 11h, BANK 4)
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE
bit 7 bit 0
bit 7 SSPIE: Synchronous Serial Port Interrupt Enable bit
1 = Enable SSP interrupt
0 = Disable SSP interrupt
bit 6 BCLIE: Bus Collision Interrupt Enable bit
1 = Enable bus collision interrupt
0 = Disable bus collision interrupt
bit 5 ADIE: A/D Module Interrupt Enable bit
1 = Enable A/D module interrupt
0 = Disable A/D module interrupt
bit 4 Unimplemented: Read as 0
bit 3 CA4IE: Capture4 Interrup t Enable bit
1 = Enable Capture4 interrupt
0 = Disabl e Capture4 interrup t
bit 2 CA3IE: Capture3 Interrup t Enable bit
1 = Enable Capture3 interrupt
0 = Disabl e Capture3 interrup t
bit 1 TX2IE: USART2 Transmit Interrupt Enable bit
1 = Enable USART2 Transmit buffer empty int e rrupt
0 = Disable USART2 Transmit buffer empty interrupt
bit 0 RC2IE: USART2 Rece iv e Interru pt Enab le bit
1 = Enable USART2 Receive buffer full interrupt
0 = Disable USART2 Receive buffer full interrupt
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 37
PIC17C7XX
6.3 Peripheral Interrupt Request
Register1 (PI R1 ) and Register2
(PIR2)
These registers contains the individual flag bits for the
peripheral interrupts.
REGISTER 6-4: PIR1 REGISTER (ADDRESS: 16h, BANK 1)
Note: These bits will be set by the specified condi-
tion, even if the corresponding interrupt
enable bit is cleared (interrupt disabled), or
the GLINTD bit is set (all interrupts disabled).
Before enabling an interrupt, the user may
wish to clear the interrupt flag to ensure that
the program does not immediately branch to
the peripheral Interrupt Service Routine.
R/W-x R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R-1 R-0
RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF
bit 7 bit 0
bit 7 RBIF: PORTB Interrupt-on-C hange Flag bit
1 = One of the PORTB inputs changed (software must end the mismatch condition)
0 = None of the PORTB inputs have changed
bit 6 TMR3IF: TMR3 Interrupt Flag bit
If Capture1 is enabled (CA1/PR3 = 1):
1 = TMR3 overflowed
0 = TMR3 did not overflow
If Capture1 is disabled (CA1/PR3 = 0):
1 = TMR3 value has rolled over to 0000h from equalling the period register (PR3H:PR3L) value
0 = TMR3 value has not rolled over to 0000h from equalling the period register (PR3H:PR3L)
value
bit 5 TMR2IF: TMR2 Interrupt Flag bit
1 = TMR2 value has rolled over to 0000h from equalling the period register (PR2) value
0 = TMR2 value has not rolled over to 0000h from equalling the period register (PR2) value
bit 4 TMR1IF: TMR1 Interrupt Flag bit
If TMR1 is in 8-bit mode (T16 = 0):
1 = TMR1 value has rolled over to 0000h from equalling the period register (PR1) value
0 = TMR1 value has not rolled over to 0000h from equalling the period register (PR1) value
If Timer1 is in 16-bit mode (T16 = 1):
1 = TMR2:TMR1 value has rolled over to 0000h from equalling the period register (PR2:PR1)
value
0 = TMR2:T MR1 value has not ro lled over to 00 00h from equal ling the period register (PR2:PR1 )
value
bit 3 CA2IF: Capture2 Interrupt Flag bit
1 = Capture event occurred on RB1/CAP2 pin
0 = Capture event did not occur on RB1/CAP2 pin
bit 2 CA1IF: Capture1 Interrupt Flag bit
1 = Capture event occurred on RB0/CAP1 pin
0 = Capture event did not occur on RB0/CAP1 pin
bit 1 TX1IF: USART1 Transmit Interrupt Flag bit (state controlled by hardware)
1 = US ART1 Transmit buffer is empty
0 = USART1 Transmit buffer is full
bit 0 RC1IF: USART1 Receive In terrupt Flag bit (state controlled by hardware)
1 = USART1 Receive buffer is full
0 = US ART1 Receive buffer is empty
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 38 2000 Microchip Technology Inc.
REGISTER 6-5: PIR2 REGISTER (ADDRESS: 10h, BANK 4)
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R-1 R-0
SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF
bit 7 bit 0
bit 7 SSPIF: Synchronous Serial Port (SSP) Interrupt Flag bit
1 = The SSP interrupt condition has occurred and must be cleared in software before returning
from the Interrupt Service Routine. The conditions that will set this bit are:
SPI:
A transmission/reception has taken place.
I2 C Slave/Master:
A transmission/reception has taken place.
I2 C Master:
The initiated START condition was completed by the SSP module.
The initiated STOP c ondition was completed by the SSP module.
The initiated Restart condition was completed by the SSP module.
The initiated Acknowledge condition was completed by the SSP module.
A START condition occurred while the SSP module was idle (Multi-master system).
A STOP condition occurred while the SSP module was idle (Multi-master system).
0 = An SSP interrupt condition has NOT occurred
bit 6 BCLIF: Bus Collision Interrupt Flag bit
1 = A bus collision has occurred in the SSP, when configured for I2C Master mode
0 = No bus collision has occurred
bit 5 ADIF: A/D Module Interrupt Flag bit
1 = An A/D conversion is complete
0 = An A/D conversion is not complete
bit 4 Unimplemented: Read as 0
bit 3 CA4IF: Capture4 Interrupt Flag bit
1 = Capture event occurred on RE3/CAP4 pin
0 = Capture event did not occur on RE3/CAP4 pin
bit 2 CA3IF: Capture3 Interrupt Flag bit
1 = Capture event occurred on RG4/CAP3 pin
0 = Capture event did not occur on RG4/CAP3 pin
bit 1 TX2IF:USART2 Transmit Interrupt Flag bit (state controlled by hardware)
1 = USART2 Transmit buffer is empty
0 = USART2 Transmit buffer is full
bit 0 RC2IF: USART2 Receive In terrupt Flag bit (state controlled by hardware)
1 = USART2 Receive buffer is full
0 = USART2 Receive buffe r is empty
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 39
PIC17C7XX
6.4 Interrupt Operation
Global Interrupt Disable bit, GLINTD (CPUSTA<4>),
enables all unmasked interrupts (if clear), or disables
all interrupts (if set). Individual interrupts can be dis-
abled through their corresponding enable bits in the
INTSTA register. Peripheral interrupts need either the
global peripheral enable PEIE bit disabled, or the spe-
cific peripheral enable bit disabled. Disabling the
peripherals via the global peripheral enable bit, dis-
ables all peripheral interrupts. GLINTD is set on
RESET (interrupts disabled).
The RETFIE instruction clears the GLINTD bit while
forcing the Program Counter (PC) to the value loaded
at the Top-of-Stack.
When an interrupt is responded to, the GLINTD bit is
automatically set to disable any further interrupt, the
return address is pushed onto the stack and the PC is
loaded with the inte rrupt vector . T here are four interrupt
vectors which help reduce interrupt latency.
The peripheral interrupt vector has multiple interrupt
sources. Once in the peripheral Interrupt Service Rou-
tine, the source(s) of the interrupt ca n be determined by
polling the interrupt flag bits. The peripheral interrupt
flag bit(s) must be cleared in software before re-
enabling interrupts to avoid continuous interrupts.
The PIC17C7XX devices have four interrupt vectors.
These v ec tors and the ir ha rdware pri ority are sh ow n i n
Table 6-1. If two enabled interrupts occur at the same
time, the interrupt of the highest priority will be ser-
viced first. This means that the vector address of that
interrupt will be loaded into the program counter (PC).
TABLE 6-1: INTERRUPT VECTORS/
PRIORITIES
6.5 RA0/INT Interrupt
The external interrupt on the RA0/INT pin is edge trig-
gered. Either the rising edge if the INTEDG bit
(T0STA<7>) is set, or the fa lling edge if the INTEDG b it
is clear. When a valid edge appears on the RA0/INT
pin, the IN TF b it (INTSTA<4>) is set. Thi s i nte rrupt ca n
be disabled by clearing the INTE control bit
(INTSTA<0>). The INT interrupt can wake the proces-
sor from SLEEP. See Section 17.4 for details on
SLEEP operation.
6.6 T0CKI Interrupt
The external interrupt on the RA1/T0CKI pin is edge
triggered. Either the rising edge if the T0SE bit
(T0STA<6>) is set, or the fall ing edge if the T0SE bit i s
clear. When a valid edge appears on the RA1/T0CKI
pin, the T0CKIF bit (INTSTA<6>) is set. This interrupt
can be disabled by clearing the T0CKIE control bit
(INTSTA<2>). The T0CKI interrupt can wake up the
process or from SLEEP. See Section 17.4 fo r det ails on
SLEEP operation.
6.7 Peripheral Interrupt
The peri pheral int errupt flag indicates that at least one
of the periphe ral interrupts occurred (P EIF is set). The
PEIF bit is a read only bit and is a bit wise OR of all the
flag bits in the PIR registers ANDd with the correspond-
ing enable bits in the PIE registers. Some of the periph-
eral interrupts can wake the processor from SLEEP.
See Section 17.4 for details on SLEEP operat ion.
6.8 Context Saving During Interrupts
During an interrupt, only th e returned PC value is sa ved
on the stack. Typically, users may wish to save key reg-
isters during an interrupt; e.g. WREG, ALUSTA and the
BSR registers. This requires implement ation in software.
Example 6-2 shows the saving and restoring of infor-
mation for an Interrupt Service Routine. This is for a
simple interrupt scheme, where only one interrupt may
occur at a time (no interrupt nesting). The SFRs are
stored in the non-banked GPR area.
Example 6-2 shows the saving and restoring of infor-
mation for a more complex Interrupt Service Routine.
This is useful where nesting of interrupts is required. A
maxim um of 6 levels can be don e by this ex ample. Th e
BSR is stored in the non-banked GPR area, while the
other registers would be stored in a particular bank.
Therefore, 6 saves may be don e with this routine (si nce
there are 6 non-banke d GPR registers). These routines
require a d edica ted ind irect ad dress ing reg ister, FSR 0,
to be selected for this.
The PUSH and POP code segments could either be in
each I nterrupt Servi ce Routin e, or could be subrouti nes
that were called. Depending on the application, other
registers may also need to be saved.
Address Vector Priority
0008h External Interrupt on RA0/
INT pin (INTF) 1 (Highest)
0010h TMR0 Overfl ow Interru pt
(T0IF) 2
0018h External Interrupt on T0CKI
(T0CKIF) 3
0020h Periphera ls (PEIF) 4 (Lowest)
Note 1: Indiv idual inter rupt flag bit s are set, reg ard-
less of the status of their corresponding
mask bit or the GLINTD bit.
2: Before dis abling an y of the INT STA enable
bits, the GLINTD bit should be set
(disabled).
PIC17C7XX
DS30289B-page 40 2000 Microchip Technology Inc.
FIGURE 6-2: INT PIN/T0CKI PIN INTERRUPT TIMING
Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4
OSC1
OSC2
RA0/INT or
RA1/T0CKI
INTF or
T0CKIF
GLINTD
PC
Instruction
Executed
System Bus
Instruction
Fetched
PC PC + 1 Addr (Vect or)
PC Inst (PC) Inst (PC+1)
Inst (PC) Dummy Dummy
YY YY + 1
RETFIE
RETFIE
Inst (PC+1) Inst (Vector)
Addr
Addr
Addr Addr Addr Inst (YY + 1)
Dummy
PC + 1
2000 Microchip Technology Inc. DS30289B-page 41
PIC17C7XX
EXAMPLE 6-1: SAVING STATUS AND WREG IN RAM (SIMPLE)
; The addresses that are used to store the CPUSTA and WREG values must be in the data memory
; address range of 1Ah - 1Fh. Up to 6 locations can be saved and restored using the MOVFP
; instruction. This instruction neither affects the status bits, nor corrupts the WREG register.
;
UNBANK1 EQU 0x01A ; Address for 1st location to save
UNBANK2 EQU 0x01B ; Address for 2nd location to save
UNBANK3 EQU 0x01C ; Address for 3rd location to save
UNBANK4 EQU 0x01D ; Address for 4th location to save
UNBANK5 EQU 0x01E ; Address for 5th location to save
; (Label Not used in program)
UNBANK6 EQU 0x01F ; Address for 6th location to save
; (Label Not used in program)
;
: ; At Interrupt Vector Address
PUSH MOVFP ALUSTA, UNBANK1 ; Push ALUSTA value
MOVFP BSR, UNBANK2 ; Push BSR value
MOVFP WREG, UNBANK3 ; Push WREG value
MOVFP PCLATH, UNBANK4 ; Push PCLATH value
;
: ; Interrupt Service Routine (ISR) code
;
POP MOVFP UNBANK4, PCLATH ; Restore PCLATH value
MOVFP UNBANK3, WREG ; Restore WREG value
MOVFP UNBANK2, BSR ; Restore BSR value
MOVFP UNBANK1, ALUSTA ; Restore ALUSTA value
;
RETFIE ; Return from interrupt (enable interrupts)
PIC17C7XX
DS30289B-page 42 2000 Microchip Technology Inc.
EXAMPLE 6-2: SAVING STATUS AND WREG IN RAM (NESTED)
; The addresses that are used to store the CPUSTA and WREG values must be in the data memory
; address range of 1Ah - 1Fh. Up to 6 locations can be saved and restored using the MOVFP
; instruction. This instruction neither affects the status bits, nor corrupts the WREG register.
; This routine uses the FRS0, so it controls the FS1 and FS0 bits in the ALUSTA register.
;
Nobank_FSR EQU 0x40
Bank_FSR EQU 0x41
ALU_Temp EQU 0x42
WREG_TEMP EQU 0x43
BSR_S1 EQU 0x01A ; 1st location to save BSR
BSR_S2 EQU 0x01B ; 2nd location to save BSR (Label Not used in program)
BSR_S3 EQU 0x01C ; 3rd location to save BSR (Label Not used in program)
BSR_S4 EQU 0x01D ; 4th location to save BSR (Label Not used in program)
BSR_S5 EQU 0x01E ; 5th location to save BSR (Label Not used in program)
BSR_S6 EQU 0x01F ; 6th location to save BSR (Label Not used in program)
;
INITIALIZATION ;
CALL CLEAR_RAM ; Must Clear all Data RAM
;
INIT_POINTERS ; Must Initialize the pointers for POP and PUSH
CLRF BSR, F ; Set All banks to 0
CLRF ALUSTA, F ; FSR0 post increment
BSF ALUSTA, FS1
CLRF WREG, F ; Clear WREG
MOVLW BSR_S1 ; Load FSR0 with 1st address to save BSR
MOVWF FSR0
MOVWF Nobank_FSR
MOVLW 0x20
MOVWF Bank_FSR
:
: ; Your code
:
: ; At Interrupt Vector Address
PUSH BSF ALUSTA, FS0 ; FSR0 has auto-increment, does not affect status bits
BCF ALUSTA, FS1 ; does not affect status bits
MOVFP BSR, INDF0 ; No Status bits are affected
CLRF BSR, F ; Peripheral and Data RAM Bank 0 No Status bits are affected
MOVPF ALUSTA, ALU_Temp ;
MOVPF FSR0, Nobank_FSR ; Save the FSR for BSR values
MOVPF WREG, WREG_TEMP ;
MOVFP Bank_FSR, FSR0 ; Restore FSR value for other values
MOVFP ALU_Temp, INDF0 ; Push ALUSTA value
MOVFP WREG_TEMP, INDF0 ; Push WREG value
MOVFP PCLATH, INDF0 ; Push PCLATH value
MOVPF FSR0, Bank_FSR ; Restore FSR value for other values
MOVFP Nobank_FSR, FSR0 ;
;
: ; Interrupt Service Routine (ISR) code
;
POP CLRF ALUSTA, F ; FSR0 has auto-decrement, does not affect status bits
MOVFP Bank_FSR, FSR0 ; Restore FSR value for other values
DECF FSR0, F ;
MOVFP INDF0, PCLATH ; Pop PCLATH value
MOVFP INDF0, WREG ; Pop WREG value
BSF ALUSTA, FS1 ; FSR0 does not change
MOVPF INDF0, ALU_Temp ; Pop ALUSTA value
MOVPF FSR0, Bank_FSR ; Restore FSR value for other values
DECF Nobank_FSR, F ;
MOVFP Nobank_FSR, FSR0 ; Save the FSR for BSR values
MOVFP ALU_Temp, ALUSTA ;
MOVFP INDF0, BSR ; No Status bits are affected
;
RETFIE ; Return from interrupt (enable interrupts)
2000 Microchip Technology Inc. DS30289B-page 43
PIC17C7XX
7.0 MEMORY ORGANIZATION
There are two memory blocks in the PIC17C7XX; pro-
gram memory and data memory. Each block has its
own bus , so that acces s to each block ca n occur during
the same oscillator cycle.
The data memory can further be broken down into
General Purpose RAM and the Special Function Reg-
isters (SFRs). The operation of the SFRs that control
the core are descr ibed he re. Th e SFRs us ed to con -
trol the peripheral modules are described in the section
discus s ing each ind iv idu al peri phe ral modul e.
7.1 Program Memory Organization
PIC17C7XX devices have a 16-bit program counter
capable of addressing a 64K x 16 program memory
spa ce. The RESET vector is at 0000h and the interru pt
vectors are at 0008h, 0010h, 0018h, and 0020h
(Figure 7-1).
7.1.1 PROGRAM MEMORY OPERATION
The PIC17C7XX can operate in one of four possible
program memory configurations. The configuration is
select ed by configu ration bit s. The poss ible modes a re:
Microprocessor
Microcontroller
Extended Microcontroller
Protected Microcontroller
The Microcontroller and Protected Microcontroller
modes only allow internal execution. Any access
beyond the program m emory reads unk nown dat a. The
Protected Microcontroller mode also enables the code
prote ction feature.
The Extended Microcontroller mode accesses both
the internal program memory, as well as external pro-
gram memory. Execution automatically switches
between internal and external memory. The 16-bits of
address al low a pro gram m emory rang e o f 64 K-w ords.
The Microprocessor mod e only acce sses the ext ernal
program memory. The on-chip program memory is
ignored. The 16-bits of address allow a program mem-
ory range of 64K-words. Microprocessor mode is the
default mode of an unp rogrammed device.
The di ffere nt modes all ow diffe rent ac cess to the c on-
figuration bits, test memory and boot ROM. Table 7-1
lists which modes can access which areas in memory.
Test Memory and Boot Memory are not required for
normal operation of the device. Care should be taken
to ensure that no unintended branches occur to these
areas.
FIGURE 7-1: PROGRAM MEMORY MAP
AND STACK
PC<15:0>
Stack Level 1
Stack Level 16
RESET Vector
INT Pin Interrupt Vec tor
Timer0 Interrupt Vec tor
T0CKI Pin Interrupt Vector
Peripheral Interrupt Vector
FOSC0
FOSC1
WDTPS0
WDTPS1
PM0
Reserved
PM1
Reserved
Configuration Memory
Space User Mem o ry
Space(1)
CALL, RETURN
RETFIE, RETLW
16
0000h
0008h
0010h
0020h
0021h
0018h
FDFFh
FE00h
FE01h
FE02h
FE03h
FE04h
FE05h
FE06h
FE07h
FE0Fh
Test EPROM
Boot RO M
FE10h
FF5Fh
FF60h
FFFFh
1FFFh
3FFFh
(PIC17C752
(PIC17C756A
Reserved
PM2
FE08h
Note 1: User memory space may be internal, external,
or both. The memory configuration depends
on the processor mode.
FE0Eh
BODEN FE0Dh
PIC17C762)
PIC17C766)
PIC17C7XX
DS30289B-page 44 2000 Microchip Technology Inc.
TABLE 7-1: MODE MEMORY ACCESS The PIC17C7XX can operate in modes where the pro-
gram memory is off-chip. They are the Microprocessor
and Extended Microcontroller modes. The Micropro-
cessor mode is the default for an unprogrammed
device.
Regardless of the processor mode, data memory is
always on-chip.
FIGURE 7-2: MEMORY MAP IN DIFFERENT MODES
Operating
Mode
Internal
Program
Memory
Configuration Bits,
Test Memory,
Boot ROM
Microprocessor No Access No Access
Microcontroller Access Access
Extended
Microcontroller Access No Access
Protected
Microcontroller Access Access
Microprocessor
Mode
0000h
FFFFh
External
Program
Memory External
Program
Memory
2000h
FFFFh
0000h
01FFFh
On-chip
Program
Memory
Extended
Microcontroller
Mode
Microcontroller
Modes
0000h
01FFFh
2000h
FE00h
FFFFh
ON-CHIP ON-CHIP ON-CHIP
OFF-CHIP ON-CHIP OFF-CHIP ON-CHIP OFF-CHIP ON-CHIP
PROGRAM SPACEDATA SPACE
Config. Bits
Test Memory
Boot ROM
PIC17C752/762
0000h
FFFFh
External
Program
Memory External
Program
Memory
FFFFh
0000h 0000h
3FFFh
4000h
FE00h
FFFFh
OFF-CHIP ON-CHIP OFF-CHIP ON-CHIP OFF-CHIP ON-CHIP
Config. Bits
Test Memory
Boot ROM
PROGRAM SPACEDATA SPACE
ON-CHIPON-CHIP
00h
FFh 1FFh
120h
ON-CHIP
3FFFh
4000h
PIC17C756A/766
On-chip
Program
Memory
On-chip
Program
Memory
On-chip
Program
Memory
2FFh
220h
3FFh
320h
00h
FFh 1FFh
120h
2FFh
220h
3FFh
320h
00h
FFh 1FFh
120h
2FFh
220h
3FFh
320h
00h
FFh 1FFh
120h
00h
FFh 1FFh
120h
00h
FFh 1FFh
120h
2000 Microchip Technology Inc. DS30289B-page 45
PIC17C7XX
7.1.2 EX TERN AL ME MORY INT ERFA CE
When eit her Microp rocessor or Extended M icrocontro l-
ler mo de is s elected, PO RTC, PORTD a nd POR TE are
configu red as the system bus . PORTC and PORTD a re
the multiplexed address/data bus and PORTE<2:0> is
for the control signals. External components are
needed to demultiplex the address and data. This can
be done as shown in Figure 7-4. The waveforms of
address and data are shown in Figure 7-3. For com-
plete timings, please refer to the electrical specification
section.
FIGURE 7-3: EXTERNAL PROGRAM
MEMORY ACCESS
WAVEFORMS
The system bus requires that there is no bus conflict
(minim al leakage), so t he output val ue (address) wi ll be
capacitively held at the desired value.
As the speed of the processor increases, external
EPROM memory with faster access time must be used.
Table 7-2 lists external m emory speed requirement s for
a given PIC 17C7XX device frequen c y.
In Extended Microcontroller mode, when the device is
executing out of internal memory, the control signals
will continue to be active. That is, they indicate the
action that is occurring in the internal memory. The
external memory access is ignored.
The following selection is for use with Microchip
EPROMs. For inte rfacing to other manufac turers mem-
ory, please refer to the electrical specifications of the
desired PIC17C7XX device, as well as the desired
memory device to ensure compatibility.
TABLE 7-2: EPROM MEMORY ACCESS
TIME OR DERING SUFFIX
The elec trical speci ficati ons no w includ e timi ng spe cifi-
cations for the memory interface with PIC17LCXXX
devices. These specifications reflect the capability of
the device by characterization. Please validate your
design w ith the se tim in gs.
FIGURE 7-4: TYPICAL EXTERNAL PROGRAM MEMORY CONNECTION DIAGRAM
Q3
Q1 Q2 Q4 Q3
Q1 Q2 Q4
AD
<15:0>
ALE
OE
WR 1
Read Cycle Write Cycle
Address out Data in Address out Data out
Q1
PIC17C7XX
Oscillator
Frequency
Instruction
Cycle Time
(TCY) EPROM Suffix
8 MHz 500 ns -25
16 MHz 250 ns -15
20 MHz 200 ns -10
25 MHz 160 ns -70
Note: The access times for this requires the use
of fast SRAMs.
AD7-AD0
PIC17CXXX
AD15-AD8
ALE
I/O(1)
AD15-AD0
Memory(3)
(MSB)
Ax-A0
D7-D0
A15-A0 Memory(3)
(LSB)
Ax-A0
D7-D0
138(1)
OE
WR
OE OE
WR(2) WR(2)
CE CE
Note 1: Use of I/O pins is only required for paged memory.
2: This signal is unused for ROM and EPROM devices.
3: 16-bit wide devices are now common and could be used instead of 8-bit wide devices.
373(3)
373(3)
PIC17C7XX
DS30289B-page 46 2000 Microchip Technology Inc.
7.2 Data Memory Organizati on
Data memory is partitioned into two areas. The first is
the General Purpose Registers (GPR) area, and the
second is the Special Function Registers (SFR) area.
The SFRs control and provide status of device opera-
tion.
Portions of data memory are banked, this occurs in
both areas. The GPR area is banked to allow greater
than 232 bytes of general purpose RAM.
Banking requires the use of control bits for bank selec-
tion. These control bits are located in the Bank Select
Register (BSR). If an access is made to the unbanked
region, th e BSR bi t s a re ig nore d. Fi gure 7-5 shows the
data m emory map organization.
Instructions MOVPF and MOVFP provide the means to
move v alues fro m the periph eral ar ea ( P) to an y loca-
tion in the register file (F), an d vic e-vers a. The defin i-
tion of the P range is from 0h to 1Fh, while the F
range is 0h to FFh. The P range has six more loca-
tions than peripheral registers, which can be used as
General Purpose Registers. This can be useful in some
applic ations wher e variables need to be co pied to other
locations in the general purpose RAM (such as saving
status information during an interrupt).
The entire data memory can be accessed either
directly, or indirectly (through file select registers FSR0
and FSR1) (see Section 7.4). Indirect addressing uses
the appropriate control bits of the BSR for access into
the banked areas of data memory. The BSR is
explained in greater detail in Section 7.8.
7.2. 1 GENERAL PURPOSE REGISTER
(GPR)
All devi ces have some amoun t of GPR area. The GPRs
are 8-bits wide. When the GPR area is greater than
232, it must be banked to allow acce ss to the additi onal
memory space.
All the PIC17C7XX devices have banked memory in
the GPR area. To facilitate switching between these
banks, the MOVLR bank instructio n has been a dded to
the instru ction set. GPRs are not initi alized by a Power-
on Reset and are unchanged on all other RESETS.
7.2.2 SPECIAL FUNCTION REGISTERS
(SFR)
The SFRs are used by the CPU and peripheral func-
tions to control th e operation of the dev ice (Figure 7-5).
These registers are static RAM.
The SFRs can be classified into two sets, those asso-
ciated with the core function and those related to the
peripheral functions. Those registers related to the
core are described here, while those related to a
periphera l featu re ar e desc ribed i n the s ection for eac h
peripheral feature.
The peripheral registers are in the banked portion of
memory, while the core registers are in the unbanked
region. To facilitate switching between the peripheral
banks, the MOVLB bank inst ruction has been pr ovided.
2000 Microchip Technology Inc. DS30289B-page 47
PIC17C7XX
FIGURE 7-5: PIC17C7XX REGISTER FILE MAP
Addr Unbanked
00h INDF0
01h FSR0
02h PCL
03h PCLATH
04h ALUSTA
05h T0STA
06h CPUSTA
07h INTSTA
08h INDF1
09h FSR1
0Ah WREG
0Bh TMR0L
0Ch TMR0H
0Dh TBLPTRL
0Eh TBLPTRH
0Fh BSR
Bank 0 Bank 1(1) Bank 2(1) Bank 3(1) Bank 4(1) Bank 5(1) Bank 6(1) Bank 7(1) Bank 8(1,4)
10h PORTA DDRC TMR1 PW1DCL PIR2 DDRF SSPADD PW3DCL DDRH
11h DDRB PORTC TMR2 PW2DCL PIE2 PORTF SSPCON1 PW3DCH PORTH
12h PORTB DDRD TMR3L PW1DCH DDRG SSPCON2 CA3L DDRJ
13h RCSTA1 PORTD TMR3H PW2DCH RCSTA2 PORTG SSPSTAT CA3H PORTJ
14h RCREG1 DDRE PR1 CA2L RCREG2 ADCON0 SSPBUF CA4L
15h TXSTA1 PORTE PR2 CA2H TXSTA2 ADCON1 CA4H
16h TXREG1 PIR1 PR3L/CA1L TCON1 TXREG2 ADRESL TCON3
17h SPBRG1 PIE1 PR3H/CA1H TCON2 SPBRG2 ADRESH
Unbanked
18h PRODL
19h PRODH
1Ah
1Fh
General
Purpose
RAM
Bank 0(2) Bank 1(2) Bank 2(2) Bank 3(2,3)
20h
FFh
General
Purpose
RAM
General
Purpose
RAM
General
Purpose
RAM
General
Purpose
RAM
Note 1: SFR file locations 10h - 17h are banked. The lower nibble of the BSR specifies the bank. All unbanked
SFRs ignore the Bank Select Register (BSR) bits.
2: General Purpose Registers (GPR) locations 20h - FFh, 120h - 1FFh, 220h - 2FFh, and 320h - 3FFh are
banked. The upper nibble of the BSR specifies this bank. All other GPRs ignore the Bank Select Register
(BSR) bits.
3: RAM bank 3 is not implemented on the PIC17C752 and the PIC17C762. Reading any unimplemented reg-
ister reads 0s.
4: Bank 8 is only implemented on the PIC17C76X devices.
PIC17C7XX
DS30289B-page 48 2000 Microchip Technology Inc.
TABLE 7-3: SPECIAL FUNCTION REGISTERS
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
Unbanked
00h INDF0 Uses contents of FSR0 to address Data Memory (not a physical register) ---- ---- ---- ----
01h FSR0 Indirect Data Memory Address Pointer 0 xxxx xxxx uuuu uuuu
02h PCL Low order 8-bit s of PC 0000 0000 0000 0000
03h(1) PCLATH Holding Register for upper 8-bits of PC 0000 0000 uuuu uuuu
04h ALUSTA FS3 FS2 FS1 FS0 OV Z DC C 1111 xxxx 1111 uuuu
05h T0STA INTEDG T0SE T0CS T0PS3 T0PS2 T0PS1 T0PS0 0000 000- 0000 000-
06h(2) CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
07h INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
08h INDF1 Uses contents of FSR1 to address Data Memory (not a physical register) ---- ---- ---- ----
09h FSR1 Indirect Data Memory Address Pointer 1 xxxx xxxx uuuu uuuu
0Ah WREG Working Register xxxx xxxx uuuu uuuu
0Bh TMR0L TMR0 Register; Low Byte xxxx xxxx uuuu uuuu
0Ch TMR0H TMR0 Register; High Byte xxxx xxxx uuuu uuuu
0Dh TBLPTRL Low Byte of Progra m Memory Table Pointer 0000 0000 0000 0000
0Eh TBLP TRH High Byte of Progra m Memory Table Pointer 0000 0000 0000 0000
0Fh BSR Bank Select Regist er 0000 0000 0000 0000
Bank 0
10h PORTA(4,6) RBPU RA5/TX1/
CK1 RA4/RX1/
DT1 RA3/SDI/
SDA RA2/SS/
SCL RA1/T0CKI RA0/INT 0-xx 11xx 0-uu 11uu
11h DDRB Data Direct ion Register for PORTB 1111 1111 1111 1111
12h PORTB(4) RB7/
SDO RB6/
SCK RB5/
TCLK3 RB4/
TCLK12 RB3/
PWM2 RB2/
PWM1 RB1/
CAP2 RB0/
CAP1 xxxx xxxx uuuu uuuu
13h RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h RCREG1 Serial Port Receive Register xxxx xxxx uuuu uuuu
15h TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
16h TXREG1 Serial Port Transmit Register (for USART1) xxxx xxxx uuuu uuuu
17h SPBRG1 Baud Rate Generator Register (for USART 1) 0000 0000 0000 0000
Bank 1
10h DDRC(5) Data Direct ion Regis ter for POR TC 1111 1111 1111 1111
11h PORTC(4,5) RC7/AD7 RC6/AD6 RC5/AD5 RC4/AD4 RC3/AD3 RC2/AD2 RC1/AD1 RC0/AD0 xxxx xxxx uuuu uuuu
12h DDRD(5) Data Direct ion Regis ter for POR TD 1111 1111 1111 1111
13h PORTD(4,5) RD7/
AD15 RD6/
AD14 RD5/
AD13 RD4/
AD12 RD3/
AD11 RD2/
AD10 RD1/AD9 RD0/AD8 xxxx xxxx uuuu uuuu
14h DDRE(5) Data Direct ion Registe r for POR TE ---- 1111 ---- 1111
15h PORTE(4,5) RE3/
CAP4 RE2/WR RE1/OE RE0/ALE ---- xxxx ---- uuuu
16h PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimp lemented, read as '0', q = value depends on condition.
Shaded ce lls are unimplemented, r ead as '0'.
Note 1: The upper byte of the program counter is not di rectly access i ble. PCLATH is a holding register for PC<15:8> whose
conten ts are updated from, or transferred to, the upper byte of the program c ounter.
2: The TO and PD status bits in CPUSTA are not affected by a MCLR Reset.
3: Bank 8 and associated registers are only implemented on the PIC17C76X devices.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Micro controlle r mode, the operation of this port does not rely on these
registers.
6: On any devic e RESET, these pins are con figured as inputs.
2000 Microchip Technology Inc. DS30289B-page 49
PIC17C7XX
Bank 2
10h TMR1 Timer1s Register xxxx xxxx uuuu uuuu
11h TMR2 Timer2s Register xxxx xxxx uuuu uuuu
12h TMR3L Timer3s Register; Low Byte xxxx xxxx uuuu uuuu
13h TMR3H Timer3s Register; High Byt e xxxx xxxx uuuu uuuu
14h PR1 Timer1s Per iod Regis ter xxxx xxxx uuuu uuuu
15h PR2 Timer2s Per iod Regis ter xxxx xxxx uuuu uuuu
16h PR3L/CA1L Timer3s Period Re giste r - Low Byte/Cap tur e1 Regis ter ; Low Byte xxxx xxxx uuuu uuuu
17h PR3H/CA1H Timer3s Period Register - High Byt e/Cap ture1 Re giste r; High Byte xxxx xxxx uuuu uuuu
Bank 3
10h PW1DCL DC1 DC0 xx-- ---- uu-- ----
11h PW2DCL DC1 DC0 TM2PW2 xx0- ---- uu0- ----
12h PW1DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
13h PW2DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
14h CA2L Capture2 Low Byte xxxx xxxx uuuu uuuu
15h CA2H Capture2 High Byte xxxx xxxx uuuu uuuu
16h TCON1 CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS 0000 0000 0000 0000
17h TCON2 CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
Bank 4
10h PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
12h Unimplemented ---- ---- ---- ----
13h RCSTA2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h RCREG2 Serial Port Receive Register for USART2 xxxx xxxx uuuu uuuu
15h TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
16h TXREG2 Serial Port Transmit Register for USART2 xxxx xxxx uuuu uuuu
17h SPBRG2 Baud Rate Generator for USAR T2 0000 0000 0000 0000
Bank 5:
10h DDRF Data Direction Register for POR TF 1111 1111 1111 1111
11h PORTF(4) RF7/
AN11 RF6/
AN10 RF5/
AN9 RF4/
AN8 RF3/
AN7 RF2/
AN6 RF1/
AN5 RF0/
AN4 0000 0000 0000 0000
12h DDRG Data Direction Register for POR TG 1111 1111 1111 1111
13h PORTG(4) RG7/
TX2/CK2 RG6/
RX2/DT2 RG5/
PWM3 RG4/
CAP3 RG3/
AN0 RG2/
AN1 RG1/
AN2 RG0/
AN3 xxxx 0000 uuuu 0000
14h ADCON0 CHS3 CHS2 CHS1 CHS0 GO/DONE ADON 0000 -0-0 0000 -0-0
15h ADCON1 ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0 000- 0000 000- 0000
16h ADRESL A/D Result Register Low By te xxxx xxxx uuuu uuuu
17h ADRESH A/D Result Register High Byte xxxx xxxx uuuu uuuu
TABLE 7-3: SPECIAL FUNCTION REGISTERS (CONTINUED)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
Legend: x = unknown, u = unchanged, - = unimp lemented, read as '0', q = value depends on condition.
Shaded ce lls are unimplemented, r ead as '0'.
Note 1: The upper byte of the program counter is not direc tly accessible. PCLATH is a holding register for PC<15:8> whose
conten ts are up dated from, or transferred to, the upper byte of the program c ounter.
2: The TO and PD status bits in CPUSTA are not affected by a MCLR Reset.
3: Bank 8 and associated registers are only implemented on the PIC17C76X devices.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Microcontroller mode, the operation of this port does not rely on these
registers.
6: On any devic e RESET, these pins are con figured as inputs.
PIC17C7XX
DS30289B-page 50 2000 Microchip Technology Inc.
Bank 6
10h SSPADD SSP Address Regi ster in I2C Sl ave mode. SSP Baud Ra te Reloa d Re gister in I2C Maste r mode 0000 0000 0000 0000
11h SSPCON1 WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0 0000 0000 0000 0000
12h SSPCON2 GCEN AKSTAT AKDT AKEN RCEN PEN RSEN SEN 0000 0000 0000 0000
13h SSPSTAT SMP CKE D/A PSR/WUA BF 0000 0000 0000 0000
14h SSPBUF Synchrono us Serial Port Receive Buff er/ Transmit Register xxxx xxxx uuuu uuuu
15h Unimplemented ---- ---- ---- ----
16h Unimplemented ---- ---- ---- ----
17h Unimplemented ---- ---- ---- ----
Bank 7
10h PW3DCL DC1 DC0 TM2PW3 xx0- ---- uu0- ----
11h PW3DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
12h CA3L Capture3 Low Byte xxxx xxxx uuuu uuuu
13h CA3H Capture3 High Byte xxxx xxxx uuuu uuuu
14h CA4L Capture4 Low Byte xxxx xxxx uuuu uuuu
15h CA4H Capture4 High Byte xxxx xxxx uuuu uuuu
16h TCON3 CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
17h Unimplemented ---- ---- ---- ----
Bank 8(3)
10h(3) DDRH Data Direc tion Regis ter for PO R TH 1111 1111 1111 1111
11h(3) PORTH(4) RH7/
AN15 RH6/
AN14 RH5/
AN13 RH4/
AN12 RH3 RH2 RH1 RH0 xxxx xxxx uuuu uuuu
12h(3) DDRJ Data Direction Registe r for POR TJ 1111 1111 1111 1111
13h(3) PORTJ(4) RJ7 RJ6 RJ5 RJ4 RJ3 RJ2 RJ1 RJ0 xxxx xxxx uuuu uuuu
14h(3) Unimplemented ---- ---- ---- ----
15h(3) Unimplemented ---- ---- ---- ----
16h(3) Unimplemented ---- ---- ---- ----
17h(3) Unimplemented ---- ---- ---- ----
Unbanked
18h PRODL Low Byte of 16-bit Product (8 x 8 Hardware Mult iply) xxxx xxxx uuuu uuuu
19h PRODH High Byte of 16-bit Product (8 x 8 Hardware Multiply) xxxx xxxx uuuu uuuu
TABLE 7-3: SPECIAL FUNCTION REGISTERS (CONTINUED)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
Legend: x = unknown, u = unchanged, - = unimp lemented, read as '0', q = value depends on condition.
Shaded ce lls are unimplemented, r ead as '0'.
Note 1: The upper byte of the program counter is not di rectly access i ble. PCLATH is a holding register for PC<15:8> whose
conten ts are updated from, or transferred to, the upper byte of the program c ounter.
2: The TO and PD status bits in CPUSTA are not affected by a MCLR Reset.
3: Bank 8 and associated registers are only implemented on the PIC17C76X devices.
4: This is the value that will be in the port output latch.
5: When the device is configured for Microprocessor or Extended Micro controlle r mode, the operation of this port does not rely on these
registers.
6: On any devic e RESET, these pins are con figured as inputs.
2000 Microchip Technology Inc. DS30289B-page 51
PIC17C7XX
7.2.2.1 ALU Status Register (ALUSTA)
The ALUSTA register contains the status bits of the
Arithmetic and Logic Unit and the mode control bits for
the indirect addressing register.
As with all the other re gisters, t he ALUSTA register ca n
be the destination for any instruction. If the ALUSTA
register is the destination for an instruction that affects
the Z, DC, C, or OV bits, then the write to these three
bits is disabled. These bits are set or cleared according
to th e dev ice lo gic. Theref ore, the r esult of an i nstr uc-
tion with the ALUSTA register as destination may be
different than intended.
For example, the CLRF ALUSTA, F instruction will clear
the upper four bits and set the Z bit. This leaves the
ALUST A register as 0000u1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF, SWAPF
and MOVWF instructions be used to alter the ALUSTA
register, because these instructions do not affect any
status bits. To see how other instructions affect the sta-
tus bit s, see the Instruction Set Summary.
The A ri th me tic a nd Log i c Un it (A L U) i s c apabl e o f ca r-
rying out arithm etic or logical operations on two oper-
ands, or a single operand. All single operand
instructions operate either on the WREG register, or
the given file register . For two operand instructio ns, one
of the operands is the WREG register and the other is
either a file register, or an 8-bit immediate constant.
REGISTER 7-1: ALUSTA REGISTER (ADDRESS: 04h, UNBANKED)
Note 1: The C and DC bits opera te as a borr ow and
digit borrow bit, respectively, in subtracti on.
See the SUBLW and SUBWF instructions for
examples.
2: The overflow bit will be set if the 2s c omple-
ment result exceeds +127, or is less than -128.
R/W-1 R/W-1 R/W-1 R/W-1 R/W-x R/W-x R/W-x R/W-x
FS3 FS2 FS1 FS0 OV Z DC C
bit 7 bit 0
bit 7-6 FS3:FS2: FSR1 Mode Select bits
00 = Post auto-decrement FSR1 value
01 = Post auto-increment FSR1 value
1x = FSR1 value does not change
bit 5-4 FS1:FS0: FSR0 Mode Select bits
00 = Post auto-decrement FSR0 value
01 = Post auto-increment FSR0 value
1x = FSR0 value does not change
bit 3 OV: Overflow bit
This bit is used for signed arithmetic (2s complement). It indicates an overflow of the 7-bit
magnitude, which causes the sign bit (bit7) to change state.
1 = Overflow occurred f or signed arithmetic (in this ar ithmetic operation)
0 = No overflow occurred
bit 2 Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit 1 DC: Digit carry/borrow bit
For ADDWF and ADDLW instructions.
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
Note: For borrow, the polarity is reversed.
bit 0 C: Carry/borrow bit
For ADDWF and ADDLW instructions. Note that a subtraction is executed by adding the twos
complement of the second operand.
For rotate (RRCF, RLCF) instructions, this bit is loaded with either the high or low order bit of the
source register.
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
Note: For borrow, the polarity is reversed.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 52 2000 Microchip Technology Inc.
7.2.2.2 CPU Status Register (CPUSTA)
The CPUSTA register contains the status and control
bits for the CPU. This register has a bit that is used to
globally enable/disable interrupts. If only a specific
inter rupt is desire d to be enabled/d isabled, ple ase refer
to the Interrupt Status (INTSTA) register and the
Peripheral Interrupt Enable (PIE) registers. The
CPUSTA register als o indi cates if the st ack is avail able
and contains the Power-down (PD) and Time-out (TO)
bits. The TO, PD, and STKAV bits are not writable.
These bits are set and cleared according to device
logic. Therefore, the result of an instruction with the
CPUSTA register as destination may be different than
intended.
The POR bit allows the differentiation between a
Power-on Reset, external MCLR Reset, or a WDT
Reset. The BOR bit indicates if a Brown-out Reset
occurred.
REGISTER 7-2: CPUSTA REGISTER (ADDRESS: 06h, UNBANKED)
Note 1: The BOR status bit is a dont care and is
not necessarily predictable if the Brown-out
circuit is disabled (when the BODEN bit in
the Configuration word is programmed).
U-0 U-0 R-1 R/W-1 R-1 R-1 R/W-0 R/W-1
STKAV GLINTD TO PD POR BOR
bit 7 bit 0
bit 7-6 Unimplemented: Read as '0'
bit 5 STKAV: Stack Available bit
This bit indicates that the 4-bit stack pointer value is Fh, or has rolled over from Fh 0h
(stack overflow).
1 =Stack is available
0 =Stack is full, or a stack overflow may have occurred (once this bit has been cleared by a
stack overflow, only a device RESET will set this bit)
bit 4 GLINTD: Global Interrupt Disable bit
This bit disables all interrupts. When enabling interrupts, only the sources with their enable bits
set can cause an interru pt.
1 = Disable all interrupts
0 = Enables all unmasked interrupts
bit 3 TO: WDT Time-out Status bit
1 = After power-up, by a CLRWDT instruction, or by a SLEEP instruction
0 = A Watchdog Timer time-out occurred
bit 2 PD: Power-down Status bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
bit 1 POR: Power-on Reset Status bit
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set by software)
bit 0 BOR: Brown-out Reset Status bit
When BODEN Configuration bit is set (enabled):
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred (must be set by software)
When BODEN Configuration bit is clear (disabled):
Dont care
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 53
PIC17C7XX
7.2.2.3 TMR0 Status/Control Register
(T0STA)
This register contains various control bits. Bit7
(INTEDG) is used to control the ed ge upon which a si g-
nal on the RA0/INT pin will set the RA0/INT interrupt
flag. The other bit s co nfigure Timer0, its prescaler an d
clock source.
REGISTER 7-3: T0STA REGISTER (ADDRESS: 05h, UNBANKED)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0
INTEDG T0SE T0CS T0PS3 T0PS2 T0PS1 T0PS0
bit 7 bit 0
bit 7 INTEDG: RA0/INT Pin Interrupt Edge Select bit
This bit selects the edge upon which the interrupt is detected.
1 = Rising edge of RA0/INT pin generates interrupt
0 = Falling edge of RA0/INT pin generates interrupt
bit 6 T0SE: Timer0 External Clock Input Edge Select bit
This bit selects the edge upon which TMR0 will increment.
When T0CS = 0 (External Clock):
1 = Rising edge of RA1/T0CKI pin increments TMR0 and/or sets the T0CKIF bit
0 = Falling edge of RA1/T0CKI pin increments TMR0 and/or sets a T0CKIF bit
When T0CS = 1 (Internal Clock):
Dont care
bit 5 T0CS: Timer0 Clock Source Select bit
This bit selects the clock source for Timer0.
1 = Internal instruction clock cycle (TCY)
0 = External clock input on the T0CKI pin
bit 4-1 T0PS3:T0PS0: Timer0 Prescale Selection bits
These bits select the prescale value for Timer0.
bit 0 Unimplemented: Read as 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
T0PS3:T0PS0 Prescale Value
0000
0001
0010
0011
0100
0101
0110
0111
1xxx
1:1
1:2
1:4
1:8
1:16
1:32
1:64
1:128
1:256
PIC17C7XX
DS30289B-page 54 2000 Microchip Technology Inc.
7.3 S tack Operation
PIC17C7XX d evices have a 1 6 x 16-bit ha rdware st ack
(Figure 7-1). The stack is not part of either the program
or data memory space, and the stack pointer is neither
readable nor writable. The PC (Program Counter) is
PUSHd onto the stack when a CALL or LCALL
instruction is executed, or an interrupt is acknowl-
edged. The stack is POPd in the event of a RETURN,
RETLW, or a RETFIE inst ruc ti o n e x ec ut i on. P CLATH is
not affected by a PUSH or a POP operation.
The stack operates as a circular buffer, with the stack
pointer initialized to '0' after all RESETS. There is a
stac k av ai lab le bi t (STKAV) to all ow s oftware to ensu re
that the stack will not overflow. The STKAV bit is set
after a device RESET. When the stack pointer equals
Fh, STKAV is cleared. When the stack pointer rolls over
from Fh to 0h, the STKAV bit will be held clear until a
device RESET.
After the device is PUSHd sixteen times (without a
POP), the seventeenth push overwrites the value
from the firs t push. The eigh teenth pu sh overwri tes the
second push (and so on).
7.4 Indirect Addressing
Indirect addressing is a mode of add ressing dat a mem-
ory where the data memory address in the instruction
is not fixed. That is, the register that is to be read or
written can be modified by the program. This can be
useful for data tables in the data memory. Figure 7-6
shows the operation of indirect addressing. This
depicts the moving of the value to the data memory
address spec ifi ed by the value of the FSR regis ter.
Example 7-1 shows the use of indirect addressing to
clear RA M in a min imum numbe r of instru ctions. A s im-
ilar concept could be used to move a defined number
of bytes (block) of data to the USART transmit register
(TXREG). The starting address of the block of data to
be transmitted could ea sily be modified by the program.
FIGURE 7-6: INDIRECT ADDRESSING
7.4.1 INDIRECT ADDRESSING
REGISTERS
The PIC17C7XX ha s four registers for ind irect address-
ing. These regi ste r s are:
INDF0 and FSR0
INDF1 and FSR1
Registers INDF0 and INDF1 are not physically imple-
mented. Read ing or wr i tin g to the se regi st ers ac tiv ate s
indirec t addressing , with the va lue in the co rresponding
FSR regist er being the add ress of the da ta. The FSR is
an 8-bit re gister and al lows addre ssing anywhere i n the
256-byte data memory address range. For banked
memory, the bank of memory accessed is specified by
the value in the BSR.
If file INDF0 (or INDF1) itself is read indirectly via an
FSR, all '0's are read (Zero bit is set ). Similarly , if INDF0
(or INDF1) is written to indirectly, the operation will be
equival ent to a NOP, an d the stat us bits are not affec ted.
Note 1: There is not a status bit for stack under-
flow. The STKAV bit can be used to detect
the underflow which results in the stack
pointer being at the Top-of-Stack.
2: There are no instruction mnemonics
called PUSH or POP. These are actions
that occur from the execution of the CALL,
RETURN, RETLW and RETFIE instruc-
tions, or the vectoring to an interrupt
vector.
3: After a RESET, if a POP operation
occurs before a PUSH operation, the
STKAV bit will be cleared. This will
appear as if the stack is full (underflow
has occurred). If a PUSH operation
occurs next (before another POP), the
STKAV bit will be locked clear. Only a
device RESET will cause this bit to set.
Opcode Address
File = INDFx
FSR
Instruction
Executed
Instruction
Fetched
RAM
Opcode File
8
8
8
2000 Microchip Technology Inc. DS30289B-page 55
PIC17C7XX
7.4.2 INDIRECT ADDRESSING
OPERATION
The indirect addressing capability has been enhanced
over that of the PIC16CXX family . There are two control
bits associated with each FSR register. These two bits
configure the FSR register to:
Auto-decrement the value (address) in the FSR
after an indirect access
Auto-increment the va lue (addres s) in the FSR
after an indirect access
No chan ge to the value (addr ess) in the FSR afte r
an indirect access
These control bits are located in the ALUSTA register.
The FSR1 register is controlled by the FS3:FS2 bits
and FSR0 is controlled by the FS1:FS0 bits.
When us ing the auto-in crement or aut o-decrement fe a-
tures, the effect on the FSR is not reflected in the
ALUSTA register. For example, if the indirect address
causes the FSR to equal '0', the Z bit will not be set.
If the FSR register contains a value of 0h, an indirect
read will rea d 0h (Zero bit is set) while an in dire ct write
will b e equivalent to a NOP (status bit s are not af fected).
Indirect addressing allows single cycle data transfers
within the entire data space. This is possible with the
use of the MOVPF a nd MOVFP instructions, where either
'p' or 'f' is specified as INDF0 (or INDF1).
If the source or destination of the indirect address is in
banked memory, the location accessed will be deter-
mined by the value in t he BSR .
A simple program to clear RAM from 20h - FFh is
shown in Example 7-1.
EXAMPLE 7-1: INDIRECT ADDRESSING
7.5 Table Pointer (TBLPTRL and
TBLPTRH)
File registers TBLPTRL and TBLPTRH form a 16-bit
pointer to address the 64K program memory space.
The table pointer is used by instructions TABLWT and
TABLRD.
The TABLRD and the TABLWT instructions allow trans-
fer of dat a between program and dat a spa ce. The t able
pointer serves as the 16-bit address of the data word
within the program memory. For a more complete
description of these registers and the operation of
Table Reads and Table Writes, see Section 8.0.
7.6 Table Latch (TBLATH, TBLATL)
The table latch (TBLAT) is a 16-bit register, with
TBLATH and TBLATL referring to the high and low
bytes of the register. It is not mapped into data or pro-
gram memory. The table latch is used as a temporary
holding latch during data transfer between program
and data memory (see TABLRD, TABLWT, TLRD and
TLWT instruction descriptions). For a more complete
description of these registers and the operation of
Table Reads and Table Writes, see Section 8.0.
MOVLW 0x20 ;
MOVWF FSR0 ; FSR0 = 20h
BCF ALUSTA, FS1 ; Increment FSR
BSF ALUSTA, FS0 ; after access
BCF ALUSTA, C ; C = 0
MOVLW END_RAM + 1 ;
LP CLRF INDF0, F ; Addr(FSR) = 0
CPFSEQ FSR0 ; FSR0 = END_RAM+1?
GOTO LP ; NO, clear next
: ; YES, All RAM is
: ; cleared
PIC17C7XX
DS30289B-page 56 2000 Microchip Technology Inc.
7.7 Program Counter Module
The Program Counter (PC) is a 16-bit register . PCL, the
low byte of the PC, is mapped in the data memory . PCL
is readable and writable just as is any other register.
PCH is the high byte of the PC and is not directly
addressable. Since PCH is not mapped in data or pro-
gram memory, an 8-bit register PCLATH (PC high
latch) i s u sed as a h old in g la tch for the high by te of th e
PC. PCLATH is mapped into data memory. The user
can read or write PCH through PCLATH.
The 16-bit wide PC is incremented after each instruc-
tion fetch duri ng Q1 unles s:
Modified by a GOTO, CALL, LCALL, RETURN,
RETLW, or RETFIE instruction
Modified by an interrupt response
Due to destination write to PCL by an instruction
Skips are equivalent to a forced NOP cycle at the
skipped address.
Figure 7-7 and Figure 7-8 show the operation of the
program counter for various situations.
FIGURE 7-7: PROGRAM COUNTER
OPERATION
FIGURE 7-8: PROGRAM COUNTER
USING THE CALL AND
GOTO INSTRUCTIONS
Using Figure 7-7, the operations of the PC and
PCLATH for diffe rent instructions are as foll ows:
a) LCALL instructions:
An 8-bit destination address is provided in the
instruction (opcode). PCLATH is unchanged.
PCLATH PCH
Opcode<7:0> PCL
b) Read instructions on PCL:
Any instruction that reads PCL.
PCL data bus ALU or destination
PCH PCLATH
c) Write instructions on PCL:
Any instruction that writes to PCL.
8-bit data data bus PCL
PCLATH PCH
d) Read-Modify-Write instructions on PCL:
Any instruction that does a read-write-modify
operation on PCL, such as ADDWF PCL.
Read: PCL data bus ALU
Write: 8-bi t result data bus PCL
PCLATH PCH
e) RETURN instruction:
Stack<MRU> PC<15:0>
Using Fig ure 7-8, the opera tion of t he PC and PCLATH
for GOTO and CALL instructions is as follows:
CALL, GOTO instructions:
A 13-bit destination address is provided in the
ins truction (opcod e).
Opcode<12:0> PC<12:0>
PC<15:13> PCLATH<7:5>
Opcode<12:8> PCLATH<4:0>
The read-modify-write only affects the PCL with the
result. P CH is loaded with the value in the PCLA TH. For
example, ADDWF PCL will result in a jump within the
current page. If PC = 03F0h, WREG = 30h and
PCLATH = 03h be fore instru ction, PC = 0320h after th e
instruction. To accomplish a true 16-bit computed jump,
the user needs to compute the 16-bit destination
address, write the high byte to PCLATH and then write
the low value to PCL.
The following PC related operations do not change
PCLATH:
a) LCALL, RETLW, and RETFIE instructions .
b) Interrupt vector is forced onto the PC.
c) Read-modify-write instructions on PCL
(e.g. BSF PCL).
Inte r nal Da ta B u s <8>
PCLATH 8
8
8
PCH PCL
8
15 0
7540
12 8 7 0
87
PC<15:13>
PCLATH
From Instruction
5
3
8
PCH PCL
1315
2000 Microchip Technology Inc. DS30289B-page 57
PIC17C7XX
7.8 Bank Select Register (BSR)
The BSR is used to switch between banks in the data
memory area (Fi gure 7-9). In the PIC17C7XX devi ces ,
the entire byte is implemented. The lower nibble is
used to select the peripheral register bank. The upper
nibble is used to select the general purpose memory
bank.
All the Special Function Registers (SFRs) are mapped
into the data memory space. In order to accommodate
the large number of registers, a banking scheme has
been used. A segment of the SFRs, from address 10h
to addres s 17h, is bank ed. The low er nibble of t he bank
select register (BSR) selects the currently active
peripheral bank. Effort has been made to group the
periphera l registers of related fu nctional ity in one bank .
Howeve r , it wil l still be ne cessary to sw itch from ba nk to
bank in order to address a ll periph erals rel ated to a sin-
gle task. To assist this, a MOVLB bank instruct ion has
been included in the instruction set.
The need for a large general purpose memory space
dictated a general purpose RAM b ank in g sc hem e. Th e
upper nibble of the BSR selects the currently active
general purpose RAM bank. To assist this, a MOVLR
bank instruction has been provided in the instruction
set.
If the currentl y select ed bank is no t implemen ted (suc h
as Bank 13), any read will read all '0's. Any write is
comple ted to th e b it bucket and th e ALU status bi ts wil l
be set/cleared as appropriate.
FIGURE 7-9: BSR OPERATION
Note: Registers in Bank 15 in the Special Func-
tion Register area, are reserved for
Microchip use. Reading of registers in this
bank may caus e random valu es to be read.
7430
10h
17h
BSR
0 123 8 15
• • •
20h
FFh • • •
(1)
(2)
Bank 15Bank 8
Bank 3Bank 2Bank 1Bank 0
012
Bank 2Bank 1Bank 0
15
Bank 15
SFR
Banks
GPR
Banks
Address
Range
Note 1: For the SFRs only Banks 0 through 8 are implemented. Selection of an unimplemented bank is not recommended.
Bank 15 is reserved for Microchip use, reading of registers in this bank may cause random values to be read.
2: For the GPRs, Bank 3 is unimplemented on the PIC17C752 and the PIC17C762. Selection of an unimplemented bank
is not recommended.
3: SFR Bank 8 is only implemented on the PIC17C76X.
3
Bank 3
4
Bank 4
4 56 7
Bank 7Bank 6B ank 5Bank 4
(Peripheral)
(RAM)
PIC17C7XX
DS30289B-page 58 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 59
PIC17C7XX
8.0 TABLE READS AND TABLE
WRITES
The PIC17C7XX has four instructions that allow the
process or to move dat a from the data mem ory space to
the program memory space, and vice versa. Since the
program memory space is 16-bits wide and the data
memory space is 8-bits wide, two operations are
required to move 16-bit values to/from the data
memory.
The TLWT t,f and TABLWT t,i,f instructions are
used to write data from the data memory space to the
program memory space. The TLRD t,f and TABLRD
t,i,f instructio ns are us ed to wri te dat a from the pro-
gram memory space to the data memory space.
The program memory can be internal or external. For
the pr ogra m mem ory ac ce ss to b e ex tern al , the dev ic e
needs to be operating in Microprocessor or Extended
Microcontroller mode.
Figure 8-1 through Figure 8-4 show the operation of
these four instructions. The steps show the sequence
of operation.
FIGURE 8-1: TLWT INSTRUCTION
OPERATION
FIGURE 8-2: TABLWT INSTRUCTION
OPERATION
TABLE POINTER
TABLE LATCH (16-bit)
Program Memory
Data
Memory
TBLPTRH TBLPTRL
TABLATH TABLATL
f
TLWT 1,f TLWT 0,f
1
Step 1: 8-bit value from register f, loaded into the high or low
byte in TABLAT (16-bit).
TABLE POINTER
TABLE LATCH (16-bit)
Program Memory
Data
Memory
TBLPTRH TBLPTRL
TABLATH TABLATL
f
TABLWT 1,i,f TABLWT 0,i,f
1
Prog-Mem
(TBLPTR)
2
Step 1: 8-bit value from register f, loaded into the high or low
byte in TABLAT (16-bit).
2: 16-bit T ABLAT value written to address Program Memory
(TBLPTR).
3: If i = 1, then TBLPTR = TBLPTR + 1,
If i = 0, then TBLPTR is unchanged.
33
PIC17C7XX
DS30289B-page 60 2000 Microchip Technology Inc.
FIGURE 8-3: TLRD INSTRUCTION
OPERATION FIGURE 8-4: TABLRD INSTRUCTION
OPERATION
TABLE POINTER
TABLE LATCH (16-bit)
Program Memory
Data
Memory
TBLPTRH TBLPTRL
TABLATH TABLATL
f
TLRD 1,f TLRD 0,f
1
Step 1: 8-bit value from TABLAT (16-bit) high or low byte,
loaded into register f.
TABLE POINTER
TABLE LATCH (16-bit)
Program Memory
Data
Memory
TBLPTRH TBLPTRL
TABLATH TABLATL
f
TABLRD 1,i,f TABLRD 0,i,f
1
Prog-Mem
(TBLPTR)
2
Step 1: 8-bit value from TABLAT (16-bit) high or low byte,
loaded into register f.
2: 16-bit value at Program Memory (TBLPTR), loaded into
TABLAT register.
3: If i = 1, then TBLPTR = TBLPTR + 1,
If i = 0, then TBLPTR is unchanged.
3
3
2000 Microchip Technology Inc. DS30289B-page 61
PIC17C7XX
8.1 Table Writes to In ternal Memory
A table write operation to internal memory causes a
long write operation. The long write is necessary for
programming the internal EPROM. Instruction execu-
tion is halted while in a long write cycle. The long write
will be terminated by any enabled interrupt. To ensure
that the EPROM location has been well programmed,
a minimum programming time is required (see specifi-
cation #D1 14). Having o nly one i nterrupt enabled to t er-
minate the long write ensures that no unintentional
interrupts will prematurely terminate the long write.
The sequence of events for programming an internal
program memory location should be:
1. Disa ble all i nter rupt so urces, except the s ource
to terminate EPROM program write.
2. Raise MCLR/VPP pin to the programming
voltage.
3. Clear the WDT.
4. Do the table write. The interrupt will terminate
the long write.
5. Verify the memory location (table read).
8.1.1 TERMINATIN G LONG WR ITES
An interrupt source or RESET are the only events that
terminate a long write operation. Terminating the long
write fro m an interrupt source requires that the interru pt
enable and flag bits are set. The GLINTD bit only
enables the vectoring to the interrupt address.
If the T0CKI, RA0/INT, or TMR0 interrupt source is
used to term inate the long write, th e interrupt flag of th e
highest priority enabled interrupt, will terminate the long
write and automatically be cleared.
If a peripheral interrupt source is used to terminate the
long write, the interrupt enable and flag bits must be
set. The interrupt flag will not be automatically cleared
upon the vectoring to the interrupt vector address.
The GLINTD bit determines whether the program will
branch to the interrupt v ector when the long write is t er-
minated. If GLINTD is clear, the program will vector, if
GLINTD is set, the program will not vector to the
interrupt add res s.
TABLE 8-1: INTERRUPT - TABLE WRITE INTERACTION
Note 1: Programming requirements must be
met. See timing specifica tion in electrical
specifications for the desired device.
Violating these specifications (including
temperature) may result in EPROM
locations that are not fully programmed
and may lose their state over time.
2: If the VPP requirement is not met, the
ta ble write is a 2- cycle writ e and the pro-
gram memory is unchanged.
Note 1: If an interru pt is pen di ng, th e TABLWT is
aborted (a NOP is exec uted). The highest
priority pending interrupt, from the
T0CKI, RA0/INT, or TMR0 sources that
is enabled, has its flag cleared.
2: If the interrupt is not being used for the
program write timing, the interrupt
should be dis abled. This will ensure that
the interrupt is not lost, nor will it termi-
nate the long wri te prem aturely.
Interrupt
Source GLINTD Enable
Bit Flag
Bit Action
RA0/INT,
TMR0,
T0CKI
0
0
1
1
1
1
0
1
1
0
x
1
Terminate long t ab le wr i te (to inte rna l pro gram mem ory),
branch to interrupt vector (branch clears flag bit).
None.
None.
Terminate long table write, do not branch to interrupt
vector (flag is automatically cleared).
Peripheral 0
0
1
1
1
1
0
1
1
0
x
1
Terminate long table write, branch to interrupt vector.
None.
None.
Terminate long table write, do not branch to interrupt
vector (flag rema ins set).
PIC17C7XX
DS30289B-page 62 2000 Microchip Technology Inc.
8.2 Table Writes to External Memory
Tab le writ es to ex ternal m emory a re alwa ys two-c ycle
instructions. The second cycle writes the data to the
external memory location. The sequence of events for
an external memory write are the same for an internal
write.
8.2.1 TABLE WRITE CODE
The i operand of the TABLWT instruction can specify
that the value in the 1 6-bit TBLP TR re gister i s automat-
ically incremented (for the next write). In Example 8-1,
the TBLPTR register is not automatically incremented.
EXAMPLE 8-1: TABLE WRITE
FIGURE 8-5: TABLWT WRITE TIMING (EXTERNAL MEMORY)
CLRWDT ; Clear WDT
MOVLW HIGH (TBL_ADDR) ; Load the Table
MOVWF TBLPTRH ; address
MOVLW LOW (TBL_ADDR) ;
MOVWF TBLPTRL ;
MOVLW HIGH (DATA) ; Load HI byte
TLWT 1, WREG ; in TABLATH
MOVLW LOW (DATA) ; Load LO byte
TABLWT 0,0,WREG ; in TABLATL
; and write to
; program memory
; (Ext. SRAM)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
Instruction
Fetched
Instruction
Executed
ALE
OE
WR
TABLWT INST (PC+1)
INST (PC-1) TABLWT cy cle1 TABLWT cycle2
INST (PC+2)
Data write cycle
1
PC PC+1 TBL PC+2Data out
INST (PC+1)
Note: If external write and GLINTD = 1 and Enable bit = 1, then when 1 Flag bit, do table write.
The highest pending interrupt is cleared.
OE
2000 Microchip Technology Inc. DS30289B-page 63
PIC17C7XX
FIGURE 8-6: CONSECUTIVE TABLWT WRITE TIMING (EXTERNAL MEMORY)
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
Instruction
Fetched
Instruction
Executed
ALE
OE
WR
PC
TABLWT1 TABLWT2 INST (PC+2)
INST (PC-1) TABLWT1 cycle1 TABLWT1 cycle2 TABLWT2 cycle1 TABLWT 2 cyc le2
Data write cycle Data write cycle
INST (PC+3)
PC+1 TBL1 PC+2 TBL2 PC+3
Data out 1 Data out 2
INST (PC+2)
PIC17C7XX
DS30289B-page 64 2000 Microchip Technology Inc.
8.3 Table Reads
The table read allo w s th e pro gram memory to be rea d.
This allows constant s to be stored in the program mem-
ory space and retrieved into data memory when
needed. Example 8-2 reads the 16-bit value at program
memory address TBLPTR. After the dummy byte has
been read from the TABLATH, the TABLATH is loaded
with the 16-bit data from program memory address
TBLPTR and then increments the TBLPTR value. The
first read loads the data into the latch and can be con-
sidered a dummy read (unknown data loaded into f).
INDF0 should be configured for either auto-increment
or auto-decrement.
EXAMPLE 8-2: TABLE READ
FIGURE 8-7: TABLRD TIMING
FIGURE 8-8: TABLRD TIMING (CONSECUTIVE TABLRD INSTRUCTIONS)
MOVLW HIGH (TBL_ADDR) ; Load the Table
MOVWF TBLPTRH ; address
MOVLW LOW (TBL_ADDR) ;
MOVWF TBLPTRL ;
TABLRD 0, 1, DUMMY ; Dummy read,
; Updates TABLATH
; Increments TBLPTR
TLRD 1, INDF0 ; Read HI byte
; of TABLATH
TABLRD 0, 1, INDF0 ; Read LO byte
; of TABLATL and
; Update TABLATH
; Increment TBLPTR
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
Instruction
Fetched
Instruction
Executed
ALE
OE
WR
TABLRD INST (PC+ 1) INST (PC+2)
INST (PC-1) TABLRD cycle1 TABLRD cycle2 INST (PC+1)
Data read cycle
PC PC+1 TBL Data in PC+2
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
AD15:AD0
Instruction
Fetched
Instruction
Executed
TABLRD1 TABLRD2 INST (PC+2) INST (PC+3)
INST (PC+2)
ALE
OE
WR
INST (PC-1) TABLRD1 cycle1 TABLRD1 cycle2 TABLRD2 cycle1 TABLRD2 cyc le2
Data read cycle Data read cycle
1
PC PC+1 PC+2 PC+3
TBL1 D ata in 1 TB L2 Data in 2
2000 Microchip Technology Inc. DS30289B-page 65
PIC17C7XX
8.4 Operation with Exter nal Memory
Interface
When the table reads/writes are accessing external
memory (via the external system interface bus), the
tabl e latch for the t abl e rea ds is d if f eren t from the t abl e
latch for the table writes (see Figure 8-9).
This means that you cannot do a TABLRD instruction,
and use the values that were loaded into the table
latches for a TABLWT instruction. Any table write
sequence should use both the TLWT and then the
TABLWT instructions.
FIGURE 8-9: ACCESSING EXTERNAL MEMORY WITH TABLRD AND TABLWT INSTRUCTIONS
TABLPTR
TABLATH (for Table Reads)
TABLATH (for Table Wr ites )
Progra m Me mor y
TABLRD
TABLWT
(In External Memory Space)
PIC17C7XX
DS30289B-page 66 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 67
PIC17C7XX
9.0 HARDWARE MULTIPLIER
All PI C17 C7 XX de vice s ha ve an 8 x 8 ha rd ware mu lti -
plier included in the ALU of the device. By making the
multiply a hardware operation, it completes in a single
instruc tion cycle. This is an unsigned multip ly that gives
a 16-bit result. The result is stored into the 16-bit
Product register (PRODH:PRODL). The multiplier does
not affect any flags in the ALUSTA register.
Making the 8 x 8 multiplier execute in a single cycle
gives the fol low i ng adv antages:
Higher computational throughput
Reduc es c od e si ze requirements for mu ltiply alg o-
rithms
The performance increase allows the device to be used
in applications previously reserved for Digital Signal
Processors.
Table 9-1 shows a performance comparison between
PIC17CXXX devices using the single cycle hardware
multiply and performing the same function without the
hardware multiply.
Example 9-1 shows the sequence to do an 8 x 8
unsigned multiply. Only one instruction is required
when one arg um ent of the multiply is al rea dy lo ade d in
the WREG register.
Example 9-2 shows the sequence t o do an 8 x 8 signed
multiply. To account for the sign bits of the arguments,
each arguments most significant bit (MSb) is tested
and the appropriate subtractions are done.
EXAMPLE 9- 1: 8 x 8 UNSIGNED
MULTIPLY ROUTINE
EXAMPLE 9-2: 8 x 8 SIGNED MULTIPLY
ROUTINE
TABLE 9-1: PERFORMANCE COMPARISON
MOVFP ARG1, WREG ;
MULWF ARG2 ; ARG1 * ARG2 ->
; PRODH:PRODL
MOVFP ARG1, WREG
MULWF ARG2 ; ARG1 * ARG2 ->
; PRODH:PRODL
BTFSC ARG2, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH
; - ARG1
MOVFP ARG2, WREG
BTFSC ARG1, SB ; Test Sign Bit
SUBWF PRODH, F ; PRODH = PRODH
; - ARG2
Routine Mult iply Me thod Program
Memory
(Words)
Cycles
(Max)
Time
@ 33 MHz @ 16 MHz @ 8 MHz
8 x 8 unsigned Without hardware multiply 13 69 8.364 µs17.25 µs 34.50 µs
Hardware multiply 1 1 0.121 µs0.25 µs0.50 µs
8 x 8 si gned Without hardwar e multiply ———
Hardware multiply 6 6 0.727 µs1.50 µs3.0 µs
16 x 16 unsigned Without hardware multiply 21 242 29.333 µs60.50 µs 121.0 µs
Hardware multiply 24 24 2.91 µs6.0 µs 12.0 µs
16 x 16 signed Without hardware multiply 52 254 30.788 µs63.50 µs 127.0 µs
Hardware multiply 36 36 4.36 µs9.0 µs 18.0 µs
PIC17C7XX
DS30289B-page 68 2000 Microchip Technology Inc.
Example 9-3 shows the sequence to do a 16 x 16
unsigned multiply. Equation 9-1 shows the algorithm
that is used. The 32-bit result is stored in 4 registers,
RES3:RES0.
EQUATION 9-1: 16 x 16 UNSIGNED
MULTIPLICATION
ALGORITHM
EXAMPLE 9-3: 16 x 16 UNSIGNED
MU LTIPLY ROUTINE
RES3:RES0 = ARG1H:ARG1L ARG2H:ARG2L
= (ARG1H ARG2H 216)+
(ARG1H ARG2L 28)+
(ARG1L ARG2H 28)+
(ARG1L ARG2L)
MOVFP ARG1L, WREG
MULWF ARG2L ; ARG1L * ARG2L ->
; PRODH:PRODL
MOVPF PRODH, RES1 ;
MOVPF PRODL, RES0 ;
;
MOVFP ARG1H, WREG
MULWF ARG2H ; ARG1H * ARG2H ->
; PRODH:PRODL
MOVPF PRODH, RES3 ;
MOVPF PRODL, RES2 ;
;
MOVFP ARG1L, WREG
MULWF ARG2H ; ARG1L * ARG2H ->
; PRODH:PRODL
MOVFP PRODL, WREG ;
ADDWF RES1, F ; Add cross
MOVFP PRODH, WREG ; products
ADDWFC RES2, F ;
CLRF WREG, F ;
ADDWFC RES3, F ;
;
MOVFP ARG1H, WREG ;
MULWF ARG2L ; ARG1H * ARG2L ->
; PRODH:PRODL
MOVFP PRODL, WREG ;
ADDWF RES1, F ; Add cross
MOVFP PRODH, WREG ; products
ADDWFC RES2, F ;
CLRF WREG, F ;
ADDWFC RES3, F ;
2000 Microchip Technology Inc. DS30289B-page 69
PIC17C7XX
Example 9-4 shows the sequence to do a 16 x 16
signed multiply. Equation 9-2 shows the algorithm
used. The 32-bit result is stored in four registers,
RES3:RES0. To account for the sign bits of the argu-
ments, e ach a rgume nt pai rs most sign if icant bit ( MSb)
is tested and the appropriate subtractions are done.
EQUATION 9-2: 16 x 16 SIGNED
MULTIPLICATION
ALGORITHM
EXAMPLE 9-4: 16 x 16 SIGNED
MULTIPLY ROUTINE
RES3:RES0
= ARG1H:ARG1L ARG2H:ARG2L
= (ARG1H ARG2H 216)+
(ARG1H ARG2L 28)+
(ARG1L ARG2H 28)+
(ARG1L ARG2L ) +
(-1 ARG2H<7> ARG1H:ARG1L 216)+
(-1 ARG1H<7> ARG2H:ARG2L 216)
MOVFP ARG1L, WREG
MULWF ARG2L ; ARG1L * ARG2L ->
; PRODH:PRODL
MOVPF PRODH, RES1 ;
MOVPF PRODL, RES0 ;
;
MOVFP ARG1H, WREG
MULWF ARG2H ; ARG1H * ARG2H ->
; PRODH:PRODL
MOVPF PRODH, RES3 ;
MOVPF PRODL, RES2 ;
;
MOVFP ARG1L, WREG
MULWF ARG2H ; ARG1L * ARG2H ->
; PRODH:PRODL
MOVFP PRODL, WREG ;
ADDWF RES1, F ; Add cross
MOVFP PRODH, WREG ; products
ADDWFC RES2, F ;
CLRF WREG, F ;
ADDWFC RES3, F ;
;
MOVFP ARG1H, WREG ;
MULWF ARG2L ; ARG1H * ARG2L ->
; PRODH:PRODL
MOVFP PRODL, WREG ;
ADDWF RES1, F ; Add cross
MOVFP PRODH, WREG ; products
ADDWFC RES2, F ;
CLRF WREG, F ;
ADDWFC RES3, F ;
;
BTFSS ARG2H, 7 ; ARG2H:ARG2L neg?
GOTO SIGN_ARG1 ; no, check ARG1
MOVFP ARG1L, WREG ;
SUBWF RES2 ;
MOVFP ARG1H, WREG ;
SUBWFB RES3
;
SIGN_ARG1
BTFSS ARG1H, 7 ; ARG1H:ARG1L neg?
GOTO CONT_CODE ; no, done
MOVFP ARG2L, WREG ;
SUBWF RES2 ;
MOVFP ARG2H, WREG ;
SUBWFB RES3
;
CONT_CODE
:
PIC17C7XX
DS30289B-page 70 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 71
PIC17C7XX
10.0 I/O PORTS
PIC17C75X devices have seven I/O ports, PORTA
through PORTG. PIC17C76X devices have nine I/O
ports, PORTA through PORTJ. PORTB through
PORTJ have a corresponding Data Direction Register
(DDR), which is used to configure the port pins as
inputs or outputs. Some of these ports pins are multi-
plexed with alternate functions.
PORT C, PORTD, and POR TE are multip lexed wit h the
system bus. These pins are configured as the system
bus w hen the dev ices configuration bits are selected to
Microprocessor or Extended Microcontroller mode s. In
the two other microcontroller modes, these pins are
general purpose I/O.
PORTA, PORTB, PORTE<3>, PORTF, PORTG and
the upper four bits of PORTH are multiplexed with the
periphera l features of the devi ce. These periph eral fea-
tures are:
Timer Modules
Capture Modules
PWM Modules
USART/SCI Modules
SSP Module
A/D Modul e
External Inte rrup t pin
When so me of these p eripheral m odules are t urned on,
the port pi n w il l au tom at ica ll y c onfigure to the alte rna t e
function. The modules that do this are:
PWM Mo dule
SSP Module
USART/SCI Module
When a pin is auto mat ically c onf igured a s an outp ut by
a peripheral module, the pins data direction (DDR) bit
is unknown. After disabling the peripheral module, the
user should re-initialize the DDR bit to the desired con-
figuration.
The other peripheral modules (which require an input)
must h av e th ei r da ta direction bi t s c onfi gu r ed app rop ri-
ately.
When the device enters the RESET state, the Data
Direction registers (DDR) are forced set, which will
make the I/O hi-impe dance input s. The RESET sta te of
some peripheral modules may force the I/O to other
operations, such as analog inputs or the system bus.
Note: A pin tha t is a periph eral input, can b e con-
figured as an output (DDRx<y> is cle ared).
The peripheral events will be determined
by the action out put on the port pin .
PIC17C7XX
DS30289B-page 72 2000 Microchip Technology Inc.
10.1 PORTA Register
PORTA is a 6-bit wide latch. PORTA does not have a
corresponding Data Direction Register (DDR). Upon a
device RESET, the PORTA pins are forced to be hi-
impedance inputs. For the RA4 and RA5 pins, the
peripheral module controls the output. When a device
RESET occurs, the peripheral module is disabled, so
these pins are forced to be hi-impedance inputs.
Reading PORTA reads the status of the pins.
The RA0 pin is multiplexed with the external interrupt,
INT. The RA1 p in is mu ltiple xed wi th T MR0 cl ock i nput,
RA2 and RA3 are multiplexed with the SSP functions,
and RA4 and RA5 are multiplexed with the USART1
functions. The control of RA2, RA3, RA4 and RA5 as
outputs, is automatically configured by their multi-
plexed peripheral module when the module is enabled.
10.1.1 USING RA2, RA3 AS OUTPUTS
The RA2 and RA3 pins are open drain outputs. To use
the RA2 and/or the RA3 pin(s) as output(s), simply
write to the PO R TA register the de si red v al ue. A 0 will
cause the pin to drive low, while a 1 will cause the pin
to float (hi-impedance). An external pull-up resistor
should be used to pull the pin high. Writes to the RA2
and RA3 pins will not affect the other PORTA pins.
Example 10-1 shows a n instruc tio n s equence to initia l-
ize PORTA. The Bank Select Register (BSR) must be
select ed to Bank 0 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-1: INITIALIZING PORTA
FIGURE 10-1: RA0 AND RA1 BLOCK
DIAGRAM
FIGURE 10-2: RA2 BLOCK DIAGRAM
Note: When using the RA2 or RA3 pin(s) as out-
put(s), read-modify-write instructions (such
as BCF, BSF, BTG) on PORTA are not
recommended.
Such operations read the port pins, do the
desired operatio n, and then write this value
to the data latch. This may inadvertently
cause the RA2 or RA3 pins to switch from
input to output (or vice-versa).
To avoid this po ssib ility, use a sha dow reg-
ister for PORTA. Do the bit operations on
this shadow register and then move it to
PORTA.
MOVLB 0 ; Select Bank 0
MOVLW 0xF3 ;
MOVWF PORTA ; Initialize PORTA
; RA<3:2> are output low
; RA<5:4> and RA<1:0>
; are inputs
; (outputs floating)
Note: Input pins have protection diodes to VDD and VSS.
Data Bus
RD_PORTA
(Q2)
Note: I/O pin has protection diodes to VSS.
Data Bus
WR_PORTA
(Q4)
QD
QCK
RD_PORTA
(Q2)
QD
EN
Peripheral Data In
1
0
I2C Mode Enable
SCL Out
2000 Microchip Technology Inc. DS30289B-page 73
PIC17C7XX
FIGURE 10-3: RA3 BLOCK DIAGRAM FIGURE 10-4: RA4 AND RA5 BLOCK
DIAGRAM
TABLE 10-1: PORTA FUNCTIONS
TABLE 10-2: REGISTERS/BITS ASSOCIATED WITH PORTA
Note: I/O pin has protection diodes to VSS.
Data Bus
WR_PORTA
(Q4)
QD
QCK
RD_PORTA
(Q2)
QD
EN
Peripheral Data In
SDA Out
SSP Mode
1
Note: I/O pins have protection diodes to VDD and VSS.
Data Bus
RD_PORTA
(Q2)
Serial Port Output Signals
Serial Port Input Signal
OE = SPEN,SY N C, TXEN, C REN, SREN for RA 4
OE = SPEN (SYNC +S YNC, CSRC) for RA5
Name Bit0 Buffer Type Function
RA0/ INT bit0 S T Input or exte rnal interrupt input.
RA1/T0CKI bit1 ST Input or clock input to the TMR0 timer/counter and/or an external interrupt
input.
RA2/SS/SCL bit2 ST Input/output or slave select input for the SPI, or clock input for the I2C bus.
Output is open drain type.
RA3/SDI/SDA bit3 ST Input/output or data input for the SPI, or data for the I2C bus.
Output is open drain type.
RA4/RX1/DT1 bit4 ST Input or USART1 Asynchronous Receive input, or
USART1 Synchronous Data input/output.
RA5/TX1/CK1 bit5 ST Input or USART1 Asynchronous Transmit output, or
USART1 Synchronous Clock input/output.
RBPU bit7 Control bit for PORTB weak pull-ups.
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
10h, Bank 0 PO RTA (1) RBPU RA5/
TX1/CK1 RA4/
RX1/DT1 RA3/
SDI/SDA RA2/
SS/SCL RA1/T0CKI RA0/INT 0-xx 11xx 0-uu 11uu
05h, Unba nke d T0STA INTEDG T 0S E T0CS T0PS3 T0PS2 T0PS1 T0PS0 0000 000- 0000 000-
13h, Bank 0 RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
15h, Bank 0 TXS TA1 CSR C TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
Legend: x = unknown, u = unchanged, - = unimplemented, reads as '0'. Shaded cells are not used by PORTA.
Note 1: On any device RESET, these pins are configured as inputs.
PIC17C7XX
DS30289B-page 74 2000 Microchip Technology Inc.
10.2 PORTB and DDRB Registers
PORTB is an 8-bit wide, bi-directional port. The corre-
sponding data direction register is DDRB. A 1 in DDRB
configu r es the c orre sp ond ing port pin as an in put. A 0
in the DDRB register configures the corre sponding port
pin as an output. Reading PORTB reads the status of
the pins, whereas writing to POR TB will write to the port
latch.
Each of th e POR TB pins has a we ak inte rnal pul l-up. A
single control bit can turn on all the pull-ups. This is
done by c learing the RBPU (PORTA<7>) bit. The weak
pull-up is automatically turned off when the port pin is
configured as an output. The pull-ups are enabled on
any RESET.
PORTB also has an interrupt-on-change feature. Only
pins configured as inputs can cause this interrupt to
occur (i.e ., any RB7: RB0 pin config ured as an out put is
excluded from the interrupt-on-change comparison).
The input pins (of RB7:RB0) are compared with the
value i n the POR TB data latc h. The mismatch output s
of RB7:RB0 are ORd together to se t the PORTB In ter-
rupt Flag bit, RBIF (PIR1<7>).
This interrupt can wake the device from SLEEP. The
user, in the Interrupt Service Routine, can clear the
interrupt by :
a) Read-Write PORTB (such as: MOVPF PORTB,
PORTB). This will end the mismatch condition.
b) Then, clear the RBIF bit.
A mismatch condition will continue to set the RBIF bit.
Reading, then writing PORTB, will end the mismatch
condition and allow the RBIF bit to be cleared.
This interrupt-on-mismatch feature, together with soft-
ware configurable pull-ups on this port, allows easy
interface to a keypad and makes it possible for wake-
up on key depression. For an example, refer to Appli-
cation Note AN552, Implementing Wake-up on
Keystroke.
The interrupt-on-change feature is recommended for
wake-up on operati ons , w here PORTB is only used f or
the interrupt-on-change feature and key depression
operations.
FIGURE 10-5: BLOCK DIAGRAM OF RB5:RB4 AND RB1:RB0 PORT PINS
Note: On a device RESET, the RBIF bit is inde-
terminate, since the value in the latch may
be different than the pin.
Note: I/O pins have protection diodes to VDD and VSS.
Data Bus
Q
D
CK
Q
D
CK
Weak
Pull-up
Port
Input Latch
Port
Data
OE
WR_PORTB (Q4)
WR_DDRB (Q4)
RD_PORTB ( Q2)
RD_DDRB (Q2)
RBIF
RBPU
Match Signal
from other
port pins
(PORTA<7>)
Peripheral Data In
2000 Microchip Technology Inc. DS30289B-page 75
PIC17C7XX
Exampl e 10-2 s hows a n i ns truc tio n s eq uence to ini t ia l-
ize PORTB. The Bank Select Register (BSR) must be
select ed t o Bank 0 fo r the po rt to be ini tia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR register for bank selection.
EXAMPLE 10-2: INITIALIZING PORTB
FIGURE 10-6: BLOCK DIAGRAM OF RB3:RB2 PORT PINS
MOVLB 0 ; Select Bank 0
CLRF PORTB, F ; Init PORTB by clearing
; output data latches
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWF DDRB ; Set RB<3:0> as inputs
; RB<5:4> as outputs
; RB<7:6> as inputs
Note: I/O pins have protection diodes to VDD and VSS.
Data Bus
Q
D
CK
Q
D
CK
R
Weak
Pull-up
Port
Input Latch
Port
Data
OE
Peripheral_enable
Peripheral_output
WR_PORTB (Q4)
WR_DDRB (Q4)
RD_PORTB (Q2)
RD_DDRB (Q2)
RBIF
RBPU
Match Signal
from other
port pins
(PORTA<7>)
Peripheral Data In
PIC17C7XX
DS30289B-page 76 2000 Microchip Technology Inc.
FIGURE 10-7: BLOCK DIAGRAM OF RB6 PORT PIN
FIGURE 10-8: BLOCK DIAGRAM OF RB7 PORT PIN
Note: I/O pin has protection diodes to Vdd and Vss .
Data Bus
QD
CK
QD
CK
Weak
Pull-up
Port
Data
OE
SPI Output Enab l e
SPI Output
WR_PORTB (Q4)
WR_DDRB (Q4)
RD_PORTB ( Q2)
RD_DDRB (Q2)
RBIF
RBPU
Match Signal
from other
port pins
(PORTA<7>)
Periphe ra l Data In
Q
D
EN
P
NQ
0
1
Note: I/O pin has protection diod es to VDD and VSS.
Data Bus
QD
CK
QD
CK
Weak
Pull-up
Port
Data
OE
SPI Output Enab l e
SPI Output
WR_PORTB (Q4)
WR_DDRB (Q4)
RD_PORTB (Q2)
RD_DDRB (Q2)
RBIF
RBPU
Match Signal
from other
port pins
(PORTA<7>)
Peripheral Data In
QD
EN
P
NQ
0
1
SS Output Disabl e
2000 Microchip Technology Inc. DS30289B-page 77
PIC17C7XX
TABLE 10-3: PORTB FUNCTIONS
TABLE 10-4: REGISTERS/BITS ASSOCIATED WITH PORTB
Name Bit Buffer Type Function
RB0/CAP1 bit0 ST Input/output or the Capture1 input pin. Software programmable weak
pull-up and interrupt-on-change features.
RB1/CAP2 bit1 ST Input/output or the Capture2 input pin. Software programmable weak
pull-up and interrupt-on-change features.
RB2/PWM 1 bit2 ST Input/output or th e PWM1 output pin. Sof twa re programm able wea k pull-u p
and interrupt-on-change features.
RB3/PWM 2 bit3 ST Input/output or th e PWM2 output pin. Sof twa re programm able wea k pull-u p
and interrupt-on-change features.
RB4/TCLK12 bit4 ST Input/output or the external clock input to Timer1 and Timer2. Software
programmable weak pull-up and interrupt-on-change features.
RB5/TCLK3 bit5 ST Input/output or the external clock input to Timer3. Software programmable
weak pull-up and interrupt-on-change features.
RB6/SCK bit6 ST Input/output or the M as ter/Sl ave clo ck for the SPI. Software progra mm able
weak pull-up and interrupt-on-change features.
RB7/SDO bit7 ST Input/output or data output for the SPI. Software programmable weak
pull-up and interrupt-on-change features.
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
12h, Bank 0 PORTB RB7/
SDO RB6/
SCK RB5/
TCLK3 RB4/
TCLK12 RB3/
PWM2 RB2/
PWM1 RB1/
CAP2 RB0/
CAP1 xxxx xxxx uuuu uuuu
11h, Bank 0 DDRB Data Direction Register for PORTB 1111 1111 1111 1111
10h, Bank 0 PORTA RBPU RA5/
TX1/CK1 RA4/
RX1/DT1 RA3/
SDI/SDA RA2/
SS/SCL RA1/T0CKI RA0/INT 0-xx 11xx 0-uu 11uu
06h, Unba nke d CPU STA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
07h, Unba nke d IN TS TA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RB IE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
16h, Bank 3 TCON1 CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS 0000 0000 0000 0000
17h, Bank 3 TCON2 CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as 0, q = value depends on condition. Shaded cells are not used by PORTB.
PIC17C7XX
DS30289B-page 78 2000 Microchip Technology Inc.
10.3 PORTC and DDRC Registers
PORTC is an 8-bit bi-directional port. The correspond-
ing data direction register is DDRC. A 1 in DDRC con-
figures the corresponding port pin as an input. A 0 in
the DDRC register configures the corresponding port
pin as an output. Reading PORTC reads the status of
the pins, whereas writi ng to PORTC will writ e to the port
latch. PORTC is multiplexed with the system bus.
When op er a tin g as t h e s ys tem bus, P ORTC i s th e l o w
order byt e of the address/data bus (AD7:AD0). The tim-
ing for the sys tem bus is show n in the Elect ric al Speci-
fications section.
Example 10-3 shows a n instruc tio n s equence to initia l-
ize PORTC. The Bank Select Register (BSR) must be
select ed to Bank 1 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-3: INITIALIZING PORTC
FIGURE 10-9: BLOCK DIAGRAM OF RC7:RC0 PORT PINS
Note: This port is configured as the system bus
when the devices configuration bits are
selected to Microprocessor or Extended
Microcontroller modes. In the two other
microcontroller modes, this port is a
general purpose I/O.
MOVLB 1 ; Select Bank 1
CLRF PORTC, F ; Initialize PORTC data
; latches before setting
; the data direction reg
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWF DDRC ; Set RC<3:0> as inputs
; RC<5:4> as outputs
; RC<7:6> as inputs
Note: I/O pins have protection diodes to VDD and VSS.
QD
CK
TTL
0
1
QD
CK
RS
Input
Buffer
Port
Data
To D_Bus IR
INSTRUCTION READ
Data Bus
RD_PORTC
WR_PORTC
RD_DDRC
WR_DDRC
EX_EN
DATA/ADDR_OUT
DRV_SYS System Bus
Control
2000 Microchip Technology Inc. DS30289B-page 79
PIC17C7XX
TABLE 10-5: PORTC FUNCTIONS
TABLE 10-6: REGISTERS/BITS ASSOCIATED WITH PORTC
Name Bit Buffer Type Function
RC0/AD0 bit0 TTL Input/output or system bus address/data pin.
RC1/AD1 bit1 TTL Input/output or system bus address/data pin.
RC2/AD2 bit2 TTL Input/output or system bus address/data pin.
RC3/AD3 bit3 TTL Input/output or system bus address/data pin.
RC4/AD4 bit4 TTL Input/output or system bus address/data pin.
RC5/AD5 bit5 TTL Input/output or system bus address/data pin.
RC6/AD6 bit6 TTL Input/output or system bus address/data pin.
RC7/AD7 bit7 TTL Input/output or system bus address/data pin.
Legend: TTL = TTL input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value o n
POR,
BOR
MCLR,
WDT
11h, Bank 1 PORTC RC7/
AD7 RC6/
AD6 RC5/
AD5 RC4/
AD4 RC3/
AD3 RC2/
AD2 RC1/
AD1 RC0/
AD0 xxxx xxxx uuuu uuuu
10h, Bank 1 DDRC Data Direction Register for PORTC 1111 1111 1111 1111
Legend: x = unknown, u = unchanged
PIC17C7XX
DS30289B-page 80 2000 Microchip Technology Inc.
10.4 PORTD and DDRD Registers
PORTD is an 8-bit bi-directional port. The correspond-
ing data direction register is DDRD. A 1 in DDRD con-
figures the corresponding port pin as an input. A 0 in
the DDRD register configures the corresponding port
pin as an output. Reading PORTD reads the status of
the pins, whereas writi ng to PORTD will writ e to the port
latch. PORTD is multiplexed with the system bus.
When ope rati ng as the syst em bus , POR T D is the high
order byte of the address/data bus (AD15:AD8). The
timing for the system bus is shown in the Electrical
Specifications section.
Example 10-4 shows a n instruc tio n s equence to initia l-
ize PORTD. The Bank Select Register (BSR) must be
select ed to Bank 1 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-4: INITIALIZING PORTD
FIGURE 10-10: BLOCK DIAGRAM OF RD7:RD0 PORT PINS (IN I/O PORT MODE)
Note: This port is configured as the system bus
when the devices configuration bits are
selected to Microprocessor or Extended
Microcontroller modes. In the two other
microcontroller modes, this port is a gen-
eral purpos e I/O.
MOVLB 1 ; Select Bank 1
CLRF PORTD, F ; Initialize PORTD data
; latches before setting
; the data direction reg
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWF DDRD ; Set RD<3:0> as inputs
; RD<5:4> as outputs
; RD<7:6> as inputs
Note: I/O pins have protection diodes to VDD and VSS.
QD
CK
TTL
0
1
QD
CK
RS
Input
Buffer
Port
Data
To D_Bus IR
INSTRUCTION READ
Data Bus
RD_PORTD
WR_PORTD
RD_DDRD
WR_DDRD
EX_EN
DATA/ADDR_OUT
DRV_SYS System Bus
Control
2000 Microchip Technology Inc. DS30289B-page 81
PIC17C7XX
TABLE 10-7: PORTD FUNCTIONS
TABLE 10-8: REGISTERS/BITS ASSOCIATED WITH PORTD
Name Bit Buffer Type Function
RD0/AD8 bit0 TTL Input/output or system bus address/data pin.
RD1/AD9 bit1 TTL Input/output or system bus address/data pin.
RD2/AD10 bit2 TTL Input/output or system bus address/data pin.
RD3/AD11 bit3 TTL Input/output or system bus address/data pin.
RD4/AD12 bit4 TTL Input/output or system bus address/data pin.
RD5/AD13 bit5 TTL Input/output or system bus address/data pin.
RD6/AD14 bit6 TTL Input/output or system bus address/data pin.
RD7/AD15 bit7 TTL Input/output or system bus address/data pin.
Legend: TTL = TTL input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
13h, Bank 1 PORTD RD7/
AD15 RD6/
AD14 RD5/
AD13 RD4/
AD12 RD3/
AD11 RD2/
AD10 RD1/
AD9 RD0/
AD8 xxxx xxxx uuuu uuuu
12h, Bank 1 DDRD Data Direction Register for PORTD 1111 1111 1111 1111
Legend: x = unknown, u = unchanged
PIC17C7XX
DS30289B-page 82 2000 Microchip Technology Inc.
10.5 PORTE and DDRE Register
PORT E is a 4-bi t bi-direc tional po rt. The co rrespondin g
data direction register is DDRE. A 1 in DD RE con fig-
ures the correspon din g p ort p in as an i nput. A 0 in the
DDRE register configures the corresponding port pin
as an output. Reading PORTE reads the status of the
pins, whereas writing to PORTE will write to the port
latch. PORTE is multiplexed with the system bus.
When operating as the system bus, PORTE contains
the control signals for the address/data bus
(AD15:AD0). These control signals are Address Latch
Enable (ALE), Output Enable (OE) and Write (WR).
The control signals OE and WR are active low signals.
The tim ing f or t he sys tem b us is sho wn i n the Electr ical
Specifications section.
Example 10-5 shows a n instruc tio n s equence to initia l-
ize PORT E. The Bank Select Register (BSR) must be
select ed to Bank 1 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-5: INITIALIZING PORTE
FIGURE 10-11: BLOCK DIAGRAM OF RE2:RE0 (IN I/O PORT MODE)
Note: Three pins of this port are configured as
the sys tem bu s wh en the dev ic es configu-
ration bits are selected to Microprocessor
or Extended Microcontroller modes. The
other pin is a general purpose I/O or
Capture4 pin. In the two other micro-
controller modes, RE2:RE0 are general
purpose I /O pins.
MOVLB 1 ; Select Bank 1
CLRF PORTE, F ; Initialize PORTE data
; latches before setting
; the data direction
; register
MOVLW 0x03 ; Value used to initialize
; data direction
MOVWF DDRE ; Set RE<1:0> as inputs
; RE<3:2> as outputs
; RE<7:4> are always
; read as ’0’
Note: I/O pins have protection diodes to VDD and VSS.
QD
CK
TTL
0
1
QD
CK
RS
Input
Buffer
Port
Data
Data Bus
RD_PORTE
WR_PORTE
RD_DDRE
WR_DDRE
EX_EN
CNTL
DRV_SYS System Bus
Control
2000 Microchip Technology Inc. DS30289B-page 83
PIC17C7XX
FIGURE 10-12: BLOCK DIAGRAM OF RE3/CAP4 PORT PIN
TABLE 10-9: PORTE FUNCTIONS
TABLE 10-10: REGISTERS/BITS ASSOCIATED WITH PORTE
Note: I/O pin has protection diodes to VDD and VSS.
D
CK
QD
CK
QS
Port
Data
Data Bus
RD_PORTE
WR_PORTE
RD_DDRE
WR_DDRE
EN
QD
EN
P
N
Q
Q
Peripheral In
VDD
Name Bit Buffer Type Function
RE0/ALE bit0 TTL Input/output or system bus Address Latch Enable (ALE) control pin.
RE1/OE bit1 TTL Input/output or system bus Output Enable (OE) control pin.
RE2/WR bit2 TTL Input/output or system bus Write (WR) control pin.
RE3/CAP4 bit3 ST Input/output or Capture4 input pin.
Legend: TTL = TTL input, ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, W DT
15h, Bank 1 PORTE RE3/CAP4 RE2/WR RE1/OE RE0/ALE ---- xxxx ---- uuuu
14h, Bank 1 DDRE Data Direction Register for PORTE ---- 1111 ---- 1111
14h, Bank 7 CA 4L Ca ptu re4 Low Byte xxxx xxxx uuuu uuuu
15h, Bank 7 CA 4H C a ptu re4 High Byte xxxx xxxx uuuu uuuu
16h, Bank 7 T CON3 —CA4OVFCA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTE.
PIC17C7XX
DS30289B-page 84 2000 Microchip Technology Inc.
10.6 PORTF and DDRF Registers
PORTF is an 8-bit wide bi-directional port. The corre-
sponding data direction register is DDRF. A 1 in DDRF
configu r es the c orre sp ond ing port pin as an in put. A 0
in the D DRF registe r configure s the correspo nding port
pin as an output. Reading PORTF reads the status of
the pins, whereas writing to PORTF will write to the
respective port latch.
All eight bits of POR TF are multi plexed w ith 8 chan nels
of the 10-bit A/D converter.
Upon RESET, the entire Port is automatically config-
ured as analog inputs and must be configured in soft-
ware to be a digital I/O.
Example 10-6 shows a n instruc tio n s equence to initia l-
ize PORTF. The Bank Select Register (BSR) must be
select ed to Bank 5 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-6: INITIALIZING PORTF
FIGURE 10-13: BLOCK DIAGRAM OF RF7:RF0
MOVLB 5 ; Select Bank 5
MOVWF 0x0E ; Configure PORTF as
MOVWF ADCON1 ; Digital
CLRF PORTF, F ; Initialize PORTF data
; latches before
; the data direction
; register
MOVLW 0x03 ; Value used to init
; data direction
MOVWF DDRF ; Set RF<1:0> as inputs
; RF<7:2> as outputs
Data Bus
WR PORTF
WR DDRF
RD PORTF
Data Latch
DDRF Latch
P
VSS
I/O pin
PCFG3:PCFG0
Q
D
QCK
Q
D
QCK
EN
QD
EN
N
ST
Input
Buffer
VDD
RD DDRF
To other pads
VAIN
CHS3:CHS0 To other pads
Note: I/O pins have protection diodes to VDD and VSS.
2000 Microchip Technology Inc. DS30289B-page 85
PIC17C7XX
TABLE 10-11: PORTF FUNCTIONS
TABLE 10-12: REGISTERS/BITS ASSOCIATED WITH PORTF
Name Bit Buffer Type Function
RF0/AN4 bit0 ST Input/output or analog input 4.
RF1/AN5 bit1 ST Input/output or analog input 5.
RF2/AN6 bit2 ST Input/output or analog input 6.
RF3/AN7 bit3 ST Input/output or analog input 7.
RF4/AN8 bit4 ST Input/output or analog input 8.
RF5/AN9 bit5 ST Input/output or analog input 9.
RF6/AN10 bit6 ST Input/output or analog input 10.
RF7/AN11 bit7 ST Input/output or analog input 11.
Legend: ST = Schmitt Trigger input
Addr e s s Name B it 7 Bit 6 Bi t 5 B it 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
10h, Bank 5 DDRF D ata Direction Register for PORTF 1111 1111 1111 1111
11h, Bank 5 PORTF RF7/
AN11 RF6/
AN10 RF5/
AN9 RF4/
AN8 RF3/
AN7 RF2/
AN6 RF1/
AN5 RF0/
AN4 0000 0000 0000 0000
15h, Bank 5 ADCON1 ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0 000- 0000 000- 0000
Legend: x = unknown, u = unchanged, - = unimplem ented, read as '0'. Shaded cells are not used by PORTF.
PIC17C7XX
DS30289B-page 86 2000 Microchip Technology Inc.
10.7 PORTG and DDRG Registers
PORTG is an 8-bit wide, bi-directional port. The corre-
sponding data direction register is DDRG. A 1 in
DDRG configures the corresponding port pin as an
input. A 0 in the DDRG register configures the corre-
spondi ng port pin as an output. Reading PORT G reads
the status of the pins, whereas writing to PORTG will
write to the port latch.
The low er four b its of PO R TG a re mult iplex ed with fo ur
channels of the 10-bit A/D converter.
The remaining bits of PORTG are multiplexed with
peripheral output and inputs. RG4 is multiplexed with
the CAP3 input, RG5 is multiplexed with the PWM3
output, RG6 and RG7 are multiplexed with the
USART2 functions.
Upon RESET, RG3:RG0 is autom atically configu red as
analog i np uts and m ust be config ured in sof tware to b e
a di gital I/O.
Example 10-7 shows the instru ction s equence t o initial-
ize PORTG. The Bank Select Register (BSR) must be
select ed to Bank 5 fo r the po rt to be initia liz ed . Th e fol-
lowing example uses the MOVLB instruction to load the
BSR r egister for bank selection.
EXAMPLE 10-7: INITIALIZING PORTG
FIGURE 10-14: BLOCK DIAGRAM OF RG3:RG0
MOVLB 5 ; Select Bank 5
MOVLW 0x0E ; Configure PORTG as
MOVPF WREG, ADCON1 ; digital
CLRF PORTG, F ; Initialize PORTG data
; latches before
; the data direction
; register
MOVLW 0x03 ; Value used to init
; data direction
MOVWF DDRG ; Set RG<1:0> as inputs
; RG<7:2> as outputs
Data Bus
WR PORTG
WR DDRG
RD PORTG
Data Latch
DDRG Latch
P
VSS
I/O pin
PCFG3:PCFG0
Q
D
QCK
Q
D
QCK
EN
QD
EN
N
ST
Input
Buffer
VDD
RD DDRG
To other pads
VAIN
CHS3:CHS0 To other pads
Note: I/O pins have protection diodes to VDD and VSS.
2000 Microchip Technology Inc. DS30289B-page 87
PIC17C7XX
FIGURE 10-15: RG4 BLOCK DIAGRAM
FIGURE 10-16: RG7:RG5 BLOCK DIAGRAM
Note: I/O pins have protection diodes to VDD and VSS.
D
CK
QD
CK
Q
Data Bus
RD_PORTG
WR_PORTG
RD_DDRG
WR_DDRG
EN
Q
D
EN
P
N
Q
Peripheral Data In
VDD
Note: I/O pins have protection diodes to VDD and VSS.
QD
CK
1
0
QD
CK
R
Port
Data
Data Bus
RD_PORTG
WR_PORTG
RD_DDRG
WR_DDRG
N
QD
EN
P
N
Q
Q
OUTPUT
OUTPUT ENABLE
Peripheral Data In
VDD
PIC17C7XX
DS30289B-page 88 2000 Microchip Technology Inc.
TABLE 10-13: PORTG FUNCTIONS
TABLE 10-14: REGISTERS/BITS ASSOCIATED WITH PORTG
Name Bit Buffer Type Function
RG0/AN3 bit0 ST Input/output or analog input 3.
RG1/AN2 bit1 ST Input/output or analog input 2.
RG2/AN1/VREF- bit2 ST Input/output or analog input 1 or the ground reference voltage.
RG3/AN0/VREF+ bit3 ST Input/output or analog input 0 or the positive reference voltage.
RG4/CAP3 bit4 ST Input/output or the Capture3 input pin.
RG5/PWM3 bit5 ST Input/output or the PWM3 output pin.
RG6/RX2/DT2 bit6 ST Input/output or the USART2 (SCI) Asynchronous Receive or USART2
(SCI) Synchr ono us Dat a .
RG7/TX 2/CK2 b it7 ST Input/output or the USAR T2 (SCI ) Asyn chrono us Transmi t or USAR T2
(SCI) Synchr ono us C lock.
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
12h, Bank 5 DDRG Data Direction Register for PORTG 1111 1111 1111 1111
13h, Bank 5 PORTG RG7 /
TX2/CK2 RG6/
RX2/DT2 RG5/
PWM3 RG4/
CAP3 RG3/
AN0 RG2/
AN1 RG1/
AN2 RG0/
AN3 xxxx 0000 uuuu 0000
15h, Bank 5 ADCON1 ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0 000- 0000 000- 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by PORTG.
2000 Microchip Technology Inc. DS30289B-page 89
PIC17C7XX
10.8 PORTH and DDRH Registers
(PIC17C76X only)
PORTH is an 8-bit wide, bi-directional port. The corre-
sponding data direction register is DDRH. A 1 in
DDRH configures the corresponding port pin as an
input. A 0 in the DDRH register configures the corre-
spondi ng port pin as an outpu t. Reading POR TH reads
the status of the pins, whereas writing to PORTH will
write to the respective port latch.
The upper four bits of PORTH are multiplexed with
4 channels of the 10-bit A/D converter.
The remai ning bi ts of PORT H are ge neral pur pose I/O .
Upon RESET, RH7:RH4 are automatically configured
as analo g input s and m ust be co nfigure d in sof twa re to
be a digital I/O.
EXAMPLE 10-8: INITIALIZING PORTH
FIGURE 10-17: BLOCK DIAGRAM OF RH7:RH4
MOVLB 8 ; Select Bank 8
MOVLW 0x0E ; Configure PORTH as
MOVPF ADCON1 ; digital
CLRF PORTH, F ; Initialize PORTH data
; latches before
; the data direction
; register
MOVLW 0x03 ; Value used to init
; data direction
MOVWF DDRH ; Set RH<1:0> as inputs
; RH<7:2> as outputs
Data Bus
WR PORTH
WR DDRH
RD PORT
Data Latch
DDRH Latch
P
VSS
I/O pin
PCFG3:PCFG0
To other pads
Q
D
Q
CK
EN
QD
EN
N
ST
Input
Buffer
VDD
RD DDRH
To other pads
VAIN
CHS3:CHS0
Q
D
QCK
Note: I/O pins have protection diodes to VDD and VSS.
PIC17C7XX
DS30289B-page 90 2000 Microchip Technology Inc.
FIGURE 10-18: RH3:RH0 BLOCK DIAGRAM
TABLE 10-15: PORTH FUNCTIONS
TABLE 10-16: REGISTERS/BITS ASSOCIATED WITH PORTH
Note: I/O pins have protection diodes to VDD and VSS.
D
CK
QD
CK
Q
Data Bus
RD_PORTH
WR_PORTH
RD_DDRH
WR_DDRH
EN
Q
D
EN
P
N
Q
VDD
Name Bit Buffer Type Function
RH0 bit0 ST Input/output.
RH1 bit1 ST Input/output.
RH2 bit2 ST Input/output.
RH3 bit3 ST Input/output.
RH4/AN12 bit4 ST Input/output or analog input 12.
RH5/AN13 bit5 ST Input/output or analog input 13.
RH6/AN14 bit6 ST Input/output or analog input 14.
RH7/AN15 bit7 ST Input/output or analog input 15.
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
10h, Bank 8 DDRH Data Direction Register for PORTH 1111 1111 1111 1111
11h, Bank 8 PORTH RH7/
AN15 RH6/
AN14 RH5/
AN13 RH4/
AN12 RH3 RH2 RH1 RH0 0000 xxxx 0000 uuuu
15h, Bank 5 AD CON 1 ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0 000- 0000 000- 0000
Legend: x = unknown, u = unchanged
2000 Microchip Technology Inc. DS30289B-page 91
PIC17C7XX
10.9 PORTJ and DDRJ Registers
(PIC17C76X only)
PORTJ is an 8-bit wide, bi-directional port. The corre-
spondi ng data dire ction regis ter is DDRJ. A 1 in DDRJ
configu r es the c orre sp ond ing port pin as a n in put. A 0
in the DDRJ register configures the corresponding port
pin as an output. Reading PORTJ reads the status of
the pins, whereas writing to PORTJ will write to the
respective port latch.
PORTJ is a gen eral purpose I/O por t.
EXAMPLE 10-9: INITIALIZING PORTJ
FIGURE 10-19: PORTJ BLOCK DIAGRAM
MOVLB 8 ; Select Bank 8
CLRF PORTJ, F ; Initialize PORTJ data
; latches before setting
; the data direction
; register
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWF DDRJ ; Set RJ<3:0> as inputs
; RJ<5:4> as outputs
; RJ<7:6> as inputs
Note: I/O pins have protection diodes to VDD and VSS.
D
CK
QD
CK
Q
Data Bus
RD_PORTJ
WR_PORTJ
RD_DDRJ
WR_DDRJ
EN
Q
D
EN
P
N
Q
VDD
PIC17C7XX
DS30289B-page 92 2000 Microchip Technology Inc.
TABLE 10-17: PORTJ FUNCTIONS
TABLE 10-18: REGISTERS/BITS ASSOCIATED WITH PORTJ
Name Bit Buffer Type Function
RJ0 bit0 ST Input/output
RJ1 bit1 ST Input/output
RJ2 bit2 ST Input/output
RJ3 bit3 ST Input/output
RJ4 bit4 ST Input/output
RJ5 bit5 ST Input/output
RJ6 bit6 ST Input/output
RJ7 bit7 ST Input/output
Legend: ST = Schmitt Trigger input
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on,
POR,
BOR
MCLR,
WDT
12h, Bank 8 DDRJ Data Direction Register for PORTJ 1111 1111 1111 1111
13h, Bank 8 PORTJ RJ7 RJ6 RJ5 RJ4 RJ3 RJ2 RJ1 RJ0 xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchanged
2000 Microchip Technology Inc. DS30289B-page 93
PIC17C7XX
10.10 I/O Programming Considerations
10.10.1 BI-DIRECTIONAL I/O PORTS
Any instruction which writes, operates internally as a
read, followed by a write operation. For example, the
BCF and BSF instructions read the register into the
CPU, execute the bit operation and write the result
back to the register. Caution must be used when thes e
instructions are applied to a port with both inputs and
outputs defined. For example, a BSF operation on bit5
of POR TB, will caus e all eight bits of PORTB to be rea d
into the CPU. Then the BSF operation takes place on
bit5 and PORTB is written to the output latches. If
another bit of PORTB is used as a bi- directional I/O pin
(e.g. bit0) and it is defined as an input at this time, the
input si gnal presen t on th e pi n itself wo uld be rea d in to
the CPU and rewri tten to the dat a latch of this p articular
pin, ov erwriting the previous co ntent. As long as the pin
stays in the input mode, no problem occurs. However,
if bit 0 is switch ed into outp ut mode la ter on, the co ntent
of the data latch may now be unknown.
Reading a por t reads the values of the port pins. Writing
to the port register writes the value to the port latch.
When us ing rea d-modi fy-wri te instruc tions (BCF, BSF,
BTG, etc.) on a port, the value of the port pins is read,
the desired operation is performed with this value and
the value is then written to the port latch.
Example 10-10 shows the possible effect of two
sequential read-modify-write instructions on an I/O port.
EXAMPLE 10-10: READ-MODIFY -WRITE
INSTRUCTIONS ON AN
I/O PORT
; Initial PORT settings: PORTB<7:4> Inputs
; PORTB<3:0> Outputs
; PORTB<7:6> have pull-ups and are
; not connected to other circuitry
;
; PORT latch PORT pins
; ---------- ---------
;
BCF PORTB, 7 ; 01pp pppp 11pp pppp
BCF PORTB, 6 ; 10pp pppp 11pp pppp
BCF DDRB, 7 ; 10pp pppp 11pp pppp
BCF DDRB, 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).
Note: A pin actively outputting a Low or High
should not be driven from external devices,
in order to ch ange the level on this pi n (i.e.,
wired-or, wired-and). The res ul ting hig h
output currents may damage the dev ice.
PIC17C7XX
DS30289B-page 94 2000 Microchip Technology Inc.
10.10.2 SUCCESSIVE OPERATIONS ON I/O
PORTS
The actu al write to an I/O port ha ppens at t he end of a n
instruc tion cycle, whereas for re ading, the d ata mus t be
valid at the beginning of the instruction cycle
(Figure 10-20). Therefore, care must be exercised if a
write followed by a read operation is carried out on the
same I/O port. The sequence of instructions should be
such to allow the pin voltage to stabilize (load depen-
dent) before executing the instruction that reads the
values on tha t I/O po rt. Otherwise, the pre vious sta te of
that pin may be read into the CPU, rather than the
new state. When in doubt, it is better to separate
these instructions with a NOP, or another instruction
not accessing this I/O port.
Figure 10-21 shows the I/O model which causes this
situation. As the effective capacitance (C) becomes
larger, the rise/fall time of the I/O pin increases. As the
device frequency increases, or the effective capaci-
tance increases, the possibility of this subsequent
PORTx read-modify-write instruction issue increases.
This effective capacitance includes the effects of the
board traces.
The best w ay to ad dres s this is to add a ser ies res ist or
at the I/O pin. This resistor allows the I/O pin to get to
the desired level before the next instruction.
The use of NOP instructions between the subsequent
PORTx read-modify-write instructions, is a lower cost
solution, but has the issue that the number of NOP
instructions is dependent on the effective capacitance
C and the frequency of the device.
FIGURE 10-20: SUCCESSIVE I/O OPERATION
FIGURE 10-21: I/O CONNECTION ISSUES
PC PC + 1 PC + 2 PC + 3
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Instruction
Fetched
RB7:RB0
MOVWF PORTB
write to
PORTB NOP
Port pin
sample d here
NOP
MOVF PORTB,W
Instruction
Executed MOVWF PORTB
write to
PORTB
NOPMOVF PORTB,W
Note:
This example shows a write to PORTB,
followed by a read from PORTB.
Note tha t:
data setup time = (0.25TCY - TPD)
where TCY = instruction cycle
TPD = propagation delay
Therefore, at higher clock frequencies, a
write followed by a read may be problematic.
PIC17CXXX
I/O
C(1)
Q4 Q1 Q2 Q3 Q4 Q1
VIL
BSF PORTx, PINy
Q2 Q3
BSF PORTx, PINz
PORTx, PINy
Read PORTx, PINy as low
BSF PORTx, PINz clears the value
to be driven on the PORTx, PINy pin.
Note 1: This is not a capacitor to ground, but the effective
capacitive loading on the trace.
2000 Microchip Technology Inc. DS30289B-page 95
PIC17C7XX
11.0 OVERVIEW OF TIMER
RESOURCES
The P IC17C7 XX has four tim er mo dules . Each modul e
can generate an interrupt to indicate that an event has
occurred. These timers are called:
Timer0 - 16-bit timer with programmable 8-bit
prescaler
Timer1 - 8-bit timer
Timer2 - 8-bit timer
Timer3 - 16-bit timer
For enhanced time base functionality, four input Cap-
tures an d three Puls e Width Mod ulation (PWM) outputs
are possible. The PWMs use the Timer1 and Timer2
resources and the input Captures use the Timer3
resource.
11.1 Timer0 Overview
The Timer0 module is a simple 16-bit overflow counter.
The clock source can be either the internal system
clock (Fosc/4) or an external clock.
When Timer0 uses an external clock source, it has the
flexibility to allow user selection of the incrementing
edge, rising or falling.
The Timer0 module also has a programmable pres-
caler. The T0PS 3:T0PS0 bi ts (T0STA<4:1>) determin e
the prescale value. TMR0 can increment at the follow-
ing rates: 1:1, 1:2, 1:4, 1:8, 1:16, 1:32, 1:64, 1:128,
1:256.
Synchronization of the external clock occurs after the
prescaler. When the prescaler is used, the external
clock frequency may be higher than the devices fre-
quency. The maximum external frequency on the
T0CKI pin is 50 MHz, given the high and low time
requirements of the clock.
11.2 Timer1 Overview
The Timer1 module is an 8-bit timer/counter with an 8-
bit period register (PR1). When the TMR1 value rolls
over from the period match value to 0h, the TMR1IF
flag is se t and an int errupt w ill be ge nerated if enable d.
In Counter mode, the clock comes from the RB4/
TCLK12 p in, which ca n also be selec ted to be the cloc k
for the Timer2 module.
TMR1 can be concatenated with TMR2 to form a 16-bit
timer. The TMR1 register is the LSB and TMR2 is the
MSB. When in the 16-bit timer mode, there is a corre-
sponding 16-bit period register (PR2:PR1). When the
TMR2:TMR1 value rolls over from the period match
value t o 0h , th e TM R 1IF fla g i s set and an int errup t w il l
be generated, if enabled.
11.3 Timer2 Overview
The Timer2 module is an 8-bit timer/counter with an 8-
bit period register (PR2). When the TMR2 value rolls
over from the period match value to 0h, the TMR2IF
flag is se t and an interrupt wil l be generated, if enabled.
In Counter mode, the clock comes from the RB4/
TCLK12 pin, which can also provide the clock for the
Timer1 module.
TMR2 can be concaten ated with TMR1 to form a 16-bit
timer. The TMR2 register is the MSB and TMR1 is the
LSB. When in the 16-bit timer mode, there is a corre-
sponding 16-bit period register (PR2:PR1). When the
TMR2:TMR1 value rolls over from the period match
value to 0h , th e TM R1IF fla g i s s et and an int errup t wil l
be generated, if enabled.
11.4 Timer3 Overview
The Timer3 module is a 16-bit timer/counter with a 16-
bit period register. When the TMR3H:TMR3L value
rolls over to 0h, the TM R3IF bit is set and an interrupt
will be generated, if enabled. In Counter mode, the
clock comes from the RB5/TCLK3 pin.
When operating in the four Capture modes, the period
registers become the second (of four) 16-bit capture
registers.
11.5 Ro le of the Tim er /Coun ters
The timer mo dules are general purpose , but have de d-
icated resources associated with them. TImer1 and
Timer2 are the time bases for the three Pulse Width
Modulation (PWM) outputs, while Timer3 is the time
base for the four input captures.
PIC17C7XX
DS30289B-page 96 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 97
PIC17C7XX
12.0 TIMER0
The Timer0 module consists of a 16-bit timer/counter,
TMR0. The high byte is register TMR0H and the low
byte is regis ter TMR0L. A softw are programm able 8-bit
prescaler makes Timer0 an effective 24-bit overflow
timer. The clock source is software programmable as
either th e internal i nstructio n clock, or an external clock
on the RA1/T0CKI pin. The control bits for this module
are in register T0STA (Figure 12-1).
REGISTER 12-1: T0STA REGISTER (ADDRESS: 05h, UNBANKED)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0
INTEDG T0SE T0CS T0PS3 T0PS2 T0PS1 T0PS0
bit 7 bit 0
bit 7 INTEDG: RA0/INT Pin Interrupt Edge Select bit
This bit selects the edge upon which the interrupt is detected.
1 = Rising edge of RA0/INT pin generates interrupt
0 = Falling edge of RA0/INT pin generates interrupt
bit 6 T0SE: Timer0 Clock Input Edge Select bit
This bit selects the edge upon which TMR0 will increment.
When T0CS = 0 (External Clock):
1 = Rising edge of RA1/T0CKI pin increments TMR0 and/or sets the T0CKIF bit
0 = Falling edge of RA1/T0CKI pin increments TMR0 and/or sets the T0CKIF bit
When T0CS = 1 (Internal Clock):
Dont care
bit 5 T0CS: Timer0 Clock Source Select bit
This bit selects the clock source for TMR0.
1 = Internal instruction clock cycle (TCY)
0 = External clock input on the T0CKI pin
bit 4-1 T0PS3:T0PS0: Timer0 Prescale Selection bits
These bits select the prescale value for TMR0.
bit 0 Unimplemented: Read as 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
T0PS3:T0PS0 Prescale Value
0000
0001
0010
0011
0100
0101
0110
0111
1xxx
1:1
1:2
1:4
1:8
1:16
1:32
1:64
1:128
1:256
PIC17C7XX
DS30289B-page 98 2000 Microchip Technology Inc.
12.1 Timer0 Operation
When the T0CS (T0STA<5>) bit is set, TMR0 incre-
ment s on the i nternal clo ck. When T0 CS is clear, TM R0
increm ents on th e exter nal cl ock (RA1 /T0CKI pin). Th e
external c loc k ed ge can b e selected in sof tware. Whe n
the T0SE (T0STA<6>) bit is set , the timer will increment
on the r ising edg e of the RA 1/T0CK I pin. When T0 SE
is clear, the timer will increment on the falling edge of
the RA1/T0 CKI pin. The prescale r can be programmed
to introduc e a prescale of 1:1 to 1:256. The time r incre-
ments from 0000h to FFFFh and rolls over to 0000h.
On overflow, the TMR0 Interrupt Flag bit (T0IF) is set.
The TMR0 interrupt can be masked by clearing the cor-
responding TMR0 Interrupt Enable bit (T0IE). The
TMR0 Interrupt Flag bit (T0IF) is automatically cleared
when vectoring to the TMR0 interrupt vector.
12.2 Using Timer0 with External Clock
When an external clock input is used for Timer0, it is
synchronized with the internal phase clocks. Figure 12-
2 shows the sy nchron izati on of the exte rnal clock . This
synchronization is done after the prescaler. The output
of the prescaler (PSOUT) is sampled twice in every
instruc tion cycl e to detect a rising or a fa lling edg e. The
timing requirements for the external clock are detailed
in the electrical specification section.
12.2.1 DELAY FROM EXTERNAL CLOCK
EDGE
Since the prescaler output is synchronized with the
internal clocks, there is a small delay from the time the
external clock edge occurs to the time TMR0 is actually
incremented. Figure 12-2 shows that this delay is
between 3TOSC and 7TOSC. Thus, for example, mea-
suring th e in terv al bet we en two ed ges (e. g. pe rio d) w il l
be accurate within ±4TOSC (±121 ns @ 33 MHz).
FIGURE 12-1: TIMER0 MODULE BLOCK DIAGRAM
FIGURE 12-2: TMR0 TIMING WITH EXTERNAL CLOCK (INCREMENT ON FALLING EDGE)
RA1/T0CKI Synchronization
Prescaler
(8 Stage
Async Ripple
Counter)
T0SE
(T0STA<6>)
FOSC/4
T0CS
(T0STA<5>) T0PS3:T0PS0
(T0STA<4:1>) Q2 Q4
0
1TMR0H<8> TMR0L<8>
Interrupt-on-Overflow
sets T0IF
(INTSTA<5>)
4
PSOUT
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Prescaler
Output
(PSOUT)
Sampled
Prescaler
Output
Increment
TMR0
TMR0 T0 T0 + 1 T0 + 2
(Note 3)
(Note 2)
Note 1: The delay from the T0CKI edge to the TMR0 increment is 3Tosc to 7Tosc.
2: = PSOUT is sampled here.
3: The PSOUT high time is too short and is missed by the sampling circuit.
(Note 1)
2000 Microchip Technology Inc. DS30289B-page 99
PIC17C7XX
12.3 Read/Write Consideration for
TMR0
Although TMR0 is a 16-bit timer/counter, only 8-bits at
a time c an be re ad or wr itten during a sing le instruc tion
cycle. Care must be taken during any read or write.
12.3.1 READING 16-BIT VALUE
The problem in reading the entire 16-bit value is that
after reading the low (or high) byte, its value may
change from FFh to 00h.
Exampl e 12-1 s hows a 1 6-bi t rea d. To ensure a prop er
read, interrupts must be disabled during this routine.
EXAMPLE 12-1: 16-BIT READ
12.3.2 WRITING A 16-BIT VALUE TO TMR0
Since writing to either TMR0L or TMR0H will effectively
inhibit increment of that half of the TMR0 in the next
cycle (following write), but not inhibit increment of the
other half, the user must write to TMR0L first and
TMR0H second, in two consecutive instructions, as
shown in Example 12-2. The interrupt must be dis-
abl ed. An y write to either TMR0L or TMR0H clear s the
prescaler.
EXAMPLE 12-2: 16-BIT WRITE
12.4 Prescaler Assignments
Timer0 has an 8-bit prescaler. The prescaler selection
is fully under software control; i.e., it can be changed
on the fly during program execution. Clearing the
prescaler is recommended before changing its setting.
The va lu e o f t h e pre sc al e r is unknown and assigning
a value that i s les s tha n the presen t valu e, mak es i t dif-
ficult to take this unknown time into account.
FIGURE 12-3: TMR0 TIMING: WRITE HIGH OR LOW BYTE
MOVPF TMR0L, TMPLO ;read low tmr0
MOVPF TMR0H, TMPHI ;read high tmr0
MOVFP TMPLO, WREG ;tmplo −> wreg
CPFSLT TMR0L ;tmr0l < wreg?
RETURN ;no then return
MOVPF TMR0L, TMPLO ;read low tmr0
MOVPF TMR0H, TMPHI ;read high tmr0
RETURN ;return
BSF CPUSTA, GLINTD ; Disable interrupts
MOVFP RAM_L, TMR0L ;
MOVFP RAM_H, TMR0H ;
BCF CPUSTA, GLINTD ; Done, enable
; interrupts
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
ALE
TMR0L
TMR0H
MOVFP W,TMR0L
Write to TMR0L MOVFP TMR0L,W
Read TMR0L
(Value = NT0)
MOVF P TMR0L,W
Read TMR0L
(Value = NT0)
MOVFP TMR0L, W
Read TMR0L
(Value = NT0 +1)
T0 T0+1 New T0 (NT0) New T0+1
PC PC+1 PC+2 PC+3 PC+4
Fetch
Instruction
Executed
PIC17C7XX
DS30289B-page 100 2000 Microchip Technology Inc.
FIGURE 12-4: TMR0 READ/WRITE IN TIMER MODE
TABLE 12-1: REGISTERS/BITS ASSOCIATED WITH TIMER0
Instruction
Executed
MOVFP
DATAL,TMR0L
Wr ite TMR0L
MOVFP
DATAH,TMR0H
Write TMR0H
MOVPF
TMR0L,W
Read TMR0L
MOVPF
TMR0L,W
Read TMR0L
MOVPF
TMR0L,W
Read TMR0L
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
AD15:AD0
ALE
WR_TRM0L
WR_TMR0H
RD_TMR0L
TMR0H
TMR0L
12 12 13 AB
FE FF 56 57 58
Note: In this example, old TMR0 value is 12FEh, new value of AB56h is written.
Instruction
Fetched
MOVFP
DATAL,TMR0L
Wr ite TMR0L
MOVFP
DATAH,TMR0H
Write TMR0H
MOVPF
TMR0L,W
Read TMR0L
MOVPF
TMR0L,W
Read TMR0L
MOVPF
TMR0L,W
Read TMR0L
MOVPF
TMR0L,W
Read TMR0L
Previously
Fetched
Instruction
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
05h, Unba nke d T0STA INTEDG T0SE T0CS T0PS3 T0PS2 T0PS1 T0PS0 0000 000- 0000 000-
06h, Unba nke d CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
07h, Unba nke d INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
0Bh, Unbanked TMR0L TMR0 Register; Low Byte xxxx xxxx uuuu uuuu
0Ch, Unbanked TMR0H TMR0 Register; High Byte xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0', q = value depends on condition. Shaded cells are not used by Timer0.
2000 Microchip Technology Inc. DS30289B-page 101
PIC17C7XX
13.0 TIMER1, TIMER2, TIMER3,
PWMS AND CAPTURES
The PIC1 7C7XX has a w ealth of time rs and time b ased
functio ns to ease the implementation of control applica-
tions. These time base functions include three PWM
outputs and four Capture inputs.
Timer1 and Timer2 are two 8-bit incrementing timers,
each with an 8-bit period register (PR1 and PR2, respec-
tively) and sep arate ov erflow interru pt flags. Timer1 and
T ime r2 can operate either as timers (increment on inte r-
nal FOSC/4 clock), or as counters (increment on falling
edge of external clock on pin RB4/TCLK12). They are
also software configurable to operate as a single 16-bit
timer/counter. These timers are also used as the time
base for the PWM (Pulse Wid th M odulation) mo dules.
T imer3 is a 16-b it timer/counte r which uses the TM R3H
and TMR3L registers. Timer3 also has two additional
registers (PR3H/CA1H:PR3L/CA1L) that are config-
urable as a 16-bit period register or a 16-bit capture
register. TMR3 can be software configured to incre-
ment from the internal system clock (FOSC/4), or from
an external signal on the RB5/TCLK3 pin. T imer3 is the
time base for all of the 16-bit captures.
Six other registers comprise the Capture2, Capture3,
and Capture4 registers (CA2H:CA2L, CA3H:CA3L,
and CA4H:CA4L).
Figure 13-1, Figure 13-2 and Figure 13-3 are the con-
trol registers for the operation of Timer1, Timer2 and
Timer3, as well as PWM1, PWM2, PWM3, Capture1,
Capture2, Capture3 and Capture4.
Table 13-1 shows the Timer resource requirements for
these time base functions. Each timer is an open
resource so that multiple functions may operate with it.
TABLE 13-1: TIME-BASE FUNCTION/
RESOURCE REQUIREMENTS
REGISTER 13-1: TCON1 REGISTER (ADDRESS: 16h, BANK 3)
Time Ba se Func tion Timer Resou r ce
PWM1 Timer1
PWM2 Timer1 or Timer2
PWM3 Timer1 or Timer2
Capture1 Timer3
Capture2 Timer3
Capture3 Timer3
Capture4 Timer3
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS
bit 7 bit 0
bit 7-6 CA2ED1:CA2ED0: Capture2 Mode Select bits
00 = Capture on every falling edge
01 = Capture on every rising edge
10 = Capture on every 4th rising edge
11 = Capture on every 16th rising edge
bit 5-4 CA1ED1:CA1ED0: Capture1 Mode Select bits
00 = Capture on every falling edge
01 = Capture on every rising edge
10 = Capture on every 4th rising edge
11 = Capture on every 16th rising edge
bit 3 T16: Timer2:Timer1 Mode Select bit
1 = Timer2 and Timer1 form a 16-bit timer
0 = Timer2 and Timer1 are two 8-bit timers
bit 2 TMR3CS: Timer3 Clock Source Select bit
1 = TMR3 increments off the falling edge of the RB5/TCLK3 pin
0 = TMR3 increments off the inte rnal clock
bit 1 TMR2CS: Timer2 Clock Source Select bit
1 = TMR2 increments of f the fal lin g edge of the RB4/TCLK12 pin
0 = TMR2 increments off the inte rnal clock
bit 0 TMR1CS: Timer1 Clock Source Select bit
1 = TMR1 increments of f the fal lin g edge of the RB4/TCLK12 pin
0 = TMR1 increments off the inte rnal clock
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 102 2000 Microchip Technology Inc.
REGISTER 13-2: TCON2 REGISTER (ADDRESS: 17h, BANK 3)
R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON
bit 7 bit 0
bit 7 CA2OVF: Capture2 Overflow Status bit
This bit indicates that the capture value had not been read from the capture register pair
(CA2H:CA2L) before the next capture event occurred. The capture register retains the oldest
unread capture value (last capture before overflow). Subsequent capture events will not update
the capture register with the TMR3 value until the capture register has been read (both bytes).
1 = Overflow occurred on Capture2 register
0 = No overflow occurred on Capture2 register
bit 6 CA1OVF: Capture1 Overflow Status bit
This bit ind icate s that the capture val ue had no t been rea d from the capture register pair (PR3H/
CA1H:PR3 L/CA1L), before the next capture e vent occurred. The capture regist er retains the old-
est unread capture value (last capture before overflow). Subsequent capture events will not
update the capture register with the TMR3 value until the capture register has been read (both
bytes).
1 = Overflow occurred on Capture1 register
0 = No overflow occurred on Capture1 register
bit 5 PWM2ON: PWM2 On bit
1 =PWM2 is enabled
(The RB3/PWM2 pin ignores the state of the DDRB<3> bit.)
0 =PWM2 is disabled
(The RB3/PWM2 pin uses the state of the DDRB<3> bit for data direction.)
bit 4 PWM1ON: PWM1 On bit
1 =PWM1 is enabled
(The RB2/PWM1 pin ignores the state of the DDRB<2> bit.)
0 =PWM1 is disabled
(The RB2/PWM1 pin uses the state of the DDRB<2> bit for data direction.)
bit 3 CA1/PR3: C A1/PR3 Register Mode Select bit
1 =Enables Capture1
(PR3H/CA1H:PR3L/CA1L is the Capture1 register. Timer3 runs without a period register.)
0 =Enables the Period register
(PR3H/CA1H:PR3L/CA1L is the Period register for Timer3.)
bit 2 TMR3ON: Timer3 On bit
1 = Starts Ti mer3
0 = Stops Timer3
bit 1 TMR2ON: Timer2 On bit
This bit controls the incrementing of the TMR2 register . When TMR2:TMR1 form the 16-bit timer
(T16 is set), TMR2ON must be set. This allows the MSB of the timer to increment.
1 = Starts Timer2 (must be enabled if the T16 bit (TCON1<3>) is set)
0 = Stops Timer2
bit 0 TMR1ON: Timer1 On bit
When T16 is set (in 16-bit Timer mode):
1 = Starts 16-bit TMR2:TMR1
0 = Stops 16-bit TMR2:TMR1
When T16 is clear (in 8-bit Timer mode:
1 = Starts 8-bit Timer1
0 = Stops 8- bit Timer1
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 103
PIC17C7XX
REGISTER 13-3: TCON3 REGISTER (ADDRESS: 16h, BANK 7)
U-0 R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON
bit 7 bit 0
bit 7 Unimplemented: Read as 0
bit 6 CA4OVF: Capture4 Overflow Status bit
This bit indicates that the capture value had not been read from the capture register pair
(CA4H:CA4L) before the next capture event occurred. The capture register retains the oldest
unread capture value (last capture before overflow). Subsequent capture events will not update
the capture register with the TMR3 value until the capture register has been read (both bytes).
1 = Overflow occurred on Capture4 registers
0 = No overflow occurred on Capture4 registers
bit 5 CA3OVF: Capture3 Overflow Status bit
This bit indicates that the capture value had not been read from the capture register pair
(CA3H:CA3L) before the next capture event occurred. The capture register retains the oldest
unread capture value (last capture before overflow). Subsequent capture events will not update
the capture register with the TMR3 value until the capture register has been read (both bytes).
1 = Overflow occurred on Capture3 registers
0 = No overflow occurred on Capture3 registers
bit 4-3 CA4ED1:CA4ED0: Capture4 Mode Select bits
00 = Capture on every falling edge
01 = Capture on every rising edge
10 = Capture on every 4th rising edge
11 = Capture on every 16th rising edge
bit 2-1 CA3ED1:CA3ED0: Capture3 Mode Select bits
00 = Capture on every falling edge
01 = Capture on every rising edge
10 = Capture on every 4th rising edge
11 = Capture on every 16th rising edge
bit 0 PWM3ON: PWM3 On bit
1 = PWM3 is enabled (the RG5/PWM3 pin ignores the state of the DDRG<5> bit)
0 = PWM3 is disabled (the RG5/PWM3 pin uses the state of the DDRG<5> bit for data direction)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 104 2000 Microchip Technology Inc.
13.1 Timer1 and Timer2
13.1.1 TIMER1, TIMER2 IN 8-BIT MODE
Both Timer1 and Timer2 will operate in 8-bit mode
when the T16 bit is clear . These two timers can be inde-
pendently configured to increment from the internal
instr uction cycle c lock (TCY), or from an external clock
source on the RB4/TC LK12 pin. The timer clock so urce
is configured by the TMRxCS bit (x = 1 for Timer1,
or = 2 for Timer2). When TMRxCS is clear, the clock
source is internal and increments once every instruc-
tion cycle (FOSC/4). When TMRxCS is set, the clock
source is the RB4/TCLK12 pin and the counters will
increment on every falling edge of the RB4/TCLK12
pin.
The tim er incremen ts from 00h until it e quals the Period
register (PRx). It then resets to 00h at the next incre-
ment cycle. The timer interrupt flag is set when the
timer is reset. TMR1 and TMR2 have individual inter-
rupt flag b its . The TM R1 interru pt flag bit is l atched in to
TMR1IF and the TMR2 interrupt flag bit is latched into
TMR2IF.
Each timer also has a corresponding interrupt enable
bit (TMRxIE). The timer interrupt can be enabled/
disabled by setting/clearing this bit. For peripheral
interrupts to be enabled, the Peripheral Interrupt
Enable bit must be set (PEIE = 1) and global interrupt
must be enabled (GLINTD = 0).
The timers can be turned on and off under software
control. When the ti mer on contro l bit (TMRxON) is set,
the timer increments from the clock source. When
TMRxON is cleared, the timer is turned off and cannot
cause the timer interrupt flag to be set.
13.1.1.1 External Clock Input for Timer1 and
Timer2
When TMRxCS is set, the clock source is the RB4/
TCLK12 pin, and the counter will increment on every
falling edge on the RB4/TCLK12 pin. The TCLK12
input is synchronized with internal phase clocks. This
causes a del ay from the tim e a fal ling e dge ap pears o n
TCLK12 to the time TMR1 or TMR2 is actually incre-
mented. For the external clock input timing require-
ments, see the Elect r ic al Specific ati on se cti on.
FIGURE 13-1: TIMER1 AND TIMER2 IN TWO 8-BIT TIMER/COUNTER MODE
FOSC/4
RB4/TCLK12
TMR1ON
(TCON2<0>)
TMR1CS
(TCON1<0>)
TMR1
PR1
RESET
Equal
Set TMR1IF
(PIR1<4>)
0
1
Comparator<8>Comparator x8
FOSC/4
TMR2ON
(TCON2<1>)
TMR2CS
(TCON1<1>)
TMR2
PR2
RESET
Equal
Set TMR2IF
(PIR1<5>)
1
0
Comparator<8>Comparator x8
2000 Microchip Technology Inc. DS30289B-page 105
PIC17C7XX
13.1.2 T IMER1 AND TIMER2 IN 16-BIT
MODE
To select 16-bit mode, set the T16 bit. In this mode,
TMR2 and TMR1 are concatenated to form a 16-bit
timer (TMR2:TMR1). The 16-bit timer increments until
it matc hes the 16 -bit period register (PR2:P R1). On th e
followin g timer clock , the ti mer va lue is reset to 0h, an d
the TMR1IF bit is set.
When selectin g the clock source for the 16-bit ti mer , the
TMR1CS bit controls the entire 16-bit timer and
TMR2CS is a dont care, however, ensure that
TMR2ON is set (allows TMR2 to increment). When
TMR1CS is clear, the timer increments once every
instruction cycle (FOSC/4). When TMR1CS is set, the
timer increments on every falling edge of the RB4/
TCLK12 pin. For the 16-bit timer to increment, both
TMR1ON and TMR2ON bits must be set (Table 13-2).
TABLE 13-2: TURNING ON 16-BIT TIMER
13.1.2.1 External Clock Input for
TMR2:TMR1
When TMR1CS is set, the 16-bit TMR2:TMR1 incre-
ments on the falling edge of clock input TCLK12. The
input on the RB4 /TC LK1 2 p in i s sam ple d and syn ch ro-
nized by the internal phase clocks twice every instruc-
tion cycle. This causes a delay from the time a falling
edge appears on RB4/TCLK12 to the time
TMR2 :TMR1 is actually increme nted. F or the exte rnal
clock input timing requirements, see the Electrical
Specification section.
FIGURE 13-2: TMR2 AND TMR1 IN 16-BIT TIMER/COUNTER MODE
T16 TMR2ON TMR1ON Result
11 116-bit timer
(TMR2:TMR1) ON
10 1Only TMR1 increments
1x 016-bit timer OFF
01 1Timers in 8-bit mode
RB4/TCLK12 FOSC/4 TMR1ON
(TCON2<0>)
TMR1CS
(TCON1<0>) TMR1 x 8
PR1 x 8
RESET
Equal
Set Int errupt TMR1IF
(PIR1<4>)
1
0
Comparator<8>
Comparator x16
TMR2 x 8
PR2 x 8
MSB LSB
PIC17C7XX
DS30289B-page 106 2000 Microchip Technology Inc.
TABLE 13-3: SUMMARY OF TIMER1, TIMER2 AND TIMER3 REGISTERS
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 3 TCON1 CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS 0000 0000 0000 0000
17h, Bank 3 TCON2 CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
16h, Bank 7 TCON3 CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
10h, Bank 2 TMR1 Timer1s Register xxxx xxxx uuuu uuuu
11h, B ank 2 TM R2 Timer2s Register xxxx xxxx uuuu uuuu
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
07h, Unba nked INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
06h, Unbanked CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
14h, Bank 2 PR1 Timer1 Period Register xxxx xxxx uuuu uuuu
15h, Bank 2 PR2 Timer2 Period Register xxxx xxxx uuuu uuuu
10h, Bank 3 PW1DCL DC1 DC0 xx-- ---- uu-- ----
11h, Bank 3 P W2DCL DC1 DC0 TM2PW2 xx0- ---- uu0- ----
10h, Bank 7 PW3DCL DC1 DC0 TM2PW3 xx0- ---- uu0- ----
12h, Bank 3 PW1DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
13h, Bank 3 PW2DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
11h, Bank 7 PW3DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0', q = value depends on condition.
Shaded cells are not used by Timer1 or Timer2.
2000 Microchip Technology Inc. DS30289B-page 107
PIC17C7XX
13.1.3 USING PULSE WIDTH
MODULATION (PWM) OUTPUTS
WITH TIMER1 AND TIMER2
Three high speed pulse width modulation (PWM) out-
puts are provided. The PWM1 output uses Timer1 as
its time base, while PWM2 and PWM3 may indepen-
dently be software configured to use either Timer1 or
Timer2 as the time base. The PWM outputs are on the
RB2/PWM1, RB3/P WM2 and RG5/PWM3 pins.
Each PWM output has a maximum resolution of 10-
bits. At 10-bit resolution, the PWM output frequency is
32.2 kHz (@ 32 MHz clock) and at 8-bit resolution the
PWM out put freq ue ncy is 12 8.9 kHz . The du ty cy cl e of
the output can vary from 0% to 100%.
Figure 13-3 shows a simplified block diagram of a
PWM module.
The duty cycle registers are double buffered for glitch
free operation. Figure 13-4 shows how a glitch could
occur if the duty cycle registers were not double
buffered.
The user needs to set the PWM1ON bit (TCON2<4>)
to enable the PWM1 output. When the PWM1ON bit is
set, the RB2/PWM1 pin is configured as PWM1 output
and forced as an output, irrespective of the data direc-
tion bit (DDRB<2>). When the PWM1ON bit is clear,
the pin behaves as a port pin and its direction is con-
trolled by its data direction bit (DDRB<2>). Similarly,
the PWM2ON (TCON2<5>) bit controls the configura-
tion of the RB3/PWM2 pin and the PWM3ON
(TCON3<0>) bit controls the configuration of the RG5/
PWM3 pin.
FIGURE 13-3: SIMPLIFIED PWM BLOCK
DIAGRAM
FIGURE 13-4: PWM OUTPUT (NOT BUFFERED)
PWxDCH
Duty Cycle Registers PWxDCL<7:6>
Clear Timer,
PWMx pin and
Latch D.C.
(Slave)
Comparator
TMRx
Comparator
PRy
(Note 1)
R
S
Q
PWMxON
PWMx
Note 1: 8-bit timer is concatenated with 2-bit internal
Q clock or 2 bits of the prescaler to create
Read
Write
10-bit time base.
010203040 0
PWM
Output
Timer
Interrupt Write New
PWM Duty Cycle Value Timer Interrupt
New PWM Duty Cycle Value
Transferred to Slave
The dotted line shows PWM output if duty cycle registers were not double buffered.
If the new duty cycle is written after the timer has passed that value, then the PWM does
not reset at all during the current cycle, causing a glitch.
In this example, PWM period = 50. Old duty cycle is 30. New duty cycle value is 10.
10 20 30 40 0
Note:
PIC17C7XX
DS30289B-page 108 2000 Microchip Technology Inc.
13.1.3.1 PWM Periods
The period of the PWM1 output is determined by
Timer1 and its period register (PR1). The period of the
PWM2 and PWM3 output s can be in dividual ly softwa re
configured to use either Timer1 or Timer2 as the time-
base. For PWM 2, when TM2PW 2 bit (PW2 DCL<5> ) is
clear, the time base is determined by TMR1 and PR1
and whe n TM2PW2 is set, the ti me bas e is de termine d
by Timer2 and PR2. For PWM3, when TM2PW3 bit
(PW3DCL<5 >) is c lea r, the tim e b as e is de term in ed b y
TMR1 and PR1, and when TM2PW3 is set, the time
base is determined by Timer2 and PR2.
Running two different PWM outputs on two different
timers allows different PWM periods. Running all
PWMs from Tim er1 allows the bes t use of resources b y
freeing Timer2 t o operate a s an 8 - bi t ti me r. Timer1 and
Timer2 cannot be used as a 16-bit timer if any PWM is
being used.
The PWM periods can be calculated as follows:
period of PWM1 = [(PR1) + 1] x 4TOSC
period of PWM2 = [(PR1) + 1] x 4TOSC or
[(PR2) + 1] x 4TOSC
period of PWM3 = [(PR1) + 1] x 4TOSC or
[(PR2) + 1] x 4TOSC
The duty cycle of PWMx is determined by the 10-bit
value DCx<9:0>. The upper 8-bits are from register
PWxDCH and the lower 2-bits are f rom PWxDCL<7:6>
(PWxDCH:PWxDCL<7:6>). Table 13-4 shows the
maximum PWM frequency (FPWM), given the value in
the period register.
The number of bits of resolution that the PWM can
achieve depends on the operation frequency of the
device as well as the PWM frequency (FPWM).
Maximum PWM resolution (bits) for a given PWM
frequency:
where: FPWM = 1 / period of PWM
The PWMx duty cycle is as follows:
PWMx Duty Cycle = (DCx) x TOSC
where DCx represents the 10-bit value from
PWxDCH:PWxDCL.
If DCx = 0, then the duty cycle is zero. If
PRx = PWxDCH, then the PWM output will be low for
one to four Q-clocks (depending on the state of the
PWxDCL<7:6> bits). For a duty cycle to be 100%, the
PWxDCH value must be greater then the PRx val ue.
The duty cycle regis ters for both PWM out puts a re dou-
ble buffered. When the user writes to these registers,
they are stored in master latches. When TMR1 (or
TMR2) overflows and a new PWM period begins, the
master la tch values are transferred to the slave latc hes
and the PWMx pin is forced high.
The user should also avoid any "read-modify-write"
operations on the duty cycle registers, such as:
ADDWF PW1DCH. This may cause duty cycle outputs
that are unpredictable.
TABLE 13-4: PW M FREQUENCY vs.
RESOLUTION AT 33 MHz
13.1.3.2 PWM INTERRUPTS
The PWM modules make use of the TMR1 and/or
TMR2 interrupts. A timer interrupt is generated when
TMR1 or TMR2 equals its period register and on the
following increment is cleared to zero. This interrupt
also marks the beginning of a PWM cycle. The user
can write new duty cycle values before the timer
rollove r . The TMR1 interrup t is latched into th e TMR1IF
bit and the TMR2 interrupt is latched into the TMR2IF
bit. These flags must be cleared in software.
log (FPWM
log (2)
FOSC )bits=
Note: For PW1DCH, PW1DCL, PW2DCH,
PW2DCL, PW3DCH and PW3DCL regis-
ters, a w rite opera tion wri tes to the "master
latches", while a read operation reads the
"slave latches". As a result, the user may
not read back what was just written to the
duty cycle registers (until transferred to
slave latch).
PWM
Frequency Frequency (kHz)
32.2 64.5 90.66 128.9 515.6
PRx Value 0xFF 0x7F 0x5A 0x3F 0x0F
High
Resolution 10-bit 9-bit 8.5-bit 8-bit 6-bit
Standard
Resolution 8-bit 7-bit 6.5-bit 6-bit 4-bit
2000 Microchip Technology Inc. DS30289B-page 109
PIC17C7XX
13.1.3.3 External Clock Source
The PWMs will operate, regardless of the clock source
of the timer. The use of an external clock has ramifica-
tions that must be understood. Because the external
TCLK12 input is synchroni zed internally (sampled once
per instruction cycle), the time TCLK12 changes to the
time the timer inc rement s, will vary by as m uch as 1TCY
(one instruction cycle). This will cause jitter in the duty
cycle as well as the period of the PWM output.
This j itter will b e ±1TCY, unless the external clock is syn-
chronized with the processor clock. Use of one of the
PWM outp ut s as th e cloc k so urce to the TCLK1 2 inpu t,
will supply a synchronized clock.
In general, when using an external clock source for
PWM, its frequency should be much less than the
device frequency (FOSC).
13.1.3.4 Maximum Resolution/Frequency for
Extern al Cloc k Input
The use of an external clock for the PWM time base
(Timer1 or Timer2) limits the PWM output to a maxi-
mum re sol uti on of 8-b it s . Th e PWxD CL <7:6 > b it s m us t
be kept cleared. Use of any other value will distort the
PWM output. All resolutions are supported when inter-
nal clock mode is selected. The maximum attainable
frequency is also lower. This is a result of the timing
requirem ents of an exte rnal c lock input f or a tim er (se e
the Electrical Specification section). The maximum
PWM frequency, when the timers clock source is the
RB4/TCLK12 pin, is shown in Table 13-4 (Standard
Resolution mode).
TABLE 13-5: REGISTERS/BITS ASSOCIATED WITH PWM
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR
MCLR,
WDT
16h, Bank 3 TCO N1 CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS 0000 0000 0000 0000
17h, Bank 3 TCO N2 CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
16h, Bank 7 TCO N3 CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
10h, Bank 2 TMR 1 Timer 1s Register xxxx xxxx uuuu uuuu
11h, Bank 2 TMR2 Timer2s Register xxxx xxxx uuuu uuuu
16h, Bank 1 PIR 1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
07h, Unba nke d INTSTA PE IF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
06h, Unba nke d CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
14h, Bank 2 PR1 Timer1 Period Regi s ter xxxx xxxx uuuu uuuu
15h, Bank 2 PR2 Timer2 Period Regi s ter xxxx xxxx uuuu uuuu
10h, Bank 3 PW1DCL DC1 DC0 xx-- ---- uu-- ----
11h, Bank 3 PW2DCL DC1 DC0 TM2PW2 xx0- ---- uu0- ----
10h, Bank 7 PW3DCL DC1 DC0 TM2PW3 xx0- ---- uu0- ----
12h, Bank 3 PW1DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
13h, Bank 3 PW2DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
11h, Bank 7 PW3DCH DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0', q = value depe nds on conditions .
Shaded cells are not used by PWM Module.
PIC17C7XX
DS30289B-page 110 2000 Microchip Technology Inc.
13.2 Timer3
Timer3 is a 16-bit timer consisting of the TMR3H and
TMR3L registers. TMR3H is the high byte of the timer
and TMR3L is the low byte. This timer has an associ-
ated 16-bit period register (PR3H/CA1H:PR3L/CA1L).
This pe rio d re gis ter can be soft wa re c on fig ured to be a
another 16-bit capture register.
When the TMR3CS bit (TCON1<2>) is clear, the timer
increments every instruction cycle (FOSC/4). When
TMR3CS i s set, the counter increment s on every fallin g
edge of the RB5/TCLK3 pin. In either mode, the
TMR3ON bi t mu st b e se t for t he ti mer/count er to incre-
ment. When TMR3ON is clear, the timer will not incre-
ment or set flag bit TMR3IF.
Timer3 has two modes of operation, depending on the
CA1/PR3 bit (TCON2<3>). These modes are:
Three capture and one period register mode
Four captu re register mode
The PIC17C7XX has up to four 16-bit capture registers
that capt ure th e 16-bit val ue of TMR3 when e vents are
detected on capture pins. There are four capture pins
(RB0/CAP1, RB1/CAP2, RG4/CAP3, and RE3/CAP4),
one for ea ch captu re regis ter pai r . The c apture pin s are
multiplexed with the I/O pins. An event can be:
A rising edge
A falling edge
Every 4th rising edge
Every 16th rising edge
Each 16-b it c apt ure re gi ster has an int errup t flag asso-
ciated with it. The flag is set when a capture is made.
The cap ture m odules are t ruly part of the Timer3 blo ck.
Figure 13-5 and Figure 13-6 show the block diagrams
for the two modes of operation.
13.2.1 THREE CAPTURE AND ONE
PERIOD REGISTER MODE
In this mode, registers PR3H/CA1H and PR3L/CA1L
constitute a 16-bit period register. A block diagram is
shown in Figure 13-5. The timer increments until it
equals the period register and then resets to 0000h on
the next timer clock. TMR3 Interrupt Flag bit (TMR3IF)
is set at this point. This interrupt can be disabled by
clearing the TMR3 Interrupt Enable bit (TMR3IE).
TMR3IF must be cleared in software.
FIGURE 13-5: TIMER3 WITH THREE CAPTURE AND ONE PERIOD REGISTER BLOCK DIAGRAM
PR3H/CA1H
TMR3H
Comparator<8>
FOSC/4
TMR3ON
Reset
Equal
0
1
Comparator x16
RB5/TCLK3
Set TMR3IF
TMR3CS PR3L/CA1L
TMR3L
CA2H CA2L
RB1/CAP2
Edge select,
Prescaler select
2
Set CA2IF
Capture2
CA2ED1: CA2ED0
(TCON1<7:6>)
(TCON2<2>)
(TCON1<2>)
(PIR1<3>)
(PIR1<6>)
Enable
CA3H CA3L
RG4/CAP3
Edge select,
Prescaler selec t
2
Set CA3IF
Capture3
CA3ED1: CA3ED0
(TCON3<2:1>) (PIR2<2>)
Enable
CA4H CA4L
RE3/CAP4
Edge select,
Prescaler selec t
2
Set CA4IF
Capture4
CA4ED1: CA4ED0
(TCON3<4:3>) (PIR2<3>)
Enable
2000 Microchip Technology Inc. DS30289B-page 111
PIC17C7XX
This mode (3 Capt ure, 1 Period) is selected if control b it
CA1/PR3 is clear. In this mode, the Capture1 register,
consisting of high byte (PR3H/CA1H) and low byte
(PR3L/CA1L ), is confi gured as the period con trol regis-
ter for TM R3. Capture1 is d isabled in this mode and th e
corresponding interrupt bit, CA1IF, is never set. TMR3
increments until it equals the value in the period regis-
ter and then reset s to 0000h on the nex t time r clock.
All other Captures are active in this mode.
13.2.1.1 Capture Operation
The CAx ED1 an d CAxED0 bit s determ ine the event on
which capture will occur. The possible events are:
Capture on every falling edge
Capture on every rising edge
Capture every 4th rising edge
Capture every 16th rising edge
When a c apture t akes pla ce, an in terrupt flag is latche d
into the CAxIF b it. This int errupt can be enabl ed by s et-
ting the correspon din g m as k bit C Ax IE. T he Peripheral
Interrupt Enable bit (PEIE) must be set and the Global
Interrupt Disable bit (GLINTD) must be cleared for the
interrupt to be acknowledged. The CAxIF interrupt flag
bit is cleared in software.
When the capture pr escale sele ct is ch anged, the pre s-
caler is not reset and an event may be generated.
Therefore, the first capture after such a change will be
ambiguous. However, it sets the time-base for the next
capture. The prescaler is reset upon chip RESET.
The capture pin, CAPx, is a multiplexed pin. When
used as a port pin, the capture is not disabled. How-
ever, the user can simply disable the Capture interrupt
by clear ing CAxIE. If the CAPx pin is used as an output
pin, the user can activate a capture by writing to the
port pin. This may be useful du ring devel opment p hase
to emulate a capture interrupt.
The input on the capture pin CAPx is synchronized
internal ly to intern al phase c locks. Th is imposes certain
restrictions on the input waveform (see the Electrical
Specification section for timing).
The capture overflow status flag bit is double buffered.
The master bit is set if one captured word is already
residing in the Capture register (CAxH:CAxL) and
another event has occurred on the CAPx pin. The
new event will not transfer the TMR3 value to the cap-
ture register, protecting the previous unread capture
value . W hen the use r re ads bot h the hi gh and the low
bytes (in an y orde r) of the Ca ptu re regi ste r, the master
overflow bit is transferred to the slave overflow bit
(CAxOVF) and then the master bit is reset. The user
can then read TCONx to determine the value of CAx-
OVF.
The recommended sequence to read capture registers
and capture overflo w flag bit s is shown in Example 13-1.
PIC17C7XX
DS30289B-page 112 2000 Microchip Technology Inc.
13.2.2 FOUR CAPTURE MODE
This mode is selected by setting bit CA1/PR3. A block
diagram is shown in Figure 13-6. In this mode, TMR3
runs without a period register and increments from
0000h to FFFFh and rolls over to 0000h. The TMR3
interrupt Flag (TMR3IF) is set on this rollover. The
TMR3IF bit must be cleared in software.
Registers PR3H/CA1H and PR3L/CA1L make a 16-bit
capture register (Capture1). It captures events on pin
RB0/CAP1. Capture mode is configured by the
CA1ED1 and CA1ED0 bits. Capture1 Interrupt Flag bit
(CA1IF) is set upon detection of the capture event. The
corresponding interrupt mask bit is CA1IE. The
Capture1 Overflow Status bit is CA1OVF.
All the captures operate in the same manner. Refer to
Section 13.2.1 for the operation of capture.
FIGURE 13-6: TIMER3 WITH FOUR CAPTURES BLOCK DIAGRAM
RB0/CAP1
Edge Select,
Prescaler Select
PR3H/CA1H PR3L/CA1L
RB1/CAP2
RG4/CAP3
Edge Select,
Prescaler Select
2
Set CA1IF
(PIR1<2>)
Capture1 Enable
TMR3ON
TMR3CS
(TCON1<2>)
0
1
Set TMR3IF
(PIR1<6>)
Edge Select,
Prescaler Sele ct
CA2H CA2L
Set CA2IF
(PIR1<3>)
CA3H CA3L
Set CA3IF
(PIR2<2>)
CA1ED1, CA1ED0
(TCON1<5:4>)
(TCON2<2>)
FOSC/4
RB5/TCLK3
Capture2 Enable
Capture3 Enable
CA2ED1, CA2ED0
(TCON1<7:6>)
2
CA3ED1: CA3ED0
(TCON3<2:1>)
TMR3H TMR3L
2
RE3/CAP4
Edge Select,
Prescaler Select
2CA4H CA4L
Set CA4IF
(PIR2<3>)
Capture4 Enable
CA4ED1: CA4ED0
(TCON3<4:3>)
2000 Microchip Technology Inc. DS30289B-page 113
PIC17C7XX
13.2.3 READING THE CAPTURE
REGISTERS
The Capture overflow status flag bits are double buff-
ered. The master bit is set if one captured word is
already residing in the Capture register and another
event has occurred on the CAPx pin. The new event
will not tran sfer th e TMR 3 va lue to the c apture registe r,
protecting the previous unread capture value. When
the user reads both the high and the low bytes (in any
order) of the Capt ure register , the m aster overflow bit i s
transferred to the slave overflow bit (CAxOVF) and
then the master bit is reset. The user can then read
TCONx to determine the value of CAxOVF.
An examp le of a n instr uct ion se quenc e to read captu re
registers and capture overflow flag bits is shown in
Example 13-1. Depending on the capture source, dif-
ferent registers will need to be read.
EXAMPLE 13-1: SEQUENCE TO READ CAPTURE REGISTERS
TABLE 13-6: REGISTERS ASSOCIATED WITH CAPTURE
MOVLB 3 ; Select Bank 3
MOVPF CA2L, LO_BYTE ; Read Capture2 low byte, store in LO_BYTE
MOVPF CA2H, HI_BYTE ; Read Capture2 high byte, store in HI_BYTE
MOVPF TCON2, STAT_VAL ; Read TCON2 into file STAT_VAL
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 3 TCON1 CA2ED1 CA2ED0 CA1ED1 CA1ED0 T16 TMR3CS TMR2CS TMR1CS 0000 0000 0000 0000
17h, Bank 3 TCON2 CA2OVF CA1O VF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
16h, Bank 7 TCON3 CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
12h, Bank 2 TMR3L Holding Register for the Low Byte of the 16-bit TMR3 Register xxxx xxxx uuuu uuuu
13h, Bank 2 TMR3H Holding Register for the High Byte of the 16-bit TM R3 Regist er xxxx xxxx uuuu uuuu
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, B ank 4 PIE 2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
07h, Unba nked INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
06h, Unbanked CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
16h, Bank 2 PR3L/CA1L Timer3 Period Register, Low Byte/Capture1 Register, Low Byte xxxx xxxx uuuu uuuu
17h, Bank 2 PR3H/CA1H Timer3 Period Register, High Byte/Cap ture1 Re gist er, High Byte xxxx xxxx uuuu uuuu
14h, Bank 3 CA2L Capture2 Low Byte xxxx xxxx uuuu uuuu
15h, Bank 3 CA2H Capture2 High Byte xxxx xxxx uuuu uuuu
12h, Bank 7 CA3L Capture3 Low Byte xxxx xxxx uuuu uuuu
13h, Bank 7 CA3H Capture3 High Byte xxxx xxxx uuuu uuuu
14h, Bank 7 CA4L Capture4 Low Byte xxxx xxxx uuuu uuuu
15h, Bank 7 CA4H Capture4 High Byte xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchange d, - = unimplemented, read as '0', q = value depends on condition.
Shaded cells are not used by Capture.
PIC17C7XX
DS30289B-page 114 2000 Microchip Technology Inc.
13.2.4 EXTERNAL CLOCK INPUT FOR
TIMER3
When TM R 3 CS is s et , th e 1 6 - bit T MR 3 i nc rem en ts on
the falling edge of clock input TCLK3. The input on the
RB5/TCLK3 pin is sampled and synchronized by the
internal phase clocks, twice every instruction cycle.
This causes a delay from the time a falling edge
appears on TCLK3 to the time TMR3 is actually incre-
mented. For the external clock input timing require-
ments, see the Electrical Specification section.
Figure 13-7 shows the timing diagram when operating
from an external clock.
13.2.5 READING/WRITING TIMER3
Since Timer3 is a 16-bit timer and only 8-bits at a time
can be read or written, care should be taken when
reading or writing while the timer is running. The best
method is to stop the timer, perform any read or write
operation and then restart Timer3 (using the TMR3ON
bit). However, if it is necessary to keep Timer3 free-
running, care must be taken. For writing to the 16-bit
TMR3, Example 13-2 may be used. For rea ding the 16-
bit TMR3, Example 13-3 may be used . Interrupts must
be d isabled during thi s rout ine.
EXAMPLE 13-2: WRITING TO TMR3
EXAMPLE 13-3: READING FROM TMR3
FIGURE 13-7: TIMER1, TIMER2 AND TIMER3 OPERATION (IN COUNTER MODE)
BSF CPUSTA, GLINTD ; Disable interrupts
MOVFP RAM_L, TMR3L ;
MOVFP RAM_H, TMR3H ;
BCF CPUSTA, GLINTD ; Done, enable interrupts
MOVPF TMR3L, TMPLO ; read low TMR3
MOVPF TMR3H, TMPHI ; read high TMR3
MOVFP TMPLO, WREG ; tmplo −> wreg
CPFSLT TMR3L ; TMR3L < wreg?
RETURN ; no then return
MOVPF TMR3L, TMPLO ; read low TMR3
MOVPF TMR3H, TMPHI ; read high TMR3
RETURN ; return
Q1Q2Q3Q4Q1Q2Q3Q4Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3Q4Q1Q2Q3Q4
Instruction
Executed
MOVWF MOVFP
TMRx,WTMRx MOVFP
TMRx,W
Write to TMRx Read TMRx Read TMRx
34h 35h A8h A9h 00h
A9h’’A9h
TCLK12
TMR1, TMR2, or TMR3
PR1, PR2, or PR3H:PR3L
WR_TMR
RD_TMR
TMRxIF
Note 1: TCLK12 is sampled in Q2 and Q4.
2: indicates a sampling point.
3: The latency from TCLK12 to timer increment is between 2Tosc and 6Tosc.
or TCLK3
2000 Microchip Technology Inc. DS30289B-page 115
PIC17C7XX
FIGURE 13-8: TIMER1, TIMER2 AND TIMER3 OPERATION (IN TIMER MODE)
Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3 Q4 Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2Q3Q4 Q1Q2 Q3Q4 Q1Q2 Q3Q4
AD15:AD0
ALE
Instruction
Fetched
TMR1
PR1
TMR1ON
WR_TMR1
WR_TCON2
TMR1IF
RD_TMR1 TMR1
Reads 03h TMR1
Reads 04h
MOVWF
TMR1
Write TMR1
MOVF
TMR1, W
Read TMR1
MOVF
TMR1, W
Read TMR1
BSF
TCON2, 0
Stop TMR1
BCF
TCON2, 0
Start TMR1
MOVLB 3 NOP NOP NOP NOP NOP
04h 05h 03h 04h 05h 06h 07h 08h 00h
PIC17C7XX
DS30289B-page 116 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 117
PIC17C7XX
14.0 UNIVERSAL SYNCHRONOUS
ASYNCHRONOUS RECEIVER
TRANSMITTER (USART)
MODULES
Each USART module is a serial I/O module. There are
two USART modules that are available on the
PIC17C7XX. They are specified as USART1 and
USAR T2. The de scription of the operation of these mod-
ules is generic in regard to the register names and pin
names used. Table 14-1 shows the generic names that
are used in the description of operation and the actual
names for both USART1 and USART2. Since the control
bits in each register have the same function, their names
are the same (there is no need to dif ferentiate).
The Transmit Status and Control Register (TXSTA) is
shown in Figure 14-1, while the Receive Status and
Control Register (RCSTA) is shown in Figure 14-2.
TABLE 14-1: USART MODULE GENERIC
NAMES
REGISTER 14-1: TXSTA1 REGISTER (ADDRESS: 15h, BANK 0)
TXSTA2 REGISTER (ADDRESS: 15h, BANK 4)
Generic Name USART1 Name USART2 Name
Registers
RCSTA RCSTA1 RCSTA2
TXSTA TXSTA1 TXSTA2
SPBRG SPBRG1 SPBRG2
RCREG RCREG1 RCREG2
TXREG TXREG1 TXREG2
Interrupt Contro l Bit s
RCIE RC1IE RC2IE
RCIF RC1IF RC2IF
TXIE TX1IE TX2IE
TXIF TX1IF TX2IF
Pins
RX/DT RA4/RX1/DT1 RG6/RX2/DT2
TX/CK RA5/TX1/CK1 RG7/TX2/CK2
R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 R-1 R/W-x
CSRC TX9 TXEN SYNC TRMT TX9D
bit 7 bit 0
bit 7 CSRC: Clock Source Select bit
Synchronous mode:
1 = Master mode (clock generated internally from BRG)
0 = Slave mode (clock from external source)
Asynchronous mode:
Dont care
bit 6 TX9: 9-bit Transmit Select bit
1 = Selects 9-b it transmission
0 = Selects 8-b it transmission
bit 5 TXEN: Transmit Enable bit
1 = Transmit enabled
0 = Transmit disabled
SREN/CREN overrides TXEN in SYNC mode
bit 4 SYNC: USART Mode Select bit
(Synchronous/Asynchronous)
1 = Synchronous mode
0 = Asynchr ono us mo de
bit 3-2 Unimplemented: Read as '0'
bit 1 TRMT: Transmit Shift Register (TSR) Empty bit
1 = TSR empty
0 = TSR full
bit 0 TX9D: 9th bit of Transmit Data (can be used to calculate the parity in software)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is se t 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 118 2000 Microchip Technology Inc.
The USART can be configured as a full duplex asyn-
chronous system that can communicate with peripheral
devices such as CRT terminals and personal comput-
ers, or it can be configured as a half duplex synchro-
nous system that can communicate with peripheral
devices such as A/D or D/A integrated circuits, Serial
EEPROMs etc. The USART can be configured in the
following modes:
Asynchronous (full duplex)
Synchronous - Master (half duplex)
Synchronous - Slave (half duplex)
The SPEN (RCSTA<7>) bit has to be set in order to
configure the I/O pins as the Serial Communication
Interface (USART).
The USAR T module w ill control the direction of the RX/
DT and TX/CK pins, depending on the states of the
USART configuration bits in the RCSTA and TXSTA
registers. The bits that control I/O direction are:
SPEN
TXEN
SREN
CREN
CSRC
REGISTER 14-2: RCSTA1 REGISTER (ADDRESS: 13h, BANK 0)
RCSTA2 REGISTER (ADDRESS: 13h, BANK 4)
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R-0 R-0 R-x
SPEN RX9 SREN CREN FERR OERR RX9D
bit 7 bit 0
bit 7 SPEN: Serial Port Enable bit
1 = Configures TX/CK and RX/DT pins as serial port pins
0 = Serial port disabled
bit 6 RX9: 9-bit Receive Select bit
1 = Selects 9-bit reception
0 = Selects 8-bit reception
bit 5 SREN: Single Receive Enable bit
This bit enables the reception of a single byte. After receiving the byte, this bit is automatically
cleared.
Synchronous mode:
1 = Enable reception
0 = Disable recepti on
Note: This bit is ignored in synchronous slave reception.
Asynchronous mode:
Dont care
bit 4 CREN: Continuous Rec eive Enable bit
This bit enables the continuous reception of serial data.
Asynchronous mode:
1 = Enable continuous reception
0 = Disables continuous reception
Synchronous mode:
1 = Enables contin uo us rec epti on until CREN is cleared (CREN overrides SREN)
0 = Disables continuous reception
bit 3 Unimplemented: Read as '0'
bit 2 FERR: Framing Error bit
1 = Framing error (updated by reading RCREG)
0 = No framing error
bit 1 bit OERR: Overrun Error bit
1 = Overrun (cleared by clearing CR EN)
0 = No overrun error
bit 0 RX9D: 9th bit of Receive Data (can be the software calculated parity bit)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit i s set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 119
PIC17C7XX
FIGURE 14-1: USART TRANSMIT
FIGURE 14-2: USART RECEIVE
CK/TX
DT
Sync/Async TSR
Start 0 1 7 8 Stop
• • •
÷ 16
÷ 4BRG
01 7
• • • 8Bit Count
TXIE
Interrupt
TXEN/
Write to TXREG
Clock
Sync/Async
Sync/Async
TXSTA<0>
Sync
Master/Slave
Data Bus
Load
TXREG
CK
RX 0178Stop • • •
÷ 16
÷ 4
BRG
Bit Count
Clock
Buffer
Logic
Buffer
Logic
SPEN
OSC
START
017RX9D • • • 017RX9D • • •
FERR
FERR
Majority
Detect Data MSb LSb
RSR
RCREG
Async/Sync
Sync/Async
Master/Slave
Sync
Enable
FIFO
Logic
Clk
FIFO
RCIE
Interrupt
RX9
Data Bus
SREN/
CREN/
Start_Bit
Async/Sync
Detect
PIC17C7XX
DS30289B-page 120 2000 Microchip Technology Inc.
14.1 USART Baud Rate Generator
(BRG)
The BRG supports both the Asynchronous and Syn-
chronous modes of the USART. It is a dedicated 8-bit
baud rate generator. The SPBRG register controls the
period of a free running 8-bit timer. Table 14-2 shows
the formula for computation of the baud rate for differ-
ent USAR T modes. Thes e only apply whe n the USART
is in Synchronous Master mode (internal clock) and
Asynchronous mode.
Given the desired b aud rate an d Fosc, the n earest inte-
ger value between 0 and 255 can be calculated using
the formula below. The error in baud rate can then be
determined.
TABLE 14-2: BAUD RATE FORMULA
Example 14-1 shows the calculation of the baud rate
error for the following conditions:
FOSC = 16 MHz
Desired Baud Rate = 9600
SYNC = 0
EXAMPLE 14-1: CALCULATING BAUD
RATE ERROR
Writing a new value to the SPBRG, causes the BRG
timer to be reset (or cleared). This ensures that the
BRG does not wait for a timer overflow before output-
ting the new baud rate.
Effects of Reset
After any device RESET, the SPBRG register is
cleared. The SPBRG register will need to be loaded
with the desired value after each RESET.
TABLE 14-3: REGISTERS ASSOCIATED WITH BAUD RATE GENERATOR
SYNC Mode Baud Rate
0
1Asynchronous
Synchronous FOSC/(64(X+1))
FOSC/(4(X+1))
X = value in SPBRG (0 to 255)
Desired Baud Rate = F OSC / (64 (X + 1) )
9600 = 16000000 /(64 (X + 1))
X = 25.042 25
Calculat ed Baud Ra te = 160 0000 0 / (64 (25 + 1))
= 9615
Error = (Calculate d Baud Rate - Desi red Baud Rate )
Desired Baud Rate
= (9615 - 9600) / 9600
=0.16%
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
USART1
13h, Bank 0 RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
USART2
13h, Bank 4 RCSTA2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Baud Rate Generator.
2000 Microchip Technology Inc. DS30289B-page 121
PIC17C7XX
TABLE 14-4: BAUD RATES FOR SYNCHRONOUS MODE
BAUD
RATE
(K)
FOSC = 33 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 25 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 20 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 16 MHz SPBRG
VALUE
(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 ——NA ——NA ——
19.2 NA ——NA ——19.53 +1.73 255 19.23 +0.16 207
76.8 77.10 +0.39 106 77.16 +0.47 80 76.92 +0.16 64 76.92 +0.16 51
96 95.93 -0.07 85 96.15 +0.16 64 96.15 +0.16 51 95.24 -0.79 41
300 294.64 -1.79 27 297.62 -0.79 20 294.1 -1.96 16 307.69 +2.56 12
500 485.29 -2.94 16 480.77 -3.85 12 500 0 9 500 0 7
HIGH 8250 06250050000 4000 0
LOW 32.22 255 24.41 255 19.53 255 15.625 255
BAUD
RATE
(K)
FOSC = 10 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 7.159 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 5.068 MHz SPBRG
VALUE
(DECIMAL)KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR
0.3 NA ——NA ——NA ——
1.2 NA ——NA ——NA ——
2.4 NA ——NA ——NA ——
9.6 9.766 +1.73 255 9.622 +0.23 185 9.6 0 131
19.2 19.23 +0.16 129 19.24 +0.23 92 19.2 0 65
76.8 75.76 -1.36 32 77.82 +1.32 22 79.2 +3.13 15
96 96.15 +0.16 25 94.20 -1.88 18 97.48 +1.54 12
300 312.5 +4.17 7 298.3 -0.57 5 316.8 +5.60 3
500 500 0 4 NA NA ——
HIGH 2500 0 1789.8 0 1267 0
LOW 9.766 255 6.991 255 4.950 255
BAUD
RATE
(K)
FOSC = 3.579 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 1 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 32.768 kHz SPBRG
VALUE
(DECIMAL)KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR
0.3 NA ——NA ——0.303 +1.14 26
1.2 NA ——1.202 +0.16 207 1.170 -2.48 6
2.4 NA ——2.404 +0.16 103 NA ——
9.6 9.622 +0.23 92 9.615 +0.16 25 NA ——
19.2 19.04 -0.83 46 19.24 +0.16 12 NA ——
76.8 74.57 -2.90 1 1 83.34 +8.51 2 NA ——
96 99.43 _3.57 8 NA ——NA ——
300 298.3 -0.57 2 NA ——NA ——
500 NA ——NA ——NA ——
HIGH 894.9 02500 8.192 0
LOW 3.496 255 0.976 255 0.032 255
PIC17C7XX
DS30289B-page 122 2000 Microchip Technology Inc.
TABLE 14-5: BAUD RATES FOR ASYNCHRONOUS MODE
BAUD
RATE
(K)
FOSC = 33 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 25 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 20 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 16 MHz SPBRG
VALUE
(DECIMAL)KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR
0.3 NA ——NA ——NA ——NA ——
1.2 NA ——NA ——1.221 +1.73 255 1.202 +0.16 207
2.4 2.398 -0.07 214 2.396 0.14 162 2.404 +0.16 129 2.404 +0.16 103
9.6 9.548 -0.54 53 9.53 -0.76 40 9.469 -1.36 32 9.615 +0.16 25
19.2 19.09 -0.54 26 19.53 +1.73 19 19.53 +1.73 15 19.23 +0.16 12
76.8 73.66 -4.09 6 78.13 +1.73 4 78.13 +1.73 3 83.33 +8.51 2
96 103.12 +7.42 4 97.65 +1.73 3 104.2 +8.51 2 NA ——
300 257.81 -14.06 1 390.63 +30.21 0 312.5 +4.17 0 NA ——
500 515.62 +3.13 0 NA ——NA ——NA ——
HIGH 515.62 0—— 0312.502500
LOW 2.014 255 1.53 255 1.221 255 0.977 255
BAUD
RATE
(K)
FOSC = 10 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 7.159 M Hz SPBRG
VALUE
(DECIMAL)
FOSC = 5.068 MHz SPBRG
VALUE
(DECIMAL)KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR
0.3 NA ——NA ——0.31 +3.13 255
1.2 1.202 +0.16 129 1.203 _0.23 92 1.2 0 65
2.4 2.404 +0.16 64 2.380 -0.83 46 2.4 0 32
9.6 9.766 +1.73 15 9.322 -2.90 11 9.9 -3.13 7
19.2 19.53 +1.73 7 18.64 -2.90 5 19.8 +3.13 3
76.8 78.13 +1.73 1 NA ——79.2 +3.13 0
96 NA ——NA ——NA ——
300 NA ——NA ——NA ——
500 NA ——NA ——NA ——
HIGH 156.3 0 111.9 079.20
LOW 0.610 255 0.437 255 0.309 255
BAUD
RATE
(K)
FOSC = 3.579 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 1 MHz SPBRG
VALUE
(DECIMAL)
FOSC = 32.768 kHz SPBRG
VALUE
(DECIMAL)KBAUD %ERROR KBAUD %ERROR KBAUD %ERROR
0.3 0.301 +0.23 185 0.300 +0.16 51 0.256 -14.67 1
1.2 1.190 -0.83 46 1.202 +0.16 12 NA ——
2.4 2.432 +1.32 22 2.232 -6.99 6 NA ——
9.6 9.322 -2.90 5 NA ——NA ——
19.2 18.64 -2.90 2 NA ——NA ——
76.8 NA ——NA ——NA ——
96 NA ——NA ——NA ——
300 NA ——NA ——NA ——
500 NA ——NA ——NA ——
HIGH 55.93 015.630 0.512 0
LOW 0.218 255 0.061 255 0.002 255
2000 Microchip Technology Inc. DS30289B-page 123
PIC17C7XX
14.2 USART Asynchronous Mode
In this mode, the USART uses standard nonreturn-to-
zero (NRZ) format (one START bit, eight or nine data
bits, and one STOP bit). The most common data format
is 8-bits. An on-chip dedicated 8-bit baud rate genera-
tor c an be us ed to deriv e standa rd baud rate frequ en-
cies from the osc illator. The USARTs transmitter and
receive r are func tionally in depend ent but use the same
data format and baud rate. The baud rate generator
produces a clock x64 of the bit shift rate. Parity is not
supporte d by the hard ware, but can be imple mente d in
software (and stored as the ninth data bit). Asynchro-
nous mode is stopped during SLEEP.
The Asynchronous mode is selected by clearing the
SYNC bit (TXSTA<4>).
The USART As ynchronous module consists of the fol-
lowing components:
Baud Rate Ge nera tor
Sampling Circuit
Asynchronous Transmitter
Asynchronous Receiver
14.2.1 USART ASYNCHRONOUS
TRANSMITTER
The USART transmitter block diagram is shown in
Figure 14-1. The heart of the transmitter is the transmit
shift register (TSR). The shift register obtains its data
from the read/write transmit buffer (TXREG). TXREG is
loaded with data in software. The TSR is not loaded until
the STOP bit has been transmitted from the previous
load. A s s oo n as the STOP bit is trans m it ted , th e T SR is
loaded with new data from the TXREG (if available).
Once TXREG transfers the data to the TSR (occurs in
one TCY at the end of the current BRG cycle), the TXREG
is empty and an interrupt bit, TXIF, is set. This interrupt
can be enab led/ di sabl ed by s ettin g/cl earin g t he TXIE bit.
TXIF wi ll be s et, regardle ss of TXIE and c ann ot be re se t
in software. It will reset only when new data is loaded into
TXREG. Whil e TXIF indica tes the s tatus of the T XREG,
the TRMT (TXSTA<1>) bit shows the status of the TSR.
TRMT is a read only bit which is set when the TSR is
empty . No interrupt logic is tied to this bit, so the user has
to poll this bit in order to determine if the TSR is empty.
Transmission is enabled by setting the
TXEN (TXSTA<5> ) bit. The actua l transmi ssion wil l not
occur until TXREG has been loaded with data and the
baud rate generator (BRG) has produced a shift clock
(Figure 14-3). The transmission can also be started by
first loading TXREG and then setting TXEN. Normally,
when trans mission is first s tarte d, the TS R is e mpty, so
a transfer to TXR EG will resu lt in an immediat e transfer
to TS R, resul ting i n an empty TXREG. A back-t o-back
transfer is thus possible (Figure 14-4). Clearing TXEN
during a tr ans mi ss io n wi ll c aus e the tra ns mi ss ion to b e
aborted. This will reset the transmitter and the TX/CK
pin will revert to hi-impedance.
In order to select 9-bit transmission, the
TX9 (TXSTA<6>) bit should be set and the ninth bit
value should be written to TX9D (TXSTA<0>). The
ninth bit value must be written before writing the 8-bit
data to the TXREG. This is because a data write to
TXREG can result in an immediate transfer of the data
to the TSR (if the TSR is empty).
Steps to follow when setting up an Asynchronous
Transmission:
1. Initialize the SPBRG re gis ter for the ap prop ria te
baud rate.
2. Enable the asy nch ron ous seri al port by cle arin g
the SYNC bit and setting the SPEN bit.
3. If interrupts are desired, then set the TXIE bit.
4. If 9-bit tran smis si on is des ire d, th en s et the TX9
bit.
5. If 9-bit transmission is selected, the ninth bit
should be loa ded in TX9D.
6. Load data to the TXREG register.
7. Enable the transm ission by settin g TXEN (start s
transmission).
FIGURE 14-3: ASYNCHRONOUS MASTER TRANSMISSION
Note: The TSR is not mapped in data memory,
so it is not available to the user.
Word 1 STOP Bit
Word 1
Transmit Shift Reg
START Bit Bit 0 Bit 1 Bit 7/8
Write to TXREG Wo r d 1
BRG Output
(Shift Clock)
TX
TXIF bit
TRMT bi t
(TX/CK pin)
PIC17C7XX
DS30289B-page 124 2000 Microchip Technology Inc.
FIGURE 14-4: ASYNCHRONOUS MASTER TRANSMISSION (BACK TO BACK)
TABLE 14-6: REGISTERS ASSOCIATED WITH ASYNCHRONOUS TRANSMISSION
Transmit Shift Reg.
Write to TXREG
BRG output
(shift clock)
TX
TXIF bit
TRMT bi t
Word 1 Word 2
Word 1 Word 2
START Bit STOP Bit START Bit
Transmit Shift Reg.
Word 1 Word 2
Bit 0 Bit 1 Bit 7/8 Bit 0
Note: This timing diagram shows two conse cuti ve trans missions .
(TX/CK pin)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank 0 RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
16h, Bank 0 TXRE G1 Serial Port Transmit Reg is ter (USART1 ) xxxx xxxx uuuu uuuu
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register (USART1) 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
16h, Bank 4 TXRE G2 Serial Port Transmit Reg is ter (USART2 ) xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register (USART2) 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0'. Shaded cells are not used for asynchronous transmission.
2000 Microchip Technology Inc. DS30289B-page 125
PIC17C7XX
14.2.2 USART ASYNCHRONOUS
RECEIVER
The receiver block diagram is shown in Figure 14-2.
The data comes in the RX/DT pin and drives the data
recovery block. The data recovery block is actually a
high speed shifter operating at 16 times the baud rate,
whereas the main receive serial shifter operates at the
bit rate or at FOSC.
Once Asynchronous mode is selected, reception is
enabled by setting bit CREN (RCSTA<4>).
The heart of the receive r is the receive (s erial) shif t reg-
ister (RSR). After sampling the STOP bit, the received
data in the RSR is transferred to the RCREG (if it is
empty). If the transfer is complete, the interrupt bit,
RCIF, is set. The actual interrupt can be enabled/
disabled by setting/clearing the RCIE bit. RCIF is a
read only bit which is cleared by the hardware. It is
cleared when RCREG has been read and is empty.
RCREG is a double buffered register (i.e., it is a two-
deep FIFO). It is possible for two bytes of data to be
received and transferred to the RCREG FIFO and a
third by te begin shifti ng to the R SR. On d etection o f the
STOP bit of the third byte, if the RCREG is still full, then
the overrun error bit, OERR (RCSTA<1>) will be set.
The word in the RSR will be lost. RCREG can be read
twice to retrieve the two bytes in the FIFO. The OERR
bit has to be cleared i n software w hich is done by reset-
ting the receive logic (CREN is set). If the OERR bit is
set, trans fers from the RSR to RCREG are inhibited, so
it is essen tial to cle ar the OERR bit if it is set. The fram -
ing error bit FERR (RCSTA<2>) is set if a STOP bit is
not detected.
14.2.3 SAMPLING
The dat a on the RX/DT p in is samp led three t imes by a
majority detect circuit to determine if a high or a low
level is present at the RX/DT pin. The sam pling is done
on the seventh, eighth and ninth falling edges of a x16
clock (Figure 14-5).
The x16 clock is a free running clock and the three
sample points occur at a frequency of every 16 falling
edges.
FIGURE 14-5: RX PIN SAMPLING SCHEME
FIGURE 14-6: START BIT DETECT
Note: The F E RR an d t he 9th re cei ve bi t are buff-
ered the same way as the receive data.
Reading the RCREG register will allow the
RX9D and FERR b its to b e loaded wi th val-
ues for the next received data. Therefore,
it is essential for the user to read the
RCSTA register before reading RCREG, in
order not to lose the old FERR and RX9D
information.
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
(RX/DT pin)
RX
x16 CLK
Q2, Q4 CLK
START bit
(RX/DT pin)
First rising edge of x16 clock after RX pin goes low
RX sampled low
PIC17C7XX
DS30289B-page 126 2000 Microchip Technology Inc.
Steps to follow when setting up an Asynchronous
Reception:
1. Initialize th e SPBRG re gis te r for the ap prop ria te
baud rate.
2. Enable the asynchronous serial port by clearing
the SYNC bit and setting the SPEN bit.
3. If interrupts are desired, then set the RCIE bit.
4. If 9-bit rece ption is de sired, then set the RX9 bi t.
5. Enable the reception by setting the CREN bit.
6. The RCIF bit will be set when reception com-
pletes and an interrupt will be generated if the
RCIE b it wa s set.
7. Read RCSTA to get the ni nth bit (if enabled) and
FERR bit to determine if an y error occurred dur-
ing reception.
8. Read RCREG for the 8-bit received data.
9. If an overrun error occurred, clear the error by
clearing the OERR bit.
FIGURE 14-7: ASYNCHRONOUS RECEPTION
TABLE 14-7: REGISTERS ASSOCIATED WITH ASYNCHRONOUS RECEPTION
Note: To terminate a reception, either clear the
SREN and CREN bits, or the SPEN bit.
This will reset the receive logic, so that it
will be in the proper state when receive is
re-enabled.
START
bit bit7/8
bit1bit0 bit7/8 bit0STOP
bit
START
bit START
bit
bit7/8 STOP
bit
RX
Reg
Rcv Buffer Reg
Rcv Shift
Read Rcv
Buffer Reg
RCREG
RCIF
(Interrupt Flag)
OERR bit
CREN
Word 1
RCREG Word 2
RCREG
STOP
bit
Note: This timing diagram shows three words appearing on the RX input. The RCREG (receive buffer) is read after the third word,
causing the OERR (overrun) bit to be set.
(RX/DT pin)
Word 3
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank 0 RCSTA 1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank 0 RCREG1 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA 2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank 4 RCREG2 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0'. Shaded cells are not used for asynchronous reception.
2000 Microchip Technology Inc. DS30289B-page 127
PIC17C7XX
14.3 USART Synchronous Master
Mode
In Mas ter Synchron ous mode, the data is transmi tted in
a half -dupl ex mann er; i .e., t ransmis sion a nd recep tion
do not occur at the sa me time : whe n trans m itti ng data,
the reception is inhibited and vice versa. The synchro-
nous mode is entered by setting the SYNC
(TXST A< 4>) bit. In addition, the SPEN (RCSTA<7> ) bit
is set in order to configure the I/ O pins to CK (clock) and
DT (data) lines, respectively. The Master mode indi-
cates that the processor transmits the master clock on
the CK lin e. The Master m ode is e nter ed by se ttin g th e
CSRC (TXSTA<7>) bit.
14.3.1 USART SYNCHRONOUS MASTER
TRANSMISSION
The USART transmitter block diagram is shown in
Figure 14-1. T he hea rt of t he trans mitte r is the t ransm it
(serial) shi ft register (TSR). The shif t register obta ins its
data from the read/write transmit buffer TXREG.
TXREG is loaded with data in software. The TSR is not
loaded until the last bit has been transmitted from the
previous load. As soon as the last bit is transmitted, the
TSR is loaded with new dat a from TXREG (if available).
Once TXREG transfers the data to the TSR (occurs in
one TCY at the en d of the cur rent BRG cy cle), TXR EG
is empty and the TXIF bit is set. This interrupt can be
enabled / di sa ble d b y s et ting /c lea ring the TX IE bi t. T XIF
will be set regardl ess of the state of bit TXIE and cannot
be cleared in software. It will reset only when new data
is loaded into TXREG. While TXIF indicates the status
of TXREG, TRMT (TXSTA<1>) sh ows the s t atu s of th e
TSR. TRMT is a read only bit which is set when the
TSR is emp ty. No inte rrupt logic is tied to thi s bit, so the
user has to pol l this bit in o rder to dete rmi ne i f the TSR
is em pty. The TSR i s not map ped i n d at a m em ory, so it
is no t available to t he user.
Transmission is enabled by setting the TXEN
(TXSTA<5>) bit. The actual transmission will not occur
until TXREG has been loaded with data. The first data
bit will be shifted out on the next available rising edge
of the cl ock on the TX/CK pi n. Data o ut is stable a round
the falli ng edge of the synchronou s clock (Fig ure 14-9).
The transmission can also be started by first loading
TXREG and then setting TXEN. This is advantageous
when slow baud rates are selected, since BRG is kept
in RESET when the TXEN, CREN, and SREN bits are
clear. Setti ng the TXE N bi t wi ll s tart the BRG, cr eati ng
a shift clock immediately. Normally when transmission
is first started, the TSR is empty, so a transfer to
TXREG will res ul t i n a n i mmed iate trans fer to the TSR ,
resulting in an empty TXREG. Back-to-back transfers
are possible.
Clearing TXEN during a transmission will cause the
transmission to be aborted and will reset the transmit-
ter. The RX/DT and TX/CK pins will revert to hi-imped-
ance. If either CREN or SREN are set during a
transmission, the transmission is aborted and the RX/
DT pin reverts to a hi-impedance state (for a reception).
The TX/CK pin will remain an output if the CSRC bit is
set (internal clock). The transmitter logic is not reset,
although it is disconnected from the pins. In order to
reset the transmitter , the user has to clear the TXEN bit.
If the SREN bit is s et (to i nte rrup t a n on goi ng tra nsm is -
sion and receive a single word), then after the single
word is received, SREN will be cleared and the serial
port will revert back to transmitting, since the TXEN bit
is still set. The DT line will immediately switch from hi-
impeda nce Re ceive mode to tran smit an d st art driv ing.
To avoid this, TXEN should be cleared.
In order to select 9-bit transmission, the
TX9 (TXSTA<6>) bit should be set and the ninth bit
should be written to TX9D (TXSTA<0>). The ninth bit
must be writ ten before writi ng the 8-bit dat a to TXREG.
This is b ecaus e a dat a wri te to TXREG can re sult in an
immedi ate transfer of the dat a to the TSR (if the TSR is
empty). If the TS R wa s e mpt y an d TXRE G w as wr itte n
before writing the new TX9D, the present value of
TX9D is loaded.
Steps to follow when setting up a Synchronous Master
Transmission:
1. Initialize the SPBRG re gis ter for the ap prop ria te
baud rate (s ee Baud Rate Generator Se ction for
details).
2. Enable the synchronous master serial port by
setting the SYNC, SPEN, and CSRC bits.
3. Ensure that the CREN and SREN bits are clear
(these bits override transmission when set).
4. If interrupts are desired, then set the TXIE bit
(the GLIN TD b it m ust b e cl ear and th e PEI E bi t
must be set).
5. If 9-bit transmission is desired, then set the TX9 bit.
6. If 9-bit transmission is selected, the ninth bit
should be loa ded in TX9D.
7. S tart transmission by loading data to the TXREG
register.
8. Enable the transmission by setting TXEN.
Writing the transmit data to the TXREG, then enabling
the transmit (setting TXEN), allows transmission to st art
sooner than doing these two events in the reverse order .
Note: To terminate a transmission, either clear
the SPEN bit, or the TXEN bit. This will
reset the transmit logic, so that it will be in
the proper state when transmit is re-
enabled.
PIC17C7XX
DS30289B-page 128 2000 Microchip Technology Inc.
TABLE 14-8: REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER TRANSMISSION
FIGURE 14-8: SYNCHRONOUS TRANSMISSION
FIGURE 14-9: SYNCHRONOUS TRANSMISSION (THROUGH TXEN)
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank 0 RCSTA 1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
16h, Bank 0 TXREG1 TX7 TX6 TX5 TX4 TX3 TX2 TX1 TX0 xxxx xxxx uuuu uuuu
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA 2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
16h, Bank 4 TXREG2 TX7 TX6 TX5 TX4 TX3 TX2 TX1 TX0 xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0'. Shaded cells are not used for synchronous master transmission.
Q1 Q2Q3Q4Q1 Q2Q3Q4Q1 Q2Q3Q4Q1 Q2Q3Q4Q1 Q2Q3 Q4 Q1 Q2Q3Q4Q1 Q2Q3 Q4Q1 Q2Q3Q4Q1 Q2Q3 Q4Q1 Q2Q3Q4Q1 Q2Q3 Q4Q3Q4
DT
CK
Write to
TXREG
TXIF
Interrupt Flag
TRMT
TXEN 1
Write Word 1 Wri te Word 2
bit0 bit1 bit2 bit7 bit0
Word 1 Word 2
(RX/DT pin)
(TX/CK pin)
DT
CK
Write to
TXREG
TXIF bit
TRMT bit
bit0 bit1 bit2 bit6 bit7
(RX/DT pin)
(TX/CK pin)
2000 Microchip Technology Inc. DS30289B-page 129
PIC17C7XX
14.3.2 USART SYNCHRONOUS MASTER
RECEPTION
Once Synchronous mode is selected, reception is
enabled by set ting eit her the SREN (RCSTA<5>) bit or
the CREN (RCSTA<4>) bit. Dat a is sampled on th e RX/
DT pin on the falling edge of the clock. If SREN is set,
then only a single word is received. If CREN is set, the
reception is co ntin uo us u ntil CREN i s reset. If both bits
are set, then CREN takes precedence. After clocking
the last bit, the received data in the Receive Shift
Register (RSR) is transferred to RCREG (i f it is empty).
If the transfer is complete, the interrupt bit RCIF is set.
The actual interrupt can be enabled/disabled by set-
ting/cl earing the R CIE bit. RCI F i s a r ead on ly b it whic h
is reset by the hardware. In this case, it is reset when
RCREG has been read and is empty . RCREG is a dou-
ble buffered register; i.e., it is a two deep FIFO. It is
possib le for tw o byt es of da ta t o be received and tran s-
ferred to the RCREG FIFO and a third byte to begin
shifting into the RSR. On the clocking of the last bit of
the third byte, if RCREG is still full, then the overrun
error bit OERR (RCSTA<1>) is set. The word in the
RSR will be lost. RCREG can be read twice to retrieve
the two bytes in the FIFO. The OERR bit has to be
cleared in software. This is done by clearing the CREN
bit. If OERR is set, transfers from RSR to RCREG are
inhibited, so it is essential to clear the OERR bit if it is
set. The 9th rece ive bit i s buf fered the same w ay as the
receive data. Reading the RCREG register will allow
the RX9D and FERR bits to be loaded with values for
the next received data; therefore, it is essential for the
user to read the RCSTA register before reading
RCREG in order not to lose the old FERR and RX9D
information.
Steps to follow when setting up a Synchronous Master
Reception:
1. Initialize the SPBRG re gis ter for the ap prop ria te
baud rate. See Section 14.1 for details.
2. Enable the synchronous master serial port by
setting bits SYNC, SPEN, and CSRC.
3. If interrupts are desired, then set the RCIE bit.
4. If 9-bit rece ption is de sired, then set th e RX9 bit.
5. If a single reception is required, set bit SREN.
For continuous reception set bit CREN.
6. The RCIF bit will be set when reception is com-
plete and an interrupt will be generated if the
RCIE bit was set.
7. Read RCSTA to get the ni nth bit (if enabled) and
determine if any error occurred during reception.
8. Read the 8-bit received data by reading
RCREG.
9. If any error occurred, clear the error by clearing
CREN.
FIGURE 14-10: SYNCHRONOUS RECEPTION (MASTER MODE, SREN)
Note: To terminate a reception, either clear the
SREN and CREN bits, or the SPEN bit.
This will reset t he receive logic so that it will
be in the proper state when receive is re-
enabled.
CREN bit
DT
CK
Write to the
SREN bit
SREN bit
RCIF bit
Read
RCREG
Note: Timing diagram demonstrates SYNC Master mode with SREN = 1.
Q3 Q4Q1 Q2Q3 Q4Q1Q2Q3Q4Q2 Q1Q2 Q3Q4Q1 Q2Q3 Q4 Q1 Q2Q3 Q4Q1 Q2Q3Q4 Q1 Q2Q3 Q4Q1Q2Q3 Q4 Q1Q2 Q3Q4
0
bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7
0
Q1Q2Q3Q4
(RX/DT pin)
(TX/CK pin)
PIC17C7XX
DS30289B-page 130 2000 Microchip Technology Inc.
TABLE 14-9: REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER RECEPTION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank 0 RCSTA 1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank 0 RCREG1 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA 2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank 4 RCREG2 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0'. Shaded cells are not used for synchronous master reception.
2000 Microchip Technology Inc. DS30289B-page 131
PIC17C7XX
14.4 USART Synchronous Slave Mode
The Synchronous Slave mode differs from the Master
mode, in the fact that the shift clock is supplied exter-
nal ly at t h e T X/ C K pi n (i n st e ad of b e in g s up p li e d i n ter -
nally in the Master mode). This allows the device to
transfer or recei ve dat a i n the SLEEP mod e. The Slav e
mode is en tered by clearing the CSRC (TXST A<7>) bit.
14.4.1 USART SYNCHRONOUS SLAVE
TRANSMIT
The operation of the SYNC Master and Slave modes
are identical except in the case of the SLEEP mode.
If two wo rds a r e written to TXR EG and t hen th e SLEEP
instruction executes, the following will occur. The first
word will immediately tran sfer to the TSR and will trans-
mit as the shift clock is supplied. The second word will
remain in TXREG. TXIF will not be set. When the first
word h as bee n s hi f ted ou t of TSR, TXREG will transfer
the seco nd w or d to the TSR and the TXI F fla g w ill now
be set. If TXIE is enabled, the interrupt will wake the
chip from SLEEP and if the global interrupt is enabled,
then the program will branch to the interrupt vector
(0020h).
Steps to follow when setting up a Synchronous Slave
Transmission:
1. Enable the sy nchronou s slave seri al port by s et-
ting the SYNC and SPEN bits and clearing the
CSRC bit.
2. Clear the CREN bit.
3. If interrupts are desired, then set the TXIE bit.
4. If 9-bit transm is s ion is des ire d, th en s et the TX9
bit.
5. If 9-bit transmission is selected, the ninth bit
should be loaded in TX9D.
6. Start transmission by loading data to TXREG.
7. Enable the transmission by setting TXEN.
Writing the transmit data to the TXREG, then enabling
the transmit (setting TXEN), allows transmission to
start soon er tha n doi ng the se two even ts in t he rev erse
order.
14.4.2 USART SYNCHRONOUS SLAVE
RECEPTION
Operation of the Synchronous Master and Slave
modes are identical except in the case of the SLEEP
mode. Also, SREN is a don't care in Slave mode.
If recei ve is enabl ed (CREN) p rior to the SLEEP instruc-
tion, then a word may be received during SLEEP. On
completely receiving the word, the RSR will transfer the
data to RCREG (setting RCIF) and if the RCIE bit is set,
the interru pt ge nera t ed will wake t he chip from SLEEP.
If the global interrupt is enabled, the program will
branch to the interrupt vector (0020h).
Steps to follow when setting up a Synchronous Slave
Reception:
1. Enable the synchronous master serial port by
setting the SYNC and SPEN bits and clearing
the CSRC bit.
2. If interrupts are desired, then set the RCIE bit.
3. If 9-bit rece ption is de sired, then set th e RX9 bit.
4. To enable reception, set the CREN bit.
5. The RCIF bit will be set when reception is com-
plete and an interrupt will be generated if the
RCIE bit was set.
6. Read RCSTA to get the ni nth bit (if enabled) and
determine if any error occurred during reception.
7. Read the 8-bit received data by reading
RCREG.
8. If any error occurred, clear the error by clearing
the CREN bit.
Note: To terminate a transmission, either clear
the SPEN bit, or the TXEN bit. This will
reset the transmit logic, so that it will be in
the proper state when transmit is re-
enabled.
Note: To abort reception, either clear the SPEN
bit, or the CREN bit (when in Continuous
Rece ive mode ). T his w ill res et th e re cei ve
logic, so that it will be in the proper state
when receive is re-enabled.
PIC17C7XX
DS30289B-page 132 2000 Microchip Technology Inc.
TABLE 14-10: REGISTERS ASSOCIATED WITH SYNCHRONOUS SLAVE TRANSMISSION
TABLE 14-11: REGISTERS ASSOCIATED WITH SYNCHRONOUS SLAVE RECEPTION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR,
BOR MCLR, WDT
16h, Bank 1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank 1 PIE1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank 0 RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
16h, Bank 0 TXREG1 TX7 TX6 TX5 TX4 TX3 TX2 TX1 TX0 xxxx xxxx uuuu uuuu
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA 2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
16h, Bank 4 TXREG2 TX7 TX6 TX5 TX4 TX3 TX2 TX1 TX0 xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '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 0 Value on
POR,
BOR
MCLR, WDT
16h, Bank1 PIR1 RBIF TMR3IF TMR2IF TMR1IF CA2IF CA1IF TX1IF RC1IF x000 0010 u000 0010
17h, Bank1 PIE 1 RBIE TMR3IE TMR2IE TMR1IE CA2IE CA1IE TX1IE RC1IE 0000 0000 0000 0000
13h, Bank0 RCSTA1 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank0 RCREG1 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 0 TXSTA1 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 0 SPBRG1 Baud Rate Generator Register 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
13h, Bank 4 RCSTA 2 SPEN RX9 SREN CREN FERR OERR RX9D 0000 -00x 0000 -00u
14h, Bank 4 RCREG2 RX7 RX6 RX5 RX4 RX3 RX2 RX1 RX0 xxxx xxxx uuuu uuuu
15h, Bank 4 TXSTA2 CSRC TX9 TXEN SYNC TRMT TX9D 0000 --1x 0000 --1u
17h, Bank 4 SPBRG2 Baud Rate Generator Register 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as a '0'. Shaded cells are not used for synchronous slave reception.
2000 Microchip Technology Inc. DS30289B-page 133
PIC17C7XX
15.0 MASTER SYNCHRONOUS
SERIAL PORT (MSSP)
MODULE
The Master Synchronous Serial Port (MSSP) module is
a serial interface useful for communicating with other
periphera l or m icroc ontroll er devic es. Th ese p eriphera l
devices may be serial EEPROMs, shift registers, dis-
play drivers, A/D converters, etc. The MSSP module
can operate in one of two modes:
Serial Peripheral Interface (SPI)
Inter-Integrated CircuitTM (I2C)
Figure 15-1 shows a block diagram for the SPI mode,
while Figure 15-2 and Figure 15-3 show the block
diagrams for the two different I2C modes of operation.
FIGURE 15-1: SPI MODE BLOCK
DIAGRAM
FIGURE 15-2: I2C SLAVE MODE BLOCK
DIAGRAM
FIGURE 15-3: I2C MASTER MODE
BLOCK DIAGRAM
Read Write
Internal
Data Bus
SSPSR reg
SSPBUF reg
SSPM3:SSPM0
bit0 Shift
Clock
SS Control
Enable
Edge
Select
Clock Select
TMR2 Output
Tosc
Prescaler
4, 16, 64
2
Edge
Select
2
4
Data to TX/RX in SSPSR
Data Direction bit
2
SMP:CKE
SDI
SDO
SS
SCK
Read Write
SSPSR reg
Match Detect
SSPADD reg
START and
STOP b i t D e tect
SSPBUF reg
Internal
Data Bus
Addr Match
Set, Reset
S, P bits
(SSPSTAT reg)
SCL
Shift
Clock
MSb LSb
SDA
or General
Call Detected
Read Write
SSPSR reg
Match detect
SSPADD reg
START and STOP bit
Detect/Generate
SSPBUF reg
Internal
Data Bus
Addr Match
Set/Clear S bit
Clear/Set P, bit
(SSPSTAT reg)
SCL
Shift
Clock
MSb LSb
SDA
Baud Rate Generator
7
SSPADD<6:0>
and
and Set SSPIF
or General
Call Detected
PIC17C7XX
DS30289B-page 134 2000 Microchip Technology Inc.
REGISTER 15-1: SSPSTAT: SYNC SERIAL PORT STATUS REGISTER (ADDRESS: 13h, BANK 6)
R/W-0 R/W-0 R-0 R-0 R-0 R-0 R-0 R-0
SMP CKE D/A PSR/WUA BF
bit 7 bit 0
bit 7 SMP: Sample bit
SPI Master mode:
1 = Input data sampled at end of data output time
0 = Input data sampled at middle of data output time
SPI Slave mode:
SMP must be cleared when SPI is used in Slave mode
In I 2 C Master or Slave mode:
1 = Slew rate control disabled for Standard Speed mode (100 kHz and 1 MHz)
0 = Slew rate control enabled for High Speed mode (400 kHz)
bit 6 CKE: SPI Clock Edge Select (Figure 15-6, Figure 15-8 and Figure 15-9)
CKP = 0:
1 = Data transmitted on rising edge of SCK
0 = Data transmitted on falling edge of SCK
CKP = 1:
1 = Data transmitted on falling edge of SCK
0 = Data transmitted on rising edge of SCK
bit 5 D/A: Data/Address bit (I2C mode only)
1 = Indicates that the last byte received or transmitted was data
0 = Indicates that the last byte received or transmitted was address
bit 4 P: STOP bit
(I2C mode only. This bit is cleared when the MSSP module is disabled, SSPEN is cleared.)
1 = Indicates that a STOP bit has been detected last (this bit is 0 on RESET)
0 = STOP bit was not detected last
bit 3 S: START bit
(I2C mode only. This bit is cleared when the MSSP module is disabled, SSPEN is cleared.)
1 = Indicates that a START bit has been detected last (this bit is 0 on RESET)
0 = START bit was not detected last
bit 2 R/W: Read/Write bit Information (I2C mode only)
This b it hold s the R/W b it info rmatio n foll owin g the l ast ad dress ma tch. T his bi t is o nly v alid from
the address match to the next START bit, STOP bit, or not ACK bit.
In I 2 C Slave mode:
1 = Read
0 = Write
In I 2 C Master mode:
1 = Transmit is in progress
0 = Transmit is not in progress
Oring this bit with SEN, RSEN, PEN, RCEN, or ACKEN will indicate if the MSSP is in IDLE mode.
bit 1 UA: Update Address (10-bit I2C mode onl y)
1 = Indicates that the user needs to update the address in the SSPADD register
0 = Address does not need to be updated
bit 0 BF: Buffer Full Status bit
Receive (SPI and I2C modes)
1 = Receive complete, SSPBUF is full
0 = Receive not complete, SSPBUF is empty
Transmit (I2C mode only)
1 = Data transmit in progress (does not include the ACK and STOP bits), SSPBUF is full
0 = Data transmit complete (does not include the ACK and STOP bits), SSPBUF is empty
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 135
PIC17C7XX
REGISTER 15-2: SSPCON1: SYNC SERIAL PORT CONTROL REGISTER1 (ADDRESS 11h, BANK 6)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0
bit 7 bit 0
bit 7 WCOL: Write Collision Detect bit
Master mode:
1 = A write to the SSPBUF register was attempted while the I2C conditions were not va lid for a
transmission to be started
0 = No collision
Slave mode:
1 = The SSPBUF register is written while it is still transmitting the previous word (must be cleared
in software)
0 = No collision
bit 6 SSPOV: Receive Overflow Indicator bit
In SPI mode:
1 = A new byte is receive d w hi le t he SSPBUF reg is ter is st ill holding the prev i ous data. In case
of overflow, the data in SSPSR i s lost . Ov er flo w can onl y oc cur in Slave mode. In Slave
mode, the user must read the SSPBUF, even if only transmitting data, to avoid setting
overflow. In Master mode, the overflow bit is not set, since each new reception (and
transmission) is initiated by writing to the SSPBUF register. (Must be cleared in software.)
0 = No ov er flow
In I2 C mo de:
1 = A byte is received while the SSPBUF register is still holding the previous byte. SSPOV is a
dont care in Transmit mode. (Must be cleared in software.)
0 = No overflow
bit 5 SSPEN: Synchrono us Serial Port Enab l e bi t
In both mod es, w hen enabled, these pin s m ust be properl y configured as input or out p ut .
In SPI mode:
1 = Enables serial port and configures SCK, SDO, SDI and SS as the source of the serial port pins
0 = Disabl es s erial port and configures t hese pins as I/O port pins
In I2 C mo de:
1 = Enables the serial port and configures the SDA and SCL pins as the source of the serial port pins
0 = Disabl es s erial port and configures t hese pins as I/O port pins
Note: In SPI mode, th ese pins mu st be pr operly con figu re d as input or out put .
bit 4 CKP: Clock Polarity Select bit
In SPI mode:
1 = Idle state for clock is a high level
0 = Idle sta te for clock is a low level
In I2 C Slave m ode:
SCK release control
1 = Enable clock
0 = Holds cl ock low (c lo ck stretch). (Use d to ensu re data setup ti m e.)
In I2 C Ma st er mode:
Unused in this mode
bit 3-0 SSPM3:SSPM0: Synchronous Serial Por t Mo de Select bits
0000 = SPI Master mode, clock = FOSC/4
0001 = SPI Master mode, clock = FOSC/16
0010 = SPI Master mode, clock = FOSC/64
0011 = SPI Master mode, clock = TMR2 output/2
0100 = S PI Slave m od e, clock = SCK pin, SS pin control enabled
0101 = S PI Slave m od e, clock = SCK pin, SS pin contr ol disabled, SS can be used as I/O pin
0110 = I2C Sla ve m ode, 7-bit a ddr ess
0111 = I2C Sla ve m ode, 10-bit address
1000 = I2C Ma st er mode, clo ck = FOSC / (4 * (SSPADD+1) )
1xx1 = Reserved
1x1x = Reserved
Legend:
R = Readable bit W = Writable bit U = Unimple m ented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 136 2000 Microchip Technology Inc.
REGISTER 15-3: SSPCON2: SYNC SERIAL PORT CONTROL REGISTER2 (ADDRESS 12h, BANK 6)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
GCEN ACKSTAT ACKDT ACKEN RCEN PEN RSEN SEN
bit 7 bit 0
bit 7 GCEN: General Call Enable bit (in I2C Slave mode only)
1 = Enable interrupt when a general call address (0000h) is received in the SSPSR
0 = General call address disabled
bit 6 ACKSTAT: Acknowledg e Status bit (in I2C Master mode only)
In Master Transmit mode:
1 = Acknowledge was not received from slave
0 = Acknowledge was received from slave
bit 5 ACKDT: Acknowledge Data bit (in I2C Master mode only)
In Master Receive mode:
Value that will be transmitted when the user initiates an Acknowledge sequence at the end of a
receive.
1 = Not A cknowledge
0 = Acknowle dge
bit 4 ACKEN: Acknowledge Sequence Enable bit (in I2C Master mode only)
In Master Receive mode:
1 =Initiate Acknowledge sequence on SDA and SCL pins and transmit AKDT data bit.
Automatically cleared by hardware.
0 =Acknowledge sequence idle
Note: If the I2C module is not in the IDLE mode, this bit may not be set (no spooling) and
the SSPBUF may not be written (or writes to the SSPBUF are disabled).
bit 3 RCEN: Receive Enable bit (in I2C Master mode only)
1 = Enables Receive mode for I2C
0 = Receive idle
Note: If the I2C module is not in the IDLE mode, this bit may not be set (no spooling) and
the SSPBUF may not be written (or writes to the SSPBUF are disabled).
bit 2 PEN: STOP Condition Enable bit (in I2C Master mo de only)
SCK Release Control:
1 = Initiate STOP condition on SDA and SCL pins. Automatically cleared by hardware.
0 = STOP condition idle
Note: If the I2C module is not in the IDLE mode, this bit may not be set (no spooling) and
the SSPBUF may not be written (or writes to the SSPBUF are disabled).
bit 1 RSEN: Repeated Start Condition Enabled bit (in I2C Master mode only)
1 = Init iate Repe ated Sta rt co ndi tio n on SDA an d SCL pi ns . Autom at ic all y cl ea red by hardware .
0 = Repeated Start condition idle
Note: If the I2C module is not in the IDLE mode, this bit may not be set (no spooling) and
the SSPBUF may not be written (or writes to the SSPBUF are disabled).
bit 0 SEN: START Condition Enabled bit (In I2C Master mode only)
1 = Initiate START condition on SDA and SCL pins. Automatically cleared by hardware.
0 = START condi tio n idle .
Note: If the I2C module is not in the IDLE mode, this bit may not be set (no spooling) and
the SSPBUF may not be written (or writes to the SSPBUF are disabled).
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
2000 Microchip Technology Inc. DS30289B-page 137
PIC17C7XX
15.1 SPI Mode
The SPI mode allows 8-bit s of data to be synchronously
transmitted and received simultaneously. All four
modes of SPI are supported. To accomplish communi-
cation, typically three pins are used:
Serial Data Out (SDO)
Serial Data In (SDI)
Serial Clock (SCK)
Additionally, a fourth pin may be used when in a Slave
mode of operation:
Slave Select (SS)
15.1.1 OPERATION
When initializing the SPI, several options need to be
specif ied. This is done by progra mming the ap propriate
control bits in the SSPCON1 register
(SSPCON1<5:0>) and SSPSTAT<7:6>. These control
bits allow the following to be specified:
Master mode (SC K is the clock output)
Slave mode (SCK is the clock input)
Clock Polarity (Idle state of SCK)
Data Input Sample Phase
(middle or end of data output time)
Clock Edge
(output data on rising/falling edge of SCK)
Clock Rate (Master mode onl y)
Slave Select mode (Slave mode only)
Figure 15-4 shows the block diagram of the MSSP
module when in SPI mode.
FIGURE 15-4: MSSP BLOCK DIAGRAM
(SPI MODE)
The MSSP consis ts of a trans mit/recei ve Sh ift Register
(SSPSR) and a Buf fer register (SSPBUF). The SSPSR
shifts the data in and out of the device, MSb first. The
SSPBUF holds the data that was written to the SSPSR,
until the re ceived da t a i s rea dy. Once the 8-bi t s of data
have bee n received, that byte is move d to the SSPBUF
register. Then the buffer full detect bit BF
(SSPSTAT<0>) and the interrupt flag bit SSPIF
(PIR2<7>) are set. This double buffering of the
received data (SSPBUF) allows the next byte to start
reception before reading the data that was just
received. Any write to the SSPBUF register during
transmission/reception of data will be ignored, and the
write collisio n det ect bit WCOL (SSPCON1<7>) will be
set. User software must clear the WCOL bit so that it
can be determined if the following write(s) to the
SSPBUF register completed successfully.
Read Write
Internal
Data Bus
SSPSR reg
SSPBUF reg
SSPM3:SSPM0
bit0 Shift
Clock
SS Control
Enable
Edge
Select
Clock Select
TMR2 Output
Tosc
Prescaler
4, 16, 64
2
Edge
Select
2
4
Data to TX/RX i n SSPSR
Data Direction bit
2
SMP:CKE
SDI
SDO
SS
SCK
PIC17C7XX
DS30289B-page 138 2000 Microchip Technology Inc.
When the application software is expecting to receive
valid da ta, the SSPBUF shoul d be read before th e next
byte of dat a to transfer is written to the SSPBUF. Buffer
full bit, BF (SSPSTAT<0>), indicates when SSPBUF
has been loaded with the received data (transmission
is complete). When the SSPBUF is read, bit BF is
cleared. This data may be irrelevant if the SPI is only a
transmitter. Generally the MSSP interrupt is used to
determine when the transmission/reception has com-
pleted. The SSPBUF must be rea d and/or written. If the
inter rupt metho d is not going to be use d, then softw are
polling can be done to ensure tha t a write collision does
not occur. Example 15-1 shows the loading of the
SSPBUF (SSPSR) for data transmission.
EXAMPLE 15-1: LOADING THE SSPBUF
(SSPSR ) REGISTER
The SSPSR is not directly readable, or writable and
can onl y be acce ss ed b y addressing th e SSPBUF re g-
ister . Additionally , the MSSP status register (SSPST AT)
indicates the various status conditions.
15.1.2 ENABLING SPI I/O
To enable the serial port, MSSP Enable bit, SSPEN
(SSPCON1<5>), must be set. To reset or reconfigure
SPI mode, clear bit SSPEN, re-initialize the SSPCON
registers and then set bit SSPEN. This configures the
SDI, SDO, SCK and SS pins as serial port pins. Fo r the
pins to behave as the serial port function, some must
have their data direction bits (in the DDR register)
appropriately programmed. That is:
SDI is autom aticall y c ont roll ed by the SPI module
SDO must have DDRB<7> cleared
SCK (Maste r mo de) must have D DRB <6> cl eare d
SCK (Slave mode) must have DDRB<6> set
SS must have PORTA<2> set
Any serial po rt function that is not desired may be ov er-
ridden by programming the corresponding data direc-
tion (DDR) register to the opposite value.
15.1.3 TYPIC AL CO NNEC TI ON
Figure 15-5 shows a typical connection between two
microcontrollers. The master controller (Processor 1)
initiates the data transfer by sending the SCK signal.
Data is shifted out of both shift registers on their pro-
grammed clock e dge and l atched on the oppos ite edge
of the clock. Both processors should be programmed to
same Cloc k Polarity (CKP), then both co ntrollers woul d
send and receive data at the same time. Whether the
data is meaningful (or dummy data) depends on the
application software. This leads to three scenarios for
dat a tran sm is si on:
Master sends data Slave sen ds dumm y data
Master sends data Slave sends data
Master sends dummy data Slave sends data
FIGURE 15-5: SPI MASTER/SLAVE CONNECTION
MOVLB 6 ; Bank 6
LOOP BTFSS SSPSTAT, BF ; Has data been
; received
; (transmit
; complete)?
GOTO LOOP ; No
MOVPF SSPBUF, RXDATA ; Save in user RAM
MOVFP TXDATA, SSPBUF ; New data to xmit
Serial Inpu t Buffer
(SSPBUF)
Shift Register
(SSPSR)
MSb LSb
SDO
SDI
PROCESSOR 1
SCK
SPI Master SSP M3 :SSPM0 = 00xxb
Serial Input Buffer
(SSPBUF)
Shift Register
(SSPSR)
LSb
MSb
SDI
SDO
PROCESSOR 2
SCK
SPI Slave SSPM3:SSP M0 = 010xb
Serial Clock
2000 Microchip Technology Inc. DS30289B-page 139
PIC17C7XX
15.1.4 MASTER MODE
The master can initiate the data transfer at any time
because it controls the SCK. The master determines
when the slave (Processor 2, Figure 15-5) is to broad-
cast dat a by the so ftware protocol.
In Master mode, the data is transmitted/received as
soon as the SSPBUF registe r is written to. If the SPI is
only going to receive, the SDO output could be dis-
abled (programmed as an input). The SSPSR register
will co ntinue to shift in the signal pre sent on the SDI pin
at the programmed clock rate. As each byte is
received, it will be loaded into the SSPBUF register as
if a normal received byte (interrupts and status bits
appropriately set). This could be useful in receiver
applications as a Line Activity Monitor mode.
The clock polarity is selected by appropriately program-
ming bit CKP (SSPCON1<4>). This then, would give
waveforms for SPI communication as shown in
Figure 15-6, Figure 15-8 and Figure 15-9, where the
MSb is transm it ted first. In Mast er mod e, the SPI cloc k
rate (bit rate) is user programmable to be one of the
following:
FOSC/4 (or TCY)
FOSC/16 (or 4 TCY)
FOSC/64 (or 16 TCY)
Timer2 output/2
This allo ws a maximu m bit clock freq uency (at 33 MHz)
of 8.25 MHz.
Figure 15-6 shows the waveforms for Master mode.
When CKE = 1, the SDO data is valid before there is a
clock edge on SCK. The change of the input sample is
shown based on the state of the SMP bit. The time
when the SSPBUF is loaded with the received data is
shown.
FIGURE 15-6: SPI MODE WAVEFORM (MASTER MODE)
SCK
(CKP = 0
SCK
(CKP = 1
SCK
(CKP = 0
SCK
(CKP = 1
4 clock
modes
Input
Sample
Input
Sample
SDI bit7 bit0
SDO bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
bit7 bit0
SDI
SSPIF
(SMP = 1)
(SMP = 0)
(SMP = 1)
CKE = 1)
CKE = 0)
CKE = 1)
CKE = 0)
(SMP = 0)
Write to
SSPBUF
SSPSR to
SSPBUF
SDO bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
(CKE = 0)
(CKE = 1)
Next Q4 cycle
after Q 2
PIC17C7XX
DS30289B-page 140 2000 Microchip Technology Inc.
15.1.5 SLAVE MODE
In Slave m ode , the dat a is trans mi tted and rece iv ed a s
the external clock pulses appear on SCK. When the
last bit is latched, the interrupt flag bit SSPIF (PIR2<7>)
is set.
While in Slave mode, the external clock is supplied by
the external clock source on the SCK pin. This external
clock must meet the minimum high and low times as
specified in the electrical specifications.
While in SLEEP mode, the slave can transmit/receive
data. When a byte is received, the device will wake-up
from SLEEP.
15.1.6 SLAVE SELECT
SYNCHRONIZATION
The SS pin allows a Synchronous Slave mode. The
SPI must be in Slave mode with SS pin control
enabled (SSPCON1<3:0> = 04h). The pin must not
be driven low for the SS pin to function as an input.
The RA2 Data Latch must be high . When the SS pin
is low, transmission and reception are enabled and
the SDO pin is driven. When the SS pin goes high,
the SDO pin is no longer driven, even if in the mid-
dle of a transmitted byte and becomes a floating
output. External pull-up/pull-down resistors may be
desirable, depending on the application.
When the SPI module resets, the bit counter is forced
to 0. This can be done by either forcing the SS pin to a
high level, or clearing the SSPEN bit.
To emulate two-wire communication, the SDO pin can
be connected to the SDI pin. When the SPI needs to
operate as a receiver, the SDO pin can be configured
as an in put. This d isables transmissi ons from th e SDO.
The SDI can always be left as an input (SDI function),
since it can not cre ate a bus con f li ct .
FIGURE 15-7: SLAVE SYNCHRONIZATION WAVEFORM
Note 1: When the SPI is in Slave mode with SS
pin control enabled (SSPCON<3:0> =
0100), the SPI module will reset if the SS
pin is set to VDD.
2: If the SPI is used in Slave mode with
CKE = 1, then the SS p in control must be
enabled.
SCK
(CKP = 1
SCK
(CKP = 0
Input
Sample
SDI bit7
SDO bit7 bit6 bit7
SSPIF
Interrupt
(SMP = 0)
CKE = 0)
CKE = 0)
(SMP = 0)
Write to
SSPBUF
SSPS R to
SSPBUF
SS
Flag
bit0
bit7 bit0
Next Q4 cycle
after Q2
2000 Microchip Technology Inc. DS30289B-page 141
PIC17C7XX
FIGURE 15-8: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = 0)
FIGURE 15-9: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = 1)
SCK
(CKP = 1
SCK
(CKP = 0
Input
Sample
SDI bit7 bit0
SDO bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
SSPIF
Interrupt
(SMP = 0)
CKE = 0)
CKE = 0)
(SMP = 0)
Write to
SSPBUF
SSPS R to
SSPBUF
SS
Flag
optional
Next Q4 cycle
after Q2
SCK
(CKP = 1
SCK
(CKP = 0
Input
Sample
SDI bit7 bit0
SDO bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
SSPIF
Interrupt
(SMP = 0)
CKE = 1)
CKE = 1)
(SMP = 0)
Write to
SSPBUF
SSPSR to
SSPBUF
SS
Flag
not optional
Next Q4 cycle
after Q2
PIC17C7XX
DS30289B-page 142 2000 Microchip Technology Inc.
15.1.7 SLEEP OPERATION
In Master mode, all module clocks are halted, and the
transmission/reception will remain in that state until the
device wakes from SLEEP. After the device returns to
normal mode, the module will continue to transmit/
receive data.
In Slave mode, the SPI transmit/receive shift register
operat es asy nchron ously to the devi ce. Th is al lows the
device to be placed in SLEEP mode and data to be
shifted into the SPI transmit/receive shift register.
When all 8-bits have been received, the MSSP inter-
rupt flag bit will be set and if enabled, will wake the
device from SLEEP.
15.1.8 EFFECTS OF A RESET
A RESET disables the MSSP module and terminates
the current transfer.
TABLE 15-1: REGISTERS ASSOCIATED WITH SPI OPERATION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 POR, BOR MCLR , WDT
07h, Unbanked INTSTA P EIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
14h, Bank 6 SSPBUF Synchronous Serial Port Receive Buffer/Transmit Register xxxx xxxx uuuu uuuu
11h, Bank 6 SSPCON1 WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0 0000 0000 0000 0000
13h, Bank 6 SSPSTAT SMP CKE D/A P S R/W UA BF 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the SSP in SPI mode.
2000 Microchip Technology Inc. DS30289B-page 143
PIC17C7XX
15.2 MSSP I2 C Operation
The MSSP module in I2C mode fully implements all
master an d sla ve func tion s (includi ng ge nera l call sup-
port) and pro vid es interrup ts on START and S T O P bits
in hardw are to determine a free bus (m ulti-master fun c-
tion). The MSSP module implements the standard
mode specifications as well as 7-bit and 10-bit
addressing.
Refer to Application Note AN578, “Use of the SSP
Module in the I2C Multi- Ma ste r Enviro nm ent.
A “glitch” filter is on the SCL and SDA pins when the pin
is an i npu t. Th is fil ter operates in both the 100 kHz an d
400 kH z modes. In the 10 0 kHz mode, whe n these pins
are an output, there is a s lew rate contr ol of the pin th at
is independent of device frequency.
FIGURE 15-10 : I2C SLAVE MODE BLOCK
DIAGRAM
FIGURE 15-11: I2C MASTER MODE
BLOCK DIAGRAM
T wo pins are used for data transfer . These are the SCL
pin, which is the clock and the SDA pin, which is the
data. The SDA and SCL pins are automatically config-
ured when the I2C mode is enabled. The SSP module
functions are enabled by setting SSP Enable bit
SSPEN (SSPCON1<5>).
The MSSP module has six registers for I2C operation.
These are the:
SSP Control Register1 (SSPCON1)
SSP Control Register2 (SSPCON2)
SSP Status Register (SSPSTAT)
Serial Receive/Transmit Buffer (SSPBUF)
SSP Shift Register (SSPSR) - Not directly acces-
sible
SSP Address Register (SSPADD)
The SSPCON1 register allows control of the I2C oper-
ation. Four mode selection bits (SSPCON1<3:0>) allow
one of the following I2C modes to be selected:
•I
2C Slave mode (7-bit address)
•I
2C Slave mode (10-bit address)
•I
2C Master mode, clock = OSC/4 (SSPADD +1)
Before s electi ng any I2C mode, the SCL and SDA pins
must be programmed to inputs by setting the appropri-
ate DDR bits. Selecting an I2C mode, by setting the
SSPEN bit, enables the SCL and SDA pins to be used
as the clock and data lines in I2C mode.
Read Write
SSPSR reg
Match Detect
SSPADD reg
START and
STOP b i t D e tect
SSPBUF reg
Internal
Data Bus
Addr Match
Set, Reset
S, P bits
(SSPSTAT reg)
SCL
Shift
Clock
MSb LSb
SDA
Read Write
SSPSR reg
Match Detect
SSPADD reg
START and STOP bit
Detect/Generate
SSPBUF reg
Internal
Data Bus
Addr Match
Set/Clear S bit
Clear/Set P, bit
(SSPSTAT reg)
SCL
Shift
Clock
MSb LSb
SDA
Baud Rate Generator
7
SSPADD<6:0>
and
and Set SSPIF
PIC17C7XX
DS30289B-page 144 2000 Microchip Technology Inc.
The SSPSTAT register gives the status of the data
transfer. This information includes detection of a ST ART
or STOP bit, specifies if the received byt e was data or
address if the next byte is the completion of 10-bit
address and if this will be a read or write data transfer .
The SSPBUF is the register to which transfer data is
written to or read from. The SSPSR register shifts the
data in or out of the device. In receive operations, the
SSPBUF and SSPSR create a doubled buffered
receive r . Th is allows rec eption of th e next byte to begin
befor e read ing t he la st by te o f r eceiv ed da ta. W hen th e
complete byte is received, it is transferred to the
SSPBUF register and flag bit SSPIF is set. If another
complete byte is received before the SSPBUF register
is read, a receiver overflow has occurred and bit
SSPOV (SSPCON1<6>) is set and the byte in the
SSPSR is lost.
The SSPADD register holds the slave address. In
10-bit mo de, the user needs to write the high b yte of the
address (1111 0 A9 A8 0). Following the high byte
address match, the low byte of the address needs to be
loaded (A7:A0 ).
15.2.1 SLAVE MODE
In Slave mod e, the SCL and SDA pin s must be co nfig-
ured as inputs. The MSSP module will override the
input state with the output data when required (slave-
transmitter).
When an address is matched or the data transfer after
an address match is received, the hardware automati-
cally will generate the acknowledge (ACK) pulse and
then load the SSPBUF reg is ter wi th th e re ceive d valu e
currently in the SSPSR register.
There are certain conditions that will cause the MSSP
module not to give this ACK pulse. These are if either
(or both):
a) The buffer full bit BF (SSPSTAT<0>) was set
before the transfer was received.
b) The overflow bit SSPOV (SSPCON1<6>) was
set before the transfer was received.
If the BF bit is set, the SSPSR register value is not
loaded into the SSPBUF, but bit SSPIF and SSPOV are
set. Table 15-2 shows what happens when a data
transfer byte is receiv ed, given the statu s of bits BF and
SSPOV. The shaded cells show the condition where
user so ft ware d id no t pr operly c lear th e ove rflow cond i-
tion. Flag bit BF is cl eared by reading the SSPBUF re g-
ister, while bit SSPOV is cleared through software.
The SCL clock input must have a minimum high and
low time for proper operation. The high and low times
of the I2C specification, as well as the requirement of
the MSSP module, are shown in timing p arameter #100
and parameter #101 of the Electrical Specifications.
2000 Microchip Technology Inc. DS30289B-page 145
PIC17C7XX
15.2.1.1 Addressing
Once the MSSP module has been enabled, it waits for
a STAR T co nditio n to occur. Foll owing the STAR T co n-
dition, the 8-bit s are shifted int o the SSPSR registe r . All
incoming bits are sampled with the rising edge of the
clock (SCL) line. The value of register SSPSR<7:1> is
compared to the value of the SSPADD register. The
address is compared on the falling edge of the eighth
clock (SCL) pulse. If the addresses match and the BF
and SSPOV bits are clear, the following events occur:
a) The SSPSR register value is loaded into the
SSPBUF register on the falling edge of the 8th
SCL pulse.
b) The buffer full bit, BF, is set on the falling edge
of the 8th SCL pulse.
c) An ACK pulse is generated.
d) SSP interrupt flag bit, SSPIF (PIR2<7>), is set
(interrupt is genera ted if e nabled ) - on the fallin g
edge of the 9th SCL pulse.
In 10-bit address mode, two address bytes need to be
received by the slave. The five Most Significant bits
(MSbs) of the first address byte specify if this is a 10-bit
address. Bit R/W (SSPST A T<2>) must specify a write so
the slave device will receive the second address byte.
For a 10-bit address, the first byte would equal 1111 0
A9 A8 0, where A9 and A8 are the two MSbs of the
address. The sequence of events for a 10-bit address is
as follows, with step s 7- 9 for slav e-transmitter:
1. Receive first (high) byte of Addre ss (bit s SSPIF,
BF and bit UA (SSPSTAT<1>) are set).
2. Update the SSPADD register with second (low)
byte of Address (clears bit UA and releases the
SCL line).
3. Read the SSPBUF register (clears bit BF) and
clear flag bit SSPIF.
4. Receive second (low) byte of Address (bits
SSPIF, BF and UA are set).
5. Update the SSPADD register w ith the f irst (hig h)
byte of Address. This will clear bit UA and
release t he SCL lin e.
6. Read the SSPBUF register (clears bit BF) and
clear flag bit SSPIF.
7. Receive Repeated Start condition.
8. Receive first (high) byte of Address (bits SSPIF
and BF are set).
9. Read the SSPBUF register (clears bit BF) and
clear flag bit SSPIF.
15.2.1.2 Slave Reception
When the R/W bit of the address byte is clear and an
address match occurs, the R/W bit of the SSPSTAT
register i s cleared . The rec eive d addre ss is loa ded in to
the SSPBUF register.
When the address byte overflow condition exists, then
no ackn owledge (ACK) pulse is given. An overflow con-
dition is defined as either bit BF (SSPSTAT<0>) is set,
or bit SSPOV (SSPCON1<6>) is set.
An SSP interrupt is generated for each data transfer
byte. F lag bit SSPIF (PIR2<7>) mu st be cle ared in so ft-
ware. The SSPSTAT register is used to determine the
status of the received byte.
TABLE 15-2: DATA TRANSFER RECEIVED BYTE ACTIONS
Note: Following the Repeated Start condition
(step 7) in 10-bit mode, the user only
needs to ma tc h the first 7-bit address. The
user does not update the SSPADD for the
second half of the address.
Note: The SSPBUF will be loaded if the SSPOV
bit is set and the BF flag is cleared. If a
read of the SSPBUF was performed, but
the user did not clear the state of the
SSPOV bit before the next receive
occurred, the ACK is not sent and the SSP-
BUF is update d.
Status Bits as Data
Transfer is Received SSPSR SSPBUF Generate ACK
Pulse
Set bit SSPIF
(SSP Interrupt occurs
if enabled)
BF SSPOV
00 Yes Yes Yes
10 No No Yes
11 No No Yes
0 1 Yes No Yes
Note 1: Shaded cells show the conditions where the user software did not properly clear the overflow condition.
PIC17C7XX
DS30289B-page 146 2000 Microchip Technology Inc.
15.2.1.3 Slave Transmission
When the R/W bit o f the inco ming add ress byte i s set
and an address match occurs, the R/W bit of the
SSPSTAT register is set. The received address is
loaded into the SSPBUF register. The ACK pulse will
be sent on the ninth bit, and the SCL pin is held low.
The transmit data must be loaded into the SSPBUF
register, which also loads the SSPSR register. Then
SCL pin should be enabled by setting bit CKP
(SSPCON1<4>). Th e master m ust monitor the SCL pin
prior to asserting another clock pulse. The slave
devices may be holding off the master by stretching the
clock. The eight data bits are shifted out on the falling
edge of the SCL input. This ensures that the SDA sig-
nal is valid during the SCL high time (Figure 15-13).
An SSP interrupt is generated for each data transfer
byte. The SSPIF flag bit must be cleared in software,
and the S SPST AT register is used to dete rmine the st a-
tus of the by te tran sf er. The SSPIF fl ag bit is set on th e
falling edge of the ninth clock pulse.
As a s lav e-t rans mi tte r, the AC K puls e from the m aster-
receiver is latched on the rising edge of the ninth SCL
input pulse. If the SDA line was high (not ACK), then
the data transfer is complete. When the not ACK is
latched by the slave, the slave logic is reset and the
slave then monitors for another occurrence of the
START bit. If the SDA line was low (ACK), the t rans mit
data must be loaded into the SSPBUF register, which
also loads the SSPSR register. Then, the SCL pin
should be enabled by setting the CKP bit.
FIGURE 15-12 : I2C WAVEFORMS FOR RECEPTION (7-BIT ADDRESS)
FIGURE 15-13 : I2C WAVEFORMS FOR TRANSMISSION (7-BIT ADDRESS)
P
9
8
7
6
5
D0
D1
D2
D3D4
D5
D6D7
S
A7 A6 A5 A4 A3 A2 A1SDA
SCL 123456789123456789123
4
Bus Master
Terminates
Transfer
Bit SSPOV is set because the SSPBUF register is still full.
Cleared in software
SSPBUF register is read
ACK Receiving Data
Receiving Data D0
D1
D2
D3D4
D5
D6D7
ACK
R/W = 0
Receiving Ad dr ess
SSPIF
BF (SSPSTAT<0>)
SSPOV (SSPCON1<6>)
ACK
ACK is not sent.
Not
SDA
SCL
SSPIF
BF (SSPSTAT<0>)
CKP (SSPCON1<4>)
A7 A6 A5 A4 A3 A2 A1 ACK D7 D6 D5 D4 D3 D2 D1 D0 Not ACK
Transmitting Data
R/W = 1
Receiving Address
123456789 123456789 P
Cleared in software
SSPBUF is written in software From SSP Interrupt
Service Routine
Set bit after writing to SSPBUF
SData in
sampled SCL held low
while CPU
responds to SSPIF
(the SSPBUF must be written to
before the CKP bit can be set)
R/W = 0
2000 Microchip Technology Inc. DS30289B-page 147
PIC17C7XX
FIGURE 15-14 : I2C SLAVE-TRANSMITTER (10-BIT ADDRESS)
SDA
SCL
SSPIF
BF (SSPSTAT<0>)
S123456789 1 23456789 12345 789 P
11110A9A8 A7 A6A5A4A3A2A1A0 11110 A8
R/W=1
ACK
ACK
R/W = 0
ACK
Receive First Byte of Address
Cleared in software
Master sends NACK
A9
6
(PIR1<3>)
Receive Second Byte of Address
Cleared by hardware when
SSPADD is updated.
UA (SSPSTAT<1>)
Clock is held low until
update of SSPADD has
taken place
UA is set indicating that
the SSPADD needs to be
updated
UA is set indicating that
SSPADD needs to be
updated
Cleared by hardware when
SSPADD is updated.
SSPBUF is written with
contents of SSPSR Dummy read of SSPBUF
to clear BF flag
Receive First Byte of Address
12345 789
D7 D6 D5 D4 D3 D1
ACK
D2
6
Transmitting Data Byte
D0
Dummy read of SSPBUF
to clear BF flag
Sr
Cleared in software
Write of SSPBUF
initiates transmit
Cleared in software
Transmit is complete
CKP has to be set for clock to be released
Bus Master
terminates
transfer
PIC17C7XX
DS30289B-page 148 2000 Microchip Technology Inc.
FIGURE 15-15 : I2C SLAVE-RECEIVER (10-BIT ADDRESS)
SDA
SCL
SSPIF
BF (SSPSTAT<0>)
S1234 56 789 1 2345 67 89 1 2345 789 P
1 1 1 1 0 A9A8 A7 A6A5A4A3A2A1A0 D7D6D5D4D3 D1D0
Receive Data Byte
ACK
R/W = 0
ACK
Receive First Byte of Address
Cleared in soft ware
Bus Master
terminates
transfer
D2
6
(PIR1<3>)
Receive Second Byte of Address
Cleared by hardware when
SSPADD is u pdate d with low
byte of address.
UA (SSPSTAT<1>)
Clock is held low until
update of SSPADD has
taken place
UA is set indicating that
the SSPADD needs to be
updated
UA is set indicating that
SSPADD needs to be
updated
SSPBUF is written with
contents of SSPSR Dummy read of SSPBUF
to clear BF flag
ACK
R/W = 1
Cleared in software
Dummy read of SSPBUF
to clear BF flag Read of SSPBUF
clears BF flag
Cleared by hardware when
SSPADD is updated with high
byte of address.
2000 Microchip Technology Inc. DS30289B-page 149
PIC17C7XX
15.2.2 GENERAL CALL ADDRESS
SUPPORT
The addressing procedure for the I2C bus is such tha t
the first byte after the START condition usually deter-
mines which device will be the slave addressed by the
master. The exception is the general call address,
which can address all devices. When this address is
used, all devices should, in theory, respond with an
acknowledge.
The general call address is one of eight addresses
reserved for specific purposes by the I2C protocol. It
consists of all 0s with R/W = 0.
The general call address is recognized when the Gen-
eral Call Ena ble bit (GCEN) is enabled (SSPCON2< 7>
is set). Following a START bit detect, 8-bits are shifted
into SSPSR and the address is compared against
SSPADD and is also compared to the general call
address, fixed in hardware.
If the general call address matches, the SSPSR is
transferred to the SSPBUF, the BF flag is set (eighth
bit) and on the falling edg e of the ninth bit (ACK bit), the
SSPIF flag is set.
When the i nterrupt is serviced, t he sou r ce f or the int er-
rupt can be checked by reading the contents of the
SSPBUF to determine if the address was device spe-
cific, or a general call address.
In 10-bit mode, the SSPADD is required to be updated
for the seco nd half of the address to match an d the UA
bit is set (SSPSTAT<1>). If the general call address is
sampled when GCEN is set, while the slave is config-
ured in 10-bit address mode, then the second half of
the address is not necessary, the UA bit will not be set
and the slave will begin receiving data after the
acknowledge (Figure 15-16).
FIGURE 15-16: SLAVE MODE GENERAL CALL ADDRESS SEQUENCE (7 OR 10-BIT MODE)
SDA
SCL S
SSPIF
BF (SSPSTAT<0>)
SSPOV (SSPCON1<6>)
Cleared in Softwar e
SSPBUF is Read
R/W = 0ACK
General Call Address
Address is compared to General Call Address
GCEN (SSPCON2<7>)
Receiving Data ACK
123456789123456789
D7 D6 D5 D4 D3 D2 D1 D0
after ACK, set Interrupt
0
1
PIC17C7XX
DS30289B-page 150 2000 Microchip Technology Inc.
15.2.3 SLEEP OPERATION
While in SLEEP mode, the I2C module can receive
address es or data and when an addr ess match or com-
plete byte transfer occurs, wake the processor from
SLEEP (if the SSP interrupt is enabled).
15.2.4 EFFECTS OF A RESET
A RESET disables the SSP mo dule and termina tes the
current transfe r.
TABLE 15-3: REGISTERS ASSOCIATED WITH I2C OPERATION
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 POR, BOR MCLR, WDT
07h, Unbanked INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0000 000- 0000
11h, Bank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
10h. Bank 6 SSPADD Synchronous Serial Port (I2C mode) Addr ess Register 0000 0000 0000 0000
14h, Bank 6 SSPBUF Synchronous Serial Port Receive Buffer/Transmit Register xxxx xxxx uuuu uuuu
11h, Bank 6 SSPCON1 WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0 0000 0000 0000 0000
12h, Bank 6 SSPCON2 GCEN ACKSTAT ACKDT ACKEN RCEN PEN RSEN SEN 0000 0000 0000 0000
13h, Bank 6 SSPSTAT SMP CKE D/A PSR/WUA BF 0000 0000 0000 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the SSP in I2C mode.
2000 Microchip Technology Inc. DS30289B-page 151
PIC17C7XX
15.2.5 MASTER MODE
Master mode of operation is supported by interrupt
generation on the detection of the START and STOP
conditions. The STOP (P) and START (S) bits are
cleared from a RESET, or when the MSSP module is
disabled. Control of the I2C bus may be taken when the
P bit is set, or th e bus is idle, with bo th the S and P bit s
clear.
In Master mode, the SCL and SDA lines are manipu-
lated by the MSSP hardware.
The following events will cause SSP Interrupt Flag bit,
SSPIF, to be set (SSP Interrupt if enabled):
START condition
STOP condition
Data transfer byte transmitted/received
Acknowledge transmit
Repeat ed Star t
FIGURE 15-17: SSP BLOCK DIAGRAM (I2C MASTER MODE)
Read Write
SSPSR
START bit, STOP bit,
SSPBUF
Internal
Data Bus
Set/Reset, S, P, WCOL (SSPSTAT)
Shift
Clock
MSb LSb
SDA
Acknowledge
Generate
SCL
SCL In
Bus Collision
SDA In
Receive Enable
Clock Cntl
Clock Arbitrate/WCO L Detect
(hold off clock source)
SSPADD<6:0>
Baud
Set SS PIF, BCLIF
Reset ACKSTAT, PEN (SSPCON2)
Rate
Generator
SSPM3:SSPM0
START bit Detect ,
STOP bit Detec t
Write Collision Detect
Clock Arbitration
State Counter for
end of XMIT/RCV
PIC17C7XX
DS30289B-page 152 2000 Microchip Technology Inc.
15.2.6 MULTI-MASTER MODE
In Multi-Master mode, the interrupt generation on the
detection of the START and STOP conditions allows
the determination of when the bus is free. The STOP
(P) and START (S) bits are cleared from a RESET, or
when the MSSP modul e is dis abl ed . Control of the I2C
bus may be taken when bit P (SSPSTAT<4>) is set, or
the bus is idle, with both the S and P bits clear. When
the bus is busy, enabling the SSP interrupt will gener-
ate the interrupt when the STOP condition occurs.
In Multi-Master operation, the SDA line must be moni-
tored for arbitration, to see if the signal level is the
expect ed output level. This c heck is perfo rmed in hard-
ware, with the result placed in the BCLIF bit.
The states where arbitration can be lost are:
Address Transfer
Data Transfer
A START Condition
A Repeated Start Condition
An Acknowledge Condition
15.2.7 I2C MASTER MODE SUPPORT
Master mode is enabled by setting and clearing the
appropri ate SSPM bit s in SSPCON1 and by set ting the
SSPEN bit. Once Master mode is enabled, the user
has si x opti ons .
Assert a START condition on SDA and SCL.
Assert a Repeated Start condition on SDA and
SCL.
Write to the SSPBUF register initiating
transmission of data/address.
Generate a STOP condition on SDA and SCL.
Configure the I2C port to receive data.
Generat e an Ackno wled ge conditi on at the end of
a received byte of data.
15.2.7.1 I2C Master Mode Operation
The master device generates all of the serial clock
pulses and the START and STOP condi tions. A transfer
is ended with a STOP condition or with a Repeated
Start condition. Since the Repeated Start condition is
also the beginning of the next serial transfer, the I2C
bus will not be released.
In Master Transmitter mode, serial data is output
through SDA, while SCL outputs the serial clock. The
first byte transmitted contains the slave address of the
receiving device (7 bits) and the Read/Write (R/W) bit.
In th is case , the R/W bit will be logic '0'. Serial data is
transmi tted 8 bi t s at a tim e. After each byte is tr ans mi t-
ted, an ac knowl edge bi t is rec eived. START and STO P
conditions are output to indicate the beginning and the
end of a serial transfer.
In Master Rec eive mode, the firs t byte transmitte d con-
tains the slave address of the transmitting device
(7 bits) and th e R/W bi t. In t his c ase, the R/W bit wil l b e
logic '1'. Thus, the first byte transmitted is a 7-bit slave
address, followed by a '1' to indicate receive bit. Serial
data is r ece ived via SD A, wh ile S CL out puts the se rial
clock. Serial dat a is received 8 bit s at a time. Af ter each
byte is received, an acknowledge bit is transmitted.
START and STOP conditions indicate the beginning
and end of transmission.
The baud rate generator used for SPI mode operation
is now used to set the SCL clock frequency for either
100 kHz, 400 kHz, or 1 MHz I2C operation. The baud
rate generator reload value is contained in the lower 7
bits of the SSPADD register. The baud rate generator
will auto matical ly beg in count ing on a write to the SSP-
BUF. Once the given operation is complete (i.e., trans-
mission of the last data bit is followed by ACK), the
internal clock will automatically stop counting and the
SCL pin will rem ain in its last state
Note: The MSSP Module, when configured in I2C
Master mode, does not allow queueing of
events. For instance: The user is not
allowed to initiate a START condition and
immediately write the SSPBUF register to
initiate transmission before the START
condition is complete. In this case, the
SSPBUF will not be written to and the
WCOL bit will be set, indicating that a write
to the SSPBUF did not occur.
2000 Microchip Technology Inc. DS30289B-page 153
PIC17C7XX
A typical transmit sequence would go as follows:
a) The user generates a START Condition by set-
ting the START enable bit (SEN) in SSPCON2.
b) SSPIF is set. The module will wait the required
START time before any other operation takes
place.
c) The user loads the SSPBUF with address to
transmit.
d) Addres s is s hifted out the SD A pin un til a ll 8 bits
are transmitted.
e) The MSSP Modu le shift s in the ACK bit from the
slave device and writes its value into the
SSPCON2 register (SSPCON2<6>).
f) The module genera tes an inte rrupt at t he end of
the ninth clock cycle by setting SSPIF.
g) The user lo ad s th e SSPBUF with eight b it s o f d ata.
h) DAT A is shif ted out the SDA pin unt il all 8 bit s are
transmitted.
i) The MSSP Module s hift s in the ACK bit from the
slave device, and writes its value into the
SSPCON2 register (SSPCON2<6>).
j) The MSSP module gene rates an interrup t at the
end of t he nin th clock c ycle by se tting the SSPIF
bit.
k) The use r generate s a ST OP cond ition by settin g
the STOP enable bit PEN in SSPCON2.
l) Interrupt is generated once the STOP condition
is complete.
15.2.8 BAUD RATE GENERATOR
In I2C Master mode, the reload value for the BRG is
located in the lower 7 bits of the SSPADD register
(Figure 15-18). When the BRG is loaded with this
value, the BRG counts down to 0 and stops until
another re load has taken place. The BRG count is dec-
remented twice per instruction cycle (TCY), on the Q2
and Q4 clock.
In I2C M aster mode , the BRG is reloaded a utomaticall y .
If Clock Arbitration is taking place, for instance, the
BRG will be reloaded when the SCL pin is sampled
high (Figure 15-19).
FIGURE 15-18: BAUD RATE GENERATOR
BLOCK DIAGRAM
FIGURE 15-19: BAUD RATE GENERATOR TIMING WITH CLOCK ARBITRATION
SSPM3:SSPM0
BRG Down Counter
CLKOUT FOSC/4
SSPADD<6:0>
SSPM3:SSPM0
SCL
Reload
Control
Reload
SDA
SCL
SCL de-asserted but slave holds
DX-1DX
BRG
SCL is sampled high, reload takes
place and BRG starts it s count.
03h 02h 01h 00h (hold off) 03h 02h
Reload
BRG
Value
SCL low (clock arbitration). SCL allowed to transition high.
BRG decrements
(on Q2 and Q4 cycles).
PIC17C7XX
DS30289B-page 154 2000 Microchip Technology Inc.
15.2.9 I2C MASTER MODE START
CONDITION TIMING
To initia te a STAR T condi tion, the user sets the STAR T
condition enable bit, SEN (SSPCON2<0>). If the SDA
and SCL pin s are sa mp led hig h, th e ba ud ra te g enera-
tor is reloaded with the contents of SSPADD <6:0> and
starts its coun t. If SCL and SDA are both sam pl ed hig h
when the baud rate generator times out (TBRG), the
SDA pin is driven low. The action of the SDA being
driven low while SCL is high is the START condition
and causes the S bit (SSPSTAT<3>) to be set. Follow-
ing this, the baud rate generator is reloaded with the
contents of SSPADD<6:0> and resumes its count.
When the baud rate generator times out (TBRG), the
SEN bit (SSPCON2<0>) will be automatically cleared
by hardware, the baud rate generator is suspended,
leavin g the SDA l ine h eld low and the START co nditio n
is complete.
15.2.9.1 WCOL Status Flag
If the user writes the SSPBUF when a START
sequence is in progress, then WCOL is set and the
contents of the buf fer are un ch anged (th e write doesn t
occur).
FIGURE 15-20: FIRST START BIT TIMING
Note: If at the beginning of START condition, the
SDA and SCL pins are already sampled
low, or if during the START condition, the
SCL line is sampled low before the SDA
line is driven low, a bus collision occurs.
The B us Coll is ion In terru pt F lag (BCLI F) i s
set, the START condition is aborted and
the I2C module is reset into its IDLE state.
Note: Because queueing of events is not
allowed, writing to the lower 5 bits of
SSPCON2 is disabled until the START
conditi on is complete.
SDA
SCL
S
TBRG
1st Bit 2nd Bit
TBRG
SDA = 1, At completion of START bit,
SCL = 1
Write to SSPBUF occurs here.
TBRG
Hardware clears SEN bit
TBRG
Write to SEN bit occurs here. Set S bit (SSPSTAT<3>)
and sets SSPIF bit.
2000 Microchip Technology Inc. DS30289B-page 155
PIC17C7XX
FIGURE 15-21: START CONDITION FLOW CHART
Idle Mode
SEN (SSPCON2<0> = 1)
Bus Collision Detected,
Set BCLIF, SDA = 1?
Load BRG with
Yes
BRG
Rollover?
Force SDA = 0,
Load BRG with
SSPADD<6:0>,
No
Yes
Force SCL = 0,
Clear SEN
Set S bit.
SSPADD<6:0>
SCL = 1?
SDA = 0? No
Yes
BRG
Rollover?
No
Clear SEN
START Condition Done,
No
Yes
Reset BRG
SCL= 0?
No
Yes
SCL = 0?
No
Yes
Reset BRG
Release SC L,
SSPEN = 1,
SSPCON1<3:0> = 1000
and set SSPIF
PIC17C7XX
DS30289B-page 156 2000 Microchip Technology Inc.
15.2.10 I2C MASTER MODE REPEATED
START CONDITION TIMING
A Repeated Start condition occurs when the RSEN bit
(SSPCON2<1>) is prog rammed hi gh and the I2C mod-
ule is in the idle state. When the RSEN bit is set, the
SCL pin is as s erted low. When the SCL pin is sam ple d
low , th e baud rate gen erator is loaded w ith the cont ents
of SSPADD<6:0> and be gin s co unti ng . Th e SD A pi n i s
released (brought high) for one baud rate generator
count (TBRG). When the bau d rate g enerato r times out,
if SDA i s samp led high, the SCL pi n will be de-asserte d
(brought high). When SCL is sampled high the baud
rate generator is reloaded with the contents of
SSPADD<6:0> and begins counting. SDA and SCL
must be sampled high fo r one TBRG. This ac tion is the n
followed by assertion of the SDA pin (SDA is low) for
one TBRG while SCL is high. Following this, the RSEN
bit in the SSPCON2 register will be automatically
cleared and the baud rate generator is not reloaded,
leaving the SDA pin held low . As soon as a ST AR T con-
dition is detected on the SDA and SCL pins, the S bit
(SSPSTAT<3>) will be set. The SSPIF bit will not be set
until the baud rate generator has timed out.
Immediately following the SSPIF bit getting set, the
user may write the SSPBUF with the 7-bit addres s in 7-
bit mode, or the default first address in 10-bit mode.
After the first eight bits are transmitted and an ACK is
received, the user may then transmit an additional eig ht
bits of add ress (1 0-bit mod e), or ei ght bi ts o f dat a (7-b it
mode).
15.2.10.1 WCOL status flag
If the user writes the SSPBUF when a Repeated Start
sequence is in progress, then WCOL is set and the
contents of the buf fer are un ch anged (th e write doesn t
occur).
FIGURE 15-22: REPEAT START CONDITION WAVEFORM
Note 1: If the RSEN is programmed while any
other event is in progress, it will not take
effect.
2: A bus collision during the Repeated Start
conditi on oc curs if:
SDA is sampl ed low when SCL goes
from low to high.
SCL goes low before SDA is
asserted low. This may indicate that
another master is attempting to
transmit a dat a 1.
Note: Because queueing of events is not
allowed, writing of the lower 5 bits of
SSPCON2 is disabled until the Repeated
Start condition is complete.
SDA
SCL
Sr = Repeated Start
Write to SSPCON2
Writ e to SSPBUF occurs here
Falling edge of ninth clock
End of Xmit
At completion of START bit,
hardware clear RSEN bit
1st Bit
Set S (SSPSTAT<3>)
TBRG
TBRG
SDA = 1,
SDA = 1,
SCL (no change) SCL = 1
occurs here.
TBRG TBRG TBRG
and set SSPIF
2000 Microchip Technology Inc. DS30289B-page 157
PIC17C7XX
FIGURE 15-23: REPEATED START CONDITION FLOW CHART (PAGE 1)
Idle Mode,
SSPEN = 1,
Force SCL = 0
SCL = 0?
Release SDA,
Load BRG with
SCL = 1? No
Yes
No
Yes
BRG
No
Yes
Release SCL
SSPCON1<3:0> = 1000
Rollover?
SSPADD<6:0>
Load BRG with
SSPADD<6:0>
(Clock Arbitration)
A
B
C
SDA = 1?
No
Yes
Start
RSEN = 1
Bus Collision,
Set BCLIF,
Release SDA,
Clear RSEN
PIC17C7XX
DS30289B-page 158 2000 Microchip Technology Inc.
FIGURE 15-24: REPEATED START CONDITION FLOW CHART (PAGE 2)
Force SDA = 0,
Load BRG with
SSPADD<6:0>
Yes
Repeated Start
Clear RSEN,
Yes
BRG
Rollover?
BRG
Rollover?
Yes
SDA = 0?
No SCL = 1? No
B
Set S
CA
No
No
Yes
Force SCL = 0,
Reset BRG
Set SSPIF.
SCL = 0?
Reset BRG
No
Yes
condition done,
2000 Microchip Technology Inc. DS30289B-page 159
PIC17C7XX
15.2.11 I2C MASTER MODE
TRANSMISSION
Transmission of a data byte, a 7-bit address, or either
half of a 10-bit add ress, is acco mplished by sim ply writ-
ing a val ue to SSPBUF regi st er. This act ion will set the
buff er full flag (BF) a nd allow the bau d rate generato r to
begin counting and st art the next transmission. Each bit
of address/data will be shifted out onto the SDA pin
after the fallin g edg e of SC L is asserte d (se e data hold
time spe c). SCL is held low for on e baud rate genera tor
roll over count (TBRG). Dat a should be valid before SCL
is released high (see Data setup time spec). When the
SCL pin is rel eased h igh, it is held that way for TBRG,
the data on the SDA pin must remain stable for that
duration and som e ho ld ti me af te r the next fall in g edg e
of SCL. After the eighth bit is shifted out (the falling
edge of th e eighth c lock), th e BF flag is cl eared and th e
master releases SDA, allowing the slave device being
addr es se d t o res p on d w ith an ACK bit during the ninth
bit time, if an address match occurs or if data was
received properly. The status of ACK is read into the
ACKDT on the falling edge of the ninth clock. If the
master receives an acknowledge, the acknowledge
stat us bit (AKST AT) is cleared. If not, the bi t is set. After
the ninth clock, the SSPIF is set and the master clock
(baud rate generator) is suspended until the next data
byte is loaded into the SSPBUF, leaving SCL low and
SDA unchanged (Figure 15-26).
After the write to the SSPBUF, each bit of address will
be shifted out on the fall ing edge of SCL until all s eve n
address bits and the R/W bit are co mpleted. O n the fall-
ing edge of the eighth clock, the master will de-assert
the SDA pin, allowing the slave to respond with an
acknowl edge. On the falling edge of the ninth clock, the
master will sample the SDA pin to see if the address
was rec ognized by a sla ve. The st atus of the ACK bit is
loaded into the ACKSTAT status bit (SSPCON2<6>).
Following the falling edge of the ninth clock transmis -
sion of the address, the SSPIF is set, the BF flag is
cleared and the baud rate generator is turned off until
another write to the SSPBUF tak es p lac e, ho ldi ng SCL
low and allowing SDA to float.
15.2.11.1 BF Status Flag
In Transmit mode, the BF bit (SSPSTAT<0>) is set
when the CPU writes to SSPBUF and is cleared when
all 8 bits are shifted out.
15.2.11.2 WCOL Status Flag
If the user writes the SSPBUF when a transmit is
already in progress (i.e., SSPSR is still shifting out a
data byte), then WCOL is set and the contents of the
buffer are unchanged (the write doesnt occ ur) .
WCOL must be cleared in software.
15.2.11.3 AKSTAT Status Flag
In Transmit mode, the AKSTAT bit (SSPCON2<6>) is
cleared when the sl ave has sen t an acknowle dge (ACK
= 0) and is set when the slave does not acknowledge
(ACK = 1). A slave sends an acknowledge when it has
recognized its address (including a general call), or
when the slave has properly received its data.
PIC17C7XX
DS30289B-page 160 2000 Microchip Technology Inc.
FIGURE 15-25: MASTER TRANSMIT FLOW CHART
Idle Mode
Num_Clocks = 0,
Release SDA so
Slave can drive ACK,
Num_Clocks
Load BRG with
SDA = Current Data bit
Yes
BRG
Rollover?
No
BRG
No
Yes
Force SCL = 0
= 8?
Yes
No
Yes
BRG
Rollover? No
Force SCL = 1,
Stop BRG
SCL = 1?
Load BRG with
Count High Time
Rollover? No
Read SDA and place into
ACKSTAT bit (SSPCON2<6>)
Force SCL = 0,
SCL = 1?
SDA =
Data bit?
No
Yes
Yes
Rollover?
No
Yes
Stop BRG,
Force SCL = 1
(Clock Arbitration)
(Clock Arbitration)
Num_Clocks
= Num_Clocks + 1
Bus Collision Detected
Set BCLIF, Hold Prescale Off,
Yes
No
BF = 1
Force BF = 0
SSPADD<6:0>,
Start BRG Count,
Load BRG with
SSPADD<6:0>,
start BRG count
SSPADD<6:0>,
Load BRG with
Count SCL High Time
SSPADD<6:0>,
SDA =
Data bit?
Yes
No
Clear XMIT Enable
SCL = 0? No
Yes
Reset BRG
Write SSPBUF
Set SSPIF
2000 Microchip Technology Inc. DS30289B-page 161
PIC17C7XX
FIGURE 15-26 : I2C MASTER MODE TIMING (TRANSMISSION, 7 OR 10-BIT ADDRESS)
SDA
SCL
SSPIF
BF (SSPSTAT<0>)
SEN
A7 A6 A5 A4 A3 A2 A1 ACK = 0 D7D6D5D4 D3D2D1D0
ACK
Transmitting Data or Second Half
R/W = 0Transmit Address to Slave
123456789 123456789 P
Cleared in Software Service Routine
SSPBUF is Written in Sof tware
From SSP inter rupt
After STA RT Cond iti on S EN Clear ed by Ha rd ware.
S
SSPBUF Written wit h 7-bi t Address and R/W
Start Transmit
SCL held low
while CPU
Responds to SSPIF
SEN = 0
of 10-bit Addres s
Write SSPCON2<0> SEN = 1
START Condition Begins From Slave Clear ACKSTAT bit SSPCON2<6>
ACKSTAT in
SSPCON2 = 1
Cleared in Softwar e
SSPBUF Written
PEN
Cleared in Software
R/W
PIC17C7XX
DS30289B-page 162 2000 Microchip Technology Inc.
15.2.12 I2C MASTER MODE RECEPTION
Master mode recepti on is enab led by progra mmin g the
receive enable bit, RCEN (SSPCON2<3>).
The baud rate generator begins counting and on each
rollover, the state of the SC L pin changes (high to low/
low to high) and data is shifted into the SSPSR. After
the falling edge of the eighth clock, the receive enable
flag is automatically cleared, the contents of the
SSPSR are loade d into the SSPBUF, the BF flag is se t,
the SSPIF is set and the baud rate generator is sus-
pended from counting, holding SCL low. The SSP is
now in IDLE state, awaiting the next command. When
the buffer is read by the CPU, the BF flag is automati-
cally c le ared . The user c an the n se nd an acknowl edge
bit at the end of reception, by setting the acknowledge
sequence enable bit, ACKEN (SSPCON2<4>).
15.2.12.1 BF Status Flag
In receiv e operation, BF is se t when an add ress or data
byte is loaded into SSPBUF from SSPSR. It is cleared
when SSPBUF is read.
15.2.12.2 SSPOV Status Flag
In receive operation, SSPOV is set when 8 bits are
received in to the SSPSR, and the BF flag i s already set
from a previous reception.
15.2.12.3 WCOL Status Flag
If the user writes the SSPBUF when a receive is
already in progress (i.e., SSPSR is still shifting in a dat a
byte), then WCOL is set and the contents of the buffer
are unchanged (the write doesnt occur).
Note: The SSP Module must be in an IDLE
STATE before the RCEN bit is set, or the
RCEN bit will be disregarded.
2000 Microchip Technology Inc. DS30289B-page 163
PIC17C7XX
FIGURE 15-27: MASTER RECEIVER FLOW CHART
Idle Mode
Num_Clocks = 0,
Release SDA
Force SCL=0,
Yes
No
BRG
Rollover?
Release SCL
Yes
No
SCL = 1?
Load BRG with
Yes
No
BRG
Rollover?
(Clock Arbitration)
Load BRG w/
Start Count
SSPADD<6:0>,
Start Count.
Sample SDA,
Shift Data into SSPSR
Num_Clocks
= Num_Clocks + 1
Yes
Num_Clocks
= 8?
No
Force SCL = 0,
Set SSPIF,
Set BF.
Move Contents of SSPSR
into SSPBUF,
Clear RCEN.
RCEN = 1
SSPADD<6:0>,
SCL = 0?
Yes
No
PIC17C7XX
DS30289B-page 164 2000 Microchip Technology Inc.
FIGURE 15-28 : I2C MASTER MODE TIMING (RECEPTION 7-BIT ADDRESS)
P
9
87
6
5
D0
D1
D2
D3D4
D5
D6D7
S
A7 A6 A5 A4 A3 A2 A1
SDA
SCL 12345678912345678 9 1234
Bus Master
Terminates
Transfer
ACK Receiving Data from Slave
Receiving Data from Slave
D0
D1
D2
D3D4
D5
D6D7
ACK
R/W = 1
Transmit Address to Slave
SSPIF
BF
ACK is Not Sent
Write to SSPCON2<0> (SEN = 1)
Write to SSPBUF Occurs Here ACK from Slave
Master Configured as a Receiver
by Programming SSPCON2<3>, (RCEN = 1) PEN bit = 1
Written Here
Data Shifted in on Falling Edge of CLK
Cleared in Software
Start XMIT
SEN = 0
SSPOV
SDA = 0, SCL = 1
while CPU
(SSPSTAT<0>)
ACK
Last bit is shifted into SSPSR and
contents are unloaded into SSPBUF
Cleared in Software
Cleared in soft ware
Set SSPIF interrupt
at end of receive
Set P bit
(SSPSTAT<4>)
and SSPIF
Cleared in
Software
ACK from Master
Set SS PIF at End
Set SSPIF Interrupt
at End of Acknowledge
Sequence
Set SS PIF Interrupt
at End of Acknow-
ledge sequence
of Receive
Set ACKEN, Start Acknowledge Sequence
SSP OV is Se t Be c au s e
SSPBUF is Still Full
SDA = ACK DT = 1
RCEN Cleared
Automatically
RCEN = 1 Start
Next Receive
Write to SSPCON2<4>
to Start Acknowledge Sequence
SDA = ACKDT (SSPCON2<5>) = 0
RCEN cleared
automatically
Responds to SSPIF
ACKEN
Begin START Condition
Cleared in software
SDA = ACKDT = 0
2000 Microchip Technology Inc. DS30289B-page 165
PIC17C7XX
15.2.13 ACKNOWLEDGE SEQUENCE
TIMING
An acknowledge sequence is enabled by setting the
acknowledge sequence enable bit, ACKEN
(SSPCON2<4>). When this bit is set, the SCL pin is
pulled low and t he content s of the acknowledg e data b it
is pres ent ed o n th e SD A pin . If t he user wishes to ge n-
erat e an ack nowled ge, then the ACK DT bit should be
cleared. If not, the user should set the ACKDT bit
before starting an acknowledge sequence. The baud
rate generator then counts for one rollover period
(TBRG), and the SCL pin is de-asserted (pulled high).
When the SCL pin is sampled high (clock arbitration),
the baud rate generator counts for TBRG. The SCL pin
is then pulled low. Following this, the ACKEN bit is
automatically cleared, the bau d rate generator i s turned
off and the SSP module then goes into IDLE mode
(Figure 15-29).
15.2.13.1 WCOL Status Flag
If the user writes the SSPBUF when an acknowledge
sequence is in progress, then WCOL is set and the
contents of the buf fer are un ch anged (th e write doesn t
occur).
FIGURE 15-29: ACKNOWLEDGE SEQUENCE WAVEFORM
Note: TBRG = one baud rate generator period.
SDA
SCL
Set SSPIF at the End
Acknowledge Sequence Starts Here,
Write to SSPCON 2 ACKEN Automatically Cleared
Cleared in
of Receive
ACK
8
ACKEN = 1, ACKDT = 0
D0
9
SSPIF
Software Set SSPIF at the End
of Acknowledge Sequence
Cleared in
Software
TBRG TBRG
PIC17C7XX
DS30289B-page 166 2000 Microchip Technology Inc.
FIGURE 15-30: ACKNOWLEDGE FLOW CHART
Idle Mode
Force SCL = 0
Yes
No SCL = 0?
Drive ACKDT bit
Yes
No BRG
Rollover?
(SSPCON2<5>)
onto SDA pin,
Load BRG with
SSPADD<6:0>,
Start Count.
Force SCL = 1
Yes
No SCL = 1?
No ACKDT = 1?
Load BRG with
No
BRG
Rollover?
SSPADD <6:0>,
Start Count.
No
SDA = 1?
Bus Collision Detected,
Set BCLIF,
Yes
Force SCL = 0,
(Clock Arbitr atio n)
Clear ACKEN
No
SCL = 0? Reset BRG Clear ACKEN
Set ACKEN
Release SCL,
Yes
Yes
Yes
Set SSPIF
2000 Microchip Technology Inc. DS30289B-page 167
PIC17C7XX
15.2.14 STOP CONDITION TIMING
A STOP bit is asserted on the SDA pin at the end of a
recei ve/t ransm it by s etti ng th e St op S equenc e Ena ble
bit PEN (SSPCON2<2>). At the end of a receive/
transmit the SCL line is held low after the falling edge
of the ninth clock. When the PEN bit is set, the master
will a ssert the SDA line low. When the SDA l ine is sam -
pled low, the baud rate generator is reloaded and
count s down to 0. When t he baud rate generato r times
out, the SCL pin will be brought high and one TBRG
(baud rate generator rollover count) later, the SDA pin
will be de-asserted. Wh en the SDA pin is s ampled high
while SCL is high, the P bit (SSPSTAT<4>) is set. A
TBRG later, the PEN bit is cleared and the SSPIF bit is
set (Figure 15-31).
Whenever the firmware decides to take control of the
bus, i t will firs t determine i f th e bus is busy b y ch ec kin g
the S and P bits in the SSPSTAT register. If the bus is
busy, then the CPU can be interrupted (notified) when
a STOP bit is detected (i.e., bus is free).
15.2.14.1 WCOL Status Flag
If the use r writes t he SSPBUF when a STO P sequenc e
is in progress, then WCOL is set and the content s of the
buffer are unchanged (the write doesnt occ ur) .
FIGURE 15-31: STOP CONDITION RECEIVE OR TRANSMIT MODE
SCL
SDA
SDA asserted low before rising edge of clock
Write to SSPCON 2
Set PEN
Falling Edge of
SCL = 1 for TBRG, followed by SDA = 1 for TBRG
9th Clock
SCL brought high after TBRG.
Note: TBRG = one baud rate generator period.
TBRG TBRG
after SDA sampled high. P bit (SSPSTAT<4>) is set.
TBRG
to setup STOP condition.
ACK P
TBRG
PEN bit (SSPCON2<2>) is cleared by
hardware and the SSPIF bit is set.
PIC17C7XX
DS30289B-page 168 2000 Microchip Technology Inc.
FIGURE 15-32: STOP CONDITION FLOW CHART
Idle Mode,
SSPEN = 1,
Force SDA = 0
SCL Doesnt Change
SDA = 0?
De-assert SCL,
SCL = 1
SCL = 1? No
Yes
Start BRG
No
Yes
BRG
SDA going from
0 to 1 while SCL = 1
No
Yes
Set SSPIF,
Release SDA,
Start BRG
STOP Condition done,
SSPCON1<3:0> = 1000
Rollover?
No
BRG
Rollover?
Yes
P bit Set? No
Yes
Bus Collision Detected,
Set BCLIF,
Clear PEN
Star t BRG
No
Yes
BRG
Rollover?
(Clock Arbitration)
PEN = 1
PEN cleared
2000 Microchip Technology Inc. DS30289B-page 169
PIC17C7XX
15.2.15 CLOCK ARBITRATION
Clock arbitration occurs when the master, during any
receive, transmit, or Repeated S tart/Stop condition, de-
asserts the SCL pin (SCL allowed to float high). When
the SCL pin is allo w ed to flo at hig h, the ba ud rate gen-
erator (BRG) is suspended from counting until the SCL
pin is ac tually sam pled high. When the SCL pin is sam -
pled high, the baud rate generator is reloaded with the
contents of SSPADD<6:0> and begins counting. This
ensures that the SCL high time will always be at least
one BRG rollover count, in the event that the clock is
held low by an external device (Figure 15-33).
15.2.16 SL EE P OP ER AT ION
While in SLEEP mode, the I2C module can receive
address es or data and when an addre ss match or com-
plete byte transfer occurs, wake the processor from
SLEEP (if the SSP interrupt is enabled).
15.2.17 EFFECTS OF A RESET
A RESET disables the SSP mo dule and termina tes the
current transfe r.
FIGURE 15-33: CLOCK ARBITRATION TIMING IN MASTER TRANSMIT MODE
SCL
SDA
BRG Overflow,
Release SCL,
If SCL = 1 Load BRG with
SSPADD<6:0>, and Start Count BRG overflow occurs,
Release SCL, Slave device holds SCL low. SCL = 1 BRG starts counting
clock high interval.
SCL line sampled once every machine cycle (TOSC 4).
Hold off BRG until SCL is sampled high.
TBRG TBRG TBRG
to measure high time interval.
PIC17C7XX
DS30289B-page 170 2000 Microchip Technology Inc.
15.2.18 MULTI -MASTER COMMUNICATION,
BUS COLL IS IO N AND BUS
ARBITRATION
Multi-Master mode support is achieved by bus arbitra-
tion. When the master outputs address/data bits onto
the SDA pin, arbitration takes place when the master
outputs a 1 on SDA, by letting SDA float high and
another master asserts a 0. When t he S CL pin floa ts
high, data should be stable. If the expected data on
SDA is a 1 and the dat a samp led on the SD A pin = 0,
then a bus collision has taken place. The master will
set the Bus Collision Interrupt Flag, BCLIF and reset
the I2C port to its IDLE state (Figure 15-34).
If a transmit was in progress when the bus collision
occurred, the transmission is halted, the BF flag is
cleared, the SDA and SCL lines are de-asserted and
the SSPBUF can be written to. When the user ser-
vices t he bus collis ion In terru pt Serv ice Rout ine an d if
the I2C bus is free, the user can resume communica-
tion by asserting a START condition.
If a START, Repeated Start, STOP, or Acknowledge
condition was in progress when the bus collision
occurred, the condition is aborted, the SDA and SCL
lines are de-asserted and the respective control bits in
the SSPCON2 register are cleared. When the user
services the bus collision Interrupt Service Routine,
and if the I2C bus is free, the us er can res ume comm u-
nication by asserting a START condition.
The master will continue to monitor the SDA and SCL
pins and if a STOP condition occurs, the SSPIF bit will
be set.
A write to the SSPBUF will start the transmission of
data at the first data bit, regardless of where the trans-
mitter left off when bus collision occurred.
In Multi-Master mode, the interrupt generation on the
detection of START and STOP conditions allows the
determination of when the bus is free. Control of the
I2C bus can be taken when the P bit is set in the SSP-
STAT register, or the bus is idle and the S and P bits
are cleared.
FIGURE 15-34: BUS COLLISION TIMING FOR TRANSMIT AND ACKNOWLEDGE
SDA
SCL
BCLIF
SDA released
SDA line pulled low
by another source. Sample SDA. While SCL is high
data doesnt match what is driven
Bus collision has occurred.
Set bus collision
interrupt.
by th e master.
by master.
Data changes
while SCL = 0.
2000 Microchip Technology Inc. DS30289B-page 171
PIC17C7XX
15.2.18.1 Bus Collision During a START
Condition
During a START condition, a bus collision occurs if:
a) SDA or SC L are sampled low at the b eginning of
the START condition (Figure 15-35).
b) SCL is s am pl ed l ow be fore SD A is asse rted low
(Figure 15-36).
During a START condition, both the SDA and the SCL
pins are monitored.
If: the SDA pin is already low
or the SCL pin is already low,
then:
the START condition is aborted,
and the BCLIF flag is set,
and the SSP module is reset to its IDLE state
(Figure 15-35).
The START condition begins with the SDA and SCL
pins de-asserted. When the SDA pin is sampled high,
the baud rate generator is loaded from SSPADD<6:0>
and counts down to 0. If the SCL pin is sampled low
while SDA is high, a bus collision occurs, because it is
assumed that another master is attempting to drive a
data '1' during the START condition.
If the SDA pin is sampled low during this count, the
BRG is reset and the SDA line is asserted early
(Figure 15-37 ). If, however , a ' 1' is sampled o n the SDA
pin, the SDA pin is asserted low at the end of the BRG
count. The baud rate generator is then reloaded and
count s dow n to 0 an d dur ing this tim e, if the SCL pin i s
sampled as '0', a bus collision does not occur. At the
end of the BRG count, the SCL pin is asserted low.
FIGURE 15-35: BUS COLLISION DURING START CONDITION (SDA ONLY)
Note: The re ason that bus coll ision is not a fact or
during a START condition is that no two
bus mas ters can a ssert a STAR T condi tion
at the exact same time. Therefore, one
master will always assert SDA before the
other. This condition does not cause a bu s
collis ion be cause the two m as ters m us t b e
allow ed to arbitrate t he first addres s follow-
ing the START c ondition a nd if the a ddress
is the sam e, arbi trat ion mus t be al lowe d to
continue into the data portion, Repeated
Start, or Stop conditions.
SDA
SCL
SEN
SDA sampled low before
SDA goes low before the SEN bit is set.
S bit and SSPIF set because
SSP module reset into IDLE state.
SEN cleared automatically because of bus collision.
S bit and SSPIF set because
Set SEN, enable START
condition if SDA = 1, SCL=1.
SDA = 0, SCL = 1.
BCLIF
S
SSPIF
SDA = 0, SCL = 1.
SSPIF and BCLIF are
cleared in software.
SSPIF and BCLIF are
cleared in software.
. Set BCL I F,
START condition. Set BCLIF.
PIC17C7XX
DS30289B-page 172 2000 Microchip Technology Inc.
FIGURE 15-36: BUS COLLISION DURING START CONDITION (SCL = 0)
FIGURE 15-37: BRG RESET DUE TO SDA COLLISION DURING START CONDITION
SDA
SCL
SEN Bus collision occurs, Set BCLIF.
SCL = 0 before SDA = 0,
Set SEN, enable START
sequence if SDA = 1, SCL = 1.
TBRG TBRG
SDA = 0, SC L = 1
BCLIF
S
SSPIF
Interrupts cleared
in software.
Bus collision occurs, Set BCLIF.
SCL = 0 before BRG time-out,
0
0
0
0
SDA
SCL
SEN
Set S
Set SEN, enable START
sequence if SDA = 1, SCL = 1.
Less than TBRG TBRG
SDA = 0, SCL = 1
BCLIF
S
SSPIF
S
Interrupts cleared
in software.
Set SS PIF.
SDA = 0, SCL = 1
SDA pulled low by other master.
Reset BRG and asser t SDA.
SCL pulled low after BRG
Time-out.
Set SS PIF
0
2000 Microchip Technology Inc. DS30289B-page 173
PIC17C7XX
15.2.18.2 Bus Collision During a Repeated
Start Condition
During a Repeated Start condition, a bus collision
occu rs if :
a) A low level is sampled on SDA when SCL goes
from low level to high level.
b) SCL goes low before SDA is asserted low, indi-
cating that another master is attempti ng to trans-
mit a data 1.
When the user de-asserts SDA and the pin is allowed
to float high, the BRG is loaded with SSPADD<6:0>
and counts down to 0. The SCL pin is then de-
asse rted and when sampled hig h, the SDA pin is sam-
pled. If SDA is low, a bus collision has occurred (i.e.,
another master is attempting to transmit a data 0). If,
however, SDA is sampled high, then the BRG is
reloaded and begins counting. If SDA goes from high to
low before the BRG times out, no bus collision occurs
becaus e no tw o maste rs can a ssert SDA at exactl y the
same time.
If, however, SCL goes fro m high to low before the BRG
times out and SDA has not already been asserted, then
a bus collis ion occurs. In this case, another master is
attempting to transmit a data 1 during the Repeated
Start condition.
If, at the end of the BRG time-out, both SCL and SDA
are still high, the SDA pin is driven low, the BRG is
reloaded and begins counting. At the end of the count,
regardless of the status of the SCL pin, the SCL pin is
driven low and the Repeated Start condition is com-
plete (Figure 15-38).
FIGURE 15-38: BUS COLLISION DURING A REPEATED START CONDITION (CASE 1)
FIGURE 15-39: BUS COLLISION DURING REPEATED START CONDITION (CASE 2)
SDA
SCL
RSEN
BCLIF
S
SSPIF
Sample SDA when SCL goes high.
If SDA = 0, set BCLIF and release SDA and SCL.
Cleared in software.
0
0
0
0
SDA
SCL
BCLIF
RSEN
S
SSPIF
Interrupt cleared
in software.
SCL goes low before SDA,
Set BCLIF. Release SDA and SCL.
TBRG TBRG
0
0
0
0
PIC17C7XX
DS30289B-page 174 2000 Microchip Technology Inc.
15.2.18.3 Bus Collision During a STOP
Condition
Bus collision occurs during a STOP condition if:
a) After the SDA pin has been de-asserted and
allowed to float high, SDA is sampled low after
the BRG has timed out.
b) After the SCL pin is de-asserted, SCL is sam-
pled low bef ore SDA goes hig h.
The STOP condition begins with SDA asserted low.
When SDA is sampled low, the SCL pin is allowed to
floa t. Wh en t he p in i s sa mpled hig h (c loc k arbi tr atio n),
the baud rate generator is loaded with SSPADD<6:0>
and counts down to 0. After the BRG times out, SDA
is sampled. If SDA is sampled low, a bus collision has
occurred. This is due to another master attempting to
drive a data '0'. If the SCL pin is sampled low before
SDA is allo wed to flo at high, a bus collision occurs. This
is anoth er case of an other ma ster atte mptin g to dr ive a
dat a '0 ' (Fig ure 15-40).
FIGURE 15-40: BUS COLLISION DURING A STOP CONDITION (CASE 1)
FIGURE 15-41: BUS COLLISION DURING A STOP CONDITION (CASE 2)
SDA
SCL
BCLIF
PEN
P
SSPIF
TBRG TBRG TBRG
SDA asserted low.
SDA sampled
low after TBRG,
Set BCLIF.
0
0
0
0
SDA
SCL
BCLIF
PEN
P
SSPIF
TBRG TBRG TBRG
Assert SDA . SCL goes low before SDA goes high.
Set BCLIF.
0
0
2000 Microchip Technology Inc. DS30289B-page 175
PIC17C7XX
15.3 Connection Considerations for
I2C Bus
For standard mode I2C bus devices, the values of
resistors Rp Rs in Figure 15-42 depends on the follow-
ing parameters:
Supply voltage
Bus capacitance
Number of connected devices (input current +
leakage current)
The sup ply v olt age limi ts the m inimu m va lue of res istor
Rp due to the specified minimum sink current of 3 mA
at VOL max = 0.4V for the specified output stages. For
example, with a supply voltage of VDD = 5V +10% and
VOL max = 0.4V at 3 mA, Rp min = (5.5-0.4)/0.003 =
1.7 kΩ. VDD as a fu nc tio n o f Rp is shown in Figure 15-
42. The desired noise margin of 0.1 VDD for the low
level, limits the maximum value of Rs. Seri es re sisto rs
are optional and used to improve ESD susceptibility.
The bus capacitance is the total capacitance of wire,
connections and pins. This capacitance limits the max-
imum value of Rp due to the specified rise time
(Figure 15-42).
The SMP bit is the slew rate control enabled bit. This bit
is in the SSPS T AT regis ter and controls the slew rate of
the I/O pins when in I2C mode (master or slave).
FIGURE 15-42: SAMPLE DEVICE CONFIGURATION FOR I2C BUS
Rp
Rp
VDD + 10%
SDA
SCL
Note: I2C devices with input levels related to VDD must have one common supply line to which the pull-up resistor is
DEVICE
Cb = 10 - 400 pF
Rs
Rs
also connected.
PIC17C7XX
DS30289B-page 176 2000 Microchip Technology Inc.
15.4 Example Program
Example 15-2 shows MPLAB® C17 C code for using
the I2C mo dul e in Ma ster mode to com m uni ca te wi th a
24LC01B serial EEPROM. This example uses the
PICmicro® C libraries included with MPLAB C17.
EXAMPLE 15-2: INTERFACING TO A 24LC01B SERIAL EEPROM (USING MPLAB C17)
// Include necessary header files
#include <p17c756.h> // Processor header file
#include <delays.h> // Delay routines header file
#include <stdlib.h> // Standard Library header file
#include <i2c16.h> // I2C routines header file
#define CONTROL 0xa0 // Control byte definition for 24LC01B
// Function declarations
void main(void);
void WritePORTD(static unsigned char data);
void ByteWrite(static unsigned char address,static unsigned char data);
unsigned char ByteRead(static unsigned char address);
void ACKPoll(void);
// Main program
void main(void)
{
static unsigned char address; // I2C address of 24LC01B
static unsigned char datao; // Data written to 24LC01B
static unsigned char datai; // Data read from 24LC01B
address = 0; // Preset address to 0
OpenI2C(MASTER,SLEW_ON); // Configure I2C Module Master mode, Slew rate control on
SSPADD = 39; // Configure clock for 100KHz
while(address<128) // Loop 128 times, 24LC01B is 128x8
{
datao = PORTB;
do
{
ByteWrite(address,datao); // Write data to EEPROM
ACKPoll(); // Poll the 24LC01B for state
datai = ByteRead(address); // Read data from EEPROM into SSPBUF
} while(datai != datao); // Loop as long as data not correctly
// written to 24LC01B
address++; // Increment address
}
while(1) // Done writing 128 bytes to 24LC01B, Loop forever
{
Nop();
}
}
2000 Microchip Technology Inc. DS30289B-page 177
PIC17C7XX
// Writes the byte data to 24LC01B at the specified address
void ByteWrite(static unsigned char address, static unsigned char data)
{
StartI2C(); // Send start bit
IdleI2C(); // Wait for idle condition
WriteI2C(CONTROL); // Send control byte
IdleI2C(); // Wait for idle condition
if (!SSPCON2bits.ACKSTAT) // If 24LC01B ACKs
{
WriteI2C(address); // Send control byte
IdleI2C(); // Wait for idle condition
if (!SSPCON2bits.ACKSTAT) // If 24LC01B ACKs
WriteI2C(data); // Send data
}
IdleI2C(); // Wait for idle condition
StopI2C(); // Send stop bit
IdleI2C(); // Wait for idle condition
return;
}
// Reads a byte of data from 24LC01B at the specified address
unsigned char ByteRead(static unsigned char address)
{
StartI2C(); // Send start bit
IdleI2C(); // Wait for idle condition
WriteI2C(CONTROL); // Send control byte
IdleI2C(); // Wait for idle condition
if (!SSPCON2bits.ACKSTAT) // If the 24LC01B ACKs
{
WriteI2C(address); // Send address
IdleI2C(); // Wait for idle condition
if (!SSPCON2bits.ACKSTAT) // If the 24LC01B ACKs
{
RestartI2C(); // Send restart
IdleI2C(); // Wait for idle condition
WriteI2C(CONTROL+1); // Send control byte with R/W set
IdleI2C(); // Wait for idle condition
if (!SSPCON2bits.ACKSTAT) // If the 24LC01B ACKs
{
getcI2C(); // Read a byte of data from 24LC01B
IdleI2C(); // Wait for idle condition
NotAckI2C(); // Send a NACK to 24LC01B
IdleI2C(); // Wait for idle condition
StopI2C(); // Send stop bit
IdleI2C(); // Wait for idle condition
}
}
}
return(SSPBUF);
}
EXAMPLE 15-2: INTERFACING TO A 24LC01B SERIAL EEPROM (USING MPLAB C17)
PIC17C7XX
DS30289B-page 178 2000 Microchip Technology Inc.
void ACKPoll(void)
{
StartI2C(); // Send start bit
IdleI2C(); // Wait for idle condition
WriteI2C(CONTROL); // Send control byte
IdleI2C(); // Wait for idle condition
// Poll the ACK bit coming from the 24LC01B
// Loop as long as the 24LC01B NACKs
while (SSPCON2bits.ACKSTAT)
{
RestartI2C(); // Send a restart bit
IdleI2C(); // Wait for idle condition
WriteI2C(CONTROL); // Send control byte
IdleI2C(); // Wait for idle condition
}
IdleI2C(); // Wait for idle condition
StopI2C(); // Send stop bit
IdleI2C(); // Wait for idle condition
return;
}
EXAMPLE 15-2: INTERFACING TO A 24LC01B SERIAL EEPROM (USING MPLAB C17)
2000 Microchip Technology Inc. DS30289B-page 179
PIC17C7XX
16.0 ANALOG-TO-DIGITAL
CONVERTER (A/D) MODULE
The analog-to-digital (A/D) converter module has
twelve analog inputs for the PIC17C75X devices and
sixteen for the PIC17C76X devices.
The ana log inpu t char ges a sample and hol d ca pac itor.
The output of th e sample and hold capacitor is the input
into the c on ve rter. The con ve rter t hen gen erates a di g-
ital result o f this analog level vi a successive approxima-
tion. This A/D conversion of the analog input signal,
results in a corresponding 10-bit digital number.
The analog reference voltages (positive and negative
supply) are software selectable to either the devices
supply voltages (AVDD, AVss), or the voltage level on
the RG3/AN0/VREF+ and RG2/AN1/VREF- pins.
The A/D converter has a unique feature of being able
to operat e while th e device i s in SLEEP mod e. To oper-
ate in SLEEP, the A/D clock must be derived from the
A/Ds internal RC oscillator.
The A/D module has four registers. These registers
are:
A/D Result High Register (ADRESH)
A/D Result Low Register (ADRESL)
A/D Control Register0 (ADCON0)
A/D Control Register1 (ADCON1)
The ADCON0 register, shown in Register 16-1, con-
trols the operation of the A/D module. The ADCON1
register, shown in Register 16-2, configures the func-
tions of the port pins. The port pins can be configured
as analog inputs (RG3 and RG2 can also be the volt-
age references), or as digital I/O.
REGISTER 16-1: ADCON0 REGISTER (ADDRESS: 14h, BANK 5)
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0 R/W-0
CHS3 CHS2 CHS1 CHS0 GO/DONE ADON
bit 7 bit 0
bit 7-4 CHS3:CHS0: Analog Channel Select bits
0000 = channel 0, (AN0)
0001 = channel 1, (AN1)
0010 = channel 2, (AN2)
0011 = channel 3, (AN3)
0100 = channel 4, (AN4)
0101 = channel 5, (AN5)
0110 = channel 6, (AN6)
0111 = channel 7, (AN7)
1000 = channel 8, (AN8)
1001 = channel 9, (AN9)
1010 = channel 10, (AN10)
1011 = channel 11, (AN11)
1100 = channel 12, (AN12) (PIC17C7 6X only )
1101 = channel 13, (AN13) (PIC17C7 6X only )
1110 = channel 14, (AN14) (PIC17C7 6X only )
1111 = channel 15, (AN15) (PIC17C7 6X only )
11xx = RESERVED, do not select (PIC17C75X only)
bit 3 Unimplemented: Read as 0
bit 2 GO/DONE: A/D Conversion Status bit
If ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D conversion, which is automatically
cleared by hardware when t he A/D conversion is comple te)
0 = A/D conve rsi on not in progres s
bit 1 Unimplemented: Read as 0
bit 0 ADON: A/D On bit
1 = A/D converter module is operating
0 = A/D converter module is shut-off and consumes no operating current
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bit is set 0 = Bit is cleared x = Bit is unknown
PIC17C7XX
DS30289B-page 180 2000 Microchip Technology Inc.
REGISTER 16-2: ADCON1 REGISTER (ADDRESS 15h, BANK 5)
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0
bit 7 bit 0
bit 7-6 ADCS1:ADCS0: A/D Conversion Clock Select bits
00 = FOSC/8
01 = FOSC/32
10 = FOSC/64
11 = FRC (clock derived from an internal RC oscillator)
bit 5 ADFM: A/D Result Format Select
1 = Right justified. 6 Most Significant bits of ADRESH are read as 0.
0 = Left justified. 6 Least Significant bits of ADRESL are read as 0.
bit 4 Unimplemented: Read as '0'
bit 3-1 PCFG3:PCFG1: A/D Port Configuration Control bits
bit 0 PCFG0: A/D Voltage Reference Select bit
1 = A/D reference is the VREF+ and VREF- pins
0 = A/D reference is AVDD and AVSS
Note: When this bit is set, ensur e that the A/D voltage reference specificatio ns are met.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as 0
- n = Value at POR Reset 1 = Bi t is set 0 = Bit is cleared x = Bit is unknown
A = Analog input D = Digital I/O
PCFG3:PCFG0 AN15 AN14 AN13 AN12 AN11 AN10 AN9 AN8 AN7 AN6 AN5 AN4 AN3 AN2 AN1 AN0
000x AAAAAAAAAAAAAAAA
001x DAAAAAAADAAAAAAA
010x DDAAAAAADDAAAAAA
011x D D D A A AAADDDAAAAA
100x DDDDAAAADDDDAAAA
101x DDDDDAAADDDDDAAA
110x DDDDDDAADDDDDDAA
111x DDDDDDDDDDDDDDDD
2000 Microchip Technology Inc. DS30289B-page 181
PIC17C7XX
The ADRESH:ADRESL registers contain the 10-bit
result of the A/D convers ion. When the A/D conver sion
is compl ete, the re sult is loaded i nto this A/D re sult reg-
ister pair, the GO/DONE bit (ADCON0<2>) is cleared
and A/D interrupt flag bit, ADIF is set. The block
diagrams of the A/D module are shown in Figure 16-1.
After the A/D module has been configured as desired,
the sele cted channel must be acq uire d befor e the co n-
version is started. The analog input channels must
have their corresponding DDR bi ts selected as inputs.
To determine sample time, see Section 16.1. After this
acquisition time has elapsed, the A/D conversion can
be started. The following steps should be followed for
doing an A/D convers ion:
1. Conf igure the A/D module:
a) Configure analog pins/voltage reference/
and digital I/O (ADCON1)
b) Select A/D input channel (ADCON0)
c) Select A/D conversion clock (ADCON0)
d) Turn on A/D module (ADCON0)
2. Configure A/D interrupt (if desired):
a) Clear ADIF bit
b) Set ADIE bit
c) Clear GLINTD bit
3. Wait the required acquisition time.
4. Start conversion:
a) Set GO/DONE bit (ADCON0)
5. Wait for A/D conversion to complete, by either:
a) Polling for the GO/DONE bit to be cleared
OR
b) Waiting for the A/D interrupt
6. Read A/D Result register pair
(ADRESH:ADRESL), clear bit ADIF, if required.
7. For next conversion, go to step 1 or step 2, as
required. The A/D conversion time per bit is
defined as TAD. A minimum wait of 2TAD is
required before next acquisition starts.
FIGURE 16-1: A/D BLOCK DIAGRAM
(Input Voltage)
VIN
VREF-
(Reference
Voltage)
AVDD
PCFG0
CHS3:CHS0
AN7
AN6
AN5
AN4
AN3
AN2
AN1/VREF-
AN0/VREF+
0111
0110
0101
0100
0011
0010
0001
0000
A/D
Converter
AN11
AN10
AN9
AN8
1011
1010
1001
1000
VREF+
AVSS
AN12(1)
1011
AN13(1)
1011
AN14(1)
1011
AN15(1)
1011
Note 1: These channels are only available on PIC16C76X devices.
PIC17C7XX
DS30289B-page 182 2000 Microchip Technology Inc.
Figure 16-2 shows the conversion sequence and the
terms that are used. Acquisition time is the time that the
A/D modules holding capacitor is connected to the
external voltage level. Then, there is the conversion
time of 12 TAD, which is starte d wh en the GO bi t is se t.
The sum o f these two time s is the sampl ing time. There
is a minimum ac quisition time to ensure that the holdin g
cap aci tor is charged to a l ev el that w ill gi ve the des ired
accuracy for the A/D convers ion .
FIGURE 16-2: A/D CONVERSION SEQUENCE
Acquisition Time A/D Conversion Time
A/D Sample Time
When A/D holding capacitor starts to charge.
After A/D conversion, or when new A/D channel is selected.
When A/D conversion is started
(setting the GO bit).
A/D co nversion complete , result is lo aded in AD RES register.
Holding capacitor begins acquiring voltage level on selected
channel, ADIF bit is set.
2000 Microchip Technology Inc. DS30289B-page 183
PIC17C7XX
16.1 A/D Acquisition Requirements
For the A/D converter to meet its specified accuracy,
the charge holding capacitor (CHOLD) must be allowed
to fully charge to the input channel voltage level. The
analog input model is shown in Figure 16-3. The
source impedance (RS) and the internal sampling
switch (RSS) impedance directly affect the time
required to charge the capacitor CHOLD. The sampling
switch (RSS) impedanc e varie s over the dev ice vol tag e
(VDD), Figure 16-3. The maximum recommended
impedance for analog sources is 10 k. As the
impedance is decreased, the acquisition time may be
decreased. After the analog input channel is selected
(changed) this acquisition must be done before the
conversion can be started.
To calculate the minimum acquisition time,
Equation 16-1 may be used. This equation assumes
that 1/2 LSb error is used (1024 st eps for the A/D). The
1/2 LSb err or is the ma ximu m error allo wed for the A/D
to meet its specified resolution.
Example 16-1 shows the calculation of the minimum
required acquisition time (TACQ). This is based on the
following application system assumptions.
CHOLD = 120 pF
Rs = 10 k
Conversion Error 1/2 LSb
VDD = 5V Rss = 7 k
(see graph in Figure 16-3)
Temperature = 50°C (system max.)
VHOLD =0V @ time = 0
EQUATION 16-1: ACQUISITION TIME
EQUATION 16-2: A/D MINIMUM CHARGING TIME
EXAMPLE 16-1: CALCULATING THE MINIMUM REQUIRED ACQUISITION TIME
TACQ =Amplifier Settling Time +
Holding Capacitor Charging Time +
Temperature Co efficient
=TAMP + TC + TCOFF
VHOLD = (VREF - (VREF/2048)) • (1 - e(-Tc/CHOLD(RIC + RSS + RS)))
or
TC = -(120 pF)(1 k + RSS + RS) ln(1/2047)
TACQ =TAMP + TC + TCOFF
Temperature coefficient is only required for temperatures > 25°C.
TACQ =2 µs + Tc + [(Temp - 25°C)(0.05 µs/°C)]
TC =-CHOLD (RIC + RSS + RS) ln(1/2047)
-120 pF (1 k + 7 k + 10 k) ln(0.0 004885)
-120 pF (18 k) ln(0.0004885)
-2.16 µs (-7.6241)
16.47 µs
TACQ =2 µs + 16.4 7 µs + [(50×C - 25°C)(0.05 µsC)]
18.447 µs + 1.25 µs
19.72 µs
Note 1: The reference voltage (VREF) has no effect on the equation since it cancels itself out.
2: The charge holding capacitor (CHOLD) is not discharged after each conversion.
3: The maximum recommended impedance for analog sources is 10 k. This is required to meet the pin
leakage specification.
4: After a conversion has completed, a 2.0 TAD delay must complete before acquisition can begin again.
During this time, the holding capacitor is not connected to the selected A/D input channel.
PIC17C7XX
DS30289B-page 184 2000 Microchip Technology Inc.
FIGURE 16-3: ANALOG INPUT MODEL
CPIN
VA
RSANx
5 pF
VDD
VT = 0.6V
VT = 0.6V I leakage
RIC 1k
Sampling
Switch
SS RSS
CHOLD
= DAC capacitance
VSS
6V
Sampling Switch
5V
4V
3V
2V
567891011
( k )
VDD
= 120 pF
± 500 nA
Legend CPIN
VT
I leakage
RIC
SS
CHOLD
= input capacitance
= threshold voltage
= leakage current at the pin due to
= interconnec t resistance
= sampling switch
= sample/hold capacitance (from DAC)
various junctions
2000 Microchip Technology Inc. DS30289B-page 185
PIC17C7XX
16.2 Selecting the A/D Conversion
Clock
The A/D conversion time per bit is defined as TAD. The
A/D conversion requires a minimum 12TAD per 10-bit
conversion. The source of the A/D conversion clock is
software selected. The four possible options for TAD
are:
8TOSC
32TOSC
64TOSC
Internal R C oscil la tor
For correct A/D conversions, the A/D conversion clock
(TAD) must be selected to ensure a minimum TAD time
of 1.6 µs.
Table 16-1 and T able 16-2 show the resultant TAD times
derived from the device operating frequencies and the
A/D clock source selected. These times are for stan-
dard voltage range devices.
TABLE 16-1: TAD vs. DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (C))
TABLE 16-2: TAD vs. DEVICE OPERATING FREQUENCIES (EXTENDED VOLT AGE DEVICES (LC))
AD Clock Source (TAD)Max FOSC
(MHz)
Operation ADCS1:ADCS0
8TOSC 00 5
32TOSC 01 20
64TOSC 10 33
RC 11
Note: When the device frequency is greater than 1 MHz, the RC A/D conversion clock source is only
recommended for SLEEP operation.
AD Clock Source (TAD)Max FOSC
(MHz)
Operation ADCS1:ADCS0
8TOSC 00 2.67
32TOSC 01 10.67
64TOSC 10 21.33
RC 11
Note: When the device frequency is greater than 1 MHz, the RC A/D conversion clock source is only
recommended for SLEEP operation.
PIC17C7XX
DS30289B-page 186 2000 Microchip Technology Inc.
16.3 Configuring Analog Port Pins
The ADCON1, and DDR registers control the operation
of the A/D port pins. The port pins that are desired as
analog inputs must have their correspon ding DDR bits
set (input). If the DDR bit is cleared (output), the digital
output level (VOH or VOL) will be converted.
The A/D operation is independent of the state of the
CHS2:CHS0 bits and the DDR bits.
16.4 A/D Conversions
Example 16-2 shows how to perform an A/D conver-
sion. Th e POR TF and l ower four PO R TG p ins are co n-
figured as analog inputs. The analog references
(VREF+ and V REF-) are the device AVDD and AVSS. The
A/D interrupt is enabled, and the A/D conversion clock
is FRC. The conversion is performed on the RG3/AN0
pin (channel 0).
Clearing the GO/DONE bit during a conversion will
abort the current conversion. The A/D result register
pair will NOT be updated with the partially completed A/
D conversion sample. That is, the ADRESH:ADRESL
registers will continue to contain the value of the last
completed conversion (or the last value written to the
ADRESH:ADRESL registers). Af ter the A/D conversion
is aborted, a 2TAD wait is required before the next
acquisition is started. After this 2TAD wait, acquisition
on the selected channel is automatically started.
In Figure 16-4, after the GO bit is se t, the first ti me seg-
ment has a minimum of TCY and a maximum of TAD.
EXAMPLE 16-2: A/D CONVERSION
FIGURE 16-4: A/D CONVE RSION TAD CYCLES
Note 1: When reading the port register, any pin
configu red as an a nalog inpu t ch annel wil l
read as cleared (a low level). Pins config-
ured as digital inputs, will convert an ana-
log input. Analog levels on a digitally
configu r ed inp ut w i ll not af fect the conver-
sion accuracy.
2: Analog le vels on any pin that is defined as
a digital input (including the AN15:AN0
pins), may cause the input buffer to con-
sume current that is out of the devices
specification.
Note: The GO/DONE bit should NOT be set in
the same instruction that turns on the A/D.
MOVLB 5 ; Bank 5
CLRF ADCON1, F ; Configure A/D inputs, All analog, TAD = Fosc/8, left just.
MOVLW 0x01 ; A/D is on, Channel 0 is selected
MOVWF ADCON0 ;
MOVLB 4 ; Bank 4
BCF PIR2, ADIF ; Clear A/D interrupt flag bit
BSF PIE2, ADIE ; Enable A/D interrupts
BSF INTSTA, PEIE ; Enable peripheral interrupts
BCF CPUSTA, GLINTD ; Enable all interrupts
;
; Ensure that the required sampling time for the selected input channel has elapsed.
; Then the conversion may be started.
;
MOVLB 5 ; Bank 5
BSF ADCON0, GO ; Start A/D Conversion
: ; The ADIF bit will be set and the GO/DONE bit
: ; is cleared upon completion of the A/D Conversion
TAD1TAD2TAD3TAD4 TAD5TAD6 TAD7TAD8TAD9
Set GO bit
Holding capacitor is disconnected from analog input (typically 100 ns).
holding capacitor is connected to analog input.
b9 b8 b7 b6 b5 b4 b3 b2 TAD10 TAD11
b1 b0
TCY to TAD
GO bit is cleared,
Next Q4: ADRES is loaded,
ADIF bit is set,
Conversion starts.
2000 Microchip Technology Inc. DS30289B-page 187
PIC17C7XX
FIGURE 16-5: FLOW CHART OF A/D OPERATION
Acquire
ADON = 0
ADON = 0?
GO = 0?
A/D Clock
GO = 0,
ADIF = 0
Abort Conversion
SLEEP
Power-down A/D Wait 2TAD
Wake-up
Yes
No
Yes
No
No
Yes
Finish Conversion
GO = 0,
ADIF = 1
Device in
No
Yes
Finish Conversion
GO = 0,
ADIF = 1
Wait 2TAD
Stay in SLEEP
Selected Channel
= RC? SLEEP
No
Yes
Instruction?
Start of A/D
Conversion Delayed
1 Instruction Cycle
From SLEEP?
Power-down A/D
Yes
No
Wait 2T AD
Finish Conversion
GO = 0,
ADIF = 1
SLEEP?
PIC17C7XX
DS30289B-page 188 2000 Microchip Technology Inc.
16.4.1 A/D RESULT REGISTERS
The ADRESH:ADRESL register pair is the location
where the 10-bit A/D result is loaded at the completion
of the A/D convers ion. Thi s register pair is 16-bit s wide.
The A/D mo dule gives the flexi bility to lef t or right justif y
the 10-bit result in the 16-bit result register. The A/D
Format Select bit (ADFM) controls this justification.
Figure 16-6 sh ows the ope ration of the A/D result jus ti-
ficatio n. The extra bit s are loaded with 0s. Wh en an A/
D res ult will not ove rwrite th ese loc ations (A /D disabl e),
these re gisters m ay be us ed as two general pu rpose 8-
bit registers.
16.5 A/D Operation During SLEEP
The A/D module can operate during SLEEP mode. This
requires that the A/D clock source be set to RC
(ADCS1:ADCS0 = 11). When the RC clock source is
selected, the A/D module waits one instruction cycle
before starting the conversion. This allows the SLEEP
instruction to be executed, which eliminates all digital
switchi ng noise fro m the conv ersion. Whe n the conver-
sion is completed, the GO/DONE bit will be cleared,
and the res ult lo aded into the ADR ES re gis te r. If the A/
D interrupt is enabled, the device will wake-up from
SLEEP. If the A/D interrupt is not enabled, the A/D mod-
ule will then be turned off, although the ADON bit will
remain set.
When the A/D clo ck s ource is anothe r cloc k option (not
RC), a SLEEP instruction will ca use the present conver-
sion t o be aborted and the A /D m odule to b e turn ed of f,
though the ADON bit will remain set.
Turning off the A/D pl ac es the A/D module in it s low est
current consumption state.
16.6 Effects of a RESET
A device RESET forces all registers to their RESET
state. This forces the A/D module to be turned off, and
any conve r si on is aborted .
The value that is in the ADRESH:ADRESL registers is
not modified for a Power-on Reset. The
ADRESH:ADRESL registers w ill cont ain unkno wn data
after a Power-on Reset.
FIGURE 16-6: A/D RESULT JUSTIFICATION
Note: For the A/D module to operate in SLEEP,
the A/D clock source must be set to RC
(ADCS1:ADCS0 = 11). To allow the con-
version to occur during SLEEP, ensure the
SLEEP instruction immediately follows the
instruction that sets the GO/DONE bit.
10-Bit Result
ADRESH ADRESL
0000 00
ADFM = 0
0
2 1 0 77
10-bits
RESULT
ADRESH ADRESL
10-bits
0000 00
70 7 6 5 0
RESULT
ADFM = 1
Right Justified Left Justified
2000 Microchip Technology Inc. DS30289B-page 189
PIC17C7XX
16.7 A/D Accuracy/Error
In systems where the device frequency is low, use of
the A/D RC clock is preferred. At moderate to high fre-
quencies, TAD shou ld be de riv ed from the de vi ce os ci l-
lator.
The absolute accuracy specified for the A/D converter
includes the sum of all contributions for quantization
error , integral error , different ial error , f ull scale error, off-
set error, and monotonicity. It is defined as the maxi-
mum de viation from an actual tran sition versu s an ideal
transition for any code. The absolute error of the A/D
convert er is sp ecifie d at < ± 1 LSb fo r VDD = V REF (over
the devices specified operating range). However, the
accuracy of the A/D converter will degrade as VREF
diverges from VDD.
For a given range of analog inputs, the output digital
code w ill be the same . This is due to the qua ntization of
the analog input to a digital code. Quantization error is
typically ± 1/2 LSb and is inherent in the analog to dig-
ital co nv er s i on p r oc es s. Th e on ly wa y t o re du ce qu an -
tization error is to increase the resolution of the A/D
converter or oversample.
Offset error measures the first actual transition of a
code versus the first ideal transition of a code. Offset
error shif ts the entire transfer funct ion . Offset error can
be calibrated out of a system or introduced into a sys-
tem through the interaction of the total leakage current
and source impedance at the analog input.
Gain er ror measure s the maxim um deviat ion of the last
actual transition and the last ideal transition adjusted
for off set error. This erro r appears as a cha nge in slop e
of the transfer function. The difference in gain error to
full scale error is that fu ll scale does not take offset error
into account. Gain error can be calibrated out in soft-
ware.
Linearity error refers to the uniformity of the code
changes. Linearity errors cannot be calibrated out of
the system. Integral non-linearity error measures the
actual code transition versus the ideal code transition,
adjusted by the gain error for each code.
Different ial non-linearit y measures the maximum actual
code w idth ver sus th e idea l code width. Th is me asure
is unadjusted.
The maximum pin leakage current is specified in the
Devi ce Da ta Shee t el ect rical spec ifi cat ion (Ta ble 2 0-2 ,
parameter #D060).
In systems where the device frequency is low, use of
the A/D RC clock is preferred. At moderate to high fre-
quencies, TAD shou ld be de riv ed from the de vi ce os ci l-
lato r. TAD must not violate the minimum and should be
minimized to reduce inaccuracies due to noise and
sampling capacitor bleed off.
In systems where the device will enter SLEEP mode
after the start of the A/D conversion, the RC clock
source selection is required. In this mode, the digital
noise from the modules in SLEEP are stopped. This
method giv es high acc ura cy.
16.8 Connection Considerations
If the inp ut voltage exceeds th e rail values (V SS or VDD)
by greater than 0.3V, then the accuracy of the conver-
sion is out of specification.
An external RC filter is sometimes added for anti-
aliasi ng of the input signal. The R component shou ld be
selected to ensure that the total source impedance is
kept under the 10 k rec om me nde d sp eci fic ati on . Any
external components connected (via hi-impedance) to
an analo g input pin (capacitor , zener diode, etc. ) should
have very little leakage current at the pin.
16.9 Transfer Function
The transfer fun ction of the A/D convert er is as follows:
the first tr ansition occurs w hen the analog inpu t volt age
(VAIN) equals Analog VREF / 1024 (Figure 16-7).
FIGURE 16-7: A/D TRANSFER
FUNCTION
Digital Code Output
3FEh
003h
002h
001h
000h
0.5 LSb
1 LSb
1.5 LSb
2 LSb
2.5 LSb
1022 LSb
1022.5 LSb
3 LSb
Analog Input Voltage
3FFh
1023 LSb
1023.5 LSb
PIC17C7XX
DS30289B-page 190 2000 Microchip Technology Inc.
16.10 References
A good reference for understanding A/D converter is the
"Analog-Digital Conversion Handbook" third edition,
published by Prenti ce Hall (ISBN 0-13-03-2848-0).
TABLE 16-3: REGISTERS/BIT S ASSOCIATED WITH A/D
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 POR,
BOR MCLR, WDT
06h, unbanked CPUSTA STAKAV GLINTD TO PD POR BOR --11 1100 --11 qq11
07h, unbanked INTSTA PEIF T0CKIF T0IF INTF PEIE T0CKIE T0IE INTE 0000 0000 0000 0000
10h, Bank 4 PIR2 SSPIF BCLIF ADIF CA4IF CA3IF TX2IF RC2IF 000- 0010 000- 0010
11h, B ank 4 PIE2 SSPIE BCLIE ADIE CA4IE CA3IE TX2IE RC2IE 000- 0000 000- 0000
10h, Bank 5 DDRF Data Direction Register for PORTF 1111 1111 1111 1111
11h, Bank 5 PORTF RF7/
AN11 RF6/
AN10 RF5/
AN9 RF4/
AN8 RF3/
AN7 RF2/
AN6 RF1/
AN5 RF0/
AN4 0000 0000 0000 0000
12h, Bank 5 DDRG Data Direction register for PORTG 1111 1111 1111 1111
13h, Bank 5 PORTG RG7/
TX2/CK2 RG6/
RX2/DT2 RG5/
PWM3 RG4/
CAP3 RG3/
AN0/VREF+RG2/
AN1/VREF-RG1/
AN2 RG0/
AN3 xxxx 0000 uuuu 0000
14h, Bank 5 ADCON0 CHS3 CHS2 CHS1 CHS0 GO/DONE ADON 0000 -0-0 0000 -0-0
15h, Bank 5 ADCON1 ADCS1 ADCS0 ADFM PCFG3 PCFG2 PCFG1 PCFG0 000- 0000 000- 0000
16h, Bank 5 ADRESL A/D Result Low Register xxxx xxxx uuuu uuuu
17h, Bank 5 ADRESH A/D Result High Register xxxx xxxx uuuu uuuu
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used for A/D conversion.
Note: Other (non power-up) RESETS include: external RESET through MCLR and Watchdog T imer Reset.
2000 Microchip Technology Inc. DS30289B-page 191
PIC17C7XX
17.0 SPECIAL FEATURES OF THE
CPU
What sets a microcontroller apart from other proces-
sors are special circuits to deal with the needs of real-
time appl ications. The PIC17CXXX famil y has a host of
such features intended to maximize system reliability,
minimize cost through elimination of external compo-
nent s, provide p ower saving opera ting modes an d offer
code protection. These are:
Oscillator Selection (Section 4.0)
RESET (Section 5.0)
- Power-on Reset (POR )
- Power-up Timer (PWRT)
- Oscillator Start-up Timer (OST)
- Brown-out Reset (BOR)
Interrupts (Section 6.0)
Watchdog Timer (WDT)
SLEEP mode
Code protection
The PIC17CXXX has a Watchdog Timer which can be
shut-of f only through EPROM bits. It runs off its own RC
oscill ator for ad ded reli abili ty. There are two time rs that
offer necessary delays on POR and BOR. One is the
Oscillator Start-up Timer (OST), intended to keep the
chip in RESET until the crystal oscillator is stable. The
other is the Pow er-up Timer (PWRT ), which prov ides a
fixed delay of 96 ms (nominal) on power-up only,
designed to keep the part in RESET while the power
supply stabilizes. With these two timers on-chip, most
applications need no external RESET circuitry.
The SLEEP mode is designed to offer a very low cur-
rent power-down mode. The user can wake from
SLEEP through external RESET, Watchdog Timer
Reset, or through an interrupt. Several oscillator
options are also made available to allow the part to fit
the application. The RC oscillator option saves system
cost, w hil e th e LF c rys t al option saves po w er. Con fig u-
ration bi ts are used to sel ec t v ario us op tio ns . This co n-
figuration word has the format shown in Figure 17-1.
REGISTER 17-1: CONFIGURATION WORDS
Hi gh (H ) Tabl e Re a d A dd r. U-x R/P-1 R/P-1 U-x U-x U-x U-x U-x U-x
FE0F h - FE0 8h PM2 BODEN
bit 15 bit 8 bit 7 bit 0
Lo w ( L) Tabl e R ea d Add r. U-x U-x R/P-1 U-x R/P-1 R/P-1 R/P-1 R/P-1 R/P-1
FE07 h - FE0 0h PM1 PM0 WDTPS1 WDTPS0 FOSC1 FOSC0
bit 15 bit 8 bit 7 bit 0
bits 7H, 6L, 4L PM2, PM1, PM0: Processor Mode Select bits
111 = Microprocessor mode
110 = Microcontroller mode
101 = Extended Microcon troller mode
000 = Code Protected Microcontroller mode
bit 6H BODEN: Brown-out Detect Enable
1 = Brown-out Detect circuitry is enabled
0 = Brown-out Detect circuitry is disabled
bits 3L:2L WDTPS1:WDTPS0: WDT Postscaler Select bits
11 = WDT enabled, posts cal er = 1
10 = WDT enabled, posts cal er = 256
01 = WDT enabled, posts cal er = 64
00 = WDT disabled, 16-bit overflow timer
bits 1L:0L FOSC1:FOSC0: Oscillator Select bits
11 = EC oscillator
10 = XT oscillator
01 = RC oscillator
00 = LF oscillator
Shaded bits ()Reserved
PIC17C7XX
DS30289B-page 192 2000 Microchip Technology Inc.
17.1 Configuration Bits
The PIC17CXXX has eight configuration locations
(Table 17-1). These locations can be programmed
(read as 0), or left unprogrammed (read as 1) to
select various device configurations. Any write to a
configuration location, regardless of the data, will pro-
gram that configuration bit. A TABLWT instruction and
raising the MCLR/VPP pin to th e pro gr ammi ng v olta ge
are both required to write to program memory loca-
tions. The configuration bits can be read by using the
TABLRD instructions. Reading any configuration loca-
tion between FE00h and FE07h will read the low byte
of the configuration word (Figure 17-1) into the TAB-
LATL register. The TABLATH register will be FFh.
Reading a configuration location between FE08h and
FE0Fh wil l read the high byte of the co nfigura tio n word
into the TABLATL register. The TABLATH register will
be FFh.
Addresses FE00h through FE0Fh are only in the pro-
gram m em ory s p a ce for Microcontroller and Cod e Pro-
tected Microcontroller modes. A device programmer
will be able to read the configuration word in any pro-
cessor mode. See programming specifications for
more detail.
TABLE 17-1: CONFIGURATION
LOCATIONS
17.2 Oscillator Configurations
17.2.1 OSCILLATOR TYPES
The PIC17CXXX can be operat ed in four different oscil-
lator modes. The user can program two configuration
bits (FOSC1:FOSC0) to select one of these four
modes:
LF Low Power Crystal
XT Crystal/Resonator
EC External Clock Input
RC Resistor/Capacitor
For information on the different oscillator types and
how to use them, please refer to Section 4.0.
Bit Address
FOSC0 FE00h
FOSC1 FE01h
WDTPS0 FE02h
WDTPS1 FE03h
PM0 FE04h
PM1 FE06h
BODEN FE0Eh
PM2 FE0Fh
Note: When pr og ram ming the desired configu r a-
tion locations, they must be programmed
in ascending order, starting with address
FE00h.
2000 Microchip Technology Inc. DS30289B-page 193
PIC17C7XX
17.3 W atchdog Ti mer (WDT)
The Watchdog Timers function is to recover from soft-
ware malfuncti on, or to reset t he device while i n SLEEP
mode. The WDT uses an internal free running on-chip
RC osc illato r fo r it s c lo ck so urc e. This d oes no t re qui re
any external components. This RC oscillator is sepa-
rate from the RC oscillator of the OSC1/CLKIN pin.
That means that the WDT will run even if the clock on
the OSC1/CLKIN and OSC2/CLKOUT pins has been
stopped , for example , by execution of a SLEEP ins truc-
tion. During normal operation, a WDT time-out gener-
ates a device RESET. The WDT can be permanently
disabled by programming the configuration bits
WDTPS1:WDTPS0 as '00' (Section 17.1).
Under normal operation, the WDT must be cleared on
a regular interval. This time must be less than the m in-
imum WDT overflow time. Not clearing the WDT in this
time frame will cause the WDT to overflow and reset
the device.
17.3.1 WDT PERIO D
The WDT ha s a nomi nal time -out peri od of 12 ms (wi th
post scal er = 1). Th e t ime-out period s vary with te mper-
ature, VDD and pr ocess variatio ns from part to part (se e
DC specs ). If lon ger tim e-o ut peri od s are desire d, co n-
figuration bits should be used to enable the WDT with
a gr eate r p res cale. Th us , ty pi ca l time-ou t p eri ods u p to
3.0 seconds can be realized.
The CLRWDT and SLEEP instructions clear the WDT
and its postsca le setting an d prevent it from timing out,
thus generating a device RESET condition.
The T O bit in the C PUSTA reg ister will be cleared upon
a WDT time-out.
17.3.2 CLEARING THE WDT AND
POSTSCALER
The WDT and postscaler are cleared when:
The device is in the RESET state
A SLEEP instruction is executed
A CLRWDT instruction is executed
Wake-up from SLEEP by an interrupt
The WDT counter/postscaler will start counting on the
first edge after the device exits the RESET state.
17.3.3 WDT PROGRAMMING
CONSIDERATIONS
It should also be taken in account that under worst case
conditions (VDD = Min., Temperature = Max., Max.
WDT postscaler), it may take several seconds before a
WDT time-out occurs.
The WDT and postscaler become the Power-up Timer
whenever the PWRT is invoked.
17.3.4 WDT AS NORMAL TIMER
When the WDT is sele cted a s a normal timer, the cloc k
source is the device clock. Neither the WDT nor the
postscaler are directly readable or writable. The over-
flow t ime i s 65536 TOSC cycles. On over flow, the TO bit
is cleared (d ev ice is not RESET) . The CLRWDT instruc-
tion can be used to set the T O bit. This allows the WDT
to be a simple overflow timer. The simple timer does
not increment when in SLEEP.
FIGURE 17-1: WATCHDOG TIMER BLOCK DIAGRAM
TABLE 17-2: REGISTERS/BITS ASSOCIATED WITH THE W A TCHDOG TIMER
WDT
WDT Enable
Postscaler
4 - to - 1 MUX WDTPS1:WDTPS0
On-chip RC
WDT Overflow
Oscillator(1)
Note 1: This oscilla tor i s separate fr om the external
RC oscillator on the OSC1 pin.
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on
POR, BOR MCLR, WDT
Config See Figure 17-1 for location of WDTPSx bits in Configuration Word. (Note 1) (Note 1)
06h, Unbanked CPUSTA STKAV GLINTD TO PD POR BOR --11 11qq --11 qquu
Legend: - = unimplemented, read as '0', q = value depends on condition. Shaded cells are not used by the WDT.
Note 1: This value will be as the device was programmed, or if unprogrammed, will read as all '1's.
PIC17C7XX
DS30289B-page 194 2000 Microchip Technology Inc.
17.4 Power-down Mode (SLEEP)
The Power-down mode is entered by executing a
SLEEP instructio n. This clears the W atchdo g Timer an d
postscaler (if enabled). The PD bit is cleared and the
TO bit is set (in the CPUSTA register). In SLEEP mode,
the osc illat or driv er is turned of f. The I/O p orts main tai n
their status (driving high,low, or hi-impedance input).
The MCLR/VPP pin must be at a logic high level
(VIHMC). A WDT time-out RESET does not drive the
MCLR/VPP pin low.
17.4.1 WAKE-UP FR OM SLEE P
The device can wake-up from SLEEP through one of
the following events:
Power-on Reset
Brown-out Reset
External RESET input on MCLR/VPP pin
WDT Reset (if WDT was enabled)
Interrupt from RA0/INT pin, RB port change,
T0CKI interrupt, or some peripheral interrupts
The follo wing periph eral interrupt s can wake the device
from SLEEP:
Capture interrupts
USART synchronous slave transmit interrupts
USART synchronous slave receive interrupts
A/D con ve rsi on complete
SPI slave trans mi t/rec ei ve co mp lete
I2C slave receive
Other per ipherals cann ot generate interrup ts since d ur-
ing SLEEP, no on-chip Q clocks are present.
Any RESET event will cause a device RESET. Any
interrupt ev ent is consid ered a co ntinua tion of pro gram
executi on. The TO and PD bits in the CPUSTA register
can be used to determine the cause of a device
RESET. The PD bit, which is set on power-up, is
cleared when SLEEP is invoked. The TO bit is cleared
if WD T time -out occur red (and ca used a RESET).
When the SLEEP instruction is being execut ed, the next
instruction (PC + 1) is pre-fetched. For the device to
wake-up thro ugh an interrupt eve nt, the co rres pon din g
interrupt enable bit must be set (enabled). Wake-up is
regardless of the state of the GLINTD bit. If the GLINTD
bit is set (disabled), the device continues execution at
the instruction after the SLEEP instruction. If the
GLINTD bit is clear (enabled), the device executes the
instruction after the SLEEP instruction and then
branches to the interrupt vector address. In cases
where the ex ecution of the ins truction follow ing SLEEP
is not desirable, the user should have a NOP after the
SLEEP instruction.
The WDT is cleared when the device wakes from
SLEEP, regardless of the source of wake-up.
17.4.1.1 Wake-up Delay
When the oscillator type is configured in XT or LF
mode, the Oscillator Start-up Timer (OST) is activated
on wake-up. The OST will keep the device in RESET
for 1024TOSC. This needs to be taken into account
when considering the interrupt response time when
coming out of SLEEP.
FIGURE 17-2: WAKE-UP FROM SLEEP THROUGH INTERRUPT
Note: If the global interrupt is disabled (GLINTD
is set), but any interrupt source has both its
interrupt enable bit and the corresponding
interrupt flag bit set, the device will imme-
diately wake-up from SLEEP. The T O bit is
set and the PD bit is cleared.
Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4 Q2Q1 Q3 Q4
OSC1
CLKOUT(4)
INT
INTF Flag
GLINTD bit
INST RUCTION FL OW
PC
Instruction
Fetched
Instruction
Executed
Interrupt Latency(2)
PC PC+1 PC+2 0004h 0005h
Dummy Cycle
Inst (PC) = SLEEP Inst (PC+ 1 )
Inst (PC-1) SLEEP
TOST(2)
Processor
in SLEEP
Inst ( PC+2)
Inst ( PC+1)
Note 1: XT or LF oscillator mode assumed.
2: TOST = 1024TOSC (drawing not to scale). This delay will not be there for RC osc mode.
3: When GLINTD = 0, processor jumps to interrupt routine after wake-up. If GLINTD = 1, execution will continue in line.
4: CLKOUT is not available in these osc modes, but shown here for timing reference.
(RA0/INT pin) 0 or 1
2000 Microchip Technology Inc. DS30289B-page 195
PIC17C7XX
17.4.2 MINIMIZING CURRENT
CONSUMPTION
To minimize current consumption, all I/O pins should be
either at VDD, or VSS, with no external circui try drawin g
current fro m the I/O pin . I/O pin s that are hi-i mped ance
inputs should be pulled high or low externally to avoid
switching currents caused by floating inputs. The
T0CKI inpu t should be a t VDD or VSS. The contribut ions
from on-chip pull-ups on PORTB should also be con-
sidered and disabled, when possible.
17.5 Code Protection
The code in the program memory can be protected by
selecting the microcontroller in Code Protected mode
(PM2:PM0 = 000).
In this mode, instructions that are in the on-chip pro-
gram memory space, can continue to read or write the
program memory. An instruction that is executed out-
side of the internal program memory range will be
inhibited from writing to, or reading from, program
memory.
If the code protection bit(s) have not been pro-
grammed, the on-chip program memory can be read
out for verification purposes.
Note: Microchip does not recommend code pro-
tecting w ind owed devices .
PIC17C7XX
DS30289B-page 196 2000 Microchip Technology Inc.
17.6 In-Circuit Serial Programming
The PIC17C7XX group of the high-end family
(PIC17CXXX) has an added feature that allows serial
programming while in the end applicati on circuit. This is
simply done with tw o lines for cl ock and data and thre e
other lines for power, ground, and the programming
voltage. This allows customers to manufacture boards
with unprogrammed devices and then program the
microcontroller just before shipping the product. This
also all ows the m ost recent fi rmwa re, or a custom firm-
ware to be programmed.
Devices may be serialized to m ake the product unique;
special variants of the product may be offered and
code updates are possible. This allows for increased
des ign flexibility.
To place the device into the Serial Programming Test
mode, two pins will need to be placed at VIHH. These
are the TEST pin and the MCLR/VPP pin. Also, a
sequence of events must occur as follows:
1. The TEST pin is placed at VIHH.
2. The MCLR/VPP pin is placed at VIHH.
There is a setup time between step 1 and step 2 that
must be met.
Aft er this sequen ce, the Prog ram Counter is pointing to
program memory address 0xFF60. This location is in
the Boot ROM. The code initializes the USART/SCI so
that it can re ceive c ommands. For t his, the d evice m ust
be cl ocked. Th e device c lock so urce in this mode is th e
RA1/T0CKI pi n. After dela ying to allow the USART/SCI
to initialize, commands can be received. The flow is
shown in these 3 steps:
1. The de vice cl ock source starts.
2. Wait 80 device clocks for Boot ROM code to
configure the USART/SCI.
3. Commands may now be sent.
For complete details of serial programming, please
refer to the PIC17C7XX Programming Specification.
(Contact your local Microchip Technology Sales Office
for availability.)
FIGURE 17-3: TYPICAL IN-CIRCUIT
SERIAL PROGRAMMING
CONNECTION
TABLE 17-3: ICSP INTERFACE PINS
External
Connector
Signals
To Normal
Connections
To Normal
Connections
PIC17C7XX
VDD
VSS
MCLR/VPP
RA1/T0CKI
RA4/RX1/DT1
+5V
0V
VPP
Dev. CLK
Data I/O
VDD
RA5/TX1/CK1Data CLK
TEST
TEST CNTL
During Programming
Name Function Type Description
RA4/RX1/DT1 DT I/O Serial Data
RA5/TX1/CK1 CK I Ser ial C lock
RA1/T0CKI OSCI I Device Clock Source
TEST TEST I Test mode selection control input, force to VIHH
MCLR/VPP MCLR/VPP P Master Clear Reset and Device Progr amming Voltage
VDD VDD P Positive supply for logic and I/O pins
VSS VSS P Ground reference for logic and I/O pins
2000 Microchip Technology Inc. DS30289B-page 197
PIC17C7XX
18.0 INSTRUCTION SET SUMMARY
The PIC17CXXX instruction set consists of 58 instruc-
tions. Each instruction is a 16-bit word divided into an
OPCODE and one or more operands. The opcode
specifies the instruction type, while the operand(s) fur-
ther specify the operation of the instruction. The
PIC17CXXX instruction set can be grouped into three
types:
byte-oriented
bit-oriented
literal and control operations
These formats are shown in Figure 18-1.
Table 18-1 shows the field descriptions for the
opcode s. These descriptions are useful for understand-
ing the opcodes in Table 18-2 and in each specific
instruction descriptions.
For byte-oriented instructions, 'f' represents a file
register designator and 'd' represents a destination
designator. The file register designator specifies which
file register is to be used by the instruction.
The desti nation designator specifies where the result of
the operation is to be placed. If 'd' = '0', the result is
placed in the WREG register. If 'd' = '1', the result is
placed in the file register specified by the instruction.
For bit-oriented instructions, 'b' represents a bit field
design ator which selec t s the nu mb er of the bi t affe cted
by the operation, while 'f' represents the number of the
file in which the bit is located.
For literal and control operations, 'k' represent s an 8-
or 13-bit constant or literal value.
The instruction set is highly orthogonal and is grouped
into:
byte-oriented operations
bit-oriented operations
literal and control operations
All instructions are executed within one single instruc-
tion cycl e, un le ss :
a conditional test is true
the program counter is changed as a result of an
instruction
a t able read or a t able write instruction is ex ecuted
(in this case, the execution takes two instruction
cycles with the second cycle executed as a NOP)
One instr uction cycle co nsists of four os cillator periods .
Thus, for an oscillat or frequency of 25 MHz, the no rmal
instruc tion executio n time is 160 ns. If a cond itional test
is true or th e progra m coun ter is chan ged as a resul t of
an instruction, the instruction execution time is 320 ns.
TABLE 18-1: OPCODE FIELD
DESCRIPTIONS
Field Description
fRegister file address (00h to FFh)
pPeripheral register file address (00h to 1Fh)
iTable pointer control i = 0 (do not change)
i = 1 (increment after instruction execution)
tTable byte select t = 0 (perform operation on lower
byte)
t = 1 (perform operation on upper byte literal field,
constant data)
WREG Working register (accumulator)
bBit address within an 8-bit file register
kLiteral field, constant data or label
xDont 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.
dDestination select
0 = store result in WREG
1 = store result in file register f
Default is d = 1
uUnused, encoded as 0
sDestination select
0 = store result in file register f and in the WREG
1 = store result in file register f
Default is s = 1
label Label name
C,DC,
Z,OV
ALU status bit s Carry, Digit Carry, Zero, Overflow
GLINTD Global Interrupt Disable bit (CPUSTA<4>)
TBLPTR Table Pointer (16-bit)
TBLAT Table Latch (16-bit) consists of high byte (TBLATH)
and low byte (TBLATL)
TBLATL Table Latch low byte
TBLATH Table Latch high byte
TOS Top-of-Stack
PC Program Counter
BSR Bank Select Register
WDT Watchdog Timer Counter
TO Time-out bit
PD Power-down bit
dest Destination either the WREG register or the speci-
fied register file location
[ ] Options
( ) Contents
Assigned to
< > Register bit field
In the set of
italics User defined term (font is courier)
PIC17C7XX
DS30289B-page 198 2000 Microchip Technology Inc.
Table 18-2 lists the instructions recognized by the
MPASM assemb ler.
All instruction examples use the following format to rep-
resent a hexadecimal number:
0xhh
where h signifies a hexadecimal digit.
To represent a binary number:
0000 0100b
where b signifies a binary string.
FIGURE 18-1: GENERAL FORMAT FOR
INSTRUCTIONS
18.1 Specia l Function Registers as
Source/Destination
The PIC17C7XXs orthogonal instruction set allows
read and write of all file registers, including special
function registers. There are some special situations
the user should be aware of:
18.1.1 ALUSTA AS DESTINATION
If an in struction wri tes to ALUSTA, the Z, C, DC and OV
bits may be set or cleared as a result of the instruction
and overwrite the original data bits written. For exam-
ple, executing CLRF ALUSTA will clear register
ALUSTA and then set the Z bit leaving 0000 0100b in
the register.
18.1.2 PCL AS SOURCE OR DESTINATION
Read, wri te or read-mo dify-wri te on PC L may hav e th e
following results:
Read PC: PCH PCLATH; PCL dest
Write PCL: PCLATH PCH;
8-bit destination value PCL
Read-Modify-Write: PCL ALU operand
PCLATH PCH;
8-bit result PCL
Where PCH = program counter high byte (not an
addressable register), PCLATH = Program counter
high holding latch, dest = destination, WREG or f.
18.1.3 BIT MANIPULATION
All bit manipulation instructions are done by first read-
ing the entire register, oper ating on t he selec ted bit an d
writing the result back (read-modify-write (R-M-W)).
The user should keep this in mind when operating on
some special function r egisters, such as ports.
Note 1: Any unused opcode is Reserved. Use of
any reserved opcode may cause unex-
pect ed ope rati on.
Byte-oriented file register operations
15 9 8 7 0
d = 0 for destination WREG
OPCODE d f (FILE #)
d = 1 for destination f
f = 8-bit file register address
Bit-oriented file register operations
15 11 10 8 7 0
OP C O DE b (BIT #) f (FILE #)
b = 3-bit address
f = 8-bit file register address
Literal and control operations
15 8 7 0
OPCODE k (literal)
k = 8-bit immediate value
Byte to Byte move operations
15 13 12 8 7 0
OPCODE p (FILE #) f (FILE #)
CALL and GOTO operations
15 13 12 0
OPCODE k (literal)
k = 13-bit immediate value
p = peripheral register file address
f = 8-bit file register address
Note: Status bits that are manipulated by the
device (including the interrupt flag bits) are
set or cleared in the Q1 cycle. So, there is
no issue on doing R-M-W instructions on
registers which contain these bits
2000 Microchip Technology Inc. DS30289B-page 199
PIC17C7XX
18.2 Q Cycle Activity
Each instruction cycle (TCY) is comprised of four Q
cycles (Q1-Q4). The Q cycle is the same as the device
oscill ator cycle (TOSC). The Q cycles provide the timing/
designation for the Decode, Read, Process Data,
Wr ite , etc ., of eac h in stru cti on cycle. The following dia-
gram shows the relationship of the Q cycles to the
instruction cycle.
The four Q cycles that make up an instruction cycle
(TCY) can be generalized as:
Q1: Instruction Decode Cycle or forced No
operation
Q2: Instruction Read Cycle or No operation
Q3: Process the Data
Q4: Instruction Write Cycle or No operation
Each instruction will show the detailed Q cycle opera-
tion for the instruction.
FIGURE 18-2: Q CYCLE ACTIVITY
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
TCY1TCY2TCY3
TOSC
PIC17C7XX
DS30289B-page 200 2000 Microchip Technology Inc.
TABLE 18-2: PIC17CXXX INSTRUCTION SET
Mnemonic,
Operands Description Cycles 16-bit Opcode Status
Affected Notes
MSb LSb
BYTE-ORIENTED FIL E REGISTER OPERATIONS
ADDWF f,d ADD WREG to f 1 0000 111d ffff ffff OV,C,DC,Z
ADDWFC f,d ADD WREG and Carry bit to f 1 0001 000d ffff ffff OV,C,DC,Z
ANDWF f,d AND WREG with f 1 0000 101d ffff ffff Z
CLRF f,s Clear f, or Clear f and Clear WREG 1 0010 100s ffff ffff None 3
COMF f,d Complement f 1 0001 001d ffff ffff Z
CPFSEQ f Compare f with WREG, skip if f = WREG 1 (2) 0011 0001 ffff ffff None 6,8
CPFSGT f Compare f with WREG, skip if f > WREG 1 (2) 0011 0010 ffff ffff None 2,6,8
CPFSLT f Compare f with WREG, skip if f < WREG 1 (2) 0011 0000 ffff ffff None 2,6,8
DAW f,s Decimal Adjust WREG Register 1 0010 111s ffff ffff C3
DECF f,d Decrement f 1 0000 011d ffff ffff OV,C,DC,Z
DECFSZ f,d Decrement f, skip if 0 1 (2) 0001 011d ffff ffff None 6,8
DCFSNZ f,d Dec rement f, skip if not 0 1 (2) 0010 011d ffff ffff None 6,8
INCF f,d Increment f 1 0001 010d ffff ffff OV,C,DC,Z
INCFSZ f,d Increment f, skip if 0 1 (2) 0001 111d ffff ffff None 6,8
INFSNZ f,d Increment f, skip if not 0 1 (2) 0010 010d ffff ffff None 6,8
IORWF f,d Inclusive OR WREG with f 1 0000 100d ffff ffff Z
MOVFP f,p Move f to p 1 011p pppp ffff ffff None
MOVPF p,f Move p to f 1 010p pppp ffff ffff Z
MOVWF f Move WREG to f 1 0000 0001 ffff ffff None
MULWF f Multiply WREG with f 1 0011 0100 ffff ffff None
NEGW f,s Negate WREG 1 0010 110s ffff ffff OV,C,DC,Z 1,3
NOP No Operation 1 0000 0000 0000 0000 None
RLCF f,d Rotate left f through Carry 1 0001 101d ffff ffff C
RLNCF f,d Rotate l e ft f (n o c a rr y) 1 0010 001d ffff ffff None
RRCF f,d Rotate right f through Carry 1 0001 100d ffff ffff C
RRNCF f,d Rotate right f (no carry) 1 0010 000d ffff ffff None
SETF f,s Set f 1 0010 101s ffff ffff None 3
SUBWF f,d Subtract WREG from f 1 0000 010d ffff ffff OV,C,DC,Z 1
SUBWFB f,d Subtract WREG from f with Bo rrow 1 0000 001d ffff ffff OV,C,DC,Z 1
SWAPF f,d Swap f 1 0001 110d ffff ffff None
TABLRD t,i,f Table Read 2 (3) 1010 10ti ffff ffff None 7
TABLWT t,i,f Table Write 2 1010 11ti ffff ffff None 5
TLRD t,f Table Latch Read 1 1010 00tx ffff ffff None
TLWT t,f Table Latch Write 1 1010 01tx ffff ffff None
Legend: Refer to Table 18-1 for opcode field descriptions.
Note 1: 2s Complement method.
2: Unsigned arithmetic.
3: If s = '1', only the file is affected: If s = '0', both the WREG register and the file are affected; If only the Working register
(WREG) is required to be affected, then f = WREG must be specified.
4: During an LCALL, the contents of PCLATH are loaded into the MSB of the PC and kkkk kkkk is loaded into the LSB of the
PC (PCL).
5: Multiple cycle instruction for EPROM programming when table pointer selects internal EPROM. The instruction is termi-
nated by an interrupt event. When writing to external program memory, it is a two-cycle instruction.
6: Two-cycle instruction when condition is true, else single cycle instruction.
7: Two-cycle instruction except for TABLRD to PCL (program counter low byte), in which case it takes 3 cycles.
8: A skip means that instruction fetched during execution of current instruction is not executed, instead a NOP is executed.
2000 Microchip Technology Inc. DS30289B-page 201
PIC17C7XX
TSTFSZ f Test f, skip if 0 1 (2) 0011 0011 ffff ffff None 6,8
XORWF f,d Exclusive OR WREG with f 1 0000 110d ffff ffff Z
BIT-ORIENTED FILE REGISTER OPERATIONS
BCF f,b Bit Clear f 1 1000 1bbb ffff ffff None
BSF f,b Bit Set f 1 1000 0bbb ffff ffff None
BTFSC f,b B it test, skip if clear 1 (2) 1001 1bbb ffff ffff None 6,8
BTFSS f,b B it test, skip i f set 1 (2) 1001 0bbb ffff ffff None 6,8
BTG f,b Bit Toggle f 1 0011 1bbb ffff ffff None
LITERAL AND CONTROL OPERATIONS
ADDLW k ADD literal to WREG 1 1011 0001 kkkk kkkk OV,C,DC,Z
ANDLW k A ND literal with WREG 1 1011 0101 kkkk kkkk Z
CALL k Subroutine Call 2 111k kkkk kkkk kkkk None 7
CLRWDT Clear Watchdog Timer 1 0000 0000 0000 0100 TO, PD
GOTO k Unconditional Branch 2 110k kkkk kkkk kkkk None 7
IORLW k Inclusive OR literal with WREG 1 1011 0011 kkkk kkkk Z
LCALL k Long Call 2 1011 0111 kkkk kkkk None 4,7
MOVLB k Move literal to low nibble in BSR 1 1011 1000 uuuu kkkk None
MOVLR k Move literal to high nibble in BSR 1 1011 101x kkkk uuuu None
MOVLW k Move l ite ral to WREG 1 1011 0000 kkkk kkkk None
MULLW k Multiply literal with WREG 1 1011 1100 kkkk kkkk None
RETFIE Return from interrupt (and enable interrupts) 2 0000 0000 0000 0101 GLINTD 7
RETLW k Return literal to WREG 2 1011 0110 kkkk kkkk None 7
RETURN Return from subroutine 2 0000 0000 0000 0010 None 7
SLEEP Enter SLEEP mode 1 0000 0000 0000 0011 TO, PD
SUBLW k S ubtract WREG from literal 1 1011 0010 kkkk kkkk OV,C,DC,Z
XORLW k Exclusive OR literal with WREG 1 1011 0100 kkkk kkkk Z
TABLE 18-2: PIC17CXXX INSTRUCTION SET (CONTINUED)
Mnemonic,
Operands Description Cycles 16-bit Opcode Status
Affected Notes
MSb LSb
Legend: Refer to Table 18-1 for opcode field descriptions.
Note 1: 2s Complement method.
2: Unsigned arithmetic.
3: If s = '1', only the file is affected: If s = '0', both the WREG register and the file are affected; If only the Working register
(WREG) is required to be affected, then f = WREG must be specified.
4: During an LCALL, the contents of PCLATH are loaded into the MSB of the PC and kkkk kkkk is loaded into the LSB of the
PC (PCL).
5: Multiple cycle instruction for EPROM programming when table pointer selects internal EPROM. The instruction is termi-
nated by an interrupt event. When writing to external program memory, it is a two-cycle instruction.
6: Two-cycle instruction when condition is true, else single cycle instruction.
7: Two-cycle instruction except for TABLRD to PCL (program counter low byte), in which case it takes 3 cycles.
8: A skip means that instruction fetched during execution of current instruction is not executed, instead a NOP is executed.
PIC17C7XX
DS30289B-page 202 2000 Microchip Technology Inc.
ADDLW ADD Literal to WREG
Syntax: [ label ] ADDLW k
Operands: 0 k 255
Operation: (WREG) + k (WREG)
Status Affected: OV, C, DC, Z
Encoding: 1011 0001 kkkk kkkk
Description: The contents of WREG are added to
the 8-bit literal k and the result is
placed in WREG.
:RUGV
&\FOHV
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal kProcess
Data Write to
WREG
Example:ADDLW 0x15
Before Instruction
WREG = 0x10
After Instruction
WREG = 0x25
ADDWF ADD WREG to f
Syntax: [ label ] ADDWF f,d
Operands: 0 f 255
d [0,1]
Operation: (WREG) + (f) (dest)
Status Af fe cte d: OV, C, DC, Z
Encoding: 0000 111d ffff ffff
Description: Add WREG to register f. If d is 0 the
result is stored in WREG. If d is 1 the
result is stored back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:ADDWF REG, 0
Before Instruc tio n
WREG = 0x17
REG = 0xC2
After Instruction
WREG = 0xD9
REG = 0xC2
2000 Microchip Technology Inc. DS30289B-page 203
PIC17C7XX
ADDWFC ADD WREG and Carry bit to f
Syntax: [ label ] ADDWFC f,d
Operands: 0 f 255
d [0,1]
Operation: (WREG) + (f) + C (dest)
Status Affected: OV, C, DC, Z
Encoding: 0001 000d ffff ffff
Description: Add WREG, the Carry Flag and data
memory location f. If d is 0, the result is
placed in WREG. If d is 1, the result is
placed in data memory location f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:ADDWFC REG 0
Before Instruction
Carry bit = 1
REG = 0x02
WREG = 0x4D
After Instruction
Carry bit = 0
REG = 0x02
WREG = 0x50
ANDLW And Literal with WREG
Syntax: [ label ] ANDLW k
Operands: 0 k 255
Operation: (WREG) .AND. (k) (WREG)
Status Af fe cte d: Z
Encoding: 1011 0101 kkkk kkkk
Description: The contents of WREG are ANDed with
the 8-bit literal 'k'. The result is placed in
WREG.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal
'k' Process
Data Write to
WREG
Example:ANDLW 0x5F
Before Instruc tio n
WREG = 0xA3
After Instruction
WREG = 0x03
PIC17C7XX
DS30289B-page 204 2000 Microchip Technology Inc.
ANDWF AND WREG with f
Syntax: [ label ] ANDWF f,d
Operands: 0 f 255
d [0,1]
Operation: (WREG) .AND. (f) (dest)
Status Affected: Z
Encoding: 0000 101d ffff ffff
Description: The content s of WREG are ANDed with
register 'f'. If 'd' is 0 the result is stored
in WREG. If 'd' is 1 the result is stored
back in register 'f'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write to
destination
Example:ANDWF REG, 1
Before Instruction
WREG = 0x17
REG = 0xC2
After Instruction
WREG = 0x17
REG = 0x02
BCF Bit Clear f
Syntax: [ label ] BCF f,b
Operands: 0 f 255
0 b 7
Operation: 0 (f<b>)
Status Af fe cte d: None
Encoding: 1000 1bbb ffff ffff
Description: Bit 'b' in register 'f' is cleared.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write
register 'f'
Example:BCF FLAG_REG, 7
Before Instruc tio n
FLAG_REG = 0xC7
After Instruction
FLAG_REG = 0x47
2000 Microchip Technology Inc. DS30289B-page 205
PIC17C7XX
BSF Bit Set f
Syntax: [ label ] BSF f,b
Operands: 0 f 255
0 b 7
Operation: 1 (f<b>)
Status Affected: None
Encoding: 1000 0bbb ffff ffff
Description: Bit b in register f is set.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
Example:BSF FLAG_REG, 7
Before Instruction
FLAG_REG = 0x0A
After Instruction
FLAG_REG = 0x8A
BTFSC Bit Test, skip if Clear
Syntax: [ label ] BTFSC f,b
Operands: 0 f 255
0 b 7
Operation: skip if (f<b>) = 0
Status Af fe cte d: None
Encoding: 1001 1bbb ffff 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 exe-
cution is discarded and a NOP is executed
instead, making this a two-cycle
instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE
FALSE
TRUE
BTFSC
:
:
FLAG,1
Before Instruc tio n
PC = address (HERE)
After Instruction
If FLAG<1> = 0;
PC = address (TRUE)
If FLAG<1> = 1;
PC = address (FALSE)
PIC17C7XX
DS30289B-page 206 2000 Microchip Technology Inc.
BTFSS Bit Test, skip if Set
Syntax: [ label ] BTFSS f,b
Operands: 0 f 127
0 b < 7
Operation: skip if (f<b>) = 1
Status Affected: None
Encoding: 1001 0bbb ffff 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 exe-
cution is discarded and a NOP is executed
instead, making this a two-cycle
instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE
FALSE
TRUE
BTFSS
:
:
FLAG,1
Before Instruction
PC = address (HERE)
After Instruction
If FLAG<1> = 0;
PC = address (FALSE)
If FLAG<1> = 1;
PC = address (TRUE)
BTG Bit Toggle f
Syntax: [ label ] BTG f,b
Operands: 0 f 255
0 b < 7
Operation: (f<b>) (f<b>)
Status Af fe cte d: None
Encoding: 0011 1bbb ffff ffff
Description: Bit b in data memory location f is
inverted.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
Example:BTG PORTC, 4
Before Instruc tio n:
PORTC = 0111 0101 [0x75]
After Instruction:
PORTC = 0110 0101 [0x65]
2000 Microchip Technology Inc. DS30289B-page 207
PIC17C7XX
CALL Subroutine Call
Syntax: [ label ] CALL k
Operands: 0 k 8191
Operation: PC+ 1 TOS, k PC<12:0>,
k<12:8> PCLATH<4:0>;
PC<15:13> PCLATH<7:5>
Status Affected: None
Encoding: 111k kkkk kkkk kkkk
Description: Subroutine call within 8K page. First,
return address (PC+1) is pushed onto
the stack. The 13-bit value is loaded
into PC bits<12:0>. Then the upper-
eight bits of the PC are copied into
PCLATH. CALL is a two-cycle
instruction.
See LCALL for calls outside 8K memory
space.
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal
k<7:0>,
Push PC to
stack
Process
Data Write to PC
No
operation No
operation No
operation No
operation
Example:HERE CALL THERE
Before Instruction
PC = Address(HERE)
After Instruction
PC = Address(THERE)
TOS = Address (HERE + 1)
CLRF Clear f
Syntax: [label] CLRF f,s
Operands: 0 f 255
Operation: 00h f, s [0,1]
00h dest
Status Af fe cte d: None
Encoding: 0010 100s ffff ffff
Description: Clears the contents of the specified
register(s).
s = 0: Data memory location f and
WREG are cleared.
s = 1: Data memory location f is
cleared.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
and if
specified
WREG
Example:CLRF FLAG_REG, 1
Before Instruc tio n
FLAG_REG = 0x5A
WREG = 0x01
After Instruction
FLAG_REG = 0x00
WREG = 0x01
PIC17C7XX
DS30289B-page 208 2000 Microchip Technology Inc.
CLRWDT Clear Watchdog Timer
Syntax: [ label ] CLRWDT
Operands: None
Operation: 00h WDT
0 WDT postscaler,
1 TO
1 PD
Status Affected: TO, PD
Encoding: 0000 0000 0000 0100
Description: CLRWDT instruction resets the Watch-
dog Tim er. It also resets the postscaler
of the WDT. Status bits TO and PD are
set.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No
operation Process
Data No
operation
Example:CLRWDT
Before Instruction
WDT counter = ?
After Instruction
WDT counter = 0x00
WDT Postscaler = 0
TO =1
PD =1
COMF Complement f
Syntax: [ label ] COMF f,d
Operands: 0 f 255
d [0,1]
Operation: (dest)
Status Af fe cte d: Z
Encoding: 0001 001d ffff ffff
Description: The contents of register f are comple-
mented. If d is 0 the result is stored in
WREG. If d is 1 the result is stored
back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:COMF REG1,0
Before Instruc tio n
REG1 = 0x13
After Instruction
REG1 = 0x13
WREG = 0xEC
(f)
2000 Microchip Technology Inc. DS30289B-page 209
PIC17C7XX
CPFSEQ Compare f with WREG,
skip if f = WREG
Syntax: [ label ] CPFSEQ f
Operands: 0 f 255
Operation: (f) (WREG),
skip if (f) = (WREG)
(unsigned comparison)
Status Affected: None
Encoding: 0011 0001 ffff ffff
Description: Compares the contents of data memory
location f to the contents of WREG by
performing an unsigned subtraction.
If f = WREG, then the fetched instruc-
tion is discarded and a NOP is executed
instead, making this a two-cycle
instruction.
Words: 1
Cycles: 1 (2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE CPFSEQ REG
NEQUAL :
EQUAL :
Before Instruction
PC Address = HERE
WREG = ?
REG = ?
After Instruction
If REG = WREG;
PC = Address
(EQUAL)
If REG WREG;
PC = Address
(NEQUAL)
CPFSGT Compare f with WREG,
skip if f > WREG
Syntax: [ label ] CPFSGT f
Operands: 0 f 255
Operation: (f) − (WREG),
skip if (f) > (WREG)
(unsign ed comp aris on )
Status Af fe cte d: None
Encoding: 0011 0010 ffff ffff
Description: Compares the contents of data memory
location f to the contents of the WREG
by performing an unsigned subtraction.
If the contents of f are greater than the
contents of WREG, then the fetched
instruction is discarded and a NOP is
executed instead, making this a
two-cycle instruct ion.
Words: 1
Cycles: 1 (2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE CPFSGT REG
NGREATER :
GREATER :
Before Instruc tio n
PC = Address (HERE)
WREG = ?
After Instruction
If REG > WREG;
PC = Address
(GREATER)
If REG £ WREG;
PC = Address (NGREATER)
PIC17C7XX
DS30289B-page 210 2000 Microchip Technology Inc.
CPFSLT Compare f with WREG,
skip if f < WREG
Syntax: [ label ] CPFSLT f
Operands: 0 f 255
Operation: (f) (WREG),
skip if (f) < (WREG)
(unsigned comparison)
Status Affected: None
Encoding: 0011 0000 ffff ffff
Description: Compares the contents of data memory
location f to the contents of WREG by
performing an unsigned subtraction.
If the contents of f are less than the
contents of WREG, then the fetched
instruction is discarded and a NOP is
executed instead, making this a
two-cycle instruct ion.
Words: 1
Cycles: 1 (2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE CPFSLT REG
NLESS :
LESS :
Before Instruction
PC = Address (HERE)
W= ?
After Instruction
If REG < WREG;
PC = Address (LESS)
If REG WREG;
PC = Address (NLESS)
DAW Decimal Adjust WREG Register
Syntax: [label] DAW f,s
Operands: 0 f 255
s [0,1]
Operation: If [ [WREG<7:4> > 9].OR.[C = 1] ].AND.
[WREG<3:0> > 9]
then
WREG<7:4> + 7 f<7:4>, s<7:4>;
If [WREG<7:4> > 9].OR.[C = 1]
then
WREG<7:4> + 6 f<7:4>, s<7:4>;
else
WREG<7:4> f<7:4>, s<7:4>;
If [WREG<3:0> > 9].OR.[DC = 1]
then
WREG<3:0> + 6 f<3:0>, s<3:0>;
else
WREG<3:0> f<3:0>, s<3:0>
Status Af fe cte d: C
Encoding: 0010 111s ffff ffff
Description: DAW adjusts the eight-bit value in
WREG, resulting from the earlier addi-
tion of two variables (each in packed
BCD format) and produces a correct
packed BCD result.
s = 0: Result is placed in Data
memory location f and
WREG.
s = 1: Result is placed in Data
memory location f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
and other
specified
register
Example:DAW REG1, 0
Before Instruc tio n
WREG = 0xA5
REG1 = ??
C=0
DC = 0
After Instruction
WREG = 0x05
REG1 = 0x05
C=1
DC = 0
2000 Microchip Technology Inc. DS30289B-page 211
PIC17C7XX
DECF Decrement f
Syntax: [ label ] DECF f,d
Operands: 0 f 255
d [0,1]
Operation: (f) 1 (dest)
Status Affected: OV, C, DC, Z
Encoding: 0000 011d ffff ffff
Description: Decrement register f. If d is 0, the
result is stored in WREG. If d is 1, the
result is stored back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:DECF CNT, 1
Before Instruction
CNT = 0x01
Z=0
After Instruction
CNT = 0x00
Z=1
DECFSZ Decrement f, skip if 0
Syntax: [ label ] DECFSZ f,d
Operands: 0 f 255
d [0,1]
Operation: (f) 1 (dest);
skip if result = 0
Status Af fe cte d: None
Encoding: 0001 011d ffff ffff
Description: The contents of register f are decre-
mented. If d is 0, the result is placed in
WREG. 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
and a NOP is executed instead, making
it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE DECFSZ CNT, 1
GOTO HERE
NZERO
ZERO
Before Instruc tio n
PC = Address (HERE)
After Instruction
CNT = CNT - 1
If CNT = 0;
PC = Address (HERE)
If CNT 0;
PC = Address (NZERO)
PIC17C7XX
DS30289B-page 212 2000 Microchip Technology Inc.
DCFSNZ Decrement f, skip if not 0
Syntax: [label] DCFSNZ f,d
Operands: 0 f 255
d [0,1]
Operation: (f) 1 (dest);
skip if not 0
Status Affected: None
Encoding: 0010 011d ffff ffff
Description: The contents of register f are decre-
mented. If d is 0, the result is placed in
WREG. If d is 1, the result is placed
back in register f.
If the result is not 0, the next instruc-
tion, which is already fetched is dis-
carded and a NOP is executed instead,
making it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE DCFSNZ TEMP, 1
ZERO :
NZERO :
Before Instruction
TEMP_VALUE = ?
After Instruction
TEM P_VALUE = TEMP_VALUE - 1,
If TEMP_VALUE = 0;
PC = Address (ZERO)
If TEMP_VALUE 0;
PC = Address (NZERO)
GOTO Unconditional Branch
Syntax: [ label ] GOTO k
Operands: 0 k 8191
Operation: k PC<12:0>;
k<12:8> PCLATH<4:0>,
PC<15:13> PCLATH<7:5>
Status Af fe cte d: None
Encoding: 110k kkkk kkkk kkkk
Description: GOTO allows an unconditional branch
anywhere within an 8K page boundary .
The thirteen-bit immediate value is
loaded into PC bits <12:0>. Then the
upper eight bits of PC are loaded into
PCLATH. GOTO is always a two-cycle
instruction.
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal
kProcess
Data Write to PC
No
operation No
operation No
operation No
operation
Example:GOTO THERE
After Instruction
PC = Address (THERE)
2000 Microchip Technology Inc. DS30289B-page 213
PIC17C7XX
INCF Increment f
Syntax: [ label ] INCF f,d
Operands: 0 f 255
d [0,1]
Operation: (f) + 1 (dest)
Status Affected: OV, C, DC, Z
Encoding: 0001 010d ffff ffff
Description: The contents of register f are incre-
mented. If d is 0, the result is placed in
WREG. If d is 1, the result is placed
back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:INCF CNT, 1
Before Instruction
CNT = 0xFF
Z=0
C=?
After Instruction
CNT = 0x00
Z=1
C=1
INCFSZ Increment f, skip if 0
Syntax: [ label ] INCFSZ f,d
Operands: 0 f 255
d [0,1]
Operation: (f) + 1 (dest)
skip if result = 0
Status Af fe cte d: None
Encoding: 0001 111d ffff ffff
Description: The contents of register f are incre-
mented. If d is 0, the result is placed in
WREG. 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
and a NOP is executed instead, making
it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE INCFSZ CNT, 1
NZERO :
ZERO :
Before Instruc tio n
PC = Address (HERE)
After Instruction
CNT = CNT + 1
If CNT = 0;
PC = Address(ZERO)
If CNT 0;
PC = Address(NZERO)
PIC17C7XX
DS30289B-page 214 2000 Microchip Technology Inc.
INFSNZ Increment f, skip if not 0
Syntax: [label] INFSNZ f,d
Operands: 0 f 255
d [0,1]
Operation: (f) + 1 (dest),
skip if not 0
Status Affected: None
Encoding: 0010 010d ffff ffff
Description: The contents of register f are incre-
mented. If d is 0, the result is placed in
WREG. If d is 1, the result is placed
back in register f.
If the result is not 0, the next instruction,
which is already fetched is discarded
and a NOP is executed instead, making
it a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE INFSNZ REG, 1
ZERO
NZERO
Before Instruction
REG = REG
After Instruction
REG = REG + 1
If REG = 1;
PC = Address (ZERO)
If REG = 0;
PC = Address (NZERO)
IORLW Inclusive OR Literal with WREG
Syntax: [ label ] IORLW k
Operands: 0 k 255
Operation: (WREG) .OR. (k) (WREG)
Status Af fe cte d: Z
Encoding: 1011 0011 kkkk kkkk
Description: The contents of WREG are ORed with
the eight-bit literal 'k'. The result is
placed in WREG.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal 'k' Process
Data Write to
WREG
Example:IORLW 0x35
Before Instruc tio n
WREG = 0x9A
After Instruction
WREG = 0xBF
2000 Microchip Technology Inc. DS30289B-page 215
PIC17C7XX
IORWF Inclusive OR WREG with f
Syntax: [ label ] IORWF f,d
Operands: 0 f 255
d [0,1]
Operation: (WREG) .OR. (f) (dest)
Status Affected: Z
Encoding: 0000 100d ffff ffff
Description: Inclusive OR WREG with register f. If
d is 0, the result is placed in WREG. If
d is 1, the result is placed back in
register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:IORWF RESULT, 0
Before Instruction
RESULT = 0x13
WREG = 0x91
After Instruction
RESULT = 0x13
WREG = 0x93
LCALL Long Call
Syntax: [ label ] LCALL k
Operands: 0 k 255
Operation: PC + 1 TOS;
k PCL, (PCLATH) PCH
Status Af fe cte d: None
Encoding: 1011 0111 kkkk kkkk
Description: LCALL allows an unconditional subrou-
tine call to anywhere within the 64K
program memory space.
First, the return address (PC + 1) is
pushed onto the stack. A 16-bit desti-
nation address is then loaded into the
program counter . The lower 8-bits of
the destination address are embedded
in the instruction. The upper 8-bits of
PC are loaded from PC high holding
latch, PCLATH.
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal kProcess
Data Write
register PCL
No
operation No
operation No
operation No
operation
Example:MOVLW HIGH(SUBROUTINE)
MOVPF WREG, PCLATH
LCALL LOW(SUBROUTINE)
Before Instruc tio n
SUBROUTINE = 16-bit Address
PC = ?
After Instruction
PC = Address (SUBROUTINE)
PIC17C7XX
DS30289B-page 216 2000 Microchip Technology Inc.
MOVFP Move f to p
Syntax: [label] MOVFP f,p
Operands: 0 f 255
0 p 31
Operation: (f) (p)
Status Affected: None
Encoding: 011p pppp ffff ffff
Description: Move data f rom data memory location f
to data memory location p. Location f
can be anywhere in the 256 byte data
space (00h to FFh), while p can be 00h
to 1Fh.
Either p' or 'f' can be WREG (a useful,
special situation).
MOVFP is particularly useful for transfer-
ring a data memory location to a periph-
eral register (such as the transmit buffer
or an I/O port). Both 'f' and 'p' can be
indirectly addressed.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write
register 'p'
Example:MOVFP REG1, REG2
Before Instruction
REG1 = 0x33,
REG2 = 0x11
After Instruction
REG1 = 0x33,
REG2 = 0x33
MOVLB Move Literal to low nibble in BSR
Syntax: [ label ] MOVLB k
Operands: 0 k 15
Operation: k (BSR<3:0>)
Status Affected: None
Encoding: 1011 1000 uuuu kkkk
Description: The four-bit literal k is loaded in the
Bank Select Register (BSR). Only the
low 4-bits of the Bank Select Register
are affected. The upper half of the BSR
is unchanged. The assembler will
encode the u fields as '0'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal 'k' Process
Data Write literal
'k' to
BSR<3:0>
Example:MOVLB 5
Before Instruc tio n
BSR register = 0x22
After Instruction
BSR register = 0x25 (Bank 5)
2000 Microchip Technology Inc. DS30289B-page 217
PIC17C7XX
MOVLR Move Literal to high nibble in
BSR
Syntax: [ label ] MOVLR k
Operands: 0 k 15
Operation: k (BSR<7:4>)
Status Affected: None
Encoding: 1011 101x kkkk uuuu
Description: The 4-bit literal k is loaded into the
most significant 4-bits of the Bank
Select Register (BSR). Only the high
4-bits of the Bank Select Register
are affected. The lower half of the
BSR is unchanged. The assembler
will encode the u fields as 0.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read literal
'k' Process
Data Write
literal 'k' to
BSR<7:4>
Example:MOVLR 5
Before Instruction
BSR register = 0x22
After Instruction
BSR register = 0x52
MOVLW Move Literal to WREG
Syntax: [ label ] MOVLW k
Operands: 0 k 255
Operation: k (WREG)
Status Af fe cte d: None
Encoding: 1011 0000 kkkk kkkk
Description: The eight-bit literal 'k' is loaded into
WREG.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal 'k' Process
Data Write to
WREG
Example:MOVLW 0x5A
After Instruction
WREG = 0x5A
PIC17C7XX
DS30289B-page 218 2000 Microchip Technology Inc.
MOVPF Move p to f
Syntax: [label] MOVPF p,f
Operands: 0 f 255
0 p 31
Operation: (p) (f)
Status Affected: Z
Encoding: 010p pppp ffff ffff
Description: Move data from data memory location
p to data memory location f. Location
f can be anywhere in the 256 byte data
space (00h to FFh), while p can be 00h
to 1Fh.
Either p or f can be WREG (a useful,
special situation).
MOVPF is particularly useful for transfer-
ring a peripheral register (e.g. the timer
or an I/O port) to a data memory loca-
tion. Both f and p can be indirectly
addressed.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register pProcess
Data Write
register f
Example:MOVPF REG1, REG2
Before Instruction
REG1 = 0x11
REG2 = 0x33
After Instruction
REG1 = 0x11
REG2 = 0x11
MOVWF Move WREG to f
Syntax: [ label ] MOVWF f
Operands: 0 f 255
Operation: (WREG) (f)
Status Af fe cte d: None
Encoding: 0000 0001 ffff ffff
Description: Move data from WREG to register f.
Location f can be anywhere in the 256
byte data space.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
Example:MOVWF REG
Before Instruc tio n
WREG = 0x4F
REG = 0xFF
After Instruction
WREG = 0x4F
REG = 0x4F
2000 Microchip Technology Inc. DS30289B-page 219
PIC17C7XX
MULLW Multiply Literal with WREG
Syntax: [ label ] MULLW k
Operands: 0 k 255
Operation: (k x WREG) PRODH:PRODL
Status Affected: None
Encoding: 1011 1100 kkkk kkkk
Description: An unsigned multiplication is carried
out between the contents of WREG
and the 8-bit literal k. The 16-bit
result is placed in PRODH:PRODL
register pair. PRODH contains the
high byte.
WREG is unchanged.
None of the status flags are affected.
Note that neither overflow, nor carry
is possible in this operation. A zero
result is possible, but not detected.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal kProcess
Data Write
registers
PRODH:
PRODL
Example:MULLW 0xC4
Before Instruction
WREG = 0xE2
PRODH = ?
PRODL = ?
After Instruc tio n
WREG = 0xC4
PRODH = 0xAD
PRODL = 0x08
MULWF Multiply WREG with f
Syntax: [ label ] MULWF f
Operands: 0 f 255
Operation: (WREG x f) PRODH:PRODL
Status Af fe cte d: None
Encoding: 0011 0100 ffff ffff
Description: An unsigned multiplication is carried
out between the contents of WREG
and the register file location f. The
16-bit result is stored in the
PRODH:PRODL register pair.
PRODH contains the high byte.
Both WREG and f are unchanged.
None of the status flags are affe cted.
Note that neither overflow, nor carry
is possible in this operation. A zero
result is possible, but not detected.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
registers
PRODH:
PRODL
Example:MULWF REG
Before Instruction
WREG = 0xC4
REG = 0xB5
PRODH = ?
PRODL = ?
Af ter Ins truction
WREG = 0xC4
REG = 0xB5
PRODH = 0x8A
PRODL = 0x94
PIC17C7XX
DS30289B-page 220 2000 Microchip Technology Inc.
NEGW Negate W
Syntax: [label] NEGW f,s
Operands: 0 f 255
s [0,1]
Operation: WREG + 1 (f);
WREG + 1 s
Status Affected: OV, C, DC, Z
Encoding: 0010 110s ffff ffff
Description: WREG is negated using twos comple -
ment. If 's' is 0, the result is placed in
WREG and data memory location 'f'. If
's' is 1, the result is placed only in data
memory location 'f'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write
register 'f'
and other
specified
register
Example:NEGW REG,0
Before Instruction
WREG = 0011 1010 [0x3A],
REG =1010 1011 [0xAB]
After Instruction
WREG = 1100 0110 [0xC6]
REG = 1100 0110 [0xC6]
NOP No Operation
Syntax: [ label ] NOP
Operands: None
Operation: No operation
Status Af fe cte d: None
Encoding: 0000 0000 0000 0000
Description: No operation.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No
operation No
operation No
operation
Example:
None.
2000 Microchip Technology Inc. DS30289B-page 221
PIC17C7XX
RETFIE Return from Interrupt
Syntax: [ label ] RETFIE
Operands: None
Operation: TOS (PC);
0 GLINTD;
PCLATH is unchanged.
Status Affected: GLINTD
Encoding: 0000 0000 0000 0101
Description: Retur n from Interru pt. Stac k is POPed
and Top-of-Stack (TOS) is loaded in the
PC. Interrupts are enabled by clearing
the GLINTD bit. GLINTD is the global
interrupt disable bit (CPUSTA<4>).
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No
operation Clear
GLINTD POP PC
from stack
No
operation No
operation No
operation No
operation
Example:RETFIE
After Interrupt
PC = TOS
GLINTD = 0
RETLW Return Literal to WREG
Syntax: [ label ] RETLW k
Operands: 0 k 255
Operation: k (WREG); TOS (PC);
PCLATH is unchanged
Status Af fe cte d: None
Encoding: 1011 0110 kkkk kkkk
Description: WREG is loaded with the eight-bit literal
'k'. The program counter is loaded from
the top of the stack (the return address).
The high address latch (PCLATH)
remains unchanged.
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal 'k' Process
Data POP PC
from stack,
Write to
WREG
No
operation No
operation No
operation No
operation
Example: CALL TABLE ; WREG contains table
; offset value
; WREG now has
; table value
:
TABLE
ADDWF PC ; WREG = offset
RETLW k0 ; Begin table
RETLW k1 ;
:
:
RETLW kn ; End of table
Before Instruc tio n
WREG = 0x07
After Instruction
WREG = value of k7
PIC17C7XX
DS30289B-page 222 2000 Microchip Technology Inc.
RETURN Return from Subroutine
Syntax: [ label ] RETURN
Operands: None
Operation: TOS PC;
Status Affected: None
Encoding: 0000 0000 0000 0010
Description: Return from subroutine. The stack is
popped and the top of the stack (TOS)
is loaded into the program counter.
Words: 1
Cycles: 2
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No
operation Process
Data POP PC
from stack
No
operation No
operation No
operation No
operation
Example:RETURN
After Interrupt
PC = TOS
RLCF Rotate Left f through Carry
Syntax: [ label ] RLCF f,d
Operands: 0 f 255
d [0,1]
Operation: f<n> d<n+1>;
f<7> C;
C d<0 >
Status Af fe cte d: C
Encoding: 0001 101d ffff 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
WREG. If d is 1, the result is stored
back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:RLCF REG,0
Before Instruc tio n
REG = 1110 0110
C=0
After Instruction
REG = 1110 0110
WREG = 1100 1100
C=1
Cregister f
2000 Microchip Technology Inc. DS30289B-page 223
PIC17C7XX
RLNCF Rotate Left f (no carry)
Syntax: [ label ] RLNCF f,d
Operands: 0 f 255
d [0,1]
Operation: f<n> d<n+1>;
f<7> d<0>
Status Affected: None
Encoding: 0010 001d ffff ffff
Description: The contents of register f are rotated
one bit to the left. If d is 0, the result is
placed in WREG. If d is 1, the result is
stored back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:RLNCF REG, 1
Before Instruction
C=0
REG = 1110 1011
After Instruction
C=
REG = 1101 0111
register f
RRCF Rotate Right f through Carry
Syntax: [ label ] RRCF f,d
Operands: 0 f 255
d [0,1]
Operation: f<n> d<n-1>;
f<0> C;
C d<7>
Status Af fe cte d: C
Encoding: 0001 100d ffff 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
WREG. If d is 1, the result is placed
back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:RRCF REG1,0
Before Instruc tio n
REG1 = 1110 0110
C=0
After Instruction
REG1 = 1110 0110
WREG = 0111 0011
C=0
Cregister f
PIC17C7XX
DS30289B-page 224 2000 Microchip Technology Inc.
RRNCF Rotate Right f (no carry)
Syntax: [ label ] RRNCF f,d
Operands: 0 f 255
d [0,1]
Operation: f<n> d<n-1>;
f<0> d<7>
Status Affected: None
Encoding: 0010 000d ffff ffff
Description: The contents of register f are rotated
one bit to the ri ght. If d is 0, the result is
placed in WREG. If d is 1, the result is
placed back in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example 1:RRNCF REG, 1
Before Instruction
WREG = ?
REG = 1101 0111
After Instruction
WREG = 0
REG = 1110 1011
Example 2:RRNCF REG, 0
Before Instruction
WREG = ?
REG = 1101 0111
After Instruction
WREG = 1110 1011
REG = 1101 0111
register f
SETF Set f
Syntax: [ label ] SETF f,s
Operands: 0 f 255
s [0,1]
Operation: FFh f;
FFh d
Status Af fe cte d: None
Encoding: 0010 101s ffff ffff
Description: If s is 0, both the data memory location
f and WREG are set to FFh. If s is 1,
only the data memory location f is se t
to FFh .
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register f
and other
specified
register
Example1:SETF REG, 0
Before Instruc tio n
REG = 0xDA
WREG = 0x05
After Instruction
REG = 0xFF
WREG = 0xFF
Example2:SETF REG, 1
Before Instruc tio n
REG = 0xDA
WREG = 0x05
After Instruction
REG = 0xFF
WREG = 0x05
2000 Microchip Technology Inc. DS30289B-page 225
PIC17C7XX
SLEEP Enter SLEEP mode
Syntax: [ label ] SLEEP
Operands: None
Operation: 00h WDT;
0 WDT postscaler;
1 TO;
0 PD
Status Affected: TO, PD
Encoding: 0000 0000 0000 0011
Description: The power-down status bit (PD) is
cleared. The time-out status bit (TO) is
set. Watchdog Timer and its
postscaler are cleared.
The processor is put into SLEEP
mode with the oscillator stopped.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode No
operation Process
Data Go to
sleep
Example:SLEEP
Before Instruction
TO =?
PD =?
After Instruction
TO =1
PD =0
If WDT causes wake-up, this bit is cleared
SUBLW Subtract WREG from Literal
Syntax: [ label ]SUBLW k
Operands: 0 k 255
Operation: k (WREG) → (WREG)
Status Affected: OV, C, DC, Z
Encoding: 1011 0010 kkkk kkkk
Description: WREG is subtracted from the eight-bit
literal k. The result is placed in
WREG.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal kProcess
Data Write to
WREG
Example 1:SUBLW 0x02
Before Instruc tio n
WREG = 1
C=?
After Instruction
WREG = 1
C = 1 ; result is positive
Z=0
Example 2:
Before Instruc tio n
WREG = 2
C=?
After Instruction
WREG = 0
C = 1 ; result i s zero
Z=1
Example 3:
Before Instruc tio n
WREG = 3
C=?
After Instruction
WREG = FF ; (2s complement)
C = 0 ; result is negative
Z=0
PIC17C7XX
DS30289B-page 226 2000 Microchip Technology Inc.
SUBWF Sub tract WREG from f
Syntax: [ label ] SUBWF f,d
Operands: 0 f 255
d [0,1]
Operation: (f) (W) → (dest)
Status Affected: OV, C, DC, Z
Encoding: 0000 010d ffff ffff
Description: Subtract WREG from register 'f' (2s
complement method). If 'd' is 0, the
result is stored in WREG. If 'd' is 1, the
result is stored back in register 'f'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write to
destination
Example 1:SUBWF REG1, 1
Before Instruction
REG1 = 3
WREG = 2
C=?
After Instruction
REG1 = 1
WREG = 2
C = 1 ; result is positive
Z=0
Example 2:
Before Instruction
REG1 = 2
WREG = 2
C=?
After Instruction
REG1 = 0
WREG = 2
C = 1 ; result i s z ero
Z=1
Example 3:
Before Instruction
REG1 = 1
WREG = 2
C=?
After Instruction
REG1 = FF
WREG = 2
C = 0 ; result is negative
Z=0
SUBWFB Subtract WREG from f with
Borrow
Syntax: [ label ] SUBWFB f,d
Operands: 0 f 255
d [0,1]
Operation: (f) (W) C → (dest)
Status Affected: OV, C, DC, Z
Encoding: 0000 001d ffff ffff
Description: Subtract WREG and the carry flag
(borrow) from register 'f' (2s comple-
ment method). If 'd' is 0, the result is
stored in WREG. If 'd' is 1, the result is
stored back in register 'f'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write to
destination
Example 1:SUBWFB REG1, 1
Before Instruc tio n
REG1 = 0x19 (0001 1001)
WREG = 0x0D (0000 1101)
C=1
After Instruction
REG1 = 0x0C (0000 1011)
WREG = 0x0D (0000 1101)
C = 1 ; result is positiv e
Z=0
Example2:SUBWFB REG1,0
Before Instruc tio n
REG1 = 0x1B (0001 1011)
WREG = 0x1A (0001 1010)
C=0
After Instruction
REG1 = 0x1B (0001 1011)
WREG = 0x00
C = 1 ; res u lt is zero
Z=1
Example3:SUBWFB REG1,1
Before Instruc tio n
REG1 = 0x03 (0000 0011)
WREG = 0x0E (0000 1101)
C=1
After Instruction
REG1 = 0xF5 (1111 0100) [2s comp]
WREG = 0x0E (0000 1101)
C = 0 ; result is negative
Z=0
2000 Microchip Technology Inc. DS30289B-page 227
PIC17C7XX
SWAPF Swap f
Syntax: [ label ] SWAPF f,d
Operands: 0 f 255
d [0,1]
Operation: f<3:0> dest<7:4>;
f<7:4> dest<3:0>
Status Affected: None
Encoding: 0001 110d ffff ffff
Description: The upper and lower nibbles of register
f are exchanged. If d is 0, the result is
placed in WREG. If d is 1, the result is
placed in register f.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write to
destination
Example:SWAPF REG, 0
Before Instruction
REG = 0x53
After Instruction
REG = 0x35
TABLRD Table Read
Syntax: [ label ] TABLRD t,i,f
Operands: 0 f 255
i [0,1]
t [0,1]
Operation: If t = 1,
TBLATH f;
If t = 0,
TBLATL f;
Prog Mem (TBLPTR) TBLAT;
If i = 1,
TBLPTR + 1 TBLPTR
If i = 0,
TBLPTR is unchanged
Status Af fe cte d: None
Encoding: 1010 10ti ffff ffff
Description: 1. A byte of the table latch (TBLAT)
is moved to register file f.
If t = 1: the high byte is moved;
If t = 0: the low byte is moved.
2. Then, the contents of the pro-
gram memory locat ion pointed to
by the 16-bit Table Pointer
(TBLPTR) are loaded into the
16-bit Table Latch (TBLAT).
3. If i = 1: TBLPTR is incremented;
If i = 0: TBLPTR is not
incremented.
Words: 1
Cycles: 2 (3-cycle if f = PCL)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register
TBLATH or
TBLATL
Process
Data Write
register f
No
operation No
operation
(Tabl e Pointer
on Address
bus)
No
operation No
operation
(OE goes low)
PIC17C7XX
DS30289B-page 228 2000 Microchip Technology Inc.
TABLRD Table Read
Example1:TABLRD 1, 1, REG ;
Before Instruction
REG = 0x53
TBLATH = 0xAA
TBLATL = 0x55
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0x1234
After Instruction (table write completion)
REG = 0xAA
TBLATH = 0x12
TBLATL = 0x34
TBLPTR = 0xA357
MEMORY(TBLPTR) = 0x5678
Example2:TABLRD 0, 0, REG ;
Before Instruction
REG = 0x53
TBLATH = 0xAA
TBLATL = 0x55
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0x1234
After Instruction (table write completion)
REG = 0x55
TBLATH = 0x12
TBLATL = 0x34
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0x1234
TABLWT Table Write
Syntax: [ label ] TABLWT t,i,f
Operands: 0 f 255
i [0,1]
t [0,1]
Operation: If t = 0,
f TBLATL;
If t = 1,
f TBLATH;
TBLAT Pr og Mem (TBLPTR);
If i = 1,
TBLPTR + 1 TBLPTR
If i = 0,
TBLPTR is unchanged
Status Af fe cte d: None
Encoding: 1010 11ti ffff ffff
Description: 1. Load value in f into 16-bit table
latc h ( TBLAT)
If t = 1: load into high byte;
If t = 0: load into low byte
2. The contents of TBLAT are writ-
ten to the program memory
location pointed to by TBLPTR.
If TBLPTR points to external
program memory location, then
the instruction takes two-cycle.
If TBLPTR points to an internal
EPROM location, then the
instruction is terminated when
an interrupt is received.
Note: The MCLR/VPP pin must be at the programming
voltage for successful programming of internal
memory.
If M C L R/VPP = VDD
the programming sequence of internal memory
will be interrupted. A short write will occur (2
TCY). The internal memory location will not be
affected.
3. The TBLPTR can be automati-
cally incremented
If i = 1; TBLPTR is not
incremented
If i = 0; TBLPTR is incremented
Words: 1
Cycles: 2 (many if write is to on-chip
EPROM p rogram memory)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write
register
TBLATH or
TBLATL
No
operation No
operation
(Table Pointer
on Address
bus)
No
operation No
operation
(T able Latch on
Address bus,
WR goes low)
2000 Microchip Technology Inc. DS30289B-page 229
PIC17C7XX
TABLWT Table Write
Example1:TABLWT 1, 1, REG
Before Instruction
REG = 0x53
TBLATH = 0xAA
TBLATL = 0x55
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0xFFFF
After Instruction (table write completion)
REG = 0x53
TBLATH = 0x53
TBLATL = 0x55
TBLPTR = 0xA357
MEMORY(TBLPTR - 1) = 0x5355
Example 2:TABLWT 0, 0, REG
Before Instruction
REG = 0x53
TBLATH = 0xAA
TBLATL = 0x55
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0xFFFF
After Instruction (table write completion)
REG = 0x53
TBLATH = 0xAA
TBLATL = 0x53
TBLPTR = 0xA356
MEMORY(TBLPTR) = 0xAA53
Program
Memory
16 bits
15 0
TBLPTR
TBLAT
Data
Memory
8 bits
15 8 70
TLRD Table Latch Read
Syntax: [ label ] TLRD t,f
Operands: 0 f 255
t [0,1]
Operation: If t = 0,
TBLATL f;
If t = 1,
TBLATH f
Status Af fe cte d: None
Encoding: 1010 00tx ffff ffff
Description: Read data from 16-bit table latch
(TBLAT) into file register f. Table Latch
is unaffected.
If t = 1; high byte is read
If t = 0; low byte is read
This instruction is used in conjunction
with TABLRD to transfer data from pro-
gram memory to data memory.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register
TBLATH or
TBLATL
Process
Data Write
register f
Example:TLRD t, RAM
Before Instruc tio n
t=0
RAM = ?
TBLAT = 0x00AF (TBLATH = 0x00)
(TBLATL = 0xAF)
After Instruction
RAM = 0xAF
TBLAT = 0x00AF (TBLATH = 0x00)
(TBLATL = 0xAF)
Before Instruc tio n
t=1
RAM = ?
TBLAT = 0x00AF (TBLATH = 0x00)
(TBLATL = 0xAF)
After Instruction
RAM = 0x00
TBLAT = 0x00AF (TBLATH = 0x00)
(TBLATL = 0xAF)
Program
Memory
16 bits
15 0
TBLPTR
TBLAT
Data
Memory
8 bits
15 8 70
PIC17C7XX
DS30289B-page 230 2000 Microchip Technology Inc.
TLWT Table Latc h W ri te
Syntax: [ label ] TLWT t,f
Operands: 0 f 255
t [0,1]
Operation: If t = 0,
f TBLATL;
If t = 1,
f TBLATH
Status Affected: None
Encoding: 1010 01tx ffff ffff
Description: Data from file register f is written into
the 16-bit table latch (TBLAT).
If t = 1; high byte is written
If t = 0; low byte is written
This instruction is used in conjunction
with TABLWT to transfer data from data
memory to program memory.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data Write
register
TBLATH or
TBLATL
Example:TLWT t, RAM
Before Instruction
t=0
RAM = 0xB7
TBLAT = 0x0000 (TBLAT H = 0x00)
(TBLATL = 0x00)
After Instruction
RAM = 0xB7
TBLAT = 0x00B7 (TBLATH = 0x00)
(TBLATL = 0xB7)
Before Instruction
t=1
RAM = 0xB7
TBLAT = 0x0000 (TBLAT H = 0x00)
(TBLATL = 0x00)
After Instruction
RAM = 0xB7
TBLAT = 0xB700 (TBLATH = 0xB7)
(TBLATL = 0x00)
TSTFSZ Test f, skip if 0
Syntax: [ label ] TSTFSZ f
Operands: 0 f 255
Operation: skip if f = 0
Status Af fe cte d: None
Encoding: 0011 0011 ffff ffff
Description: If f = 0, the next instruction, fetched
during the current instruction execution,
is discarded and a NOP is executed,
making this a two-cycle instruction.
Words: 1
Cycles: 1 (2)
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register fProcess
Data No
operation
If skip: Q1 Q2 Q3 Q4
No
operation No
operation No
operation No
operation
Example:HERE TSTFSZ CNT
NZERO :
ZERO :
Before Instruc tio n
PC = Address (HERE)
After Instruction
If CNT = 0x00,
PC = Address (ZERO)
If CNT ¼0x00,
PC = Address (NZERO)
2000 Microchip Technology Inc. DS30289B-page 231
PIC17C7XX
XORLW Exclusive OR Literal with
WREG
Syntax: [ label ] XORLW k
Operands: 0 k 255
Operation: (WREG) .XOR. k → (WREG)
Status Affected: Z
Encoding: 1011 0100 kkkk kkkk
Description: The contents of WREG are XORed
with the 8-bit literal 'k'. The result is
placed in WREG.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
literal 'k' Process
Data Write to
WREG
Example:XORLW 0xAF
Before Instruction
WREG = 0xB5
After Instruction
WREG = 0x1A
XORWF Exclusive OR WREG with f
Syntax: [ label ] XORWF f,d
Operands: 0 f 255
d [0,1]
Operation: (WREG) .XOR. (f) → (dest)
Status Af fe cte d: Z
Encoding: 0000 110d ffff ffff
Description: Exclusive OR the contents of WREG
with register 'f'. If 'd' is 0, the result is
stored in WREG. If 'd' is 1, the result is
stored back in the register 'f'.
Words: 1
Cycles: 1
Q Cycle Activity:
Q1 Q2 Q3 Q4
Decode Read
register 'f' Process
Data Write to
destination
Example:XORWF REG, 1
Before Instruc tio n
REG = 0xAF 1010 1111
WREG = 0xB5 1011 0101
After Instruction
REG = 0x1A 0001 1010
WREG = 0xB5
PIC17C7XX
DS30289B-page 232 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 233
PIC17C7XX
19.0 DEVELOPMENT SUPPORT
The PICmicro® microcontrollers are supported with a
full range of hard ware and soft ware dev elopment tools:
Integrated Development Environment
- MPLAB® IDE Software
Assemblers/Compilers/Linkers
- MPASMTM Assembler
- MPLAB C17 and MPLAB C18 C Compilers
-MPLINK
TM Object Linker/
MPLIBTM Object Librarian
Simulators
- MPLAB SIM Software Simulator
Emulators
- MPLAB ICE 2000 In-Circuit Emulator
- ICEPIC In-Circuit Emulator
In-Circuit Debugger
- MPLAB ICD for PIC16F87X
Device Programmers
-PRO MATE
® II Univer sa l D evi ce P rogrammer
- PICSTART® Plus Entry-Level Development
Programmer
Low Cost Demonstration Boards
- PICDEMTM 1 Demonstration Board
- PICDEM 2 Demonstration Board
- PICDEM 3 Demons trati on Boar d
- PICDEM 17 Demonstration Board
-K
EELOQ® Demonstration Board
19.1 MPLAB Integrated Development
Environment Software
The MPLAB IDE software brings an ease of software
development previously unseen in the 8-bit microcon-
troller market. The MPLAB IDE is a Windows®-based
application that contains:
An interface to debugging tools
- simulator
- programmer (sold sep arately )
- emulator (s old separately)
- in-circuit debugger (sold separately)
A full-featured editor
A project manager
Customizable toolbar and key mapping
A status bar
On-line help
The MPLAB IDE allows you to:
Edit your source f iles (either assembly or C)
One touch assemble (or compile) and download
to PICmicro emulator and simulator tools (auto-
matically updates all project information)
Debug us ing :
- source files
- absol ute listing fi le
- machine code
The ability to use MPLAB IDE with multiple debugging
tools allows users to easily switch from the cost-
effective simulator to a full-featured emulator with
minimal retraining.
19.2 MPASM Assembler
The MPASM assembler is a full-featured universal
macro assembler for all PICmicro MCUs.
The MPASM assembler has a command line interface
and a Windows shell. It can be used as a stand-alone
application on a Windows 3.x or greater system, or it
can be us ed through MPLAB ID E. The MP ASM assem-
bler generates relocatable object files for the MPLINK
object linker, Intel® standard HEX files, MAP files to
detail memory usage and symbol reference, an abso-
lute LST file that contains source lines and generated
machine code, and a COD file for debugging.
The MPASM assembler features include:
Integration into MPLAB IDE projects.
User-defined macros to streamline assembly
code.
Conditional assembly for multi-purpose source
files.
Directives that allow complete control over the
assembly process.
19.3 MPLAB C17 and MPLAB C18
C Compilers
The MPLAB C1 7 and MP LAB C18 Code De vel op me nt
Systems are complete ANSI C compilers for
Microchips PIC17CXXX and PIC18CXXX family of
microc ontrollers, re spectively. These compilers provide
powerful integration capabilities and ease of use not
found with other compilers.
For easier source level debugging, the compilers pro-
vide symbol information that is compatible with the
MPLAB IDE memory display.
PIC17C7XX
DS30289B-page 234 2000 Microchip Technology Inc.
19.4 MPLINK Object Linker/
MPLIB Object Librari an
The MPLINK object linker combines relocatable
objects created by the MPASM assembler and the
MPLAB C17 and MPLAB C18 C compilers. It can also
link relocatable objects from pre-compiled libraries,
using directives from a linker script.
The MPLIB object librarian is a librarian for pre-
compiled code to be used with the MPLINK object
linker. When a routine from a library is called from
another source file, only the modules that contain that
routine w ill be linked in with the ap plicatio n. This allo ws
large libraries to be used efficiently in many different
applications. The MPLIB object librarian manages the
creation and modification of library files.
The MPLINK object linker features include:
Integration with MPASM assembler and MPLAB
C17 and MPLAB C18 C compilers.
Allows a ll m emo ry are as t o be defined as se ctions
to provide l ink -time flex ibi lity.
The MPLIB object librarian features include:
Easier linking because single libraries can be
included instead of many smaller files.
Helps keep code maintainable by grouping
related modules together.
Allows libraries to be created and modules to be
added, listed, replaced, deleted or extracted.
19.5 MPLAB SIM Software Simulator
The MPL AB SIM sof tware simul ator allow s code de vel-
opment in a PC-hosted environment by simulating the
PICmicro series microcontrollers on an instruction
level. On any given instruction, the data areas can be
examined or modified and stimuli can be applied from
a file, or user-defined ke y press, to an y of the pins. The
execution can be performed in single step, execute
until break, or trace mode.
The MPLAB SIM simulator fully supports symbolic debug-
ging using the MPLAB C17 and the MPLAB C18 C com-
pilers and the MP ASM assembler . The software simulator
offers the flexibility to develop and debug code outside of
the laborat ory envir onment, making it an excelle nt multi-
project software development tool.
19.6 MPLAB ICE High Performance
Universal In-Circuit Emulator with
MPLAB IDE
The MPLAB ICE universal in-circuit emulator is intended
to provide the product development engineer with a
complete microcontroller design tool set for PICmicro
microcontrollers (MCUs). Software control of the
MPLAB ICE in-circuit emulator is provided by the
MPLAB Integrated Development Environment (IDE),
which allows editi ng, buildin g, downlo ading and so urce
debugging from a single environment.
The MPLAB ICE 2000 is a full-featured emulator sys-
tem with enhanced trace, trigger and data monitoring
featur es. Interchangea ble processo r modules al low the
system to be easily reconfigured for emulation of differ-
ent processors. The universal architecture of the
MPLAB ICE in-circuit emulator allows expansion to
support new PICmic ro mi cro con trol le rs.
The MPLAB ICE in-circuit emulator system has been
designed as a real-time emulation system, with
advanced features that are generally found on more
expensive development tools. The PC platform and
Microsoft® Windows environment were chosen to best
make these features available to you, the end user.
19.7 ICEPIC In-Circuit Emulator
The ICEPIC low cost, in-circuit emulator is a solution
for the Microchip Technology PIC16C5X, PIC16C6X,
PIC16C7X and PIC16CXXX families of 8-bit One-
T ime-Programmable (OTP) microcontrollers. The mod-
ular sy stem can su pport dif feren t subset s of PIC16 C5X
or PIC16CXXX products through the use of inter-
changeable personality modules, or daughter boards.
The emulator is capable of emulating without target
applic atio n circ ui try bei ng pres en t.
2000 Microchip Technology Inc. DS30289B-page 235
PIC17C7XX
19.8 MPLAB ICD In-Circuit Debugger
Microchips In-Circuit Debugger , MPLAB ICD, is a pow-
erful, low cost, run-time development tool. This tool is
based on the FLASH PIC16F87X and can be used to
develop for this and other PICmicro microcontrollers
from the PIC16CXXX family. The MPLAB ICD utilizes
the in-circuit debugging capability built into the
PIC16F87X. This feature, along with Microchips
In-Circuit Serial ProgrammingTM protocol, offers cost-
effe ctive in-circu it FLASH debugging from the graphical
user interface of the MPLAB Integrated Development
Environment. This enables a designer to develop and
debug source code by watching variables, single-
stepping and setting break points. Running at full
speed enables testing hardware in real-time.
19.9 PRO MATE II Universal Device
Programmer
The PRO MATE II universal device programmer is a
full-featured programmer, capable of operating in
stand-alone mode, as well as PC-hosted mode. The
PRO MATE II device programmer is CE compliant.
The PRO MATE II device programmer has program-
mable VDD and VPP supplies, which allow it to verify
programmed memory at VDD min and VDD max for max-
imum reliability. It has an LCD display for instructions
and error messages, keys to enter commands and a
modular detachable socket assembly to support various
package types. In stand-alone mode, the PRO MATE II
device programmer can read, verify, or program
PICmicro devices. It can also set code protection in this
mode.
19.10 PICSTART Plus Entry Level
Development Programmer
The PICSTART Plus development programmer is an
easy-to-use, low cost, prototype programmer. It con-
nects to the PC via a COM (RS-232) port. MPLAB
Inte grated D evelopm ent Envir onment softwa re makes
using the programmer simple and efficient.
The PICSTART Plus development programmer sup-
ports all PICmicro devices with up to 40 pins. Larger pin
count devices, such as the PIC16C92X and
PIC17C76 X, may be suppor ted with an adap ter socket.
The PICSTART Plus development programmer is CE
compliant.
19.11 PICDEM 1 Low Cost PICmicro
Demonstration Board
The PICDEM 1 demonstration board is a simple board
which demonstrates the capabilities of several of
Microchips mic rocon trollers . The micro contro llers sup-
ported are: PIC16C5X (PIC16C54 to PIC16C58A),
PIC16C61, PIC16C62X, PIC16C71, PIC16C8X,
PIC17C42, PIC17C43 and PIC17C44. All necessary
hardware and software is included to run basic demo
programs. The user can program the sample microcon-
trollers provided with the PICDEM 1 demonstration
board on a PRO MATE II device programmer, or a
PICSTART Plus development programmer, and easily
test firmware. The user can also connect the
PICDEM 1 demonstration board to the MPLAB ICE in-
circuit emulato r and download th e firmware to the emu-
lator for testing. A prototype area is available for the
user to build some additional hardware and connect it
to the microcontroller socket(s). Some of the features
include an RS-232 interface, a potentiometer for simu-
lated analog input, push button switches and eight
LEDs connected to PORTB.
19.12 PICDEM 2 Low Cost PIC16CXX
Demonstration Board
The PICDEM 2 demonstration board is a simple dem-
onstration board that supports the PIC16C62,
PIC16C64, PIC16C65, PIC16C73 and PIC16C74
microcontrollers. All the necessary hardware and soft-
ware is included to run the basic demonstration pro-
grams. The user can program the sample
microcontrollers provided with the PICDEM 2 demon-
stration board on a PRO MATE II device programmer,
or a PICSTART Plus development programmer, and
easily test firmware. The MPLAB ICE in-circuit emula-
tor may a lso be used with t he PICDEM 2 demon stration
board to test firmware. A prototype area has been pro-
vided to the user for adding additional hardware and
connecting it to the microcontroller socket(s). Some of
the features include a RS-232 interface, push button
switches , a poten tiomet er for simula ted anal og inpu t, a
serial EEPROM to d emonstrate u sage o f the I2CTM bus
and separate headers for connection to an LCD
module and a keypad.
PIC17C7XX
DS30289B-page 236 2000 Microchip Technology Inc.
19.13 PICDEM 3 Low Cost PIC16CXXX
Demonstration Board
The PICDEM 3 demonstration board is a simple dem-
onstration board that supports the PIC16C923 and
PIC16C924 in the PLCC package. It will also support
future 44-p in PLCC micro controlle rs with an LCD Mo d-
ule. All the necessary hardware and software is
includ ed to r un the basic dem onstrat ion pro grams . The
user can program the sample microcontrollers pro-
vided with the PICDEM 3 demonstration board on a
PRO MATE II device prog rammer , or a PICS T AR T Plus
development programmer with an adapter socket, and
easily test firmware. The MPLAB ICE in-circuit emula-
tor may a lso be used with the PICDEM 3 demon stration
board to test firmware. A prototype area has been pro-
vided t o the use r for ad ding hardwa re and con necting it
to the microcontroller socket(s). Some of the features
include a RS-232 interface, push button switches, a
potentiometer for simulated analog input, a thermistor
and separate headers for connection to an external
LCD module and a keypad. Also provided on the
PICDEM 3 demonstration board is a LCD panel, with 4
commo ns and 1 2 segment s , tha t is capable of displa y-
ing time, temperature and day of the week. The
PICDEM 3 d emons tration board pr ovi des an add itiona l
RS-232 interface and Windows software for showing
the demul tiplexed LC D signals on a PC. A simp le serial
interface allows the user to construct a hardware
demultiplexer for the LCD signals.
19.14 PICDEM 17 Demonstration Board
The P ICDEM 17 dem o ns tr at i on bo a rd is an ev al u at i on
board that demonstrates the capabilities of several
Microchip microcontrollers, including PIC17C752,
PIC17C756A, PIC17C762 and PIC17C766. All neces-
sary hard ware is inc luded to ru n basic d emo progra ms,
which are supplied on a 3.5-inch disk. A programmed
sample is included and the user may erase it and
program it with the other sample programs using the
PRO MATE II device programmer, or the PICSTART
Plus development programmer, and easily debug and
test the sample code. In addition, the PICDEM 17 dem-
onstratio n board supports download ing of programs to
and executing out of external FLASH memory on board.
The PICDEM 17 demonstration board is also usable
with the MPLAB ICE in-circuit emulator, or the
PICMAST ER emulator and al l of the sample progr ams
can be run and modified using either emulator. Addition-
ally, a generous prototype area is available for user
hardware.
19.15 KEELOQ Evaluati on and
Programming Tools
KEELOQ evaluation and programming tools support
Microchips HCS Secure Data Products. The HCS eval-
uation kit includes a LCD display to show changing
codes, a decoder to decode transmissions and a pro-
gramming interface to program test transmitters.
2000 Microchip Technology Inc. DS30289B-page 237
PIC17C7XX
TABLE 19-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
Soft war e To ol s
MPLAB® Integrated
Development Environment
á
á
á
á
á
á
á
á
á
á
á
á
á
á
MPLAB® C17 C Compiler
á
á
MPLAB® C18 C Compiler
á
MPASMTM Assembler/
MPLINKTM Object Linker
á
á
á
á
á
á
á
á
á
á
á
á
á
á
á
á
Emulators
MPLAB® ICE In-Circuit Emulator
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
ICEPICTM In -Circu it Emu lat or
á
á
á
á
á
á
á
á
Debugger
MPLAB® ICD In-Circuit
Debugger
á
*
á
*
á
Programmers
PICSTART® Plus Entr y Le vel
Development Programmer
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
PRO MATE® II
Universal Device Programmer
á
á
á
á
á
á
**
á
á
á
á
á
á
á
á
á
á
Demo Boards and Eval Kits
PICDEMTM 1 Demonstration
Board
á
á
á
á
á
PICDEMTM 2 Demonstration
Board
á
á
á
PICDEMTM 3 Demonstration
Board
á
PICDEMTM 14A Demonst r ation
Board
á
PICDEMTM 17 Demonstration
Board
á
KEELOQ® Evaluation Kit
á
KEELOQ® Transponder Kit
á
microIDTM Programmers Kit
á
125 kHz microIDTM
Developers Kit
á
125 kHz Anticollision microIDTM
Developers Kit
á
13.56 MHz Anticollision
microIDTM Developers Kit
á
MCP2510 CAN Developers Kit
á
* Contact the Microchip Technology Inc. web site at www.microchip.com for information on how to use the MPLAB® ICD In-Circuit Debugger (DV164001) with PIC16C62, 63, 64, 65, 72, 73, 74, 76, 77.
** Contact Microchip Technology Inc. for availability date.
Development tool is available on select devices.
PIC17C7XX
DS30289B-page 238 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 239
PIC17C7XX
20.0 PIC17C7XX ELECTRICAL CHARACTERISTICS
Absolute Maximum Ratings
Ambient temperature under bias.............................................................................................................-55°C to +125°C
Storage temperature.............................................................................................................................. -65°C to +150°C
Volta ge on VDD with respect to VSS ........................................................................................................... 0 V to +7.5 V
Volta ge on MCLR with respect to VSS (Note 2).......................................................................................-0.3 V to +14 V
Voltage on RA2 and RA3 with respect to VSS..........................................................................................-0.3 V to +8.5 V
Voltage on all other pins with respect to VSS ...................................................................................-0.3 V to VDD + 0.3 V
Total power dissipation (Note 1) ..............................................................................................................................1.0 W
Maximum current out of VSS pin(s) - total (@ 70°C)............................................................................................500 mA
Maximum current int o VDD pin(s) - total (@ 70°C)...............................................................................................500 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 (except RA2 and RA3).....................................................................35 mA
Maximum output current sunk by RA2 or RA3 pins................................................................................................60 mA
Maximum output current sourced by any I/O pin....................................................................................................20 mA
Maximum current sunk by PORTA and PORTB (combined).................................................................................150 mA
Maximum current sourced by PORTA and PORTB (combined) ...........................................................................100 mA
Maximum current sunk by PORTC, PORTD and PORTE (combined)..................................................................150 mA
Maximum current sourced by PORTC, PORTD and PORTE (combined) ............................................................100 mA
Maximum current sunk by PORTF and PORTG (combined)................................................................................150 mA
Maximum current sourced by PORTF and PORTG (combined)...........................................................................100 mA
Maximum current sunk by PORTH and PORTJ (combined).................................................................................150 mA
Maximum current sourced by PORTH and PORTJ (combined) ...........................................................................100 mA
Note 1: Pow er dissipation is calcula ted as follows : Pdis = VDD x {IDD - IOH} + {(VDD-VOH) x IOH} + (VOL x IOL)
2: Voltage spikes below VSS at the MCLR pin, inducing currents greater than 80 mA, may cause latch-up.
Thus, a series resi stor of 50-100 should be used when ap plying a "low" level to the MCL R pin, rather than
pulling this pin directl y to VSS.
NOTICE: Stresses above those listed under "Absolute Maximum Ratings" may cause permanent dam-
age 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.
PIC17C7XX
DS30289B-page 240 2000 Microchip Technology Inc.
FIGURE 20-1: PIC17C7XX-33 VOLTAGE-FREQUENCY GRAPH
FIGURE 20-2: PIC17C7XX-16 VOLTAGE-FREQUENCY GRAPH
Frequency
Voltage
6.0 V
5.5 V
4.5 V
4.0 V
2.0 V
33 MHz
5.0 V
3.5 V
3.0 V
2.5 V
PIC17C7XX-33
Frequency
Voltage
6.0 V
5.5 V
4.5 V
4.0 V
2.0 V
16 MHz
5.0 V
3.5 V
3.0 V
2.5 V
PIC17C7XX-16
2000 Microchip Technology Inc. DS30289B-page 241
PIC17C7XX
FIGURE 20-3: PIC17LC7XX-08 VOLTAGE-FREQUENCY GRAPH
FIGURE 20-4: PIC17C7XX/CL VOLTAGE-FREQUENCY GRAPH
Frequency
Voltage
6.0 V
5.5 V
4.5 V
4.0 V
2.0 V
8 MHz
5.0 V
3.5 V
3.0 V
2.5 V
PIC17LC7XX-08
Frequency
Voltage
6.0 V
5.5 V
4.5 V
4.0 V
2.0 V
8 MHz
5.0 V
3.5 V
3.0 V
2.5 V
33 MHz
PIC17C7XX/CL
PIC17C7XX
DS30289B-page 242 2000 Microchip Technology Inc.
20.1 DC Characteristics
PIC17LC7XX-08
(Commercial, Industrial)
Standard Operating Conditions (unless otherwise stated)
Operating t emperature -40°C TA +85°C for industrial and
0°C TA +70°C for commercial
PIC17C7XX-16
(Commercial, Industrial, Extended)
PIC17C7XX-33
(Commercial, Industrial, Extended)
Standard Operating Conditions (unless otherwise stated)
Operating t emperature
-40°C TA +125°C for extended
-40°C TA +85°C for industrial
0°C TA +70°C for commercial
Param.
No. Sym Characteristic Min TypMax Units Conditions
D001 VDD Supply Voltage
PIC17LC7XX 3.0 5.5 V
D001 PIC17C7XX-33
PIC17C7XX-16 4.5
VBOR
5.5
5.5 V
V(BOR enabled) (Note 5)
D002 VDR RAM Data Retention
Voltage (Note 1) 1.5 ——V Device in SLEEP mode
D003 VPOR VDD Start Voltage to
ensure internal
Power-on Reset signal
Vss V See section on Power-on
Reset for deta ils
D004 SVDD VDD Rise Rate to ensure proper operation
PIC17LCXX 0.010 ——V/ms See section on Power-on
Reset for deta ils
D004 PIC17CXX 0.085 V/ms See section on Power-on
Reset for deta ils
D005 VBOR Brown-out Reset
voltage trip point 3.65 4.35 V
D006 VPORTP Power-on Reset tri p
point 2.2 VVDD = VPORTP
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: This is the limit to which VDD can be lowered in SLEEP mode without losing RAM data.
2: The supp ly curre nt i s m ain ly a fun cti on o f the ope rating voltage and frequenc y. Other factors su ch as I/ O p in
loading and switching rate, oscillator type, internal code execution pattern and temperature also have an
impact on the current consumption.
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 or VSS, T0CKI = VDD,
MCLR = VDD; WDT disa bl ed.
Current consumed from the oscillator and I/Os driving external capacitive or resistive loads needs to be
considered.
For the RC oscillator, the current through the external pull-up resistor (R) can be estimated as:
VDD/(2 R).
For capacitive loads, the current can be estimated (for an individual I/O pin) as (CL VDD) f
CL = Total capacitive load on the I/O pin; f = average frequency the I/O pin switches.
The capacitive currents are most significant when the device is configured for external execution (includes
Extended Microcontroller mode).
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: For RC os c c on figu r ati on, cu rrent thro ugh R EXT is not in cl uded. The c urre nt th roug h the resis to r ca n be es ti-
mated by the formula IR = VDD/2REXT (mA) with REXT in kOhm.
5: This is the voltage where the device enters the Brown-out Reset. When BOR is enabled, the device (-16)
will operate correctly to this trip point.
2000 Microchip Technology Inc. DS30289B-page 243
PIC17C7XX
D010 IDD Supply Current (Note 2)
PIC17LC7XX 36mAF
OSC = 4 MHz (Note 4)
D010 PIC17C7XX 3 6 mA FOSC = 4 MHz (Note 4)
D011 PIC17LC7XX 510mAF
OSC = 8 MHz
D011
D012 PIC17C7XX
5
910
18 mA
mA FOSC = 8 MHz
FOSC = 16 MH z
D014 PIC17LC7XX 85 150 µAF
OSC = 32 kHz,
(EC osc configuration)
D015 PIC17C7XX 15 30 mA FOSC = 33 M Hz
D021 IPD Power-down Current (Note 3)
PIC17LC7XX <1 5 µAVDD = 3.0V, WDT disabled
D021
(commercial,
industrial)
PIC17C7XX <1 20 µA VDD = 5.5V, WDT disabled
D021A
(extended) 220 µA VDD = 5.5V, WDT disabled
Module Differential Current
D023 IBOR BOR circuitry 75 150 µAVDD = 4.5V, BODEN
enabled
D024 IWDT Watchdog Timer 10 35 µAVDD = 5.5V
D026 IAD A/D converter 1µAVDD = 5.5V, A/D not
converting
PIC17LC7XX-08
(Commercial, Industrial)
Standard Operating Conditions (unless otherwise stated)
Operating t emperature -40°C TA +85°C for industrial and
0°C TA +70°C for commercial
PIC17C7XX-16
(Commercial, Industrial, Extended)
PIC17C7XX-33
(Commercial, Industrial, Extended)
Standard Operating Conditions (unless otherwise stated)
Operating t emperature
-40°C TA +125°C for extended
-40°C TA +85°C for industrial
0°C TA +70°C for commercial
Param.
No. Sym Characteristic Min TypMax Units Conditions
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: This is the limit to which VDD can be lowered in SLEEP mode without losing RAM data.
2: The supp ly curre nt i s m ain ly a fun cti on o f the ope rating voltage and frequenc y. Other factors su ch as I/ O p in
loading and switching rate, oscillator type, internal code execution pattern and temperature also have an
impact on the current consumption.
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 or VSS, T0CKI = VDD,
MCLR = VDD; WDT disa bl ed.
Current consumed from the oscillator and I/Os driving external capacitive or resistive loads needs to be
considered.
For the RC oscillator, the current through the external pull-up resistor (R) can be estimated as:
VDD/(2 R).
For capacitive loads, the current can be estimated (for an individual I/O pin) as (CL VDD) f
CL = Total capacitive load on the I/O pin; f = average frequency the I/O pin switches.
The capacitive currents are most significant when the device is configured for external execution (includes
Extended Microcontroller mode).
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: For RC os c c on figu r ati on, cu rrent thro ugh R EXT is not in cl uded. The c urre nt th roug h the resis to r ca n be es ti-
mated by the formula IR = VDD/2REXT (mA) with REXT in kOhm.
5: This is the voltage where the device enters the Brown-out Reset. When BOR is enabled, the device (-16)
will operate correctly to this trip point.
PIC17C7XX
DS30289B-page 244 2000 Microchip Technology Inc.
20.2 DC Characteristics: PIC17C7XX-16 (Commercial, Industr ial, Extended)
PIC17C7XX-33 (Commercial, Industrial , Extended)
PIC17LC7XX-08 (Commercial, Industrial)
DC CHARACTERISTICS
Standard Operating Conditions (unless otherwise stated)
Operating temperature -40°C TA +125°C for extended
-40°C TA +85°C for industrial
0°C TA +70°C for commercial
Operating voltage VDD range as described in Section 20.1
Param.
No. Sym Characteristic Min TypMax Units Conditions
Input Low Volt a ge
VIL I/O ports
D030 with TTL buffer (Note 6) Vss
Vss
0.8
0.2VDD V
V4.5V VDD 5.5V
3.0V VDD 4.5V
D031 with Schmitt Trigger buffer
RA2, RA3
All others Vss
Vss
0.3VDD
0.2VDD V
VI2C compliant
D032 MCLR, OSC1 (in EC and RC
mode) Vss 0.2VDD V(Note 1)
D033 OSC1 (in XT, and LF mode) 0.5VDD V
Input High Voltage
VIH I/O ports
D040 with TTL buffer (Note 6) 2.0
1 + 0.2VDD
VDD
VDD V
V4.5V VDD 5.5V
3.0V VDD 4.5V
D041 with Schmitt Trigger buffer
RA2, RA3
All others 0.7VDD
0.8VDD
VDD
VDD V
VI2C compliant
D042 MCLR 0.8VDD VDD V(Note 1)
D043 OSC1 (XT, and LF mode) 0.5VDD V
D050 VHYS Hysteresis of
Schmitt Trigger Inputs 0.15VDD ––V
Data in Typ column is at 5V, 25°C unless otherwi se stated.
Note 1: In RC oscillator configuration, the OSC1/CLKIN pin is a Schmitt Trigger input. It is not recommended that the
PIC17CXXX devices be driven with external clock in RC mode.
2: The leakage current on the MCLR pin is strongly dependent on the applied voltage level. Higher leakage
current may be measured at different input voltages.
3: Negative current is defined as current sourced by the pin.
4: These specifications are for the programming of the on-chip program memory EPROM through the use of the
table write instructions. The complete programming specifications can be found in: PIC17C7XX Programming
Specifications (Literature number DS TBD).
5: The MCLR/VPP pin may be kept in this range at times other than programming, but is not recommended.
6: For TTL buffers , the better of the two specifications m ay be used.
2000 Microchip Technology Inc. DS30289B-page 245
PIC17C7XX
Input Leakage Current
(Notes 2, 3)
D060 IIL I/O ports (except RA2, RA3) ––±1µAVss VPIN VDD,
I/O Pin (in digital mode) at
hi-imped an ce PORTB
weak pull -ups di sabled
D061 MCLR, TEST ––±2µAVPIN = Vss or VPIN = VDD
D062 RA2, R A3 ±2µAVss VRA2, VRA3 12V
D063 OSC1 (EC, RC modes) ––±1µAVss VPIN VDD
D063B OSC1 (XT, LF modes) ––VPIN µARF 1 M
D064 MCLR, TEST ––25 µAVMCLR = VPP = 12V
(wh en not prog ramming)
D070 IPURB PORTB Weak Pull-up Current 85 130 260 µA VPIN = VSS, RBPU = 0
4.5V VDD 5.5V
Output Low Voltage
D080
D081
VOL I/O ports
with TTL buf fer
0.1VDD
0.1VDD
0.4
V
V
V
IOL = VDD/1.250 mA
4.5V VDD 5.5V
VDD = 3.0V
IOL = 6 mA, VDD = 4.5V
(Note 6)
D082 RA2 and RA3
3.0
0.6 V
VIOL = 60.0 mA, VDD = 5.5V
IOL = 60.0 mA, VDD = 4.5V
D083
D084 OSC2/CLKOUT
(RC and EC osc modes)
0.4
0.1VDD V
VIOL = 1 mA, VDD = 4.5V
IOL = VDD/5 mA
(PIC17LC7XX only)
Output High Voltage (Note 3)
D090
D091
VOH I/O ports (except RA2 and
RA3)
with TTL buf fer
0.9VDD
0.9VDD
2.4
V
V
V
IOH = -VDD/2.5 mA
4.5V VDD 5.5V
VDD = 3.0V
IOH = -6.0 mA, VDD =4.5V
(Note 6)
D093
D094 OSC2/CLKOUT
(RC and EC osc modes) 2.4
0.9VDD
V
VIOH = -5 mA, VDD = 4.5V
IOH = -VDD/5 mA
(PIC17LC7XX only)
DC CHARACTERISTICS
Standard Operating Conditions (unless otherwise stated)
Operating temperature -40°C TA +125°C for extended
-40°C TA +85°C for industrial
0°C TA +70°C for commercial
Operating voltage VDD range as described in Section 20.1
Param.
No. Sym Characteristic Min TypMax Units Conditions
Data in Typ column is at 5V, 25°C unless otherwi se stated.
Note 1: In RC oscillator configuration, the OSC1/CLKIN pin is a Schmitt Trigger input. It is not recommended that the
PIC17CXXX devices be driven with external clock in RC mode.
2: The leakage current on the MCLR pin is strongly dependent on the applied voltage level. Higher leakage
current may be measured at different input voltages.
3: Negative current is defined as current sourced by the pin.
4: These specifications are for the programming of the on-chip program memory EPROM through the use of the
table write instructions. The complete programming specifications can be found in: PIC17C7XX Programming
Specifications (Literature number DS TBD).
5: The MCLR/VPP pin may be kept in this range at times other than programming, but is not recommended.
6: For TTL buffers , the better of the two specifications m ay be used.
PIC17C7XX
DS30289B-page 246 2000 Microchip Technology Inc.
D150 VOD Open Drain High Voltage ––8.5 V RA2 and RA3 pins only
pulled up to externally
applied voltage
Capacitive Loading Specs on
Output Pins
D100 COSC2 OSC2/CLKOUT pin ––25 pF In EC or RC osc modes ,
when OSC2 p in is outputti ng
CLKOUT. External clock is
used to drive OSC1.
D101 CIO All I/O pins and OSC2
(in RC mode) ––50 pF
D102 CAD System Interface Bus
(PORTC, PORTD and PORT E) ––50 pF In Microprocessor or
Extended Microcontroller
mode
Internal Program Memory
Programmi ng Specs (Note 4)
D110
D111
D112
D113
D114
VPP
VDDP
IPP
IDDP
TPROG
Voltage on MCLR/VPP pin
Supply voltage during
programming
Current into MCLR/VPP pin
Supply current during
programming
Programming pulse width
12.75
4.75
100
5.0
25
13.25
5.25
50
30
1000
V
V
mA
mA
ms
(Note 5)
Terminated via internal/
external interrupt or a
RESET
DC CHARACTERISTICS
Standard Operating Conditions (unless otherwise stated)
Operating temperature -40°C TA +125°C for extended
-40°C TA +85°C for industrial
0°C TA +70°C for commercial
Operating voltage VDD range as described in Section 20.1
Param.
No. Sym Characteristic Min TypMax Units Conditions
Data in Typ column is at 5V, 25°C unless otherwi se stated.
Note 1: In RC oscillator configuration, the OSC1/CLKIN pin is a Schmitt Trigger input. It is not recommended that the
PIC17CXXX devices be driven with external clock in RC mode.
2: The leakage current on the MCLR pin is strongly dependent on the applied voltage level. Higher leakage
current may be measured at different input voltages.
3: Negative current is defined as current sourced by the pin.
4: These specifications are for the programming of the on-chip program memory EPROM through the use of the
table write instructions. The complete programming specifications can be found in: PIC17C7XX Programming
Specifications (Literature number DS TBD).
5: The MCLR/VPP pin may be kept in this range at times other than programming, but is not recommended.
6: For TTL buffers , the better of the two specifications m ay be used.
Note 1: When using the Table Write for internal programming, the device temperature must be less than 40°C.
2: For In-Circuit Serial Programming (ICSP), refer to the device programming specification.
2000 Microchip Technology Inc. DS30289B-page 247
PIC17C7XX
20.3 Timing Parameter Symbology
The timing parameter symbols have been created
following one of the following formats:
1. TppS2ppS 3. TCC:ST (I2C specifications only)
2. TppS 4. Ts (I2C specifications only)
TF Frequency T Time
Lowercase symbols (pp) and their meanings:
pp
ad Address/Data ost Oscillator Start-Up Timer
al ALE pwrt Power-U p Timer
cc Capture1 and Capture2 rb PORTB
ck CLKOUT or clock rd RD
dt Data in rw RD or WR
in INT p in t0 T0CKI
io I/O port t123 TCLK12 and TCLK3
mc MCLR wdt Watchdog Timer
oe OE wr WR
os OSC1
Uppercase symbols and their meanings:
SDDriven LLow
EEdge PPeriod
FFall RRise
H High V Valid
I Invalid (Hi-impedance) Z Hi-impedance
PIC17C7XX
DS30289B-page 248 2000 Microchip Technology Inc.
FIGURE 20-5: PARAMETER MEASUREMENT INFORMATION
0.9 VDD
0.1 VDD R ise Time Fal l Time
VOH = 0.7VDD
VDD/2
VOL = 0.3VDD
Data out valid
Data out invalid Output
hi-impedance
Output
driven
0.25V
0.25V
0.25V
0.25V
OUTPUT LEVEL CONDITIONS
PORTC, D, E, F, G, H and J pins
All other input pins
VIH = 2.4V
VIL = 0.4V
Data in valid
Data in invalid VIH = 0.9VDD
VIL = 0.1VDD
Data in valid
Data in invalid
INPUT LEVEL CONDITIONS
LOAD CONDITIONS
Load Condition 1
Pin CL
VSS
50 pF CL
All timings are measured between high and low
measurement points as indicated below.
2000 Microchip Technology Inc. DS30289B-page 249
PIC17C7XX
20.4 Timing Diagrams and Specifications
FIGURE 20-6: EXTERNAL CLOCK TIMING
TABLE 20-1: EXTERNAL CLOCK TIMING REQUIREMENTS
OSC1
OSC2
Q4 Q1 Q2 Q3 Q4 Q1
13344
2
In EC and RC modes only .
Param
No. Sym Characteristic Min TypMax Units Conditions
FOSC External CLKIN
Frequency (Note 1) DC
DC
DC
8
16
33
MHz
MHz
MHz
EC osc mode - 08 devices (8 MHz devices)
- 16 devices (16 MHz devices)
- 33 devices (33 MHz devices)
Oscillator Frequency
(Note 1) DC
2
2
2
DC
4
8
16
33
2
MHz
MHz
MHz
MHz
MHz
RC osc mode
XT osc mode - 08 devices (8 MHz devices)
- 16 devices (16 MHz devices)
- 33 devices (33 MHz devices)
LF osc mode
1T
OSC External CLKIN Period
(Note 1) 125
62.5
30.3
ns
ns
ns
EC osc mode - 08 devices (8 MHz devices)
- 16 devices (16 MHz devices)
- 33 devices (33 MHz devices)
Oscillator Period
(Note 1) 250
125
62.5
30.3
500
1,000
1,000
1,000
ns
ns
ns
ns
ns
RC osc mode
XT osc mode - 08 devices (8 MHz devices)
- 16 devices (16 MHz devices)
- 33 devices (33 MHz devices)
LF osc mode
2T
CY Instruction Cycle Time
(Note 1) 121.2 4/FOSC DC ns
3TosL,
TosH Clock in (OSC1)
High or Low Time 10 ——ns EC oscillator
4TosR,
TosF Clock in (OSC1 )
Rise or Fall Time —— 5 ns EC oscillator
Data in Typ column is at 5V, 25°C unless otherwise stated.
Note 1: Ins truction cyc le period (TCY) equals four times the input oscillator time base period. All specified values are based on
characterization data for that particular oscillator type under standard operating conditions with the device executing
code. Exceeding these specified limit s may result in an unstable oscillator operation and/or higher than expected current
consumption. All devices are tested to operate at min. values with an external clock applied to the OSC1/CLKIN pin.
When an external clock input is used, the max. cycle time limit is DC (no clock) for all devices.
PIC17C7XX
DS30289B-page 250 2000 Microchip Technology Inc.
FIGURE 20-7: CLKOUT AND I/O TIMING
TABLE 20-2: CLKOUT AND I/O T IMING REQUIREMENTS
OSC1
OSC2 †
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
† In EC and RC modes only.
Param
No. Sym Characteristic Min Typ† Max Units Conditions
10 TosL2ckL OSC1 to C L KOUT15 30 ns (Note 1)
11 TosL2ckH OSC1 to C L KOU T15 30 ns (Note 1)
12 TckR CLKOUT rise time 5 15 ns (Note 1)
13 TckF CLKOUT fall time 5 15 ns (Note 1)
14 TckH2ioV CLKO UT to Port out valid ——0.5TCY + 20 ns (Note 1)
15 TioV2ckH Port in valid before CLKOUT0.25TCY + 25 ——ns (No te 1)
16 TckH2ioI Port in hold after CLKOUT 0 ——ns (Note 1)
17 TosL2ioV OSC1 (Q1 cycle) to Port out valid ——100 ns
18 TosL2ioI OSC1 (Q2 cycle) to Port input
invalid
(I/O in hold time)
0 —— ns
19 TioV2osL Port input valid to OSC1
(I/O in setup time) 30 ——ns
20 TioR Port output rise time 10 35 ns
21 TioF Port output fall time 10 35 ns
22 TinHL INT pin high or low time 25 —— ns
23 TrbHL RB7:RB0 change INT high or low
time 25 ——ns
Data in Typ column is at 5V, 25°C unless otherwise st ated. These p arameters are for design guidance only and are not
tested.
Note 1: Measurements are taken in EC mode, where CLKOUT output is 4 x TOSC.
2000 Microchip Technology Inc. DS30289B-page 251
PIC17C7XX
FIGURE 20-8: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP
TIMER, AND BROWN-OUT RESET TIMING
TABLE 20-3: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER,
AND BROWN-OUT RESET REQUIREMENTS
VDD
MCLR
Internal
POR/BOR
PWRT
Time-out
OSC
Time-out
Internal
Reset
Watchdog
Timer
Reset
33
32
30
31
Address/
Data
35
Param.
No. Sym Characteristic Min TypMax Units Conditions
30 TmcL MCLR Pulse W idth (low) 100 ——ns VDD = 5V
31 TWDT Wat chdog Timer Time- out Period
(Postscale = 1) 5 12 25 ms VDD = 5V
32 TOST Oscillation St art-up Timer Period 1024TOSC ms TOSC = OSC1 period
33 TPWRT Power-up Timer Period 40 96 200 ms VDD = 5V
34 TIOZ MCLR to I/O hi-impedance 100 ——ns Depends on pin load
35 TmcL2adI MCLR to System
Interface bus
(AD15:AD0>) invalid
PIC17C7XX ——100 ns
PIC17LC7XX ——120 ns
36 TBOR Brown-out Reset Pulse Width (low) 100 ——ns VDD within VBOR limits
(parameter D005)
Data in Typ column is at 5V, 25°C unless otherwise stated.
.
PIC17C7XX
DS30289B-page 252 2000 Microchip Technology Inc.
FIGURE 20-9: TIMER0 EXTERNAL CLOCK TIMINGS
TABLE 20-4: TIMER0 EXTERNAL CLOCK REQUIREMENTS
FIGURE 20-10: TIMER1, TIMER2 AND TIMER3 EXTERNAL CLOCK TIMINGS
TABLE 20-5: TIMER1, TIMER2 AND TIMER3 EXTERNAL CLOCK REQUIREMENTS
RA1/T0CKI
40 41
42
Param
No. Sym Characteristic Min TypMax Units Conditions
40 Tt0H T0CKI High Pulse Width No Prescaler 0.5TCY + 20 ——ns
With 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:
20 ns or TCY + 40
N
——ns N = prescale
value (1, 2, 4, ...,
256)
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
TCLK12
45 46
or
TCLK3
TMRx
48
48
47
Param
No. Sym Characteristic Min TypMax Units Conditions
45 Tt123H TCLK12 and TCLK3 high time 0.5TCY + 20 ——ns
46 Tt123L TCLK12 and TCLK3 low time 0.5TCY + 20 ——ns
47 Tt123P TCLK12 and TCLK3 input period TCY + 40
N——ns N = prescale
value (1, 2, 4, 8)
48 TckE2tmrI Delay from selected Ex ternal Clock Edge to
Timer increment 2TOSC 6Tosc
Data in Typ column is at 5V, 25°C unless otherwise stated.
2000 Microchip Technology Inc. DS30289B-page 253
PIC17C7XX
FIGURE 20-11: CAPTURE TIMINGS
TABLE 20-6: CAPTURE REQUIREMENTS
FIGURE 20-12: PWM TIMINGS
TABLE 20-7: PWM REQUIREMENTS
CAP pin
(Capture mode)
50 51
52
Param
No. Sym Characteristic Min Typ
Max Unit
sConditions
50 TccL Capture pin input low time 10 ——ns
51 TccH Capture pin input high time 10 ——ns
52 TccP Capture pin input period 2TCY
N——ns N = prescale value
(4 or 16)
Data in Typ column is at 5V, 25°C unless otherwise stated.
PWM pin
(PWM mode) 53 54
Param
No. Sym Characteristic Min Typ
Max Units Conditions
53 Tcc R P WM pin output rise time 10 35 ns
54 TccF PWM pin output fall time 10 35 ns
Data in Typ column is at 5V, 25°C unless otherwise stated.
PIC17C7XX
DS30289B-page 254 2000 Microchip Technology Inc.
FIGURE 20-13: SPI MASTER MODE TIMING (CKE = 0)
TABLE 20-8: SPI MODE REQUIREMENT S (MASTER MODE, CKE = 0)
SS
SCK
(CKP = 0)
SCK
(CKP = 1)
SDO
SDI
70
71 72
73 74
75, 76
78
79
80
79
78
MSb LSb
BIT6 - - - - - -1
MSb IN LSb IN
BIT6 - - - -1
Note: Refer to Figure 20-5 for load conditions.
Param.
No. Symbol Characteristic Min TypMax Units Conditions
70 TssL2scH,
TssL2scL SS to SCK or SCK input Tcy ——ns
71 TscH SC K input high time
(Slave mode) Continuous 1.25TCY + 30 ——ns
71A Single Byte 40 ——ns (No te 1)
72 TscL S CK input low time
(Slave mode) Continuous 1.25TCY + 30 ——ns
72A Single Byte 40 ——ns (No te 1)
73 TdiV2scH,
TdiV2scL Setup time of SDI data input to SCK edge 100 ——ns
73A TB2BLast clock edge of Byte1 to the 1st clock edge
of Byte2 1.5TCY + 40 ——ns (Note 1)
74 TscH2diL,
TscL2diL Hold time of SDI data input to SCK edge 100 ——ns
75 TdoR SDO data output rise time 10 25 ns
76 TdoF SDO data output fall time 10 25 ns
78 TscR S CK output rise time (Ma ster mode) 10 25 ns
79 TscF S CK output fall time (Master mod e) 10 25 ns
80 TscH2doV,
TscL2doV SDO data output valid after SCK edge ——50 ns
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: Specification 73A is only required if specifications 71A and 72A are used.
2000 Microchip Technology Inc. DS30289B-page 255
PIC17C7XX
FIGURE 20-14: SPI MASTER MODE T IMING (CKE = 1)
TABLE 20-9: SPI MODE REQUIREMENTS (MASTER MODE, CKE = 1)
SS
SCK
(CKP = 0)
SCK
(CKP = 1)
SDO
SDI
81
71 72
74
75, 76
78
80
MSb
79
73
MSb IN
BIT6 - - - - - -1
LSb IN
BIT6 - - - -1
LSb
Note: Refer to Figure 20-5 for load conditions.
Param.
No. Symbol Characteristic Min TypMax Units Conditions
71 TscH SCK input high time
(Slave mode) Continuous 1.25TCY + 30 ——ns
71A Single Byte 40 ——ns (Note 1)
72 TscL SCK input low time
(Slave mode) Continuous 1.25 TCY + 30 ——ns
72A Single Byte 40 ——ns (Note 1)
73 TdiV2scH,
TdiV2scL Setup time of SDI data input to SCK edge 100 ——ns
73A TB2BLast clock edge of Byte1 to the 1st clock edge
of Byte2 1.5TCY + 40 ——ns (Note 1)
74 TscH2diL,
TscL2diL Hold time of SDI data input to SCK edge 100 ——ns
75 TdoR SDO data output rise time 10 25 ns
76 TdoF SDO data output fall time 10 25 ns
78 TscR SCK output rise time (Master mode) 10 25 ns
79 TscF SCK output fall time (Master mode) 10 25 ns
80 TscH2doV,
TscL2doV SDO data output valid after SCK edge ——50 ns
81 TdoV2scH,
TdoV2scL SDO data output setup to SCK edge Tcy ——ns
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: S peci fication 73A is only required if specifications 71A and 72A are used.
PIC17C7XX
DS30289B-page 256 2000 Microchip Technology Inc.
FIGURE 20-15: SPI SLAVE MODE TIMING (CKE = 0)
TABLE 20-10: SPI MODE REQUIREMENTS (SLAVE MODE TI MING, CKE = 0)
SS
SCK
(CKP = 0)
SCK
(CKP = 1)
SDO
SDI
70
71 72
73 74
75, 76 77
78
79
80
79
78
SDI
MSb LSb
BIT6 - - - - - -1
MSb IN BI T 6 - - - -1 LSb IN
83
Note: Refer to Figure 20-5 for load conditions.
Param.
No. Symbol Characteristic Min TypMax Units Conditions
70 TssL2scH,
TssL2scL SS to SCK or SCK input Tcy ——ns
71 TscH SCK input high time
(Slave mode) Continuous 1.25TCY + 30 ——ns
71A Single Byte 40 ——ns (Note 1)
72 TscL SCK input low time
(Slave mode) Continuous 1.25TCY + 30 ——ns
72A Single Byte 40 ——ns (Note 1)
73 TdiV2scH,
TdiV2scL Setup time of SDI data input to SCK edge 100 ——ns
73A TB2BLast clock edge of Byte1 to the 1st clock edge
of Byte2 1.5TCY + 40 ——ns (Note 1)
74 TscH2diL,
TscL2diL Hold time of SDI data input to SCK edge 100 ——ns
75 TdoR SDO data output rise time 10 25 ns
76 TdoF SDO data output fall time 10 25 ns
77 TssH2doZ SS to SDO output hi-impedance 10 50 ns
78 TscR SCK output rise time (Master mode) 10 25 ns
79 TscF SCK output fall time (Master mode) 10 25 ns
80 TscH2doV,
TscL2doV SDO data output valid after SCK edge ——50 ns
83 TscH2ssH,
TscL2ssH SS after SCK edge 1.5TCY + 40 ——ns
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: Specification 73A is only required if specifications 71A and 72A are used.
2000 Microchip Technology Inc. DS30289B-page 257
PIC17C7XX
FIGURE 20-16: SPI SLAVE MODE TIMING (CKE = 1)
TABLE 20-11: SPI MODE REQUIREMENTS (SLAVE MODE, CKE = 1)
SS
SCK
(CKP = 0)
SCK
(CKP = 1)
SDO
SDI
70
71 72
82
SDI
74
75, 76
MSb BIT6 - - - - - -1 LSb
77
MSb IN BIT6 - - - -1 LSb IN
80
83
Note: Refer to Figure 20-5 for load conditions.
Param.
No. Symbol Characteristic Min TypMax Units Conditions
70 TssL2scH,
TssL2scL SS to SCK or SCK input Tcy ——ns
71 TscH SCK input high time
(Slave mode) Continuous 1.25TCY + 30 ——ns
71A Single Byte 40 ——ns (Note 1)
72 TscL SCK input low time
(Slave mode) Continuous 1.25TCY + 30 ——ns
72A Single Byte 40 ——ns (Note 1)
73A TB2BLast clock edge of Byte1 to the 1st clock edge
of Byte2 1.5TCY + 40 ——ns (Note 1)
74 TscH2diL,
TscL2diL Hold time of SDI data input to SCK edge 100 ——ns
75 TdoR SDO data output rise time 10 25 ns
76 TdoF SDO data output fall time 10 25 ns
77 TssH2doZ SS to SDO output hi-impedance 10 50 ns
80 TscH2doV,
TscL2doV SDO data output valid after SCK edge ——50 ns
82 TssL2doV SDO data output valid after SS edge ——50 ns
83 TscH2ssH,
TscL2ssH SS after SCK edge 1.5TCY + 40 ——ns
Data in "Typ" column is at 5V, 25°C unless otherwise stated.
Note 1: S pecificati on 73A is only required if specifications 71A and 72A are used.
PIC17C7XX
DS30289B-page 258 2000 Microchip Technology Inc.
FIGURE 20-17 : I2C BUS START/STOP BITS TIMING
TABLE 20-12: I2C BUS START/STOP BITS REQUIREMENTS
Note: Refer to Figure 20-5 for load conditions.
91 93
SCL
SDA
START
Condition STOP
Condition
90 92
Param.
No. Sym Characteristic Min Ty
pMax Units Conditions
90 Tsu:sta START condition 100 kHz mode 2(TOSC)(BRG + 1) —— ns Only relevant for
Repeated Start condition
Setup time 400 kHz mode 2(TOSC)(BRG + 1) ——
1 MHz mode(1) 2(TOSC)(BRG + 1) ——
91 Thd:sta START condition 100 kHz mode 2(TOSC)(BRG + 1) —— ns A fter this period, the first
clock pulse is generated
Hold time 400 kHz mode 2(TOSC)(BRG + 1) ——
1 MHz mode(1) 2(TOSC)(BRG + 1) ——
92 Tsu:sto STOP condition 100 kHz mode 2(TOSC)(BRG + 1) —— ns
Setup time 400 kHz mode 2(TOSC)(BRG + 1) ——
1 MHz mode(1) 2(TOSC)(BRG + 1) ——
93 Thd:sto STOP condition 100 kHz mode 2(TOSC)(BRG + 1) —— ns
Hold time 400 kHz mode 2(TOSC)(BRG + 1) ——
1 MHz mode(1) 2(TOSC)(BRG + 1) ——
Note 1: Maximum pin capacitance = 10 pF for all I2C pins.
2000 Microchip Technology Inc. DS30289B-page 259
PIC17C7XX
FIGURE 20-18 : I2C BUS DATA TIMING
TABLE 20-13: I2C BUS DATA REQUIREMENTS
Param
No. Sym Characteristic Min Max Units Conditions
100 Thigh Clock high time 100 kHz mode 2(TOSC)(BRG + 1) ms
400 kHz mode 2(TOSC)(BRG + 1) ms
1 MHz mode(1) 2(TOSC)(BRG + 1) ms
101 Tlow Clock low time 100 kHz mod e 2(TOSC)(BRG + 1) ms
400 kHz mode 2(TOSC)(BRG + 1) ms
1 MHz mode(1) 2(TOSC)(BRG + 1) ms
102 Tr SDA and SCL rise time 100 kHz mode 1000 ns Cb is specified to be from
10 to 400 pF
400 kHz mode 20 + 0.1Cb 300 ns
1 MHz mode(1) 300 ns
103 Tf SDA and SCL fall time 100 kHz mode 300 ns Cb is specified to be from
10 to 400 pF
400 kHz mode 20 + 0.1Cb 300 ns
1 MHz mode(1) 10 ns
90 Tsu:st a ST ART condition setup
time 100 kHz mode 2(TOSC)(BRG + 1) ms Only relevant for Repeated
Start condition
400 kHz mode 2(TOSC)(BRG + 1) ms
1 MHz mode(1) 2(TOSC)(BRG + 1) ms
91 Thd:sta START condition hold
time 100 kHz mode 2(TOSC)(BRG + 1) ms After this period, the first
clock pulse is generated
400 kHz mode 2(TOSC)(BRG + 1) ms
1 MHz mode(1) 2(TOSC)(BRG + 1) ms
106 Thd:d at Data input hold time 100 kHz mode 0 ns
400 kHz mode 0 0. 9 ms
1 MHz mode(1) 0ns
107 Tsu:dat Data input setup time 100 kHz mode 250 ns (Note 2)
400 kHz mode 100 ns
1 MHz mode(1) 100 ns
92 Tsu:sto STOP condition
setup time 100 kHz mod e 2(TOSC)(BRG + 1) ms
400 kHz mode 2(TOSC)(BRG + 1) ms
1 MHz mode(1) 2(TOSC)(BRG + 1) ms
109 Taa Output valid from clock 100 kHz mode 3500 ns
400 kHz mode 1000 ns
1 MHz mode(1) 400 ns
Note 1: Maximum pin capacitance = 10 pF for all I2C pins.
2: A fast mode (400 KHz) I2C bus device can be used in a standard mode I2C bus system, but the p arameter # 107 250 ns
must then be met. This will automatically be the case if the device does not stretch the LOW period of the SCL signal. If
such a device does stretch the LOW period of the SCL signal, it must output the next data bit to the SDA line.
Parameter #102 + #107 = 1000 + 250 = 1250 ns (for 100 kHz mode) before the SCL line is released.
3: Cb is specified to be from 10-400pF. The minimum specifications are characterized with Cb=10pF. The rise time spec (tr)
is characterized with Rp=Rp min. The minimum fall time specification (tf) is characterized with Cb=10pF,and Rp=Rp max.
These are only valid for fast mode operation (VDD=4.5- 5.5V) and where the SPM bit (SSPSTAT<7>) =1.)
4: Max specifications for these parameters are valid for falling edge only. Spec s are characterized with Rp=Rp min and
Cb=400pF for standard mode, 200pF for fast mode, and 10pF for 1MHz mode.
Note: Refer to Figure 20-5 for load conditions.
90 91 92
100 101
103
106 107
109 109 110
102
SCL
SDA
In
SDA
Out
PIC17C7XX
DS30289B-page 260 2000 Microchip Technology Inc.
FIGURE 20-19: USART SYNCHRONOUS TRANSMISSION (MASTER/SLAVE) TIMING
TABLE 20-14: USART SYNCHRONOUS TRANSMISSION REQUIREMENTS
110 Tbuf Bus free time 100 kHz mode 4.7 ms Time the bus must be free
before a new transmission
can start
400 kHz mode 1.3 ms
1 MHz mode(1) 0.5 ms
D102 Cb Bus capacitive loading 400 pF
Param
No. Sym Characteristic Min Max Units Conditions
Note 1: Maximum pin capacitance = 10 pF for all I2C pins.
2: A fast mode (400 KHz) I2C bus device can be used in a standard mode I2C bus system, but the p arameter # 107 250 ns
must then be met. This will automatically be the case if the device does not stretch the LOW period of the SCL signal. If
such a device does stretch the LOW period of the SCL signal, it must output the next data bit to the SDA line.
Parameter #102 + #107 = 1000 + 250 = 1250 ns (for 100 kHz mode) before the SCL line is released.
3: Cb is specified to be from 10-400pF. The minimum specifications are characterized with Cb=10pF. The rise time spec (tr)
is characterized with Rp=Rp min. The minimum fall time specification (tf) is characterized with Cb=10pF,and Rp=Rp max.
These are only valid for fast mode operation (VDD=4.5- 5.5V) and where the SPM bit (SSPSTAT<7>) =1.)
4: Max specifications for these parameters are valid for falling edge only. Spec s are characterized with Rp=Rp min and
Cb=400pF for standard mode, 200pF for fast mode, and 10pF for 1MHz mode.
121 121
120 122
TX/CK
RX/DT
pin
pin
Param
No. Sym Characteristic Min TypMax Units Conditions
120 TckH2dtV SYNC XMIT (MAS T ER & SLAVE)
Clock high to data out valid P IC17 CXXX ——50 ns
PIC17LCXXX ——75 ns
121 TckRF Clock out rise time and fall time
(Master mode) PIC17CXXX ——25 ns
PIC17LCXXX ——40 ns
122 TdtRF Data out rise time and fall time PIC17CXXX ——25 ns
PIC17LCXXX ——40 ns
Data in Typ column is at 5V, 25°C unless otherwise stated.
2000 Microchip Technology Inc. DS30289B-page 261
PIC17C7XX
FIGURE 20-20: USART SYNCHRONOUS RECEIVE (MASTER/SLAVE) TIMING
TABLE 20-15: USART SYNCHRONOUS RECEIVE REQUIREMENTS
125
126
TX/CK
RX/DT
pin
pin
Param
No. Sym Characteristic Min TypMax Unit
sConditions
125 TdtV2ckL SYNC RCV (MASTER & SLAVE)
Data setup before CK (DT setup time) 15 ——ns
126 TckL2dtl Data hold after CK (DT hold time) 15 ——ns
Data in Typ column is at 5V, 25°C unless otherwise stated.
PIC17C7XX
DS30289B-page 262 2000 Microchip Technology Inc.
FIGURE 20-21: USART ASYNCHRONOUS MODE START BIT DETECT
TABLE 20-16: USART ASYNCHRONOUS MODE START BIT DETECT REQUIREMENTS
FIGURE 20-22: USART ASYNCHRONOUS RECEIVE SAMPLING WAVEFORM
TABLE 20-17: USART ASYNCHRONOUS RECEIVE SAMPLING REQUIREMENTS
RX
x16 CLK
Q2, Q4 CLK
START bit
(RX/DT pin) 121A
120A 123A
Param
No. Sym Characteristic Min Typ Max Unit
sConditions
120A TdtL2ckH Time to ensure that the RX pin is sampled low ——TCY ns
121A TdtRF Data rise time and fall time Receive ——(Note 1) ns
Transmit ——40 ns
123A TckH2bckL T ime from RX pin sampled low to first rising edge
of x16 clock ——TCY ns
Note 1: Sc hmitt trigger will determine logic level.
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
(RX/DT pin)
125A 126A
Param
No. Sym Characteristic Min Typ Max Unit
sConditions
125A TdtL2ckH Setup time of RX pin to first data sampled TCY ——ns
126A TdtL2ckH Hold time of RX pin from last data sam-
pled TCY ——ns
2000 Microchip Technology Inc. DS30289B-page 263
PIC17C7XX
TABLE 20-18: A/D CONVERTER CHARACTERISTICS
Param.
No. Sym Characteristic Min TypMax Units Conditions
A01 NRResolution —— 10 bit VREF+ = VDD = 5.12V,
VSS VAIN VREF+
—— 10 bit (VREF+ VREF-) 3.0V,
VREF- VAIN VREF+
A02 EABS Absolute error ——< ±1LSbVREF+ = VDD = 5.12V,
VSS VAIN VREF+
——< ±1LSb(V
REF+ VREF-) 3.0V,
VREF- VAIN VREF+
A03 EIL Integral linearity error ——< ±1LSbVREF+ = VDD = 5.12V,
VSS VAIN VREF+
——< ±1LSb(V
REF+ VREF-) 3.0V,
VREF- VAIN VREF+
A04 EDL Differential linearity error ——< ±1LSbVREF+ = VDD = 5.12V,
VSS VAIN VREF+
——< ±1LSb(V
REF+ VREF-) 3.0V,
VREF- VAIN VREF+
A05 EFS Full scale error ——< ±1LSbVREF+ = VDD = 5.12V,
VSS VAIN VREF+
——< ±1LSb(V
REF+ VREF-) 3.0V,
VREF- VAIN VREF+
A06 EOFF Offset error ——< ±1LSbVREF+ = VDD = 5.12V,
VSS VAIN VREF+
——< ±1LSb(V
REF+ VREF-) 3.0V,
VREF- VAIN VREF+
A10 Monotonicity guaranteed(3) ——VSS VAIN VREF
A20 VREF Reference voltage
(VREF+ VREF-) 0V ——VV
REF delta when changing voltage
levels on VREF inputs
A20A 3V ——V Absolute minimum electrical spec.
to ensure 10-bit accuracy
A21 VREF+ Ref erence voltage high AVSS
+ 3.0V AVDD +
0.3V V
A22 VREF- Reference voltage low Avss -
0.3V AVDD -
3.0V V
A25 VAIN Analog input voltage AVSS -
0.3V Vref +
0.3V V
A30 ZAIN Recommended impedance of
analog voltage source ——10.0 k
A40 IAD A/D conversion
current (VDD)PIC17CXXX 180 µA Average curr ent consu mption when
A/D is on (Note 1)
PIC17LCXXX 90 µA
A50 IREF VREF input curr ent (Note 2) 10 1000 µA During VAIN acquisition.
Based on differential of VHOLD to
VAIN
—— 10 µA During A/D conversion cycle
Data in Typ column is at 5V, 25°C unless otherwise stated.
Note 1: When A/D is off, it will not consume any current other than minor leakage current. The power-down current spec includes
any such leakage from the A/D module.
2: VREF current is from RG0 and RG1 pins or AVDD and AVSS pins, whichever is selected as reference input.
3: The A/D conversion result never decreases with an increase in the Input Voltage and has no missing codes.
PIC17C7XX
DS30289B-page 264 2000 Microchip Technology Inc.
FIGURE 20-23: A/D CONVERSION TIMING
TABLE 20-19: A/D CONVERSION REQUIREMENTS
Param.
No. Sym Characteristic Min TypMax Units Conditions
130 TAD A/D clock period PIC17CXXX 1.6 ——µsTOSC based, VREF 3.0V
PIC17LCXXX 3.0 ——µsT
OSC based, V REF full range
PIC17CXXX 2.0 4.0 6.0 µs A/D RC mode
PIC17LCXXX 3.0 6.0 9.0 µs A/D RC mode
131 TCNV Conversion time
(not including acquisition time) (Note 1) 11 12 Tad
132 TACQ Acquisition time (Note 2)
10
20
µs
µs The mi nimum time is the
amplifier settling time. This
may be used if the new
input voltage has not
changed by more than 1LSb
(i.e., 5 mV @ 5.12V) from
the last sampled voltage (as
stated on CHOLD).
134 TGO Q4 to ADCLK start Tosc/2 If the A/D clock source is
selected as RC, a time of
TCY is added before the A/D
clock starts. This allows the
SLEEP instruction to be
executed.
Data in Typ column is at 5V, 25°C unless otherwise stated.
Note 1: ADRES regist er may be read on the following TCY cycle.
2: See Section 16.1 for minimum conditions when input voltage has changed more than 1 LSb.
131
130
132
BSF ADCON0, GO
Q4
A/D CLK
A/D DATA
ADRES
ADIF
GO
SAMPLE
OLD_DATA
SAMPLIN G STO PPED
DONE
NEW_DATA
(TOSC/2)(1)
987 210
Note 1: If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts. This allows the
SLEEP instruction to be executed.
1 TCY
. . . . . .
2000 Microchip Technology Inc. DS30289B-page 265
PIC17C7XX
FIGURE 20-24: MEMORY INTERFACE WRITE TIMING
TABLE 20-20: MEMORY INTERFACE WRITE REQUIREMENTS
OSC1
ALE
OE
WR
AD<15:0>
Q1 Q2 Q3 Q4 Q1 Q2
150
151
152 153
154
addr out data out addr out
Q1
Param.
No. Sym Characteristic Min TypMax Unit
sConditions
150 TadV2alL AD<15:0> (address) valid
to PIC17CXXX 0.25TCY - 10 ——ns
ALE (address setup
time) PIC17LCXXX 0.25TCY - 10 ——
151 TalL2adI ALE to address out invalid PIC17CXXX 0 ——ns
(address hold time) PIC17LCXXX 0 ——
152 TadV2wrL Data out valid to WRPIC17CXXX 0.25TCY - 40 ——ns
(data setup time) PIC17LCXXX 0.25TCY - 40 ——
153 TwrH2adI WR to data out invalid PIC17CXXX 0.25TCY ns
(data hold time) PIC17LCXXX 0.25TCY
154 TwrL WR pulse width PIC17CXXX 0.25TCY ns
PIC17LCXXX 0.25TCY
Data in Typ column is at 5V, 25°C unless otherwise stated.
PIC17C7XX
DS30289B-page 266 2000 Microchip Technology Inc.
FIGURE 20-25: MEMORY INTERFACE READ TIMING
TABLE 20-21: MEMORY INTERFACE READ REQUIREMENTS
OSC1
ALE
OE
AD<15:0>
WR
Q1 Q2 Q3
Data in Addr out
150 151
160
166
165
162 163
161
11
Q4 Q1 Q2
Addr out
164 168
167
Param.
No. Sym Characteristic Min TypMax Unit
sConditions
150 TadV2alL AD15:AD0 (address) valid to PIC17CXXX 0.25TCY - 10 ——ns
ALE (address setup time) PIC17LCXXX 0.25TCY - 10 ——
151 TalL2adI ALE to address out invalid PIC17CXXX 5 ——ns
(address hold time) PIC17LCXXX 5 ——
160 TadZ2oeL AD15:AD0 hi-impedance to PIC17CXXX 0 ——ns
OEPIC17LCXXX 0 ——
161 ToeH2ad
DOE to AD15:AD0 driven PIC17CXXX 0.25TCY - 15 ——ns
PIC17LCXXX 0.25TCY - 15 ——
162 TadV2oeH Data in valid before OE PIC17CXXX 35 ——ns
(data setup time) PIC17LCXXX 45 ——
163 ToeH2adI OEto data in invalid PIC17CXXX 0 ——ns
(data hold time) PIC17LCXXX 0 ——
164 TalH ALE pulse width PIC17CXXX 0.25TCY ns
PIC17LCXXX 0.25TCY
165 ToeL OE pulse width PIC17CXXX 0.5TCY - 35 ——ns
PIC17LCXXX 0.5TCY - 35 ——
166 TalH2alH ALE to ALE(cycle time) PIC17CXXX TCY ns
PIC17LCXXX TCY
167 Tac c Add ress acc ess tim e PIC17CXXX ——0.75TCY - 30 ns
PIC17LCXXX ——0.75TCY - 45
168 Toe O utput enable access time PIC17CXXX ——0.5TCY - 45 ns
(OE low to data valid) PIC17LCXXX ——0.5TCY - 75
Data in Typ column is at 5V, 25°C unless otherwise stated.
2000 Microchip Technology Inc. DS30289B-page 267
PIC17C7XX
21.0 PIC17 C7XX DC AND AC CHARACTERISTICS
The graphs and tables provided in this section are for design guidance and are not tested nor guaranteed. In some
graph s or t a ble s the dat a presente d is out s ide speci fie d ope rati ng range (e.g., ou tside specified VDD range). Thi s is for
information only and devices are ensured to operate properly only within the specified range.
The data presented in this section is a statistical summary of data collected on units from different lots over a period of
time.
Typ or Typical represents the mean of the distribution at 25°C.
Max or Maximum represents (mean + 3 σ) over the temperature range of -40°C to 85°C.
Min or Minimum represents (mean - 3σ) over the temperature range of -40°C to 85°C.
Note: Standard deviation is denoted by sigma (σ).
TABLE 21-1: PIN CAPACITANCE PER PACKAGE TYPE
FIGURE 21-1: TYPICAL RC OSCILLATOR FREQUENCY vs. TEMPERATURE
Pin Name Typical Capacitance (pF)
68-pin PLCC 64-pin TQFP
All pins, except MCLR, VDD, and VSS 10 10
MCLR pin 20 20
Fosc
Fosc (25°C)
1.10
1.08
1.06
1.04
1.02
1.00
0.98
0.96
0.94
0.92
0.90
01020253040506070
T(°C)
Frequency normalized to +25°C
VDD = 5.5V
VDD = 3.5V
REXT 10 k
CEXT = 100 pF
PIC17C7XX
DS30289B-page 268 2000 Microchip Technology Inc.
FIGURE 21-2: TYPICAL RC OSCILLATOR FREQUENCY vs. VDD
FIGURE 21-3: TYPICAL RC OSCILLATOR FREQUENCY vs. VDD
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.04.0 4.5 5.0 5.5 6.0 6.5
FOSC (MHz)
VDD (Volt s)
R = 10k
CEXT = 22 pF, T = +25°C
R = 100k
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.04.0 4.5 5.0 5.5 6.0 6.5
FOSC (MHz)
VDD (Volt s)
R = 10k
CEXT = 100 pF, T = +25°CR = 100k
R = 3.3k
R = 5.1k
2000 Microchip Technology Inc. DS30289B-page 269
PIC17C7XX
FIGURE 21-4: TYPICAL RC OSCILLATOR FREQUENCY vs. VDD
TABLE 21-2: RC OSCILLATOR FREQUENCIES
2.0
1.8
1.6
1.4
1.2
1.0
0.8
0.6
0.4
4.0 4.5 5.0 5.5 6.0 6.5
FOSC (MHz)
VDD (Volts)
R = 10k
CEXT = 300 pF, T = +25°C
R = 160k
R = 3.3k
R = 5.1k
0.2
0.0
CEXT REXT Average
FOSC @ 5V, +25°C
22 pF 10k 3.33 MHz ± 12%
100k 353 kHz ± 13%
100 pF 3 .3k 3.54 MHz ± 10%
5.1k 2.43 MHz ± 14%
10k 1.30 MHz ± 17%
100k 129 kHz ± 10%
300 pF 3 .3k 1.54 MHz ± 14%
5.1k 980 kHz ± 12%
10k 564 kHz ± 16%
160k 35 kHz ± 18%
PIC17C7XX
DS30289B-page 270 2000 Microchip Technology Inc.
FIGURE 21-5: TRANSCONDUCTANCE (gm) OF LF OSCILLATOR vs. VDD
FIGURE 21-6: TRANSCONDUCTANCE (gm) OF XT OSCILLATOR vs. VDD
500
450
400
350
300
250
200
150
100
2.5 3.0 3.5 4.0 4.5 5.0
gm(µA/V)
VDD (Volts)
Min @ +85°C
50
05.5 6.0
Max @ -40°C
Typ @ +25°C
20
18
16
14
12
10
8
6
4
2.5 3.0 3.5 4.0 4.5 5.0
gm(mA/V)
VDD (Volts)
Min @ +85°C
2
05.5 6.0
Max @ -40°C
Typ @ +25°C
2000 Microchip Technology Inc. DS30289B-page 271
PIC17C7XX
FIGURE 21-7: TYPICAL IDD vs. FOSC OVER VDD (LF MODE)
FIGURE 21-8: MAXIMU M IDD vs. FOSC OVER VDD (LF MODE)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
FOSC (MHz)
I
DD
(mA)
3.0V
3.5V
4.0V
5.5V
5.0V
4.5V
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0.00.20.40.60.81.01.21.41.61.82.0
FOSC (MH z )
I
DD
(mA)
3.0V
3.5V
4.0V
5.5V
5.0V
4.5V
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Mini mum: mean 3s (-40°C to 125°C)
PIC17C7XX
DS30289B-page 272 2000 Microchip Technology Inc.
FIGURE 21-9: TYPICAL IDD vs. FOSC OVER VDD (XT MODE)
FIGURE 21-10 : MAXIMU M IDD vs. FOSC OVER VDD (XT MODE)
0
2
4
6
8
10
12
14
16
0 5 10 15 20 25 30 35
FOSC(MHz)
I
DD
(mA)
5.5V
5.0V
4.5V
4.0V
3.5V
3.0V
Typical: s tatis tic al mean @ 25 °C
Ma ximum: mean + 3σ (-40°C to 125 °C)
Min imu m: me an 3σ (-40°C to 125 °C)
Typical: statistica l m ean @ 25°C
Maxim um: mean + 3s (-40°C to 125 °C)
Minimum: mean 3s (- 40°C to 1 2 5°C)
0
2
4
6
8
10
12
14
16
18
0 5 10 15 20 25 30 35
FOSC (MHz)
I
DD
(mA)
5.5V
5.0V
4.5V
4.0V
3.5V
3.0V
Typical: statis tic al mean @ 25°C
Maximum: mean + 3σ (-40°C to 125°C)
Min imum: me an 3σ (-40°C to 125°C)
Typical: statistical mean @ 25°C
Maxim um: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
2000 Microchip Technology Inc. DS30289B-page 273
PIC17C7XX
FIGURE 21-11: TYPICAL AND MAXIMUM IPD vs. VDD (SLEEP MODE, ALL PERIPHERALS
DISABLED, -40°C to +125°C)
FIGURE 21-12: TYPICAL AND MAXIMUM IPD vs. VDD (SLEEP MODE, BOR ENABLED, -40°C to
+125°C)
0.0
1.0
2.0
3.0
4.0
5.0
6.0
3.03.54.04.55.05.5
VDD (V )
I
PD
(uA)
Max
Typ
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Mini mum: mean 3s (-40°C to 125°C)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
I
DD
(mA)
Max Reset
Ty p Reset (25C)
M ax S leep
Ty p Sleep (25C)
Device in S leepDevice in Res et
Indeterm inate St ate
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
PIC17C7XX
DS30289B-page 274 2000 Microchip Technology Inc.
FIGURE 21-13: TYPICAL AND MAXIMUM IPD vs. VDD (SLEEP MODE, WDT ENABLED, -40°C to
+125°C)
FIGURE 21-14: TYPICAL AND MAXIMUM IRBPU vs. VDD (MEASURED PER INPUT PIN,
-40°C TO +125°C)
0
2
4
6
8
10
12
14
16
18
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V )
I
PD
(uA)
Max
Typ
0
50
100
150
200
250
300
2.5 3.0 3.5 4.0 4.5 5.0 5.5
VDD (V )
I (uA)
Ty p i c a l (2 5 C)
Maximum
Typical: statistical mean @ 25°C
Maximum: mean + 3σ (-40°C to 1 2 5 °C)
Minimum: mean 3σ (-40°C to 1 2 5 °C)
Typical: statistical mean @ 25°C
Maxim um: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (- 40°C to 125°C)
2000 Microchip Technology Inc. DS30289B-page 275
PIC17C7XX
FIGURE 21-15: TYPICAL, MINIMUM AND MAXIMUM WDT PERIOD vs. VDD (-40°C TO +125°C)
FIGURE 21-16: TYPICAL WDT PERIOD vs. VDD OVER TEMPERATURE (-40°C TO +125°C)
0
5
10
15
20
25
30
35
40
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V )
WDT Period (ms)
Max (125C)
Typ (25C)
M in (-40C)
Typical: statistical mean @ 25°C
Ma ximum: me an + 3σ (-40°C to 125 °C)
Mini mum: me an 3σ (-40°C to 1 2 5 °C)
Typical: statistical mean @ 25°C
Maximum: me an + 3s (-40°C to 1 2 5 °C)
Minimum: mean 3s (-40°C to 125°C)
0
5
10
15
20
25
30
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
WDT Period (ms)
125C
85C
25C
-40C
PIC17C7XX
DS30289B-page 276 2000 Microchip Technology Inc.
FIGURE 21-17: TYPICAL, MINIMUM AND MAXIMUM VOH vs. IOH (VDD = 5V, -40°C TO +125°C)
FIGURE 21-18: TYPICAL, MINIMUM AND MAXIMUM VOL vs. IOL (VDD = 5V, -40°C TO +125°C)
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
0 5 10 15 20 25
IOH (-m A )
V
OH
(V)
Max
Ty p (25C)
Min
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
0 5 10 15 20 25
IOL (mA)
V
OL
(V)
Max (125C )
Typ (25C )
Min (-40C )
Typic al: statis tical mean @ 25°C
Maximum: me an + 3σ (-40°C to 1 2 5 °C)
Minimum: mean 3 σ (- 40 °C to 1 2 5 °C)
Typical: statistical mean @ 25°C
Maximu m: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
2000 Microchip Technology Inc. DS30289B-page 277
PIC17C7XX
FIGURE 21-19: TYPICAL, MINIMUM AND MAXIMUM VOH vs. IOH (VDD = 3V, -40°C TO +125°C)
FIGURE 21-20: TYPICAL, MINIMUM AND MAXIMUM VOL vs. IOL (VDD = 3V, -40°C TO +125°C)
0.0
0.5
1.0
1.5
2.0
2.5
3.0
0 5 10 15 20 25
IOH (-m A )
V
OH
(V)
Max
Ty p (25C)
Min
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
0 5 10 15 20 25
IOL (mA)
V
OL
(V)
Max (125C)
Typ (25C)
Min (-40C)
Typical: s tatistical mean @ 25°C
Ma ximum: me an + 3 σ (-40°C to 12 5 °C)
Min imum: mean 3σ (- 40°C to 1 25 °C)
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
PIC17C7XX
DS30289B-page 278 2000 Microchip Technology Inc.
FIGURE 21-21: TYPICAL, MAXIMUM AND MINIMUM VIN vs. VDD (TTL INPUT, -40°C to 125°C)
FIGURE 21-22: MAX IMU M AND MINIMUM VIN vs. VDD (ST Input, -40° C to +125°C)
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
V
IN
(V)
Min
Max
Ty p (25C)
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Mini mum: mean 3s (-40°C to 125°C)
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
3.0 3.5 4.0 4.5 5.0 5.5
VDD (V)
V
IN
(V)
Max Rising
Min Rising
Ma x Falling
Min Fall ing
Typical: statistical mean @ 25°C
Maximum: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
2000 Microchip Technology Inc. DS30289B-page 279
PIC17C7XX
FIGURE 21-23: MAX IMU M AND MINIMUM VIN vs. VDD (I2C Input, -40°C to +125°C)
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
3.03.54.04.55.05.5
VDD (V )
V
IN
(V)
Max Rising
Min Rising
Max Falling
Min Fa lling
Typical: statistical mean @ 25°C
Maximu m: mean + 3s (-40°C to 125°C)
Minimum: mean 3s (-40°C to 125°C)
PIC17C7XX
DS30289B-page 280 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 281
PIC17C7XX
22.0 PACKAGING INFORMATION
22.1 Package Marking Information
64-Lead TQFP
XXXXXXXXXX
YYWWNNN
XXXXXXXXXX
Example
XXXXXXXXXX -08I/PT
0017CAE
PIC17C752
Legend: XX...X Customer specific information*
YY Year code (last 2 digits of calendar year)
WW Week code (week of January 1 is week 01)
NNN Alphanumeric traceability code
Note: In the event the ful l Micro chip pa rt numbe r cannot be ma rked on o ne line, it will
be carried ov er to the ne xt l ine t hus lim iti ng the number of av ai lab le cha racters
for customer specific information.
68-Lead PLCC
YYWWNNN
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
Example
0048CAE
PIC17C756A-08/L
80-Lead TQFP
YYWWNNN
XXXXXXXXXXXX
XXXXXXXXXXXX
Example
0017CAE
PIC17C762
-08I/PT
*Standard OTP marking consists of Microchip part number, year code, week code, facility code, mask
rev#, and assembly code. For OTP marking beyond this, certain price adders apply. Please check with
your Microchip Sales Office. For QTP devices, any special marking adders are included in QTP price.
PIC17C7XX
DS30289B-page 282 2000 Microchip Technology Inc.
Package Marking Information (Cont.)
84-Lead PLCC
YYWWNNN
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX
Example
0048CAE
PIC17C766-08/L
2000 Microchip Technology Inc. DS30289B-page 283
PIC17C7XX
64-Lead Plastic Thin Quad Flatpack (PT) 10x10x1 mm Body, 1.0/0.10 mm Lead Form (TQFP)
* Controlling Parameter
Notes:
Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MS-026
Drawing No. C04-085
1510515105
β
Mold Draft Angle Bottom 1510515105
α
Mold Draft Angle Top
0.270.220.17.011.009.007BLead Width 0.230.180.13.009.007.005
c
Lead Thic kness
1616
n1
Pins per Side
10.1010.009.90.398.394.390
D1
Molded Package Length 10.1010.009.90.398.394.390E1Molded Package Width 12.2512.0011.75.482.472.463DOverall Length 12.2512.0011.75.482.472.463EOverall Width 73.5073.50
φ
Foot Angl e
0.750.600.45.030.024.018LFoot Length 0.250.150.05.010.006.002A1Standoff §1.051.000.95.041.039.037A2Molded Package Thickness 1.201.101.00.047.043.039AOverall Height
0.50.020
p
Pitch 6464
n
Number of Pins MAXNOMMINMAXNOMMINDimen sion Li mits MILLIMETERS*INCHESUnits
c
2
1
n
DD1
B
p
#leads=n1
E1
E
A2
A1
A
L
CH x 45°
βφ
α
(F)
Footprint (Reference) (F) .039 1.00
Pin 1 Corner Chamfer CH .025 .035 .045 0.64 0.89 1.14
§ Significant Characteristic
PIC17C7XX
DS30289B-page 284 2000 Microchip Technology Inc.
68-Lead Plastic Leaded Chip Carrier (L) Square (PLCC)
10501050
β
Mold Draft Angle Bottom 10501050
α
Mold Draft Angle Top 0.530.510.33.021.020.013BLower Lead Width 0.810.740.66.032.029.026B1Upper Lead Width 0.330.270.20.013.011.008
c
Lead Thickness
1717n1Pi ns per Side
23.6223.3722.61.930.920.890D2Footprint Length 23.6223.3722.61.930.920.890E2Footprint Width 24.3324.2324.13.958.954.950D1Molded Package Length 24.3324.2324.13.958.954.950E1Molded Package Width 25.2725.1525.02.995.990.985DOverall Length 25.2725.1525.02.995.990.985EOverall Width 0.250.130.00.010.005.000CH2Corner Chamfer (others) 1.271.141.02.050.045.040CH1Corner Chamfer 1 0.860.740.61.034.029.024A3Side 1 Chamfer Height 0.51.020A1Standoff §A2Molded Package Thickness 4.574.394.19.180.173.165AOverall Height
1.27.050
p
Pitch 68
n
Number of Pins MAXNOMMINMAXNOMMINDimension Limits MILLIMETERSINCHES*Units
β
A2
c
E2
2
DD1
n
#leads=n1
E
E1
1α
p
B
A3
A
B1
32°
D2
68
A1
.145 .153 .160 3.68 3.87 4.06
.028 .035 0.71 0.89
CH1 x 45 °
CH2 x 45°
* Controlling Parameter
Notes:
Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MO-047
Drawing No. C04-049
§ Significant Characteristic
2000 Microchip Technology Inc. DS30289B-page 285
PIC17C7XX
80-Lead Plastic Thin Quad Flatpack (PT) 12x12x1 mm Body, 1.0/0.10 mm Lead Form (TQFP)
* Controlling Parameter
Notes:
Dimensions D1 and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MS-026
Drawing No. C04-092
1.101.00.043.039
1.140.890.64.045.035.025CHPin 1 Corner Chamfer
1.00.039
(F)
Footprint (Reference)
(F)
E
E1
#leads=n1
p
B
D1 D
n
1
2
φ
c
βL
A
A1 A2
α
Units INCHES MILLIMETERS*
Dimen sion Li mit s M IN NO M MAX MIN NOM MAX
Number of Pins n80 80
Pitch p.020 0.50
Overall Height A .047 1.20
Molded Package Thickness A2 .037 .039 .041 0.95 1.00 1.05
Standoff §A1 .002 .004 .006 0.05 0.10 0.15
Foot Length L .018 .024 .030 0.45 0.60 0.75
Foot Angle φ03.5 7 03.5 7
Overall Wi dth E .541 .551 .561 13 .75 14.00 1 4.2 5
Overal l Length D . 541 .551 .561 13 .75 14.00 1 4.2 5
Molded Package Width E1 .463 .472 .482 11.75 12.00 12.25
Molded Package Length D1 .463 .472 .482 11.75 12.00 12.25
Pins per Side n1 20 20
Lead Thickness c.004 .006 .008 0.09 0.15 0.20
Lead Width B .007 .009 .011 0.17 0.22 0.27
Mold Draft Angle Top α5 10 15 5 10 15
Mold Draft Angle Bottom β5 10 15 5 10 15
CH x 45°
§ Significant Characteristic
PIC17C7XX
DS30289B-page 286 2000 Microchip Technology Inc.
84-Lead Plastic Leaded Chip Carrier (L) Square (PLCC)
10501050
β
Mold Draft Angle Bottom 10501050
α
Mold Draft Angle Top 0.530.510.33.021.020.013BLower Lead Width 0.810.740.66.032.029.026B1Upper Lead Width 0.330.270.20.013.011.008
c
Lead Thickness
1717n1Pins per Side
23.6223.3722.61.930.920.890D2Footprint Length 23.6223.3722.61.930.920.890E2Footprint Width 24.3324.2324.13.958.954.950D1Molded Package Length 24.3324.2324.13.958.954.950E1Molded Package Width 25.2725.1525.02.995.990.985DOverall Length 25.2725.1525.02.995.990.985EOverall Width 0.250.130.00.010.005.000CH2Corner Chamfer (others) 1.271.141.02.050.045.040CH1Corner Chamfer 1 0.860.740.61.034.029.024A3Side 1 Chamfer Height 0.51.020A1Standoff §A2Molded Package Thickness 4.574.394.19.180.173.165AOverall Height
1.27.050
p
Pitch 68
n
Number of Pins MAXNOMMINMAXNOMMINDim en si on Limits MILLIMETERSINCHES*Units
β
A2
c
E2
2
DD1
n
#leads=n1
E
E1
1α
p
B
A3
A
B1
32°
D2
68
A1
.145 .153 .160 3.68 3.87 4.06
.028 .035 0.71 0.89
CH1 x 45°CH2 x 45°
* Controlling Parameter
Notes:
Dimensions D and E1 do not include mold flash or protrusions. Mold flash or protrusions shall not exceed
.010 (0.254mm) per side.
JEDEC Equivalent: MO-047
Drawing No. C04-093
§ Significant Characteristic
2000 Microchip Technology Inc. DS30289B-page 287
PIC17C7XX
APPENDIX A: MODIFICATIONS
The following is the list of modifications over the
PIC16CXX microcontroller family:
1. Instruction word length is increased to 16-bit.
This allows larger page sizes, both in program
memory (8 Kwo rds ve rses 2 Kword s) and re gi s-
ter file (256 bytes versus 128 bytes).
2. Four modes of operation: Microcontroller,
Protected Microcontroller, Extended Micro-
controller, and Microprocessor.
3. 22 new instructions.
The MOVF, TRIS and OPTION instructions are
no longer supported.
4. Four new instructions (TLRD, TLWT, TABLRD,
TABLWT) for transferring data between data
memory and program memory. They can be used
to self program the EPROM program memory.
5. Single cycle data memo ry to data memory trans-
fers possible (MOVPF and MOVFP instructions).
These instructions do not affect the Working
register (WREG).
6. W registe r (WREG ) is now d irectly addres sabl e.
7. A PC h igh l atch r egis ter (P CLATH) is ex tend ed
to 8-bits. The PCLATCH register is now both
readable and writable.
8. Data memory paging is redefined slightly.
9. DDR registers replace function of TRIS regis-
ters.
10. Multiple Interrupt vectors added. This can
decrease the latency for servicing interrupts.
11. Stack size is increased to 16 deep.
12. BSR register for data memory paging.
13. W ake-up from SLEEP operates slig htly dif ferently.
14. The Oscill ator Start- Up T imer (O ST) and Po wer-
Up Timer (PWRT) operate in parallel and not in
series.
15. PORTB interrupt-on-change feature works on
all eight port pins.
16. TMR0 is 16-bit, plus 8-bit presc al er.
17. Second indirect addressing register added
(FSR1 and FSR2). Control bits can select the
FSR registers to auto-increment, auto-decre-
ment, remain unchanged after an indirect
address.
18. Hardware multiplier added (8 x 8 16-bit).
19. Peripheral modules operate slightly differently.
20. A/D has both VREF+ and VREF- inputs.
21. USARTs do not implement BRGH feature.
22. Oscillator modes slightly redefined.
23. Control/Status bits and registers have been
placed in different registers and the control bit
for globally enabling interrupts has inverse
polarity.
24. In-circuit serial programming is implemented
differently.
APPENDIX B: COMPATIBILITY
To convert code written for PIC16CXXX to
PIC17CXXX, the user should take the following steps:
1. Remove any TRIS and OPTION instructions,
and implement the equivalent code.
2. Separate the Interrupt Service Routine into its
four vectors.
3. Replace:
MOVF REG1, W
with:
MOVFP REG1, WREG
4. Replace:
MOVF REG1, W
MOVWF REG2
with:
MOVPF REG1, REG2 ; Addr(REG1)<20h
or
MOVFP REG1, REG2 ; Addr(REG2)<20h
5. Ensure that all bit names and register names are
updated to new data memory map locations.
6. Verify data memory banking.
7. V erify mode of opera tion for indire ct addressin g.
8. Verify peripheral routines for compatibility.
9. Weak pull-ups are enabled on RESET.
10. WDT time-outs always reset the device (in run
or SLEEP mode).
B.1 Upgrading from PIC17C42 Devices
To convert code from the PIC17C42 to all the other
PIC17CXXX devices, the user should take the follow-
ing steps.
1. If the hardware multiply is to be used, ensure
that any variables at address 18h and 19h are
moved to another address.
2. Ensure that t he upper n ibble of the BSR was not
written with a non-zero value. This may cause
unexpec ted o peratio n sin ce the RAM bank is no
longer 0.
3. The disabling of global interrupts has been
enhance d, so there is no additional testing of the
GLINTD bit after a BSF CPUSTA, GLINTD
instruction.
Note: If REG1 and REG2 are both at addresses
greater then 20h, two instructions are
required.
MOVFP REG1, WREG ;
MOVPF WREG, REG2 ;
PIC17C7XX
DS30289B-page 288 2000 Microchip Technology Inc.
APPENDIX C: WHATS NEW
This is a new Data Sheet for the Following Devices:
PIC17C752
PIC17C756A
PIC17C762
PIC17C766
This Data Sheet is based on the PIC17C75X Data
Sheet (DS30246A).
APPENDIX D: WHATS CHANGED
Clarified the TAD vs. device maximum operating fre-
quency tables in Section 16.2.
Added device characteristic graphs and charts in
Section 21.
Removed the Preliminary status from the entire
document.
2000 Microchip Technology Inc. DS30289B-page 289
PIC17C7XX
INDEX
A
A/D Accuracy/Error..........................................................189
ADCON0 Register.....................................................179
ADCON1 Register.....................................................180
ADIF bit................. .............. ............... ............... ........181
Analog Input Model Block Diagram......................... ..184
Analog-to-Digital Converter.......................................179
Block Diag ram......... .......... ............... ............... ..........181
Configuring Analog Port Pins....................................186
Configuring the Interrupt...........................................181
Configuring the Module.............................................181
Connection Considerations.......................... ....... .. ....189
Conversi o n Clo ck.......... .......... ............... ............... ....185
Conversions..............................................................186
Converter Characteristics .........................................263
Delays.......................................................................183
Effects of a RESET...................................................188
Equations..................................................................183
Flow Chart of A/D Operation.....................................187
GO/DONE bit............................................................181
Internal Sampling Switch (Rss) Impedence..............183
Operation During SLEEP..........................................188
Sampling Requirements..................... .... .. .. .. ....... .... ..183
Sampli n g Time........ .......... ............... ............... ..........183
Source Impedence.................. ......... .... .... .... ......... ....183
Time Dela ys...................... ............... ............... ..........183
Transfe r Functio n.................. ............... ............... ......189
A/D Interrupt.................. .............. ............... ............... ..........38
A/D Interrupt Flag bi t, ADIF............. ............... ............... ......38
A/D Module Interrupt Enable, ADIE ....................................36
ACK...................................................................................144
Acknowledge Data bit, AKD..............................................136
Acknowledge Pulse...........................................................144
Acknowledge Sequence Enable bit, AKE .........................136
Acknowledge Status bit, AKS ...........................................136
ADCON0.............................................................................49
ADCON1.............................................................................49
ADDLW.............................................................................202
ADDWF.............................................................................202
ADDWFC ..........................................................................203
ADIE....................................................................................36
ADIF....................................................................................38
ADRES Register...............................................................179
ADRESH.............................................................................49
ADRESL..............................................................................49
AKD...................................................................................136
AKE...................................................................................136
AKS...........................................................................136, 159
ALU.....................................................................................11
ALUSTA............................................................................198
ALUSTA Register................................................................51
ANDLW.............................................................................203
ANDWF.............................................................................204
Application Note AN552, Implementing Wake-up
on Keystroke......................................................................74
Application Note AN578, "Use of the SSP Module
in the I2C Multi-Master Environment."...............................143
Assembler
MPASM Assembler...................................................233
Asynchronous Master Transmission.................................123
Asynchronous Transmitter................................................123
B
Bank Select Register (BSR)............................................... 57
Banking......................................................................... 46, 57
Baud Rate Formula........................................................... 120
Baud Rate Generator ....................................................... 153
Baud Rate Generator (BRG) ............................................ 120
Baud Rates
Asynchronous Mode................................................. 122
Synchronous Mode................................................... 121
BCF .................................................................................. 204
BCLIE ................................................................................. 36
BCLIF ................................................................................. 38
BF............................................................. 134, 14 4, 159, 162
Bit Manipu lation...... .......... ............... ............... .............. .... 198
Block Diagrams
A/D............................................................................ 181
Analog Input Model................................................... 184
Baud Rate Generator ............................................... 153
BSR Operatio n ..... ............... .......... ............... .......... .... 57
External Brown-out Protection Circuit (Case1)........... 31
External Power-on Reset Circuit ................................ 24
External Program Mem ory Connec tion . ..................... 45
I2C Master Mode ...................................................... 151
I2C Module................................................................ 143
Indirect Addressing..................................................... 54
On-chip Reset Circuit ................................................. 23
PORTD....................................................................... 80
PORTE........................................................... 82, 90, 91
Program Counter Operation....................................... 56
PWM......................................................................... 107
RA0 and RA1. ............................................................. 72
RA2............................................................................. 72
RA3............................................................................. 73
RA4 and RA5. ............................................................. 73
RB3:RB2 Por t Pins.............. .............. ............... .......... 75
RB7:RB4 and RB1:RB0 Port Pins.............................. 74
RC7:RC0 Port Pins................ .............. ............... ........ 78
SSP (I2C Mode). ....................................................... 143
SSP (SPI Mode) .................................... ................... 137
SSP Module (I2C Master Mode)............................... 133
SSP Module (I2C Slave Mode)................................. 133
SSP Module (SPI Mode ) . ......................................... 133
Timer3 with One Capture and One Period Register. 110
TMR1 and TMR2 in 16-bit Timer/Counter Mode...... 105
TMR1 and TMR2 in Two 8-bit Timer/Counter Mode 104
TMR3 with Two Capture Registers........................... 112
Using CALL, GOTO.................................................... 56
WDT ......................................................................... 193
BODEN............................................................................... 31
Borrow ................................................................................ 11
BRG.......................................................................... 120, 153
Brown-o u t Protect i o n...... ............... .............. ............... ........ 31
Brown-o u t Reset (BOR).... ........... .......... ............... .............. 31
BSF................................................................................... 205
BSR .................................................................................... 57
BSR Operatio n ............... ............... .......... ............... .......... .. 57
BTFSC.............................................................................. 205
BTFSS.............................................................................. 206
BTG .................................................................................. 206
Buffe r Full b i t, BF................ ............... ......................... ...... 144
Buffe r Full Status bi t, BF................ .............. ............... ...... 134
Bus Arbitration...... .............. ................... ............... ............ 170
Bus Collision
Section...................................................................... 170
PIC17C7XX
DS30289B-page 290 2000 Microchip Technology Inc.
Bus Collision During a RESTART Condition.......... ...... .....173
Bus Collision During a START Condition........... ............. ..171
Bus Collision During a STOP Condition..................... .......174
Bus Collision Interrupt Enable, BCLIE ......... ...... ...... ....... ....36
Bus Collision Interrupt Flag bit, BCLIF....... ...... ...... ...... .......38
C
C....................................................................................11, 51
CA1/PR3...........................................................................102
CA1ED0............................................................................101
CA1ED1............................................................................101
CA1IE..................................................................................35
CA1IF..................................................................................37
CA1OVF............................................................................102
CA2ED0............................................................................101
CA2ED1............................................................................101
CA2H.............................................................................28, 49
CA2IE..........................................................................35, 111
CA2IF..........................................................................37, 111
CA2L.............................................................................28, 49
CA2OVF............................................................................102
CA3H...................................................................................50
CA3IE..................................................................................36
CA3IF..................................................................................38
CA3L...................................................................................50
CA4H...................................................................................50
CA4IE..................................................................................36
CA4IF..................................................................................38
Calculating Baud Rate Error .............................................120
CALL...........................................................................54, 207
Capacitor Selection
Ceramic Resonators ............... .. .. .... ..... .. .... .. .. .. .... ..... ..18
Crystal Oscillator.........................................................18
Capture .....................................................................101, 110
Capture Sequence to Read Example................................113
Capture1
Mode.........................................................................101
Overflow............................................................102, 103
Capture1 In terrupt..................... .............. ............... .............37
Capture2
Mode.........................................................................101
Overflow............................................................102, 103
Capture2 In terrupt..................... .............. ............... .............37
Capture3 In terrupt Enable , CA3 IE........ ............... ...............36
Capture3 In terrupt Flag bit, CA3IF........ ........... .......... .........38
Capture4 In terrupt Enable , CA4 IE........ ............... ...............36
Capture4 In terrupt Flag bit, CA4IF........ ........... .......... .........38
Carry (C ) .......... .............. ............... ............... .............. .........11
Ceramic Resonators ....................... .. .. .. ....... .. .. .... .. .. .... ..... ..17
Circular Buffer.....................................................................54
CKE...................................................................................134
CKP...................................................................................135
Clearing th e Pr esc a le r...... ........... .......... ............... ........... ..193
Clock Polarity Select bit, CKP...........................................135
Clock/Instruction Cycle (Figure)..........................................21
Clocking Scheme/Instruction Cycle.....................................21
CLRF.................................................................................207
CLRWDT...........................................................................208
Code Examples
Indirect Addressing .....................................................55
Loading the SSPBUF register...................................138
Savin g Statu s and WREG in RAM......... .............. .......42
Table Read .................................................................64
Table Write..................................................................62
Code Protection ................................................................195
COMF................................................................................208
Configuration
Bits............................................................................ 192
Locations .................................................................. 192
Oscillator............................................................. 17, 192
Word......................................................................... 191
CPFSEQ........................................................................... 209
CPFSGT........................................................................... 209
CPFSLT............................................................................ 210
CPUSTA..................................................................... 52, 194
Crystal Operation, Overtone Crystals................................. 18
Crystal or Ceramic Resonator Operation ............................ 18
Crystal Oscillator................................................................. 17
D
D/A.................................................................................... 134
Data Memory
GPR...................................................................... 43, 46
Indirect Addressing..................................................... 54
Organization ............................................................... 46
SFR ............................................................................ 43
Data Memor y Ban k in g.... .......... ............... .......... ............... .. 46
Data/Address bit, D/A ....................................................... 134
DAW ................................................................................. 210
DC................................................................................. 11, 51
DDRB ...................................................................... 27, 48, 74
DDRC ..................................................................... 28, 48, 78
DDRD ..................................................................... 28, 48, 80
DDRE ...................................................................... 28, 48, 82
DDRF.................................................................................. 49
DDRG................................................................................. 49
DECF................................................................................ 211
DECFSNZ......................................................................... 212
DECFSZ ........................................................................... 211
Delay From External Clock Edge........................................ 98
Digit Borrow........................................................................ 11
Digit Carry (DC).................................................................. 11
Duty Cycle .................... .............. ............... .......... ............. 107
E
Electrical Characteristics
PIC17C752/756
Abso l u te M a ximum R a t in g s........ .. ...... .. ..... .. .. ... 239
Capture Timing..... .......... ............... ........... ........ 253
CLKOUT and I/O Timing .................................. 250
DC Characteristics............................................ 242
External Clock Timing....................................... 249
Memory Interface Read Timing ........................ 266
Memory Interface Write Timing ........................ 265
Paramete r Measurem e n t In formation........... .... 248
Reset, Watchdog Timer, Oscillator Start-up
Timer and Power-up Timer Timing................... 251
Timer0 Clock Timing......................................... 252
Timer1, Timer2 and Timer3 Clock Timing ........ 252
Timing Parameter Symbology .......................... 247
USART Module Synchronous Receive Timing. 261
USART Module Synchronous Transmission
Timing............................................................... 260
EPROM Memory Access Time Order Suffix....................... 45
Errata.................................................................................... 5
Extended Microcontroller. ................................................... 43
Extended Microcontroller Mode.......................................... 45
External Memory Interface.................................................. 45
External Program Memory Waveforms ............................... 45
2000 Microchip Technology Inc. DS30289B-page 291
PIC17C7XX
F
Family of Devices
PIC17C75X...................................................................8
FERR ................................................................................125
Flowcharts
Acknowledge.............................................................166
Master Receiver........................................................163
Master Transmit........................................................160
RESTART Con dition.................. .......... ............... ......157
Start Condition................ .. .... ......... .... .... .... ......... .... ..155
STOP Condition........................................................168
FOSC0..............................................................................191
FOSC1..............................................................................191
FS0 .....................................................................................51
FS1 .....................................................................................51
FS2 .....................................................................................51
FS3 .....................................................................................51
FSR0...................................................................................54
FSR1...................................................................................54
G
GCE..................................................................................136
General Call Address Sequence.......................................149
General Call Address Support ..........................................149
General Call Enable bit, GCE...........................................136
General Format for Instructions........................................198
General Purpose RAM................ .... ....... .... .. .... .... ....... .... ....43
General Purpose RAM Bank...............................................57
General Purpose Register (GPR) .......................................46
GLINTD.........................................................39, 52, 111, 194
Global Interrupt Disable bit, GLINTD..................................39
GOTO ...............................................................................212
GPR (General Purpose Register) .......................................46
GPR Banks.........................................................................57
Graphs
RC Oscillator Frequency vs. VDD (CEXT = 100 pF)...268
RC Oscillator Frequency vs. VDD (CEXT = 22 pF).....268
RC Oscillator Frequency vs. VDD (CEXT = 300 pF)...269
Transconductance of LF Oscillator vs.VDD...............270
Transconductance of XT Oscillator vs. VDD..............270
Typical RC Osci lla tor vs. Temper at ure................... ..267
H
Hardware Multiplie r......... .............. ........... .......... ........... ......67
I
I/O Por ts
Bi-directional...............................................................93
I/O Ports................................ .......................... ............71
Program ming Co n siderat io n s .......... .......... ............... ..93
Read-Modify-Write Instructions. ..................................93
Succes sive Opera tio n s....... ............... ............... ..........94
I2C.....................................................................................143
I2C Input ...........................................................................279
I2C Master Mode Receiver Flow Chart .............................163
I2C Master Mode Reception..............................................162
I2C Master Mode RESTART Condition.............................156
I2C Mode Selection...........................................................143
I2C Module
Acknowledge Flow Chart..........................................166
Acknowledge Sequence Timing................................165
Addressing................................................................145
Baud Rate Generator................................................153
Block Diag ram......... .......... ............... ............... ..........151
BRG Block Diagram..................................................153
BRG Reset due to SDA Collision..............................172
BRG Timing ..............................................................153
Bus Arbitration........ .............. .......................... ..........170
Bus Collision................. ........... .......... ........... .......... .. 170
Acknowledge.................................................... 170
RESTART Condition.. ...... .......... ........... .......... .. 173
RESTART Condition Timin g (Case1)... .......... .. 173
RESTART Condition Timin g (Case2)... .......... .. 173
START Condition. ............................................. 171
START Condition Timing.......................... 171, 172
STOP Condition................................................ 174
STOP Condition Timing (Case1)...................... 174
STOP Condition Timing (Case2)...................... 174
Transmit Timing ................................................ 170
Bus Collision Timing....... ........... ...... ..................... .... 170
Clock Arbitration....................................................... 169
Clock Arbitration Timing (Master Transmit).............. 169
Conditions to not give ACK Pulse............................. 144
General Call Address Support.................................. 149
Master Mode............................................................. 151
Master Mode 7-bit Reception timing................. .... .. .. 164
Master Mode Operation. ........................................... 152
Master Mode Start Condition.................................... 154
Master Mode Transmission ...................................... 159
Master Mode Transmit Sequence ............................ 152
Master Transmit Flowchart....................................... 160
Multi-Master Communication.................................... 170
Multi-master Mode.................................................... 152
Operation.................................................................. 143
Repeat Start Condition timing............................. .... .. 156
RESTART Condition Flowc h a rt... ............... .......... .... 157
Slave Mode................... .......................... .............. .... 144
Slave Reception ....... ............... .......... ..................... .. 145
Slave Tra n smissio n.... ............... ............... ................ 146
SSPBUF................................................................... 144
Start Condition Flowchart............................. .... .... .... 155
Stop Condition Flowchart ................ .. ......... .. .... .... .. .. 168
Stop Condition Receive or Transmit timing.............. 167
Stop Condition timing ........................................... .... 167
Waveforms for 7-bit Reception................................. 146
Waveforms for 7-bit Transmission............................ 146
I2C Module Address Register, SSPADD .......................... 144
I2C Slave Mode ................................................................ 144
INCF ................................................................................. 213
INCFSNZ.......................................................................... 214
INCFSZ............................................................................. 213
In-Circuit Serial Programming........................................... 196
INDF0 ................................................................................. 54
INDF1 ................................................................................. 54
Indirect Addressing
Indirect Addressing..................................................... 54
Operation.................................................................... 55
Registers .................................................................... 54
Initializing PORTB............................................................... 75
Initializing PORTC.............................................................. 78
Initializing PORTD.............................................................. 80
Initializing PORTE................................................... 82, 84, 86
INSTA................................................................................. 48
Instruction Flow/Pipelining.................................................. 21
Instruction Set
ADDLW..................................................................... 202
ADDWF .................................................................... 202
ADDWFC.................................................................. 203
ANDLW..................................................................... 203
ANDWF .................................................................... 204
BCF .......................................................................... 204
BSF........................................................................... 205
BTFSC...................................................................... 205
BTFSS...................................................................... 206
PIC17C7XX
DS30289B-page 292 2000 Microchip Technology Inc.
BTG...........................................................................206
CALL.........................................................................207
CLRF.........................................................................207
CLRWDT...................................................................208
COMF .......................................................................208
CPFSEQ ...................................................................209
CPFSGT ...................................................................209
CPFSLT ....................................................................210
DAW..........................................................................210
DECF ........................................................................211
DECFSNZ.................................................................212
DECFSZ....................................................................211
GOTO .......................................................................212
INCF..........................................................................213
INCFSNZ ..................................................................214
INCFSZ.....................................................................213
IORLW ......................................................................214
IORWF......................................................................215
LCALL.......................................................................215
MOVFP .....................................................................216
MOVLB .....................................................................216
MOVLR.....................................................................217
MOVLW ....................................................................217
MOVPF .....................................................................218
MOVWF ....................................................................218
MULLW.....................................................................219
MULWF.....................................................................219
NEGW.......................................................................220
NOP..........................................................................220
RETFIE .....................................................................221
RETLW .....................................................................221
RETURN...................................................................222
RLCF.........................................................................222
RLNCF......................................................................223
RRCF........................................................................223
RRNCF .....................................................................224
SETF.........................................................................224
SLEEP ......................................................................225
SUBLW .....................................................................225
SUBWF.....................................................................226
SUBWFB...................................................................226
SWAPF .....................................................................227
TABLRD............................................................227, 228
TABLWT ...........................................................228, 229
TLRD.........................................................................229
TLWT ........................................................................230
TSTFSZ ....................................................................230
XORLW.....................................................................231
XORWF.....................................................................231
Instruction Set Summary...................................................197
Instructions
TABLRD......................................................................64
TLRD...........................................................................64
INT Pin................................................................................40
INTE....................................................................................34
INTEDG.........................................................................53, 97
Inter-Integrated Circuit (I2C)..............................................133
Internal Sampling Switch (Rss) Impedence ......................183
Interrupt on Change Feature................... ......... .. .... .. .... .......74
Inter rupt St a tu s Register (INTSTA)............ .........................34
Interrupts
A/D Interrupt.................. .............. ............... ............... ..38
Bus Collision Interrupt............. ...... ........... ...... ...... .......38
Capture1 In terrupt............. .............. ............... .............37
Capture2 In terrupt............. .............. ............... .............37
Capture3 In terrupt............. .............. ............... .............38
Capture4 In te rrupt .... .............. ............... ............... ...... 38
Context Saving........................................................... 39
Flag bits
TMR1IE .............................................................. 33
TMR1IF............................................................... 33
TMR2IE .............................................................. 33
TMR2IF............................................................... 33
TMR3IE .............................................................. 33
TMR3IF............................................................... 33
Global Interrupt Disable.............................................. 39
Interrupts .................................................................... 33
Logic........................................................................... 33
Operation.................................................................... 39
Peripheral Interrupt Enable................................... .... .. 35
Peripheral Interrupt Request.................. .... .. ......... .... .. 37
PIE2 Register .............................................................36
PIR1 Register.............................................................37
PIR2 Register.............................................................38
PORTB Interrupt on Change ...................................... 37
PWM......................................................................... 108
RA0/INT...................................................................... 39
Statu s Reg i ster..... .............. ............... ............... ..........34
Synchronous Serial Port Interrupt............................... 38
T0CKI Int e rr u p t................. ............... ............... ............ 39
Timing......................................................................... 40
TMR1 Overflow Interrupt............................................ 37
TMR2 Overflow Interrupt............................................ 37
TMR3 Overflow Interrupt............................................ 37
USART1 Receive In terrupt........ .............. ........... ........ 37
USART1 Tran sm i t Interrupt................... ............... ......37
USART2 Receive In terrupt........ .............. ........... ........ 38
Vectors
Peripheral Interrupt............................................. 39
Program Memory Locations ............................... 43
RA0/INT Interrupt ............................................... 39
T0CKI Int e rr u p t....... ............... .............. ........... .... 39
Vectors/Priorities......................................................... 39
Wake-up from SLEEP............................................... 194
INTF.................................................................................... 34
INTST A Register................... ............... .............. ............... .. 34
IORLW.............................................................................. 214
IORWF.............................................................................. 215
IRBPU VS. VDD ................................................................... 274
K
KeeLoq Evaluation and Programming Tools .................... 236
L
LCALL......................................................................... 54, 215
M
MapsRegi ster File Map...... .......... ............... .......... ........... .... 47
Memory
External Interface ....................................................... 45
External Memory Waveforms..................................... 45
Memory Map (Different Modes).................................. 44
Mode Memor y Ac cess........................... ............... ...... 44
Organization ............................................................... 43
Program Memory........................................................ 43
Program Memory Map................................................ 43
Microcontroller.................................................................... 43
Microprocessor................................................................... 43
Minimizing Current Consumption...................................... 195
MOVFP....................................................................... 46, 216
Moving Data Between Data and Program Memories ......... 46
MOVLB....................................................................... 46, 216
MOVLR............................................................................. 217
MOVLW............................................................................ 217
2000 Microchip Technology Inc. DS30289B-page 293
PIC17C7XX
MOVPF.......................................................................46, 218
MOVWF ............................................................................218
MPLAB Integrated Development Environment Software..233
MULLW.............................................................................219
Multi-Master Communication............................................170
Multi-Master Mode............................................................152
Multiply Examples
16 x 16 Routin e................. ......................... ............... ..68
16 x 16 Signed Routine............................ .. .. ....... .. .. ....69
8 x 8 Routine...... ........... ............... .............. ........... ......67
8 x 8 Signed Routine.......................... .. .. .. .... ..... .. .... .. ..67
MULWF.............................................................................219
N
NEGW...............................................................................220
NOP..................................................................................220
O
Opcode Field Descriptions................................................197
Opcodes..............................................................................56
Oscillator
Configuration.......................................................17, 192
Crystal.........................................................................17
External Clock.............................................................19
External Crystal Circuit ...............................................19
External Parallel Resonant Crystal Circuit..................19
External Series Resonant Crystal Circuit....................19
RC...............................................................................20
RC Frequencies........................................................269
Oscillator Start-up Time (Figure)................ ...... ....... ...... ......24
Oscillato r Start-up Timer (OST).... ....... ...... ...... ....... ...... ......24
OST.....................................................................................24
OV.................................................................................11, 51
Overflow (OV)................. ......................... ................... ........11
P
P........................................................................................134
Packagi n g In fo rmation.................... ............... ............... ....281
PC (Program Counter)........................................................56
PCFG0 bit......................... .............. ............... ............... ....180
PCFG1 bit......................... .............. ............... ............... ....180
PCFG2 bit......................... .............. ............... ............... ....180
PCH ....................................................................................56
PCL.............................................................................56, 198
PCLATH..............................................................................56
PD...............................................................................52, 194
PEIE............................................................................34, 111
PEIF....................................................................................34
Peripheral Bank ..................................................................57
Peripheral Banks.................................................................57
Peripheral Interrupt Enable.................................................35
Peripheral Interrupt Request (PIR1) ...................................37
Peripheral Register Banks ..................................................46
PICDEM-1 Low-Cost PICmicro Demo Board ....................235
PICDEM-2 Low-Cost PIC16CXX Demo Board.................235
PICDEM-3 Low-Cost PIC16CXX X Demo Boar d...............236
PICSTART Plus Entry Level Development System.........235
PIE ....................................................................126, 130, 132
PIE1..............................................................................28, 48
PIE2................. ............... .............. ..........................28, 36 , 49
PIR....................................................................126, 130, 132
PIR1..............................................................................28, 48
PIR2..............................................................................28, 49
PM0...........................................................................191, 195
PM1...........................................................................191, 195
POP ..............................................................................39, 54
POR....................................................................................24
PORTA................... ............... ............... .............. .....27, 48, 72
PORTB................................................................... 27, 48, 74
PORTB Interrupt on Change .............................................. 37
PORTC................................................................... 28, 48, 78
PORTD................................................................... 28, 48, 80
PORTE................................................................... 28, 48, 82
PORTF ............................................................................... 49
PORTG............................................................................... 49
Power-down Mode............................................................ 194
Power-on Reset (POR)....................................................... 24
Power-up Timer (PWRT).................................................... 24
PR1 ............................................................................... 28, 49
PR2 ............................................................................... 28, 49
PR3/CA1H.......................................................................... 28
PR3/CA1L........................................................................... 28
PR3H/CA1H........................................................................ 49
PR3L/CA1L......................................................................... 49
Prescaler Assignments....................................................... 99
PRO MA TE II Universa l Programme r.................. .......... .. 235
PRODH......................................................................... 30, 50
PRODL......................................................................... 30, 50
Program Counter (PC)........................................................ 56
Program Mem ory
External Access Waveforms....................................... 45
External Connection Diagram ..................................... 45
Map............................................................................. 43
Modes
Extended Microcontroller.................................... 43
Microcontroller.................................................... 43
Microprocessor................................................... 43
Protected Microcontroller.................................... 43
Operation.................................................................... 43
Organization............................................................... 43
Protected Microcontroller.................................................... 43
PS0............................................................................... 53, 97
PS1............................................................................... 53, 97
PS2............................................................................... 53, 97
PS3............................................................................... 53, 97
PUSH ............................................................................ 39, 54
PW1DCH...................................................................... 28, 49
PW1DCL ....................................................................... 28, 49
PW2DCH...................................................................... 28, 49
PW2DCL ....................................................................... 28, 49
PW3DCH...................................................................... 30, 50
PW3DCL ....................................................................... 30, 50
PWM......................................................................... 101, 107
Duty Cycle.............. ............... .......... ............... .......... 108
External Clock Source.............................................. 109
Frequency vs. Resolution......................................... 108
Interrupts .................................................................. 108
Max Resolution/Frequency for External Clock Input 109
Output....................................................................... 107
Periods ..................................................................... 108
PWM1....................................................................... 102, 103
PWM1ON.................................................................. 102, 107
PWM2....................................................................... 102, 103
PWM2ON.................................................................. 102, 107
PWM3ON.......................................................................... 103
PWRT................................................................................. 24
PIC17C7XX
DS30289B-page 294 2000 Microchip Technology Inc.
R
R/W...................................................................................134
R/W bit..............................................................................145
R/W bit..............................................................................145
RA1/T0CKI p i n... .............. ........... ............... .............. ...........97
RBIE....................................................................................35
RBIF....................................................................................37
RBPU..................................................................................74
RC Oscillator.......................................................................20
RC Oscillator Frequencies................................................269
RC1IE..................................................................................35
RC1IF..................................................................................37
RC2IE..................................................................................36
RC2IF..................................................................................38
RCE, Receive Enable bit, RCE.........................................136
RCREG.....................................................125, 126, 130, 131
RCREG1.......................................................................27, 48
RCREG2.......................................................................27, 49
RCSTA..............................................................126, 130, 132
RCSTA1........................................................................27, 48
RCSTA2........................................................................27, 49
Read/Write bit, R/W ..........................................................134
Reading 16-bit Value................... .... .. .. .... ..... .... .. .. .... .. .. .......99
Receive Over flo w In d icator bi t, SSPOV................. ...........135
Receive Status and Control Register.... ........... .......... .......117
Register File Map............. ........... ............... .............. ...........47
Registers
ADCON0.....................................................................49
ADCON1.....................................................................49
ADRESH.....................................................................49
ADRESL......................................................................49
ALUSTA............. ......................... ............... .....39, 48 , 51
BRG ..........................................................................120
BSR .......................................................................39, 48
CA2H ..........................................................................49
CA2L...........................................................................49
CA3H ..........................................................................50
CA3L...........................................................................50
CA4H ..........................................................................50
CA4L...........................................................................50
CPUSTA ...............................................................48, 52
DDRB..........................................................................48
DDRC..........................................................................48
DDRD..........................................................................48
DDRE..........................................................................48
DDRF..........................................................................49
DDRG .........................................................................49
FSR0.....................................................................48, 54
FSR1.....................................................................48, 54
INDF0....................................................................48, 54
INDF1....................................................................48, 54
INSTA .........................................................................48
INTSTA .......................................................................34
PCL.............................................................................48
PCLATH......................................................................48
PIE1......................................................................35, 48
PIE2......................................................................36, 49
PIR1......................................................................37, 48
PIR2......................................................................38, 49
PORTA........................................................................48
PORTB........................................................................48
PORTC .......................................................................48
PORTD .......................................................................48
PORTE........................................................................48
PORTF........................................................................49
PORTG .......................................................................49
PR1............................................................................. 49
PR2............................................................................. 49
PR3H/CA1H................................................................ 49
PR3L/CA1L................................................................. 49
PRODH....................................................................... 50
PRODL ....................................................................... 50
PW1DCH.................................................................... 49
PW1DCL..................................................................... 49
PW2/DCL.................................................................... 49
PW2DCH.................................................................... 49
PW3DCH.................................................................... 50
PW3DCL..................................................................... 50
RCREG1..................................................................... 48
RCREG2..................................................................... 49
RCSTA1 ..................................................................... 48
RCSTA2 ..................................................................... 49
SPBRG1..................................................................... 48
SPBRG2..................................................................... 49
SSPADD..................................................................... 50
SSPBUF ..................................................................... 50
SSPCON1 .................................................................. 50
SSPCON2 .................................................................. 50
SSPSTAT........................................................... 50, 134
T0STA ............................................................ 48, 53, 97
TBLPTRH ................................................................... 48
TBLPTRL.................................................................... 48
TCON1 ............................................................... 49, 101
TCON2 ............................................................... 49, 102
TCON3 ............................................................... 50, 103
TMR0H ....................................................................... 48
TMR1.......................................................................... 49
TMR2.......................................................................... 49
TMR3H ....................................................................... 49
TMR3L........................................................................ 49
TXREG1 ..................................................................... 48
TXREG2 ..................................................................... 49
TXSTA1...................................................................... 48
TXSTA2...................................................................... 49
WREG .............. .................................................... 39, 48
Regsters
TMR0L........................................................................ 48
Reset
Section........................................................................ 23
Status Bits and Their Significance.............................. 25
Time-Ou t in Va rious Situ a tions.................... ............... 25
Time-Out Sequence.................................................... 25
Restart Condition Enabled bit, RSE.................................. 136
RETFIE............................................................................. 221
RETLW............................................................................. 221
RETURN........................................................................... 222
RLCF ................................................................................ 222
RLNCF.............................................................................. 223
RRCF................................................................................ 223
RRNCF............................................................................. 224
RSE .................................................................................. 136
RX Pin Sampling Scheme ................................................ 125
S
S ....................................................................................... 134
SAE................................................................................... 136
Sampling........................................................................... 125
Savi ng STATUS and WREG in RAM..... .............. ............... 42
SCK .................................................................................. 137
SCL................................................................................... 144
SDA .................................................................................. 144
SDI.................................................................................... 137
SDO.................................................................................. 137
2000 Microchip Technology Inc. DS30289B-page 295
PIC17C7XX
SEEVAL Evaluation and Programm i ng System................236
Serial Clock, SCK .............................................................137
Serial Clock, SCL..............................................................144
Serial Data Address, SDA .................................................144
Serial Data In, SDI ............................................................137
Serial Data Out, SDO........................................................137
SETF.................................................................................224
SFR...................................................................................198
SFR (Special Function Registers) .......................................43
SFR As Source/Destination..............................................198
Signed Math........................................................................11
Slave Select Synchronization ...........................................140
Slave Select, SS ...............................................................137
SLEEP ......................................................................194, 225
SLEEP Mode, All Peripherals Disabled ........................ ....273
SLEEP Mode, BOR Enabled ............................................273
SMP..................................................................................134
Softwa re Simulato r ( MP L AB SIM).................. ............... ....234
SPBRG .............................................................126, 130, 132
SPBRG1 .......................................................................27, 48
SPBRG2 .......................................................................27, 49
SPE...................................................................................136
Speci a l Features of the CPU ........ ........... ............... ..........191
Special Function Registers.........................................43, 198
Summary.....................................................................48
Spec ia l Fun c ti o n R e g i s t e r s, File M a p ... .. ...... ...... ..... .. ...... ...47
SPI Master Mode.............................................................139
Serial Clock...............................................................137
Serial Data In............................................................137
Serial Data Out .........................................................137
Serial Peripheral Interface (SPI)...............................133
Slave Select..............................................................137
SPI clock...................................................................139
SPI Mode..................................................................137
SPI Clock Edge Select, CKE . ...........................................134
SPI Da ta Input Sample Ph a se Se l e ct, SMP ..... .. .. ............134
SPI Master/Slave Connection...........................................138
SPI Module
Master/Slave Connection.................................. .... .. ..138
Slave Mode...............................................................140
Slave Select Synchronization...................................140
Slave Synch Timing..................................................140
SS .....................................................................................137
SSP...................................................................................133
Block Diagram (SPI Mode) ................................... .. ..137
SPI Mode..................................................................137
SSPADD...........................................................144, 145
SSPBUF............................................................139, 144
SSPCON1.................................................................135
SSPCON2.................................................................136
SSPSR..............................................................139, 144
SSPSTAT..........................................................134, 144
SSP I2C
SSP I2C Operation................ ....... .............. ........... ....143
SSP Module
SPI Master Mode......................................................139
SPI Master/Slave Connection...................................138
SPI Slave Mode........................................................140
SSPCON1 Register ..................................................143
SSP Overflow Detect bit, SSPOV.....................................144
SSPADD.............................................................................50
SSPBUF ......................................................................50, 144
SSPCON1................................... ........... .... .... .... .50, 135, 143
SSPCON2...................................................................50, 136
SSPEN..............................................................................135
SSPIE................................................................................. 36
SSPIF......................................................................... 38, 145
SSPM3:SSPM0 ................................................................ 135
SSPOV ............................... ............... ...... ......... 135, 144, 162
SSPSTAT ........................................................... 50, 134, 144
ST Input............................................................................ 278
Stack
Operation.................................................................... 54
Pointer........................................................................ 54
Stack........................................................................... 43
START bit (S) ................................................................... 134
START Condition Enabled bit, SAE.................................. 136
STKAV.......................................................................... 52, 54
STOP bit (P)..................................................................... 134
STOP Condition Enable bit............................................... 136
SUBLW............................................................................. 225
SUBWF............................................................................. 226
SUBWFB .......................................................................... 226
SWAPF............................................................................. 227
Synchronous Master Mode............................................... 127
Synchronous Master Reception........................................ 129
Synchronous Master Transmission .................................. 127
Synchronous Serial Port................................................... 133
Synchronous Serial Port Enable bit, SSPEN.................... 135
Synchronous Serial Port Interrupt....................................... 38
Synchronous Serial Port Interrupt Enable, SSPIE.............. 36
Synchronous Serial Port Mode Select bits,
SSPM3:SSPM0 ................................................................ 135
Synchronous Slave Mode................................................. 131
T
T0CKI ................................................................................. 39
T0CKI Pi n........ ............... ......................... ............... ............ 40
T0CKIE............................................................................... 34
T0CKIF ............................................................................... 34
T0CS ............................................................................ 53, 97
T0IE.................................................................................... 34
T0IF .................................................................................... 34
T0SE ............................................................................. 53, 97
T0STA ................................................................................ 53
T16 ................................................................................... 101
Table Latch..................... ............... .............. ............... ........ 55
Table Pointer................ ............... .............. ......................... 55
Table Read
Example...................................................................... 64
Table Reads Section ......................... .. ....... .... .. .... .. .... 64
TLRD.......................................................................... 64
Table Write
Code........................................................................... 62
Timing......................................................................... 62
To Exte rna l Memory..... ............... ............................. .. 62
TABLRD ................................................................... 227, 228
TABLWT................................................................... 228, 229
TAD ................................................................................... 185
TBLATH.............................................................................. 55
TBLATL .............................................................................. 55
TBLPTRH ........................................................................... 55
TBLPTRL............................................................................ 55
TCLK12 ............................................................................ 101
TCLK3 .............................................................................. 101
TCON1 ......................................................................... 28, 49
TCON2 ............................................................................... 49
TCON2,TCON3 .................................................................. 28
TCON3 ....................................................................... 50, 103
Time-Out Sequence.......................................................... .. 25
Timer Resources................................................................ 95
PIC17C7XX
DS30289B-page 296 2000 Microchip Technology Inc.
Timer0.................................................................................97
Timer1
16-bit Mode...............................................................105
Clock Source Select..................................................101
On bit ............. .... .. .. .. .. ..... .. .. .. .... .. .. .. ..... .. .. .. .. .... .102, 103
Section..............................................................101, 104
Timer2
16-bit Mode...............................................................105
Clock Source Select..................................................101
On bit ............. .... .. .. .. .. ..... .. .. .. .... .. .. .. ..... .. .. .. .. .... .102, 103
Section..............................................................101, 104
Timer3
Clock Source Select..................................................101
On bit ............. .... .. .. .. .. ..... .. .. .. .... .. .. .. ..... .. .. .. .. .... .102, 103
Section..............................................................101, 110
Timers
TCON3......................................................................103
Timing Diagrams
A/D Conversion...... ........... .............. ........... ...............264
Acknowledge Sequence Timing................................165
Asynchronous Master Transmission.........................123
Asynchronous Reception..........................................126
Back to Back Asynchronous Master Transmission...124
Baud Rate Generator with Clock Arbitration.............153
BRG Reset Due to SDA Collision.............................172
Bus Collision
START Condition Timing..................................171
Bus Collision During a RESTART Condition
(Case 1)....................................................................173
Bus Collision During a RESTART Condition
(Case 2)....................................................................173
Bus Collision During a START Condition
(SCL = 0).................. ........... ......................... .............172
Bus Collision During a
STOP Condition........................................................174
Bus Collision for Transmit and Acknowledge............170
External Parallel Resonant Crystal Oscillator Circuit..19
External Program Memory Access .............................45
I2C Bus Data.............................................................259
I2C Bus START/STOP bits .......................................258
I2C Master Mode First START bit Timing . ................154
I2C Master Mode Reception Timing..........................164
I2C Master Mode Transmission Timing.....................161
Interrupt (INT, TMR0 Pins)..........................................40
Mas te r Mo de Tra n s mit Cl o c k Arbit ra tion... ...... .. ..... ...169
Oscillator Start-up Time..............................................24
PIC17C752/756 Capture Timing...............................253
PIC17C752/756 CLKOUT and I/O............................250
PIC17C752/756 External Clock................. .. .. .... .. .....249
PIC17C752/756 Memory Interface Read..................266
PIC17C752/756 Memory Interface Write..................265
PIC17C752/756 PWM Timing...................... .... .. .......253
PIC17C752/756 Reset, Watchdog Timer, Oscillator
Start-up Timer and Power-up Timer .........................251
PIC17C752/756 Timer0 Clock ............................. .....252
PIC17C752/756 Timer1, Timer2 and Timer3 Clock..252
PIC17C752/756 USART Module Sy nchronous
Receive.....................................................................261
PIC17C752/756 USART Module
Synchronous Transmission.......................................260
Repeat START Condition ......... .. .. ....... .. .. .. .. .. .. .. .. .....156
Slave Synchronization ..............................................140
STOP Condition Receive or Transmit.......................167
Synchronous Reception....................................... .....129
Synchronous Transmission.......................................128
Table Write..................................................................62
TMR0.................................................................... 98, 99
TMR0 Read/Write in Timer Mode............................. 100
TMR1, TMR2, and TMR3 in Timer Mode ............... ..115
Wake-U p fro m SLEEP...... ............... ................... ...... 194
TLRD ................................................................................ 229
TLWT................................................................................ 230
TMR0
16-bit Re a d...... ........... ............... .............. ............... .... 99
16-bit Write............. .............. ............... ............... ........ 99
Module........................................................................ 98
Operation.................................................................... 98
Overview..................................................................... 95
Prescaler Assignments............................................... 99
Read/Write Considerations......................................... 99
Read/Write in Timer Mode........................................ 100
Timing................................................................... 98, 99
TMR0 Status/Control Register (T0STA) ............................. 53
TMR1............................................................................ 28, 49
8-bit Mode................................................................. 104
External Clock Input.................................................. 104
Overview..................................................................... 95
Timer Mode............................................................... 115
Two 8-bit Timer/Counter Mode................................. 104
Using with PWM .......................................................107
TMR1 Overflow Interrupt .................................................... 37
TMR1CS........................................................................... 101
TMR1IE............................................................................... 35
TMR1IF............................................................................... 37
TMR1ON........................................................................... 102
TMR2............................................................................ 28, 49
8-bit Mode................................................................. 104
External Clock Input.................................................. 104
In Timer Mode........................................................... 115
Two 8-bit Timer/Counter Mode................................. 104
Using with PWM .......................................................107
TMR2 Overflow Interrupt .................................................... 37
TMR2CS........................................................................... 101
TMR2IE............................................................................... 35
TMR2IF............................................................................... 37
TMR2ON........................................................................... 102
TMR3
Example, Reading From................ .. .... .... .. ....... .... .... 114
Example , Writing To....... ........... .............. ............... .. 114
External Clock Input.................................................. 114
In Timer Mode........................................................... 115
One Capture and One Period Register Mode........... 110
Overview..................................................................... 95
Reading/Writing........................................................ 114
TMR3 Interrupt Flag bit, TMR3IF........................................ 37
TMR3CS. .................................................................. 101, 110
TMR3H ......................................................................... 28, 49
TMR3IE............................................................................... 35
TMR3IF....................................................................... 37, 110
TMR3L.......................................................................... 28, 49
TMR3ON . .................................................................. 102, 110
TO.............. .. .... .. .. .. .. .. ....... .. .. .. .. .. .... ..... .. .. .. .. .... .. . 52, 193, 194
Transmit Status and Control Register. .............................. 117
TSTFSZ............................................................................ 230
TTL INPUT........................................................................ 278
Turning o n 16- b i t Tim e r .............. ........... .............. ............. 105
TX1IE.................................................................................. 35
TX1IF.................................................................................. 37
TX2IE.................................................................................. 36
TX2IF.................................................................................. 38
TXREG ..................................................... 123, 127 , 131, 132
TXREG1 ....................................................................... 27, 48
2000 Microchip Technology Inc. DS30289B-page 297
PIC17C7XX
TXREG2 ........................................................................27, 49
TXSTA ..............................................................126, 130, 132
TXSTA Register
TXEN Bit.........................................34, 51, 97, 101, 117
TXSTA1 ........................................................................27, 48
TXSTA2 ........................................................................27, 49
U
UA.....................................................................................134
Update Address, UA ....................... ....... .. .... .. .. .... ....... .. .. ..134
Upward Compatibility............................................................7
USART
Asynchronous Master Transmission.........................123
Asynchronous Mode.................................................123
Asynchronous Receive.............................................125
Asynchronous Transmitter........................................123
Baud Rate Generator................................................120
Synchronous Master Mode.......................... .............127
Synchronous Master Reception................................129
Synchronous Master Transmission...........................127
Synchronous Slave Mode.........................................131
Synchronous Slave Transmit................................ ....131
Transmit Enable (TXEN Bit)............34, 51, 97, 101, 117
USART1 Receive Interru p t .................. .............. ........... ......37
USART1 Tran smit Interrupt .... ............... .............. ...............37
USART2 Recei ve In terrupt E nable, RC2IE.... ........... ..........36
USART2 Recei ve Interrupt Flag b it, RC2IF ......... ....... ........38
USART2 Recei ve In terrupt Flag b i t, TX2IF................. ........38
USART2 Transmit Interrupt Enable, TX2IE ........................36
V
VDD....................................................................................242
VOH VS. IOH .......................................................................276
VOL VS. IOL ........................................................................276
W
Wake-up from SLEEP....................................................... 194
Wake-up from SLEEP Through Interrupt.......................... 194
Watchdog Timer ............................ .... .. .... .. .. ......... .. .... .. .. .. 193
Waveform for General Call Address Seq uence................ 149
Waveforms
External Program Memory Access............................. 45
WCOL.............. .. ..... .... .. .. .. .. .. .. .. 135, 154, 159, 162, 165, 167
WCOL Statu s Fl a g........ ................... ............... .................. 154
WDT ................................................................................. 193
Clearing th e WDT.............. .......... ............... .......... .... 193
Normal Time r................ ........... ............... .......... ........ 193
Period....................................................................... 193
Program min g Co n side r a tions.............. ............... ...... 193
WDT PERIOD........... .............. ............... ......................... .. 275
WDTPS0........................................................................... 191
WDTPS1........................................................................... 191
Write Colli sion Detect bit, WCOL.................... .......... ........ 135
WWW, On-Line Support....................................................... 5
X
XORLW ............................................................................ 231
XORWF ............................................................................ 231
Z
Z ................................................................................... 11, 51
Zero (Z)............ ............... ......................... ............... ............ 11
PIC17C7XX
DS30289B-page 298 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 299
PIC17C7XX
Systems Information and Upgrade Hot Line
The Systems Information and Upgrade Line provides
system users a listing of the latest versions of all of
Microchips development systems software products.
Plus, this line provides information on how customers
can receive any currently available upgrade kits.The
Hot Line Numbers are:
1-800-755-2345 for U.S. and most of Canada, and
1-480-792-7302 for the rest of the world.
Trademarks: The Microchip name, logo, PIC, PICmicro,
PICMASTE R , PICSTART, PRO MATE, KEELOQ, SEEVAL,
MPLAB and The Embedded Control Solutions Company
are registered trademarks of Microchip Technology
Incorporated in the U.S.A. and other countries.
To tal Endurance, ICSP, In-Circuit Serial Programm ing,
FilterLab, MXDEV , microID, FlexROM, fuzzyLAB, MPASM,
MPLINK, MPLIB, PICDEM, ICEPIC and Migratable
Memory are trademarks and SQ TP is a service mark of
Microchip 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 Microchip
World Wide Web (WWW) site.
The web site is used b y Micr ochip as a me ans to mak e
files and information easily available to customers. To
view t he site, the user must have acce ss to the In ternet
and a web browser, such as Netscape or Microsoft
Explorer. Files are also available for FTP download
from our FTP site.
Connecting to the Microchip Internet Web Site
The Microchip web site is available by using your
fa vorite 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 of
services. Users may download files for the latest
Development Tools, Data Sheets, Application Notes,
Users Guides, Articles and Sample Programs. A vari-
ety of Microchip specific business information is also
available, including listings of Microchip sales offices,
distributors and factory representatives. Other data
available for consideration is:
Latest Microchip Press Releases
Technical Support Section with Frequently Asked
Questions
Design Tips
Device Errata
Job Postin gs
Microchip Consultant Program Member Listing
Links to other useful web sites related to
Microchip Products
Conferences for products, Development Systems,
technical information and more
Listing of seminars and events
001024
PIC17C7XX
DS30289B-page 300 2000 Microchip Technology Inc.
READER RESPONSE
It is ou r intentio n to provide you w i th the bes t docum ent ati on pos si ble to en su re s uc ce ss ful us e of y ou r Mic r oc hip pro d-
uct. If you w ish to p rovide your commen ts on org anizatio n, cl arity, subj ect matt er , and ways in which our doc umentatio n
can better serve you, please FAX your comments to the Technical Publications Manager at (480) 792-4150.
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 del etions from the data s heet could be made without affecting the ov eral l 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 Num ber:
Questions:
FAX: (______) _________ - _________
DS30289B
PIC17C7XX
2000 Microchip Technology Inc. DS30289B-page 301
PIC17C7XX
PRODUCT IDENTIFICATION SYSTEM
To order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office.
* JW Devices are UV er asable and can be programm ed to any device configurat ion. JW Devices meet the electr ical requirement of
each oscillator type.
Sales and Support
Data Sheets
Products 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 office
2. The Microchip Corporate Literature Center U.S. FAX: (480) 792-7277
3. 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 System
Register on our web site (www.microchip.com /cn) to receive the most current information on our products.
PART NO. X/XX XXX
PatternPackageTemperature
Range
Device
Device PIC17C756: Standard VDD range
PIC17C756T: (Tape and Reel)
PIC17LC75 6: Ex tend ed VDD range
Temperatu re R ang e - = 0°C to +70°C
I= -40
°C to +85°C
Package CL = Windowed LCC
PT = TQFP
L=PLCC
Pattern QTP, SQTP, ROM Code (factory specified) or
Special Requirements . Blamk for OTP and
Windowed devices.
Examples:
a) PIC17C756 16L Commercial Te mp.,
PLCC package, 16 MHz,
normal VDD limits
b) PIC17LC75608/PT Commercial Temp.,
TQFP package, 8MHz,
extended VDD limits
c) PIC17C75633I/PT Industrial Temp.,
TQFP package, 33 MHz,
normal VDD limits
PIC17C7XX
DS30289B-page 302 2000 Microchip Technology Inc.
NOTES:
2000 Microchip Technology Inc. DS30289B-page 303
PIC17C7XX
NOTES:
Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by
update s. It i s your respo nsibilit y to en sure t hat you r app licatio n mee ts with y our sp ecifica tions. N o re presen tation or warra nty is given and n o liability is
assumed by M icroc hip Techno logy In corpor ated with respe ct to the a ccuracy or u se of such in format ion, or infringem ent of paten ts or other intel lectual
property rights arising from such use or otherwise. Use of Microchips 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, except as maybe explicitly expressed herein, under any intellec-
tual p roperty rights. The M icrochip logo an d name are reg istered tradema rks of Microchip Technolo gy Inc. in the U.S.A . and other countries. All rights
reserved. All other trademarks mentioned herein are the property of their respective companies.
DS30289B-page 304 2000 Microchip Technology Inc.
All rights reserved. © 2000 Microchip Technology Incorporated. Printed in the USA. 11/00 Printed on recycled paper.
AMERICAS
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200 Fax: 480-792-7277
Technical Support: 480-792-7627
Web Address: http://ww w.microchip .com
Rocky Mountain
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7966 Fax: 480-792-7456
Atlanta
500 Sugar Mill Road, Suite 200B
Atlanta, GA 30350
Tel: 770-640- 003 4 Fax: 770- 640 -03 07
Boston
2 Lan Drive, Suite 120
Westford, MA 01886
Tel: 978-692- 383 8 Fax: 978- 692 -38 21
Chicago
333 Pierce Road, Suite 180
Itasca, IL 60143
Tel: 630-285-0071 Fax: 630-285-0075
Dallas
4570 Westgrove Drive, Suite 160
Addison, TX 7500 1
Tel: 972-818- 742 3 Fax: 972- 818 -29 24
Dayton
Tw o Pres tige Pla ce, Su ite 130
Miamisburg, OH 45342
Tel: 937-291- 165 4 Fax: 937- 291 -91 75
Detroit
Tri-Atria Office Building
32255 Northwestern Highway, Suite 190
Farmington Hills, MI 48334
Tel: 248-538-2250 Fax: 248-538-2260
Los A n ge les
18201 Von Karman, Suite 1090
Irvine, CA 92612
Tel: 949-263- 188 8 Fax: 949- 263 -13 38
New York
150 Motor Parkway, Suite 202
Hauppauge, NY 11788
Tel: 631-273- 530 5 Fax: 631- 273 -53 35
San Jose
Microchip Technology Inc.
2107 North First Street, Suite 590
San Jose, CA 95131
Tel: 408-436- 795 0 Fax: 408- 436 -79 55
Toronto
6285 Northam Drive, Suite 108
Mississ aug a, Ontario L4V 1X5, C ana da
Tel: 905-673-0699 Fax: 905-673-6509
ASIA/PACIFIC
China - Be ijing
Microchip Technology Beijing Office
Unit 915
New China Hong Kong Manhattan Bldg.
No. 6 Chaoyangmen Beidajie
Beijing, 100027, No. China
Tel: 86-10-85282100 Fax: 86-10-85282104
China - Shanghai
Microchip Technology Shanghai Office
Room 701, Bldg. B
Far East International Plaza
No. 317 Xian Xia Road
Shanghai, 200051
Tel: 86-21-6275-5700 Fax: 86-21-6275-5060
Hong Kong
Microchip Asia Pacific
RM 2101, Tower 2, Metroplaza
223 Hing Fong Road
Kwai Fong, N.T., Hong Kong
Tel: 852-2401-1200 Fax: 852-2401-3431
India
Microchip Technology Inc.
India Liaiso n Office
Divyasree Chambers
1 Floor, Wing A (A3/A4)
No. 11, OShaugnessey Road
Bangalore, 560 025, India
Tel: 91-80-2290061 Fax: 91-80-2290062
Japan
Microchip Technology Intl. Inc.
Benex S-1 6F
3-18-20, Shinyokohama
Kohoku -Ku, Yok ohama-shi
Kanaga wa, 222 -0 033 , Japan
Tel: 81-45-471- 6166 Fax: 81-45-471-6122
Korea
Microchip Technology Korea
168-1, Youngbo Bldg. 3 Floor
Samsung-Dong, Kangnam-Ku
Seoul, Korea
Tel: 82-2-554-7200 Fax: 82-2-558-5934
ASIA/PACIFIC (continued)
Singapore
Microchip Technology Singapore Pte Ltd.
200 Midd le Ro ad
#07-02 Prime Centre
Singapore, 188980
Tel: 65-334-8870 Fax: 65-334-8 850
Taiwan
Microc hip Technolo gy Taiwan
11F-3, No. 207
Tung Hua North Road
Taipei, 105, Taiwan
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPE
Denmark
Microchip Technology Denmark ApS
Regus Business Centre
Lautrup hoj 1-3
Ballerup DK-2750 Denmark
Tel: 45 4420 9895 Fax: 45 4420 9910
France
Arizona Microchip Technology SARL
Parc dActivite du Moulin de Massy
43 Rue du Saule Trap u
Batiment A - ler Et age
91300 Massy, France
Tel: 33-1-6 9-53-63-2 0 Fax: 33-1-69-30-90-79
Germany
Arizona Microchip Technology GmbH
Gustav-Heinemann Ring 125
D-81739 Munich, Germany
Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
Italy
Arizona Microchip Technology SRL
Centro Direzionale Colleoni
Palazzo Taurus 1 V. Le Colleoni 1
20041 Agrate Brianza
Milan, Italy
Tel: 39-039-65791-1 Fax: 39-039-6899883
United Kingdom
Arizona Microchip Technology Ltd.
505 Eskdale Road
Winnersh Triangle
Wokingham
Berksh ire, E ngla nd RG 41 5TU
Tel: 44 118 921 5869 Fax: 44-118 921-5820
10/01/00
WORLDWIDE SALES AND SERVICE
Microchip received QS-9000 quality system
certification for its worldwide headquarters,
design and wafer fabrication facil itie s in
Chandler and T empe, Arizona in July 1999. The
Companys 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, Microchips quality
system for the design and manufacture of
development systems is ISO 9001 certified.