Note the following details of the code protection feature on PICmicro® MCUs.
•The PICmicro family meets the specifications contained in the Microchip Data Sheet.
•Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today,
when used in the intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.
The person doing so may be engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable”.
•Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of
our product.
If you have any further questions about this matter, please contact the local sales office nearest to you.
Information contained in this publication regarding device
applications and the like is intended through suggestion only
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect
to the accuracy or use of such information, or infringement of
patents or other intellectual property rights arising from such
use or otherwise. Use of Microchip’s products as critical components in life support systems is not authorized except with
express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, PIC, PICmicro,
PICMASTER, PICSTART, PRO MATE, K
EELOQ, SEEVAL,
MPLAB and The Embedded Control Solutions Company are registered tradem arks of Micr ochip Technology Incorporated in the
U.S.A. and other countries.
Total Endurance, ICSP, In-Circuit Serial Programming, FilterLab, MXDEV, microID, FlexROM, fuzzyLAB, MPASM,
MPLINK, MPLIB, PICC, PICDEM, PICDEM.net, ICEPIC,
Migratable Memory, FanSense, ECONOMONITOR, Select
Mode and microPort are trademarks of Microchip Technology
Incorporated in the U.S.A.
Serialized Quick T erm Programming (SQTP) is a service mark
of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received QS-9000 quality system
certification for its worldwide headquarters,
design and wafer fabrication facilities in
Chandler and Tempe, Arizona in July 1999. The
Company’s quality system processes and
procedures are QS-9000 compliant for its
PICmicro
devices, Serial EEPROMs and microperipheral
products. In addition, Microchip’s quality
system for the design and manufacture of
development systems is ISO 9001 certified.
®
8-bit MCUs, KEELOQ
®
code hoppin g
DS41171A - page iiPreliminary 2001 Microchip Technology Inc.
PIC16C781/782
8-Bit CMOS Microcontrollers with A/D, D/A, OPAMP,
Comparators and PSMC
Microcontroller Core Features:
• High performance RISC CPU
• Only 35 single word instructions to learn
• All single cycle instructions except for program
branches which are two cycle
• Direct, indirect and relative addressing modes
- Operating speed: DC - 20 MHz clock input
DC - 200 ns instruction cycle
Program
Device
Memory
X14
PIC16C7811K128
PIC16C7822K128
• 8-level deep hardware stack
• Interrupt capability (up to 8 internal/external
interrupt sources)
• 16 I/O pins:
- Individual direction control (13 pins)
- Input only (3 pins), low leakage (2 pins)
- Digital/Analog inputs (8 pins)
• Programmable PORTB interrupt-on-change (8 pins)
• Programmable PORTB weak pull-ups (8 pins)
• Power-on Reset (POR)
• Power-up Timer (PWRT) and
Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with a software enabled
option and its own on-chip RC oscillator for
reliable operation
• Programmable Brown-out Reset (BOR)
• Programmable Low Voltage Detection (LVD)
• Internal/external MCLR
• Programmable code protection
• Power saving SLEEP mode
• Selectable oscillator options:
HS, XT, LP, EC, RC, INTRC (4 MHz/37 kHz)
• In-Circuit Serial Programming™ (ISCP™)
• Program Memory Read (PMR) capability
• Four user programmable ID locations
• Wide operating voltage range:
- 2.5V to 5.5V for commercial and industrial
temperature ranges
- Extended temperature range available
Data Memory
X8
Microcontroller Core Features (Continued):
• Low power, high speed CMOS EPROM
technology
• Fully static design
• Low power consumption:
- < 2mA @ 5V, 4MHz
-< 1 µA typical standby current.
Pin Diagram
PDIP, Windowed CERDIP, SOIC, SSOP
RA0/AN0/OPA+
RA1/AN1/OPA-
RA4/T0CKI
RA5/MCLR
RA2/AN2/VREF2
RA3/AN3/V
RB0/INT/AN4/V
RB1/AN5/VDAC
/VPP
VSS
AVSS
REF1
R
20
•1
1
PIC16C781/782
2
2
3
3 4
4
5
5
6
6
7
7
8
8
9
910
10
RB3/AN7/OPA
20
RB2/AN6
19
19
RA7/OSC1/CLKIN
18
18
RA6/OSC2/CLKOUT/T1CKI
17
17
16
16
15
15
14
14
13
13
12
1211
11
DD
V
AVDD
RB7/C2/PSMC1B/T1G
RB6/C1/PSMC1A
RB5
RB4
Peripheral Features:
• Timer0: 8-bit timer/counter with 8-bit prescaler
• Enhanced Timer1:
- 16-bit timer/counter with prescaler
- External Gate Input mode
- Option to use OSC1 and OSC2 in LP mode
as Timer1 osci llator, if INTRC oscillator m ode
selected
6.0Timer1 Module with Gate Control .............................................................................................................................................. 55
7.0Voltage Reference Module (V
8.0Programmable Low Voltage Detect Module (PLVD) ................................................................................................................. 63
13.0 Programmable Switch Mode Contr o lle r (PSMC) ............ .................................. .................................. ....................................... 99
14.0 Special Features of The CPU ....................................... .................................. ......................................................................... 117
15.0 Instruction Set Summary ......................................................................................................................................................... 133
16.0 Development Support .............................................................................................................................................................. 141
18.0 DC and AC Characteristics Graphs and Tables ...................................................................................................................... 167
19.0 Packaging Information ................... ................. ................ ................. ........................................................................................ 169
Index ..................................................................................................................................................................................................175
It is our intention to provide our valued customers with the best documentation possible to ensure successful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or c omm ents regarding th is publication, p lease c ontact the M a rketing Communications Department via
E-mail at docerrors@mail.microchip.com or fax the Reader Response Form in the back of this data sheet to (480) 792-4150.
We welcome your feedback.
Most Current Data Sheet
To obtain the most up-to-date version of this data sheet, please register at our Worldwide Web site at:
http://www.microchip.com
You can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page.
The last character of the literature number is the version number, (e.g., DS30000A is version A of document DS30000).
Errata
An errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for current
devices. As device/documentation issues become known to us, we will publish an errata sheet. The errata will specify the revision
of silicon and revision of document to which it applies.
To determine if an errata sheet exists for a particular device, please check with one of the following:
• Microchip’s Worldwide Web site; http://www.microchip.com
• Your local Microchip sales office (see last page)
• The Microchip Corporate Literature Center; U.S. FAX: (480) 792-7277
When contacting a sales office or the literature center, please specify which device, revision of silicon and data sheet (include literature number) you are using.
Customer Notification System
Register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
DS41171A-page 4Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
1.0DEVICE OVERVIEW
This document contains device-specific information.
Additional information m ay be found in the PICm ic ro™
Mid-Range Reference Manual (DS33023), which may
be obtained from your local Microchip Sales Representative or downloaded from the Microchip website. The
Reference manual should be considered a complementary document to this data sheet. The Reference
FIGURE 1-1: PIC16C781 BLOCK DIAGRAM
Program
Bus
OSC1/
CLKIN
OSC2/
CLKOUT
EPROM
Program
Memory
1K x 14
14
Instruction reg
Instruction
Decode &
Control
Timing
Generation
Internal
RC
Oscillator
INTRC
13
Program Counter
8 Level Stack
(13-bit)
Program Memory
Read (PMR)
Direct Addr
8
Power-up
Timer
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Reset
7
Data Bus
RAM
File
Registers
128 x 8
RAM
Addr
Addr MUX
3
ALU
8
W reg
Timer1
(TMR1)
Voltage Reference
(VR) Module
manual is highly recommended reading for a better
understanding o f the d ev ic e arc hi tec ture a nd operation
of the peripheral modules.
This data sheet covers two devices: PIC16C781 and
PIC16C782. Both devices come in a variety of 20-pin
packages.
The following figures are block diagrams of the
PIC16C781 and the PIC16C782.
DS41171A-page 10Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
2.0MEMORY ORGANIZATION
There are two memory blocks in each of these
PICmicro
data memory) has its own bus, so that concurrent
access can occur.
Additional informa tion on devi ce memory may be found
in the PICmicro™ Mid-Range Reference Manual,
(DS33023).
2.1Program Memory Organization
The PIC16C781/782 devices have a 13-bit program
counter capable of addressing an 8K x 14 program
memory space. The PIC16C781 has 1K x 14 words of
program memo ry. The PIC16C 782 has 2K x 14 w ords
of program memory. Accessing a location above the
physically i mplemented addr ess ca uses a wrap aroun d.
The RESET vector is at 0000h and the interrupt vector
is at 0004h.
FIGURE 2-1:PIC16C781 PROGRAM
®
microcontrollers. Each block (program and
MEMORY MAP AND
STACK
PC<12:0>
FIGURE 2-2:PIC16C782 PROGRAM
MEMORY MAP AND
STACK
PC<12:0>
CALL, RETURN
RETFIE, RETLW
On-Chip
Program
Memory
Stac k Lev el 1
Stack Level 2
Stack Level 8
RESET Vector
Interrupt Vector
Page 0
13
0000h
0004h
0005h
07FFh
0800h
CALL, RETURN
RETFIE, RETLW
On-Chip
Program
Memory
13
Stack Level 1
Stack Le vel 2
Stac k Lev el 8
RESET Vector
Interrupt Vector
Page 0
0000h
0004h
0005h
03FFh
0400h
1FFFh
1FFFh
2.2Data Memory Organization
The data memory is partitioned into multiple banks,
which contain the General Purpose Registers and the
Special Function Registers. Bits RP0 and RP1 are
bank select bits.
Each bank extends up to 7Fh (128 bytes). The lower
locations of each bank are reserved for the Special
Function Registers. Above the Special Function Registers are th e Genera l Purpos e Regist ers, im plement ed
as static RAM. All implemented banks contain Special
Function Registers. Some frequently used Special
Function Registers from one bank are mirrored in
another bank for code reduction and quicker access.
DS41171A-page 12Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
2.2.1GENERAL PURPOSE REGISTER
FILE
The register file can be acces sed either directly, or indirectly, through the File Select Register (FSR).
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registers are registers used by
the CPU and Peripheral Modules for controlling the
desired operation of the device. These registers are
implemented as static RAM. A list of these registers is
given in Table 2-1.
TABLE 2-1:PIC16C781/782 SPECIAL FUNCTION REGISTER SUMMARY
04h
05hPORTARA7RA6RA5RA4RA3RA2RA1RA0
06hPORTBRB7RB6RB5RB4RB3RB2RB1RB0
07h—Unimplemented——
08h—Unimplemented——
09h—Unimplemented——
0Ah
0Bh
0ChPIR1LVDIFADIFC2IFC1IF
0Dh—Un implemented——
0EhTMR1LHolding register for the Least Significant Byte of the 16-bit TMR1 Register
0FhTMR1HHolding register for the Most Significant Byte of the 16-bit TMR1 Register
84h
85hTRISAPORTA Data Direction Register
86hTRISBPORTB Data Direction Register
87h—Unimplemented——
88h—Unimplemented——
89h—Unimplemented——
8Ah
8Bh
8ChPIE1LVDIEADIEC2IEC1IE
8Dh—Un implemented
Note 1: The upper byte of the program counter is not directly accessible. PCLATH is a holding register for the PC<12:8> whose contents are trans-
INDFAddressing this location uses contents of FSR to address data memory (not a physical register) 0000 000023
(2)
PCLProgram Counter’s (PC) Least Significant Byte0000 000023
(2)
STATUSIRPRP1RP0TOPDZDCC0001 1xxx17
(2)
FSRIndirect Data Memory Address Pointerxxxx xxxx23
(1,2)
PCLATH———Write Buffer for the upper 5 bits of the Program Counter---0 000023
(2)
INTCONGIEPEIET0IEINTERBIET0IFINTFRBIF0000 000x19
Reserved——————RD1--- ---047
x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0'.
Shaded locations are unimplemented, read as ‘0’.
ferred to the upper byte of the program counter. See Section 2.9 for more detail.
2: These registers can be addressed from any bank.
INTEDGT0CST0SEPSAPS2PS1PS01111 111118
Value on:
POR, BOR
1111 111135
Details on
Page:
DS41171A-page 16Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
2.3STATUS Register
The STATUS register, shown in Register 2-1, contains
the arithmetic st atus of th e ALU, the RE SET statu s and
the bank select bits for data memory.
The STATUS register can be the destination for any
instruction, as with any other register. If the STATUS
register is the destination for an instruction that affects
the Z, DC, or C bits, the write to these three bits is disabled. These bits are set or cleared according to the
device logic. The TO
Therefore, the result of an instruction with the STATUS
register as the destination may be different than
intended.
and PD bits are not writable.
For example, CLRF STATUS cle ars the upper thr ee bit s
and sets the Z bit. This leaves the STA T US register a s
000u u1uu (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
STATUS register, since these instructions do not affect
the Z, C, or DC bits fro m the ST A TUS registe r. Fo r other
instructions not affecting any status bits, see the
"Instruction Set Summary."
Note:The C and DC bits operate as a borrow
and digit borrow bit, respectively, in subtraction. See the SUBLW and SUBWF
instructions for examples.
REGISTER 2-1: STATUS REGISTER (STATUS: 03h, 83h, 103h, 183h)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
IRPRP1RP0TO
bit7bit0
bit 7IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh)
0 = Bank 0, 1 (00h - FFh)
bit 6-5RP<1:0>: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h - 1FFh)
10 = Bank 2 (100h - 17Fh)
01 = Bank 1 (80h - FFh)
00 = Bank 0 (00h - 7Fh)
Each bank is 128 bytes
bit 4TO
bit 3PD
bit 2Z: Zero bit
bit 1DC: Digit carry/borrow
bit 0C: Carry/borrow
: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
bit (ADDWF, ADDLW,SUBLW,SUBWF instructio ns) (for borrow, the polarity
is reversed)
1 = A carry-out from the 4th low order bit of the result occurred
0 = No carry-out from the 4th low order bit of the result
bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
PDZDCC
Note:For bo rrow, the polarity is reversed. A subtraction is executed by adding the two’s
compleme nt of th e sec ond ope rand . For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low order bit of the source register.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
Note 1: Individual weak pull-up s on RB pi ns can be e nabled/disa bled from the weak pul l-up
PORTB register (WPUB).
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS41171A-page 18Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
2.5INTCON Register
The INTCON register is a readable and writable register which contains:
• Enable and interrupt flag bits for TMR0 register
overflow
• Enable and interrupt flag bits for the external
interrupt (INT)
• Enable and interrupt flag bits for PORTB
Interrupt-on-Change (IOCB)
• Peripheral interrupt enable bit
• Global interrupt enable bit
Note:Interrupt flag bits are se t w he n an interrupt
condition occurs, re gardless of the state of
its corresponding enable bit, or the global
enable bit, GIE (INTCON<7>). User software should ensure the appropriate interrupt flag bits are clear prior to enabling an
interrupt.
REGISTER 2-3:INTERRUPT CONTROL REGISTER (INTCON: 0Bh, 8Bh, 10Bh, 18Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIEPEIET01EINTERBIET0IFINTFRBIF
bit 7bit 0
bit 7GIE: Global Interrupt Enable bit
1 = Enables all unmasked interrupts
0 = Disables all interrupts
bit 6PEIE: Peripheral Interrupt Enable bit
1 = Enables all unmasked peripheral interrupts
0 = Disables all peripheral interrupts
bit 5T0IE: TMR0 Overflow Interrupt Enable bit
1 = Enables the TMR0 interrupt
0 = Disables the TMR0 interrupt
bit 4INTE: RB0/INT External Interrupt Enable bit
1 = Enables the RB0/INT external interrupt
0 = Disables the RB0/INT external interrupt
bit 7LVDIE: Low Voltage Detect Interrupt Enable bit
1 = LVD interrupt is enabled
0 = LVD interrupt is disabled
bit 6ADIE: Analog-to-Digital Converter Interrupt Enable bit
1 = Enables the Analog-to-Digital Converter interrupt
0 = Disables the Analog-to-Digital Converter interrupt
bit 5C2IE: Comparator C2 Interrupt Enable bit
1 = Enables the Comparator C2 interrupt
0 = Disables the Comparator C2 interrupt
bit 4C1IE: Comparator C1 Interrupt Enable bit
1 = Enables the Comparator C1 interrupt
0 = Disables the Comparator C1 interrupt
bit 3-1Unimplemented: Read as '0'
bit 0TMR1IE: TMR1 Overflow Interrupt Enable bit
1 = Enables the TMR1 overflow interrupt
0 = Disables the TMR1 overflow interrupt
Note:Bit PEIE (INTCON<6>) must be set to
enable any peripheral interrupt (see
Register 2-3).
———TMR1IE
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS41171A-page 20Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
2.7PIR1 Register
This register contains the individual flag bits for the
peripheral interrupts.
Note:Interrupt flag bits are se t w he n an interrupt
condition occurs, re gardless of the state of
its corresponding enable bit, or the global
enable bit, GIE (INTCON<7>). User software should ensure the appropriate interrupt flag bits are clear prior to enabling an
interrupt.
1 = The supply volt age has fall en below t he spe cified LVD volt age (m ust be cle ared in s oftwa re)
0 = The supply voltage is greater than the specified LVD voltage
bit 6ADIF: Analog-to-Digital Converter Interrupt Flag bit
1 = An ADC conversion completed (must be cleared in software)
0 = The ADC conversion is not complete
bit 5C2IF: Comparator C2 Interrupt Flag bit
1 = Comparator C2 input has crossed the threshold (must be cleared in software)
0 = Comparator C2 input has not crossed the threshold
bit 4C1IF: Comparator C1 Interrupt Flag bit
1 = Comparator C1 input has crossed the threshold (must be cleared in software)
0 = Comparator C1 input has not crossed the threshold
bit 3-1Unimplemented: Read as ‘0’
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = TMR1 register overflowed (must be cleared in software)
0 = TMR1 register did not overflow
———TMR1IF
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
The Power Control (PCON) register contains two flag
bits to allow determination of the source of the most
recent RESET:
• Power-on Reset (POR
• External MCLR Reset
• Power Supply Brown-out (BOR
The Power Control register also contains frequency
select bits for the INTRC oscillator and the WDT software enable bit.
Note:BOR is unknown on Power-on Reset. It
must then be set by the user and checked
on subsequent RESETS to see if BOR
clear , indic ating a brow n-out has occurred.
The BOR status bit is a don't care and is
not necessarily predic table if the brown-o ut
circuit is disabled (by clearing the BODEN
bit in the Configuration word).
speed (i.e., the OSCF bit, INTRC mode),
the processor will be inactive during the
oscillator frequency change.
REGISTER 2-6: POWER CONTROL REGISTER (PCON: 8Eh)
U-0U-0U-0R/W-qR/W-1U-0R/W-qR/W-q
———WDTONOSCF—PORBOR
bit 7bit 0
bit 7-5Unimplemented: Read as '0'
bit 4WDTON: WDT Software Enable bit
If WDTE bit (Configuration Word <3>) = 1:
This bit is not writable, always reads ‘1’
Typical Time Inactive
MinimumMaximum
If WDTE bit (Configuration Word <3>) = 0:
1 = WDT is enabled
0 = WDT is disabled
bit 3OSCF: Oscillator Speed INTRC Mode bit
1 = 4 MHz typical
0 = 37 kHz typical
All other oscillator modes (X = Ignored)
bit 2Unimplemented: Read as '0'
bit 1POR
bit 0BOR
: Power-on Reset Status bit
1 = No Power-on Reset occurred
0 = A Power-on Reset occurred (must be set in software after a Power-on Reset occurs)
: Brown-out Reset Status bit
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred
Legend:
q = Value depends on conditions
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR’1’ = Bit is set’0’ = Bit is clearedx = Bit is unknown
DS41171A-page 22Preliminary 2001 Microchip Technology Inc.
2.9PCL and PCLATH
The program counter (PC) s pec ifi es the add res s o f the
instruction to fetch for execution. The PC is 13-bits
wide. The low byte is call ed th e PCL reg is ter. This register is readable and writable. The high byte is called
00hINDFAddressing this location uses contents of FSR to address data memory (not a physical register)
02hPCLProgram Counter’s (PC) Least Significant Byte0000 0000 0000 0000
04hFSRIndirect Data Memory Address Pointerxxxx xxxx uuuu uuuu
0AhPCLATH———Write Buffer for the upper 5 bits of the Program Counter---0 0000 ---0 0000
0ChPIR1LVDIFADIFC2IFC1IF———TMR1IF 0000 ---0 0000 ---0
8EhPCON———WDTONOSCF—PORBOR---q 1-qq ---q 1-qq
Legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0'.
Note 1: Other (non power-up) RESETS include external RESET through MCLR
Shaded locations are unimplemented, read as ‘0’.
INTEDGT0CST0SEPSAPS2PS1PS0xxxx xxxx 1111 1111
and Watchdog Timer Reset.
Value on:
POR, BOR
0000 0000 0000 0000
Value on
all other
RESETS
(1)
DS41171A-page 24Preliminary 2001 Microchip Technology Inc.
PIC16C781/782
3.0I/O PORTS
Most pins for the I/O p orts are mu ltiplexed w ith an alternate function for the peripheral features on the device.
In general, when a peripheral is enabled, that pin may
not be used as a general purpose I/O pin.
Additional inform atio n o n I/O ports may be f oun d i n th e
PICmicro™ Mid-Range Reference Man ual (DS33023 )
3.1I/O Port Analog/Digital Mode
The PIC16C781/782 has two I/O ports: PORTA and
PORTB. Some of these po rt pins are mixed si gnal (can
be digital or anal og). When an analog signal is present
on a pin, the pin mus t be c onfigu red as an an alo g inp ut
to prevent unnecessary current drawn from the power
supply. The Analog Select regist er (ANSEL) a llo w s th e
user to individually select the Digital/Analog mode on
these pins. When the Analog mode is active, the port
pin always reads as a logic 0.
Note 1: On a Power-on Reset, the ANSEL regis-
ter configures these mixed signal pins as
Analog mode: RA<3:0>, RB<3:0>.
2: If a pin is configured as Anal og mode, the
pin always reads '0', even if th e digital ou tput is active.
PORTA is an 8-bit wide, bi-directional port with the
exception of RA0, RA1 and RA5, w hich are inputs only.
The corresponding data direction register is TRISA.
Setting a TRISA bit (= 1) makes the corresponding
PORTA pin an input (i.e., disables the digital output).
Clearing a TRISA bit (= 0) makes the corresponding
PORTA pin an output (i.e., disables the digital output).
Reading the PORTA register reads the status of the
pins, whereas writing to it, writes to the port latch. All
write operations are read-modify-write operations.
Therefore, a write to a port implies that the port pins are
read, this value is then modified and written to the port
data latch.
Pins RA<3:0> are multiplexed with analog functions:
• Analog inputs AN<3:0> to the A/D Converter.
REF1 and VREF2 inputs to the comparators .
• V
• OPAMP inverting/non-inverting inputs.
Note:
Pins RA<7:4> are multiplexed with digital functions:
• Pin RA4 is multiplexed with the TMR0 module
clock input.
• Pin RA5 is multiplexed with the device RESET
(MCLR
) and programming input (VPP) function.
• Pins RA6 and RA7 are multiplexed with the
oscillator/clock I/O functions. RA6 can also be
configured as the TMR1 clock input.
PORTA has the following I/O characteristics:
• RA0, RA1, and RA5 are input only.
• RA4 is an open drain output. All other PORTA
pins have full CMOS buffer outputs.
• All PORTA pins have Schmitt trigger inputs.
EXAMPLE 3-1:INITIALIZING PORTA
;* This code block will configure PORTA
;* as follows
;* RA<7:4>digital outputs
;* RA<3:2>digital inputs
;* RA<1:0>analog inputs
;* RB<3:0>digital I/O
;* Note 1: RB<3:0> configured as digital I/O
;* Note 2: RA<7:6> availability depends on
;* the oscillator selection
BANKSELPORTA; Select Bank 0
CLRFPORTA; Preset PORTA data
; reg
BANKSELTRISA; Select Bank 1
MOVLWB’00001111’; Digital I/O
; config data
MOVWFTRISA; Configure PORTA
; digital
MOVLWB’00000011’; Analog I/O config
; data
MOVWFANSEL; Configure PORTA
; analog
3.2.1TRISA, ANSEL, AND CONTROL
PRECEDENCE
The ANSEL and TRISA registers are the primary software controls for the configuration of PORTA pins.
TRISA bits tri-state the output drivers of PORTA, and
ANSEL register bits control the digital input buffers. It is
important to program bo th registers when configu ring a
mixed signal port pin, as most peripherals cann ot override the TRISA and ANSEL registers control. Even if a
peripheral has the ability to override control of the
TRISA and ANSEL registers, it is good programming
practice to program both registers appropriately.
There are specific cases in which the TRISA and
ANSEL registers can be overridden by a peripheral or
a configuration bit, see Figures 3-1 through 3-8 for
details.
DS41171A-page 26Preliminary 2001 Microchip Technology Inc.