Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digit al Millennium Copyright Act. If suc h a c t s
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of M icrochip’s prod ucts 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 Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, SEEVAL, SmartSensor and The Embedded
Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programmin g, IC SP, ICEPI C, M PASM, MPLIB, MPLINK,
MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail,
PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartTel, Total
Endurance and WiperLock are trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
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 ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
6.0Timer1 Module with Gate Control...............................................................................................................................................73
10.0 Data EEPROM and Flash Program Memory Control ............................................................................................................... 105
14.0 Special Features of the CPU........................................................ ..................... ....................................................................... 173
15.0 Instruction Set Summary.......................................................................................................................................................... 193
16.0 Development Support. .............................................................................................................................................................. 203
18.0 DC and AC Characteristics Graphs and Tables....................................................................................................................... 237
Appendix A: Data Sheet Revision History.......................................................................................................................................... 245
Appendix B: Migrating from other PICmicro® Devices ...................................................................................................................... 245
The Microchip Web Site....................................... ............................................................. ................................................................. 253
Customer Change Notification Service ..............................................................................................................................................253
It is our intention to provide our valued customers with the best docum entation possible to ensure s uccessful use of your Microchip
products. To this end, we will continue to improve our publications to better suit your needs. Our publications will be refined and
enhanced as new volumes and updates are introduced.
If you have any questions or comments regarding this publication, please contact the Marketing Communications Department via Email at docerrors@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)
When contacting a sales office, 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 to receive the most current information on all of our products.
The PIC16F685/687/689/690 has a 13-bit program
counter capable of addressing an 8k x 14 program
memory space. Onl y the first 2k x 14 (0000h-07 FFh) for
the PIC16F687 is physic ally impleme nted and first 4k x
14 (0000h-0FFFh) for the PIC16F685/PIC16F689/
PIC16F690. Accessing a location above these
boundaries will caus e a wrap around. The Reset vector
is at 0000h and the interrupt vector is at 0004h (see
Figures 2-1 and 2-2).
The data memory (see Figures 2-3, 2-4 and 2-5) is
partitioned into four banks which contain the General
Purpose Registers (GPR) and the Special Function
Registers (SFR). The Special Function Registers are
located in the fir st 32 l oca tio ns o f eac h ba nk. Regi ste r
locations 20h-7Fh in Bank 0 and A0h-EFh (A0-BF,
PIC16F687 only) in Bank 1 are General Purpose
Registers, implemented as static RAM. Register
locations F0h-FFh i n Bank 1, 170 h-17Fh in Ban k 2 an d
1F0h-1FFh in Bank 3 point to addresses 70h-7Fh in
Bank 0. Other General Purpose Resisters (GPR) are
also available in Bank 1 an d Ban k 2 , depending on the
device. Details are shown in Figures 2-3, 2-4 and 2-5.
All other RAM is unimplemented and returns ‘0’ when
read. RP<1:0> (STATUS<6:5>) are the bank select
bits:
RP1
RP0
00→Bank 0 is selected
01→Bank 1 is selected
10→Bank 2 is selected
11→Bank 3 is selected
2.2.1GENERAL PURPOSE REGISTER
FILE
The register file is organized as 128 x 8 in the
PIC16F687 and 256 x 8 in the PIC16F685/PIC16F689/
PIC16F690. Each register is accessed, either directly or
indirectly, through the File Select Register (FSR) (see
Section 2.4 “Indirect Addressing, INDF and FSR
Registers”).
2.2.2SPECIAL FUNCTION REGISTERS
The Special Function Registe rs are registers used by
the CPU and peripheral functions for controlling the
desired operation of the device (see Tables 2-1, 2-2, 2-3
and 2-4). These registers are static RAM.
The special re gisters can be classifi ed into two sets:
core and peripheral. The Special Function Registers
associated with the “c ore” are des cribed in this sect ion.
Registers related to the operati on of peripheral features
are described in the section of that peri phe ral feature .
———Write Buffer for upper 5 bits of Program Counter---0 0000 ---0 0000
(2)
0000 000x 0000 000x
—ADIFRCIF
(3)
TXIF
(3)
SSPIF
(3)
CCP1IF
(4)
TMR2IF
(4)
TMR1IF -000 0000 -000 0000
OSFIFC2IFC1IFEEIF————0000 ---- 0000 ----
0EhTMR1LHolding Register for the Least Significant Byte of the 16-bit TMR1xxxx xxxx uuuu uuuu
0FhTMR1HHolding Register for the Most Significant Byte of the 16-bit TMR1xxxx xxxx uuuu uuuu
10hT1CONT1GINVTMR1GE T1CKPS1 T1CKPS0 T1OSCEN T1SYNC
Synchronous Serial Port Receive Buffer/Transmit Registerxxxx xxxx uuuu uuuu
WCOLSSPOVSSPENCKPSSPM3SSPM2SSPM1SSPM0 0000 0000 0000 0000
Capture/Compare/PW M Regi st er 1 (LSB )xxxx xxxx uuuu uuuu
Capture/Compare/PW M Regi st er 1 (MSB )xxxx xxxx uuuu uuuu
1EhADRESHA/D Result Register High Bytexxxx xxxx uuuu uuuu
1FhADCON0ADFMVCFGCHS3CHS2CHS1CHS0GO/DONE
ADON0000 0000 0000 0000
Legend:– = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1:Other (non Power-up) Resets include MCLR
2:MCLR
and WDT Reset do not affect the previous value data latch. The RABIF bit will be cleared upon Reset but will set again if the
Reset and Watchdog Timer Reset dur ing nor mal operation.
mismatched exists.
3:PIC16F687/PIC16F689/PIC16F690 only.
4:PIC16F685/PIC16F690 only.
5:When SSPCON bits SSPM<3:0> = 1001, any reads or writes to the SSPADD SFR address are accessed through the SSPMSK register.
Legend:– = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1:Other (non Power-up) Resets include MCLR
2:MCLR
and WDT Reset do not affect the previous value data latch. The RABIF bit will be cleared upon Reset but will set again if the
Reset and Watchdog Timer Reset during normal operation.
mismatched exists.
3:PIC16F687/PIC16F689/PIC16F690 only.
4:PIC16F685/PIC16F690 only.
5:RA3 pull-up is enabled when pin is configured as MCLR
Legend:– = Unimplemented locations read as ‘0’, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1:Other (non Power-up) Resets include MCLR
(3)
(3)
2:MCLR
mismatched exists.
3:PIC16F685/PIC16F689/PIC16F690 only.
——RA5RA4RA3RA2RA1RA0--xx xxxx --uu uuuu
———Write Buffer for the upper 5 bits of the Program Counter---0 0000 ---0 0000
——
————
————ANS11ANS10ANS9A NS8---- 1111 ---- 1111
and WDT Reset does not affect the previous value data latch. The RABIF bit will be cleared upon Reset but will set again if the
Legend:– = Unimplemented locations read as ‘0’, u = unchange d, x = unknown, q = value depends on condition, shaded = unimplemented
Note 1:Other (non Power-up) Resets include MCLR
The Status register, shown in Register 2-1, contains:
• the arithmetic status of the ALU
• the Reset status
• the bank select bits for data memory (GPR and
SFR)
The Status register can be the destination for any
instruction, like any other register. If the Status register
is the destination for an instruction that affects the Z,
DC or C bits, then the write to these three bits is
writable. Therefore, the result of an instruction with the
Status register as destination may be different than
intended.
For example, CLRF STATUS, will clear the upper three
bits and set the Z bit. Thi s leaves the Status register as
‘000u u1uu’ (where u = unchanged).
It is recommended, therefore, that only BCF, BSF,SWAPF and MOVWF instructions are used to alter the
Stat us register , beca use these instru ctions do not af fect
any Status bits. For other instructions not affecting any
Status bits, see the “Instruction Set Summary.”
disabled. These bit s are set or cleared ac cording to the
device logic. Furthermore, the TO
and PD bits are not
Note 1: The C and DC bits operate as a Borrow
and Digit Borrow out bit, respectively, in
subtraction. See the SUBLW and SUBWF
instructions for examples.
REGISTER 2-1:STATUS – STATUS REGISTER (ADDRESS: 03h, 83h, 103h OR 183h)
R/W-0R/W-0R/W-0R-1R-1R/W-xR/W-xR/W-x
(1)
(1)
bit 7
bit 6-5
bit 4
bit 3
bit 2
bit 1
bit 0
IRPRP1RP0TOPDZDC
bit 7bit 0
IRP: Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h-1FFh)
0 = Bank 0, 1 (00h-FFh)
RP<1:0>: Register Bank Select bits (used for direct addressing)
00 = Bank 0 (00h-7Fh)
01 = Bank 1 (80h-FFh)
10 = Bank 2 (100h-17Fh)
11 = Bank 3 (180h-1FFh)
TO: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
Z: Zero bit
1 = The result of an arithmetic or logic operation is zero
0 = The result of an arithmetic or logic operation is not zero
DC: Digit Carry/Borrow bit (ADDWF, ADDLW,SUBLW,SUBWF 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
C: Carry/Borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)
(1)
1 = A carry-out from the Most Significant bit of the result occurred
0 = No carry-out from the Most Significant bit of the result occurred
Note 1: For Bo
rrow, the polarity is reversed. A subtraction is executed by adding the two’s
complement of the second operand. For rotate (RRF, RLF) instructions, this bit is
loaded with either the high or low-order bit of the source register.
(1)
C
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 INTCON register is a readable and writable
register , which c ontains the various en able and fl ag bit s
for TMR0 register overflow, PORTA change and
external RA2/AN2/T0CKI/INT/C1OUT pin interrupts.
Note:Interrupt flag bits are set when an interru pt
condition occurs, regar dless of the st ate of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to
enabling an interrupt.
REGISTER 2-3:INTCON – INTERRUPT CONTROL REGISTER (ADDRESS: 0Bh, 8Bh, 10Bh OR
18Bh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-x
GIEPEIET0IEINTERABIE
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 in terrupt
bit 4INTE: RA2/INT External Interrupt Enable bit
1 = Enables the RA2/INT external interrupt
0 = Disables the RA2/INT external interrupt
bit 3RABIE: PORTA/PORTB Change Interrupt Enable bit
1 = Enables the PORTA/PORTB change interrupt
0 = Disables the PORTA/PORTB change interrupt
bit 2T0IF: TMR0 Overflow Interrupt Flag bit
1 = TMR0 regis ter has overflowed (must be cleared in software)
0 = TMR0 register did not overflow
bit 1INTF: RA2/INT External Interrupt Flag bit
1 = The RA2/INT external interrupt occurred (must be cleared in software)
0 = The RA2/INT external interrupt did not occur
bit 0RABIF: PORTA/PORTB Change Interrupt Flag bit
1 = When at least o ne of the PORTA or PORTB general purpose I/O p ins cha nge d s tate (must
be cleared in software)
0 = None of the PORTA or PORTB general purpose I/O pins have changed state
(2)
(1,3)
(1, 3)
T0IF
(2)
INTFRABIF
Note 1: IOCA or IOCB register must also be enabled.
2: T0IF bit is set when Timer0 rolls over. Timer0 is unchanged on Reset and should
be initialized before clearing T0IF bit.
3: Includes ULPWU interrupt.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
bit 7Unimplemented: Read as ‘0’
bit 6ADIF: A/D Converter Interrupt Flag bit
1 = The A/D conversion completed (must be cleared in software)
0 = The A/D conversion is not complete
bit 5RCIF: EUSART Receive Interrupt Flag bit
1 = The EUSART receive buffer is full (cleared by reading RCREG)
0 = The EUSART receive buffer is not full
bit 4TXIF: EUSART Transmit Interrupt Flag bit
1 = The EUSART transmit buffer is empty (cleared by writing to TXREG)
0 = The EUSART transmit buffer is full
bit 3SSPIF: Synchronous Serial Port (SSP) Interrupt Flag bit
1 = The Transmission/Reception is complete (must be cleared in software)
0 = Waiting to Transmit/Receive
bit 2CCP1IF: CCP1 Interrupt Flag bit
Capture mode
1 = A TMR1 register capture occurred (must be cleared in software)
0 = No TMR1 register capture occurred
Compare mode
1 = A TMR1 register compare match occurred (must be cleared in software)
0 = No TMR1 register compare match occurred
PWM mode
Unused in this mode
bit 1TMR2IF: TMR2 to PR2 Interrupt Flag bit
1 = A TMR2 to PR2 match occurred (must be cleared in software)
0 = No TMR2 to PR2 match occurred
bit 0TMR1IF: TMR1 Overflow Interrupt Flag bit
1 = The TMR1 register overflowed (must be cleared in software)
0 = The TMR1 register did not overflow
(1)
(2)
Note:Interrupt flag bits are set when an interru pt
condition occurs, regar dless of the st ate 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.
TXIF
(1)
(1)
(1)
(2)
SSPIF
(1)
CCP1IF
(1)
(2)
TMR2IF
(2)
TMR1IF
Note 1: PIC16F687/PIC16F689/PIC16F690 onl y.
2: PIC16F685/PIC16F690 only.
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
1 = System oscillator failed, cloc k input ha s changed to INT OSC (must be c leared in softw are)
0 = System clock operating
bit 6C2IF: Comparator 2 Interrupt Flag bit
1 = Comparator output (C2OUT bit) has changed (must be cleared in software)
0 = Comparator output (C2OUT bit) has not changed
bit 5C1IF: Comparator 1 Interrupt Flag bit
1 = Comparator output (C1OUT bit) has changed (must be cleared in software)
0 = Comparator output (C1OUT bit) has not changed
bit 4EEIF: EE Write Operation Interrupt Flag bit
1 = Write operation completed (must be cleared in software)
0 = Write operation has not completed or has not started
bit 3-0Unimplemented: Read as ‘0’
Note:Interrupt flag bits are set when an interrupt
condition occurs, regardless of the state of
its corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User
software should ensure the appropriate
interrupt flag bits are clear prior to enabling
an interrupt.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
The Program Counter (PC) is 13 bits wide. The lo w byte
comes from the PCL register, which is a readable and
writable register . The hig h byte (PC<12:8>) is not directl y
readable or writable and comes from PCLATH. On any
Reset, the PC is cleared. Figure 2-6 shows the two
situatio ns fo r t he l o ad i n g o f t h e PC . The u p pe r e x am pl e
in Figure 2-6 shows how the PC is loaded on a write to
PCL (PCLATH<4:0> → PCH). The lower example in
Figure 2-6 shows how the PC is loaded during a CALL or
GOTO instruction (PCLATH<4:3> → PCH).
FIGURE 2-6:LOADING OF PC IN
DIFFERENT SITUATIONS
PCHPCL
128 70
PC
PCLATH<4:0>
5
PCLATH
PCHPCL
12 11 100
PC
2
2.3.1COMPUTED
87
PCLATH<4:3>
PCLATH
11
GOTO
A computed GOTO is accomplished by adding an offset
to the program counter (ADDWF PCL). When performing
a table read using a computed GOTO method, care
should be exercised if the table location crosses a PCL
memory boundary (each 256-byte block). Refer to the
Application Note AN556, “Implementing a Table Read”
(DS00556).
Instruction wit
PCL a
Destinatio
8
ALU Result
GOTO, CALL
OPCODE<10:0>
The stack operat es as a circular buf fer . This means th at
after the stack has been PUSHed eight times, the ninth
push overwrites the va lue tha t was s tored fro m the first
push. The tenth pus h ov erwr i tes the se co nd push (and
so on).
Note 1: There are no Status bits to indicate stack
overflow or stack underflow conditions.
2: There are no instructions/mnemonics
called PUSH or POP. These are actions
that occur from the execution of the
CALL, RETURN, RETLW and RETFIE
instructions or the vectoring to an
interrupt address.
2.4Indirect Addressing, INDF and
FSR Registers
The INDF register is not a physica l register . Addr essing
the INDF register will cause indirect addressing.
Indirect addressing is possible by using the INDF
register. Any instruction using the INDF register actually
accesses data pointe d to by the File Select Register
(FSR). Reading INDF itself in direct ly will pro duce 00h.
Writing to the INDF register indirectly resul ts in a no
operation (although Status bits may be affected). An
effective 9-bit address is obtained by concatenating the
8-bit FSR and the IRP bit (STATUS<7>), as shown in
Figure 2-7.
A simple program to clear RAM location 20h-2Fh using
indirect addressing is shown in Example 2-1.
EXAMPLE 2-1:INDIRECT ADDRESSING
MOVLW0x20;initialize pointer
MOVWFFSR;to RAM
NEXTCLRFINDF;clear INDF register
INCFFSR;inc pointer
BTFSSFSR,4;all done?
GOTONEXT;no clear next
CONTINUE;yes continue
2.3.2STACK
The PIC16F685/687/689/690 devices have an
8-level x 13-bit wide hardware stack (see Figures 2-1
and 2-2). The stack spac e is not part of eit her progra m
or data space and the Stack Pointer is not readable or
writable. The PC is PUSHed onto the stack when a
CALL instruction is executed or an interrupt causes a
branch. The st ack i s POPe d in th e eve nt of a RETURN,RETLW or a RETFIE instruction ex ecuti on. PC LATH is
not affected by a PUSH or POP operat ion.
The PIC16F685/687/689/690 devices have a wide
variety of clock sources and selection features to allow
it to be used in a wide range of applications while
maximizing performance and minimizing power
consumption. Figure 3-1 illustrates a block diagram of
the PIC16F685/687/689/690 clock sources.
Clock sources can be configured from external
oscillators, quartz cryst al resonators , ceramic resonators
and Resistor-Capacitor (RC) circuits. In addition, the
system clock source can be configured from one of two
internal oscillators, with a choice of speeds select able via
software. Additional clo ck feat ures inc lud e:
• Selectable system clock source between external
or internal via softwa re.
• Two-Speed Clock Start-up mode, which
minimizes latency between external oscillator
start-up and code execu t io n.
• Fail-Safe Clock Monitor (FSCM) designed to
detect a failure of the external clock source (LP,
XT, HS, EC or RC modes) and switch to the
internal oscillator.
The PIC16F685/687/689/690 can be configured in on e
of eight clock modes.
1.EC – External clock with I/O on RA4.
2.LP – 32 kHz low-power Crystal mode.
3.XT – Medium gain Crystal or Ceramic Resonator
Oscillator mode.
4.HS – High gain Crystal or Ceramic Resonator
mode.
5.RC – External Resistor-Capacitor (RC) with
OSC/4 output on RA4.
F
6.RCIO – External Resistor-Capacitor with I/O on
RA4.
7.INTOSC – Internal oscillator with F
OSC/4 output
on RA4 and I/O on RA5.
8.INTOSCIO – Internal oscillator with I/O on RA4
and RA5.
Clock Source modes are configured by the FOSC<2:0>
bits in the Configuratio n Word register (see Secti on 14.0“Special Features of the CPU ”). The intern al clock can
be generated from two internal oscillators. The
HFINTOSC is a high -frequency cali brated osci llator . The
LFINTOSC is a low -frequ enc y un calibrated oscillator .
Clock Source modes can be classified as external or
internal.
• External Clock mod es rely on e xternal circui try fo r
the clock source. Exam ples are oscillator modules
(EC mode), quartz crystal resonators or ceramic
resonators (LP, XT and HS modes), and
Resistor-Capacitor (RC mode) circuits.
• Internal clock sources are contained internally
within the PIC16F685/687/689/690. The
PIC16F685/687/689/690 has two internal
oscillators, the 8 MHz High-Frequency Internal
Oscillator (HFINTOSC) and 31 kHz
Low-Frequency Internal Oscillator (LFINTOSC).
The system clock can be selected between external or
internal clock sources via the System Clock Selection
(SCS) bit (see Section 3.5 “Clock Switching”).
3.3External Clock Modes
3.3.1OSCILLATOR START-UP TIMER (OST)
If the PIC16F685/687/689/690 is configured for LP, XT
or HS modes, the Oscillator Start-up Timer (OST)
counts 1024 osci llations from the OSC1 pi n, following a
Power-on Reset (POR) and the Power-up Timer
(PWRT) has expired (if configured), or a wake-up from
Sleep. During this time, the program counter does not
increment and program execution is suspended. The
OST ensures that the oscillator circuit, using a quartz
crystal resonator o r ce ramic res onator, has started an d
is providing a stable system clock to the PIC16F685/
687/689/690. When s witching betwe en clock so urces a
delay is required to allow the new clock to stabilize.
These oscillator delays are shown in Table 3-1.
In order to minimize latency between external
oscillator start-up and code execution, the Two-Speed
Clock St art-up mode can be selected (see Section 3.6
“Two-Speed Clock Start-up Mode”).
TABLE 3-1:OSCILLATOR DELAY EXAMPLES
Switch FromSwitch ToFrequencyOscillator Delay
Sleep/POR
Sleep/POREC, RCDC – 20 MHz
LFINTOSC (31 kHz)EC, RCDC – 20 M Hz
Sleep/PORLP, XT, HS32 kHz to 20 MHz1024 Clock Cycles (OST)
LFINTOSC (31 kHz)HFINTOSC125 kHz to 8 MHz1 μs (approx.)
Note 1:The 5 μs to 10 μs start-up delay is based on a 1 MHz system clock.
LFINTOSC
HFINTOSC
31 kHz
125 kHz to 8 MHz
5 μs-10 μs (approx.) CPU Start-up
(1)
3.3.2EC MODE
The External Clock (EC) mode allows an externally
generated logic level as the system clock source. When
operating in this mode, an external clock source is
connected to the OSC1 pin and the RA4/AN3/T1G
OSC2/CLKOUT pin is available for general purpose I/O.
Figure 3-2 shows the pin connections for EC mode.
The Oscillator Start-up Timer (OST) is disabled when
EC mode is selected. Therefore, there is no delay in
operation after a Power-on Reset (POR) or wake-up
from Sleep. Because the PIC16F685/687/689/690
design is full y static, stoppi ng the extern al clock input
will have the ef fect of halting th e device while leaving all
data intact. Upon restarting the external clock, the
device will resum e ope ration as if no ti me ha d elap se d.
The LP, XT and HS modes support the use of quartz
crystal resonators or ceramic resonators connected to
the OSC1 and OSC2 pins (Figure 3-3). The mode
selects a low, medium or high gain setting of the
internal inverter-amplifier to support various resonator
types and speed.
LP Oscillator mode selects the lowest gain setting of the
internal inverter-amplifier. LP mode current consumption
is the least of the three modes. This mode is best suited
to drive resonators with a low drive level specification, for
example, tuning fork type crystals.
XT Oscillator mode selects the intermediate gain
setting of the internal inverter-amplifier. XT mode
current consumption is the medi um of the three modes.
This mode is best suited to drive resonators with a
medium drive level specification, for example, lowfrequency/AT-cut quartz crystal resonators.
HS Oscillator mode selects the highest gain setting of
the internal inverter-amplifier. HS mode current
consumption is the highest of the three modes. This
mode is best suited for resonato rs that req uire a hi gh
drive setting, for example, high-frequency/AT-cut
quartz crystal resonators or ceramic resonators.
Figure 3-3 and Figure3-4 show typical circuits for
quartz crystal and ceramic resonators, respectively.
FIGURE 3-4:CERAMIC RESONATOR
OPERATION
(XT OR HS MODE)
PIC16F685/687/689/690
OSC1
C1
(3)
RP
OSC2
(1)
S
C2
Ceramic
Resonator
Note 1: A series resistor (RS) may be required fo
2: The value of R
3: An a dditional parallel feedback resistor (R
R
ceramic resonators with low drive level.
mode selected (typically between 2 MΩ to
10 MΩ).
may be required for proper ceramic resonato
operation (typical value 1 MΩ).
(2)
RF
F varies with the Oscillato
To Internal
Logic
Sleep
P
FIGURE 3-3:QUARTZ CRYSTAL
OPERATION (LP, XT OR
HS MODE)
PIC16F685/687/689/690
OSC1
C1
Quartz
Crystal
OSC2
(1)
R
S
C2
Note 1: A series resistor (RS) may be required for
quartz crystals with low drive level.
2: The value of R
mode selected (typically between 2 MΩ to
10 MΩ).
(2)
RF
F varies with the Oscillator
Note 1: Quartz crystal characteristics vary
according to type, package and
manufacturer. The user should consult the
manufacturer data sheets for specifications
and recommended application.
The External Resistor-Capacitor (RC) modes support
the use of an external RC circuit. This allows the
designer maximum flexibility in frequency choice while
keeping costs to a minimum when clock accuracy is not
required. There are two modes, RC and RCIO.
In RC mode, the RC circuit connects to the OSC1 pin.
The OSC2/CLKOUT pin outputs the RC oscillator
frequency divided by 4. This signal may be used to
provide a clock for external circuitry, synchronization,
calibration, test or other application requirements.
Figure 3-5 shows the RC mode connections.
FIGURE 3-5: RC MODE
VDD
REXT
OSC1
CEXT
VSS
OSC/4
F
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
PIC16F685/687/689/690
OSC2/CLKOUT
C
EXT > 20 pF
Internal
Clock
In RCIO mode, the RC circuit is connecte d to the OSC1
pin. The OSC2 pin becomes an additional general
purpose I/O pin. The I/O pin becomes bit 4 of PORTA
(RA4). Figure 3-6 shows the RCIO mode connections.
FIGURE 3-6:RCIO MODE
VDD
REXT
OSC1
CEXT
VSS
RA4
Recommended values: 3 kΩ ≤ REXT ≤ 100 kΩ
PIC16F685/687/689/690
I/O (OSC2)
C
EXT > 20 pF
The RC oscillator frequency is a function of the supply
voltage, the resistor (R
EXT) and capacitor (CEXT)
values and the operating temperature. Other factors
affecting the oscillator frequency are:
• threshold voltage variation
• component tolerances
• packaging variations in capacitance
The user also needs to take into account variation due
to tolerance of external RC components used.
Internal
Clock
3.4Internal Clock Modes
The PIC16F685/687/689/690 has two independent,
internal oscillators that can be configured or selected
as the system clock source.
1.The HFINTOSC (High-Frequency Internal
Oscillator) is factory calibrated and operates at
8 MHz. The frequency of t he HFINT OSC can be
user adjusted ±12% via software using the
OSCTUNE register (Register 3-1).
2.The LFINTOSC (Low-Frequency Internal
Oscillator) is uncalibrated and operates at
approximately 31 kHz.
The system cloc k speed ca n be selec ted via sof tware
using the Internal Oscillator Frequency Select (IRCF)
bits.
The system clock ca n be se lec ted betw ee n external or
internal clock sources via the System Clock Selection
(SCS) bit (see Section 3.5 “Clock Switching”).
3.4.1INTOSC AND INTOSCIO MODES
The INTOSC and INTOSCIO modes configure the
internal oscillators as the system clock source when
the device is programmed using the Oscillator Selection (FOSC) bits in the Configuration Word register
(Register 14-1).
In INTOSC mode, the OSC1 pin is available for ge neral
purpose I/O. The OSC2/CLKOUT pin outputs the
selected internal os ci lla tor freq uen cy div ide d by 4. The
CLKOUT signal may be used to provide a clock for
external circuitry, synchronization, calibration, test or
other application require me nt s .
In INTOSCIO mode, the OSC1 and OSC2 pins are
available for general purpose I/O.
3.4.2HFINTOSC
The High-Frequency Int ernal Oscillato r (HFINT OSC) is
a factory calibrated 8 MHz internal clock source. The
frequency of the HFINTOSC can be altered
approximately ±12% via software using the OSCTU NE
register (Register 3-1).
The output of the HFINTOSC connects to a postscaler
and multiplexer (see Figure 3-1). One of seven
frequencies can be selected via software using the
IRCF bits (see Section 3.4.4 “Frequency Select Bits(IRCF)”).
The HFINTOSC is enabled by selecting any frequency
between 8 MHz and 125 kHz (IRCF ≠ 000) as the
system clock s ource (SCS = 1), or when Two-Speed
Start-up is enabled (IESO = 1 and IRCF ≠ 000).
The HF Internal Oscillator (HTS) bit (OSCCON<2>)
indicates whether the HFINTOSC is stable or not.
The HFINTOSC is factory calibrated but can be
adjusted in software by writing to the OSCTUNE
register (Register3-1).
The OSCTUNE register has a tuning range of ±12%.
The default value of the OSCTUNE register is ‘0’. The
value is a 5-bit two’s complement number. Due to
process variatio n, the m onoton icity and freq uency step
cannot be specified.
When the OSCTUNE register is modified, the
HFINTOSC frequency will begin shifting to the new
frequency. The HFINTOSC clock will stabilize within
1 ms. Code execution continues during this shift. There
is no indication that the shift has occurred.
OSCTUNE does not affect the LFINTOSC frequency.
Operation of features that depend on the LFINTOSC
clock source frequency, such as the Power-up Timer
(PWRT), Watchdog Timer (WDT), Fail-Safe Clock
Monitor (FSCM) and peripherals, are not af fected by the
change in frequency.
The Low-Frequency Internal Oscillator (LFINTOSC) is
an uncalibrated (approximate) 31 kHz internal clock
source.
The output of the LFINTOSC connects to a postscaler
and multiplexer (see Figure3-1). 31 kHz can be
selected via software using the IRCF bits (see
Section 3.4.4 “Frequency Select Bits (IRCF)”). The
LFINTOSC is also the frequency for the Power-up
Timer (PWRT), Watchdog Timer (WDT) and Fail-Safe
Clock Monitor (FSCM).
The LFINTOSC is enabled by selecting 31 kHz
(IRCF = 000) as the system clock sourc e (SCS = 1), or
when any of the following are enabled:
• Two-Speed Start-up (IESO = 1 and IRCF = 000)
• Power-up Timer (PWRT)
• Watchdog Timer (WDT)
• Fail-Safe Clock Monitor (FSCM)
The LF Internal Oscillator (LTS) bit (OSCCON<1>)
indicates whether the LFINTOSC is stable or not.
3.4.4FREQUENCY SELECT BITS (IRCF)
The output of the 8 MHz HFINTOSC and 31 kHz
LFINTOSC connects to a postscaler and multiplexer
(see Figure 3-1). The Internal Oscillator Frequency
select bits, IRCF<2:0> (OSCCON<6:4>), select the
frequency output of the internal oscillators. One of eight
frequencies can be selected via software:
•8 MHz
• 4 MHz (Default after Reset)
•2 MHz
•1 MHz
• 500 kHz
• 250 kHz
• 125 kHz
•31 kHz
Note:Following any Reset, the IRCF bit s are s et
to ‘110’ and the frequency selection is set
to 4 MHz. The user can modify the IRCF
bits to select a different frequency.
3.4.5HF AND LF INTOSC CLOCK
SWITCH TIMING
When switching between the LFINTOSC and the
HFINTOSC, the new oscillator may already be shut
down to save power. If this is the case, there is a 10 μs
delay after the IRCF bits are modified before the
frequency selection takes place. The LTS/HTS bits will
reflect the current active status of the LFINTOSC and
the HFINTOSC oscillators. The timing of a frequency
selection is as follows:
1.IRCF bits are modified.
2.If the new clock is sh ut down, a 10 μs clock start-
up delay is started.
3.Clock switch circuitry waits for a falling edge of
the current clock.
4.CLKOUT is held low and the clock switch
circuitry waits fo r a ris ing edge in the new clock.
5.CLKOUT is now connected with the new clock.
HTS/LTS bits are updated as required.
6.Clock switch is complete.
If the internal oscillator speed selected is between
8 MHz and 125 kHz, there is no start-up delay before
the new frequency is selected. This is because the old
and the new frequencies are derived from the
HFINTOSC via the postscaler and multiplexer.
The system clock source can be switched between
external and internal clock sources via software using
the System Clock Select (SCS) bit.
3.5.1SYSTEM CLOCK SELECT (SCS) BIT
The System Clock Select (SCS) bit (OSCCON<0>)
selects the system clock source that is used for the
CPU and peripherals.
• When SCS = 0, the system clock source is
determined by configuration of the FOSC<2:0>
bits in the Configuration Word register (CONFIG).
• When SCS = 1, the system clock source is
chosen by the internal oscillator frequency
selected by the IRCF bits. After a Reset, SCS is
always cleared.
Note:Any automatic clock switch, which may
occur from Two-Speed Start-up or
Fail-Safe Clock Monitor, does not update
the SCS bit. The user can monitor the
OSTS (OSCCON<3>) to determine the
current system clock source.
3.5.2OSCILLA TOR START-UP TIME-OUT
STATUS BIT
The Oscillator Start-up Time-out Status (OSTS) bit
(OSCCON<3>) indicates whether the system clock is
running from the external clock source, as defined by
the FOSC bits, or from internal clock source. In
particular, OSTS indicates that the Oscillator Start-up
Timer (OST) has timed out for LP, XT or HS modes.
3.6Two-Speed Clock Start-up Mode
Two-Speed Start-up mode provides additional power
savings by minimizing the latency between external
oscillator start-up and code execution. In applications
that make heavy us e of the Sleep mode, Two-Speed
Start-up will remove the external oscillator start-up
time from the time spent awake and can reduce the
overall power consumption of the device.
This mode allows the application to wake-up from
Sleep, perform a few instructions using the INTOSC
as the clock source and go back to Sleep without
waiting for the primary oscillator to become stable.
When the PIC16F685/687/689/690 is configured for
LP, XT or HS modes, the Oscillator Start-up Timer
(OST) is enabled (see Section 3.3.1 “Oscillator St art-up Timer (OST)”). The OST timer will suspend
program execution until 1024 oscillations are counted.
Two-Speed Start-up mode minimizes the delay in code
execution by operating from the internal oscillator as
the OST is counting. When the OST count reaches
1024 and the OSTS bit ( OSCC O N<3> ) is se t, pro gram
execution switches to the external oscillator.
3.6.1TWO-SPEED STAR T-UP MODE
CONFIGURATION
Two-Speed Start-up mode is configured by the
following settings:
• IESO = 1 (CONFIG<10>) Internal/External
Switchover bit.
•SCS = 0.
• FOSC configured for LP, XT or HS mode.
Two-Speed Start-up mode is entered after:
• Power-on Reset (POR) and, if enabled, after
PWRT has expired, or
• Wake-up from Sleep.
If the external clock oscillator is configured to be
anything other than LP, XT or HS mode, then TwoSpeed Start-up is disabled. This is because the external
clock oscillator do es not require any stabilizat ion time
after POR or an exit from Sleep.
3.6.2TWO-SPEED START-UP
SEQUENCE
1.Wake-up from Power-on Reset or Sleep.
2.Instructions begin execution by the internal
oscillator at the frequency set in the IRCF bits
(OSCCON<6:4>).
3.OST enabled to count 1024 clock cycles.
4.OST timed out, wait for falling edge of the
internal oscillator.
5.OSTS is set.
6.System clock held low until the next fal ling edg e
of new clock (LP, XT or HS mode).
7.System clock is switched to external clock
source.
Note:Executing a SLEEP instruction will abort
the oscillator start-up time and will cause
the OSTS bit (OSCCON<3>) to remain
clear.
Checking the state of the OSTS bit (OSCCON<3>) will
confirm if the PIC16F685/687/689/690 is running from
the exter nal c lo ck source as d e fi ned by t h e FO SC b i ts
in the Configuration Word register (CONFIG) or the
internal oscillator.
The Fail-Safe Clock Monit or (FSCM) al low s the dev ic e
to continue operat ing sh oul d the external oscillator fail.
The FSCM can detect oscillator failure anytime after
the Oscillator Start-up Timer (OST) has expired. The
FSCM is enabled by setting the FCMEN bit in the
Configuration Word register (CONFIG). The FSCM is
applicable to all external oscillator modes (LP, XT, HS,
EC, RC and RCIO).
FIGURE 3-8:FSCM BLOCK DIAGRAM
Clock Monitor
Latch (CM)
Primary
Clock
LFINTOSC
Oscillator
31 kHz
(~32 μs)
÷ 64
488 Hz
(~2 ms)
3.7.1FAIL-SAFE D ETECTION
The FSCM module detects a failed oscillator by
comparing the ex tern al osci llator to the FS CM sa mple
clock. The sample clock is generated by dividing the
LFINTOSC by 64. See Figure 3-8. Inside the fail
detector block is a latch. The external clock sets the
latch on each falling edge of the external clock. The
sample clock clears the latch on each falling edge of
the sample clock. If a sample clock edge occurs while
the latch is cleared, a failure has occurred.
(edge-triggered)
S
Q
C
Q
Clock
Failure
Detected
3.7.3FAIL-SAFE CONDITION CLEARING
The Fail-Safe condition is cleared after a Reset,
executing a SLEEP instruction or togg ling the SC S bit
(OSCCON<0>). When the SCS bit is tog gle d, th e OS T
is restarted. While the OST is running, the device
continues to operate from the INTOSC selected in
OSCCON. When the OST times out, the Fail-Safe
condition is cleared and the device will be operating
from the external clock s ource. Th e Fail-Saf e condi tion
must be cleared before th e O SFIF f lag ca n be cle are d.
3.7.4RESET OR WAKE-UP FROM SLEEP
The FSCM is designed to detect an oscillator failure
after the Os cillator Start-up Time (OST) has expi red.
The OST is used after waking up from Sleep and after
any type of Reset. The OST is not used with the EC or
RC clock modes so the FSCM will be active as soon as
the Reset or wake-up have completed. When the
FSCM is enabled, the Two-Speed Start-up is also
enabled. Therefore, the device will always be executing
code while the OST is operating.
Note:Due to the wide range of oscillato r st art-up
times, the Fail-Safe circuit is not active
during oscillator start-up (i.e., after exiting
Reset or Sleep). After an appropriate
amount of time, the u se r sho uld check the
OSTS bit (OSCCON<3>) to verify the
oscillator start-up and system clock
switchover has successfully completed.
3.7.2FAIL-SAFE OPERATION
When the external clock fails, the FSCM switches the
device clock to an internal clock source and sets the
OSFIF (PIR2<7>) flag . Setting thi s flag will gen erate an
interrupt if the OSFIE (PIE2<7>) bit is also set. The
device firmware can then take steps to mitigate the
problems that may arise from a failed clock. The
system clock will continue to be sourced from the
internal clock source until the device firmware
successfully restarts the external oscillator and
switches back to external operation.
The internal clock source chosen by the FSCM is
determined by the IRCF bits (OSCCON<6:4>). This
allows the internal oscillator to be configured before a
failure occurs.
Legend:x = unknown, u = unchanged, – = unimplemented locations read as ‘0’. Shaded cells are not used by oscillators.
Note 1:Other (non Power-up) Resets include MCLR
CONFIGCPDCPMCLRE PWRTE WDTEFOSC2 FOSC1 FOSC0——
2:See
Register 14-1 for operation of all Configuration Word register bits.
There are as many as eighteen general purpose I/O
pins available. Depending on which peripherals are
enabled, some or all of the pins may not be a vailable a s
general purpose I/O. In general, when a peripheral is
enabled, the associated pin may not be used as a
general purpose I/O pin.
4.1PORTA and the TRISA Registers
PORTA is a 6-bit wide, bidirectional port. The
corresponding data direction register is TRISA
(Register 4 -2). Setting a TRISA bit (= 1) will make the
corresponding PORTA pin an input (i.e., put the
corresponding output driver i n a High-impedance mod e).
Clearing a TRIS A bi t (= 0) will make the corresponding
PORTA pin an output (i.e., put the contents of th e output
latch on the selected pin). The exception is RA3, which
is input only and its TRIS bit will always read as ‘1’.
Example 4-1 shows how to initialize PORTA.
Reading the PORTA register (Register 4-1) reads the
status of the pins, whereas writing to it will write to the
port latch. All write operations are read-modify-write
operations. Therefore, a write to a port implies that the
port pins are read, this value is modified and then
written to the port data latch. RA3 reads ‘0’ when
MCLRE = 1.
The TRISA register controls the direction of the
PORT A pins, even when they are being used as an alog
inputs. The user must ensure the bits in the TRISA
register are maint ai ned set when using the m as an alog
inputs. I/O pin s co nfigure d as analo g inpu t alw ays rea d
‘0’.
EXAMPLE 4-1:INITIALIZING PORTA
BCFSTATUS,RP0 ;Bank 0
BCFSTATUS,RP1 ;
CLRFPORTA;Init PORTA
BSFSTATUS,RP1 ;Bank 2
CLRF ANSEL;digital I/O
BSFSTATUS,RP0 ;Bank 1
BCFSTATUS,RP1 ;
MOVLW 0Ch;Set RA<3:2> as inputs
MOVWF TRISA;and set RA<5:4,1:0>
BCFSTATUS,RP0 ;Bank 0
;as outputs
4.2Additional Pin Functions
Every PORTA pin on the PIC16F685/687/689/690 has
an interrupt-on-change option and a weak pull-up
option. RA0 also has an Ultra Low-Power Wake-up
option. The next three sections describe these
functions.
4.2.1WEAK PULL-UPS
Each of the PORTA pins, except RA3, has an
individually configurable internal weak pull-up. Control
bits WPUAx enable or disable each pull-up. Refer to
Register 4-3. Each weak pull-up is automatically turne d
off when the port pin is configured as an output. The
pull-ups are disabled on a Power-on Reset by the
RABPU
automatically enabled for RA3 when configured as
MCLR and disabled when RA3 is an I/O. There is no
software control of the MCLR
bit (OPTION_REG<7>). A weak pull-up is
pull-up.
Note:The ANSEL (11Eh) register must be
initialized to configure an analog channel
as a digital input. Pins configured as
analog inputs will read ‘0’.
REGISTER 4-1:PORTA – PORTA REGISTER (ADDRESS: 05h OR 105h)
U-0U-0R/W-xR/W-xR/W-xR/W-xR/W-xR/W-x
——RA5RA4RA3RA2RA1RA0
bit 7bit 0
bit 7-6:Unimplemented: Read as ‘0’
bit 5-0:RA<5:0>: PORTA I/O Pin bit
1 = Port pin is > V
0 = Port pin is < VIL
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Each of the PORTA pins is individually configurable as
an interrupt-on-change pin. Control bits IOCAx enable
or disable the interrupt function for each pin. Refer to
Register 4-4. The interrupt-on-change is disabled on a
Power-on Reset.
For enabled interrupt-on-change pins, the values are
compared with the old value la tched on the last rea d of
PORTA. The ‘mismatch’ outputs of the last read are
OR’d together to set t he PORTA Change Interrupt Flag
bit (RABIF) in the INTCON register (Register 2-3).
This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, clears the
interrupt by:
a) Any read or write of PORTA. This will end the
mismatch condition, then,
b) Clear the flag bit RABIF.
A mismatch condition will continue to set flag bit RABIF .
Reading PORTA will end the mismatch condition and
allow flag bit RABIF to be cleared. The latch holding the
last read value is not affected by a MCLR
Reset. After these Re se t s, the RABIF flag will continue
to be set if a mismatch is present.
Note:If a change on the I/O pin should occur
when the read operation is being ex ecuted
(start of the Q2 cycle), then the RABIF
interrupt flag may not get set.
nor BOR
REGISTER 4-4:IOCA – INTERRUPT-ON-CHANGE PORTA REGISTER (ADDRESS: 96h)
U-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
——IOCA5IOCA4IOCA3IOCA2IOCA1IOCA0
bit 7bit 0
bit 7-6Unimplemented: Read as ‘0’
bit 5-0IOCA<5:0>: Interrupt-on-change PORTA Control bit
The Ultra Low-Power Wake-up (ULPWU) on RA0 allows
a slow falling voltage to generate an interrupt-on-change
on RA0 without excess current consumption. The mode
is selected by setting the ULPWUE bit (PCON<5>). This
enables a small current sink which can be used to
discharge a capacitor on RA0.
To use this feature, the RA0/AN0/C1IN+/ICSPDAT/
ULPWU pin is configured to output ‘1’ to charge the
capacitor, interrupt-on-change for RA0 is enabled, and
RA0 is configured as an input. The ULPWUE bit is set to
begin the discharge and a SLEEP instruction is performed. When the voltage on RA0 drops below V
interrupt will be generated which will cause the device to
wake-up. Depending on the state of the GIE bit
(INTCON<7>), the device will either jump to the interrupt
vector (0004h) or execute the next instruction when the
interrupt event occurs. See Section 4.2.2 “Interrupt-
on-change” and Section 14.3.3 “PORTA/PORTB
Interrupt” for more information.
This feature provides a low-power technique for
periodically waking up the device from Sleep. The
time-out is dependent on the discharge time of the RC
circuit on RA0. See Example 4-2 for initializing the
Ultra Low-Power Wake-up module.
IL, an
The series resistor provides overcurrent protection for
the RA0/AN0/C1IN+/ICSPDAT/ULPWU pin and can
allow for software calibration of the time-out (see
Figure 4-1). A timer can be us ed to measure the c harge
time and discharge time of the capacitor. The charge
time can then be adjusted to provide the desired
interrupt delay. This technique will compensate for the
affects of temperature, voltage and component
accuracy. The Ultra Low-Power Wake-up peripheral
can also be configured as a simple Programmable Low
Voltage Detect or temperature sensor.
Note:For more information, refer to AN879,
“Using the Microchip Ultra Low-PowerWake-up Module” Application Note
(DS00879).
EXAMPLE 4-2:ULTRA LOW-POWER
WAKE-UP INITIALIZATION
BCFSTATUS,RP0 ;Bank 0
BCFSTATUS,RP1 ;
BSFPORTA,0;Set RA0 data latch
BSFSTATUS,RP1 ;BANK 2
BCFANSEL,0;RA0 to digital I/O
BSFSTATUS,RP0 ;BANK 1
BCFSTATUS,RP1 ;
BCFTRISA,0;Output high to
CALLCapDelay;charge capacitor
BSFPCON,ULPWUE ;Enable ULP Wake-up
BSFIOCA,0;Select RA0 IOC
BSFTRISA,0;RA0 to input
MOVLWB’10001000’ ;Enable interrupt
MOVWFINTCON;and clear flag
BCFSTATUS,RP0 ;BANK 0
SLEEP;Wait for IOC
Each PORT A pin is multiplexed with other functio ns. The
pins and their combined functions are briefly described
here. For specific information about individual functions
such as the comparator or the A/D Converter, refer to the
appropriate section in this data sheet.
FIGURE 4-1:BLOCK DIAGRAM OF RA0
Data Bus
WR
WPUDA
WPUDA
PORTA
RD
WR
D
Q
CK
Q
D
Q
CK
Q
4.2.4.1RA0/AN0/C1IN+/ICSPDAT/ULPWU
Figure 4-2 shows the diagram for this pin. The RA0/
10Bh/18Bh
10hT1CON
14hSSPCON
1FhADCON0
81h/181hOPTION_REG
85h/185hTRISA
95hWPUA
96hIOCA
119hCM1CON0
11EhANSEL
Legend:x = unknown, u = unchanged, – = unimplemented locations read as ‘0’. Shaded cells are not used by PORTA.
PORTB is a 4-bit wide, bidirectional port. The
corresponding data direction register is TRI SB (Register
4-6). Setting a TRISB bit (= 1) will make the
corresponding PORTB pin an input (i.e., put the
corresponding output driver in a High-impedance mode).
Clearing a TRISB bit (= 0) will make the correspondi ng
PORTB pin an output (i.e., put the contents of the output
latch on the selected pin). Example 4-3 shows how to
initialize PORTB. Reading the PORTB register (Register
4-5) reads the status of the pins, whereas writing to it will
write to the port latch. All write operations are readmodify-write operations. Therefore, a write to a port
implies that the port pins are r ead, this value is modifi ed
and then written to the port data latch.
The TRISB register controls the direction of the PORTB
pins, even when they are being used as analog inputs.
The user must ensure the bits in the TRIS B register are
maintained set when using them as analog inputs. I/O
pins configured as analog input always read ‘0’.
initialized to configure an analog channel
as a digital input. Pins configured as
analog inputs will read ‘0’.
4.4Additional PORTB Pin Functions
PORTB pins RB<7:4> on the PIC16F685/687/689/690
have an interrupt-o n-cha nge op tion a nd a we ak pu ll-up
option. The following three sections describe these
PORTB pin functions.
4.4.1WEAK PULL-UPS
Each of the PORTB pins has an indiv idually configurable
internal weak pull-up. Control bits WPUB<7:4> enable or
disable each pull-up. Refer to Register 4-7. Each weak
pull-up is automatically turned off when the port pin is
configured as an output. The pull-ups are disabled on a
Power-on Reset by the RABPU
4.4.2INTERRUPT-ON-CHANGE
Four of the PORTB pins are individually configurable
as an interrupt-on-change pin. Control bits IOCB<7:4>
enable or disable the interrupt function for each pin.
Refer to Register 4-8. The interrupt-on-change feature
is disabled on a Power-on Reset.
For enabled interrupt-on-change pins, the values are
compared with the old value latch ed on the la st read of
PORTB. The ‘mismatch’ outputs of the last read are
OR’d together to set the PORTB Change Interrupt flag
bit (RABIF) in the INTCON register (Register 2-3).
This interrupt can wake the device from Sleep. The user ,
in the Interrupt Service Routine, clears the interrupt by:
a) Any read or write of PORTB. This will end the
mismatch condition.
b) Clear the flag bit RABIF.
A mismatch conditio n will contin ue to set flag bit RABIF.
Reading or writing PORTB will end the mismatch
condition and allow flag bit RABIF to be cleared. The latch
holding the last read value is not affected by a MCLR
Brown-out Reset. After these Resets, the RABIF flag will
continue to be set if a mismatch is present.
bit (OPTION_REG<7>).
nor
Note:If a change on the I/O pin should occur
when the read operation is being executed
(start of the Q2 cycle), then the RABIF
interrupt flag may not get set. Furthermore,
since a read or write on a port affects all bits
of that port, care must be taken when using
multiple pins in Interrupt-on-change mode.
Changes on one pin may not be seen while
servicing changes on another pin.
Each PORTB pin is multiplexed with other functions. The
pins and their combined functions are briefly described
here. For specific information about i ndividual functions
such as the SSP, I
section in this data sheet.
2
C or interrupts, refer to the appropriate
4.4.3.1RB4/AN10/SDI/SDA
Figure 4-7 shows the diagram for this pin. The RB4/
AN10/SDI/SDA
of the following:
• a general purpose I/O
• an analog input for the A/D
• a SPI data I/O
2
C data I/O
•an I
Note 1: SDI and SDA are available on
(1)
pin is configurable to fu nction as on e
PIC16F687/PIC16F689/PIC16F690 only.
FIGURE 4-7:BLOCK DIAGRAM OF RB4
(1)
Analog
Data Bus
WR
WPUB
RD
WPUB
WR
PORTB
WR
TRISB
RD
TRISB
D
CK
D
CK
D
CK
Q
Q
Q
Q
Q
Q
Input Mode
RABPU
SSPEN
Input Mode
0
1
1
0
Analog
VDD
Weak
VDD
I/O Pin
VSS
(1)
RD
PORTB
D
Q
D
WR
IOCB
RD
IOCB
Interrupt-on-
CK
Q
Change
RD PORTB
To SSPSR
To A/D Converter
Available on PIC16F68 7/PIC1 6F 689 /P IC16 F6 90 only.
10Bh/18Bh
115hWPUBWPUB7 WPUB6WPUB5WPUB4
116hIOCBIOCB7IOCB6IOCB5IOCB4
Legend:x = unknown, u = unchanged, – = unimplemented locations read as ‘0’. Shaded cells are not used by PORTB.
PORTC is a 8-bit wide, bidirectional port. The
correspondin g da t a dir ec ti on regi s ter is TRISC (Register
4-10). Setting a TRISC bit (= 1) will make the
corresponding PORTC pin an input (i.e., put the
correspondin g output driver in a High-impedan ce mode).
Clearing a TRISC bit (= 0) will make the corresponding
PORTC pin an output (i.e., put the contents of the output
latch on the sele cted pin). Example 4-4 sh ows how to
initialize PORTC. Reading the PORTC register (Register
4-9) reads the status of the pins, whereas writing to it will
write to the port latch. All write operations are readmodify-write operations. Therefore, a write to a port
implies that the port pins are read, this value is modified
and then written to th e p ort d at a l atc h .
The TRISC regi st er co nt rol s the di re ct io n of the P ORTC
pins, even when they are being used as analog inputs.
The user must en sur e the bi ts in th e T RI SC r egi st er are
maintained set when using them as analog inputs. I/O
pins config ure d a s an al og i np ut always read ‘0’.
Note:The ANSEL (11Eh) and ANSELH (11Fh)
registers must be initialized to configure
an analog channel as a digital input. Pins
configured as analog inputs will read ‘0’.
EXAMPLE 4-4:INITIALIZING PORTC
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
CLRFPORTC;Init PORTC
BSFSTATUS,RP1;Bank 2
CLRFANSEL;digital I/O
BSFSTATUS,RP0;Bank 1
BCFSTATUS,RP1;
MOVLW0Ch;Set RC<3:2> as inputs
MOVWFTRISC;and set RC<5:4,1:0>
;as outputs
BCFSTATUS,RP0;Bank 0
REGISTER 4-9:PORTC – PORTC REGISTER (ADDRESS: 07h OR 107h)
R/W-xR/W-xR/W-xR/W-xR/W-xR/W-xR/W-xR/W-x
RC7RC6RC5RC4RC3RC2RC1RC0
bit 7bit 0
bit 7-0RC<7:0>: PORTC General Purpose I/O Pin bits
1 = Port pin is > V
0 = Port pin is < VIL
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
-n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
IH
REGISTER 4-10:TRISC – TRI-STATE PORTC REGISTER (ADDRESS: 87h OR 187h)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
TRISC7TRISC6TRISC5TRISC4TRISC3TRISC2TRISC1TRISC0
bit 7bit 0
bit 7-0TRISC<7:0>: PORTC Tri-State Control bit
1 = PORTC pin configured as an input (tri-stated)
0 = PORTC pin configured as an output
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
• a PWM output
Note 1: Enabling both C2OUT and P1B will cause
a conflict on RC4 and create unpredictable
results. Therefore, if C2OUT is enabled,
the ECCP+ can not be used in Half-bridge
or Full-bridge mode and vise-versa.
2: P1B is available on PIC16F685/
PIC16F690 only.
(1, 2)
is configurable to function
FIGURE 4-13:BLOCK DIAGRAM OF RC4
C2OUT EN
CCPOUT EN
C2OUT EN
CCPOUT EN
Data Bus
WR
PORTC
C2OUT
CCPOUT
D
CK
0
1
1
0
Q
Q
VDD
I/O Pin
VSS
4.5.6RC5/CCP1/P1A
The RC5/CCP1/P1A
one of the following:
• a general purpose I/O
• a digital input/output for the Enhanced CCP
• a PWM output
Note 1: CCP1 and P1A are available on
Legend:x = unknown, u = unchanged, – = unimplemented locations read as ‘0’. Shaded cells are not used by PORTC.
Note 1:PIC16F687/PIC16F689/PIC16F690 only.
The Timer0 module timer/counter has the following
features:
• 8-bit timer/counter
• Readable and writable
• 8-bit software programmable prescaler
• Internal or external clock select
• Interrupt on overflow from FFh to 00h
• Edge select for external clock
Figure 5-1 is a block diagram of th e Ti mer0 module and
the prescaler shared with the WDT.
5.1Timer0 Operation
Timer mode is selected by clearing the T0CS bit
(OPTION_REG<5>). In Timer mode, the Timer0
module will increment every instruction cycle (without
prescaler). If TMR0 is written , the increment is inhibited
for the following two instruction cycles. The user can
work around this by writing an adjusted value to the
TMR0 register.
Counter mode is selected by setting the T0CS bit
(OPTION_REG<5>). In this mode, the Timer0 module
will increment either on every rising or falling edge of pin
RA2/AN1/T0CKI/INT/C1OUT. The incrementing edge is
determined by the source edge (T0SE) control bit
(OPTION_REG<4>). Clearing the T0SE bit selects the
rising edge.
5.2Timer0 Interrupt
A Timer0 interrupt is generated when the TMR0
register timer/counter overflows from FFh to 00h. This
overflow sets the T0IF bit (INTCON<2>). The interrupt
can be masked by clearing the T0IE bit (INTCO N<5 >).
The T0IF bit must be cleared in softwa re by the T i mer0
module Interrupt Service Routine before re-enabling
this interrupt. The Timer0 interrupt cannot wake the
processor from Sleep since the timer is shut off during
Sleep.
FIGURE 5-1:BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER
CLKOUT
(= FOSC/4)
0
1
1
T0CKI
pin
T0SE
WDTE
SWDTEN
31 kHz
INTOSC
Note 1: T0SE, T0CS, PSA, PS<2:0> are bits in the OPTION register, WDTPS<3:0> are bits in the WDTCON register.
When no prescaler is used, the external clock input is
the same as the prescaler output . The syn chroniza tion
of T0CKI, with the internal phase clocks, is
accomplished by sampling the prescaler ou tput on the
Q2 and Q4 cycles of the internal phase clocks.
Therefore, it is necessar y for T0CKI to be high for at
least 2 T
at least 2 T
to the electrical specification of the desired device.
REGISTER 5-1:OPTION_REG – OPTION REGISTER (ADDRESS: 81h OR 181h)
OSC (and a small RC delay of 20 ns) and low for
OSC (and a small RC delay of 20 ns). Re fer
Note:The ANSEL (11Eh) register must be
initialized to configure an analog channel
as a digital input. Pins configured as
analog inputs will read ‘0’.
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
RABPU
bit 7bit 0
INTEDGT0CST0SEPSAPS2PS1PS0
bit 7RABPU
1 = PORTA/PORTB pull-ups are disabled
0 = PORTA/PORTB pull-ups are enabled by individual port latch values
bit 6INTEDG: Interrupt Edge Select bit
1 = Interrupt on rising edge of RA2/AN2/T0CKI/INT/C1OUT pin
0 = Interrupt on falling edge of RA2/AN2/T0CKI/INT/C1OUT pin
An 8-bit counter is available as a prescaler for the
Timer0 module, or as a postscaler for the Watchdog
Timer. For simplicity, this counter will be referred to as
“prescaler” throughout this data sheet. The prescaler
assignment is controlled in software by the control bit
PSA (OPTION_REG<3>). Clearing the PSA bit will
assign the prescaler to Timer0. Prescale values are
selectable via the PS<2:0> bits (OPTION_REG<2:0>).
The prescaler is not readable or writable. When
assigned to the Timer0 module, all instructions writing
to the TMR0 register (e.g., CLRF 1, MOVWF 1,
BSF 1, x....etc.) will clear the prescaler. When
assigned to WDT, a CLRWDT instruction will clear the
prescaler along with the Watchdog Timer.
5.4.1SWITCHING PRESCALER
ASSIGNMENT
The prescaler assignment is fully under software
control (i.e., it can be changed “on the fly” during
program execution). To avoid an unintended device
Reset, the following instruction sequence (Example 5-1
and Example 5-2) must be executed when changing
the prescaler assignment from Timer0 to WDT.
EXAMPLE 5-1:CHANGING PRESCALER
(TIMER0 → WDT)
BCFSTATUS,RP0;Bank 0
BCFSTATUS,RP1;
CLRWDT;Clear WDT
CLRFTMR0;Clear TMR0 and
;prescaler
BSFSTATUS,RP0;Bank 1
MOVLWb’00101111’;Required if desired
MOVWFOPTION_REG;PS<2:0> is
CLRWDT;000 or 001
;
MOVLWb’00101xxx’;Set postscaler to
MOVWFOPTION_REG;desired WDT rate
BCFSTATUS,RP0;Bank 0
To change prescaler from the WDT to the TMR0
module, use the se quence sh own in Examp le 5-2. This
precaution must be t aken even if the WDT is disabled.
• 16-bit Asynchronous counter
In Timer mode, Timer1 is incremented on every
instruction cycle. In Counter mode, Timer1 is
incremented on the rising edge of the external clock
input T1CKI. In addition, the Counter mode clock can be
synchronized to the microcontroller system clock or run
asynchronously.
In Counter and Timer modules, the counter/timer clock
can be gated by the Timer1 gate, which can be
selected as either the T1G
If an external clock oscillator is needed (and the
microcontroller is us ing the INTOS C without CLKOUT),
Timer1 can use the LP oscillator as a clock source.
Note:In Counter mode, a falling edge must be
registered by the counter prior to the first
incrementing rising edge.
pin or Comparator 2 output.
6.2Timer1 Interrupt
The Timer1 register pair (TMR1H:TMR1L) increments
to FFFFh and rolls over to 0000h. When Timer1 rolls
over, the Timer1 interrupt flag bit (PIR1<0>) is set. To
enable the inte rrupt on rollo ver , you must set these bits :
• Timer1 interrupt enable bit (PIE1<0>)
• PEIE bit (INTCON<6>)
• GIE bit (INTCON<7>)
The interrupt is cleared by clearing the TMR1IF bit in
the Interrupt Service Routine.
Note:The TMR1H:TTMR1L register p air and the
TMR1IF bit should be cleared before
enabling interrupts.
6.3Timer1 Prescaler
Timer1 has four prescaler options allowing 1, 2, 4 or 8
divisions of the clock input. The T1CKPS bits
(T1CON<5:4>) control the prescale counter. The
prescale counter is not directly readable or writable;
however, the prescaler counter is cl eared upon a write to
TMR1H or TMR1L.
6.4Timer1 Gate
Timer1 gate source is software configurable to be the
T1G
pin or the output of Comp ara t or 2. This all ows th e
device to directly time external events using T1G
analog events using Comparator 2. See CM2CON1
(Register 8-3) for selecting the Timer1 gate source.
This feature can si mplify the softwa re for a Delta-Si gma
A/D converter and many other applications. For more
information on Delta-Sigma A/D converters, see the
Microchip web site (www.microchip.com).
Note:TMR1GE bit (T1CON<6>) must be set to
use either T1G
gate source. See Register 8-3 for more
information on selecting the Timer1 gate
source.
Timer1 gate can be inverted using the T1GINV bit
(T1CON<7>), whether it origin ates fro m the T1G
Comparator 2 output. This configures Timer1 to
measure either the active-high or active-low time
between events.
or C2OUT as the Timer1
or
pin or
FIGURE 6-2:TIMER1 INCREMENTING EDGE
T1CKI = 1
when TMR1
Enabled
T1CKI = 0
when TMR1
Enabled
Note 1: Arrows indicate counter increments.
2: In Counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge of
If control bit T1SYNC (T1CON<2>) is set, the external
clock input is not synchronized. The timer continues to
increment asynchronous to the internal phase clocks.
The timer will continue to run during Sleep and can
generate an interrupt on overflow, which will wake-up
the processor. However, special precautions in
software are needed to read/write the timer (see
Section 6.5.1 “Reading and Writing Timer1 in
Asynchronous Counter Mode”).
Note:The ANSEL (11Eh) register must be
initialized to configure an analog channel
as a digital input. Pins configured as analog
inputs will read ‘0’.
6.5.1READING AND WRITING TIMER1 IN
ASYNCHRONOUS COUNTER
MODE
Reading TMR1H or TMR1L while the timer is running
from an external asy nchronous cl ock will ens ure a valid
read (taken care of in hardware). However, the user
should keep in min d that re ading t he 16-b it time r in tw o
8-bit values itself, poses certain problems, since the
timer may overflow between the reads.
For writes, it is recomm ended that the us er simply stop
the timer and write the desired values. A write
contention may occur by writing to the timer registers,
while the register is incrementi ng. This may pro duce an
unpredictable value in the timer r egister.
6.6Timer1 Oscillator
A crystal oscilla tor circuit is built-in between pin s OSC1
(input) and OSC2 (amplifier output). It is enabled by
setting control bit, T1OSCEN (T1CON<3>). The
oscillator is a low-p ower oscil lator rated up to 32 kHz . It
will continue to run durin g Sleep. It is primarily intended
for a 32 kHz crystal. Table 3-1 shows the capacitor
selection for the T im er1 osc il lat or.
The Timer1 oscillator is shared with the system LP
oscillator. Thus, Timer1 can use this mode only when
the primary system clock is derived from the internal
oscillator. As with the system LP oscillator, the user
must provide a software time delay to ensure proper
oscillator start-up.
TRISA5 and TRISA4 bits are set when the Timer1
oscillator is enabled. RA5 and RA4 bits read as ‘0’ an d
TRISA5 and TRISA4 bits read as ‘1’.
Note:The oscillator requires a start-up and
stabilization time before use. Thus,
T1OSCEN should be set and a suitable
delay observed prior to enabling Timer1.
6.7Timer1 Operation During Sleep
Timer1 can only operate during Sleep when setup in
Asynchronous Counte r mode. In this mode, an external
crystal or clock source can be used to increment the
counter. To set up the timer to wake the device:
• Timer1 must be on (T1CON<0>)
• TMR1IE bit (PIE1<0>) must be set
• PEIE bit (INTCON<6>) must be set
The device will wake-up on an overflow. If the GIE bit
(INTCON<7>) is set, the devi ce w il l wake -up and jump
to the Interrupt Service Routine (0004h) on an overflow .
If the GIE bit is clear, executio n will contin ue with the
next instruction.
TABLE 6-1:REGISTERS ASSOCIATED WITH TIMER1
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
0Bh/8Bh/
10Bh/18Bh
0ChPIR1
0EhTMR1LHolding register for the Least Significant Byte of the 16-bit TMR1 Registerxxxx xxxx uuuu uuuu
0FhTMR1HHolding register for the Most Significant Byte of the 16-bit TMR1 Registerxxxx xxxx uuuu uuuu
10hT1CONT1GINV TMR1GE T1CKPS1 T1CKPS0 T1OSCEN T1SYNC
11BhCM2CON1 MC1OUT MC2OUT
8ChPIE1
Legend:x = unknown, u = unchanged, — = unimplemented, read as ‘0’. Shaded cells are not used by the Timer1 module.
• Interrupt on TMR2 match with PR2
Timer2 has a control register shown in Register 7-1.
TMR2 can be shut-of f by cl earing control bit, TMR2ON
(T2CON<2>), to minimize power consumption.
Figure 7-1 is a simplified block diagram of the Timer2
module. The prescaler and postscaler selection of
Timer2 are controlled by this register.
7.1Timer2 Operation
Timer2 can be used as the PWM time base for the
PWM mode of the ECCP+ modu le. The TM R 2 reg ist er
is readable and writable, and is cleared on any device
Reset. The in put cl ock (F
of 1:1, 1:4 or 1:16, selected by control bits
T2CKPS<1:0> (T2CON<1:0>). The match output of
TMR2 goes through a 4-bit postscaler (which gives a
1:1 to 1:16 scaling inclusive) to generate a TMR2
interrupt (latched in flag bit, TMR2IF (PIR1<1>)).
The prescaler and postscaler counters are cleared
when any of the following occurs:
• A write to the TMR2 register
• A write to the T2CON register
• Any device Reset (Power-on Reset, MCLR
Watchdog Timer Reset, or Brown-out Reset)
TMR2 is not cleared when T2CON is written.
OSC/4) has a prescale option
REGISTER 7-1:T2CON — TIMER2 CONTROL REGISTER (ADDRESS: 12h)
The Timer2 module has an 8-bit period register, PR2.
Timer2 increments from 00h until it matches PR2 and
then resets to 00h on the next increment cycle. PR2 is
a readable and writable register. The PR2 register is
initialized to FFh upon Reset.
FIGURE 7-1:TIMER2 BLOCK DIAGRAM
TMR2
Output
OSC/4
F
Prescaler
1:1, 1:4, 1:16
2
T2CKPS<1:0>
TMR2
Comparator
PR2
TABLE 7-1:REGISTERS ASSOCIATED WITH TIMER2
AddrNameBit 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
0Bh/8Bh/
10Bh/18Bh
0ChPIR1
11hTMR2Holding Register for the 8-bit TMR2 Register0000 0000 0000 0000
12hT2CON
8ChPIE1
92hPR2Timer2 Module Period Register1111 1111 1111 1111Legend:x = unknown, u = unchanged, — = unimplemented, read as ‘0’. Shaded cells are not used by the Timer2 module.
The comparator module has two separate voltage
comparators: Comparator C1 and Comparator C2.
Each comparator offers the following list of features:
• Control and configuration register
• Comparator output available externally
• Programmable output polarity
• Interrupt-on-change flags
• Wake-up from Sleep
• Configurable as feedback input to the PWM
• Programmable four input multiplexer
• Programmable two input reference selections
• Timer1 gate
• Output synchronization to Timer1 clock input
(Comparator C2 only)
Note:C2 can be linked to Timer1Gate.
8.1Control Registers
Both comparators have separate control and
configuration registers: CM1CON0 for C1 and CM2CON0
for C2. In addition, Comparator C2 has a second control
register, CM2CON1, for synchronization control and
simultaneous reading of both comparator outputs.
A complete table showing the output state versus input
conditions and the polarity bit is shown in Table 8-1.
latched at the end of each instruction
cycle. Exte rnal outputs are not latched.
2: The C1 interrupt will operate correctly
with C1OE set or cleared.
3: For C1 output on RA2/AN2/T0CKI/INT/
C1OUT:
C1OE = 1, C1ON = 1 and TRISA<2> = 0.
8.1.1COMPARATOR C1 CONTROL
REGISTER
The CM1CON0 register (shown in Register 8-1)
contains the control and Status bits for the following:
• Comparator enable
• Comparator input selection
• Comparator reference selection
• Output mode
Setting C1ON (CM1CON0<7>) enables Comparator
C1 for operation.
Bits C1CH<1:0> (CM1CON0<1:0>) select the
comparator input fro m the four anal og pins AN<7:5,1 >.
Note:To use AN<7:5,1> as analog inputs the
appropriate bits must be programmed to
‘1’ in the ANSEL register.
Setting C1R (CM1CON0<2>) selects the C1V
output of the comparator voltage reference module as
the reference volt age for the comp arator. Clearing C1R
selects the C1IN+ input on the RA0/AN0/C1IN+/
ICSPDAT/ULPWU pin.
The output of the comparator is available internally via
the C1OUT flag (CM1CON0<6>). To make the output
available for an external connection, the C1OE bit
(CM1CON0<5>) must be set.
The polarity of the comparator output can be inverted
by setting the C1POL bit (CM1CON0<4>). Clearing
C1POL results in a non-inverted output.
1 = C1OUT is present on the RA2/AN2/T0CKI/INT/C1OUT pin
0 = C1OUT is internal only
bit 4C1POL: Comparator C1 Output Polarity Select bit
1 = C1OUT logic is inverted
0 = C1OUT logic is not inverted
bit 3Unimplemented: Read as ‘0’
bit 2C1R: Comparator C1 Reference Select bit (non-inverting input)
1 = C1VP connects to C1VREF output
0 = C1VP connects to RA0/AN0/C1IN+/ICSPDAT/ULPWU
bit 1-0C1CH<1:0>: Comparator C1 Channel Select bit
00 = C1VN of C1 connects to RA1/AN1/C12IN-/V
01 = C1VN of C1 connects to RC1/AN5/C12IN-
10 = C1VN of C1 connects to RC2/AN6/P1D
11 = C1VN of C1 connects to RC3/AN7/P1C
1 (inverted polarity):
0 (non-inverted polarity):
REF/ICSPCLK
(1)
Note 1: C1OUT will only drive RA2/AN2/T0CKI/INT/C1OUT if:
C1OE = 1, C1ON = 1 and TRISA<2> = 0.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
The Comparator 2 (C2) register (CM2CON0) is a
functional copy of the CM1CON0 register described in
Section 8.1.1 “Comparator C1 Control Register”. A
second control register, CM2CON1, is also present for
control of an additional synchronizing feature, as well
as mirrors of both comparator outputs.
8.1.2.1Comparator 2 Control Register 0
The CM2CON0 register, shown in Register 8-2,
contains the cont rol and S t atus bit s for Comp arator C2.
Setting C2ON (CM2CON0<7>) enables Comparator
C2 for operation.
Bits C2CH<1:0> (CM2CON0<1:0>) select the comparator input from the four analog pins, AN<7:5,1>.
Note 1: To use AN<7:5,1> as analog inputs, the
appropriate bits must be programmed to
1 in the ANSEL register.
C2R (CM2CON0<2>) selects the reference to be used
with the comparator. Setting C2R (CM2CON0<2>)
selects the C2V
reference module as the reference voltage for the
comparator. Clearing C2R selects th e C2IN+ in put on
the RC0/AN4/C2IN+ pin.
The output of the comparator is available internally via
the C2OUT bit (CM2CON0<6>). To make the output
available for an external connection, the C2OE bit
(CM2CON0<5>) must be set.
REF output of the comparator voltage
The comparator output, C2OUT, can be inverted by
setting the C2POL bit (CM2CON0<4>). Clearing
C2POL results in a non-inverted output.
A complete table showing the output state versus input
conditions and the polarity bit is shown in Table 8-2.
1 = C2OUT is present on RC4/C2OUT/P1B
0 = C2OUT is internal only
bit 4C2POL: Comparator C2 Output Polarity Select bit
1 = C2OUT logic is inverted
0 = C2OUT logic is not inverted
bit 3Unimplemented: Read as ‘0’
bit 2C2R: Comparator C2 Reference Select bits (non-i nverting input)
1 = C2VP connects to C2V
0 = C2VP connects to RC0/AN4/C2IN+
bit 1-0C2CH<1:0>: Comparator C2 Channel Select bits
00 = C2VN of C2 connects to RA1/AN1/C12IN-/VREF/ICSPCLK
01 = C2VN of C2 connects to RC1/AN5/C12IN-
10 = C2VN of C2 connects to RC2/AN6/P1D
11 = C2VN of C2 connects to RC3/AN7/P1C
1 (inverted polarity):
0 (non-inverted polarity):
(1)
REF
Note 1: C2OUT will only drive RC4/C2OUT/P1B if:
C2OE = 1, C2ON = 1 and TRISC<4> = 0.
Legend:
R = Readable bitW = Writable bitU = Unimplemented bit, read as ‘0’
- n = Value at POR‘1’ = Bit is set‘0’ = Bit is clearedx = Bit is unknown
Comparator 2 has one addition al feat ure: it s output can
be synchronized to the Timer1 clock input. Setting
C2SYNC (CM2CON1<0>) synchronizes the output of
Comparator 2 to the fal ling edge of T imer1’ s clock input
(see Figure 8-2 and Register 8-3).
The CM2CON1 register also contains mirror copies of
both comparator outputs, MC1OUT and MC2OUT
(CM2CON1<7:6>). The ability to read both outputs
simultaneously from a single register eliminates the
timing skew of reading separate registers.
Note 1: Obtaining the status of C1OUT or C2OUT
by reading CM2CON 1 do es not af fect the
comparator interrupt mismatch registers.
REGISTER 8-3:CM2CON1 – COMPARATOR 2 CONTROL REGISTER 1 (ADDRESS: 11Bh)
R-0R-0U-0U-0U-0U-0R/W-1R/W-0
MC1OUT MC2OUT————T1GSSC2SYNC
bit 7bit 0
bit 7MC1OUT: Mirror Copy of C1OUT bit (CM1CON0<6>)
bit 6MC2OUT: Mirror Copy of C2OUT bit (CM2CON0<6>)
bit 5-2Unimplemented: Read as ‘0’
bit 1T1GSS: Timer1 Gate Source Select bit
1 = Timer1 gate source is RA4/AN3/T1G
0 = Timer1 gate source is C2OUT.
bit 0C2SYNC: C2 Output Synchronous Mode bit
1 = C2 output is synchronous to falling edge of TMR1 clock
0 = C2 output is asynchronous
/OSC2/CLKOUT
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 comparator outputs are read through the
CM1CON0, COM2CON0 or CM2CON1 registers.
CM1CON0 and CM2CON0 each contain the individual
comparator output of Comparator 1 and Comparator 2,
respectively. CM2CON1 contains a mirror copy of both
comparator outputs facilitating a simultaneous read of
both comparators. These bits are read-only. The
comparator outputs may also be directly output t o the
RA2/AN2/T0CKI/INT/C1OUT and RC4/C2OUT/P1B I/O
pins. When enabled, multiplexers in the output path of
the RA2/AN2/T0CKI/INT/C1OUT and RC4/C2OUT/
P1B pins will switch and the output of each pin will be
the unsynchronized output of the comparator. The
uncertainty of each of the comparators is relat ed t o th e
input offset voltage and the response time given in the
specifications. Figure 8-1 and Figure 8-2 show the
output block diagrams for Comparators 1 and 2,
respectively.
The TRIS bits will still function as an output enable/
disable for the RA2/AN2/T0CKI/INT/C1OUT and RC4/
C2OUT/P1B pins while in this mode.
The polarity of the comparator outputs can be changed
using the C1POL and C2POL bits (CMxCON0<4>).
Timer1 gate source can be configured to use the T1G
pin or Comparator 2 output as selected b y the T1GSS bit
(CM2CON1<1>). The Timer1 gate feature can be used
to time the duration or interval of analog events. The
output of Comparator 2 can also be synchronized with
Timer1 by setting the C2SYNC bit (CM2CON1<0>).
When enabled, the output of Comparator 2 is latched on
the falling edge of Timer1 clock source. If a prescaler is
used with Timer1, Comparator 2 is latched after the
prescaler. To prevent a race condition, the Comparator 2
output is latched on the falling edge of the Timer1 clock
source and Timer1 increments on the rising edge of its
clock source. See the Comparator 2 Block Diagram
(Figure 8-2) and the Timer1 Block Diagram (Figure 6-1)
for more information.
It is recommended to synchronize Comparator 2 with
Timer1 by setting the C2SYNC bit when Comparator 2
is used as the Timer1 gate source. This ensures Timer1
does not mi ss an inc rement if Comparator 2 changes
during an increment.
8.2.1COMPARATOR INTERRUPT
OPERATION
The comparator interrupt flags are set whenever there
is a change in the output value of its respective
comparator. Software will need to maintain information
about the status of the output bits, as read from
CM2CON0<7:6>, to determine the actual change that
has occurred. The CxIF bits, PIR2<6:5>, are the
Comparator Interrupt Flags. Each comparator interrupt
bit must be reset in software by clearing it to ‘0’. Since
it is also possible to write a ‘1’ to this register, a
simulated interrupt may be initiated.
The CxIE bits (PIE2<6:5>) and the PEIE bit
(INTCON<6>) must be set to enable the interrupts. In
addition, the GIE bit must also be set. If any of these
bits are cleared, th e interrupt is n ot enabled, th ough the
CxIF bits will still be se t if an interru pt condi tion occ urs.
The comparator interrupt of the PIC16F685/687/689/
690 differs from previous designs in that the interrupt
flag is set by the mismatc h ed ge an d no t the mis matc h
level. This means that the interrupt flag can be reset
without the additional step of reading or writing the
CMxCON0 register to clear the mismatch registers.
When the mismatch registers are not cleared, an
interrupt will not occur when the comparator output
returns to the previous state. When the mismatch
registers are cleared, an interrupt will occur when the
comparator returns to the previous state.
Note 1: If a change in the CMxCON0 register
(CxOUT) should occur when a read
operation is being executed (start of the
Q2 cycle), then the CxIF (PIR2<5:6>)
interrupt flag may not get set.
2: When either comparator is first enabled,
bias circuitry in the comparator module
may cause an invalid output from the
comparator until the bias circuitry is stable. Allow about 1 μs for bias settling then
clear the mismatch condition and interrupt flags before enabling comparator
interrupts.
An SR latch is connected to the comparator outputs
C1OUT and C2OUT. Upon any Reset, the SR latch is
always disabled. As a result, the latch output must be
initialized before the outputs are made available to the
output pins. Additionally, the applicable TRIS bits of the
corresponding ports must be set to output (‘0’) and the
respective comparator output enable bits (C1OE and/or
C2OE) must be initialized in order to make the latch
outputs available on the output pins. The four different
configurations available for the SR latch are shown in
Figure 8-5, and the SR<1:0> bits in the SRCON register
(Register 8-4) control whether or not the latch is
enabled. The latch enable state is completely
independent of the enable state for the comparators.
The SR latch is a Reset-dominant latch that does not
depend on a clock source. Each of the Set and Reset
inputs are acti ve-high. The Se t input is dri ven by the C1
comparator output following the inversion gate, which
is accounted for wi th the C1INV bi t. If the ef fective com parator output si gnal is low , t hen the la tch can be set b y
writing ‘1’ to the PULSS bit. Conversely, the Reset input
is driven by the C1 comparator output following the
inversion gate, which is accounted for with the C2INV
bit. If the compara tor output si gnal is low, then the latch
can be reset by writing ‘1’ to the PULSR bit.
REGISTER 8-4:SRCON – SR LATCH CONTROL REGISTER (ADDRESS: 19Eh)
R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0U-0U-0
(2)
SR1
bit 7bit 0
bit 7-6SR<1:0>: SR Latch Configuration bits
00 = SR latch is disabled
01 = SR latch is enabled. C1OUT pin is the latch non-inverting output. C2OUT pin is the C2
comparator output.
10 = SR latch is enabled. C1OUT pin is the C1 comparator output. C2OUT pin is the latch
inverting output.
11 = SR latch is enabled. C1OUT pin is the latch non-inverting output. C2OUT pin is the latch
inverting output.
bit 5C1SEN: C1 Set Enable bit
1 = C1 comparator output sets SR latch
0 = C1 comparator output has no effect on SR latch
bit 4C2REN: C2 Reset Enable bit
1 = C2 comparator output resets SR la tch
0 = C2 comparator output has no effect on SR latch
bit 3PULSS: Pulse the SET Input of the SR Latch bit
1 = Pulse input
0 = Always reads back ‘0’
bit 2PULSR: Pulse the Reset Input of the SR Latch bit
1 = Pulse input
0 = Always reads back ‘0’
bit 1-0Unimplemented: Read as ‘0’.
SR0
(2)
C1SENC2RENPULSSPULSR——
(2)
Note 1: The C1OUT or C2OUT bits in the CM1CON0 and CM2CON0 registers, respectively,
will always reflect the actual comparator outputs (not the pins), regardless the SR
latch operation.
2: To enable the SR Latch output to the pins, the appropriate C1OE, C2OE, TRISA2
and TRISC4 bits (CM1CON0, CM2CON0, TRISA and TRISC registers, respectively) must be properly configured.
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 comparato r m od ule al so allows the selection of an
internally generated voltage reference for one of the
comparator inputs. There are two voltage references
available in the PIC16F685/687/689/690: The voltage
referred to as the comparator reference (CV
variable volt age ba se d on V
as the VP6 reference is a fixed voltage derived from a
stable band gap source. Each source may be
individually routed internally to the comparators. The
VRCON register (Register 8-5) controls the voltage
reference module shown in Figure 8-5.
DD; The voltage referred to
8.4.1CONFIGURING THE VOLTAGE
REFERENCE
The voltage reference can output 32 distinct voltage
levels, 16 in a high range and 16 in a low range.
The following equation determines the output volt ages:
The VP6 reference has a constant voltage output of
0.6V nominal. This reference ca n be enabled by setting
the VP6EN bit to ‘1’ (VRCON<4>). This reference is
always enabled when the HFINTOSC oscillator is
active.
8.4.4VP6 STABILIZATION PERIOD
When the voltage reference module is enabled, it will
require some time for the reference and its amplifier
circuits to stabilize. The user program must include a
small delay routine to allow the module to settle. See
the electrical specifications section for the minimum
delay requirement.
8.4.2VOLTAGE REFERENCE
ACCURACY/ERROR
The full range of VSS to VDD cannot be realized due to
the construction of t he module. The transistors on th e top
and bottom of the resistor ladder network (Figure 8-5)
keep CV
exception is when the module is disabled by clearing
C1VREN and C2VREN bits (VRCON<7:6>). When
disabled, the reference voltage is V
‘0000’ and the VRR (VRCON<5>) bit is set. This allows
the comparators to detect a zero-crossing and not
consume CV
The voltage referen ce is V
CV
tested absolute accuracy of the comparator voltage
Reference can be found in Section 17.0 “ElectricalSpecifications”.
Response time is the minimum time, after selecting a
new reference voltage or input source, before the
comparator output is ensured to have a valid level. If
the internal reference is changed, the maximum delay
of the internal voltage reference must be considered
when using the comparator outputs. Otherwise, the
maximum delay of the comparators should be used
(Table 17-8).
8.6Operation During Sleep
The comparators and voltage reference, if enabled
before entering Sleep mode, remain active during Sleep.
This results in higher Sleep currents than shown in the
power-down specifications. The additional current
consumed by the comparator and the voltage reference
is shown separately in the specifications. To minimize
power consumption while in Sleep mode, turn off the
comparator, CMxCON0<7> = 0, and voltage reference,
VRCON<7:6>= 00.
While the comparator is enabled during Sleep, an
interrupt will wake-up the device. If the GIE bit
(INTCON<7>) is set, the device will jump to the interrupt
vector (0004h), and if clear , continues execution w ith the
next instruction. If the device wakes up from Sleep, the
contents of the CM1CON0, CM2CON0 and VRCON
registers are not affected.
8.7Effects of a Reset
A device Reset forces the CM1CON0, CM2CON0 and
VRCON registers to their Reset states. This forces the
comparator module to be in the Comparator Reset
mode, CMxC O N0< 7 >= 0, and the volta ge refe rence to
its OFF state. Thus, all potential inputs are analog
TABLE 8-3:REGISTERS ASSOCIATED WITH COMPARATOR MODULE
10Bh/18Bh
0ChPIR1
8ChPIE1
85h/185hTRISA
87h/187hTRISC
118hVRCONC1VREN C2VRENVRRVP6ENVR3VR2VR1VR00000 00000000 0000
119hCM1CON0C1ONC1OUTC1OEC1POL
11AhCM2CON0C2ONC2OUTC2OEC2POL
11BhCM2CON1 MC1OUT MC2OUT
11EhANSELANS7ANS6ANS5ANS4
19EhSRCONSR1SR0C1SENC2SENPULSSPULSR
Legend: x = unknown, u = unchanged, – = unimplemented, read as ‘0’. Shaded cells are not used by the Capture, Compare or Timer1 module.
The analog-to-digital converter (A/D) allows conversion of
an analog input signal to a 10-bit binary representation of
that signal. The PIC16F685/687/689/690 has twelve
analog I/O inputs, plus two int ernal inputs, mult iplexed
into one sample and hold circuit. The output of the sample
and hold is connected to the inp ut of the converter. The
converter generates a binary result via successive
approximation and st ores the resulting or remai ning 10
bits of data into ADRESL (9Eh) and ADRESH (1Eh). The
voltage reference used in the conversion is software
selectable to either V
pin. Figure 9-1 shows the block diagram of the A/D on the
PIC16F685/687/689/690.
FIGURE 9-1:A/D BLOCK DIAGRAM
DD or a voltage applied by the VREF
VREF
PIC16F685/687/689/690
VDD
VCFG = 0
VCFG = 1
RA0/AN0/C1IN+/ICSPDAT/ULPWU
RA1/AN1/C12IN-/V
RA2/AN2/T0CKI/INT/C1OUT
RA4/AN3/T1G
RB4/AN10/SDI/SDA
Note 1: When ADON = 0 all input channels are disconnected from ADC (no loading).
2: P1C and P1D available on PIC16F685/PIC16F690 only.
3: SS, SDO, SDA, RX and DT available on PIC16F687/PIC16F689/PIC16F690 only.
There are four registers available to control the
functionality of the A/D module:
1.ANSEL (Register 9-1)
2.ANSELH (Register 9-2)
3.ADCON0 (Register 9-3)
4.ADCON1 (Register 9-4)
9.1.1ANALOG PORT PINS
The ANS<11:0> bits (ANSEL<7:0> and
ANSELH<3:0>) and the TRISA<4,2:0>, TRISB<5:4>
and TRISC<7:6,3:0>> bits control the operation of the
A/D port pins. Set the corresponding TRISx bits to ‘1’ to
set the pin output driver to its high-impedance state.
Likewise, set the correspo nding ANSx bit to disable the
digital input buffer.
Note:Analog voltages on any pin that is defined
as a digital input may cause the input
buffer to conduct excess current.
9.1.2CHANNEL SELECTION
There are fourteen analog channels on
PIC16F685/687/689/690. The CHS<3:0> bits
(ADCON0<5:2>) control w hich channel is co nnected to
the sample and hold circuit.
9.1.3VOLTAGE REFERENCE
There are two options for the voltage reference to the
A/D converter: either V
applied to V
REF is used. The VCFG bit (ADCON0<6>)
DD is used or an analog voltage
controls the volt age reference s election. If VC FG is set,
then the voltage on the VREF pin is the reference;
otherwise, V
DD is the reference.
9.1.4CONVERSION CLOCK
The A/D conversion cycle requires 11 TAD. The source
of the conversion clock is software selectable via the
ADCS bits (ADCON1<6:4>). There are seven possible
clock options:
OSC/2
•F
•FOSC/4
•FOSC/8
•F
OSC/16
•FOSC/32
•FOSC/64
•F
RC (dedicated internal oscillator)
For correct conversion, the A/D conversion clock
(1/TAD) must be select ed to ensu re a minimu m TAD of
1.6 µs. Table 9-1 shows a few T
selected frequencies.
Legend: Shaded cells are outside of recommended range.
Note 1:The A/D RC source has a typical T
AD time of 4 μs for VDD > 3.0V.
2:These values violate the minimum required TAD time.
3:For faster conversion times, the selection of another clock source is recommended.
4:When the device frequency is greater than 1 MHz, the A/D RC clock source is only recommended if the
The A/D conversion is initiated by setting the
GO/DONE
bit (ADCON0 <1> ). W hen th e co nvers ion is
complete, the A/D module:
• Clears the GO/DONE
bit
• Sets the ADIF flag (PIR1<6>)
• Generates an interrupt (if enabled)
If the conversion must be aborted, the GO/DONE
bit
can be cleared in software. The ADRESH:ADRESL
registers will not be u pdated with th e pa rtiall y comple te
FIGURE 9-2:A/D CONVERSION TAD CYCLES
TCY to TAD
Holding Capacitor is Disconnected from Analog Input (typically 100 ns)
Set GO/DONE bit
TAD1 TAD2
b9b8b7b6b5b4b3b2
Conversion Starts
TAD3
TAD4
TAD5 TAD6 TAD7 TAD8
A/D conversion sample. Instead, the
ADRESH:ADRESL registers will retain the value of th e
previous conversion. After an aborted conversion, a
AD delay is required before another acquisition can
2T
be initiated. Following the delay, an input acquisition is
automatically started on the selected channel.
Note:The GO/DONE bit should not be set in the
same instruction that turns on the A/D.
TAD10 TAD11
TAD9
b1b0
ADRESH and ADRESL registers are loaded,
GO bit is cleared,
ADIF bit is set,
Holding capacitor is connected to analog input
9.1.6CONVERSION OUTPUT
The A/D conversion can be s upplied in two forma ts: left
or right justified. The ADFM bit (ADCON0<7>) controls
the output format. Figure9-3 shows the output formats .
REGISTER 9-1:ANSEL – ANALOG SELECT REGISTER (ADDRESS: 11Eh)
R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1R/W-1
ANS7ANS6ANS5ANS4ANS3ANS2ANS1ANS0
bit 7bit 0
bit 7-0ANS<7:0>: Analog Select bits
Select between analog or digital function on pins AN<7:0>, respectively.
1 = Analog input. Pin is assigned as analog input.
0 = Digital I/O. Pin is assigned to port or special function.
Note 1: Setting a pin to an analog input automatically disables the digital input circuitry,
weak pull-ups, and interrupt-on-change if available. The corresponding TRIS bit
must be set to Input mod e in order to allow exte rnal control of the volt age on the pin.
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
(1)
REGISTER 9-2:ANSELH – ANALOG SELECT HIGH REGISTER (ADDRESS: 11Fh)
U-0U-0U-0U-0R/W-1R/W-1R/W-1R/W-1
————ANS1 1ANS10ANS9ANS8
bit 7bit 0
bit 7-4Unimplemented: Read as ‘0’.
bit 3-0ANS<11:8>: Analog Select bit s
Select between analog or digital function on pins AN<11:8>, respectively.
1 = Analog input. Pin is assigned as analog input.
0 = Digital I/O. Pin is assigned to port or special function.
Note 1: Setting a pin to an analog input automatically disables the digital input circuitry,
weak pull-ups, and interrupt-on-change if available. The corresponding TRIS bit
must be set to Input mod e in order to allow exte rnal control of the volt age on the pin.
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
1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle.
This bit is automatically cleared by hardware when the A/D conversion has completed.
0 = A/D conversion completed/not in progress
bit 0ADON: A/D Enable bit
1 = A/D converter module is enabled
0 = A/D converter is shut off and consumes no operating current
REF
: A/D Conversion Status bit
ADON
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