15.0 Synchronous Serial Port (SSP) Module..................................................................................................................................... 123
17.0 Special Features of the CPU ..................................................................................................................................................... 177
18.0 Instruction Set Summary............................................................................................................................................................183
19.0 Development Support ................................................................................................................................................................ 219
21.0 PIC17C752/756 DC and AC Characteristics ............................................................................................................................. 249
22.0 Packaging Information ............................................................................................................................................................... 261
Appendix F:Status and Control Registers..................................................................................................................................... 273
Index .................................................................................................................................................................................................. 303
We constantly strive to improve the quality of all our products and documentation. We have spent an excep-
tional amount of time to ensure that these documents are correct. However, we realize that we may have
missed a few things. If you find any information that is missing or appears in error, please use the reader
response form in the back of this data sheet to inform us. We appreciate your assistance in making this a better document.
DS30264A-page 4
Preliminary
1997 Microchip Technology Inc.
PIC17C75X
1.0OVERVIEW
This data sheet covers the PIC17C75X group of the
PIC17CXXX family of microcontrollers. The following
devices are discussed in this data sheet:
• PIC17C752
• PIC17C756
The PIC17C75X devices are 68-Pin, EPROM-based
members of the versatile PIC17CXXX family of
low-cost, high-performance, CMOS, fully-static, 8-bit
microcontrollers.
All PIC16/17 microcontrollers employ an advanced
RISC architecture. The PIC17CXXX has enhanced
core features, 16-lev el deep stack, and multiple internal
and external interrupt sources. The separate instruction and data buses of the Harvard architecture allow a
16-bit wide instruction word with a separate 8-bit wide
data path. The two stage instruction pipeline allows all
instructions to execute in a single cycle, e xcept for program branches (which require two cycles). A total of 58
instructions (reduced instruction set) are available.
Additionally, a large register set gives some of the
architectural innovations used to achieve a very high
performance. For mathematical intensive applications
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.
PIC17C75X devices have up to 902 bytes of RAM and
50 I/O pins. In addition, the PIC17C75X adds several
peripheral features useful in many high performance
applications including:
• Four timer/counters
• Four capture inputs
• Three PWM outputs
• Two independant Universal Synchronous Asynchronous Receiver Transmitters (USARTs)
• An A/D converter (12 channel, 10-bit resolution)
• A Synchronous Serial Port
(SPI and I
These special features reduce external components,
thus reducing cost, enhancing system reliability and
reducing power consumption.
There are four oscillator options, of which the single pin
RC oscillator provides a low-cost solution, the LF oscillator is for low frequency crystals and minimizes power
consumption, XT is a standard crystal, and the EC is for
external clock input.
The SLEEP (power-down) mode offers additional
power saving. W ak e-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 oscillator provides protection against software malfunction.
2
C w/ Master mode)
There are four configuration options for the device
operational mode:
• Microprocessor
• Microcontroller
• Extended microcontroller
• Protected microcontroller
The microprocessor and extended microcontroller
modes allow up to 64K-words of external program
memory.
Brown-out Reset circuitry has also been added to the
device. This allo ws a device reset to occur if the device
V
DD
falls below the Brown-out voltage trip point
(BV
). The chip will remain in Brown-out Reset until
DD
V
rises above BV
DD
Table 1-1 lists the features of the PIC17CXXX devices.
A UV-erasable CERQUAD-packaged version (compat-
ible with PLCC) is ideal for code de velopment while the
cost-effective One-Time Programmable (OTP) version
is suitable for production in any volume.
The PIC17C75X 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
automotive, instrumentation, and telecom applications.
The EPROM technology makes customization of application programs (with unique security codes, combinations, model numbers, parameter storage, etc.) fast
and convenient. Small footprint package options
(including die sales) make the PIC17C75X ideal for
applications with space limitations that require high
performance.
An In-circuit Serial Programming (ISP) feature allows:
• Flexibility of programming the software code as
one of the last steps of the manufacturing process
High speed execution, powerful peripheral features,
flexible I/O, and low power consumption all at low cost
make the PIC17C75X ideal for a wide range of embedded control applications.
1.1Family and
The PIC17CXXX family of microcontrollers have architectural 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).
.
DD
Upward Compatibility
1.2Development 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 inf ormation see
Section 19.0.
SSP (SPI/I
Power-on Reset
Watchdog TimerYesYesYesYesYesYesYes
External InterruptsYesYesYesYesYesYesYes
Interrupt Sources11111111111818
Code ProtectYesYesYes Yes Yes YesYes
Brown-out Reset-----YesYes
In-circuit Serial Programming-----YesYes
I/O Pins33333333335050
I/O High Current
Capability
Package Types
Note 1: Pins RA2 and RA3 can sink up to 60 mA.
2
(EPROM)-16 K4K-8K8K16K
(ROM)2K--4K---
C w/Master mode)
Source25 mA25 mA25 mA25 mA25 mA25 mA25 mA
Sink
33 MHz33 MHz33 MHz33 MHz33 MHz33 MHz33 MHz
YesYesYesYesYesYesYes
-----YesYes
YesYesYesYesYesYesYes
(1)
25 mA
40-pin DIP
44-pin PLCC
44-pin MQFP
44-pin TQFP
44-pin PLCC
44-pin MQFP
44-pin TQFP
(1)
25 mA
40-pin DIP
(1)
25 mA
40-pin DIP
44-pin PLCC
44-pin MQFP
44-pin TQFP
(1)
25 mA
40-pin DIP
44-pin PLCC
44-pin MQFP
44-pin TQFP
(1)
25 mA
40-pin DIP
44-pin PLCC
44-pin MQFP
44-pin TQFP
(1)
25 mA
64-pin DIP
68-pin LCC
68-pin TQFP
25 mA
64-pin DIP
68-pin LCC
68-pin TQFP
(1)
DS30264A-page 6
Preliminary
1997 Microchip Technology Inc.
PIC17C75X
2.0DEVICE VARIETIES
Each device has a variety of frequency ranges and
packaging options. Depending on application and production requirements, the proper device option can be
selected using the information in the PIC17C75X Product Selection System section at the end of this data
sheet. When placing orders, please use the
“PIC17C75X Product Identification System” at the back
of this data sheet to specify the correct part number.
When discussing the functionality of the device, memory technology and voltage range does not matter.
There are three memory type options. These are specified in the middle characters of the part number.
1. C , as in PIC17 C 756. These devices have
EPROM type memory.
2. CR , as in PIC17 CR 756. These devices have
ROM type memory.
3. F , as in PIC17 F 756. These devices have Flash
type memory.
All these devices operate over the standard voltage
range. Devices are also offered which operate over an
extended voltage range (and reduced frequency
range). Table 2-1 shows all possible memory types and
voltage range designators for a particular device.
These designators are in bold typeface.
TABLE 2-1:DEVICE MEMORY
VARIETIES
Voltage Range
Memory T ype
EPROMPIC17
ROM
Flash
Note:Not all memory technologies are available
Standard Extended
C
XXXPIC17
PIC17
CR
XXXPIC17
PIC17FXXXPIC17LFXXX
for a particular device.
LC
LCR
XXX
XXX
2.1UV Erasable Devices
The UV erasable version, offered in CERQUAD package, is optimal for prototype dev elopment and pilot programs.
The UV erasable version can be erased and reprogrammed to any of the configuration modes.
Microchip's programming of the PIC17C75X. Third
party programmers also are available; ref er to the
Party Guide
for a list of sources.
Third
2.2One-Time-Programmable (OTP)
Devices
The availability of OTP devices is especially useful for
customers expecting frequent code changes and
updates.
The OTP devices, packaged in plastic packages, permit the user to program them once. In addition to the
program memory, the configuration bits must be programmed.
2.3Quick-Turnaround-Production (QTP)
Devices
Microchip offers a QTP Programming Service for factory production orders. This service is made available
for users who choose not to program a medium to high
quantity of units and whose code patterns have stabilized. The devices are identical to the OTP devices but
with all EPROM locations and configuration options
already programmed by the factory. Certain code and
prototype verification procedures apply before production shipments are available. Please contact your local
Microchip Technology sales office for more details.
2.4Serialized Quick-Turnaround
Production (SQTPSM) Devices
Microchip offers a unique programming service where
a few user-defined locations in each device are programmed with different serial numbers. The serial numbers may be random, pseudo-random or sequential.
Serial programming allows each device to have a
unique number which can serve as an entry-code,
password or ID number.
1997 Microchip Technology Inc.
Preliminary
DS30264A-page 7
PIC17C75X
2.5Read 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 contact your regional sales office.
Note:Presently, NO ROM versions of the
PIC17C75X devices are available.
2.6Flash Memory Devices
These devices are electrically erasable and, therefore,
can be offered in the low cost plastic package. Being
electrically erasable, these devices can be erased and
reprogrammed in-circuit. These devices are the same
for prototype development, pilot programs, as well as
production.
Note:Presently, NO Flash versions of the
PIC17C75X devices are available.
DS30264A-page 8Preliminary 1997 Microchip Technology Inc.
PIC17C75X
3.0ARCHITECTURAL OVERVIEW
The high performance of the PIC17CXXX can be attributed 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 separate memories. So , the de vice has a prog ram
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 opcodes are 16-bits wide, enabling single
word instructions. The full 16-bit wide program memory
bus fetches a 16-bit instruction in a single cycle. A
two-stage pipeline overlaps fetch and execution of
instructions. Consequently, all instructions execute in a
single cycle (121 ns @ 33 MHz), except for program
branches and two special instructions that transfer data
between program and data memory.
The PIC17CXXX can address up to 64K x 16 of program memory space.
The PIC17C752 integrates 8K x 16 of EPROM program memory on-chip.
The PIC17C756 integrates 16K x 16 EPROM program
memory.
Program execution can be internal only (microcontroller or protected microcontroller mode), external only
(microprocessor mode) or both (extended microcontroller mode). Extended microcontroller mode does not
allow code protection.
The PIC17CXXX can directly or indirectly address its
register files or data memory. All special function registers, including the Program Counter (PC) and Working
Register (WREG), are mapped in the 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 symmetrical nature and lack of ‘special optimal situations’ make programming with the PIC17CXXX simple yet efficient. In addition, the learning curve is
reduced significantly.
One of the PIC17CXXX family architectural enhancements from the PIC16CXX family allows two file registers to be used in some two operand instructions. This
allows data to be moved directly between two registers
without going through the WREG register. Thus
increasing performance and decreasing program
memory usage.
The PIC17CXXX devices contain an 8-bit ALU and
working register. The ALU is a general purpose arithmetic unit. It perf orms arithmetic and Boolean functions
between data in the working register and any register
file.
The ALU is 8-bits wide and capable of addition, subtraction, shift, and logical operations. Unless otherwise
mentioned, arithmetic operations are two's complement in nature.
The WREG register is an 8-bit working register used for
ALU operations.
All PIC17C75X devices have an 8 x 8 hardware multiplier. This m ultiplier generates a 16-bit result in a single
cycle.
Depending on the instruction executed, the ALU may
affect the values of the Carry (C), Digit Carry (DC), and
Zero (Z) bits in the ALUSTA register. The C and DC bits
operate as a borro
tively, in subtraction. See the SUBLW and SUBWF
instructions for examples.
Although the ALU does not perform signed arithmetic,
the Overflow bit (O V) can be used to implement signed
math. Signed arithmetic is comprised of a magnitude
and a sign bit. The overflow bit indicates if the magnitude overflows and causes the sign bit to change state.
That is if the result of the signed operation is greater
then 128 (7Fh) or less then -127 (FFh). Signed math
can have greater than 7-bit v alues (magnitude), if more
than one byte is used. The use of the overflow bit only
operates on bit6 (MSb of magnitude) and bit7 (sign bit)
of the value in the ALU. That is, the overflow 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 (15-, 24- or 31-bit), the
algorithm must ensure that the low order bytes ignore
the overflow status bit.
Care should be taken when adding and subtracting
signed numbers to ensure that the correct operation is
executed. Example 3-1 shows an item that must be
taken into account when doing signed arithmetic on an
ALU which operates as an unsigned machine.
w and digit borrow out bit, respec-
EXAMPLE 3-1:SIGNED MATH
Hex ValueSigned Value
Math
FFh
+ 01h
= ?
Signed math requires the result to be FEh
(-126). This would be accomplished by
subtracting one as opposed to adding one.
A simplified block diagram is shown in Figure 3-1. The
descriptions of the device pins are listed in Table 3-1.
DS30264A-page 10Preliminary 1997 Microchip Technology Inc.
PIC17C75X
TABLE 3-1:PINOUT DESCRIPTIONS
DIP
Name
OSC1/CLKIN475039ISTOscillator input in crystal/resonator or RC oscillator mode.
OSC2/CLKOUT485140O—Oscillator output. Connects to crystal or resonator in crystal
MCLR
/VPP15167I/PSTMaster clear (reset) input or Programming Voltage (VPP)
RA0/INT566048ISTRA0 can also be selected as an external interrupt
RA1/T0CKI414433ISTRA1 can also be selected as an external interrupt
RA2/SS
RA3/SDI/SDA434635I/OSTRA3 can also be used as the data input for the SPI or
RA4/RX1/DT1404332I/O †STRA4 can also be selected as the USART1 (SCI) Asyn-
RA5/TX1/CK1394231I/O †STRA5 can also be selected as the USART1 (SCI) Asyn-
RB0/CAP1555947I/OSTRB0 can also be the Capture1 input pin.
RB1/CAP2545846I/OSTRB1 can also be the Capture2 input pin.
RB2/PWM1505442I/OSTRB2 can also be the PWM1 output pin.
RB3/PWM2535745I/OSTRB3 can also be the PWM2 output pin.
RB4/TCLK12525644I/OSTRB4 can also be the external clock input to Timer1 and
RB5/TCLK3515543I/OSTRB5 can also be the external clock input to Timer3.
RB6/SCK444736I/OSTRB6 can also be used as the master/slave clock for the
RB7/SDO454837I/OSTRB7 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;
† The output is only available by the Peripheral operation.
/SCL424534I/OSTRA2 can also be used as the slave select input for the
ST = Schmitt Trigger input.
PLCC
No.
No.
TQFP
No.
I/O/P
Type
Buffer
Type
Description
External clock input in external clock mode.
oscillator mode. In RC oscillator or external clock modes
OSC2 pin outputs CLKOUT which has one fourth the frequency (F
rate.
input. This is the active low reset input to the chip.
PORTA is a bi-directional I/O Port except for RA0 and RA1
which are input only.
PORTB is a bi-directional I/O Port with software configurable weak pull-ups.
OSC/4) of OSC1 and denotes the instruction cycle
input. Interrupt can be configured to be on positive or
negative edge.
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.
SPI or the clock input for the I
High voltage, high current, open drain input/output port
pin.
the data for the I
High voltage, high current, open drain input/output port
pin.
chronous Receive or USART1 (SCI) Synchronous
Data.
chronous Transmit or USART1 (SCI) Synchronous
Clock.
RC0/AD02358I/OTTLThis is also the least significant byte (LSB) of the 16-bit
RC1/AD1636755I/OTTL
RC2/AD2626654I/OTTL
RC3/AD3616553I/OTTL
RC4/AD4606452I/OTTL
RC5/AD5586351I/OTTL
RC6/AD6586250I/OTTL
RC7/AD7576149I/OTTL
RD0/AD810112I/OTTLThis is also the most significant byte (MSB) of the
RD1/AD99101I/OTTL
RD2/AD108964I/OTTL
RD3/AD117863I/OTTL
RD4/AD126762I/OTTL
RD5/AD135661I/OTTL
RD6/AD144560I/OTTL
RD7/AD153459I/OTTL
RE0/ALE11123I/OTTLIn microprocessor mode or extended microcontroller
RE1/OE
RE2/WR
RE3/CAP414156I/OSTRE3 can also be the Capture4 input pin.
RF0/AN4262818I/OSTRF0 can also be analog input 4.
RF1/AN5252717I/OSTRF1 can also be analog input 5.
RF2/AN6242616I/OSTRF2 can also be analog input 6.
RF3/AN7232515I/OSTRF3 can also be analog input 7.
RF4/AN8222414I/OSTRF4 can also be analog input 8.
RF5/AN9212313I/OSTRF5 can also be analog input 9.
RF6/AN10202212I/OSTRF6 can also be analog input 10.
RF7/AN11192111I/OSTRF7 can slso be analog input 11.
Legend: I = Input only; O = Output only; I/O = Input/Output; P = Power; — = Not Used; TTL = TTL input;
ST = Schmitt Trigger input.
† The output is only available by the Peripheral operation.
PLCC
No.
12134I/OTTLIn microprocessor or extended microcontroller mode,
13145I/OTTLIn microprocessor or extended microcontroller mode,
No.
TQFP
No.
I/O/P
Type
Buffer
Type
Description
PORTC is a bi-directional I/O Port.
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.
PORTD is a bi-directional I/O Port.
16-bit system bus in microprocessor mode or extended
microprocessor mode or extended microcontroller
mode. In multiplexed system bus configuration these
pins are address output as well as data input or output.
PORTE is a bi-directional I/O Port.
mode, RE0 is the Address Latch Enable (ALE) output.
Address should be latched on the falling edge of ALE
output.
RE1 is the Output Enable (OE
low).
RE2 is the Write Enable (WR
low).
PORTF is a bi-directional I/O Port.
) control output (active
) control output (active
DS30264A-page 12Preliminary 1997 Microchip Technology Inc.
PIC17C75X
TABLE 3-1:PINOUT DESCRIPTIONS
DIP
Name
PLCC
No.
RG0/AN3323424I/OSTRG0 can also be analog input 3.
RG1/AN2313323I/OSTRG1 can also be analog input 2.
RG2/AN1/V
RG3/AN0/V
REF- 303222I/OSTRG2 can also be analog input 1, or
REF+ 293121I/OSTRG3 can also be analog input 0, or
RG4/CAP3353827I/OSTRG4 can also be the Capture3 input pin.
RG5/PWM3363928I/OSTRG5 can also be the PWM3 output pin.
RG6/RX2/DT2384130I/OSTRG6 can also be selected as the USART2 (SCI) Asyn-
RG7/TX2/CK2374029I/OSTRG7 can also be selected as the USART2 (SCI) Asyn-
TEST16178ISTTest mode selection control input. Always tie to V
V
SS17,
36,53,
33,
49,
64
V
DD1,
2, 20,
18,
34,
46
AV
SS283020PGround reference for A/D converter.
AV
DD272919PPositive supply for A/D converter.
NC-1, 18,
35, 52
Legend: I = Input only; O = Output only; I/O = Input/Output; P = Power; — = Not Used; TTL = TTL input;
ST = Schmitt Trigger input.
† The output is only available by the Peripheral operation.
No.
19,
68
37,
49,
TQFP
No.
I/O/P
Type
Buffer
Type
Description
PORTG is a bi-directional I/O Port.
the ground reference voltage
the positive reference voltage
chronous Receive or USART2 (SCI) Synchronous
Data.
chronous Transmit or USART2 (SCI) Synchronous
Clock.
DS30264A-page 14Preliminary 1997 Microchip Technology Inc.
PIC17C75X
4.0ON-CHIP OSCILLATOR
CIRCUIT
The internal oscillator circuit is used to generate the
device clock. Four device clock periods generate an
internal instruction clock (T
that the oscillator can operate in. These are selected b y
the device configuration bits during device programming. These modes are:
• LFLow Frequency (F
• XTStandard Crystal/Resonator Frequency
(2 MHz <= F
There are two timers that offer necessary delays on
power-up. 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 Power-up Timer
(PWRT), which provides 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.
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 fit the application. The RC oscillator option
saves system cost while the LF crystal option saves
power. Configuration bits are used to select various
options.
4.1Oscillator Configurations
4.1.1 OSCILLATOR TYPES
CY). There are four modes
OSC <= 2 MHz)
OSC <= 33 MHz)
4.1.2CRYSTAL OSCILLATOR / CERAMIC
RESONATORS
In XT or LF modes, a crystal or ceramic resonator is
connected to the OSC1/CLKIN and OSC2/CLKOUT
pins to establish oscillation (Figure 4-2). The
PIC17CXXX oscillator design requires the use of a parallel cut crystal. Use of a series cut crystal may give a
frequency out of the crystal manufacturers specifications.
For frequencies above 20 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.2.1OSCILLATOR / RESONATOR START-UP
As the device voltage increases from Vss , the oscillator
will start its oscillations. The time required for the oscillator to start oscillating depends on many factors.
These include:
• Crystal / resonator frequency
• Capacitor values used (C1 and C2)
• Device V
• System temperature
• Series resistor value (and type) if used
• Oscillator mode selection of device (which selects
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
oscillator waveform can be quite low (less than 50% of
device V
(refer to parameter number D033 and D043 in the electrical specification section).
DD rise time.
DD) when the waveform is centered at VDD/2
FIGURE 4-1:OSCILLATOR / RESONATOR
START-UP
CHARACTERISTICS
The PIC17CXXX can be operated in four different oscillator modes. The user can program two configuration
bits (FOSC1:FOSC0) to select one of these four
modes:
• LFLow Power Crystal
• XTCrystal/Resonator
• ECExternal Clock Input
• RCResistor/Capacitor
The main difference between the LF and XT modes is
the gain of the internal inverter of the oscillator circuit
which allows the different frequency ranges.
For more details on the device configuration bits, see
Section 17.0.
See Table 4-1 and Table 4-2 for recommended values of
C1 and C2.
RF
PIC17CXXX
SLEEP
To internal
logic
Note 1: A series resistor (Rs) may be required for
AT strip cut crystals.
TABLE 4-1:CAPACITOR SELECTION
FOR CERAMIC
RESONATORS
Oscillator
Type
Resonator
Frequency
LF455 kHz
2.0 MHz
XT4.0 MHz
8.0 MHz
16.0 MHz
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 manufacturer for appropriate values of external components.
Note 1: These values include all board capaci-
tances on this pin. Actual capacitor value
depends on board capacitance
Resonators Used:
455 kHzPanasonic EFO-A455K04B± 0.3%
2.0 MHzMurata Erie CSA2.00MG± 0.5%
4.0 MHzMurata Erie CSA4.00MG± 0.5%
8.0 MHzMurata Erie CSA8.00MT± 0.5%
16.0 MHz Murata Erie CSA16.00MX± 0.5%
Resonators used did not have built-in capacitors.
Capacitor Range
C1 = C2
(1)
15 - 68 pF
10 - 33 pF
22 - 68 pF
33 - 100 pF
33 - 100 pF
FIGURE 4-3:CRYSTAL OPERATION,
OVERTONE CRYSTALS (XT
OSC CONFIGURATION)
C1
C2
0.1 µF
To filter the fundamental frequency
1
LC2
Where f = tank circuit resonant frequency. This should be
midway between the fundamental and the 3rd overtone
frequencies of the crystal.
OSC1
SLEEP
OSC2
PIC17CXXX
2
=
(2πf)
TABLE 4-2:CAPACITOR SELECTION FOR
CRYSTAL OSCILLATOR
Osc
Type
LF32 kHz
Freq
(1)
1 MHz
2 MHz
XT2 MHz
4 MHz
(2)
8 MHz
16 MHz
25 MHz
32 MHz
Higher capacitance increases the stability of the oscillator
but also increases the start-up time and the oscillator current. 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 manufacturer for appropriate values for external components.
(3)
Note 1: For VDD > 4.5V, C1 = C2 ≈ 30 pF is recom-
mended.
2: R
S of 330Ω is required for a capacitor com-
bination of 15/15 pF.
3: These values include all board capaci-
tances on this pin. Actual capacitor value
depends on board capacitance
DS30264A-page 16Preliminary 1997 Microchip Technology Inc.
PIC17C75X
4.1.3EXTERNAL 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-impedance and the OSC2/CLKOUT pin is the CLKOUT output (4 T
OSC).
FIGURE 4-4:EXTERNAL CLOCK INPUT
OPERATION (EC OSC
CONFIGURATION)
Clock from
ext. system
CLKOUT
(F
OSC/4)
OSC1
PIC17CXXX
OSC2
4.1.4EXTERNAL CRYSTAL OSCILLATOR
CIRCUIT
Either a prepackaged oscillator can be used or a simple
oscillator circuit with TTL gates can be built. Prepackaged oscillators provide a wide operating range and
better stability. A well-designed crystal oscillator will
provide good performance with TTL gates. Two types
of crystal oscillator circuits can be used: one with series
resonance, or one with parallel resonance.
Figure 4-5 shows implementation of a parallel resonant
oscillator circuit. The circuit is designed to use the fundamental frequency of the crystal. The 74AS04 inverter
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Ω potentiometer biases the 74AS04 in the linear region. This could
be used for external oscillator designs.
FIGURE 4-5:EXTERNAL PARALLEL
RESONANT CRYSTAL
OSCILLATOR CIRCUIT
+5V
10k
4.7k
74AS04
74AS04
To Other
Devices
PIC17CXXX
OSC1
10k
XTAL
10k
20 pF
20 pF
Figure 4-6 shows a series resonant oscillator circuit.
This circuit is also designed to use the fundamental frequency of the crystal. The inverter performs a
180-degree phase shift in a series resonant oscillator
circuit. The 330 kΩ resistors provide the negative feedback to bias the inverters in their linear region.
4.1.5RC OSCILLATOR
For timing insensitive applications, the RC device
option offers additional cost savings. RC oscillator frequency is a function of the supply voltage, the resistor
(Rext) and capacitor (Cext) values, and the operating
temperature. In addition to this, oscillator frequency 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 connected 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.
1 MΩ), 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 recommend using values
above 20 pF for noise and stability reasons. With little
or no external capacitance, oscillation frequency can
vary dramatically due to changes in external capacitances, such as PCB trace capacitance or package
lead frame capacitance.
See Section 21.0 for RC frequency variation from part
to part due to normal process variation. The variation
is 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 V
DD for given Rext/Cext values as well as fre-
quency variation due to operating temperature for
given R, C, and V
DD values.
The oscillator frequency, divided by 4, is available on
the OSC2/CLKOUT pin, and can be used for test purposes or to synchronize other logic (see Figure 4-8 for
waveform).
4.1.5.1RC 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
number D032 and D042 in the electrical specification
section). The time required for the RC to start oscillating depends on many factors. These include:
• Resistor value used
• Capacitor value used
• Device V
DD rise time
• System temperature
FIGURE 4-7:RC OSCILLATOR MODE
VDD
Rext
Cext
SS
V
DS30264A-page 18Preliminary 1997 Microchip Technology Inc.
Fosc/4
PIC17CXXX
OSC1
OSC2/CLKOUT
Internal
clock
PIC17C75X
4.2Clocking Scheme/Instruction Cycle
The clock input (from OSC1) is internally divided by
four to generate four non-overlapping quadrature
clocks, namely Q1, Q2, Q3, and Q4. Internally, the program counter (PC) is incremented every Q1, and the
instruction is fetched from the program memory and
latched into the instruction register in Q4. The instruction is decoded and executed during the following Q1
through Q4. The clocks and instruction execution flow
are shown in Figure 4-8.
FIGURE 4-8:CLOCK/INSTRUCTION CYCLE
OSC1
Q1
Q2
Q3
Q4
PC
OSC2/CLKOUT
(RC mode)
Q2Q3Q4
Q1
PCPC+1PC+2
Fetch INST (PC)
Execute INST (PC-1)Fetch INST (PC+1)
Q2Q3Q4
Q1
Execute INST (PC)Fetch INST (PC+2)
4.3Instruction Flow/Pipelining
An “Instruction Cycle” consists of four Q cycles (Q1,
Q2, Q3, and Q4). The instruction fetch and execute are
pipelined such that fetch takes one instruction cycle
while decode and execute takes another instruction
cycle. However, due to the pipelining, each instruction
effectively executes in one cycle. If an instruction
causes the program counter to change (e.g. GOTO)
then two cycles are required to complete the instruction
(Example 4-1).
A fetch cycle begins with the program counter incrementing in Q1.
In the execution cycle, the f etched instruction is latched
into the “Instruction Register (IR)” in cycle Q1. This
instruction is then decoded and executed during the
Q2, Q3, and Q4 cycles. Data memory is read during Q2
(operand read) and written during Q4 (destination
write).
Q2Q3Q4
Q1
Internal
phase
clock
Execute INST (PC+1)
EXAMPLE 4-1:INSTRUCTION PIPELINE FLOW
Tcy0Tcy1Tcy2Tcy3Tcy4Tcy5
1. MOVLW 55h
2. MOVWF PORTB
3. CALL SUB_1
4. BSF PORTA, BIT3 (Forced NOP)
5. Instruction @ address SUB_1
All instructions are single cycle, except for any program branches. These take two cycles since the fetch
instruction is “flushed” from the pipeline while the new instruction is being fetched and then executed.
DS30264A-page 20Preliminary 1997 Microchip Technology Inc.
PIC17C75X
5.0RESET
The PIC17CXXX differentiates between various kinds
of reset:
• Power-on Reset (POR)
• MCLR
reset during normal operation
Note:While the device is in a reset state, the
internal phase clock is held in the Q1 state.
Any processor mode that allows external
execution will force the RE0/ALE pin as a
low output and the RE1/OE
pins as high outputs.
• Brown-out Reset
• WDT Reset (normal operation)
Some registers are not affected in any reset condition,
A simplified block diagram of the on-chip reset circuit is
shown in Figure 5-1.
their status is unknown on POR and unchanged in any
other reset. Most other registers are forced to a “reset
state” on Power-on Reset (POR), Brown-out Reset
(BOR), on MCLR
or WDT Reset and on MCLR reset
during SLEEP. A WDT Reset during SLEEP, is viewed
as the resumption of normal operation. The T
O and PD
bits are set or cleared differently in different reset situations as indicated in Table 5-3. These bits are used in
software to determine the nature of the reset. See
Table 5-4 for a full description of reset states of all registers.
FIGURE 5-1:SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT
and RE2/WR
External
Reset
MCLR
BOR
Module
WDT
Module
DD rise
V
detect
VDD
OSC1
† This RC oscillator is shared with the WDT
OST/PWRT
On-chip
RC OSC†
when not in a power-up sequence.
Brown-out
Reset
WDT
Time_Out
Reset
Power_On_Reset
OST
10-bit Ripple counter
PWRT
10-bit Ripple counter
Enable PWRT
Enable OST
S
R
Power_Up
(Enable the PWRT timer
only during Power_Up)
(Power_Up) + (Wake_Up) (XT + LF)
(Enable the OST if it is Power_Up or Wake_Up
The Power-on Reset circuit holds the device in reset
until V
DD is above the trip point (in the range of 1.4V -
2.3V). The devices produce an internal reset for both
rising and falling V
just tie the MCLR/
to V
DD. This will eliminate external RC components
DD. To take advantage of the POR,
VPP pin directly (or through a resistor)
usually needed to create Power-on Reset. A minimum
rise time for V
DD is required. See Electrical Specifica-
tions for details.
Figure 5-2 and Figure 5-3 show two possible POR cir-
cuits.
FIGURE 5-2:USING ON-CHIP POR
VDD
VDD
MCLR
PIC17CXXX
FIGURE 5-3:EXTERNAL POWER-ON
RESET CIRCUIT (FOR SLOW
DD POWER-UP)
V
V
VDD
DD
D
R
R1
MCLR
C
PIC17CXXX
5.1.2POWER-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 POR signal and 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 V
DD to rise to an acceptable level.
The power-up time delay will v ary from chip to chip and
DD and temperature. See DC parameters for
with V
details.
5.1.3OSCILLATOR START-UP TIMER (OST)
The Oscillator Start-up Timer (OST) provides a 1024
oscillator cycle (1024T
OSC) delay after MCLR is
detected high or a wake-up from SLEEP event occurs.
The OST time-out is invoked only for XT and LF oscil-
lator modes on a Power-on Reset or a Wake-up from
SLEEP.
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 figure the oscillator is of such a low frequency that
OST time out occurs after the power-up timer time-out.
FIGURE 5-4:OSCILLATOR START-UP
TIME
POR or BOR Trip Point
VDD
MCLR
OSC2
OSC1
Note 1: An external Power-on Reset circuit is
required only if V
DD power-up time is too
OST TIME_OUT
T
T
OST
slow. The diode D helps discharge the
capacitor quickly when V
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 V
MCLR/
VPP pin.
3: R1 = 100Ω to 1 kΩ will limit any current
flowing into MCLR
tor C in the event of MCLR/
breakdown due to Electrostatic Discharge (ESD) or Electrical Overstress
DD powers
IH level on the
from external capaci-
VPP pin
PWRT TIME_OUT
TPWRT
INTERNAL RESET
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
PWRT).
time (T
Tosc1 = time for the crystal oscillator to react to an oscil-
lation level detectable by the Oscillator Start-up Timer
(ost).
TOST = 1024TOSC.
(EOS).
DS30264A-page 22Preliminary 1997 Microchip Technology Inc.
PIC17C75X
5.1.4TIME-OUT SEQUENCE
If the device voltage is not within electrical specification
at the end of a time-out, the MCLR/
On power-up the time-out sequence is as follows: First
the internal POR signal goes high when the POR trip
point is reached. 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 oscillator
configuration. Table 5-1 shows the times that are associated with the oscillator configuration. Figure 5-5 and
Figure 5-6 display these time-out sequences.
held low until the voltage is within the device specification. The use of an external RC delay is sufficient for
many of these applications.
The time-out sequence begins from the first rising edge
of MCLR
Table 5-3 shows the reset conditions for some special
registers, while Table 5-4 sho ws the initialization conditions for all the registers.
TABLE 5-1:TIME-OUT IN VARIOUS SITUATIONS
Oscillator
Configuration
XT, LFGreater of: 96 ms or 1024TOSC1024TOSC——
EC, RCGreater of: 96 ms or 1024T
Power-upWake up from
OSC———
TABLE 5-2:STATUS BITS AND THEIR SIGNIFICANCE
POR
0011
1110
1101
1100
1111
10xx
000x
00x0
xx11
Note 1: When BOR is enabled, else the BOR status bit is unknown
BOR
(1)
TOPD
Power-on Reset
MCLR Reset during SLEEP or interrupt w ake-up from SLEEP
WDT Reset during normal operation
WDT W ake-up during SLEEP
MCLR Reset during normal operation
Brown-out Reset
Illegal, TO is set on POR
Illegal, PD is set on POR
CLRWDT instruction executed
VPP pin must be
.
MCLR ResetBOR
SLEEP
Event
TABLE 5-3:RESET CONDITION FOR THE PROGRAM COUNTER AND THE CPUSTA REGISTER
MCLR
WDT Reset during normal operation0000h--11 0111No
WDT Wake-up during SLEEP
(3)
0000h--11 0011
Interrupt wake-up from SLEEP GLINTD is setPC + 1--11 1011
GLINTD is clear
PC + 1
(1)
--10 1011
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 executed.
2: The OST is only active when the Oscillator is configured for XT or LF modes.
3: The Program Counter = 0, that is, the device branches to the reset vector. This is different from the
Legend: u = unchanged, x = unknown, - = 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: If Brown-out is enabled, else the BOR
Legend: u = unchanged, x = unknown, - = 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: If Brown-out is enabled, else the BOR
12h---- -------- -------- ----
bit is unknown.
uuu- uuuu
(1)
DS30264A-page 26Preliminary 1997 Microchip Technology Inc.
PIC17C75X
TABLE 5-4:INITIALIZATION CONDITIONS FOR SPECIAL FUNCTION REGISTERS (Cont.’d)
Legend: u = unchanged, x = unknown, - = 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: If Brown-out is enabled, else the BOR
5.1.5BROWN-OUT RESET (BOR)
PIC17C75X devices have an on-chip Brown-out Reset
circuitry. This circuitry places the device into a reset
when the device voltage f alls below a trip point (BV
DD).
This ensures that the device does not continue program ex ecution outside the valid oper ation range of the
device. Brown-out resets are typically used in AC line
applications or large battery applications where large
loads may be switched in (such as automotive).
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.
A configuration bit, BODEN, can disable (if clear/programmed) or enable (if set) the Brown-out Reset circuitry. If V
DD falls below BVDD (Typically 4.0V,
parameter D005 in electrical specification section), for
greater than parameter D035, the brown-out situation
will reset the chip. A reset is not guaranteed to occur if
V
DD falls below BVDD for less than parameter D035.
The chip will remain in Brown-out Reset until V
above BV
DD. The Power-up Timer will now be invoked
DD rises
and will keep the chip in reset an additional 96 ms. If
V
DD drops below BVDD while the Power-up Timer is
running, the chip will go back into a Brown-out Reset
and the Power-up Timer will be initialized. Once V
DD
rises above BVDD, the Power-up Timer will execute a
96 ms time delay. Figure 5-10 shows typical Brown-out
situations.
In some applications the Brown-out reset trip point of
the device may not be at the desired 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
VDD
DD
V
33k
10k
40 kΩ
This circuit will activate reset when VDD goes below
(Vz + 0.7V) where Vz = Zener voltage.
MCLR
PIC17CXXX
FIGURE 5-9:EXTERNAL BROWN-OUT
PROTECTION CIRCUIT 2
V
DD
VDD
R1
Q1
MCLR
R2
This brown-out circuit is less expensive, albeit less
accurate. Transistor Q1 turns off when VDD is below a
certain level such that:
VDD •
40 kΩ
R1 + R2
R1
PIC17CXXX
= 0.7V
FIGURE 5-10: BROWN-OUT SITUATIONS
V
DD
Internal
Reset
V
DD
Internal
Reset
V
DD
Internal
Reset
DS30264A-page 28Preliminary 1997 Microchip Technology Inc.
96 ms
< 96 ms
96 ms
96 ms
BV
DD Max.
DD Min.
BV
BVDD Max.
DD Min.
BV
BVDD Max.
DD Min.
BV
PIC17C75X
6.0INTERRUPTS
The PIC17C75X devices have 18 sources of interrupt:
• External interrupt from the RA0/INT pin
• Change on RB7:RB0 pins
• TMR0 Overflow
• TMR1 Overflow
• TMR2 Overflow
• TMR3 Overflow
• USART1 Transmit buffer empty
• USART1 Receive buffer full
• USART2 Transmit buffer empty
• USART2 Receive buffer full
• SSP Interrupt
• SSP I
• A/D conversion complete
• Capture1
• Capture2
• Capture3
• Capture4
• T0CKI edge occurred
There are six registers used in the control and status of
interrupts. These are:
• CPUST A
• INTST A
• 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 Memory Organization section.
FIGURE 6-1:INTERRUPT LOGIC
2
C bus collision interrupt
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 with the interrupt vector address. There are four
interrupt vectors. Each vector address is for a specific
interrupt source (except the peripheral 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 program execution vectors to one of these inter-
rupt vector addresses (except for the peripheral interrupts), the interrupt flag bit is automatically cleared.
Vectoring to the peripheral interrupt vector address
does not automatically clear the source of the interrupt.
In the peripheral interrupt service routine, the source(s)
of the interrupt can be determined by testing the interrupt flag bits. The interrupt flag bit(s) must be cleared in
software before re-enabling interrupts to avoid infinite
interrupt requests.
When an interrupt condition is met, that individual interrupt 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 cycle instructions, the latency could 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 cleared (to re-enable
interrupts).
RBIF
RBIE
TMR3IF
TMR3IE
TMR2IF
CA2IF
CA2IE
TX1IF
TX1IE
BCLIF
BCLIE
CA3IF
CA3IE
RC2IF
RC2IE
TMR2IE
RC1IF
RC1IE
ADIF
ADIE
INTSTA
T0IF
T0IE
INTF
INTE
T0CKIF
T0CKIE
PEIF
PEIE
Wake-up (If in SLEEP mode)
or terminate long write
The Interrupt Status/Control register (INTSTA) records
the individual interrupt requests in flag bits, and contains the individual interrupt enable bits (not for the
peripherals).
The PEIF bit is a read only , bit wise OR of all the peripheral flag bits in the PIR registers (Figure 6-5 and
Figure 6-6).
Note:T0IF, INTF, T0CKIF, and PEIF get set by
their specified condition, even if the corresponding interrupt enable bit is clear (interrupt disabled) or the GLINTD bit is set (all
interrupts disabled).
Care should be taken when clearing any of the INTSTA
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 corresponding interrupt enable bit is
cleared, the device will vector to the reset address
(0x00).
When disabling any of the INTSTA enable bits, the
GLINTD bit should be set (disabled).
bit7bit0
bit 7:PEIF: Peripheral Interrupt Flag bit
This bit is the OR of all peripheral interrupt flag bits AND’ed with their corresponding enable bits.
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 vector (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 vector (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 vector (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 enables all 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
DS30264A-page 32Preliminary 1997 Microchip Technology Inc.
PIC17C75X
6.3Peripheral Interrupt Request
Register1 (PIR1) and Register2 (PIR2)
These registers contains the individual flag bits for the
peripheral interrupts.
Note:These bits will be set by the specified con-
dition, 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.
bit7bit0
bit 7:RBIF: PORTB Interrupt on Change 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 enab
1 =TMR3 overflowed
0 =TMR3 did not overflow
If Capture1 is disab
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
Timer1 is in 16-bit mode (T16 = 1)
If
1 =TMR2:TMR1 value has rolled over to 0000h from equalling the period register (PR2:PR1) value
0 =TMR2:TMR1 value has not rolled over to 0000h from equalling 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 =USART1 Transmit buffer is empty
0 =USART1 Transmit buffer is full
bit 0:RC1IF: USART1 Receive Interrupt Flag bit (State controlled by hardware)
1 =USART1 Receive buffer is full
0 =USART1 Receive buffer is empty
bit7bit0
bit 7:SSPIF: Synchronous Serial Port (SSP) Interrupt Flag
1 = The SSP interrupt condition has occured, 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.
2
I
C Slave / Master
A transmission/reception has taken place.
2
I
C Master
The initiated start condition was completed by the SSP module.
The initiated stop condition 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 (Multimaster system).
A stop condition occurred while the SSP module was idle (Multimaster system).
0 = An SSP interrupt condition has occurred.
bit 6:BCLIF: Bus Collision Interrupt Flag
1 =A bus collision has occurred in the SSP, when configured for I
0 =No bus collision has occurred
bit 5:ADIF: A/D Module Interrupt Flag
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
1 =Capture event occurred on RE3/CAP4 pin
0 =Capture event did not occur on RE3/CAP4 pin
bit 2:CA3IF: Capture3 Interrupt Flag
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 (State controlled by hardware)
1 =USART2 Transmit buffer is empty
0 = USART2 Transmit buffer is full
bit 0:RC2IF: USART2 Receive Interrupt Flag (State controlled by hardware)
1 =USART2 Receive buffer is full
0 =USART2 Receive buffer is empty
—
CA4IFCA3IFTX2IFRC2IF
2
C master mode
R = Readable bit
W = Writable bit
-n = Value at POR reset
DS30264A-page 34Preliminary 1997 Microchip Technology Inc.
PIC17C75X
6.4Interrupt Operation
Global Interrupt Disable bit, GLINTD (CPUSTA<4>),
enables all unmasked interrupts (if clear) or disables all
interrupts (if set). Individual interrupts can be disabled
through their corresponding enable bits in the INTSTA
register. Peripheral interrupts need either the global
peripheral enable PEIE bit disabled, or the specific
peripheral enable bit disabled. Disabling the peripherals via the global peripheral enable bit, disables all
peripheral interrupts. GLINTD is set on reset (interrupts
disabled).
The RETFIE instruction allows retur ning from interrupt
and re-enables interrupts at the same time.
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 interrupt vector. There are four interrupt
vectors which help reduce interrupt latency.
The peripheral interrupt vector has multiple interrupt
sources. Once in the peripheral interrupt service routine, the source(s) of the interrupt can 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 PIC17C75X devices have four interrupt vectors.
These vectors and their hardware priority are shown in
Table 6-1. If two enabled interrupts occur “at the same
time”, the interrupt of the highest priority will be serviced first. This means that the vector address of that
interrupt will be loaded into the program counter (PC).
TABLE 6-1:INTERRUPT
VECTORS/PRIORITIES
AddressVectorPriority
0008hExternal Interrupt on
RA0/INT pin (INTF)
0010hTMR0 overflow interrupt
(T0IF)
0018hExternal Interrupt on T0CKI
(T0CKIF)
0020hPeripherals (PEIF)4 (Lowest)
Note 1: Individual interrupt flag bits are set regard-
less of the status of their corresponding
mask bit or the GLINTD bit.
Note 2: Before disabling any of the INTSTA enable
bits, the GLINTD bit should be set
(disabled).
1 (Highest)
2
3
6.5RA0/INT Interrupt
The external interrupt on the RA0/INT pin is edge triggered. Either the rising edge, if INTEDG bit
(T0STA<7>) is set, or the falling edge, if INTEDG bit is
clear. When a valid edge appears on the RA0/INT pin,
the INTF bit (INTSTA<4>) is set. This interrupt can be
disabled by clearing the INTE control bit (INTSTA<0>).
The INT interrupt can wake the processor from SLEEP.
See Section 17.4 for details on SLEEP operation.
6.6T0CKI 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 falling edge, if the T0SE bit is
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
processor from SLEEP. See Section 17.4 for details on
SLEEP operation.
6.7Peripheral Interrupt
The peripheral interrupt flag indicates that at least one
of the peripheral interrupts occurred (PEIF 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 AND’ed with the corresponding enable bits in the PIE registers. Some of the
peripheral interrupts can wake the processor from
SLEEP. See Section 17.4 for details on SLEEP operation.
6.8Context Saving During Interrupts
During an interrupt, only the returned PC value is saved
on the stack. Typically, users ma y wish to sa v e k e y registers during an interrupt; e.g. WREG, ALUSTA and the
BSR registers. This requires implementation in software.
Example 6-2 shows the saving and restoring of information 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 information for a more complex interrupt service routine.
This is useful where nesting of interrupts is required. A
maximum of 6 levels can be done b y this example. The
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 done with this routine (since
there are 6 non-banked GPR registers). These routines
require a dedicated indirect addressing register, FSR0
has been selected for this.
The PUSH and POP code segments could either be in
each interrupt service routine or could be subroutines
that were called. Depending on the application, other
registers may also need to be saved.
DS30264A-page 36Preliminary 1997 Microchip Technology Inc.
PIC17C75X
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)
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 ; Periperal 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)
DS30264A-page 38Preliminary 1997 Microchip Technology Inc.
PIC17C75X
7.0MEMORY ORGANIZATION
There are two memory blocks in the PIC17C75X; program memory and data memory. Each block has its
own bus, so that access to each bloc k can occur during
the same oscillator cycle.
The data memory can further be broken down into
General Purpose RAM and the Special Function Registers (SFRs). The operation of the SFRs that control
the “core” are described here. The SFRs used to control the peripheral modules are described in the section
discussing each individual peripheral module.
7.1Program Memory Organization
PIC17C75X devices have a 16-bit program counter
capable of addressing a 64K x 16 program memory
space. The reset vector is at 0000h and the interrupt
vectors are at 0008h, 0010h, 0018h, and 0020h
(Figure 7-1).
7.1.1PROGRAM MEMORY OPERATION
The PIC17C75X can operate in one of four possible
program memory configurations. The configuration is
selected by configuration bits. The possible modes
are:
• Microprocessor
• Microcontroller
• Extended Microcontroller
• Protected Microcontroller
The microcontroller and protected microcontroller
modes only allow internal execution. Any access
beyond the program memory reads unknown data.
The protected microcontroller mode also enables the
code protection feature.
The extended microcontroller mode accesses both the
internal program memory as well as external program
memory. Execution automatically switches between
internal and external memory. The 16-bits of address
allow a program memory range of 64K-words.
The microprocessor mode only accesses the external
program memory. The on-chip program memory is
ignored. The 16-bits of address allow a program memory range of 64K-words. Microprocessor mode is the
default mode of an unprogrammed device.
The different modes allow different access to the configuration bits, test memory, and boot ROM. Table 7-1
lists which modes can access which areas in memory.
Test Memor y 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>
CALL, RETURN
RETFIE, RETLW
Stack Level 1
Stack Level 16
Reset Vector
INT Pin Interrupt Vector
Timer0 Interrupt Vector
and extended microcontroller modes. The microprocessor 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
Extended
Microcontroller
Mode
External
Program
Memory
01FFFh
PIC17C752
Microprocessor
Mode
0000h
External
Program
Memory
FFFFh
OFF-CHIPON-CHIPOFF-CHIPON-CHIPOFF-CHIPON-CHIP
2000h
FFFFh
0000h
On-chip
Program
Memory
Microcontroller
Modes
0000h
01FFFh
2000h
Config. Bits
FE00h
Test Memory
FFFFh
On-chip
Program
Memory
Boot ROM
PROGRAM SPACEDATA SPACE
PIC17C756
00h
120h
FFh 1FFh
ON-CHIPON-CHIPON-CHIP
0000h
External
Program
Memory
FFFFh
OFF-CHIPON-CHIPOFF-CHIPON-CHIPOFF-CHIPON-CHIP
00h
120h
220h
FFh 1FFh
2FFh
ON-CHIP
320h
3FFh
4000h
FFFFh
External
Program
Memory
00h
FFh 1FFh
0000h
3FFFh
120h
00h
120h
FFh 1FFh
On-chip
Program
Memory
320h
220h
3FFh
2FFh
0000h
3FFFh
4000h
FE00h
FFFFh
00h
FFh 1FFh
00h
FFh 1FFh
Config. Bits
Test Memory
Boot ROM
120h
220h
2FFh
ON-CHIPON-CHIP
120h
On-chip
Program
Memory
320h
3FFh
PROGRAM SPACEDATA SPACE
DS30264A-page 40Preliminary 1997 Microchip Technology Inc.
PIC17C75X
7.1.2EXTERNAL MEMORY INTERFACE
When either microprocessor or extended microcontrol-
ler mode is selected, PORTC, P ORTD and PORTE are
configured as the system bus. P ORTC and PORTD are
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 complete timings, please refer to the electrical specification
section.
FIGURE 7-3:EXTERNAL PROGRAM
MEMORY ACCESS
WAVEFORMS
Q1 Q2Q4Q3Q1 Q2Q4
AD
<15:0>
Address out Data in
ALE
OE
'1'
WR
Q3
Read cycle
Address out
Write cycle
The system bus requires that there is no bus conflict
(minimal leakage), so the output value (address) will be
capacitively held at the desired value.
As the speed of the processor increases, external
EPROM memory with faster access time must be used.
T ab le 7-2 lists external memory speed requirements for
a given PIC17C75X device frequency.
Q1
Data out
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.
This following selection is for use with Microchip
EPROMs. For interfacing to other manufacturers memory, please refer to the electrical specifications of the
desired PIC17C75X device, as well as the desired
memory device to ensure compatibility.
Data memory is partitioned into two areas. The first is
the General Purpose Registers (GPR) area, while the
second is the Special Function Registers (SFR) area.
The SFRs control and give the status for the operation
of the device.
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 selection. These control bits are located in the Bank Select
Register (BSR). If an access is made to the unbanked
region, the BSR bits are ignored. Figure 7-5 shows the
data memory map organization.
Instructions MOVPF and MOVFP provide the means to
move values from the peripheral area (“P”) to any location in the register file (“F”), and vice-versa. The definition of the “P” range is from 0h to 1Fh, while the “F”
range is 0h to FFh. The “P” range has six more locations than peripheral registers which can be used as
General Purpose Registers. This can be useful in some
applications where variables need to be copied 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 (Section 7.4). Indirect addressing uses the
appropriate control bits of the BSR for accesses into
the banked areas of data memory. The BSR is
explained in greater detail in Section 7.8.
7.2.1GENERAL PURPOSE REGISTER (GPR)
All devices have some amount of GPR area. The GPRs
are 8-bits wide. When the GPR area is greater than
232, it must be banked to allow access to the additional
memory space.
All the PIC17C75X devices have banked memory in
the GPR area. To facilitate switching between these
banks, the MOVLR bank instruction has been added to
the instruction set. GPRs are not initialized by a
Power-on Reset and are unchanged on all other resets .
7.2.2SPECIAL FUNCTION REGISTERS (SFR)
The SFRs are used by the CPU and peripheral func-
tions to control the operation of the device (Figure 7-5).
These registers are static RAM.
The SFRs can be classified into two sets, those associated 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
peripheral feature are described in the section for each
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 instruction has been provided.
DS30264A-page 42Preliminary 1997 Microchip Technology Inc.
00hINDF0Uses contents of FSR0 to address data memory (not a physical register)---- ---- ---- ---01hFSR0Indirect data memory address pointer 0xxxx xxxx uuuu uuuu
02hPCLLow order 8-bits of PC0000 0000 0000 0000
Legend:x = unknown, u = unchanged, - = unimplemented read as '0', q - value depends on condition. Shaded cells are unimplemented, read as '0'.
Note 1:The upper byte of the program counter is not directly accessible. PCLATH is a holding register for PC<15:8> whose contents are updated
from or transferred to the upper byte of the program counter.
2: The T
3: Other (non power-up) resets include: external reset through MCLR
O and PD status bits in CPUSTA are not affected by a MCLR reset.
——STKAVGLINTDTOPDPORBOR--11 1100 --11 qquu
RA5/TX1/
—
RB7/
SDO
RC7/
AD7
RD7/
AD15
RB6/
SCK
RC6/
AD6
RD6/
AD14
————
TCLK3
AD13
RA4/RX1/
CK1
RB5/
RC5/
AD5
RD5/
DT1
RB4/
TCLK12
RC4/
AD4
RD4/
AD12
RA3/SDI/
SDA
RB3/
PWM2
—FERROERRRX9D0000 -00x 0000 -00u
——TRMTTX9D0000 --1x 0000 --1u
RC3/
AD3
RD3/
AD11
RE3/
CAP4
and Watchdog Timer Reset.
RA2/SS
SCL
RB2/
PWM1
RC2/
AD2
RD2/
AD10
RE2/WR
/
RA1/T0CKI RA0/INT 0-xx xxxx 0-uu uuuu
RB1/
CAP2
RC1/
AD1
RD1/
AD9
RE1/OERE0/ALE ---- xxxx ---- uuuu
RB0/
CAP1
RC0/
AD0
RD0/
AD8
Value on
POR,
BOR
0000 0000 uuuu uuuu
—0000 000- 0000 000-
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
Value on
all other
resets (3)
DS30264A-page 44Preliminary 1997 Microchip Technology Inc.
TCON2CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3
Bank 4:
10hPIR2SSPIFBCLIFADIF—CA4IFCA3IFTX2IFRC2IF000- 0010 000- 0010
11hPIE2SSPIEBCLIEADIE—CA4IECA3IETX2IERC2IE000- 0000 000- 0000
12hUnimplemented————————---- ---- ---- ---13hRCSTA2SPENRX9SRENCREN—FERROERRRX9D0000 -00x 0000 -00u
14hRCREG2Serial Port Receive Register for USART2xxxx xxxx uuuu uuuu
15hTXSTA2CSRCTX9TXENSYNC——TRMTTX9D0000 --1x 0000 --1u
16hTXREG2Serial Port Transmit Register for USART2xxxx xxxx uuuu uuuu
17hSPBRG2Baud Rate Generator for USART2xxxx xxxx uuuu uuuuBank 5:
10hDDRFData Direction Register for PORTF1111 1111 1111 1111
11hPORTFRF7/
12hDDRGData Direction Register for PORTG1111 1111 1111 1111
13hPORTGRG7/
14hADCON0CHS3CHS2CHS1CHS0
15hADCON1ADCS1 ADCS0ADFM—PCFG3PCFG2PCFG1PCFG0 000- 0000 000- 0000
16hADRESLA/D Result Register low bytexxxx xxxx uuuu uuuu
17hADRESHA/D Result Register high bytexxxx xxxx uuuu uuuu
Legend:x = unknown, u = unchanged, - = unimplemented read as '0', q - value depends on condition. Shaded cells are unimplemented, read as '0'.
Note 1:The upper byte of the program counter is not directly accessible. PCLATH is a holding register for PC<15:8> whose contents are updated
from or transferred to the upper byte of the program counter.
2: The T
3: Other (non power-up) resets include: external reset through MCLR
O and PD status bits in CPUSTA are not affected by a MCLR reset.
PRODLLow Byte of 16-bit Product (8 x 8 Hardware Multiply)
18h
(5)
PRODHHigh Byte of 16-bit Product (8 x 8 Hardware Multiply)
19h
Legend:x = unknown, u = unchanged, - = unimplemented read as '0', q - value depends on condition. Shaded cells are unimplemented, read as '0'.
Note 1:The upper byte of the program counter is not directly accessible. PCLATH is a holding register for PC<15:8> whose contents are updated
from or transferred to the upper byte of the program counter.
2: The T
3: Other (non power-up) resets include: external reset through MCLR
O and PD status bits in CPUSTA are not affected by a MCLR reset.
————————---- ---- ---- ----
and Watchdog Timer Reset.
Value on
POR,
BOR
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
Value on
all other
resets (3)
DS30264A-page 46Preliminary 1997 Microchip Technology Inc.
PIC17C75X
7.2.2.1ALU 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 registers, the ALUSTA register can
be the destination for any instruction. If the ALUSTA
register is the destination for an instruction that affects
the Z, DC or C bits, then the write to these three bits is
disabled. These bits are set or cleared according to the
device logic. Therefore, the result of an instruction with
the ALUSTA register as destination may be different
than intended.
For example, CLRF ALUSTA will clear the upper four
bits and set the Z bit. This leaves the ALUSTA 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 bit. To see how other instructions
affect the status bits, see the “Instruction Set Summary.”
Note 3: The C and DC bits operate as a borrow
and digit borrow bit, respectively, in subtraction. See the SUBLW and SUBWF
instructions for examples.
Note 4: The overflow bit will be set if the 2’s com-
plement result exceeds +127 or is less
than -128.
The Arithmetic and Logic Unit (ALU) is capable of carrying out arithmetic or logical operations on two operands or a single operand. All single operand
instructions operate either on the WREG register or the
given file register. For two operand instructions, one of
the operands is the WREG register and the other one
is either a file register or an 8-bit immediate constant.
R/W - 1 R/W - 1 R/W - 1 R/W - 1 R/W - xR/W - x R/W - x R/W - x
FS3FS2FS1FS0OVZDCC
bit7bit0
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 (2’s complement). It indicates an overflow of the 7-bit magnitude,
which causes the sign bit (bit7) to change state.
1 =Overflow occurred for signed arithmetic, (in this arithmetic operation)
0 =No overflow occurred
bit 2:Z: Zero bit
1 =The result of an arithmetic or logic operation is zero
0 =The results of an arithmetic or logic operation is not zero
bit 1:DC: Digit carry/borro
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/borro
For ADDWF and ADDLW instructions.
1 =A carry-out from the most significant bit of the result occurred
Note that a subtraction is executed by adding the two’s 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.
0 =No carry-out from the most significant bit of the result
Note: For borrow the polarity is reversed.
7.2.2.2CPU 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
interrupt is desired to be enabled/disabled, please refer
to the INTerrupt STAtus (INTSTA) register and the
Peripheral Interrupt Enable (PIE) registers. The
CPUSTA register also indicates if the stack is available
and contains the Power-down (PD
bits. The T
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.
O, PD, and STKAV bits are not writable.
) and Time-out (TO)
The POR
Power-on Reset, external MCLR
Reset. The BOR
occured.
bit allows the differentiation between a
bit indicates if a Brown-out Reset
Note 1: The BOR status bit is a don’t care and is
not necessarily predictable if the
brown-out circuit is disabled (when the
BODEN bit in the Configuration word is
programmed).
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 ov er from Fh → 0h (stac k ov erflow).
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 interrupt.
1 =Disable all interrupts
0 =Enables all un-masked interrupts
bit 3:T
bit 2:PD
bit 1:POR
bit 0:BOR
O: WDT Time-out Status bit
1 =After power-up or by a CLRWDT instruction
0 =A Watchdog Timer time-out occurred
: Power-down Status bit
1 =After power-up or by the CLRWDT instruction
0 =By execution of the SLEEP instruction
: Power-on Reset Status bit
1 =No Power-on Reset occurred
0 =A Power-on Reset occurred (must be set by software after a Power-on Reset occurs)
: Brown-out Reset Status bit
1 =No Brown-out Reset occurred
0 =A Brown-out Reset occurred (must be set by software after a Brown-out Reset occurs)
reset, or a WDT
R = Readable bit
W = Writable bit
U = Unimplemented bit,
Read as ‘0’
- n = Value at POR reset
DS30264A-page 48Preliminary 1997 Microchip Technology Inc.
7.2.2.3TMR0 STATUS/CONTROL REGISTER
(T0STA)
This register contains various control bits. Bit7
(INTEDG) is used to control the edge upon which a signal on the RA0/INT pin will set the RA0/INT interrupt
flag. The other bits configure the Timer0 prescaler and
clock source.
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 generates a T0CKIF interrupt
0 =Falling edge of RA1/T0CKI pin increments TMR0 and/or generates a T0CKIF interrupt
When
T0CS = 1 (Internal Clock)
Don’t care
bit 5:T0CS: Timer0 Clock Source Select bit
This bit selects the clock source for Timer0.
1 =Internal instruction clock cycle (T
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.
CY)
—
PIC17C75X
R = Readable bit
W = Writable bit
U = Unimplemented,
reads as ‘0’
PIC17C75X devices have a 16 x 16-bit hardw are stack
(Figure 7-1). The stac k 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
“PUSHed” onto the stack when a CALL or LCALL
instruction is executed or an interrupt is acknowledged.
The stack is “POP ed” in the event of a RETURN, RETLW,
or a RETFIE instruction execution. PCLATH 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 stack
available bit (STKAV) to allow software to ensure that
the stack has not overflowed. 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.
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.
Note 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.
Note 3: After a reset, if a “POP” operation occurs
before a “PUSH” operation, the STKA V 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.
After the device is “PUSHed” sixteen times (without a
“POP”), the seventeenth push overwrites the value
from the first push. The eighteenth push overwrites the
second push (and so on).
7.4Indirect Addressing
Indirect addressing is a mode of addressing data
memory 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-9 shows the operation of indirect addressing.
This shows the moving of the value to the data memory address specified by the value of the FSR register.
Example 7-1 shows the use of indirect addressing to
clear RAM in a minimum number of instructions. A
similar 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 easily be modified by the
program.
FIGURE 7-9:INDIRECT ADDRESSING
RAM
Instruction
Executed
OpcodeAddress
File = INDFx
Instruction
Fetched
Opcode
File
FSR
DS30264A-page 50Preliminary 1997 Microchip Technology Inc.
PIC17C75X
7.4.1INDIRECT ADDRESSING REGISTERS
The PIC17C75X has four registers for indirect
addressing. These registers are:
• INDF0 and FSR0
• INDF1 and FSR1
Registers INDF0 and INDF1 are not physically imple-
mented. Reading or writing to these registers activates
indirect addressing, with the value in the corresponding FSR register being the address of the data. The
FSR is an 8-bit register and allows addressing anywhere in 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 equivalent to a NOP, and the status bits are not
affected.
7.4.2INDIRECT 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 value (address) in the FSR
after an indirect access
• No change to the value (address) in the FSR after
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 using the auto-increment or auto-decrement
features, 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 read 0h (Zero bit is set) while an indirect write
will be equivalent to a NOP (status bits are not
affected).
Indirect addressing allows single cycle data transfers
within the entire data space. This is possible with the
use of the MOVPF and 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 determined by the value in the BSR.
A simple program to clear RAM from 20h - FFh is
shown in Example 7-1.
EXAMPLE 7-1:INDIRECT ADDRESSING
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 ; Addr(FSR) = 0
CPFSEQ FSR0 ; FSR0 = END_RAM+1?
GOTO LP ; NO, clear next
: ; YES, All RAM is
: ; cleared
7.5T
able 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 transfer of data between program and data space. The table
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.6Table 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 program memory. The table latch is used as a temporary
holding latch during data transfer between program
and data memory (see TABLRD, TABLWT, TLRD andTLWT instruction descriptions). For a more complete
description of these registers and the operation of
Table Reads and Table Writes, see Section 8.0.
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 program memory, an 8-bit register PCLATH (PC high
latch) is used as a holding latch for the high byte of the
PC. PCLATH is mapped into data memor y. The user
can read or write PCH through PCLATH.
The 16-bit wide PC is incremented after each instruction fetch during Q1 unless:
• 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-10 and Figure 7-11 show the operation of the
program counter for various situations.
FIGURE 7-10: PROGRAM COUNTER
OPERATION
Internal data bus <8>
8
PCLATH
8
PCHPCL
8
Using Figure 7-10, the operations of the PC and
PCLATH for different instructions are as follows:
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 instr
uctions on PCL:
Any instruction that reads PCL.
PCL → data bus → ALU or destination
PCH → PCLATH
c) Wr
ite instructions on PCL:
Any instruction that writes to PCL.
8-bit data → data bus → PCL
PCLATH → PCH
d) Read-Modify-Wr
ite 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-bit result → data bus → PCL
PCLATH → PCH
e) RETURN
instruction:
Stack<MRU> → PC<15:0>
Using Figure 7-11, the operation of the PC and
PCLATH for GOTO and CALL instructions is as follows:
CALL, GOTO instructions:
A 13-bit destination address is provided in the
DS30264A-page 52Preliminary 1997 Microchip Technology Inc.
The read-modify-write only affects the PCL with the
result. PCH is loaded with the value in the PCLATH.
For example, ADDWF PCL will result in a jump within the
current page. If PC = 03F0h, WREG = 30h and
PCLATH = 03h before instruction, PC = 0320h after the
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).
PIC17C75X
7.8Bank Select Register (BSR)
The BSR is used to switch between banks in the data
memory area (Figure 7-12). In the PIC17C752, and
PIC17C756 devices, 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 address 17h, is banked. The low er nibble of the bank
select register (BSR) selects the currently active
“peripheral bank.” Effort has been made to group the
peripheral registers of related functionality in one bank.
However, it will still be necessary to switch from bank
to bank in order to address all peripherals related to a
single task. To assist this, a MOVLB bank instruction
has been included in the instruction set.
The need for a large general purpose memory space
dictated a general purpose RAM banking scheme. The
upper nibble of the BSR selects the currently active
general purpose RAM bank. To assist this, a MOVLRbank instruction has been provided in the instruction
set.
If the currently selected bank is not implemented (such
as Bank 13), any read will read all '0's. Any write is
completed to the bit bucket and the ALU status bits will
be set/cleared as appropriate.
Note:Registers in Bank 15 in the Special Func-
tion Register area, are reserved for
Microchip use. Reading of registers in this
bank may cause random values to be read.
FIGURE 7-12: BSR OPERATION
BSR
7430
(2)
(1)
Address
Range
10h
17h
20h
FFh
Note 1: Only Banks 0 through 7 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: Bank 0 and Bank 1 are implemented for the PIC17C752, and Banks 0 through 3 are implemented for the PIC17C756.
Selection of an unimplemented bank is not recommended.
DS30264A-page 54Preliminary 1997 Microchip Technology Inc.
PIC17C75X
8.0TABLE READS AND TABLE
WRITES
The PIC17C75X has four instructions that allow the
processor to move data from the data memory 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 TABLRDt,i,f instructions are used to write data from the program memory space to the data memory space.
The program memory can be internal or external. For
the program memory access to be external, the device
needs to be operating in extended microcontroller or
microprocessor mode.
Figure 8-1 through Figure 8-4 show the operation of
these four instructions.
FIGURE 8-1:TLWT INSTRUCTION
OPERATION
TABLE POINTER
TBLPTRH
TBLPTRL
FIGURE 8-2:TABLWT INSTRUCTION
OPERATION
TABLE POINTER
TBLPTRH
TABLE LATCH (16-bit)
TABLATHTABLATL
3
TABLWT 1,i,fTABLWT 0,i,f
DATA
MEMORY
f
1
TBLPTRL
3
PROGRAM MEMORY
Prog-Mem
(TBLPTR)
2
TABLE LATCH (16-bit)
TABLATHTABLATL
TLWT 1,fTLWT 0,f
DATA
MEMORY
f
1
PROGRAM MEMORY
Note 1: 8-bit value, from register 'f', loaded into the
high or low byte in TABLAT (16-bit).
Note 1: 8-bit value, from register 'f', loaded into the
DS30264A-page 56Preliminary 1997 Microchip Technology Inc.
PIC17C75X
8.1Table Writes to Internal Memory
A table write operation to internal memory causes a
long write operation. The long write is necessary for
programming the internal EPROM. Instruction execution 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 specification #D114). Having only one interrupt enabled to
terminate 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. Disable all interrupt sources, except the source
to terminate EPROM program write.
2. Raise MCLR
age.
3. Clear the WDT.
4. Do the table write. The interrupt will terminate
the long write.
5. Verify the memory location (table read).
Note 1: Programming requirements must be
Note 2: If the V
/VPP pin to the programming volt-
met. See timing specification 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.
PP requirement is not met, the
table write is a 2 cycle write and the program memory is unchanged.
8.1.1TERMINATING LONG WRITES
An interrupt source or reset are the only events that
terminate a long write operation. Terminating the long
write from an interrupt source requires that the interrupt 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 terminate the long write; the interrupt flag, of
the highest priority enabled interrupt, will terminate the
long write and automatically be cleared.
Note 1: If an interrupt is pending, the TABLWT is
aborted (an NOP is executed). The
highest priority pending interrupt, from
the T0CKI, RA0/INT, or TMR0 sources
that is enabled, has its flag cleared.
Note 2: If the interrupt is not being used for the
program write timing, the interrupt
should be disabled. This will ensure that
the interrupt is not lost, nor will it terminate the long write prematurely.
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 vector when the long write is
terminated. If GLINTD is clear, the program will vector,
if GLINTD is set, the program will not vector to the
interrupt address.
Terminate long table write (to internal program
memory), branch to interrupt vector (branch clears
flag bit).
None
None
Terminate table write, do not branch to interrupt
vector (flag is automatically cleared).
Terminate table write, branch to interrupt vector.
None
None
Terminate table write, do not branch to interrupt
vector (flag remains set).
PIC17C75X
8.2Table Writes to External Memory
Table writes to external memor y are always two-cycle
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.2TABLE WRITE CODE
The “i” operand of the TABLWT instruction can specify
that the value in the 16-bit TBLPTR register is automatically incremented (for the next write). In
Example 8-1, the TBLPTR register is not automatically
incremented.
EXAMPLE 8-1:TABLE WRITE
Note:If an interrupt is pending or occurs during
the TABLWT, the two cycle table write
completes. The RA0/INT, TMR0, or
T0CKI interrupt flag is automatically
cleared or the pending peripheral interrupt is acknowledged.
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 TABLATH
; and write to
; program memory
; (Ext. SRAM)
FIGURE 8-5:TABLWT WRITE TIMING (EXTERNAL MEMORY)
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
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.
PCPC+1TBLPC+2Data out
TABLWT
INST (PC-1)
'1'
INST (PC+1)
TABLWT cycle1TABLWT cycle2
Data write cycle
INST (PC+2)
INST (PC+1)
DS30264A-page 58Preliminary 1997 Microchip Technology Inc.
The table read allows the program memory to be read.
This allows constants to be stored in the program
memory 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 + 1. The first read loads the data into
the latch, and can be considered a dummy read
(unknown data loaded into 'f'). INDF0 should be configured for either auto-increment or auto-decrement.
FIGURE 8-7:TABLRD TIMING
Q3
Q4
Q1 Q2
AD15:AD0
Instruction
fetched
Q1 Q2
PCPC+1TBLData in
TABLRDINST (PC+1)
EXAMPLE 8-2:TABLE READ
MOVLW HIGH (TBL_ADDR) ; Load the Table
MOVWF TBLPTRH ; address
MOVLW LOW (TBL_ADDR) ;
MOVWF TBLPTRL ;
TABLRD 0,0,DUMMY ; Dummy read,
; Updates TABLATH
TLRD 1, INDF0 ; Read HI byte
; of TABLATH
TABLRD 0,1,INDF0 ; Read LO byte
; of TABLATH and
; Update TABLATH
DS30264A-page 60Preliminary 1997 Microchip Technology Inc.
'1'
PIC17C75X
9.0HARDWARE MULTIPLIER
All PIC17C75X devices have an 8 x 8 hardware multiplier included in the ALU of the device. By making the
multiply a hardware operation, it completes in a single
instruction cycle. This is an unsigned m ultiply 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 following advantages:
• Higher computational throughput
• Reduces code size requirements for multiply algo-
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 argument of the multiply is already loaded in
the WREG register.
Example 9-2 shows the sequence to do an 8 x 8 signed
multiply. To account for the sign bits of the arguments,
each argument’s most significant bit (MSb) is tested
and the appropriate subtractions are done.
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.
DS30264A-page 62Preliminary 1997 Microchip Technology Inc.
PIC17C75X
Example 9-4 shows the sequence to do an 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 arguments, each argument pairs most significant bit (MSb)
is tested and the appropriate subtractions are done.
DS30264A-page 64Preliminary 1997 Microchip Technology Inc.
PIC17C75X
10.0I/O PORTS
PIC17C75X devices have seven I/O ports, PORTA
through PORTG. PORTB through PORTG have a corresponding Data Direction Register (DDR), which is
used to configure the port pins as inputs or outputs.
These seven ports are made up of 50 I/O pins. Some
of these ports pins are multiplexed with alternate functions.
PORTC, PORTD, and PORTE are multiplexed with the
system bus. These pins are configured as the system
bus when the device’ s configuration bits are selected to
Microprocessor or Extended Microcontroller modes. In
the two other microcontroller modes, these pins are
general purpose I/O.
PORTA, PORTB, PORTE<3>, PORTF and PORTG
are multiplexed with the peripheral features of the
device. These peripheral features are:
• Timer modules
• Capture modules
• PWM modules
• USART/SCI modules
• SSP Module
• A/D Module
• External Interrupt pin
When some of these peripheral modules are turned on,
the port pin will automatically configure to the alternate
function. The modules that do this are:
• PWM module
• SSP module
• USART/SCI module
When a pin is automatically configured as an output 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 configuration.
The other peripheral modules (which require an input)
must have their data direction bit configured appropriately.
Note:A pin that is a peripheral input, can be con-
figured as an output (DDRx<y> is cleared).
The peripheral events will be determined
by the action output on the port pin.
10.1PORTA Register
PORTA is a 6-bit wide latch. PORTA does not have a
corresponding Data Direction Register (DDR).
Reading PORTA reads the status of the pins.
The RA1 pin is multiplexed with TMR0 clock input, 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 are automatically configured by the their
multiplexed peripheral module.
10.1.1USING 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 PORTA register the desired value. 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.
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 operation, 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 possibility use a shadow register for PORTA. Do the bit operations on
this shadow register and then move it to
PORTA.
FIGURE 10-1: RA0 AND RA1 BLOCK
DIAGRAM
DATA BUS
RD_PORTA
(Q2)
Note: I/O pins have protection diodes to VDD and VSS.
Example 10-1 shows an instruction sequence to initialize PORTA. The Bank Select Register (BSR) must be
selected to Bank 0 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
EXAMPLE 10-1: INITIALIZING PORTA
MOVLB 0 ; Select Bank 0
MOVLW 0xF3 ;
MOVPF PORTA ; Initialize PORTA
; RA<3:2> are output low
; RA<5:4> and RA<1:0>
; are inputs
; (outputs floating)
FIGURE 10-2: RA2 BLOCK DIAGRAM
Peripheral data in
QD
EN
Data Bus
FIGURE 10-3: RA3 BLOCK DIAGRAM
Peripheral data in
QD
EN
QD
Q
CK
“1”
SSP Mode
Note: I/O pin has protection diodes to VSS.
Data Bus
RD_PORTA
WR_PORTA
SDA out
(Q2)
(Q4)
QD
1
0
Note: I/O pin has protection diodes to VSS.
Q
CK
I2C Mode enable
RD_PORTA
WR_PORTA
(Q4)
S
CL out
(Q2)
FIGURE 10-4: RA4 AND RA5 BLOCK
DIAGRAM
Serial port input signal
RD_PORTA
Serial port output signals
= SPEN,SYNC,TXEN, CREN, SREN for RA4
OE
= SPEN (SYNC+SYNC,CSRC) for RA5
OE
Note: I/O pins have protection diodes to VDD and VSS.
Data Bus
(Q2)
DS30264A-page 66Preliminary 1997 Microchip Technology Inc.
TABLE 10-1:PORTA FUNCTIONS
PIC17C75X
NameBit0
Buffer
Type
Function
RA0/INTbit0STInput or external interrupt input.
RA1/T0CKIbit1STInput or clock input to the TMR0 timer/counter, and/or an external interrupt
input.
RA2/SS
/SCLbit2STInput/Output or slave select input for the SPI or clock input for the I2C bus.
Output is open drain type.
RA3/SDI/SDAbit3ST
Input/Output or data input for the SPI or data for the I
2
C bus.
Output is open drain type.
RA4/RX1/DT1bit4STInput/Output or USART1 Asynchronous Receive or
USART1 Synchronous Data.
RA5/TX1/CK1bit5STInput/Output or USART1 Asynchronous Transmit or
USART1 Synchronous Clock.
RBPU
bit7—Control bit for PORTB weak pull-ups.
Legend: ST = Schmitt Trigger input.
TABLE 10-2:REGISTERS/BITS ASSOCIATED WITH PORTA
Value on
all other
resets
(Note1)
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
10h, Bank 0PORTA
05h, Unbanked T0STAINTEDG T0SE
13h, Bank 0RCSTA1SPEN
15h, Bank 0TXSTA1CSRC
Legend: x = unknown, u = unchanged, - = unimplemented reads as '0'. Shaded cells are not used by PORTA.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
This interrupt can wake the device from SLEEP. The
user, in the interrupt service routine, can clear the inter-
PORTB is an 8-bit wide bi-directional port. The corresponding data direction register is DDRB. A '1' in
DDRB configures the corresponding port pin as an
input. A '0' in the DDRB register configures the corresponding port pin as an output. Reading PORTB reads
the status of the pins, whereas writing to it will write to
the port latch.
Each of the PORTB pins has a weak internal pull-up. A
single control bit can turn on all the pull-ups. This is
done by clearing the RBPU
(PORTA<7>) bit. The w eak
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 configured as an output is
excluded from the interrupt on change comparison).
The input pins (of RB7:RB0) are compared with the
rupt by:
a) Read-Write PORTB (such as; MOVPF PORTB,
PORTB). This will end 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 software configurable pull-ups on this port, allows easy
interface to a keypad and make it possible for wake-up
on key-depression. For an example, refer to Application Note AN552, “Implementing Wake-up on Keystroke.”
The interrupt on change feature is recommended for
wake-up on operations where PORTB is only used for
the interrupt on change feature and key depression
operations.
value in the PORTB data latch. The “mismatch” outputs
of RB7:RB0 are OR’ed together to set the PORTB
Interrupt Flag bit, RBIF (PIR1<7>).
FIGURE 10-5: BLOCK DIAGRAM OF RB5:RB4 AND RB1:RB0 PORT PINS
Weak
Pull-Up
Match Signal
from other
port pins
Peripheral Data in
RBPU
(PORTA<7>)
RBIF
OE
Note: I/O pins have protection diodes to VDD and VSS.
Port
Input Latch
Port
Data
Data Bus
RD_DDRB (Q2)
RD_PORTB (Q2)
D
Q
CK
D
Q
CK
WR_DDRB (Q4)
WR_PORTB (Q4)
DS30264A-page 68Preliminary 1997 Microchip Technology Inc.
PIC17C75X
Example 10-2 shows an instruction sequence to initial-
EXAMPLE 10-2: INITIALIZING PORTB
ize PORTB. The Bank Select Register (BSR) must be
selected to Bank 0 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
MOVLB0 ; Select Bank 0
CLRF PORTB ; Initialize 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
FIGURE 10-6: BLOCK DIAGRAM OF RB3:RB2 PORT PINS
Weak
Pull-Up
Port
Input Latch
Match Signal
from other
port pins
Peripheral Data in
(PORTA<7>)
RBPU
RBIF
Data Bus
RD_DDRB (Q2)
OE
Note: I/O pins have protection diodes to VDD and Vss.
Example 10-3 shows an instruction sequence to initialize PORTC. The Bank Select Register (BSR) must be
PORTC is an 8-bit bi-directional port. The corresponding data direction register is DDRC. A '1' in DDRC configures the corresponding port pin as an input. A '0' in
selected to Bank 1 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
the DDRC register configures the corresponding port
pin as an output. Reading PORTC reads the status of
the pins, whereas writing to it will write to the port latch.
PORTC is multiplexed with the system bus. When
operating as the system bus, PORTC is the low order
byte of the address/data bus (AD7:AD0). The timing for
the system bus is shown in the Electrical Characteristics section.
Note:This por t is configured as the system bus
when the device’s configuration bits are
selected to Microprocessor or Extended
EXAMPLE 10-3: INITIALIZING PORTC
MOVLB1 ; Select Bank 1
CLRFPORTC ; Initialize PORTC data
;
; the data direction register
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWFDDRC ; Set RC<3:0> as inputs
;
; RC<7:6> as inputs
Microcontroller modes. In the two other
microcontroller modes, this port is a general purpose I/O.
FIGURE 10-9: BLOCK DIAGRAM OF RC7:RC0 PORT PINS
latches before setting
RC<5:4> as outputs
to D_Bus → IR
INSTRUCTION READ
TTL
Input
Buffer
Port
0
Data
1
Note: I/O pins have protection diodes to VDD and Vss.
Data Bus
RD_PORTC
CK
CK
S
D
WR_PORTC
D
RD_DDRC
WR_DDRC
EX_EN
DATA/ADDR_OUT
DRV_SYS
SYS BUS
Control
Q
Q
R
DS30264A-page 72Preliminary 1997 Microchip Technology Inc.
TABLE 10-5:PORTC FUNCTIONS
NameBitBuffer TypeFunction
RC0/AD0bit0TTLInput/Output or system bus address/data pin.
RC1/AD1bit1TTLInput/Output or system bus address/data pin.
RC2/AD2bit2TTLInput/Output or system bus address/data pin.
RC3/AD3bit3TTLInput/Output or system bus address/data pin.
RC4/AD4bit4TTLInput/Output or system bus address/data pin.
RC5/AD5bit5TTLInput/Output or system bus address/data pin.
RC6/AD6bit6TTLInput/Output or system bus address/data pin.
RC7/AD7bit7TTLInput/Output or system bus address/data pin.
Legend: TTL = TTL input.
TABLE 10-6:REGISTERS/BITS ASSOCIATED WITH PORTC
PIC17C75X
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
11h, Bank 1 PORTC
10h, Bank 1 DDRCData direction register for PORTC1111 11111111 1111
Legend: x = unknown, u = unchanged.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
Example 10-4 shows an instruction sequence to initialize PORTD. The Bank Select Register (BSR) must be
PORTD is an 8-bit bi-directional port. The corresponding data direction register is DDRD. A '1' in DDRD configures the corresponding port pin as an input. A '0' in
selected to Bank 1 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
the DDRD register configures the corresponding port
pin as an output. Reading PORTD reads the status of
the pins, whereas writing to it will write to the port latch.
PORTD is multiplexed with the system bus. When
operating as the system bus, PORTD is the high order
byte of the address/data bus (AD15:AD8). The timing
for the system bus is shown in the Electrical Characteristics section.
Note:This por t is configured as the system bus
when the device’s configuration bits are
selected to Microprocessor or Extended
EXAMPLE 10-4: INITIALIZING PORTD
MOVLB1 ; Select Bank 1
CLRFPORTD ; Initialize PORTD data
;
; the data direction register
MOVLW 0xCF ; Value used to initialize
; data direction
MOVWFDDRD ; Set RD<3:0> as inputs
;
; RD<7:6> as inputs
latches before setting
RD<5:4> as outputs
Microcontroller modes. In the two other
microcontroller modes, this port is a general purpose I/O.
FIGURE 10-10: BLOCK DIAGRAM OF RD7:RD0 PORT PINS (IN I/O PORT MODE)
to D_Bus → IR
INSTRUCTION READ
TTL
Input
Buffer
Port
0
Data
1
Note: I/O pins have protection diodes to VDD and Vss.
Data Bus
RD_PORTD
CK
CK
S
D
WR_PORTD
D
RD_DDRD
WR_DDRD
EX_EN
DATA/ADDR_OUT
DRV_SYS
SYS BUS
Control
Q
Q
R
DS30264A-page 74Preliminary 1997 Microchip Technology Inc.
PIC17C75X
TABLE 10-7:PORTD FUNCTIONS
NameBitBuffer TypeFunction
RD0/AD8bit0TTLInput/Output or system bus address/data pin.
RD1/AD9bit1TTLInput/Output or system bus address/data pin.
RD2/AD10bit2TTLInput/Output or system bus address/data pin.
RD3/AD11bit3TTLInput/Output or system bus address/data pin.
RD4/AD12bit4TTLInput/Output or system bus address/data pin.
RD5/AD13bit5TTLInput/Output or system bus address/data pin.
RD6/AD14bit6TTLInput/Output or system bus address/data pin.
RD7/AD15bit7TTLInput/Output or system bus address/data pin.
Legend: TTL = TTL input.
TABLE 10-8:REGISTERS/BITS ASSOCIATED WITH PORTD
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
13h, Bank 1 PORTD
12h, Bank 1 DDRDData direction register for PORTD1111 11111111 1111
Legend: x = unknown, u = unchanged.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
Example 10-5 shows an instruction sequence to initialize PORTE. The Bank Select Register (BSR) must be
PORTE is a 4-bit bi-directional port. The corresponding
data direction register is DDRE. A '1' in DDRE configures the corresponding port pin as an input. A '0' in the
selected to Bank 1 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
DDRE register configures the corresponding port pin
as an output. Reading PORTE reads the status of the
pins, whereas writing to it 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
nals OE
and WR are active low signals. The timing for
), and Write (WR). The control sig-
the system bus is shown in the Electrical Characteristics section.
Note:Three pins of this por t are configured as
EXAMPLE 10-5: INITIALIZING PORTE
MOVLB1 ; Select Bank 1
CLRFPORTE ; 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'
the system bus when the device’s configuration 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 microcontroller modes, RE2:RE0 are general purpose I/O pins.
FIGURE 10-11: BLOCK DIAGRAM OF RE2:RE0 (IN I/O PORT MODE)
TTL
Input
Buffer
Port
0
Data
1
Note: I/O pins have protection diodes to VDD and Vss.
Q
Q
R
CK
CK
S
Data Bus
RD_PORTE
D
WR_PORTE
D
RD_DDRE
WR_DDRE
EX_EN
CNTL
DRV_SYS
SYS BUS
Control
DS30264A-page 76Preliminary 1997 Microchip Technology Inc.
FIGURE 10-12: BLOCK DIAGRAM OF RE3/CAP4 PORT PIN
PIC17C75X
Peripheral In
QD
EN
EN
V
DD
Data Bus
RD_PORTE
P
Port
Data
N
Note: I/O pin has protection diodes to VDD and Vss.
Q
Q
Q
Q
CK
CK
S
D
WR_PORTE
D
RD_DDRE
WR_DDRE
TABLE 10-9:PORTE FUNCTIONS
NameBitBuffer TypeFunction
RE0/ALEbit0TTLInput/Output or system bus Address Latch Enable (ALE) control pin.
RE1/OE
RE2/WR
bit2TTLInput/Output or system bus Write (WR) control pin.
RE3/CAP4bit3STInput/Output or Capture4 input pin
Legend: TTL = TTL input. ST = Schmitt Trigger input
bit1TTLInput/Output or system bus Output Enable (OE) control pin.
TABLE 10-10: REGISTERS/BITS ASSOCIATED WITH PORTE
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
15h, Bank 1 PORTE
14h, Bank 1 DDREData direction register for PORTE---- 1111---- 1111
14h, Bank 7 CA4LCapture4 low bytexxxx xxxxuuuu uuuu
15h, Bank 7 CA4HCapture4 high bytexxxx xxxxuuuu uuuu
16h, Bank 7 TCON3
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by PORTE.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
PORTF is an 8-bit wide bi-directional port. The corresponding data direction register is DDRF. A '1' in DDRF
configures the corresponding port pin as an input. A '0'
in the DDRF register configures the corresponding port
pin as an output. Reading PORTF reads the status of
the pins, whereas writing to them will write to the
respective port latch.
All eight bits of PORTF are multiplexed with 8 of the 12
channels of the 10-bit A/D converter.
Upon reset the entire Port is automatically configured
as analog inputs, and must be configured in software to
be a digital I/O.
FIGURE 10-13: BLOCK DIAGRAM OF RF7:RF0
Data bus
WR PORTF
D
Q
Q
CK
Data Latch
Example 10-6 shows an instruction sequence to initialize PORTF. The Bank Select Register (BSR) must be
selected to Bank 5 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
EXAMPLE 10-6: INITIALIZING PORTF
MOVLB 5 ; Select Bank 5
MOVLW 0x0E ; Configure PORTF as
MOVPF ADCON1 ; Digital
CLRF PORTF ; Initialize PORTF data
; latches before setting
; the data direction
; register
MOVLW 0x03 ; Value used to initialize
; data direction
MOVWF DDRF ; Set RF<1:0> as inputs
; RF<7:2> as outputs
VDD
P
WR DDRF
RD PORT
VAN
D
CK
DDRF Latch
RD DDRF
PCFG3:PCFG0
CHS3:CHS0
Q
Q
QD
EN
EN
To other pads
To other pads
N
SS
V
I/O pin
ST
input
buffer
DS30264A-page 78Preliminary 1997 Microchip Technology Inc.
Input/Output or analog input 4
Input/Output or analog input 5
Input/Output or analog input 6
Input/Output or analog input 7
Input/Output or analog input 8
Input/Output or analog input 9
Input/Output or analog input 10
Input/Output or analog input 11
Legend: ST = Schmitt Trigger input.
TABLE 10-12: REGISTERS/BITS ASSOCIATED WITH PORTF
PIC17C75X
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
10h, Bank 5 DDRFData Direction Register for PORTF1111 11111111 1111
11h, Bank 5 PORTFRF7/
AN11
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by PORTF.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
PORTG is an 8-bit wide bi-directional port. The corresponding 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 corresponding port pin as an output. Reading PORTG
reads the status of the pins, whereas writing to them
will write to the respective port latch.
The lower four bits of POR TG are m ultiplexed with f our
of the 12 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 the entire Port is automatically configured
as analog inputs, and must be configured in software
to be a digital I/O.
FIGURE 10-14: BLOCK DIAGRAM OF RG3:RG0
Data bus
WR PORTG
D
Q
Q
CK
Data Latch
Example 10-7 shows the instruction sequence to initialize PORTG. The Bank Select Register (BSR) must be
selected to Bank 5 for the port to be initialized. The following example uses the MOVLB instruction to load the
BSR register for bank selection.
EXAMPLE 10-7: INITIALIZING PORTG
MOVLB 5 ; Select Bank 5
MOVLW 0x0E ; Configure PORTG as
MOVPF ADCON1 ; digital
CLRF PORTG ; Initialize PORTG data
; latches before setting
; the data direction
; register
MOVLW 0x03 ; Value used to initialize
; data direction
MOVWF DDRG ; Set RG<1:0> as inputs
; RG<7:2> as outputs
VDD
P
WR DDRG
RD PORT
VAN
D
CK
DDRG Latch
RD DDRG
PCFG3:PCFG0
CHS3:CHS0
Q
Q
QD
EN
EN
To other pads
To other pads
N
SS
V
I/O pin
ST
input
buffer
DS30264A-page 80Preliminary 1997 Microchip Technology Inc.
FIGURE 10-15: RG4 BLOCK DIAGRAM
PIC17C75X
Peripheral Data In
Q
D
EN
EN
VDD
P
N
Note: I/O pin has protection diodes to VDD and Vss.
Q
Q
Q
D
CK
D
CK
FIGURE 10-16: RG7:RG5 BLOCK DIAGRAM
QD
Data Bus
RD_PORTG
WR_PORTG
RD_DDRG
WR_DDRG
Peripheral Data In
Data Bus
N
V
DD
P
Port
Data
1
0
N
Note: I/O pins have protection diodes to VDD and Vss.
Input/Output or analog input 3.
Input/Output or analog input 2.
Input/Output or analog input 1 or the ground reference voltage
Input/Output or analog input 0 or the positive reference voltage
RG4 can also be the Capture3 input pin.
RG5 can also be the PWM3 output pin.
RG6 can also be selected as the USART2 (SCI) Asynchronous
Receive or USART2 (SCI) Synchronous Data.
RG7 can also be selected as the USART2 (SCI) Asynchronous Trans-
mit or USART2 (SCI) Synchronous Clock.
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
12h, Bank 5 DDRGData Direction Register for PORTG1111 11111111 1111
13h, Bank 5 PORTGRG7/
TX2/CK2
Legend: x = unknown, u = unchanged, - = unimplemented read as '0'. Shaded cells are not used by PORTG.
Note 1: Other (non power-up) resets include: external reset through MCLR and the Watchdog Timer Reset.
RG6/
RX2/DT2
RG5/
PWM3
RG4/
CAP3
RG3/
AN0
RG2/
AN1
RG1/
AN2
RG0/
AN3
Value on,
POR,
BOR
xxxx 0000uuuu 0000
Value on all
other resets
(Note1)
DS30264A-page 82Preliminary 1997 Microchip Technology Inc.
PIC17C75X
10.8I/O Programming Considerations
10.8.1BI-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 these
instructions are applied to a port with both inputs and
outputs defined. For example, a BSF operation on bit5
of PORTB will cause all eight bits of PORTB to be read
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 signal present on the pin itself would be read into
the CPU and re-written to the data latch of this particular pin, overwriting the previous content. As long as the
pin stays in the input mode, no problem occurs. However, if bit0 is switched into output mode later on, the
content of the data latch may now be unknown.
Reading a port reads the values of the por t pins. Writing
to the port register writes the value to the port latch.
When using read-modify-write instructions (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-8 shows the effect of two sequential
read-modify-write instructions on an I/O port.
EXAMPLE 10-8: 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 change the level on this pin (i.e.
“wired-or”, “wired-and”). The resulting high
output currents may damage the device.
10.8.2SUCCESSIVE OPERATIONS ON I/O P ORTS
The actual write to an I/O port happens at the end of an
instruction cycle, whereas for reading, the data must be
valid at the beginning of the instruction cycle
(Figure 10-17). 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 dependent) before executing the instruction that reads the
values on that I/O port. Otherwise, the pre vious state of
that pin may be read into the CPU rather than the “ne w”
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-17: SUCCESSIVE I/O OPERATION
Note:
Q3
PC + 3
NOP
NOPMOVF PORTB,W
Q4
This example shows a write to PORTB
followed by a read from PORTB.
Note that:
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.
DS30264A-page 84Preliminary 1997 Microchip Technology Inc.
PIC17C75X
11.0OVERVIEW OF TIMER
RESOURCES
The PIC17C75X has four timer modules. Each module
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 Captures and three Pulse Width Modulation (PWM) outputs are possible. The PWMs use the Timer1 and
Timer2 resources and the input Captures use the
Timer3 resource.
11.1Timer0 Overview
The Timer0 module is a simple 16-bit ov erflo w 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 prescaler. The PS3:PS0 bits (T0STA<4:1>) determine the
prescale value. TMR0 can increment at the following
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 then the device’s frequency. The maximum external frequency, on the
T0CKI pin, is 50 MHz, given the high and low time
requirements of the clock.
11.3Timer2 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 set, and an interrupt will 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 concatenated 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
corresponding 16-bit period register (PR2:PR1). When
the TMR2:TMR1 value rolls over from the period
match value to 0h, the TMR1IF flag is set, and an
interrupt will be generated if enabled.
11.4Timer3 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 TMR3IF 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 mode, the period
registers become the second (of four) 16-bit capture
registers.
11.5Role of the Timer/Counters
The timer modules are general purpose, but have dedicated 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.
11.2Timer1 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 set, and an interrupt will be generated if
enabled. In counter mode, the clock comes from the
RB4/TCLK12 pin, which can also be selected to be the
clock 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
corresponding 16-bit period register (PR2:PR1). When
the TMR2:TMR1 value rolls over from the period
match value to 0h, the TMR1IF flag is set, and an
interrupt will be generated if enabled.
DS30264A-page 86Preliminary 1997 Microchip Technology Inc.
12.0TIMER0
The Timer0 module consists of a 16-bit timer/counter,
TMR0. The high byte is register TMR0H and the low
byte is register TMR0L. A software programmable 8-bit
prescaler makes Timer0 an effective 24-bit overflow
timer. The clock source is software programmable as
either the internal instruction clock or an external clock
on the RA1/T0CKI pin. The control bits for this module
are in register T0STA (Figure 12-1).
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 generates a T0CKIF interrupt
0 =Falling edge of RA1/T0CKI pin increments TMR0 and/or generates a T0CKIF interrupt
When
T0CS = 1 (Internal Clock)
Don’t care
bit 5:T0CS: Timer0 Clock Source Select bit
This bit selects the clock source for TMR0.
1 =Internal instruction clock cycle (T
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.
CY)
—
PIC17C75X
R = Readable bit
W = Writable bit
U = Unimplemented,
Read as '0'
When the T0CS (T0STA<5>) bit is set, TMR0 increments on the internal clock. When T0CS is clear, TMR0
increments on the external clock (RA1/T0CKI pin). The
external clock edge can be selected in software. When
the T0SE (T0STA<6>) bit is set, the timer will increment
on the rising edge of the RA1/T0CKI pin. When T0SE
is clear, the timer will increment on the falling edge of
the RA1/T0CKI pin. The prescaler can be programmed
12.2Using Timer0 with External Clock
When an external clock input is used for Timer0, it is
synchronized with the internal phase clocks.
Figure 12-3 shows the synchronization of the external
clock. This synchronization is done after the prescaler.
The output of the prescaler (PSOUT) is sampled twice
in every instruction cycle to detect a rising or a falling
edge. The timing requirements for the external clock
are detailed in the electrical specification section.
to introduce a prescale of 1:1 to 1:256. The timer increments 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 corresponding TMR0 Interrupt Enable bit (T0IE). The
TMR0 Interrupt Flag bit (T0IF) is automatically cleared
when vectoring to the TMR0 interrupt vector.
12.2.1DELAY 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-3 shows that this delay is
between 3T
suring the interval between two edges (e.g. period) will
be accurate within ±4T
FIGURE 12-2: TIMER0 MODULE BLOCK DIAGRAM
Prescaler
(8 stage
async ripple
counter)
4
T0PS3:T0PS0
(T0STA<4:1>)
PSOUT
RA1/T0CKI
T0SE
(T0STA<6>)
Fosc/4
(T0STA<5>)
0
1
T0CS
OSC and 7TOSC. Thus, for example, mea-
Synchronization
Q2Q4
OSC (±121 ns @ 33 MHz).
Interrupt on overflow
sets T0IF
(INTST A<5>)
TMR0H<8> TMR0L<8>
FIGURE 12-3: TMR0 TIMING WITH EXTERNAL CLOCK (INCREMENT ON FALLING EDGE)
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
(note 1)
T0T0 + 1T0 + 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 3)
(note 2)
DS30264A-page 88Preliminary 1997 Microchip Technology Inc.
PIC17C75X
12.3Read/Write Consideration for TMR0
Although TMR0 is a 16-bit timer/counter, only 8-bits at
a time can be read or written during a single instruction
cycle. Care must be taken during any read or write.
12.3.1READING 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.
Example 12-1 shows a 16-bit read. To ensure a proper
read, interrupts must be disabled during this routine.
12.3.2WRITING A 16-BIT VALUE TO TMR0
Since writing to either TMR0L or TMR0H will eff ectiv ely
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 disabled. Any write to either TMR0L or TMR0H clears the
prescaler.
Timer0 has an 8-bit prescaler. The prescaler assignment is fully under software control; i.e., it can be
changed “on the fly” during program execution. When
changing the prescaler assignment, clearing the prescaler is recommended before changing assignment.
The value of the prescaler is “unknown,” and assigning
a value that is less then the present value makes it difficult to take this unknown time into account.
Legend:x = unknown, u = unchanged, - = unimplemented read as a '0', q - value depends on condition, Shaded cells are not used by Timer0.
Note 1:Other (non power-up) resets include: external reset through MCLR
DS30264A-page 90Preliminary 1997 Microchip Technology Inc.
PIC17C75X
13.0TIMER1, TIMER2, TIMER3,
PWMS AND CAPTURES
The PIC17C75X has a wealth of timers and time-based
functions to ease the implementation of control applications. 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
respectively) and separate overflow interrupt flags.
Timer1 and Timer2 can operate either as timers (increment on internal 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
Width Modulation) modules.
Timer3 is a 16-bit timer/counter which uses the TMR3H
and TMR3L registers. Timer3 also has two additional
registers (PR3H/CA1H: PR3L/CA1L) that are configurable as a 16-bit period register or a 16-bit capture
register. TMR3 can be software configured to increment from the internal system clock (F
an external signal on the RB5/TCLK3 pin. Timer3 is the
time-base for all of the 16-bit captures.
OSC/4) or from
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 control 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
Time-base FunctionTimer Resource
PWM1Timer1
PWM2Timer1 or Timer2
PWM3Timer1 or Timer2
Capture1Timer3
Capture2Timer3
Capture3Timer3
Capture4Timer3
FIGURE 13-1: TCON1 REGISTER (ADDRESS: 16h, BANK 3)
bit7bit0
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 e vent 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 indicates that the capture value had not been read from the capture register pair
(PR3H/CA1H:PR3L/CA1L) 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 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
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 Timer3
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
1 =Starts 16-bit TMR2:TMR1
0 =Stops 16-bit TMR2:TMR1
: CA1/PR3 Register Mode Select bit
T16 is set (in 16-bit Timer Mode)
TMR3ON TMR2ON TMR1ON
R = Readable bit
W = Writable bit
-n = Value at POR reset
When
T16 is clear (in 8-bit Timer Mode)
1 =Starts 8-bit Timer1
0 =Stops 8-bit Timer1
DS30264A-page 92Preliminary 1997 Microchip Technology Inc.
FIGURE 13-3: TCON3 REGISTER (ADDRESS: 16h, BANK 7)
U-0R - 0R - 0R/W - 0R/W - 0R/W - 0R/W - 0R/W - 0
-CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON
bit7bit0
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)
PIC17C75X
R = Readable bit
W = Writable bit
U = Unimplemented bit,
Reads as ‘0’
13.1.1TIMER1, 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 independently configured to increment from the internal
instruction cycle clock (T
source on the RB4/TCLK12 pin. The timer cloc k source
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 instruction 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 timer increments from 00h until it equals the Period
register (PRx). It then resets to 00h at the next increment cycle. The timer interrupt flag is set when the
timer is reset. TMR1 and TMR2 have individual interrupt flag bits. The TMR1 interrupt flag bit is latched into
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 timer on control 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.
CY) or from an external clock
13.1.1.1EXTERNAL 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 delay from the time a f alling edge
appears on TCLK12 to the time TMR1 or TMR2 is actually incremented. For the external clock input timing
requirements, see the Electrical Specification section.
FIGURE 13-4: TIMER1 AND TIMER2 IN TWO 8-BIT TIMER/COUNTER MODE
Fosc/4
RB4/TCLK12
Fosc/4
0
1
TMR1ON
(TCON2<0>)
TMR1CS
(TCON1<0>)
1
0
TMR2ON
(TCON2<1>)
TMR2CS
(TCON1<1>)
TMR1
Comparator<8>Comparator x8
PR1
TMR2
Comparator<8>Comparator x8
PR2
Reset
Set TMR1IF
(PIR1<4>)
Equal
Reset
Set TMR2IF
(PIR1<5>)
Equal
DS30264A-page 94Preliminary 1997 Microchip Technology Inc.
PIC17C75X
13.1.2TIMER1 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 matches the 16-bit period register (PR2:PR1). On
the following timer clock, the timer value is reset to 0h,
and the TMR1IF bit is set.
When selecting the clock source for the16-bit timer , the
TMR1CS bit controls the entire 16-bit timer and
TMR2CS is a “don’t 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
T16 TMR2ON TMR1ONResult
11116-bit timer
(TMR2:TMR1) ON
101Only TMR1 increments
1x016-bit timer OFF
011Timers in 8-bit mode
13.1.2.1EXTERNAL CLOCK INPUT FOR
TMR2:TMR1
When TMR1CS is set, the 16-bit TMR2:TMR1 increments on the falling edge of clock input TCLK12. The
input on the RB4/TCLK12 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 RB4/TCLK12 to the time
TMR2:TMR1 is actually incremented. For the external
clock input timing requirements, see the Electrical
Specification section.
FIGURE 13-5: TMR2 AND TMR1 IN 16-BIT TIMER/COUNTER MODE
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
16h, Bank 3TCON1
17h, Bank 3TCON2
16h, Bank 7TCON3—CA4OVF CA3OVF CA4ED1 CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
10h, Bank 2TMR1Timer1’s registerxxxx xxxx uuuu uuuu
11h, Bank 2TMR2Timer2’s registerxxxx xxxx uuuu uuuu
16h, Bank 1PIR1
17h, Bank 1PIE1
07h, Unbanked INTSTAPEIF
06h, Unbanked CPUSTA——STKAVGLINTDTOPDPORBOR--11 1100 --11 qq11
14h, Bank 2PR1Timer1 period registerxxxx xxxx uuuu uuuu
15h, Bank 2PR2Timer2 period registerxxxx xxxx uuuu uuuu
10h, Bank 3PW1DCLDC1DC0
11h, Bank 3PW2DCLDC1DC0TM2PW2
10h, Bank 7PW3DCLDC1DC0TM2PW3
12h, Bank 3PW1DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx xxxx uuuu uuuu
13h, Bank 3PW2DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx xxxx uuuu uuuu
11h, Bank 7PW3DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx 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.
Note 1: Other (non power-up) resets include: external reset through MCLR
and WDT Timer Reset.
DS30264A-page 96Preliminary 1997 Microchip Technology Inc.
PIC17C75X
13.1.3USING PULSE WIDTH MODULATION
(PWM) OUTPUTS WITH TIMER1 AND
TIMER2
Three high speed pulse width modulation (PWM) outputs are provided. The PWM1 output uses Timer1 as
its time-base, while PWM2 and PWM3 may independently be software configured to use either Timer1 or
Timer2 as the time-base. The PWM outputs are on the
RB2/PWM1, RB3/PWM2, 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 output frequency is 128.9 kHz. The duty cycle of
the output can vary from 0% to 100%.
Figure 13-6 shows a simplified block diagram of a
PWM module.
The duty cycle registers are double buffered for glitch
free operation. Figure 13-7 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 direction bit (DDRB<2>). When the PWM1ON bit is clear,
the pin behaves as a port pin and its direction is controlled by its data direction bit (DDRB<2>). Similarly,
the PWM2ON (TCON2<5>) bit controls the configuration of the RB3/PWM2 pin and the PWM3ON
(TCON3<0>) bit controls the configuration of the
RG5/PWM3 pin.
FIGURE 13-6: SIMPLIFIED PWM BLOCK
DIAGRAM
Duty Cycle registers
PWxDCH
(Slave)
Comparator
TMRx
Comparator
PRy
(Note 1)
Clear Timer,
PWMx pin and
Latch D.C.
PWxDCL<7:6>
Write
Read
PWMx
RSQ
PWMxON
Note 1: 8-bit timer is concatenated with 2-bit internal Q clock
or 2 bits of the prescaler to create 10-bit time-base.
FIGURE 13-7: PWM OUTPUT
010203040 0
PWM
output
Timer
interrupt
Note 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.
Write new
PWM value
Timer interrupt
new PWM value
transferred to slave
13.1.3.1PWM PERIODS
The period of the PWM1 output is determined by
Timer1 and its period register (PR1). The period of the
PWM2 and PWM3 outputs can be individually software
configured to use either Timer1 or Timer2 as the
time-base. For PWM2, when TM2PW2 bit
(PW2DCL<5>) is clear, the time-base is determined by
TMR1 and PR1, and when TM2PW2 is set, the
time-base is determined by Timer2 and PR2. For
PWM3, when TM2PW3 bit (PW3DCL<5>) is clear, the
time-base is determined by 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 Timer1 allows the best use of resources b y
freeing Timer2 to operate as an 8-bit timer. Timer1 and
Timer2 can not 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 4T
period of PWM2 = [(PR1) + 1] x 4TOSC or
[(PR2) + 1] x 4T
period of PWM3 = [(PR1) + 1] x 4TOSC or
[(PR2) + 1] x 4T
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 from PWxDCL<7:6>
(PWxDCH:PWxDCL<7:6>). Table 13-4 shows the
maximum PWM frequency (F
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 (F
Maximum PWM resolution (bits) for a given PWM frequency:
log
(
PWM) given the value in
OSC
F
FPWM
=
log (2)
where: F
The PWMx duty cycle is as follows:
where DCx represents the 10-bit value from
PWxDCH:PWxDCL.
PWM = 1 / period of PWM
PWMx Duty Cycle =(DCx) x T
OSC
OSC
OSC
PWM).
)
bits
OSC
If DCx = 0, then the duty cycle is zero. If PRx =
PWxDCH, then the PWM output will be low for one to
four Q-clock (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 value.
The duty cycle registers for both PWM outputs are double 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 latch values are transferred to the sla v e latches
and the PWMx pin is forced high.
Note:For PW1DCH, PW1DCL, PW2DCH,
PW2DCL, PW3DCH and PW3DCL registers, a write operation writes 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.
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:PWM FREQUENCY vs.
RESOLUTION AT 33 MHz
PWM
Frequency
PRx Value0xFF0x7F 0x5A0x3F0x0F
High
Resolution
Standard
Resolution
13.1.3.2PWM INTERRUPTS
The PWM modules makes 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
roll-over. The TMR1 interrupt is latched into the
TMR1IF bit and the TMR2 interrupt is latched into the
TMR2IF bit. These flags must be cleared in software.
32.264.590.66128.9515.6
10-bit 9-bit 8.5-bit8-bit6-bit
8-bit7-bit 6.5-bit6-bit4-bit
Frequency (kHz)
DS30264A-page 98Preliminary 1997 Microchip Technology Inc.
PIC17C75X
13.1.3.3EXTERNAL CLOCK SOURCE
13.1.3.3.1 MAX RESOLUTION/FREQUENCY FOR
EXTERNAL CLOCK INPUT
The PWMs will operate regardless of the clock source
of the timer. The use of an external clock has ramifications that must be understood. Because the external
TCLK12 input is synchronized internally (sampled once
per instruction cycle), the time TCLK12 changes to the
time the timer increments will vary by as much as 1T
CY
(one instruction cycle). This will cause jitter in the duty
cycle as well as the period of the PWM output.
This jitter will be ±1T
CY, unless the external clock is
synchronized with the processor clock. Use of one of
the PWM outputs as the clock source to the TCLK12
input, will supply a synchronized clock.
The use of an external clock for the PWM time-base
(Timer1 or Timer2) limits the PWM output to a maximum resolution of 8-bits. The PWxDCL<7:6> bits must
be kept cleared. Use of any other value will distort the
PWM output. All resolutions are supported when internal clock mode is selected. The maximum attainable
frequency is also lower. This is a result of the timing
requirements of an external clock input for a timer (see
the Electrical Specification section). The maximum
PWM frequency, when the timers clock source is the
RB4/TCLK12 pin, as shown in Table 13-4 (standard
resolution mode).
In general, when using an external clock source for
PWM, its frequency should be much less than the
device frequency (Fosc).
TABLE 13-5:REGISTERS/BITS ASSOCIATED WITH PWM
AddressNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2 Bit 1Bit 0
16h, Bank 3TCON1
17h, Bank 3TCON2CA2OVF CA1OVF PWM2ON PWM1ON CA1/PR3 TMR3ON TMR2ON TMR1ON 0000 0000 0000 0000
16h, Bank 7TCON3—CA4OVFCA3OVFCA4ED1CA4ED0 CA3ED1 CA3ED0 PWM3ON -000 0000 -000 0000
10h, Bank 2TMR1Timer1’s registerxxxx xxxx uuuu uuuu
11h, Bank 2TMR2Timer2’s registerxxxx xxxx uuuu uuuu
16h, Bank 1PIR1
17h, Bank 1PIE1
07h, Unbanked INTSTAPEIF
06h, Unbanked CPUSTA——STKAVGLINTDTOPDPORBOR--11 1100 --11 qq11
14h, Bank 2PR1Timer1 period registerxxxx xxxx uuuu uuuu
15h, Bank 2PR2Timer2 period registerxxxx xxxx uuuu uuuu
10h, Bank 3PW1DCLDC1DC0
11h, Bank 3PW2DCLDC1DC0TM2PW2
10h, Bank 7PW3DCLDC1DC0TM2PW3
12h, Bank 3PW1DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx xxxx uuuu uuuu
13h, Bank 3PW2DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx xxxx uuuu uuuu
11h, Bank 7PW3DCHDC9DC8DC7DC6DC5DC4DC3DC2xxxx xxxx uuuu uuuu
(RB0/CAP1, RB1/CAP2, RG4/CAP3, and RE3/CAP4),
one for each capture register pair . The capture pins are
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 associated 16-bit period register (PR3H/CA1H:PR3L/CA1L).
This period register can be software configured 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 is set, the counter increments on every falling
edge of the RB5/TCLK3 pin. In either mode, the
TMR3ON bit must be set for the timer/counter to increment. When TMR3ON is clear, the timer will not increment 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 capture register mode
The PIC17C75X has up to four 16-bit capture registers
that capture the 16-bit value of TMR3 when events are
detected on capture pins. There are four capture pins
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-bit capture register has an interrupt flag asso-
ciated with it. The flag is set when a capture is made.
The capture modules are truly part of the Timer3 block.
Figure 13-8 and Figure 13-9 show the block diagrams
for the two modes of operation.
13.2.1THREE 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-8. 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-8: TIMER3 WITH THREE CAPTURE AND ONE PERIOD REGISTER BLOCK DIAGRAM
RB5/TCLK3
RB1/CAP2
RG4/CAP3
RE3/CAP4
TMR3CS
(TCON1<2>)
Fosc/4
Edge select,
Prescaler select
2
CA2ED1: CA2ED0
(TCON1<7:6>)
Edge select,
Prescaler select
2
CA3ED1: CA3ED0
(TCON3<2:1>)
Edge select,
Prescaler select
2
CA4ED1: CA4ED0
(TCON3<4:3>)
0
1
TMR3ON
(TCON2<2>)
Set CA2IF
(PIR1<3>)
Set CA3IF
(PIR2<2>)
Set CA4IF
(PIR2<3>)
PR3H/CA1H
TMR3H
Capture2
Enable
CA2HCA2L
Capture3
Enable
CA3HCA3L
Capture4
Enable
CA4HCA4L
PR3L/CA1L
Comparator<8>
Comparator x16
TMR3L
Set TMR3IF
(PIR1<6>)
Equal
Reset
DS30264A-page 100Preliminary 1997 Microchip Technology Inc.
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.