PIC18F87K90 Family Data Sheet 64/80-Pin, High-Performance Microcontrollers with LCD Driver and nanoWatt XLP Technology 2009-2011 Microchip Technology Inc.
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.
PIC18F87K90 FAMILY 64/80-Pin, High-Performance Microcontrollers with LCD Driver and nanoWatt XLP Technology PIC18F65K90 32K 2K 1K I/O LCD Pixels 53 132 CCP/ ECCP SPI I2C™ RTCC Device Flash SRAM Program Data EEPROM Memory Memory (Bytes) (Bytes) (Bytes) CTMU • Direct LCD Panel Drive Capability: - Can drive LCD panel while in Sleep mode • Up to 48 Segments and 192 Pixels, Software-Selectable • Programmable LCD Timing module: - Multiple LCD timing sources available - Up to four commons: static,
PIC18F87K90 FAMILY Special Microcontroller Features: • • • • • • • • • • • Operating Voltage Range: 1.8V to 5.5V On-Chip 3.
PIC18F87K90 FAMILY Pin Diagrams – PIC18F6XK90 RE2/LCDBIAS3/P2B/CCP10(2) RE3/COM0/P3C/CCP9(2)/REFO RE4/COM1/P3B/CCP8 RE5/COM2/P1C/CCP7 RE6/COM3/P1B/CCP6 RE7/ECCP2(1)/SEG31/P2A RD0/SEG0/CTPLS VDD VSS RD1/SEG1/T5CKI/T7G RD2/SEG2 RD3/SEG3 RD4/SEG4/SDO2 RD5/SEG5/SDI2/SDA2 RD6/SEG6/SCK2/SCL2 RD7/SEG7/SS2 64-Pin QFN(3), TQFP RE1/LCDBIAS2/P2C RE0/LCDBIAS1/P2D RG0/ECCP3/P3A RG1/TX2/CK2/AN19/C3OUT RG2/RX2/DT2/AN18/C3INA RG3/CCP4/AN17/P3D/C3INB MCLR/RG5 RG4/SEG26/RTCC/T7CKI(2)/T5G/CCP5/AN16/P1D/C3INC VSS VDDCORE/V
PIC18F87K90 FAMILY Pin Diagrams – PIC18F8XK90 RH1/SEG46/AN22 RH0/SEG47/AN23 RE2/LCDBIAS3/P2B/CCP10(2) RE3/COM0/P3C/CCP9(2)(3)/REFO RE4/COM1/P3B/CCP8(3) RE5/COM2/P1C/CCP7(3) RE6/COM3/P1B/CCP6(3) RE7/ECCP2(1)/P2A/SEG31 RD0/PSP0/SEG0/CTPLS VDD VSS RD1/SEG1/T5CKI/T7G/PSP1 RD2/SEG2 RD3/SEG3 RD4/SEG4/SDO2 RD5/SEG5/SDI2/SDA2 RD6/SEG6/SCK2/SCL2 RD7/SEG7/SS2 RJ0 RJ1/SEG33 80-Pin TQFP RH2/SEG45/AN21 RH3/SEG44/AN20 RE1/LCDBIAS2/P2C RE0/LCDBIAS1/P2D RG0/ECCP3/P3A RG1/TX2/CK2/AN19/C3OUT RG2/RX2/DT2/AN18/C3INA RG3/CCP
PIC18F87K90 FAMILY Table of Contents 1.0 Device Overview .......................................................................................................................................................................... 9 2.0 Guidelines for Getting Started with PIC18FXXKXX Microcontrollers ......................................................................................... 35 3.0 Oscillator Configurations ..........................................................................................
PIC18F87K90 FAMILY NOTES: DS39957D-page 8 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 1.0 DEVICE OVERVIEW This document contains device-specific information for the following devices: • PIC18F65K90 • PIC18F66K90 • PIC18F67K90 • PIC18F85K90 • PIC18F86K90 • PIC18F87K90 This family combines the traditional advantages of all PIC18 microcontrollers – namely, high computational performance and a rich feature set – with a versatile on-chip LCD driver, while maintaining an extremely competitive price point.
PIC18F87K90 FAMILY The PIC18F87K90 family is also largely pin-compatible with other PIC18 families, such as the PIC18F8720, PIC18F8722, PIC18F85J11, PIC18F8490, PIC18F85J90, PIC18F87J90 and PIC18F87J93 families of microcontrollers with LCD drivers. This allows a new dimension to the evolution of applications, allowing developers to select different price points within Microchip’s PIC18 portfolio, while maintaining a similar feature set. 1.
PIC18F87K90 FAMILY TABLE 1-1: DEVICE FEATURES FOR THE PIC18F6XK90 (64-PIN DEVICES) Features PIC18F65K90 PIC18F66K90 Operating Frequency Program Memory (Bytes) Program Memory (Instructions) PIC18F67K90 DC – 64 MHz 32K 64K 128K 16,384 32,768 65,536 Data Memory (Bytes) 2K 4K 4K Interrupt Sources 42 I/O Ports 48 Ports A, B, C, D, E, F, G LCD Driver (available pixels to drive) Timers 132 (33 SEGs x 4 COMs) 8 11 Comparators 3 CTMU Yes RTCC Yes Capture/Compare/PWM (CCP) Modules 5 7
PIC18F87K90 FAMILY FIGURE 1-1: PIC18F6XK90 (64-PIN) BLOCK DIAGRAM Data Bus<8> Table Pointer<21> 20 Address Latch PCU PCH PCL Program Counter 12 Data Address<12> 31-Level Stack 4 BSR Address Latch Program Memory STKPTR PORTB RB0:RB7(1) 4 Access Bank 12 FSR0 FSR1 FSR2 Data Latch 8 RA0:RA7(1,2) Data Memory (2/4 Kbytes) PCLATU PCLATH 21 PORTA Data Latch 8 8 inc/dec logic 12 PORTC RC0:RC7(1) inc/dec logic Table Latch Address Decode ROM Latch Instruction Bus <16> PORTD RD0:RD7(1) IR
PIC18F87K90 FAMILY FIGURE 1-2: PIC18F8XK90 (80-PIN) BLOCK DIAGRAM Data Bus<8> Table Pointer<21> 20 Address Latch PCU PCH PCL Program Counter 31-Level Stack 4 BSR STKPTR RB0:RB7(1) 4 Access Bank 12 FSR0 FSR1 FSR2 Data Latch 8 PORTB 12 Data Address<12> Address Latch Program Memory RA0:RA7(1,2) Data Memory (2/4 Kbytes) PCLATU PCLATH 21 PORTA Data Latch 8 8 inc/dec logic PORTC RC0:RC7(1) 12 inc/dec logic Table Latch PORTD RD0:RD7(1) Address Decode ROM Latch Instruction Bus <16> P
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS Pin Number Pin Name QFN/TQFP MCLR/RG5 MCLR RG5 7 OSC1/CLKI/RA7 OSC1 CLKI 39 Pin Buffer Type Type I I ST ST I I CMOS CMOS I/O TTL O — CLKO O — RA6 I/O TTL RA7 OSC2/CLKO/RA6 OSC2 40 Description Master Clear (input) or programming voltage (input). This pin is an active-low Reset to the device. General purpose, input only pin. Oscillator crystal or external clock input. Oscillator crystal input. External clock source input.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTA is a bidirectional I/O port. RA0/AN0/ULPWU RA0 AN0 ULPWU 24 RA1/AN1/SEG18 RA1 AN1 SEG18 23 RA2/AN2/VREFRA2 AN2 VREF- 22 RA3/AN3/VREF+ RA3 AN3 VREF+ 21 RA4/T0CKI/SEG14 RA4 T0CKI SEG14 28 RA5/AN4/SEG15/T1CKI/ T3G/HLVDIN RA5 AN4 SEG15 T1CKI T3G HLVDIN 27 I/O I I TTL Analog Analog Digital I/O. Analog Input 0. Ultra Low-Power Wake-up (ULPW) input.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTB is a bidirectional I/O port. PORTB can be software programmed for internal weak pull-ups on all inputs.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTC is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTD is a bidirectional I/O port. RD0/SEG0/CTPLS RD0 SEG0 CTPLS 58 RD1/SEG1/T5CKI/T7G RD1 SEG1 T5CKI T7G 55 RD2/SEG2 RD2 SEG2 54 RD3/SEG3 RD3 SEG3 53 RD4/SEG4/SDO2 RD4 SEG4 SDO2 52 RD5/SEG5/SDI2/SDA2 RD5 SEG5 SDI2 SDA2 51 RD6/SEG6/SCK2/SCL2 RD6 SEG6 SCK2 SCL2 50 RD7/SEG7/SS2 RD7 SEG7 SS2 49 I/O O O ST Analog — Digital I/O. SEG0 output for LCD.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTE is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTF is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description PORTG is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-3: PIC18F6XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name QFN/TQFP Pin Buffer Type Type Description VSS 9, 25, 41, 56 P — VDD 26, 38, 57 P — Ground reference for logic and I/O pins. Positive supply for logic and I/O pins. AVSS 20 P — Ground reference for analog modules. AVDD 19 P — Positive supply for analog modules. ENVREG 18 I ST Enable for on-chip voltage regulator.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTA is a bidirectional I/O port. RA0/AN0/ULPWU RA0 AN0 ULPWU 30 RA1/AN1/SEG18 RA1 AN1 SEG18 29 RA2/AN2/VREFRA2 AN2 VREF- 28 RA3/AN3/VREF+ RA3 AN3 VREF+ 27 RA4/T0CKI/SEG14 RA4 T0CKI SEG14 34 RA5/AN4/SEG15/T1CKI/ T3G/HLVDIN RA5 AN4 SEG15 T1CKI T3G HLVDIN 33 I/O I I TTL Analog Analog Digital I/O. Analog Input 0. Ultra low-power wake-up input.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTB is a bidirectional I/O port. PORTB can be software programmed for internal weak pull-ups on all inputs.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP RB6/KBI2/PGC RB6 KBI2 PGC 52 RB7/KBI3/PGD RB7 KBI3 PGD 47 Pin Buffer Type Type Description I/O I I/O TTL TTL ST Digital I/O. Interrupt-on-change pin. In-Circuit Debugger and ICSP™ programming clock pin. I/O I I/O TTL TTL ST Digital I/O. Interrupt-on-change pin. In-Circuit Debugger and ICSP programming data pin.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTC is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTD is a bidirectional I/O port. RD0/SEG0/CTPLS RD0 SEG0 CTPLS 72 RD1/SEG1/T5CKI/T7G RD1 SEG1 T5CKI T7G 69 RD2/SEG2 RD2 SEG2 68 RD3/SEG3 RD3 SEG3 67 RD4/SEG4/SDO2 RD4 SEG4 SDO2 66 RD5/SEG5/SDI2/SDA2 RD5 SEG5 SDI2 SDA2 65 RD6/SEG6/SCK2/SCL2 RD6 SEG6 SCK2 SCL2 64 RD7/SEG7/SS2 RD7 SEG7 SS2 63 I/O O O ST Analog ST Digital I/O. SEG0 output for LCD.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTE is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTF is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTG is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTH is a bidirectional I/O port.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP RH7/SEG43/CCP6/P1B/ AN15 RH7 SEG43 CCP6(4) P1B AN15 Pin Buffer Type Type Description 19 I/O O I/O O I ST Analog ST — Analog Digital I/O. SEG43 output for LCD. Capture 6 input/Compare 6 output/PWM6 output. ECCP1 PWM Output B. Analog Input 15.
PIC18F87K90 FAMILY TABLE 1-4: PIC18F8XK90 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name TQFP Pin Buffer Type Type Description PORTJ is a bidirectional I/O port. RJ0 62 RJ1/SEG33 RJ1 SEG33 61 RJ2/SEG34 RJ2 SEG34 60 RJ3/SEG35 RJ3 SEG35 59 RJ4/SEG39 RJ4 SEG39 39 RJ5/SEG38 RJ5 SEG38 40 RJ6/SEG37 RJ6 SEG37 41 RJ7/SEG36 RJ7 SEG36 42 I/O ST Digital I/O. I/O O ST Analog Digital I/O. SEG33 output for LCD. I/O O ST Analog Digital I/O. SEG34 output for LCD.
PIC18F87K90 FAMILY NOTES: DS39957D-page 34 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 2.0 GUIDELINES FOR GETTING STARTED WITH PIC18FXXKXX MICROCONTROLLERS FIGURE 2-1: RECOMMENDED MINIMUM CONNECTIONS C2(2) • All VDD and VSS pins (see Section 2.2 “Power Supply Pins”) • All AVDD and AVSS pins, regardless of whether or not the analog device features are used (see Section 2.2 “Power Supply Pins”) • MCLR pin (see Section 2.3 “Master Clear (MCLR) Pin”) • ENVREG (if implemented) and VCAP/VDDCORE pins (see Section 2.
PIC18F87K90 FAMILY 2.2 2.2.1 Power Supply Pins DECOUPLING CAPACITORS The use of decoupling capacitors on every pair of power supply pins, such as VDD, VSS, AVDD and AVSS, is required. Consider the following criteria when using decoupling capacitors: • Value and type of capacitor: A 0.1 F (100 nF), 10-20V capacitor is recommended. The capacitor should be a low-ESR device, with a resonance frequency in the range of 200 MHz and higher. Ceramic capacitors are recommended.
PIC18F87K90 FAMILY 2.4 Some PIC18FXXKXX families, or some devices within a family, do not provide the option of enabling or disabling the on-chip voltage regulator: Voltage Regulator Pins (ENVREG and VCAP/VDDCORE) The on-chip voltage regulator enable pin, ENVREG, must always be connected directly to either a supply voltage or to ground. Tying ENVREG to VDD enables the regulator, while tying it to ground disables the regulator. Refer to Section 28.
PIC18F87K90 FAMILY CONSIDERATIONS FOR CERAMIC CAPACITORS In recent years, large value, low-voltage, surface-mount ceramic capacitors have become very cost effective in sizes up to a few tens of microfarad. The low-ESR, small physical size and other properties make ceramic capacitors very attractive in many types of applications. Ceramic capacitors are suitable for use with the internal voltage regulator of this microcontroller.
PIC18F87K90 FAMILY 2.6 External Oscillator Pins FIGURE 2-5: Many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to Section 3.0 “Oscillator Configurations” for details). The oscillator circuit should be placed on the same side of the board as the device. Place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins.
PIC18F87K90 FAMILY NOTES: DS39957D-page 40 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 3.0 OSCILLATOR CONFIGURATIONS 3.
PIC18F87K90 FAMILY TABLE 3-1: HS, EC, XT, LP AND RC MODES: RANGES AND SETTINGS Mode Frequency Range EC1 (low power) OSC<3:0> Setting 1101 DC-160 kHz (EC1 & EC1IO) EC2 (medium power) 1100 160 kHz-16 MHz 1011 16 MHz-64 MHz 0101 HS1 (medium power) 4 MHz-16 MHz 0011 HS2 (high power) 16 MHz-25 MHz 0010 XT 100 kHz-4 MHz 0001 LP 31.
PIC18F87K90 FAMILY 3.2 Control Registers The OSCCON register (Register 3-1) controls the main aspects of the device clock’s operation. It selects the oscillator type to be used, which of the power-managed modes to invoke and the output frequency of the INTOSC source. It also provides status on the oscillators. REGISTER 3-1: R/W-0 OSCCON: OSCILLATOR CONTROL REGISTER R/W-1 IDLEN The OSCTUNE register (Register 3-3) controls the tuning and operation of the internal oscillator block.
PIC18F87K90 FAMILY REGISTER 3-1: OSCCON: OSCILLATOR CONTROL REGISTER (CONTINUED) bit 2 HFIOFS: INTOSC Frequency Stable bit 1 = HF-INTOSC oscillator frequency is stable 0 = HF-INTOSC oscillator frequency is not stable bit 1-0 SCS<1:0>: System Clock Select bits(4) 1x = Internal oscillator block (LF-INTOSC, MF-INTOSC or HF-INTOSC) 01 = SOSC oscillator 00 = Default primary oscillator (OSC1/OSC2 or HF-INTOSC with or without PLL; defined by the OSC<3:0> Configuration bits, CONFIG1H<3:0>.
PIC18F87K90 FAMILY REGISTER 3-3: OSCTUNE: OSCILLATOR TUNING REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 INTSRC PLLEN TUN5 TUN4 TUN3 TUN2 TUN1 TUN0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 INTSRC: Internal Oscillator Low-Frequency Source Select bit 1 = 31.
PIC18F87K90 FAMILY 3.3.1 OSC1/OSC2 OSCILLATOR The OSC1/OSC2 oscillator block is used to provide the oscillator modes and frequency ranges: Mode Design Operating Frequency LP 31.25-100 kHz XT 100 kHz to 4 MHz HS 4 MHz to 25 MHz EC 0 to 64 MHz (external clock) EXTRC 0 to 4 MHz (external RC) The crystal-based oscillators (XT, HS and LP) have a built-in start-up time. The operation of the EC and EXTRC clocks is immediate. 3.3.
PIC18F87K90 FAMILY TABLE 3-2: CAPACITOR SELECTION FOR CERAMIC RESONATORS Typical Capacitor Values Used: Mode Freq. OSC1 OSC2 HS 8.0 MHz 16.0 MHz 27 pF 22 pF 27 pF 22 pF Note 1: Higher capacitance increases the stability of the oscillator but also increases the start-up time. 2: Since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. Capacitor values are for design guidance only.
PIC18F87K90 FAMILY In the RC Oscillator mode, the oscillator frequency divided by 4 is available on the OSC2 pin. This signal may be used for test purposes or to synchronize other logic. Figure 3-3 shows how the R/C combination is connected. FIGURE 3-3: RC OSCILLATOR MODE FIGURE 3-5: EXTERNAL CLOCK INPUT OPERATION (EC CONFIGURATION) OSC1/CLKI Clock from Ext.
PIC18F87K90 FAMILY FIGURE 3-7: PLL BLOCK DIAGRAM PLLCFG (CONFIG1H<4>) PLL Enable (OSCTUNE) OSC2 OSC1 HS or EC Mode FIN Phase Comparator FOUT Loop Filter VCO MUX 4 3.5.2.2 SYSCLK PLL and HF-INTOSC The PLL is available to the internal oscillator block when the internal oscillator block is configured as the primary clock source. In this configuration, the PLL is enabled in software and generates a clock output of up to 64 MHz. The operation of INTOSC with the PLL is described in Section 3.6.
PIC18F87K90 FAMILY 3.6.2 INTPLL MODES The 4x Phase Locked Loop (PLL) can be used with the HF-INTOSC to produce faster device clock speeds than are normally possible with the internal oscillator sources. When enabled, the PLL produces a clock speed of 32 MHz or 64 MHz. PLL operation is controlled through software. The control bit, PLLEN (OSCTUNE<6>) is used to enable or disable its operation.
PIC18F87K90 FAMILY 3.7 Reference Clock Output In addition to the FOSC/4 clock output in certain oscillator modes, the device clock in the PIC18F87K90 family can also be configured to provide a reference clock output signal to a port pin. This feature is available in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. This reference clock output is controlled by the REFOCON register (Register 3-4).
PIC18F87K90 FAMILY 3.8 Effects of Power-Managed Modes on the Various Clock Sources When PRI_IDLE mode is selected, the designated primary oscillator continues to run without interruption. For all other power-managed modes, the oscillator using the OSC1 pin is disabled. The OSC1 pin (and OSC2 pin if used by the oscillator) will stop oscillating. In secondary clock modes (SEC_RUN and SEC_IDLE), the SOSC oscillator is operating and providing the device clock.
PIC18F87K90 FAMILY 4.0 POWER-MANAGED MODES The PIC18F87K90 family of devices offers a total of seven operating modes for more efficient power management. These modes provide a variety of options for selective power conservation in applications where resources may be limited (such as battery-powered devices). There are three categories of power-managed modes: • Run modes • Idle modes • Sleep mode There is an Ultra Low-Power Wake-up (ULPWU) for waking from the Sleep mode.
PIC18F87K90 FAMILY 4.1.3 CLOCK TRANSITIONS AND STATUS INDICATORS The length of the transition between clock sources is the sum of two cycles of the old clock source and three to four cycles of the new clock source. This formula assumes that the new clock source is stable. The HF-INTOSC and MF-INTOSC are termed as INTOSC in this chapter. Three bits indicate the current clock source and its status, as shown in Table 4-2.
PIC18F87K90 FAMILY FIGURE 4-1: TRANSITION TIMING FOR ENTRY TO SEC_RUN MODE Q1 Q2 Q3 Q4 Q1 Q2 1 SOSCI 2 3 n-1 Q3 Q4 Q1 Q2 Q3 n Clock Transition(1) OSC1 CPU Clock Peripheral Clock Program Counter PC PC + 2 PC + 4 Note 1: Clock transition typically occurs within 2-4 TOSC.
PIC18F87K90 FAMILY If the IRCF bits and the INTSRC bit are all clear, the INTOSC output (HF-INTOSC/MF-INTOSC) is not enabled, and the HFIOFS and MFIOFS bits will remain clear. There will be no indication of the current clock source. The LF-INTOSC source is providing the device clocks. TABLE 4-3: If the IRCF bits are changed from all clear (thus, enabling the INTOSC output) or if INTSRC or MFIOSEL is set, the HFIOFS or MFIOFS bit is set after the INTOSC output becomes stable. For details, see Table 4-3.
PIC18F87K90 FAMILY FIGURE 4-3: TRANSITION TIMING TO RC_RUN MODE Q1 Q2 Q3 Q4 Q1 Q2 1 LF-INTOSC 2 3 n-1 Q3 Q4 Q1 Q2 Q3 n Clock Transition(1) OSC1 CPU Clock Peripheral Clock Program Counter PC PC + 2 PC + 4 Note 1: Clock transition typically occurs within 2-4 TOSC.
PIC18F87K90 FAMILY 4.3 Sleep Mode 4.4 The power-managed Sleep mode in the PIC18F87K90 family of devices is identical to the legacy Sleep mode offered in all other PIC devices. It is entered by clearing the IDLEN bit (the default state on device Reset) and executing the SLEEP instruction. This shuts down the selected oscillator (Figure 4-5). All clock source status bits are cleared.
PIC18F87K90 FAMILY 4.4.1 PRI_IDLE MODE 4.4.2 This mode is unique among the three low-power Idle modes, in that it does not disable the primary device clock. For timing-sensitive applications, this allows for the fastest resumption of device operation with its more accurate, primary clock source, since the clock source does not have to “warm-up” or transition from another oscillator. PRI_IDLE mode is entered from PRI_RUN mode by setting the IDLEN bit and executing a SLEEP instruction.
PIC18F87K90 FAMILY 4.4.3 RC_IDLE MODE In RC_IDLE mode, the CPU is disabled but the peripherals continue to be clocked from the internal oscillator block using the INTOSC multiplexer. This mode provides controllable power conservation during Idle periods. From RC_RUN, this mode is entered by setting the IDLEN bit and executing a SLEEP instruction. If the device is in another Run mode, first set IDLEN, then set the SCS1 bit and execute SLEEP.
PIC18F87K90 FAMILY REGISTER 4-1: R/W-0 (1) CCP10MD PMD3: PERIPHERAL MODULE DISABLE REGISTER 3 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CCP9MD(1) CCP8MD CCP7MD CCP6MD CCP5MD CCP4MD TMR12MD(1) bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 CCP10MD: PMD CCP10 Enable/Disable bit(1) 1 = Peripheral Module Disable (PMD) is enabled for CCP10, disabling all of its cloc
PIC18F87K90 FAMILY REGISTER 4-2: PMD2: PERIPHERAL MODULE DISABLE REGISTER 2 R/W-0 (1) TMR10MD R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 TMR8MD TMR7MD(1) TMR6MD TMR5MD CMP3MD CMP2MD CMP1MD bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 TMR10MD: TMR10MD Disable bit(1) 1 = Peripheral Module Disable (PMD) is enabled and all TMR10MD clock sources are disabled 0 =
PIC18F87K90 FAMILY REGISTER 4-3: PMD1: PERIPHERAL MODULE DISABLE REGISTER 1 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 — CTMUMD RTCCMD(1) TMR4MD TMR3MD TMR2MD TMR1MD — bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6 CTMUMD: PMD CTMU Enable/Disable bit 1 = Peripheral Module Disable (PMD) is enabled for CMTU, disabling all
PIC18F87K90 FAMILY REGISTER 4-4: PMD0: PERIPHERAL MODULE DISABLE REGISTER 0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CCP3MD CCP2MD CCP1MD UART2MD UART1MD SSP2MD SSP1MD ADCMD bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 CCP3MD: PMD ECCP3 Enable/Disable bit 1 = Peripheral Module Disable (PMD) is enabled for ECCP3, disabling all of its clock sources 0 =
PIC18F87K90 FAMILY 4.6 Exiting Idle and Sleep Modes An exit from Sleep mode or any of the Idle modes is triggered by an interrupt, a Reset or a WDT time-out. This section discusses the triggers that cause exits from power-managed modes. The clocking subsystem actions are discussed in each of the power-managed modes (see Section 4.2 “Run Modes”, Section 4.3 “Sleep Mode” and Section 4.4 “Idle Modes”). 4.6.
PIC18F87K90 FAMILY 4.7 Ultra Low-Power Wake-up The Ultra Low-Power Wake-up (ULPWU) on pin, RA0, allows a slow falling voltage to generate an interrupt without excess current consumption. To use this feature: 1. 2. 3. 4. 5. A series resistor, between RA0 and the external capacitor, provides overcurrent protection for the RA0/AN0/ ULPWU pin and enables software calibration of the time-out (see Figure 4-9).
PIC18F87K90 FAMILY TABLE 4-4: EXIT DELAY ON WAKE-UP BY RESET FROM SLEEP MODE OR ANY IDLE MODE (BY CLOCK SOURCES) Power-Managed Mode Clock Source(5) Exit Delay Clock Ready Status Bits LP, XT, HS HSPLL PRI_IDLE mode EC, RC HF-INTOSC(2) OSTS TCSD(1) MF-INTOSC(2) LF-INTOSC SEC_IDLE mode SOSC None TCSD(1) SOSCRUN TCSD(1) MFIOFS HF-INTOSC(2) RC_IDLE mode MF-INTOSC(2) HFIOFS LF-INTOSC Sleep mode TOST(3) HSPLL TOST + trc(3) EC, RC TCSD(1) HF-INTOSC(2) LF-INTOSC Note 1: 2: 3: 4: 5: None L
PIC18F87K90 FAMILY NOTES: DS39957D-page 68 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 5.0 RESET The PIC18F87K90 family of devices differentiates between various kinds of Reset: a) b) c) d) e) f) g) h) i) Power-on Reset (POR) MCLR Reset during normal operation MCLR Reset during power-managed modes Watchdog Timer (WDT) Reset (during execution) Configuration Mismatch (CM) Reset Brown-out Reset (BOR) RESET Instruction Stack Full Reset Stack Underflow Reset This section discusses Resets generated by MCLR, POR and BOR, and covers the operation of the various start-up timers.
PIC18F87K90 FAMILY REGISTER 5-1: RCON: RESET CONTROL REGISTER R/W-0 R/W-1 R/W-1 R/W-1 R-1 R-1 R/W-0 R/W-0 IPEN SBOREN CM RI TO PD POR BOR bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 IPEN: Interrupt Priority Enable bit 1 = Enable priority levels on interrupts 0 = Disable priority levels on interrupts (PIC16CXXX Compatibility mode) bit 6 SBOREN: BOR Softwa
PIC18F87K90 FAMILY 5.2 Master Clear (MCLR) The MCLR pin provides a method for triggering a hard external Reset of the device. A Reset is generated by holding the pin low. PIC18 extended microcontroller devices have a noise filter in the MCLR Reset path which detects and ignores small pulses. The MCLR pin is not driven low by any internal Resets, including the WDT. 5.3 Power-on Reset (POR) A Power-on Reset condition is generated on-chip whenever VDD rises above a certain threshold.
PIC18F87K90 FAMILY 5.5 Configuration Mismatch (CM) 5.6 Power-up Timer (PWRT) The Configuration Mismatch (CM) Reset is designed to detect, and attempt to recover from, random, memory corrupting events. These include Electrostatic Discharge (ESD) events that can cause widespread, single bit changes throughout the device and result in catastrophic failure. PIC18F87K90 family devices incorporate an on-chip Power-up Timer (PWRT) to help regulate the Power-on Reset process.
PIC18F87K90 FAMILY FIGURE 5-4: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 1 VDD MCLR INTERNAL POR TPWRT PWRT TIME-OUT INTERNAL RESET TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO VDD): CASE 2 FIGURE 5-5: VDD MCLR INTERNAL POR TPWRT PWRT TIME-OUT INTERNAL RESET FIGURE 5-6: SLOW RISE TIME (MCLR TIED TO VDD, VDD RISE > TPWRT) 3.3V VDD 0V 1V MCLR INTERNAL POR TPWRT PWRT TIME-OUT INTERNAL RESET 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 5.7 different Reset situations, as indicated in Table 5-1. These bits are used in software to determine the nature of the Reset. Reset State of Registers Most registers are unaffected by a Reset. Their status is unknown on POR and unchanged by all other Resets. The other registers are forced to a “Reset state” depending on the type of Reset that occurred. Table 5-2 describes the Reset states for all of the Special Function Registers.
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets TOSU PIC18F6XK90 PIC18F8XK90 ---0 0000 ---0 0000 ---0 uuuu(1) TOSH PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu(1) TOSL PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu(1) STKPTR PIC18F6XK90 PIC18F8XK90 00-0 0000 uu-0 0000 uu-u uuuu(1) Register Wake-up via WDT or Interrupt PCLAT
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Register Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets Wake-up via WDT or Interrupt INDF2 PIC18F6XK90 PIC18F8XK90 N/A N/A N/A POSTINC2 PIC18F6XK90 PIC18F8XK90 N/A N/A N/A POSTDEC2 PIC18F6XK90 PIC18F8XK90 N/A N/A N/A PREINC2 PIC18F6XK90 PIC18F8XK90 N/A N/A N/A PLUSW2 PIC18F6XK90 PIC18F8XK90 N/A N/A N/A FSR2H PIC18F6XK90
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets ECCP1DEL PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu CCPR1H PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu CCPR1L PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu CCP1CON PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu PIR5 PIC18F6XK90 PIC18F8XK90 0000
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets PSTR1CON PIC18F6XK90 PIC18F8XK90 00-0 0001 00-0 0001 uu-u uuuu OSCTUNE PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu TRISJ PIC18F6XK90 PIC18F8XK90 1111 1111 1111 1111 uuuu uuuu TRISH PIC18F6XK90 PIC18F8XK90 1111 1111 1111 1111 uuuu uuuu TRISG PIC18F6XK90 PIC18F8XK90 ---1 1
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets EECON1 PIC18F6XK90 PIC18F8XK90 xx-0 x000 uu-0 u000 EECON2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 0000 0000 LCDDATA23 PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu LCDDATA22 PIC18F6XK90 PIC18F8XK90 ---- ---x ---- ---u ---- ---u LCDDATA22 PIC18F6XK90 PIC18F8XK90 xxxx xxx
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets EEADR PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu EEDATA PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu PIE6 PIC18F6XK90 PIC18F8XK90 ---0 -000 ---0 -000 ---u -uuu RTCCFG PIC18F6XK90 PIC18F8XK90 0-00 0000 u-uu uuuu u-uu uuuu RTCCAL PIC18F6XK90 PIC18F8XK90 0000 0000
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets CCPR10L PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu CCP10CON PIC18F6XK90 PIC18F8XK90 --00 0000 --00 0000 --uu uuuu TMR7H PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu TMR7L PIC18F6XK90 PIC18F8XK90 xxxx xxxx uuuu uuuu uuuu uuuu T7CON PIC18F6XK90 PIC18F8XK90 0000 0
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets SPBRGH2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu SPBRG2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu RCREG2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu TXREG2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu PSTR2CON PIC18F6XK90 PIC18F8XK90 00-
PIC18F87K90 FAMILY TABLE 5-2: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Applicable Devices Power-on Reset, Brown-out Reset MCLR Resets, WDT Reset, RESET Instruction, Stack Resets, CM Resets SSP2CON2 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu LCDREF PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu LCDRL PIC18F6XK90 PIC18F8XK90 0000 -000 0000 -000 uuuu -uuu LCDSE5 PIC18F6XK90 PIC18F8XK90 0000 0000 0000 0000 uuuu uuuu Register Wake-up via WDT or Interrupt
PIC18F87K90 FAMILY NOTES: DS39957D-page 84 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 6.0 MEMORY ORGANIZATION PIC18F87K90 family devices have these types of memory: • Program Memory • Data RAM • Data EEPROM As Harvard architecture devices, the data and program memories use separate busses. This enables concurrent access of the two memory spaces. FIGURE 6-1: The data EEPROM, for practical purposes, can be regarded as a peripheral device because it is addressed and accessed through a set of control registers.
PIC18F87K90 FAMILY 6.1 Program Memory Organization PIC18 microcontrollers implement a 21-bit Program Counter that is capable of addressing a 2-Mbyte program memory space. Accessing a location between the upper boundary of the physically implemented memory and the 2-Mbyte address will return all ‘0’s (a NOP instruction). The entire PIC18F87K90 family offers a range of on-chip Flash program memory sizes, from 32 Kbytes (up to 16,384 single-word instructions) to 128 Kbytes (65,536 single-word instructions).
PIC18F87K90 FAMILY 6.1.2 PROGRAM COUNTER The Program Counter (PC) specifies the address of the instruction to fetch for execution. The PC is 21 bits wide and contained in three separate 8-bit registers. The low byte, known as the PCL register, is both readable and writable. The high byte, or PCH register, contains the PC<15:8> bits and is not directly readable or writable. Updates to the PCH register are performed through the PCLATH register. The upper byte is called PCU.
PIC18F87K90 FAMILY 6.1.3.2 Return Stack Pointer (STKPTR) The STKPTR register (Register 6-1) contains the Stack Pointer value, the STKFUL (Stack Full) status bit and the STKUNF (Stack Underflow) status bits. The value of the Stack Pointer can be 0 through 31. The Stack Pointer increments before values are pushed onto the stack and decrements after values are popped off the stack. On Reset, the Stack Pointer value will be zero.
PIC18F87K90 FAMILY 6.1.3.4 Stack Full and Underflow Resets Device Resets on stack overflow and stack underflow conditions are enabled by setting the STVREN bit (CONFIG4L<0>). When STVREN is set, a full or underflow condition will set the appropriate STKFUL or STKUNF bit and then cause a device Reset. When STVREN is cleared, a full or underflow condition will set the appropriate STKFUL or STKUNF bit, but not cause a device Reset.
PIC18F87K90 FAMILY 6.2 6.2.2 PIC18 Instruction Cycle 6.2.1 An “Instruction Cycle” consists of four Q cycles, Q1 through Q4. The instruction fetch and execute are pipelined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. However, due to the pipelining, each instruction effectively executes in one cycle. If an instruction (such as GOTO) causes the Program Counter to change, two cycles are required to complete the instruction.
PIC18F87K90 FAMILY 6.2.3 INSTRUCTIONS IN PROGRAM MEMORY The program memory is addressed in bytes. Instructions are stored as two or four bytes in program memory. The Least Significant Byte (LSB) of an instruction word is always stored in a program memory location with an even address (LSB = 0). To maintain alignment with instruction boundaries, the PC increments in steps of two and the LSB will always read ‘0’ (see Section 6.1.2 “Program Counter”).
PIC18F87K90 FAMILY 6.3 Note: Data Memory Organization The operation of some aspects of data memory are changed when the PIC18 extended instruction set is enabled. See Section 6.6 “Data Memory and the Extended Instruction Set” for more information. The data memory in PIC18 devices is implemented as static RAM. Each register in the data memory has a 12-bit address, allowing up to 4,096 bytes of data memory. The memory space is divided into as many as 16 banks that contain 256 bytes each.
PIC18F87K90 FAMILY FIGURE 6-6: DATA MEMORY MAP FOR PIC18FX5K90 AND PIC18FX7K90 DEVICES BSR<3:0> Data Memory Map 00h = 0000 = 0001 = 0010 = 0011 = 0100 = 0101 = 0110 = 0111 = 1000 = 1001 = 1010 = 1011 = 1100 = 1101 = 1110 = 1111 Bank 0 FFh 00h Bank 1 Access RAM GPR GPR 1FFh 200h FFh 00h Bank 2 GPR FFh 00h Bank 3 2FFh 300h GPR FFh 00h Bank 4 The second 160 bytes are Special Function Registers (from Bank 15). When a = 1: 3FFh 400h The BSR specifies the bank used by the instruction.
PIC18F87K90 FAMILY FIGURE 6-7: USE OF THE BANK SELECT REGISTER (DIRECT ADDRESSING) BSR(1) 7 0 0 0 0 0 0 0 Bank Select(2) 1 0 000h Data Memory Bank 0 100h Bank 1 200h 300h Bank 2 00h 7 FFh 00h 1 From Opcode(2) 1 11 1 11 1 0 11 11 FFh 00h FFh 00h Bank 3 through Bank 13 E00h Bank 14 F00h FFFh Note 1: 2: 6.3.2 Bank 15 FFh 00h FFh The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to the registers of the Access Bank.
PIC18F87K90 FAMILY 6.3.4 SPECIAL FUNCTION REGISTERS The Special Function Registers (SFRs) are registers used by the CPU and peripheral modules for controlling the desired operation of the device. These registers are implemented as static RAM. SFRs start at the top of data memory (FFFh) and extend downward to occupy all of Bank 15 (F00h to FFFh) and the top part of Bank 14 (EF4h to EFFh). A list of these registers is given in Table 6-1 and Table 6-2.
PIC18F87K90 FAMILY TABLE 6-1: PIC18F87K90 FAMILY SPECIAL FUNCTION REGISTER MAP(5) (CONTINUED) Addr.
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR, BOR EF4h LCDCON LCDEN SLPEN WERR — CS1 CS0 LMUX1 LMUX0 000- 0000 EF5h LCDPS WFT BIASMD LCDA WA LP3 LP2 LP1 LP0 0000 0000 EF6h LCDSE0 SE07 SE06 SE05 SE04 SE03 SE02 SE01 SE00 0000 0000 EF7h LCDSE1 SE15 SE14 SE13 SE12 SE11 SE10 SE09 SE08 0000 0000 EF8h LCDSE2 SE23 SE22 SE21 SE20 SE19 SE18 SE17 SE16
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR, BOR F24h ANCON1 ANSEL15 ANSEL14 ANSEL13 ANSEL12 ANSEL11 ANSEL10 ANSEL9 ANSEL8 1111 1111 F25h ANCON0 ANSEL7 ANSEL6 ANSEL5 ANSEL4 ANSEL3 ANSEL2 ANSEL1 ANSEL0 1111 1111 F26h — — — — — — — — — — F27h ODCON3 U2OD U1OD — — — — — CTMUDS 00-- ---0 F28h ODCON2 F29H ODCON1 CCP10OD(3) CCP9OD(3) CCP
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 Bit 4 Value on POR, BOR Bit 3 Bit 2 Bit 1 Bit 0 P2DC3 P2DC2 P2DC1 P2DC0 PSS2AC1 PSS2AC0 PSS2BD1 PSS2BD0 0000 0000 — 000- -00- F50h CCPR2H F51h ECCP2DEL Capture/Compare/PWM Register 2 High Byte F52h ECCP2AS F53h PADCFG1 F54h CM1CON CON F55h CTMUICON ITRIM5 F56h CTMUCONL EDG2POL F57h CTMUCONH CTMUEN F58h ALRMVALL Alarm Value High Register Window b
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR, BOR F81h PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 xxxx xxxx F82h PORTC RC7 RC6 RC5 RC4 RC3 RC2 RC1 RC0 xxxx xxxx F83h PORTD RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 xxxx xxxx F84h PORTE RE7 RE6 RE5 RE4 RE3 RE2 RE1 RE0 xxxx xxxx F85h PORTF RF7 RF6 RF5 RF4 RF3 RF2 RF1 — xxxx xxx- F86h PORTG —
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Value on POR, BOR TMR3GE T3GPOL T3GTM T3GSPM T3GGO/ T3DONE T3GVAL T3GSS1 T3GSS0 0000 0x00 TMR3CS1 TMR3CS0 T3CKPS1 T3CKPS0 SOSCEN T3SYNC RD16 TMR3ON FB0h T3GCON FB1h T3CON FB2h TMR3L Timer3 Register Low Byte FB3h TMR3H Timer3 Register High Byte FB4h CMSTAT CMP3OUT CMP2OUT 0000 0000 xxxx xxxx xxxx xxxx CMP1OUT — — —
PIC18F87K90 FAMILY TABLE 6-2: Address PIC18F87K90 FAMILY REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Uses contents of FSR2 to address data memory – value of FSR2 not changed (not a physical register) Value on POR, BOR FDFh INDF2 FE0h BSR FE1h FSR1L FE2h FSR1H FE3h PLUSW1 Uses contents of FSR1 to address data memory – value of FSR1 pre-incremented (not a physical register) – value of FSR1 offset by W ---- ---- FE4h PREINC1 Uses conten
PIC18F87K90 FAMILY 6.3.5 STATUS REGISTER The STATUS register, shown in Register 6-2, contains the arithmetic status of the ALU. The STATUS register can be the operand for any instruction, as with any other register. If the STATUS register is the destination for an instruction that affects the Z, DC, C, OV or N bits, the write to these five bits is disabled. These bits are set or cleared according to the device logic.
PIC18F87K90 FAMILY 6.4 Data Addressing Modes Note: The execution of some instructions in the core PIC18 instruction set are changed when the PIC18 extended instruction set is enabled. For more information, see Section 6.6 “Data Memory and the Extended Instruction Set”. While the program memory can be addressed in only one way, through the Program Counter, information in the data memory space can be addressed in several ways. For most instructions, the addressing mode is fixed.
PIC18F87K90 FAMILY 6.4.3.1 FSR Registers and the INDF Operand are mapped in the SFR space, but are not physically implemented. Reading or writing to a particular INDF register actually accesses its corresponding FSR register pair. A read from INDF1, for example, reads the data at the address indicated by FSR1H:FSR1L. At the core of Indirect Addressing are three sets of registers: FSR0, FSR1 and FSR2. Each represents a pair of 8-bit registers: FSRnH and FSRnL.
PIC18F87K90 FAMILY 6.4.3.2 FSR Registers and POSTINC, POSTDEC, PREINC and PLUSW In addition to the INDF operand, each FSR register pair also has four additional indirect operands. Like INDF, these are “virtual” registers that cannot be indirectly read or written to. Accessing these registers actually accesses the associated FSR register pair, but also performs a specific action on its stored value.
PIC18F87K90 FAMILY 6.6 Data Memory and the Extended Instruction Set Enabling the PIC18 extended instruction set (XINST Configuration bit = 1) significantly changes certain aspects of data memory and its addressing. Using the Access Bank for many of the core PIC18 instructions introduces a new addressing mode for the data memory space. This mode also alters the behavior of Indirect Addressing using FSR2 and its associated operands.
PIC18F87K90 FAMILY FIGURE 6-9: COMPARING ADDRESSING OPTIONS FOR BIT-ORIENTED AND BYTE-ORIENTED INSTRUCTIONS (EXTENDED INSTRUCTION SET ENABLED) EXAMPLE INSTRUCTION: ADDWF, f, d, a (Opcode: 0010 01da ffff ffff) When a = 0 and f 60h: The instruction executes in Direct Forced mode. ‘f’ is interpreted as a location in the Access RAM, between 060h and FFFh. This is the same as locations, F60h to FFFh (Bank 15), of data memory. Locations below 060h are not available in this addressing mode.
PIC18F87K90 FAMILY 6.6.3 MAPPING THE ACCESS BANK IN INDEXED LITERAL OFFSET MODE The use of Indexed Literal Offset Addressing mode effectively changes how the lower part of Access RAM (00h to 5Fh) is mapped. Rather than containing just the contents of the bottom part of Bank 0, this mode maps the contents from Bank 0 and a user-defined “window” that can be located anywhere in the data memory space.
PIC18F87K90 FAMILY NOTES: DS39957D-page 110 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 7.0 FLASH PROGRAM MEMORY 7.1 Table Reads and Table Writes The Flash program memory is readable, writable and erasable during normal operation over the entire VDD range. In order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data RAM: A read from program memory is executed on one byte at a time.
PIC18F87K90 FAMILY FIGURE 7-2: TABLE WRITE OPERATION Instruction: TBLWT* Program Memory Holding Registers Table Pointer(1) TBLPTRU TBLPTRH Table Latch (8-bit) TBLPTRL TABLAT Program Memory (TBLPTR) Note 1: The Table Pointer actually points to one of 64 holding registers; the address of which is determined by TBLPTRL<5:0>. The process for physically writing data to the program memory array is discussed in Section 7.5 “Writing to Flash Program Memory”. 7.
PIC18F87K90 FAMILY REGISTER 7-1: R/W-x EEPGD EECON1: EEPROM CONTROL REGISTER 1 R/W-x U-0 R/W-0 R/W-x R/W-0 R/S-0 R/S-0 CFGS — FREE WRERR(1) WREN WR RD bit 7 bit 0 Legend: S = Settable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 EEPGD: Flash Program or Data EEPROM Memory Select bit 1 = Access Flash program memory 0 = Access data EEPROM memory bit 6 CFGS: Flash Program/Dat
PIC18F87K90 FAMILY 7.2.2 TABLAT – TABLE LATCH REGISTER 7.2.4 The Table Latch (TABLAT) is an 8-bit register mapped into the SFR space. The Table Latch register is used to hold 8-bit data during data transfers between program memory and data RAM. 7.2.3 The TBLPTR is used in reads, writes and erases of the Flash program memory. When a TBLRD is executed, all 22 bits of the TBLPTR determine which byte is read from program memory into the TABLAT.
PIC18F87K90 FAMILY 7.3 Reading the Flash Program Memory The TBLRD instruction is used to retrieve data from program memory and places it into data RAM. Table reads from program memory are performed one byte at a time. FIGURE 7-4: The TBLPTR points to a byte address in program memory space. Executing TBLRD places the byte pointed to into TABLAT. In addition, TBLPTR can be modified automatically for the next table read operation. The internal program memory is typically organized by words.
PIC18F87K90 FAMILY 7.4 Erasing Flash Program Memory The erase block is 32 words or 64 bytes for the PIC18FX5K90 and PIC18FX6K90 devices, and 64 words or 128 bytes for the PIC18FX7K90 devices. Word erase in the Flash array is not supported. When initiating an erase sequence from the microcontroller itself, a block of 64 or 128 bytes of program memory is erased. The Most Significant 16 bits of the TBLPTR<21:6> point to the block being erased. The TBLPTR<5:0> bits are ignored.
PIC18F87K90 FAMILY 7.5 Writing to Flash Program Memory The programming block is 32 words or 64 bytes for PIC18FX5K90 and PIC18FX6K90 devices, and 64 words or 128 bytes for PIC18FX7K90 devices. Word or byte programming is not supported. Table writes are used internally to load the holding registers needed to program the Flash memory. There are 64 holding registers for PIC18FX5K90 and PIC18FX6K90 devices and 128 holding registers for PIC18FX7K90 used by the table writes for programming.
PIC18F87K90 FAMILY EXAMPLE 7-3: WRITING TO FLASH PROGRAM MEMORY MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF SIZE_OF_BLOCK COUNTER BUFFER_ADDR_HIGH FSR0H BUFFER_ADDR_LOW FSR0L CODE_ADDR_UPPER TBLPTRU CODE_ADDR_HIGH TBLPTRH CODE_ADDR_LOW TBLPTRL ; number of bytes in erase block TBLRD*+ MOVF MOVWF DECFSZ BRA TABLAT, W POSTINC0 COUNTER READ_BLOCK MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF DATA_ADDR_HIGH FSR0H DATA_ADDR_LOW FSR0L NEW_DATA_LOW POSTINC0 NEW_DATA_HIGH INDF0
PIC18F87K90 FAMILY EXAMPLE 7-3: WRITING TO FLASH PROGRAM MEMORY (CONTINUED) PROGRAM_MEMORY BSF BCF BSF BCF MOVLW MOVWF MOVLW MOVWF BSF BSF BCF Required Sequence 7.5.
PIC18F87K90 FAMILY NOTES: DS39957D-page 120 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 8.0 DATA EEPROM MEMORY The data EEPROM is a nonvolatile memory array, separate from the data RAM and program memory, that is used for long-term storage of program data. The PIC18F87K90 family of devices has a 1024-byte data EEPROM. It is not directly mapped in either the register file or program memory space, but is indirectly addressed through the Special Function Registers (SFRs). The EEPROM is readable and writable during normal operation over the entire VDD range.
PIC18F87K90 FAMILY REGISTER 8-1: R/W-x EEPGD EECON1: DATA EEPROM CONTROL REGISTER 1 R/W-x U-0 R/W-0 R/W-x R/W-0 R/S-0 R/S-0 CFGS — FREE WRERR(1) WREN WR RD bit 7 bit 0 Legend: S = Settable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 EEPGD: Flash Program or Data EEPROM Memory Select bit 1 = Access Flash program memory 0 = Access data EEPROM memory bit 6 CFGS: Flash Progra
PIC18F87K90 FAMILY 8.3 Reading the Data EEPROM Memory To read a data memory location, the user must write the address to the EEADRH:EEADR register pair, clear the EEPGD control bit (EECON1<7>) and then set control bit, RD (EECON1<0>). After one cycle, the data is available in the EEDATA register; therefore, it can be read after one NOP instruction. EEDATA will hold this value until another read operation, or until it is written to by the user (during a write operation).
PIC18F87K90 FAMILY 8.6 Operation During Code-Protect Data EEPROM memory has its own code-protect bits in the Configuration Words. External read and write operations are disabled if code protection is enabled. The microcontroller itself can both read and write to the internal data EEPROM, regardless of the state of the code-protect Configuration bit. Refer to Section 28.0 “Special Features of the CPU” for additional information. 8.
PIC18F87K90 FAMILY TABLE 8-1: Name INTCON EEADRH REGISTERS ASSOCIATED WITH DATA EEPROM MEMORY Bit 7 Bit 6 GIE/GIEH PEIE/GIEL — — Bit 5 Bit 4 Bit 3 Bit 2 TMR0IE INT0IE RBIE TMR0IF — — — — Bit 1 Bit 0 Reset Values on Page: INT0IF RBIF 75 EEPROM Address Register High Byte 79 EEADR EEPROM Address Register Low Byte 80 EEDATA EEPROM Data Register 80 EECON2 EEPROM Control Register 2 (not a physical register) EECON1 EEPGD CFGS — FREE WRERR 79 WREN WR RD 79 Legend: — = unim
PIC18F87K90 FAMILY NOTES: DS39957D-page 126 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 9.0 8 x 8 HARDWARE MULTIPLIER 9.1 Introduction EXAMPLE 9-1: MOVF MULWF All PIC18 devices include an 8 x 8 hardware multiplier as part of the ALU. The multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, PRODH:PRODL. The multiplier’s operation does not affect any flags in the STATUS register.
PIC18F87K90 FAMILY Example 9-3 shows the sequence to do a 16 x 16 unsigned multiplication. Equation 9-1 shows the algorithm that is used. The 32-bit result is stored in four registers (RES3:RES0).
PIC18F87K90 FAMILY 10.0 INTERRUPTS Members of the PIC18F87K90 family of devices have multiple interrupt sources and an interrupt priority feature that allows most interrupt sources to be assigned a high-priority level or a low-priority level. The high-priority interrupt vector is at 0008h and the low-priority interrupt vector is at 0018h. High-priority interrupt events will interrupt any low-priority interrupts that may be in progress.
PIC18F87K90 FAMILY FIGURE 10-1: PIC18F87K90 FAMILY INTERRUPT LOGIC PIR1<6:0> PIE1<6:0> IPR1<6:0> PIR2<7,5:0> PIE2<7,5:0> IPR2<7:7,5:0> PIR3<6:0> PIE3<6:0> IPR3<6:0> PIR3<7:0> PIE3<7:0> IPR3<7:0> PIR5<7:0> PIE5<7:0> IPR5<7:0> Wake-up if in Idle or Sleep modes TMR0IF TMR0IE TMR0IP RBIF RBIE RBIP INT0IF INT0IE INT1IF INT1IE INT1IP INT2IF INT2IE INT2IP INT3IF INT3IE INT3IP Interrupt to CPU Vector to Location 0008h GIE/GIEH IPEN PIR6<4,2:0> PIE6<4,2:0> IPR6<4,2:0> IPEN PEIE/GIEL IPEN High-Priority Inter
PIC18F87K90 FAMILY 10.1 INTCON Registers Note: The INTCON registers are readable and writable registers that contain various enable, priority and flag bits. REGISTER 10-1: Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the Global Interrupt Enable bit. User software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature allows for software polling.
PIC18F87K90 FAMILY REGISTER 10-2: INTCON2: INTERRUPT CONTROL REGISTER 2 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 RBPU INTEDG0 INTEDG1 INTEDG2 INTEDG3 TMR0IP INT3IP RBIP bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 RBPU: PORTB Pull-up Enable bit 1 = All PORTB pull-ups are disabled 0 = PORTB pull-ups are enabled by individual TRIS register values bit
PIC18F87K90 FAMILY REGISTER 10-3: INTCON3: INTERRUPT CONTROL REGISTER 3 R/W-1 R/W-1 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 INT2IP INT1IP INT3IE INT2IE INT1IE INT3IF INT2IF INT1IF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 INT2IP: INT2 External Interrupt Priority bit 1 = High priority 0 = Low priority bit 6 INT1IP: INT1 External Interrupt Priority bit 1 = High priority 0 = Low
PIC18F87K90 FAMILY 10.2 PIR Registers The PIR registers contain the individual flag bits for the peripheral interrupts. Due to the number of peripheral interrupt sources, there are six Peripheral Interrupt Request (Flag) registers (PIR1 through PIR6). Note 1: Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the Global Interrupt Enable bit, GIE (INTCON<7>).
PIC18F87K90 FAMILY REGISTER 10-5: PIR2: PERIPHERAL INTERRUPT REQUEST (FLAG) REGISTER 2 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 OSCFIF — SSP2IF BCL2IF BCL1IF HLVDIF TMR3IF TMR3GIF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 OSCFIF: Oscillator Fail Interrupt Flag bit 1 = Device oscillator failed, clock input has changed to INTOSC (must be cleared in so
PIC18F87K90 FAMILY REGISTER 10-6: PIR3: PERIPHERAL INTERRUPT REQUEST (FLAG) REGISTER 3 R/W-0 R/W-0 R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 TMR5GIF LCDIF RC2IF TX2IF CTMUIF CCP2IF CCP1IF RTCCIF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 TMR5GIF: Timer5 Gate Interrupt Flag bit 1 = Timer gate interrupt occurred (must be cleared in software) 0 = No timer gate interru
PIC18F87K90 FAMILY REGISTER 10-7: R/W-0 CCP10IF (1) PIR4: PERIPHERAL INTERRUPT FLAG REGISTER 4 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CCP9IF(1) CCP8IF CCP7IF CCP6IF CCP5IF CCP4IF CCP3IF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-1 CCP10IF:CCP4IF: CCP<10:4> Interrupt Flag bits(1) Capture Mode 1 = A TMR register capture occurred (must be cleared in softwar
PIC18F87K90 FAMILY REGISTER 10-8: R/W-0 PIR5: PERIPHERAL INTERRUPT FLAG REGISTER 5 R/W-0 TMR7GIF (1) TMR12IF R/W-0 (1) TMR10IF R/W-0 (1) TMR8IF R/W-0 TMR7IF (1) R/W-0 R/W-0 R/W-0 TMR6IF TMR5IF TMR4IF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 TMR7GIF: TMR7 Gate Interrupt Flag bits(1) 1 = TMR gate interrupt occurred (must be cleared in software) 0 = No TMR
PIC18F87K90 FAMILY REGISTER 10-9: PIR6: PERIPHERAL INTERRUPT FLAG REGISTER 6 U-0 U-0 U-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 — — — EEIF — CMP3IF CMP2IF CMP1IF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 Unimplemented: Read as ‘0’ bit 4 EEIF: Data EEDATA/Flash Write Operation Interrupt Flag bit 1 = The write operation is complete (must be cleared in software) 0 = The write operati
PIC18F87K90 FAMILY 10.3 PIE Registers The PIE registers contain the individual enable bits for the peripheral interrupts. Due to the number of peripheral interrupt sources, there are six Peripheral Interrupt Enable registers (PIE1 through PIE6). When IPEN (RCON<7>) = 0, the PEIE bit must be set to enable any of these peripheral interrupts.
PIC18F87K90 FAMILY REGISTER 10-11: PIE2: PERIPHERAL INTERRUPT ENABLE REGISTER 2 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 OSCFIE — SSP2IE BCL2IE BCL1IE HLVDIE TMR3IE TMR3GIE bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 OSCFIE: Oscillator Fail Interrupt Enable bit 1 = Enabled 0 = Disabled bit 6 Unimplemented: Read as ‘0’ bit 5 SSP2IE: Master Synchronous Serial Port 2 Inte
PIC18F87K90 FAMILY REGISTER 10-12: PIE3: PERIPHERAL INTERRUPT ENABLE REGISTER 3 R/W-0 R/W-0 TMR5GIE LCDIE (1) R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 RC2IE TX2IE CTMUIE CCP2IE CCP1IE RTCCIE bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 TMR5GIE: Timer5 Gate Interrupt Enable bit 1 = Enabled 0 = Disabled bit 6 LCDIE: LCD Interrupt Enable bit(1) 1 = Enabled 0 = Disabled bit 5 RC2IE: AUS
PIC18F87K90 FAMILY REGISTER 10-14: PIE5: PERIPHERAL INTERRUPT ENABLE REGISTER 5 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 TMR7GIE(1) TMR12IE(1) TMR10IE(1) TMR8IE TMR7IE(1) TMR6IE TMR5IE TMR4IE bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 TMR7GIE: TMR7 Gate Interrupt Enable bit(1) 1 = Enabled 0 = Disabled bit 6 TMR12IE: TMR12 to PR12 Match Interrupt Enable bit(1) 1 = Enab
PIC18F87K90 FAMILY REGISTER 10-15: PIE6: PERIPHERAL INTERRUPT ENABLE REGISTER 6 U-0 U-0 U-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 — — — EEIE — CMP3IE CMP2IE CMP1IE bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 Unimplemented: Read as ‘0’ bit 4 EEIE: Data EEDATA/Flash Write Operation Enable bit 1 = Interrupt is enabled 0 = interrupt is disabled bit 3 Unimplemented: Read as ‘0’ bit 2
PIC18F87K90 FAMILY 10.4 IPR Registers The IPR registers contain the individual priority bits for the peripheral interrupts. Due to the number of peripheral interrupt sources, there are six Peripheral Interrupt Priority registers (IPR1 through IPR6). Using the priority bits requires that the Interrupt Priority Enable (IPEN) bit (RCON<7>) be set.
PIC18F87K90 FAMILY REGISTER 10-17: IPR2: PERIPHERAL INTERRUPT PRIORITY REGISTER 2 R/W-1 U-0 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 OSCFIP — SSP2IP BCL2IP BCL1IP HLVDIP TMR3IP TMR3GIP bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 OSCFIP: Oscillator Fail Interrupt Priority bit 1 = High priority 0 = Low priority bit 6 Unimplemented: Read as ‘0’ bit 5 SSP2IP: Master Synchronous Seri
PIC18F87K90 FAMILY REGISTER 10-18: IPR3: PERIPHERAL INTERRUPT PRIORITY REGISTER 3 R/W-1 R/W-1 R-1 R-1 R/W-1 R/W-1 R/W-1 R/W-1 TMR5GIP LCDIP RC2IP TX2IP CTMUIP CCP2IP CCP1IP RTCCIP bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 TMR5GIP: Timer5 Gate interrupt Priority bit 1 = High priority 0 = Low priority bit 6 LCDIP: LCD Interrupt Priority bit (valid when the
PIC18F87K90 FAMILY REGISTER 10-20: IPR5: PERIPHERAL INTERRUPT PRIORITY REGISTER 5 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 TMR7GIP(1) TMR12IP(1) TMR10IP(1) TMR8IP TMR7IP(1) TMR6IP TMR5IP TMR4IP bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 TMR7GIP: TMR7 Gate Interrupt Priority bit(1) 1 = High priority 0 = Low priority bit 6 TMR12IP: TMR12 to PR12 Match Interrupt Priority
PIC18F87K90 FAMILY REGISTER 10-21: IPR6: PERIPHERAL INTERRUPT PRIORITY REGISTER 6 U-0 U-0 U-0 R/W-1 U-0 R/W-1 R/W-1 R/W-1 — — — EEIP — CMP3IP CMP2IP CMP1IP bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 Unimplemented: Read as ‘0’ bit 4 EEIP: EE Interrupt Priority bit 1 = High priority 0 = Low priority bit 3 SBOREN: Read as ‘0’ bit 2 CMP3IP: CMP3 Interrupt Priority bit 1 =
PIC18F87K90 FAMILY 10.5 RCON Register The RCON register contains the bits used to determine the cause of the last Reset, or wake-up from Idle or Sleep modes. RCON also contains the bit that enables interrupt priorities (IPEN).
PIC18F87K90 FAMILY 10.6 INTx Pin Interrupts External interrupts on the RB0/INT0, RB1/INT1, RB2/INT2 and RB3/INT3 pins are edge-triggered. If the corresponding INTEDGx bit in the INTCON2 register is set (= 1), the interrupt is triggered by a rising edge. If that bit is clear, the trigger is on the falling edge. When a valid edge appears on the RBx/INTx pin, the corresponding flag bit, INTxIF, is set. This interrupt can be disabled by clearing the corresponding enable bit, INTxIE.
PIC18F87K90 FAMILY TABLE 10-1: Name SUMMARY OF REGISTERS ASSOCIATED WITH INTERRUPTS Bit 6 INTCON GIE/GIEH PEIE/GIEL TMR0IE INTCON2 RBPU INTEDG0 INTEDG1 INTCON3 INT2IP INT1IP INT3IE INT2IE INT1IE INT3IF INT2IF INT1IF 75 — ADIF RC1IF TX1IF SSP1IF TMR1GIF TMR2IF TMR1IF 77 PIR1 Bit 5 Bit 4 Bit 3 INT0IE RBIE Bit 2 INTEDG2 INTEDG3 Bit 1 Bit 0 Reset Values on Page: Bit 7 TMR0IF INT0IF RBIF 75 TMR0IP INT3IP RBIP 75 PIR2 OSCFIF — SSP2IF BCL2IF BCL1IF HLVDIF TMR
PIC18F87K90 FAMILY 11.0 I/O PORTS 11.1 Depending on the device selected and features enabled, there are up to nine ports available. Some pins of the I/O ports are multiplexed with an alternate function from the peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin.
PIC18F87K90 FAMILY 11.1.3 OPEN-DRAIN OUTPUTS FIGURE 11-2: The output pins for several peripherals are also equipped with a configurable, open-drain output option. This allows the peripherals to communicate with external digital logic, operating at a higher voltage level, without the use of level translators. USING THE OPEN-DRAIN OUTPUT (USART SHOWN AS EXAMPLE) 3.
PIC18F87K90 FAMILY REGISTER 11-2: R/W-0 (1) CCP10OD ODCON2: PERIPHERAL OPEN-DRAIN CONTROL REGISTER 2 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CCP9OD(1) CCP8OD CCP7OD CCP6OD CCP5OD CCP4OD CCP3OD bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 CCP10OD: CCP10 Open-Drain Output Enable bit(1) 1 = Open-drain capability is enabled 0 = Open-drain capability is disabled bit 6 CCP9OD: CCP
PIC18F87K90 FAMILY REGISTER 11-3: R/W-0 U2OD ODCON3: PERIPHERAL OPEN-DRAIN CONTROL REGISTER 3 R/W-0 U-0 U-0 U-0 U-0 U-0 R/W-0 U1OD — — — — — CTMUDS bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 U2OD: EUSART2 Open-Drain Output Enable bit 1 = Open-drain capability is enabled 0 = Open-drain capability is disabled bit 6 U1OD: EUSART1 Open-Drain Output Enable bit 1 = Open-drain capab
PIC18F87K90 FAMILY 11.2 PORTA, TRISA and LATA Registers PORTA is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISA and LATA. RA4/T0CKI is a Schmitt Trigger input. All other PORTA pins have TTL input levels and full CMOS output drivers. The RA4 pin is multiplexed with the Timer0 clock input and one of the LCD segment drives. RA5 and RA<3:0> are multiplexed with analog inputs for the A/D Converter.
PIC18F87K90 FAMILY TABLE 11-1: PORTA FUNCTIONS Pin Name Function TRIS Setting I/O I/O Type RA0/AN0/ULPWU RA0 0 O DIG 1 I TTL PORTA<0> data input; disabled when analog input is enabled. AN0 1 I ANA A/D Input Channel 0. Default input configuration on POR; does not affect digital output. ULPWU 1 I ANA Ultra Low-Power Wake-up (ULPWU) input. RA1 0 O DIG LATA<1> data output; not affected by analog input. 1 I TTL PORTA<1> data input; disabled when analog input is enabled.
PIC18F87K90 FAMILY TABLE 11-2: Name SUMMARY OF REGISTERS ASSOCIATED WITH PORTA Bit 6 RA7(1) RA6(1) RA5 RA4 RA3 RA2 RA1 RA0 78 LATA LATA7 LATA6(1) LATA5 LATA4 LATA3 LATA2 LATA1 LATA0 78 TRISA TRISA7(1) TRISA6(1) TRISA5 TRISA4 TRISA3 TRISA2 TRISA1 TRISA0 78 ANCON1 ANSEL15 ANSEL14 ANSEL13 ANSEL12 ANSEL11 ANSEL10 PORTA (1) Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: Bit 7 ANSEL9 ANSEL8 81 LCDSE1 SE15 SE14 SE13 SE12 SE11 SE10 SE09 SE08 83 LCDSE2
PIC18F87K90 FAMILY 11.3 PORTB, TRISB and LATB Registers PORTB is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISB and LATB. All pins on PORTB are digital only.
PIC18F87K90 FAMILY TABLE 11-3: Pin Name RB0/INT0/SEG30/ FLT0 RB1/INT1/SEG8 RB2/INT2/SEG9/ CTED1 RB3/INT3/SEG10/ CTED2/ECCP2/ P2A RB4/KBI0/SEG11 RB5/KBI1/SEG29/ T3CKI/T1G RB6/KBI2/PGC RB7/KBI3/PGD Legend: PORTB FUNCTIONS Function TRIS Setting I/O I/O Type RB0 0 O DIG 1 I TTL PORTB<0> data input; weak pull-up when RBPU bit is cleared. INT0 1 I ST External Interrupt 0 input. SEG30 1 O ANA Description LATB<0> data output. LCD Segment 30 output; disables all other pin functions.
PIC18F87K90 FAMILY TABLE 11-4: SUMMARY OF REGISTERS ASSOCIATED WITH PORTB Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: PORTB RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 78 LATB LATB7 LATB6 LATB5 LATB4 LATB3 LATB2 LATB1 LATB0 78 TRISB TRISB7 TRISB6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0 78 TMR0IE INT0IE RBIE INTCON GIE/GIEH PEIE/GIEL INTCON2 RBPU INTEDG0 INTCON3 INT2IP INT1IP INT3IE INT2IE LCDSE1 SE15 SE14 SE13 SE12 LCDSE3 SE31
PIC18F87K90 FAMILY 11.4 PORTC, TRISC and LATC Registers PORTC is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISC and LATC. Only PORTC pins, RC2 through RC7, are digital only pins. PORTC is multiplexed with ECCP, MSSP and EUSART peripheral functions (Table 11-5). The pins have Schmitt Trigger input buffers. The pins for ECCP, SPI and EUSART are also configurable for open-drain output whenever these functions are active.
PIC18F87K90 FAMILY TABLE 11-5: PORTC FUNCTIONS Pin Name Function TRIS Setting I/O I/O Type RC0/SOSCO/ SCLKI/ RC0 0 O DIG LATC<0> data output. PORTC<0> data input. RC1/SOSCI/ ECCP2/P2A/ SEG32 1 I ST SOSCO 1 I ST SCLKI x O ANA Digital clock input; enabled when SOSC oscillator is disabled. RC1 0 O DIG LATC<1> data output. 1 I ST PORTC<1> data input. SOSCI x I ANA SOSC oscillator input.
PIC18F87K90 FAMILY TABLE 11-5: PORTC FUNCTIONS (CONTINUED) Pin Name Function TRIS Setting I/O I/O Type RC7/RX1/DT1/ SEG28 RC7 0 O DIG LATC<7> data output. PORTC<7> data input. 1 I ST RX1 1 I ST Asynchronous serial receive data input (EUSART module). DT1 1 O DIG Synchronous serial data output (EUSART module); takes priority over port data. 1 I ST Synchronous serial data input (EUSART module); user must configure as an input.
PIC18F87K90 FAMILY 11.5 PORTD, TRISD and LATD Registers PORTD is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISD and LATD. All pins on PORTD are implemented with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. Note: These pins are configured as digital inputs on any device Reset. Each of the PORTD pins has a weak internal pull-up. A single control bit can turn off all the pull-ups.
PIC18F87K90 FAMILY TABLE 11-7: Pin Name RD0/SEG0/ CTPLS PORTD FUNCTIONS Function TRIS Setting I/O I/O Type RD0 0 O DIG SEG0 RD1/SEG1/ T5CKI/T7G RD2/SEG2 RD3/SEG3 RD4/SEG4/ SDO2 RD5/SEG5/ SDI2/SDA2 RD6/SEG6/ SCK2/SCL2 Legend: I ST 1 O ANA LATD<0> data output. PORTD<0> data input. LCD Segment 0 output; disables all other pin functions. CTPLS x O DIG CTMU pulse generator output. RD1 0 O DIG LATD<1> data output. 1 I ST SEG1 1 O ANA T5CKI x I ST Timer5 clock input.
PIC18F87K90 FAMILY TABLE 11-8: Name PORTD SUMMARY OF REGISTERS ASSOCIATED WITH PORTD Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0 78 LATD LATD7 LATD6 LATD5 LATD4 LATD3 LATD2 LATD1 LATD0 78 TRISD TRISD7 TRISD6 TRISD5 TRISD4 TRISD3 TRISD2 TRISD1 TRISD0 78 SE02 SE01 SE00 83 — 80 LCDSE0 SE07 SE06 SE05 SE04 SE03 PADCFG1 RDPU REPU RJPU(1) — — RTSECSEL1 RTSECSEL0 Legend: Shaded cells are not used by P
PIC18F87K90 FAMILY 11.6 PORTE, TRISE and LATE Registers PORTE is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISE and LATE. All pins on PORTE are implemented with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. The RE7 pin is also configurable for open-drain output when ECCP2 is active on this pin.
PIC18F87K90 FAMILY TABLE 11-10: PORTE FUNCTIONS Pin Name Function TRIS Setting I/O I/O Type RE0/LCDBIAS1/ P2D RE0 0 O DIG LATE<0> data output. 1 I ST PORTE<0> data input. LCDBIAS1 — I ANA P2D 0 O — RE1 0 O DIG LATE<1> data output. 1 I ST PORTE<1> data input.
PIC18F87K90 FAMILY TABLE 11-10: PORTE FUNCTIONS (CONTINUED) Pin Name RE7/ECCP2/ P2A/SEG31 Function TRIS Setting I/O I/O Type RE7 0 O DIG ECCP2(1) Legend: Note 1: 2: Description LATE<7> data output. 1 I ST PORTE<7> data input. 0 O DIG ECCP2 compare/PWM output; takes priority over port data. 1 I ST ECCP2 capture input. P2A 0 O — ECCP2 PWM Output A. May be configured for tri-state during Enhanced PWM shutdown event.
PIC18F87K90 FAMILY 11.7 PORTF, LATF and TRISF Registers PORTF is a 7-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISF and LATF. All pins on PORTF are implemented with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. PORTF is multiplexed with analog peripheral functions, as well as LCD segments.
PIC18F87K90 FAMILY TABLE 11-12: PORTF FUNCTIONS Pin Name Function TRIS Setting I/O I/O Type RF1/AN6/C2OUT/ SEG19/CTDIN RF1 0 O DIG 1 I ST 1 I ANA AN6 RF2/AN7/C1OUT/ SEG20 RF4/AN9/SEG22/ C2INA RF5/AN10/CVREF/ SEG23/C1INB RF6/AN11/SEG24/ C1INA Legend: PORTF<1> data input; disabled when analog input is enabled. A/D Input Channel 6; default configuration on POR. 0 O DIG Comparator 2 output; takes priority over port data.
PIC18F87K90 FAMILY TABLE 11-13: SUMMARY OF REGISTERS ASSOCIATED WITH PORTF Name PORTF Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: RF7 RF6 RF5 RF4 RF3 RF2 RF1 — 78 78 LATF LATF7 LATF6 LATF5 LATF4 LATF3 LATF2 LATF1 — TRISF TRISF7 TRISF6 TRISF5 TRISF4 TRISF3 TRISF2 TRISF1 — 78 ANSEL4 ANSEL3 ANSEL2 ANCON0 ANSEL7 ANSEL6 ANSEL5 ANSEL1 ANSEL0 81 ANCON1 ANSEL15 ANSEL14 ANSEL13 ANSEL12 ANSEL11 ANSEL10 ANSEL9 ANSEL8 81 CMSTAT CMP3OUT CMP
PIC18F87K90 FAMILY 11.8 PORTG, TRISG and LATG Registers PORTG is a 5-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISG and LATG. PORTG is multiplexed with EUSART, LCD and CCP/ECCP/Analog/Comparator/RTCC/Timer input functions (Table 11-14). When operating as I/O, all PORTG pins have Schmitt Trigger input buffers. The open-drain functionality for the CCPx and UART can be configured using ODCONx.
PIC18F87K90 FAMILY TABLE 11-14: PORTG FUNCTIONS (CONTINUED) Pin Name Function TRIS Setting I/O I/O Type RG2 0 O DIG LATG<2> data output. PORTG<2> data input. RG2/RX2/DT2/ AN18/C3INA 1 I ST RX2 1 I ST Asynchronous serial receive data input (EUSART module). DT2 1 O DIG Synchronous serial data output (EUSART module); takes priority over port data. 1 I ST Synchronous serial data input (EUSART module); user must configure as an input. AN18 1 I ANA A/D Input Channel 18.
PIC18F87K90 FAMILY 11.9 Note: PORTH, LATH and TRISH Registers PORTH is available only on the 80-pin devices. PORTH is an 8-bit wide, bidirectional I/O port. The corresponding Data Direction and Output Latch registers are TRISH and LATH. All pins on PORTH are implemented with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. All PORTH pins are multiplexed with the ADC/CCP/Comparator and LCD segment drives controlled by the LCDSE5 register.
PIC18F87K90 FAMILY TABLE 11-16: PORTH FUNCTIONS Pin Name Function TRIS Setting I/O I/O Type RH0 0 O DIG RH0/SEG47/ AN23 1 I ST 1 O ANA LCD Segment 47 output; disables all other pin functions. AN23 1 I ANA A/D Input Channel 23. Default input configuration on POR; does not affect digital input. RH1 0 O DIG LATH<1> data output. 1 I ST SEG46 1 O ANA LCD Segment 46 output; disables all other pin functions. AN22 1 I ANA A/D Input Channel 22.
PIC18F87K90 FAMILY TABLE 11-16: PORTH FUNCTIONS (CONTINUED) Pin Name RH6/SEG42/ CCP7/P1C/ AN14/C1INC RH7/SEG43/ CCP6/P1B/ AN15 Legend: Function TRIS Setting I/O I/O Type RH6 0 O DIG Description LATH<6> data output. 1 I ST SEG42 1 O ANA LCD Segment 42 output; disables all other pin functions. PORTH<6> data input. CCP7 0 O DIG CCP7 compare/PWM output; takes priority over port data. 1 I ST CCP7 capture input. P1C 0 O — ECCP1 PWM Output C.
PIC18F87K90 FAMILY 11.10 PORTJ, TRISJ and LATJ Registers Note: PORTJ is available only on 80-pin devices. PORTJ is an 8-bit wide, bidirectional port. The corresponding Data Direction and Output Latch registers are TRISJ and LATJ. All pins on PORTJ are implemented with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. Note: These pins are configured as digital inputs on any device Reset.
PIC18F87K90 FAMILY TABLE 11-18: PORTJ FUNCTIONS Function TRIS Setting I/O I/O Type RJ0 RJ0 0 O DIG 1 I ST PORTJ<0> data input. RJ1/SEG33 RJ1 0 O DIG LATJ<1> data output. Pin Name LATJ<0> data output. 1 I ST SEG33 1 O ANA LCD Segment 33 output; disables all other pin functions. RJ2 0 O DIG LATJ<2> data output. 1 I ST SEG34 1 O ANA LCD Segment 34 output; disables all other pin functions. RJ3 0 O DIG LATJ<3> data output. RJ2/SEG34 RJ3/SEG35 PORTJ<1> data input.
PIC18F87K90 FAMILY NOTES: DS39957D-page 182 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 12.0 TIMER0 MODULE The Timer0 module incorporates the following features: • Software-selectable operation as a timer or counter in both 8-bit or 16-bit modes • Readable and writable registers • Dedicated 8-bit, software programmable prescaler • Selectable clock source (internal or external) • Edge select for external clock • Interrupt-on-overflow REGISTER 12-1: The T0CON register (Register 12-1) controls all aspects of the module’s operation, including the prescale selection.
PIC18F87K90 FAMILY 12.1 Timer0 Operation Timer0 can operate as either a timer or a counter. The mode is selected with the T0CS bit (T0CON<5>). In Timer mode (T0CS = 0), the module increments on every clock by default unless a different prescaler value is selected (see Section 12.3 “Prescaler”). If the TMR0 register is written to, 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.
PIC18F87K90 FAMILY 12.3 12.3.1 Prescaler An 8-bit counter is available as a prescaler for the Timer0 module. The prescaler is not directly readable or writable. Its value is set by the PSA and T0PS<2:0> bits (T0CON<3:0>), which determine the prescaler assignment and prescale ratio. Clearing the PSA bit assigns the prescaler to the Timer0 module. When it is assigned, prescale values from 1:2 through 1:256, in power-of-two increments, are selectable.
PIC18F87K90 FAMILY NOTES: DS39957D-page 186 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 13.0 TIMER1 MODULE The Timer1 timer/counter module incorporates these features: • Software-selectable operation as a 16-bit timer or counter • Readable and writable 8-bit registers (TMR1H and TMR1L) • Selectable clock source (internal or external) with device clock or SOSC oscillator internal options • Interrupt-on-overflow • Reset on ECCP Special Event Trigger • Timer with gated control REGISTER 13-1: Figure 13-1 displays a simplified block diagram of the Timer1 module.
PIC18F87K90 FAMILY 13.1 Timer1 Gate Control Register The Timer1 Gate Control register (T1GCON), displayed in Register 13-2, is used to control the Timer1 gate.
PIC18F87K90 FAMILY 13.2 13.3.2 Timer1 Operation The Timer1 module is an 8 or 16-bit incrementing counter that is accessed through the TMR1H:TMR1L register pair. When used with an internal clock source, the module is a timer and increments on every instruction cycle. When used with an external clock source, the module can be used as either a timer or counter. It increments on every selected edge of the external source.
PIC18F87K90 FAMILY FIGURE 13-1: TIMER1 BLOCK DIAGRAM T1GSS<1:0> T1G 00 From Timer2 Match PR2 01 T1GSPM 0 T1G_IN T1GVAL 0 From Comp. 1 Output 10 From Comp. 2 Output 11 Single Pulse TMR1ON T1GPOL D Q CK R Q 1 Acq.
PIC18F87K90 FAMILY 13.4 Timer1 16-Bit Read/Write Mode Timer1 can be configured for 16-bit reads and writes. When the RD16 control bit (T1CON<1>) is set, the address for TMR1H is mapped to a buffer register for the high byte of Timer1. A read from TMR1L loads the contents of the high byte of Timer1 into the Timer1 High Byte Buffer register.
PIC18F87K90 FAMILY 13.5.1 USING SOSC AS A CLOCK SOURCE FIGURE 13-3: The SOSC oscillator is also available as a clock source in power-managed modes. By setting the System Clock Select bits, SCS<1:0> (OSCCON<1:0>), to ‘01’, the device switches to SEC_RUN mode, and both the CPU and peripherals are clocked from the SOSC oscillator. If the IDLEN bit (OSCCON<7>) is cleared and a SLEEP instruction is executed, the device enters SEC_IDLE mode. Additional details are available in Section 4.
PIC18F87K90 FAMILY 13.7 13.8.1 Resetting Timer1 Using the ECCP Special Event Trigger The Timer1 Gate Enable mode is enabled by setting the TMR1GE bit of the T1GCON register. The polarity of the Timer1 Gate Enable mode is configured using the T1GPOL bit (T1GCON<6>). If ECCP modules are configured to use Timer1 and to generate a Special Event Trigger in Compare mode (CCPxM<3:0> = 1011), this signal will reset Timer1. The trigger from ECCP2 will also start an A/D conversion, if the A/D module is enabled.
PIC18F87K90 FAMILY 13.8.2 TIMER1 GATE SOURCE SELECTION The Timer1 gate source can be selected from one of four sources. Source selection is controlled by the T1GSSx bits, T1GCON<1:0> (see Table 13-4).
PIC18F87K90 FAMILY 13.8.3 TIMER1 GATE TOGGLE MODE When Timer1 Gate Toggle mode is enabled, it is possible to measure the full cycle length of a Timer1 gate signal, as opposed to the duration of a single level pulse. The Timer1 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. (For timing details, see Figure 13-5.) FIGURE 13-5: The T1GVAL bit (T1GCON<2>) indicates when the Toggled mode is active and the timer is counting.
PIC18F87K90 FAMILY 13.8.4 TIMER1 GATE SINGLE PULSE MODE When Timer1 Gate Single Pulse mode is enabled, it is possible to capture a single pulse gate event. Timer1 Gate Single Pulse mode is enabled by setting the T1GSPM bit (T1GCON<4>) and the T1GGO/T1DONE bit (T1GCON<3>). The Timer1 will be fully enabled on the next incrementing edge. On the next trailing edge of the pulse, the T1GGO/ T1DONE bit will automatically be cleared.
PIC18F87K90 FAMILY FIGURE 13-7: TIMER1 GATE SINGLE PULSE AND TOGGLE COMBINED MODE TMR1GE T1GPOL T1GSPM T1GTM Cleared by Hardware on Falling Edge of T1GVAL T1GGO/ Set by Software T1DONE Counting Enabled on Rising Edge of T1G T1G_IN T1CKI T1GVAL Timer1 N TABLE 13-5: N+2 N+3 N+4 Set by Hardware on Falling Edge of T1GVAL Cleared by Software RTCCIF Name N+1 Cleared by Software REGISTERS ASSOCIATED WITH TIMER1 AS A TIMER/COUNTER Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset V
PIC18F87K90 FAMILY NOTES: DS39957D-page 198 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 14.
PIC18F87K90 FAMILY 14.2 Timer2 Interrupt 14.3 Timer2 can also generate an optional device interrupt. The Timer2 output signal (TMR2 to PR2 match) provides the input for the 4-bit output counter/postscaler. This counter generates the TMR2 match interrupt flag, which is latched in TMR2IF (PIR1<1>). The interrupt is enabled by setting the TMR2 Match Interrupt Enable bit, TMR2IE (PIE1<1>).
PIC18F87K90 FAMILY 15.0 TIMER3/5/7 MODULES The Timer3/5/7 timer/counter modules incorporate these features: • Software-selectable operation as a 16-bit timer or counter • Readable and writable 8-bit registers (TMRxH and TMRxL) • Selectable clock source (internal or external) with device clock or SOSC oscillator internal options • Interrupt-on-overflow • Module Reset on ECCP Special Event Trigger A simplified block diagram of the Timer3/5/7 module is shown in Figure 15-1.
PIC18F87K90 FAMILY REGISTER 15-1: TxCON: TIMER3/5/7 CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 TMRxCS1 TMRxCS0 TxCKPS1 TxCKPS0 SOSCEN TxSYNC RD16 TMRxON bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 TMRxCS<1:0>: Timerx Clock Source Select bits 10 = The Timer1 clock source is either a pin or an oscillator depending on the SOSCEN bit.
PIC18F87K90 FAMILY 15.1 Timer3/5/7 Gate Control Register The Timer3/5/7 Gate Control register (TxGCON), provided in Register 14-2, is used to control the Timerx gate.
PIC18F87K90 FAMILY REGISTER 15-3: OSCCON2: OSCILLATOR CONTROL REGISTER 2 U-0 R-0 U-0 U-0 R/W-0 U-0 R-x R/W-0 — SOSCRUN — — SOSCGO — MFIOFS MFIOSEL bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6 SOSCRUN: SOSC Run Status bit 1 = System clock comes from a secondary SOSC 0 = System clock comes from an oscillator other than SOSC
PIC18F87K90 FAMILY 15.2 The operating mode is determined by the clock select bits, TMRxCSx (TxCON<7:6>). When the TMRxCSx bits are cleared (= 00), Timer3/5/7 increments on every internal instruction cycle (FOSC/4). When TMRxCSx = 01, the Timer3/5/7 clock source is the system clock (FOSC), and when it is ‘10’, Timer3/5/7 works as a counter from the external clock on the TxCKI pin (on the rising edge after the first falling edge) or the SOSC oscillator.
PIC18F87K90 FAMILY 15.3 Timer3/5/7 16-Bit Read/Write Mode 15.5 Timer3/5/7 can be configured for 16-bit reads and writes (see Figure 15.3). When the RD16 control bit (TxCON<1>) is set, the address for TMRxH is mapped to a buffer register for the high byte of Timer3/5/7. A read from TMRxL will load the contents of the high byte of Timer3/5/7 into the Timerx High Byte Buffer register.
PIC18F87K90 FAMILY 15.5.2 TIMER3/5/7 GATE SOURCE SELECTION The Timer3/5/7 gate source can be selected from one of four different sources. Source selection is controlled by the TxGSS<1:0> bits (TxGCON<1:0>). The polarity for each available source is also selectable and is controlled by the TxGPOL bit (TxGCON <6>).
PIC18F87K90 FAMILY 15.5.4 TIMER3/5/7 GATE SINGLE PULSE MODE No other gate events will be allowed to increment Timer3/5/7 until the TxGGO/TxDONE bit is once again set in software. When Timer3/5/7 Gate Single Pulse mode is enabled, it is possible to capture a single pulse gate event. Timer3/5/7 Gate Single Pulse mode is first enabled by setting the TxGSPM bit (TxGCON<4>). Next, the TxGGO/TxDONE bit (TxGCON<3>) must be set. Clearing the TxGSPM bit also will clear the TxGGO/ TxDONE bit.
PIC18F87K90 FAMILY FIGURE 15-5: TIMER3/5/7 GATE SINGLE PULSE AND TOGGLE COMBINED MODE TMRxGE TxGPOL TxGSPM TxGTM Cleared by Hardware on Falling Edge of TxGVAL Set by Software TxGGO/ TxDONE Counting Enabled on Rising Edge of TxG TxG_IN TxCKI TxGVAL Timer3/5/7 TMRxGIF 15.5.5 N Cleared by Software TIMER3/5/7 GATE VALUE STATUS When Timer3/5/7 gate value status is utilized, it is possible to read the most current level of the gate control value.
PIC18F87K90 FAMILY 15.6 Timer3/5/7 Interrupt The TMRx register pair (TMRxH:TMRxL) increments from 0000h to FFFFh and overflows to 0000h. The Timerx interrupt, if enabled, is generated on overflow and is latched in the interrupt flag bit, TMRxIF. Table 15-3 gives each module’s flag bit. TABLE 15-3: TIMER3/5/7 INTERRUPT FLAG BITS Timer Module Flag Bit 3 PIR2<1> 5 PIR5<1> 7 PIR5<3> This interrupt can be enabled or disabled by setting or clearing the TMRxIE bit, respectively.
PIC18F87K90 FAMILY TABLE 15-5: Name INTCON REGISTERS ASSOCIATED WITH TIMER3/5/7 AS A TIMER/COUNTER Bit 7 Bit 6 Bit 5 GIE/GIEH PEIE/GIEL TMR0IE Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: INT0IE RBIE TMR0IF INT0IF RBIF 75 PIR5 TMR7GIF(1) TMR12IF(1) TMR10IF(1) TMR8IF TMR7IF(1) TMR6IF TMR5IF TMR4IF 77 PIE5 TMR7GIE(1) TMR12IE(1) TMR10IE(1) TMR8IE TMR7IE(1) TMR6IE TMR5IE TMR4IE 77 PIR2 OSCFIF — SSP2IF BCL2IF BCL1IF HLVDIF TMR3IF TMR3GIF 77 PIE2 OSCFIE — SSP
PIC18F87K90 FAMILY NOTES: DS39957D-page 212 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 16.0 TIMER4/6/8/10/12 MODULES The Timer4/6/8/10/12 timer modules have the following features: • • • • • • 8-Bit Timer register (TMRx) 8-Bit Period register (PRx) Readable and writable (all registers) Software programmable prescaler (1:1, 1:4, 1:16) Software programmable postscaler (1:1 to 1:16) Interrupt on TMRx match of PRx Timer10 and Timer12 are unimplemented for devices with a program memory of 32 Kbytes (PIC18FX5K90).
PIC18F87K90 FAMILY REGISTER 16-1: TxCON: TIMER4/6/8/10/12 CONTROL REGISTER U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 — TxOUTPS3 TxOUTPS2 TxOUTPS1 TxOUTPS0 TMRxON TxCKPS1 TxCKPS0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 Unimplemented: Read as ‘0’ bit 6-3 TxOUTPS<3:0>: Timerx Output Postscale Select bits 0000 = 1:1 Postscale 0001 = 1:2 Postscale • • • 1111 = 1:16 Posts
PIC18F87K90 FAMILY 16.2 Timer4/6/8/10/12 Interrupt 16.3 The Timer4/6/8/10/12 modules have 8-bit Period registers, PRx, that are both readable and writable. Timer4/6/8/10/12 increment from 00h until they match PR4/6/8/10/12 and then reset to 00h on the next increment cycle. The PRx registers are initialized to FFh upon Reset. FIGURE 16-1: Output of TMRx The outputs of TMRx (before the postscaler) are used only as a PWM time base for the ECCP modules.
PIC18F87K90 FAMILY NOTES: DS39957D-page 216 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 17.0 REAL-TIME CLOCK AND CALENDAR (RTCC) The key features of the Real-Time Clock and Calendar (RTCC) module are: • • • • • • • • • • • • Time: hours, minutes and seconds Twenty-four hour format (military time) Calendar: weekday, date, month and year Alarm configurable Year range: 2000 to 2099 Leap year correction BCD format for compact firmware Optimized for low-power operation User calibration with auto-adjust Calibration range: 2.64 seconds error per month Requirements: external 32.
PIC18F87K90 FAMILY 17.
PIC18F87K90 FAMILY 17.1.
PIC18F87K90 FAMILY REGISTER 17-2: RTCCAL: RTCC CALIBRATION REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CAL7 CAL6 CAL5 CAL4 CAL3 CAL2 CAL1 CAL0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-0 x = Bit is unknown CAL<7:0>: RTC Drift Calibration bits 01111111 = Maximum positive adjustment. Adds 508 RTC clock pulses every minute. . . .
PIC18F87K90 FAMILY REGISTER 17-4: ALRMCFG: ALARM CONFIGURATION REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 ALRMEN CHIME AMASK3 AMASK2 AMASK1 AMASK0 ALRMPTR1 ALRMPTR0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 ALRMEN: Alarm Enable bit 1 = Alarm is enabled (cleared automatically after an alarm event whenever ALRMPTR<1:0> = 00 and CHIME = 0) 0 =
PIC18F87K90 FAMILY REGISTER 17-5: ALRMRPT: ALARM REPEAT REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 ARPT7 ARPT6 ARPT5 ARPT4 ARPT3 ARPT2 ARPT1 ARPT0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-0 17.1.2 x = Bit is unknown ARPT<7:0>: Alarm Repeat Counter Value bits 11111111 = Alarm will repeat 255 more times . . .
PIC18F87K90 FAMILY REGISTER 17-7: YEAR: YEAR VALUE REGISTER(1) R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x YRTEN3 YRTEN2 YRTEN1 YRTEN0 YRONE3 YRONE2 YRONE1 YRONE0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-4 YRTEN<3:0>: Binary Coded Decimal Value of Year’s Tens Digit bits Contains a value from 0 to 9.
PIC18F87K90 FAMILY REGISTER 17-9: DAY: DAY VALUE REGISTER(1) U-0 U-0 R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x — — DAYTEN1 DAYTEN0 DAYONE3 DAYONE2 DAYONE1 DAYONE0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 Unimplemented: Read as ‘0’ bit 5-4 DAYTEN<1:0>: Binary Coded Decimal value of Day’s Tens Digit bits Contains a value from 0 to 3.
PIC18F87K90 FAMILY REGISTER 17-11: HOUR: HOUR VALUE REGISTER(1) U-0 U-0 R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x — — HRTEN1 HRTEN0 HRONE3 HRONE2 HRONE1 HRONE0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 Unimplemented: Read as ‘0’ bit 5-4 HRTEN<1:0>: Binary Coded Decimal Value of Hour’s Tens Digit bits Contains a value from 0 to 2.
PIC18F87K90 FAMILY 17.1.
PIC18F87K90 FAMILY REGISTER 17-16: ALRMWD: ALARM WEEKDAY VALUE REGISTER(1) U-0 U-0 U-0 U-0 U-0 R/W-x R/W-x R/W-x — — — — — WDAY2 WDAY1 WDAY0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-3 Unimplemented: Read as ‘0’ bit 2-0 WDAY<2:0>: Binary Coded Decimal Value of Weekday Digit bits Contains a value from 0 to 6.
PIC18F87K90 FAMILY REGISTER 17-18: ALRMMIN: ALARM MINUTES VALUE REGISTER U-0 R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x — MINTEN2 MINTEN1 MINTEN0 MINONE3 MINONE2 MINONE1 MINONE0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6-4 MINTEN<2:0>: Binary Coded Decimal Value of Minute’s Tens Digit bits Contains a value from 0 to 5.
PIC18F87K90 FAMILY 17.1.4 RTCEN BIT WRITE 17.2 RTCWREN (RTCCFG<5>) must be set before a write to RTCEN can take place. Any write to the RTCEN bit, while RTCWREN = 0, will be ignored. Like the RTCEN bit, the RTCVALH and RTCVALL registers can only be written to when RTCWREN = 1. A write to these registers, while RTCWREN = 0, will be ignored. FIGURE 17-2: FIGURE 17-3: The register interface for the RTCC and alarm values is implemented using the Binary Coded Decimal (BCD) format.
PIC18F87K90 FAMILY 17.2.2 CLOCK SOURCE As previously mentioned, the RTCC module is intended to be clocked by an external Real-Time Clock (RTC) crystal oscillating at 32.768 kHz, but an internal oscillator can be used. The RTCC clock selection is decided by the RTCOSC bit (CONFIG3L<0>). FIGURE 17-4: Calibration of the crystal can be done through this module to yield an error of 3 seconds or less per month. (For further details, see Section 17.2.9 “Calibration”.) CLOCK SOURCE MULTIPLEXING 32.
PIC18F87K90 FAMILY 17.2.4 LEAP YEAR Since the year range on the RTCC module is 2000 to 2099, the leap year calculation is determined by any year divisible by four in the above range. Only February is affected in a leap year. February will have 29 days in a leap year and 28 days in any other year. 17.2.5 GENERAL FUNCTIONALITY All Timer registers containing a time value of seconds or greater are writable.
PIC18F87K90 FAMILY TABLE 17-4: ALRMVAL REGISTER MAPPING Alarm Value Register Window ALRMPTR<1:0> 00 ALRMVALH ALRMVALL ALRMMIN ALRMSEC 01 ALRMWD ALRMHR 10 ALRMMNTH ALRMDAY 11 — — Writes to the RTCCAL register should occur only when the timer is turned off or immediately after the rising edge of the seconds pulse. Note: 17.3 In determining the crystal’s error value, it is the user’s responsibility to include the crystal’s initial error from drift due to temperature or crystal aging.
PIC18F87K90 FAMILY FIGURE 17-5: ALARM MASK SETTINGS Alarm Mask Setting AMASK<3:0> Day of the Week Month Day Hours Minutes Seconds 0000 – Every half second 0001 – Every second 0010 – Every 10 seconds s 0011 – Every minute s s m s s m m s s 0100 – Every 10 minutes 0101 – Every hour 0110 – Every day 0111 – Every week d 1000 – Every month 1001 – Every year(1) Note 1: m m h h m m s s h h m m s s d d h h m m s s d d h h m m s s Annually, except when configure
PIC18F87K90 FAMILY FIGURE 17-6: TIMER PULSE GENERATION RTCEN bit ALRMEN bit RTCC Alarm Event RTCC Pin 17.4 Sleep Mode The timer and alarm continue to operate while in Sleep mode. The operation of the alarm is not affected by Sleep, as an alarm event can always wake up the CPU. The Idle mode does not affect the operation of the timer or alarm. 17.5 17.5.1 Reset 17.5.2 POWER-ON RESET (POR) The RTCCFG and ALRMRPT registers are reset only on a POR.
PIC18F87K90 FAMILY 17.6 Register Maps Table 17-5, Table 17-6 and Table 17-7 summarize the registers associated with the RTCC module.
PIC18F87K90 FAMILY NOTES: DS39957D-page 236 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 18.0 CAPTURE/COMPARE/PWM (CCP) MODULES PIC18F87K90 family devices have seven CCP (Capture/Compare/PWM) modules, designated CCP4 through CCP10. All the modules implement standard Capture, Compare and Pulse-Width Modulation (PWM) modes. Note: Each CCP module contains a 16-bit register that can operate as a 16-bit Capture register, a 16-bit Compare register or a PWM Master/Slave Duty Cycle register.
PIC18F87K90 FAMILY REGISTER 18-2: CCPTMRS1: CCPx TIMER SELECT REGISTER 1 R/W-0 R/W-0 U-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 C7TSEL1 C7TSEL0 — C6TSEL0 — C5TSEL0 C4TSEL1 C4TSEL0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-6 C7TSEL<1:0>: CCP7 Timer Selection bits 00 = CCP7 is based off of TMR1/TMR2 01 = CCP7 is based off of TMR5/TMR4 10 = CCP7 is based off of TMR5/TMR6 11 = CCP7 is bas
PIC18F87K90 FAMILY REGISTER 18-3: CCPTMRS2: CCPx TIMER SELECT REGISTER 2 U-0 U-0 U-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 — — — C10TSEL0(1) — C9TSEL0(1) C8TSEL1 C8TSEL0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 Unimplemented: Read as ‘0’ bit 4 C10TSEL0: CCP10 Timer Selection bit(1) 0 = CCP10 is based off of TMR1/TMR2 1 = CCP10 is based off of TMR7/TMR2 bit 3 Unimplemented: Rea
PIC18F87K90 FAMILY REGISTER 18-4: CCPRxL: CCPx PERIOD LOW BYTE REGISTER R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x CCPRxL7 CCPRxL6 CCPRxL5 CCPRxL4 CCPRxL3 CCPRxL2 CCPRxL1 CCPRxL0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-0 x = Bit is unknown CCPRxL<7:0>: CCPx Period Register Low Byte bits Capture Mode: Capture register low byte.
PIC18F87K90 FAMILY 18.1 TABLE 18-1: CCP Module Configuration Each Capture/Compare/PWM module is associated with a control register (generically, CCPxCON) and a data register (CCPRx). The data register, in turn, is comprised of two 8-bit registers: CCPRxL (low byte) and CCPRxH (high byte). All registers are both readable and writable. 18.1.
PIC18F87K90 FAMILY 18.1.2 OPEN-DRAIN OUTPUT OPTION When operating in Output mode (the Compare or PWM modes), the drivers for the CCPx pins can be optionally configured as open-drain outputs. This feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor and allows the output to communicate with external circuits without the need for additional level shifters. The open-drain output option is controlled by the CCPxOD bits (ODCON2<7:2>).
PIC18F87K90 FAMILY FIGURE 18-1: CAPTURE MODE OPERATION BLOCK DIAGRAM TMR5H Set CCP5IF C5TSEL0 CCP5 Pin Prescaler 1, 4, 16 and Edge Detect CCP5CON<3:0> Q1:Q4 CCP4CON<3:0> 4 4 CCPR5L TMR1 Enable TMR1H TMR1L TMR3H TMR3L Set CCP4IF 4 C4TSEL1 C4TSEL0 TMR3 Enable CCP4 Pin Prescaler 1, 4, 16 TMR5 Enable CCPR5H C5TSEL0 TMR5L and Edge Detect CCPR4H CCPR4L TMR1 Enable C4TSEL0 C4TSEL1 Note: 18.2.3 TMR1L This block diagram uses CCP4 and CCP5, and their appropriate timers, as an example.
PIC18F87K90 FAMILY 18.3 Compare Mode 18.3.3 SOFTWARE INTERRUPT MODE In Compare mode, the 16-bit CCPR4 register value is constantly compared against either the TMR1 or TMR3 register pair value. When a match occurs, the CCP4 pin can be: When the Generate Software Interrupt mode is chosen (CCP4M<3:0> = 1010), the CCP4 pin is not affected. Only a CCP interrupt is generated, if enabled, and the CCP4IE bit is set. • • • • 18.3.
PIC18F87K90 FAMILY FIGURE 18-2: COMPARE MODE OPERATION BLOCK DIAGRAM CCPR5H Set CCP5IF CCPR5L Special Event Trigger (Timer1/5 Reset) CCP5 Pin Compare Match Comparator S Output Logic Q R TRIS Output Enable 4 CCP5CON<3:0> TMR1H TMR1L 0 TMR5H TMR5L 1 C5TSEL0 0 TMR1H TMR1L 1 TMR3H TMR3L Special Event Trigger (Timer1/Timer3 Reset, A/D Trigger) C4TSEL1 C4TSEL0 Set CCP4IF Comparator CCPR4H CCPR4L Compare Match CCP4 Pin Output Logic 4 S Q R TRIS Output Enable CCP4CON<3:0> Note:
PIC18F87K90 FAMILY TABLE 18-5: Name REGISTERS ASSOCIATED WITH CAPTURE, COMPARE, TIMER1/3/5/7 Bit 7 INTCON Bit 6 Bit 5 GIE/GIEH PEIE/GIEL TMR0IE Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: INT0IE RBIE TMR0IF INT0IF RBIF 75 CM RI TO PD POR BOR 76 PIR4 CCP10IF(1) CCP9IF(1) CCP8IF CCP7IF CCP6IF CCP5IF CCP4IF CCP3IF 77 PIE4 CCP10IE(1) (1) CCP8IE CCP7IE CCP6IE CCP5IE CCP4IE CCP3IE 77 IPR4 CCP10IP(1) CCP9IP(1) CCP8IP CCP7IP CCP6IP CCP5IP CCP4IP CCP3IP 77 RCON
PIC18F87K90 FAMILY TABLE 18-5: REGISTERS ASSOCIATED WITH CAPTURE, COMPARE, TIMER1/3/5/7 (CONTINUED) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: CCP6CON — — DC6B1 DC6B0 CCP6M3 CCP6M2 CCP6M1 CCP6M0 82 CCP7CON — — DC7B1 DC7B0 CCP7M3 CCP7M2 CCP7M1 CCP7M0 82 CCP8CON — — DC8B1 DC8B0 CCP8M3 CCP8M2 CCP8M1 CCP8M0 80 CCP9CON — — DC9B1 DC9B0 CCP9M3 CCP9M2 CCP9M1 CCP9M0 80 CCP10CON(1) — — DC10B1 DC10B0 CCP10M3 CCP10M2 CCP10M1 CCP10M0 81
PIC18F87K90 FAMILY A PWM output (Figure 18-4) has a time base (period) and a time that the output stays high (duty cycle). The frequency of the PWM is the inverse of the period (1/period). FIGURE 18-4: PWM OUTPUT Period Duty Cycle TMR2 = PR2 PWM PERIOD The PWM period is specified by writing to the PR2 register.
PIC18F87K90 FAMILY 18.4.3 SETUP FOR PWM OPERATION 3. To configure the CCP module for PWM operation (with CCP4 as an example): 1. 2. 4. Set the PWM period by writing to the PR2 register. Set the PWM duty cycle by writing to the CCPR4L register and CCP4CON<5:4> bits. TABLE 18-7: Name INTCON RCON 5. Make the CCP4 pin an output by clearing the appropriate TRIS bit. Set the TMR2 prescale value, then enable Timer2 by writing to T2CON. Configure the CCP4 module for PWM operation.
PIC18F87K90 FAMILY TABLE 18-7: Name REGISTERS ASSOCIATED WITH PWM AND TIMERS (CONTINUED) Bit 7 CCPR10H(1) Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Capture/Compare/PWM Register 10 High Byte Reset Values on Page: 80 CCP4CON — — DC4B1 DC4B0 CCP4M3 CCP4M2 CCP4M1 CCP4M0 82 CCP5CON — — DC5B1 DC5B0 CCP5M3 CCP5M2 CCP5M1 CCP5M0 82 CCP6CON — — DC6B1 DC6B0 CCP6M3 CCP6M2 CCP6M1 CCP6M0 82 CCP7CON — — DC7B1 DC7B0 CCP7M3 CCP7M2 CCP7M1 CCP7M0 82 CCP8CON — — DC8B1 DC8
PIC18F87K90 FAMILY 19.0 ENHANCED CAPTURE/COMPARE/PWM (ECCP) MODULE PIC18F87K90 family devices have three Enhanced Capture/Compare/PWM (ECCP) modules: ECCP1, ECCP2 and ECCP3. These modules contain a 16-bit register, which can operate as a 16-bit Capture register, a 16-bit Compare register or a PWM Master/Slave Duty Cycle register.
PIC18F87K90 FAMILY REGISTER 19-1: CCPxCON: ENHANCED CAPTURE/COMPARE/PWM x CONTROL R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 PxM1 PxM0 DCxB1 DCxB0 CCPxM3 CCPxM2 CCPxM1 CCPxM0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 PxM<1:0>: Enhanced PWM Output Configuration bits If CCPxM<3:2> = 00, 01, 10: xx = PxA is assigned as a capture/compare input/output;
PIC18F87K90 FAMILY REGISTER 19-2: CCPTMRS0: CCP TIMER SELECT 0 REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 C3TSEL1 C3TSEL0 C2TSEL2 C2TSEL1 C2TSEL0 C1TSEL2 C1TSEL1 C1TSEL0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 C3TSEL<1:0>: ECCP3 Timer Selection bits 00 = ECCP3 is based off of TMR1/TMR2 01 = ECCP3 is based off of TMR3/TMR4 10 = ECCP3 is
PIC18F87K90 FAMILY In addition to the expanded range of modes available through the CCPxCON and ECCPxAS registers, the ECCP modules have two additional registers associated with Enhanced PWM operation and auto-shutdown features. They are: • ECCPxDEL – Enhanced PWM Control • PSTRxCON – Pulse Steering Control 19.1 ECCP Outputs and Configuration The Enhanced CCP module may have up to four PWM outputs, depending on the selected operating mode.
PIC18F87K90 FAMILY 19.2 19.2.2 Capture Mode In Capture mode, the CCPRxH:CCPRxL register pair captures the 16-bit value of the TMR1 or TMR3 registers when an event occurs on the corresponding ECCPx pin. An event is defined as one of the following: • • • • Every falling edge Every rising edge Every fourth rising edge Every 16th rising edge TABLE 19-2: ECCP1/2/3 INTERRUPT FLAG BITS ECCP Module Flag Bit 1 PIR3<1> 2 PIR3<2> 3 PIR4<0> 19.2.
PIC18F87K90 FAMILY 19.3 19.3.2 Compare Mode TIMER1/TIMER3 MODE SELECTION In Compare mode, the 16-bit CCPRx register value is constantly compared against either the TMR1 or TMR3 register pair value. When a match occurs, the ECCPx pin can be: Timer1 and/or Timer3 must be running in Timer mode or Synchronized Counter mode if the ECCP module is using the compare feature. In Asynchronous Counter mode, the compare operation will not work reliably. • • • • 19.3.
PIC18F87K90 FAMILY 19.4 The PWM outputs are multiplexed with I/O pins and are designated: PxA, PxB, PxC and PxD. The polarity of the PWM pins is configurable and is selected by setting the CCPxM bits in the CCPxCON register appropriately. PWM (Enhanced Mode) The Enhanced PWM mode can generate a PWM signal on up to four different output pins with up to 10 bits of resolution. It can do this through four different PWM Output modes: • • • • Table 19-1 provides the pin assignments for each Enhanced PWM mode.
PIC18F87K90 FAMILY TABLE 19-3: EXAMPLE PIN ASSIGNMENTS FOR VARIOUS PWM ENHANCED MODES ECCP Mode PxM<1:0> PxA PxB PxC PxD Single 00 Yes(1) Yes(1) Yes(1) Yes(1) Half-Bridge 10 Yes Yes No No Full-Bridge, Forward 01 Yes Yes Yes Yes Full-Bridge, Reverse 11 Yes Yes Yes Yes Outputs are enabled by pulse steering in Single mode (see Register 19-5).
PIC18F87K90 FAMILY FIGURE 19-5: EXAMPLE ENHANCED PWM OUTPUT RELATIONSHIPS (ACTIVE-LOW STATE) PxM<1:0> Signal PR2 + 1 Pulse Width 0 Period 00 (Single Output) PxA Modulated PxA Modulated 10 (Half-Bridge) Delay(1) Delay(1) PxB Modulated PxA Active 01 (Full-Bridge, Forward) PxB Inactive PxC Inactive PxD Modulated PxA Inactive 11 (Full-Bridge, Reverse) PxB Modulated PxC Active PxD Inactive Relationships: • Period = 4 * TOSC * (PR2 + 1) * (TMR2 Prescale Value) • Pulse Width = TOSC * (CCPRxL<7
PIC18F87K90 FAMILY 19.4.1 HALF-BRIDGE MODE In Half-Bridge mode, two pins are used as outputs to drive push-pull loads. The PWM output signal is output on the PxA pin, while the complementary PWM output signal is output on the PxB pin (see Figure 19-6). This mode can be used for half-bridge applications, as shown in Figure 19-7, or for full-bridge applications, where four power switches are being modulated with two PWM signals.
PIC18F87K90 FAMILY 19.4.2 FULL-BRIDGE MODE In the Reverse mode, the PxC pin is driven to its active state and the PxB pin is modulated, while the PxA and PxD pins are driven to their inactive state, as provided Figure 19-9. In Full-Bridge mode, all four pins are used as outputs. An example of a full-bridge application is provided in Figure 19-8. The PxA, PxB, PxC and PxD outputs are multiplexed with the PORT data latches.
PIC18F87K90 FAMILY FIGURE 19-9: EXAMPLE OF FULL-BRIDGE PWM OUTPUT Forward Mode Period (2) PxA Pulse Width PxB(2) PxC(2) PxD(2) (1) (1) Reverse Mode Period Pulse Width PxA(2) PxB(2) PxC(2) PxD(2) (1) Note 1: 2: (1) At this time, the TMR2 register is equal to the PR2 register. The output signal is shown as active-high. DS39957D-page 262 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 19.4.2.1 Direction Change in Full-Bridge Mode In the Full-Bridge mode, the PxM1 bit in the CCPxCON register allows users to control the forward/reverse direction. When the application firmware changes this direction control bit, the module will change to the new direction on the next PWM cycle. A direction change is initiated in software by changing the PxM1 bit of the CCPxCON register.
PIC18F87K90 FAMILY FIGURE 19-11: EXAMPLE OF PWM DIRECTION CHANGE AT NEAR 100% DUTY CYCLE(1) Forward Period t1 Reverse Period PxA PxB PW PxC PxD PW TON(2) External Switch C TOFF(3) External Switch D Potential Shoot-Through Current Note 1: 19.4.3 All signals are shown as active-high. 2: TON is the turn-on delay of power switch, QC, and its driver. 3: TOFF is the turn-off delay of power switch, QD, and its driver.
PIC18F87K90 FAMILY When a shutdown event occurs, two things happen: Each pin pair may be placed into one of three states: • The ECCPxASE bit is set to ‘1’. The ECCPxASE will remain set until cleared in firmware or an auto-restart occurs. (See Section 19.4.5 “Auto-Restart Mode”.) • The enabled PWM pins are asynchronously placed in their shutdown states. The PWM output pins are grouped into pairs: PxA/PxC and PxB/PxD.
PIC18F87K90 FAMILY FIGURE 19-12: PWM AUTO-SHUTDOWN WITH FIRMWARE RESTART (PxRSEN = 0) PWM Period Shutdown Event ECCPxASE bit PWM Activity Normal PWM Start of PWM Period 19.4.5 Shutdown Event Occurs AUTO-RESTART MODE The Enhanced PWM can be configured to automatically restart the PWM signal once the auto-shutdown condition has been removed. Auto-restart is enabled by setting the PxRSEN bit (ECCPxDEL<7>).
PIC18F87K90 FAMILY 19.4.6 PROGRAMMABLE DEAD-BAND DELAY MODE FIGURE 19-14: In half-bridge applications, where all power switches are modulated at the PWM frequency, the power switches normally require more time to turn off than to turn on. If both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period until one switch completely turns off.
PIC18F87K90 FAMILY REGISTER 19-4: ECCPxDEL: ENHANCED PWM CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 PxRSEN PxDC6 PxDC5 PxDC4 PxDC3 PxDC2 PxDC1 PxDC0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 PxRSEN: PWM Restart Enable bit 1 = Upon auto-shutdown, the ECCPxASE bit clears automatically once the shutdown event goes away; the PWM restart
PIC18F87K90 FAMILY REGISTER 19-5: R/W-0 CMPL1 PSTRxCON: PULSE STEERING CONTROL(1) R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-1 CMPL0 — STRSYNC STRD STRC STRB STRA bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 CMPL<1:0>: Complementary Mode Output Assignment Steering Sync bits 00 = See STRD:STRA 01 = PA and PB are selected as the complementary output pair 10 = PA an
PIC18F87K90 FAMILY FIGURE 19-16: 19.4.7.1 SIMPLIFIED STEERING BLOCK DIAGRAM The STRSYNC bit of the PSTRxCON register gives the user two choices for when the steering event will happen. When the STRSYNC bit is ‘0’, the steering event will happen at the end of the instruction that writes to the PSTRxCON register. In this case, the output signal at the Px pins may be an incomplete PWM waveform. This operation is useful when the user firmware needs to immediately remove a PWM signal from the pin.
PIC18F87K90 FAMILY 19.4.8 OPERATION IN POWER-MANAGED MODES 19.4.8.1 Operation with Fail-Safe Clock Monitor (FSCM) In Sleep mode, all clock sources are disabled. Timer2/4/6/8 will not increment and the state of the module will not change. If the ECCPx pin is driving a value, it will continue to drive that value. When the device wakes up, it will continue from this state. If Two-Speed Start-ups are enabled, the initial start-up frequency from HF-INTOSC and the postscaler may not be immediately stable.
PIC18F87K90 FAMILY TABLE 19-4: File Name REGISTERS ASSOCIATED WITH ECCP1/2/3 MODULE AND TIMER1/2/3/4/6/8/10/12 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: INTCON GIE/GIEH PEIE/GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 75 RCON PIR3 IPEN TMR5GIF SBOREN LCDIF CM RC2IF RI TX2IF TO CTMUIF PD CCP2IF POR CCP1IF BOR RTCCIF 76 77 PIR4 PIE3 PIE4 IPR3 IPR4 TRISB CCP10IF(1) TMR5GIE CCP10IE(1) TMR5GIP CCP10IP(1) TRISB7 CCP9IF(1) LCDIE CCP9IE(1) LCDIP CCP9IP(1) T
PIC18F87K90 FAMILY 20.0 LIQUID CRYSTAL DISPLAY (LCD) DRIVER MODULE The Liquid Crystal Display (LCD) driver module generates the timing control to drive a static or multiplexed LCD panel. In the 80-pin devices (PIC18F8XK90), the module drives the panels of up to four commons and up to 48 segments and in the 64-pin devices (PIC18F6XK90), the module drives the panels of up to four commons and up to 33 segments. It also provides control of the LCD pixel data.
PIC18F87K90 FAMILY 20.1 The LCDCON register, shown in Register 20-1, controls the overall operation of the module. Once the module is configured, the LCDEN (LCDCON<7>) bit is used to enable or disable the LCD module. The LCD panel can also operate during Sleep by clearing the SLPEN (LCDCON<6>) bit.
PIC18F87K90 FAMILY REGISTER 20-2: LCDPS: LCD PHASE REGISTER R/W-0 R/W-0 R-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0 WFT BIASMD LCDA WA LP3 LP2 LP1 LP0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 WFT: Waveform Type Select bit 1 = Type-B waveform (phase changes on each frame boundary) 0 = Type-A waveform (phase changes within each common type) bit 6 BIASMD: Bias Mode Select bit When LMUX
PIC18F87K90 FAMILY REGISTER 20-3: LCDREF: LCD REFERENCE VOLTAGE CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 LCDIRE LCDIRS LCDCST2 LCDCST1 LCDCST0 VLCD3PE VLCD2PE VLCD1PE bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 LCDIRE: LCD Internal Reference Enable bit 1 = Internal LCD reference is enabled and connected to the internal contrast cont
PIC18F87K90 FAMILY REGISTER 20-4: R/W-0 LCDRL: LCD REFERENCE LADDER CONTROL REGISTER R/W-0 LRLAP1 LRLAP0 R/W-0 LRLBP1 R/W-0 U-0 R/W-0 R/W-0 R/W-0 LRLBP0 —(1) LRLAT2 LRLAT1 LRLAT0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 LRLAP<1:0>: LCD Reference Ladder A Time Power Control bits During Time Interval A: 11 = Internal LCD reference ladder is powered in High
PIC18F87K90 FAMILY The LCDSE5:LCDSE0 registers configure the functions of the port pins. Setting the segment enable bit for a particular segment configures that pin as an LCD driver. There are six LCD Segment Enable registers, as shown in Table 20-1. The prototype LCDSEx register is shown in Register 20-5.
PIC18F87K90 FAMILY TABLE 20-2: LCDDATA REGISTERS AND BITS FOR SEGMENT AND COM COMBINATIONS COM Lines Segments 0 through 7 8 through 15 16 through 23 24 through 31 32 through 39 40 through 47 Note 1: 2: 0 1 2 3 LCDDATA0 LCDDATA6 LCDDATA12 LCDDATA18 S00C0:S07C0 S00C1:S07C1 S00C2:S07C2 S00C3:S07C3 LCDDATA1 LCDDATA7 LCDDATA13 LCDDATA19 S08C0:S15C0 S08C1:S15C1 S08C2:S15C2 S08C0:S15C3 LCDDATA2 LCDDATA8 LCDDATA14 LCDDATA20 S16C0:S23C0 S16C1:S23C1 S16C2:S23C2 S16C3:S23C3 LCDDATA3 LC
PIC18F87K90 FAMILY 20.2 LCD Clock Source Selection The LCD driver module has three possible clock sources: • (FOSC/4)/8192 • SOSC Clock/32 • INTRC/32 The second clock source is the SOSC oscillator/32. This also outputs about 1 kHz when a 32.768 kHz crystal is used with the SOSC oscillator. To use the SOSC oscillator as a clock source, set the SOSCEN (T1CON<3>) bit. 20.2.1 LCD PRESCALER A 16-bit counter is available as a prescaler for the LCD clock. The prescaler is not directly readable or writable.
PIC18F87K90 FAMILY 20.3 LCD Bias Types The LCD module can be configured in one of three bias types: • Static bias (two voltage levels: VSS and VDD) • 1/2 bias (three voltage levels: VSS, 1/2 VDD and VDD) • 1/3 bias (four voltage levels: VSS, 1/3 VDD, 2/3 VDD and VDD) LCD bias voltages can be generated with an internal or external resistor ladder. The internal resistor ladder eliminates the external solution’s use of up to three pins.
PIC18F87K90 FAMILY 20.3.2 INTERNAL RESISTOR BIASING This mode does not use external resistors, but rather internal resistor ladders that are configured to generate the bias voltage. The internal reference ladder actually consists of three separate ladders. Disabling the internal reference ladder disconnects all of the ladders, allowing external voltages to be supplied. Table 20-3 shows the total resistance of each of the ladders. Figure 20-4 shows the internal resister ladder connections.
PIC18F87K90 FAMILY 20.3.2.1 There are two power modes designated as “Mode A” and “Mode B”. Mode A is set by the bits, LRLAP<1:0> and Mode B by LRLB<1:0>. The resistor ladder to use for Modes A and B are selected by the bits, LRLAP<1:0> and LRLBP<1:0>, respectively As an LCD segment is electrically only a capacitor, current is drawn only during the interval when the voltage is switching.
PIC18F87K90 FAMILY 20.3.2.2 Contrast Control The LCD contrast control circuit consists of a 7-tap resistor ladder, controlled by the LCDCST bits (see Figure 20-6.). FIGURE 20-6: INTERNAL REFERENCE AND CONTRAST CONTROL BLOCK DIAGRAM 7 Stages VDD R R R R Analog MUX 7 0 To Top of Reference Ladder LCDCST<2:0> 3 Internal Reference DS39957D-page 284 Contrast Control 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 20.3.2.3 Internal Reference Under firmware control, an internal reference for the LCD bias voltages can be enabled. When enabled, the source of this voltage can be VDD. When no internal reference is selected, the LCD contrast control circuit is disabled and LCD bias must be provided externally. Whenever the LCD module is inactive (LCDA = 0), the internal reference will be turned off. 20.3.2.
PIC18F87K90 FAMILY 20.7 LCD Frame Frequency 20.8 The rate at which the COM and SEG outputs change is called the LCD frame frequency. TABLE 20-5: FRAME FREQUENCY FORMULAS Multiplex Frame Frequency = Static Clock Source/(4 x 1 x (LP<3:0> + 1)) 1/2 Clock Source/(2 x 2 x (LP<3:0> + 1)) 1/3 Clock Source/(1 x 3 x (LP<3:0> + 1)) 1/4 Clock Source/(1 x 4 x (LP<3:0> + 1)) Note: Clock source is (FOSC/4)/8192, Timer1 Osc/32 or INTRC/32.
PIC18F87K90 FAMILY FIGURE 20-7: TYPE-A/TYPE-B WAVEFORMS IN STATIC DRIVE V1 COM0 V0 COM0 V1 SEG0 V0 V1 SEG1 SEG0 SEG2 SEG7 SEG6 SEG5 SEG4 SEG3 SEG1 V0 V1 V0 COM0-SEG0 -V1 COM0-SEG1 V0 1 Frame 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-8: TYPE-A WAVEFORMS IN 1/2 MUX, 1/2 BIAS DRIVE V2 COM0 V1 V0 COM1 V2 COM0 COM1 V1 V0 V2 V1 SEG0 V0 SEG0 SEG1 SEG2 SEG3 V2 V1 SEG1 V0 V2 V1 V0 COM0-SEG0 -V1 -V2 V2 V1 V0 COM0-SEG1 -V1 -V2 1 Frame DS39957D-page 288 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-9: TYPE-B WAVEFORMS IN 1/2 MUX, 1/2 BIAS DRIVE V2 V1 COM0 COM1 V0 COM0 V2 COM1 V1 V0 V2 SEG0 V1 V2 SEG1 SEG0 SEG1 SEG2 SEG3 V0 V1 V0 V2 V1 V0 COM0-SEG0 -V1 -V2 V2 V1 V0 COM0-SEG1 -V1 -V2 2 Frames 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-10: TYPE-A WAVEFORMS IN 1/2 MUX, 1/3 BIAS DRIVE V3 V2 COM0 V1 COM1 V0 V3 COM0 V2 COM1 V1 V0 V3 V2 SEG0 V1 V0 SEG0 SEG1 SEG2 SEG3 V3 V2 SEG1 V1 V0 V3 V2 V1 V0 COM0-SEG0 -V1 -V2 -V3 V3 V2 V1 V0 COM0-SEG1 -V1 -V2 1 Frame DS39957D-page 290 -V3 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-11: TYPE-B WAVEFORMS IN 1/2 MUX, 1/3 BIAS DRIVE V3 V2 COM0 V1 COM1 V0 V3 COM0 V2 COM1 V1 V0 V3 V2 SEG0 V1 V0 V2 SEG1 SEG0 SEG1 SEG2 SEG3 V3 V1 V0 V3 V2 V1 V0 COM0-SEG0 -V1 -V2 -V3 V3 V2 V1 V0 COM0-SEG1 -V1 -V2 2 Frames 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-12: TYPE-A WAVEFORMS IN 1/3 MUX, 1/2 BIAS DRIVE V2 COM0 V1 V0 COM2 V2 COM1 V1 V0 COM1 COM0 V2 COM2 V1 V0 V2 SEG0 SEG2 V1 SEG0 SEG1 SEG2 V0 V2 SEG1 V1 V0 V2 V1 V0 COM0-SEG0 -V1 -V2 V2 V1 V0 COM0-SEG1 -V1 -V2 1 Frame DS39957D-page 292 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-13: TYPE-B WAVEFORMS IN 1/3 MUX, 1/2 BIAS DRIVE V2 COM0 V1 V0 COM2 V2 COM1 V1 COM1 V0 COM0 V2 COM2 V1 V0 V2 V1 V0 SEG0 SEG1 SEG2 SEG0 V2 SEG1 V1 V0 V2 V1 V0 COM0-SEG0 -V1 -V2 V2 V1 V0 COM0-SEG1 -V1 -V2 2 Frames 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-14: TYPE-A WAVEFORMS IN 1/3 MUX, 1/3 BIAS DRIVE V3 V2 COM0 V1 V0 V3 COM2 V2 COM1 V1 COM1 V0 COM0 V3 V2 COM2 V1 V0 V3 V2 V1 V0 SEG0 SEG1 SEG2 SEG0 SEG2 V3 V2 SEG1 V1 V0 V3 V2 V1 V0 COM0-SEG0 -V1 -V2 -V3 V3 V2 V1 V0 COM0-SEG1 -V1 -V2 -V3 1 Frame DS39957D-page 294 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-15: TYPE-B WAVEFORMS IN 1/3 MUX, 1/3 BIAS DRIVE V3 V2 COM0 V1 V0 V3 COM2 V2 COM1 V1 COM1 V0 COM0 V3 V2 COM2 V1 V0 V3 V2 V1 V0 SEG0 SEG1 SEG2 SEG0 V3 V2 SEG1 V1 V0 V3 V2 V1 V0 COM0-SEG0 -V1 -V2 -V3 V3 V2 V1 V0 COM0-SEG1 -V1 -V2 -V3 2 Frames 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-16: TYPE-A WAVEFORMS IN 1/4 MUX, 1/3 BIAS DRIVE COM3 COM2 COM1 COM0 V3 V2 V1 V0 COM1 V3 V2 V1 V0 COM2 V3 V2 V1 V0 COM3 V3 V2 V1 V0 SEG0 V3 V2 V1 V0 SEG1 V3 V2 V1 V0 COM0-SEG0 V3 V2 V1 V0 -V1 -V2 -V3 COM0-SEG1 V3 V2 V1 V0 -V1 -V2 -V3 SEG0 SEG1 COM0 1 Frame DS39957D-page 296 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY FIGURE 20-17: TYPE-B WAVEFORMS IN 1/4 MUX, 1/3 BIAS DRIVE COM3 COM2 COM1 COM0 V3 V2 V1 V0 COM1 V3 V2 V1 V0 COM2 V3 V2 V1 V0 COM3 V3 V2 V1 V0 SEG0 V3 V2 V1 V0 SEG1 V3 V2 V1 V0 COM0-SEG0 V3 V2 V1 V0 -V1 -V2 -V3 COM0-SEG1 V3 V2 V1 V0 -V1 -V2 -V3 SEG0 SEG1 COM0 2 Frames 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 20.9 When the LCD driver is running with Type-B waveforms and the LMUX<1:0> bits are not equal to ‘00’, there are some additional issues. LCD Interrupts The LCD timing generation provides an interrupt that defines the LCD frame timing. This interrupt can be used to coordinate the writing of the pixel data with the start of a new frame, which produces a visually crisp transition of the image.
PIC18F87K90 FAMILY 20.10 Operation During Sleep The LCD module can operate during Sleep. Setting the SLPEN bit (LCDCON<6>) allows the LCD module to go to Sleep. Clearing this bit allows the module to continue operating during Sleep. If a SLEEP instruction is executed and SLPEN = 1, the LCD module will cease all functions and go into a very low-current consumption mode. The module will stop operation immediately and drive the minimum LCD voltage on both segment and common lines.
PIC18F87K90 FAMILY 20.11 Configuring the LCD Module 4. To configure the LCD module. 1. 2. 3. Select the frame clock prescale, using bits, LP<3:0> (LCDPS<3:0>). Configure the appropriate pins to function as segment drivers using the LCDSEx registers.
PIC18F87K90 FAMILY TABLE 20-7: Name REGISTERS ASSOCIATED WITH LCD OPERATION Bit 7 INTCON Bit 6 GIE/GIEH PEIE/GIEL Bit 5 Bit 4 Bit 3 Bit 2 TMR0IE INT0IE RBIE TMR0IF TX2IF CTMUIF CCP2IF Bit 0 Reset Values on Page: INT0IF RBIF 75 CCP1IF RTCCIF 77 Bit 1 PIR3 TMR5GIF LCDIF RC2IF PIE3 TMR5GIE LCDIE RC2IE TX2IE CTMUIE CCP2IE CCP1IE RTCCIE 77 IPR3 TMR5GIP LCDIP RC2IP TX2IP CTMUIP CCP2IP CCP1IP RTCCIP 77 IPEN SBOREN CM RI TO PD POR BOR 76 (1) LCDDATA23 S47C
PIC18F87K90 FAMILY NOTES: DS39957D-page 302 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 21.0 21.1 MASTER SYNCHRONOUS SERIAL PORT (MSSP) MODULE Master SSP (MSSP) Module Overview The Master Synchronous Serial Port (MSSP) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. These peripheral devices may be serial EEPROMs, shift registers, display drivers, A/D Converters, etc.
PIC18F87K90 FAMILY 21.3.1 REGISTERS In receive operations, SSPxSR and SSPxBUF together create a double-buffered receiver. When SSPxSR receives a complete byte, it is transferred to SSPxBUF and the SSPxIF interrupt is set. Each MSSP module has four registers for SPI mode operation.
PIC18F87K90 FAMILY REGISTER 21-2: SSPxCON1: MSSPx CONTROL REGISTER 1 (SPI MODE) R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 WCOL SSPOV(1) SSPEN(2) CKP SSPM3(3) SSPM2(3) SSPM1(3) SSPM0(3) bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 WCOL: Write Collision Detect bit 1 = The SSPxBUF register is written while it is still transmitting the previous word (must
PIC18F87K90 FAMILY 21.3.2 OPERATION When initializing the SPI, several options need to be specified. This is done by programming the appropriate control bits (SSPxCON1<5:0> and SSPxSTAT<7:6>).
PIC18F87K90 FAMILY 21.3.4 ENABLING SPI I/O To enable the serial port, MSSP Enable bit, SSPEN (SSPxCON1<5>), must be set. To reset or reconfigure SPI mode, clear the SSPEN bit, reinitialize the SSPxCON registers and then set the SSPEN bit. This configures the SDIx, SDOx, SCKx and SSx pins as serial port pins.
PIC18F87K90 FAMILY 21.3.6 MASTER MODE The master can initiate the data transfer at any time because it controls the SCKx. The master determines when the slave (Processor 1, Figure 21-2) is to broadcast data by the software protocol. In Master mode, the data is transmitted/received as soon as the SSPxBUF register is written to. If the SPI is only going to receive, the SDOx output could be disabled (programmed as an input).
PIC18F87K90 FAMILY 21.3.7 SLAVE MODE In Slave mode, the data is transmitted and received as the external clock pulses appear on SCKx. When the last bit is latched, the SSPxIF interrupt flag bit is set. transmitted byte and becomes a floating output. External pull-up/pull-down resistors may be desirable depending on the application. While in Slave mode, the external clock is supplied by the external clock source on the SCKx pin.
PIC18F87K90 FAMILY FIGURE 21-5: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = 0) SSx Optional SCKx (CKP = 0 CKE = 0) SCKx (CKP = 1 CKE = 0) Write to SSPxBUF SDOx SDIx (SMP = 0) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 0 bit 7 Input Sample (SMP = 0) SSPxIF Interrupt Flag Next Q4 Cycle after Q2 SSPxSR to SSPxBUF FIGURE 21-6: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = 1) SSx Not Optional SCKx (CKP = 0 CKE = 1) SCKx (CKP = 1 CKE = 1) Write to SSPxBUF SDOx SDIx (SMP = 0) bit 7 bit 7 bit
PIC18F87K90 FAMILY 21.3.9 OPERATION IN POWER-MANAGED MODES In SPI Master mode, module clocks may be operating at a different speed than when in full-power mode; in the case of the Sleep mode, all clocks are halted. 21.3.11 BUS MODE COMPATIBILITY Table 21-1 shows the compatibility between the standard SPI modes and the states of the CKP and CKE control bits. In Idle modes, a clock is provided to the peripherals.
PIC18F87K90 FAMILY TABLE 21-2: Name REGISTERS ASSOCIATED WITH SPI OPERATION Bit 6 Bit 5 Bit 4 GIE/GIEH PEIE/GIEL TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 75 PIR1 — ADIF RC1IF TX1IF SSP1IF TMR1GIF TMR2IF TMR1IF 77 PIE1 — ADIE RC1IE TX1IE SSP1IE TMR1GIE TMR2IE TMR1IE 77 IPR1 — ADIP RC1IP TX1IP SSP1IP TMR1GIP TMR2IP TMR1IP 77 PIR2 OSCFIF — SSP2IF BCL2IF BCL1IF HLVDIF TMR3IF TMR3GIF 77 INTCON Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: Bit 7 PIE2 OSCFI
PIC18F87K90 FAMILY 21.4 I2C™ Mode 21.4.1 The MSSP module in I 2C mode fully implements all master and slave functions (including general call support), and provides interrupts on Start and Stop bits in hardware to determine a free bus (multi-master function). The MSSP module implements the standard mode specifications, as well as 7-bit and 10-bit addressing.
PIC18F87K90 FAMILY REGISTER 21-3: SSPxSTAT: MSSPx STATUS REGISTER (I2C™ MODE) R/W-0 R/W-0 R-0 R-0 R-0 R-0 R-0 R-0 SMP CKE D/A P(1) S(1) R/W(2,3) UA BF bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 SMP: Slew Rate Control bit In Master or Slave mode: 1 = Slew rate control is disabled for Standard Speed mode (100 kHz and 1 MHz) 0 = Slew rate control is enabled
PIC18F87K90 FAMILY REGISTER 21-4: R/W-0 SSPxCON1: MSSPx CONTROL REGISTER 1 (I2C™ MODE) R/W-0 WCOL SSPOV R/W-0 SSPEN (1) R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 CKP SSPM3(2) SSPM2(2) SSPM1(2) SSPM0(2) bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 WCOL: Write Collision Detect bit In Master Transmit mode: 1 = A write to the SSPxBUF register was attempted while the I2C con
PIC18F87K90 FAMILY REGISTER 21-5: SSPxCON2: MSSPx CONTROL REGISTER 2 (I2C™ MASTER MODE) R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 GCEN ACKSTAT ACKDT(1) ACKEN(2) RCEN(2) PEN(2) RSEN(2) SEN(2) bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 GCEN: General Call Enable bit Unused in Master mode.
PIC18F87K90 FAMILY REGISTER 21-6: SSPxCON2: MSSPx CONTROL REGISTER 2 (I2C™ SLAVE MODE) R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 GCEN ACKSTAT ADMSK5 ADMSK4 ADMSK3 ADMSK2 ADMSK1 SEN(1) bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 GCEN: General Call Enable bit 1 = Enables interrupt when a general call address (0000h) is received in the SSPxSR 0 = Genera
PIC18F87K90 FAMILY 21.4.2 OPERATION The MSSP module functions are enabled by setting the MSSP Enable bit, SSPEN (SSPxCON1<5>). The SSPxCON1 register allows control of the I2C operation.
PIC18F87K90 FAMILY 21.4.3.2 Address Masking Modes Masking an address bit causes that bit to become a “don’t care”. When one address bit is masked, two addresses will be Acknowledged and cause an interrupt. It is possible to mask more than one address bit at a time, which greatly expands the number of addresses Acknowledged. The I2C slave behaves the same way whether address masking is used or not. However, when address masking is used, the I2C slave can Acknowledge multiple addresses and cause interrupts.
PIC18F87K90 FAMILY 21.4.3.4 7-Bit Address Masking Mode Unlike 5-bit masking, 7-Bit Address Masking mode uses a mask of up to 8 bits (in 10-bit addressing) to define a range of addresses that can be Acknowledged, using the lowest bits of the incoming address. This allows the module to Acknowledge up to 127 different addresses with 7-bit addressing, or 255 with 10-bit addressing (see Example 21-3). This mode is the default configuration of the module and is selected when MSSPMSK is unprogrammed (‘1’).
PIC18F87K90 FAMILY 21.4.3.5 Reception When the R/W bit of the address byte is clear and an address match occurs, the R/W bit of the SSPxSTAT register is cleared. The received address is loaded into the SSPxBUF register and the SDAx line is held low (ACK). When the address byte overflow condition exists, then the no Acknowledge (ACK) pulse is given. An overflow condition is defined as either bit, BF (SSPxSTAT<0>), is set or bit, SSPOV (SSPxCON1<6>), is set.
DS39957D-page 322 2 A6 3 4 A4 5 A3 Receiving Address A5 6 A2 (CKP does not reset to ‘0’ when SEN = 0) CKP (SSPxCON<4>) SSPOV (SSPxCON1<6>) BF (SSPxSTAT<0>) SSPxIF (PIR1<3> or PIR3<7>) 1 SCLx S A7 7 A1 8 9 ACK R/W = 0 1 D7 3 4 D4 5 D3 Receiving Data D5 Cleared in software SSPxBUF is read 2 D6 6 D2 7 D1 8 D0 9 ACK 1 D7 2 D6 3 4 D4 5 D3 Receiving Data D5 6 D2 7 D1 8 D0 Bus master terminates transfer P SSPOV is set because SSPxBUF is still full.
2009-2011 Microchip Technology Inc. 2 A6 Note 3 A5 4 X 5 A3 6 X 1 3 4 D4 Cleared in software SSPxBUF is read 2 D5 5 D3 6 D2 7 D1 8 D0 In this example, an address equal to A7.A6.A5.X.A3.X.X will be Acknowledged and cause an interrupt. 9 D6 x = Don’t care (i.e., address bit can either be a ‘1’ or a ‘0’).
DS39957D-page 324 2 Data in sampled 1 A6 CKP (SSPxCON<4>) BF (SSPxSTAT<0>) SSPxIF (PIR1<3> or PIR3<7>) S A7 3 4 A4 5 A3 6 A2 Receiving Address A5 7 A1 8 R/W = 1 9 ACK 3 D5 4 5 D3 SSPxBUF is written in software 6 D2 Transmitting Data D4 Cleared in software 2 D6 CKP is set in software Clear by reading SCLx held low while CPU responds to SSPxIF 1 D7 7 8 D0 9 From SSPxIF ISR D1 ACK 1 D7 4 D4 5 D3 Cleared in software 3 D5 6 D2 CKP is set in software SS
2009-2011 Microchip Technology Inc. 2 1 3 1 5 0 7 A8 8 UA is set indicating that the SSPxADD needs to be updated SSPxBUF is written with contents of SSPxSR 6 A9 9 2 X 4 5 A3 6 A2 4 5 6 Cleared in software 3 7 8 9 1 2 4 5 6 Cleared in software 3 D3 D2 Receive Data Byte D1 D0 ACK D7 D6 D5 D4 Cleared by hardware when SSPxADD is updated with high byte of address 2 D3 D2 Note that the Most Significant bits of the address are not affected by the bit masking.
DS39957D-page 326 2 1 3 1 4 1 5 0 7 A8 8 UA is set indicating that the SSPxADD needs to be updated SSPxBUF is written with contents of SSPxSR 6 A9 9 (CKP does not reset to ‘0’ when SEN = 0) CKP (SSPxCON<4>) UA (SSPxSTAT<1>) SSPOV (SSPxCON1<6>) BF (SSPxSTAT<0>) Cleared in software SSPxIF (PIR1<3> or PIR3<7>) 1 SCLx S 1 ACK R/W = 0 A7 2 4 A4 5 A3 6 A2 8 9 A0 ACK UA is set indicating that SSPxADD needs to be updated Cleared by hardware when SSPxADD is updated with low b
2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 21.4.4 CLOCK STRETCHING Both 7-Bit and 10-Bit Slave modes implement automatic clock stretching during a transmit sequence. The SEN bit (SSPxCON2<0>) allows clock stretching to be enabled during receives. Setting SEN will cause the SCLx pin to be held low at the end of each data receive sequence. 21.4.4.
PIC18F87K90 FAMILY 21.4.4.5 Clock Synchronization and the CKP bit When the CKP bit is cleared, the SCLx output is forced to ‘0’. However, clearing the CKP bit will not assert the SCLx output low until the SCLx output is already sampled low. Therefore, the CKP bit will not assert the SCLx line until an external I2C master device has FIGURE 21-14: already asserted the SCLx line. The SCLx output will remain low until the CKP bit is set and all other devices on the I2C bus have deasserted SCLx.
DS39957D-page 330 2 A6 CKP (SSPxCON<4>) SSPOV (SSPxCON1<6>) BF (SSPxSTAT<0>) SSPxIF (PIR1<3> or PIR3<7>) 1 SCLx S A7 3 4 A4 5 A3 6 A2 Receiving Address A5 7 A1 8 9 ACK R/W = 0 3 4 D4 5 D3 Receiving Data D5 Cleared in software 2 D6 If BF is cleared prior to the falling edge of the 9th clock, CKP will not be reset to ‘0’ and no clock stretching will occur SSPxBUF is read 1 D7 6 D2 7 D1 9 ACK 1 D7 BF is set after falling edge of the 9th clock, CKP is reset to ‘0’ a
2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 21.4.5 GENERAL CALL ADDRESS SUPPORT If the general call address matches, the SSPxSR is transferred to the SSPxBUF, the BF flag bit is set (eighth bit), and on the falling edge of the ninth bit (ACK bit), the SSPxIF interrupt flag bit is set. The addressing procedure for the I2C bus is such that the first byte after the Start condition usually determines which device will be the slave addressed by the master. The exception is the general call address which can address all devices.
PIC18F87K90 FAMILY MASTER MODE Note: Master mode is enabled by setting and clearing the appropriate SSPM bits in SSPxCON1 and by setting the SSPEN bit. In Master mode, the SCLx and SDAx lines are manipulated by the MSSP hardware if the TRIS bits are set. Master mode of operation is supported by interrupt generation on the detection of the Start and Stop conditions. The Stop (P) and Start (S) bits are cleared from a Reset or when the MSSP module is disabled.
PIC18F87K90 FAMILY 21.4.6.1 I2C Master Mode Operation The master device generates all of the serial clock pulses and the Start and Stop conditions. A transfer is ended with a Stop condition or with a Repeated Start condition. Since the Repeated Start condition is also the beginning of the next serial transfer, the I2C bus will not be released. In Master Transmitter mode, serial data is output through SDAx while SCLx outputs the serial clock.
PIC18F87K90 FAMILY 21.4.7 BAUD RATE 21.4.7.1 2 In I C Master mode, the Baud Rate Generator (BRG) reload value is placed in the lower 7 bits of the SSPxADD register (Figure 21-19). When a write occurs to SSPxBUF, the Baud Rate Generator will automatically begin counting. The BRG counts down to 0 and stops until another reload has taken place. The BRG count is decremented twice per instruction cycle (TCY) on the Q2 and Q4 clocks. In I2C Master mode, the BRG is reloaded automatically.
PIC18F87K90 FAMILY 21.4.7.2 Clock Arbitration Clock arbitration occurs when the master, during any receive, transmit or Repeated Start/Stop condition, deasserts the SCLx pin (SCLx allowed to float high). When the SCLx pin is allowed to float high, the Baud Rate Generator (BRG) is suspended from counting until the SCLx pin is actually sampled high. When the FIGURE 21-20: SDAx SCLx pin is sampled high, the Baud Rate Generator is reloaded with the contents of SSPxADD<6:0> and begins counting.
PIC18F87K90 FAMILY 21.4.8 I2C™ MASTER MODE START CONDITION TIMING Note: To initiate a Start condition, the user sets the Start Enable bit, SEN (SSPxCON2<0>). If the SDAx and SCLx pins are sampled high, the Baud Rate Generator is reloaded with the contents of SSPxADD<6:0> and starts its count. If SCLx and SDAx are both sampled high when the Baud Rate Generator times out (TBRG), the SDAx pin is driven low.
PIC18F87K90 FAMILY 21.4.9 I2C™ MASTER MODE REPEATED START CONDITION TIMING Note 1: If RSEN is programmed while any other event is in progress, it will not take effect. A Repeated Start condition occurs when the RSEN bit (SSPxCON2<1>) is programmed high and the I2C logic module is in the Idle state. When the RSEN bit is set, the SCLx pin is asserted low. When the SCLx pin is sampled low, the Baud Rate Generator is loaded with the contents of SSPxADD<5:0> and begins counting.
PIC18F87K90 FAMILY 21.4.10 I2C™ MASTER MODE TRANSMISSION Transmission of a data byte, a 7-bit address or the other half of a 10-bit address, is accomplished by simply writing a value to the SSPxBUF register. This action will set the Buffer Full flag bit, BF, and allow the Baud Rate Generator to begin counting and start the next transmission. Each bit of address/data will be shifted out onto the SDAx pin after the falling edge of SCLx is asserted (see data hold time specification Parameter 106).
DS39957D-page 340 S R/W PEN SEN BF (SSPxSTAT<0>) SSPxIF SCLx SDAx A6 A5 A4 A3 A2 A1 3 4 5 Cleared in software 2 6 7 8 After Start condition, SEN cleared by hardware SSPxBUF written 1 9 D7 1 SCLx held low while CPU responds to SSPxIF ACK = 0 R/W = 0 SSPxBUF written with 7-bit address and R/W, start transmit A7 Transmit Address to Slave 3 D5 4 D4 5 D3 6 D2 7 D1 8 D0 SSPxBUF is written in software Cleared in software service routine from MSSP interrupt 2 D6 Trans
2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 21.4.12 ACKNOWLEDGE SEQUENCE TIMING 21.4.13 A Stop bit is asserted on the SDAx pin at the end of a receive/transmit by setting the Stop Sequence Enable bit, PEN (SSPxCON2<2>). At the end of a receive/transmit, the SCLx line is held low after the falling edge of the ninth clock. When the PEN bit is set, the master will assert the SDAx line low. When the SDAx line is sampled low, the Baud Rate Generator is reloaded and counts down to 0.
PIC18F87K90 FAMILY 21.4.14 SLEEP OPERATION 21.4.17 2 While in Sleep mode, the I C module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from Sleep (if the MSSP interrupt is enabled). 21.4.15 EFFECTS OF A RESET A Reset disables the MSSP module and terminates the current transfer. 21.4.
PIC18F87K90 FAMILY 21.4.17.1 Bus Collision During a Start Condition During a Start condition, a bus collision occurs if: a) b) SDAx or SCLx is sampled low at the beginning of the Start condition (Figure 21-28). SCLx is sampled low before SDAx is asserted low (Figure 21-29). During a Start condition, both the SDAx and the SCLx pins are monitored. If the SDAx pin is sampled low during this count, the BRG is reset and the SDAx line is asserted early (Figure 21-30).
PIC18F87K90 FAMILY FIGURE 21-29: BUS COLLISION DURING START CONDITION (SCLx = 0) SDAx = 0, SCLx = 1 TBRG TBRG SDAx Set SEN, Enable Start Sequence if SDAx = 1, SCLx = 1 SCLx SCLx = 0 before SDAx = 0, Bus Collision Occurs. Set BCLxIF. SEN SCLx = 0 before BRG Time-out, Bus Collision Occurs. Set BCLxIF.
PIC18F87K90 FAMILY 21.4.17.2 Bus Collision During a Repeated Start Condition If SDAx is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ‘0’, Figure 21-31). If SDAx is sampled high, the BRG is reloaded and begins counting. If SDAx goes from high-to-low before the BRG times out, no bus collision occurs because no two masters can assert SDAx at exactly the same time.
PIC18F87K90 FAMILY 21.4.17.3 Bus Collision During a Stop Condition The Stop condition begins with SDAx asserted low. When SDAx is sampled low, the SCLx pin is allowed to float. When the pin is sampled high (clock arbitration), the Baud Rate Generator is loaded with SSPxADD<6:0> and counts down to 0. After the BRG times out, SDAx is sampled. If SDAx is sampled low, a bus collision has occurred. This is due to another master attempting to drive a data ‘0’ (Figure 21-33).
PIC18F87K90 FAMILY TABLE 21-4: Name INTCON REGISTERS ASSOCIATED WITH I2C™ OPERATION Bit 7 Bit 6 GIE/GIEH PEIE/GIEL Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 75 PIR1 — ADIF RC1IF TX1IF SSP1IF TMR1GIF TMR2IF TMR1IF 77 PIE1 — ADIE RC1IE TX1IE SSP1IE TMR1GIE TMR2IE TMR1IE 77 IPR1 — ADIP RC1IP TX1IP SSP1IP TMR1GIP TMR2IP TMR1IP 77 PIR2 OSCFIF — SSP2IF BLC2IF BCL1IF HLVDIF TMR3IF TMR3GIF 77 PIE2 OSCFIE
PIC18F87K90 FAMILY 22.0 ENHANCED UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (EUSART) The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module is one of two serial I/O modules. (Generically, the EUSART is also known as a Serial Communications Interface or SCI.) The EUSART can be configured as a full-duplex, asynchronous system that can communicate with peripheral devices, such as CRT terminals and personal computers.
PIC18F87K90 FAMILY REGISTER 22-1: TXSTAx: TRANSMIT STATUS AND CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R-1 R/W-0 CSRC TX9 TXEN(1) SYNC SENDB BRGH TRMT TX9D bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 CSRC: Clock Source Select bit Asynchronous mode: Don’t care.
PIC18F87K90 FAMILY REGISTER 22-2: RCSTAx: RECEIVE STATUS AND CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R-0 R-0 R-x SPEN RX9 SREN CREN ADDEN FERR OERR RX9D bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 SPEN: Serial Port Enable bit 1 = Serial port is enabled 0 = Serial is port disabled (held in Reset) bit 6 RX9: 9-Bit Receive Enable bit 1 = Selects 9-bi
PIC18F87K90 FAMILY REGISTER 22-3: BAUDCONx: BAUD RATE CONTROL REGISTER R/W-0 R-1 R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 ABDOVF RCIDL RXDTP TXCKP BRG16 — WUE ABDEN bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 ABDOVF: Auto-Baud Acquisition Rollover Status bit 1 = A BRG rollover has occurred during Auto-Baud Rate Detect mode (must be cleared in software) 0 = No BRG
PIC18F87K90 FAMILY 22.1 Baud Rate Generator (BRG) The BRG is a dedicated, 8-bit or 16-bit generator that supports both the Asynchronous and Synchronous modes of the EUSART. By default, the BRG operates in 8-bit mode; setting the BRG16 bit (BAUDCONx<3>) selects 16-bit mode. The SPBRGHx:SPBRGx register pair controls the period of a free-running timer. In Asynchronous mode, bits, BRGH (TXSTAx<2>) and BRG16 (BAUDCONx<3>), also control the baud rate. In Synchronous mode, BRGH is ignored.
PIC18F87K90 FAMILY EXAMPLE 22-1: CALCULATING BAUD RATE ERROR For a device with FOSC of 16 MHz, desired baud rate of 9600, Asynchronous mode, and 8-bit BRG: Desired Baud Rate = FOSC/(64 ([SPBRGHx:SPBRGx] + 1)) Solving for SPBRGHx:SPBRGx: X = ((FOSC/Desired Baud Rate)/64) – 1 = ((16000000/9600)/64) – 1 = [25.042] = 25 Calculated Baud Rate = 16000000/(64 (25 + 1)) = 9615 Error = (Calculated Baud Rate – Desired Baud Rate)/Desired Baud Rate = (9615 – 9600)/9600 = 0.
PIC18F87K90 FAMILY TABLE 22-3: BAUD RATES FOR ASYNCHRONOUS MODES SYNC = 0, BRGH = 0, BRG16 = 0 BAUD RATE (K) FOSC = 40.000 MHz FOSC = 20.000 MHz FOSC = 10.000 MHz (decimal) % Error — — — — — 1.221 2.441 1.73 255 9.615 0.16 64 19.531 1.73 31 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 — — — 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 — — — % Error 0.3 1.2 — — 2.4 9.6 19.2 SPBRG value (decimal) Actual Rate (K) % Error — 1.73 — 255 — 1.
PIC18F87K90 FAMILY TABLE 22-3: BAUD RATES FOR ASYNCHRONOUS MODES (CONTINUED) SYNC = 0, BRGH = 0, BRG16 = 1 BAUD RATE (K) FOSC = 40.000 MHz Actual Rate (K) % Error FOSC = 20.000 MHz SPBRG value (decimal) Actual Rate (K) % Error FOSC = 10.000 MHz (decimal) Actual Rate (K) SPBRG value % Error FOSC = 8.000 MHz (decimal) Actual Rate (K) % Error SPBRG value SPBRG value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 0.300 -0.04 1.2 1.200 0.02 2082 1.200 -0.
PIC18F87K90 FAMILY 22.1.3 AUTO-BAUD RATE DETECT The Enhanced USART module supports the automatic detection and calibration of baud rate. This feature is active only in Asynchronous mode and while the WUE bit is clear. The automatic baud rate measurement sequence (Figure 22-1) begins whenever a Start bit is received and the ABDEN bit is set. The calculation is self-averaging. While the ABD sequence takes place, the EUSART state machine is held in Idle.
PIC18F87K90 FAMILY FIGURE 22-1: BRG Value AUTOMATIC BAUD RATE CALCULATION XXXXh RXx Pin 0000h 001Ch Start Edge #1 Bit 1 Bit 0 Edge #2 Bit 3 Bit 2 Edge #3 Bit 5 Bit 4 Edge #4 Bit 7 Bit 6 Edge #5 Stop Bit BRG Clock Auto-Cleared Set by User ABDEN bit RCxIF bit (Interrupt) Read RCREGx SPBRGx XXXXh 1Ch SPBRGHx XXXXh 00h Note: The ABD sequence requires the EUSART module to be configured in Asynchronous mode and WUE = 0.
PIC18F87K90 FAMILY 22.2 Once the TXREGx register transfers the data to the TSR register (occurs in one TCY), the TXREGx register is empty and the TXxIF flag bit is set. This interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, TXxIE. TXxIF will be set regardless of the state of TXxIE; it cannot be cleared in software. TXxIF is also not cleared immediately upon loading TXREGx, but becomes valid in the second instruction cycle following the load instruction.
PIC18F87K90 FAMILY FIGURE 22-4: Write to TXREGx BRG Output (Shift Clock) ASYNCHRONOUS TRANSMISSION Word 1 TXx (pin) Start bit FIGURE 22-5: bit 1 bit 7/8 Stop bit Word 1 TXxIF bit (Transmit Buffer Reg. Empty Flag) TRMT bit (Transmit Shift Reg. Empty Flag) bit 0 1 TCY Word 1 Transmit Shift Reg ASYNCHRONOUS TRANSMISSION (BACK-TO-BACK) Write to TXREGx Word 1 Word 2 BRG Output (Shift Clock) TXx (pin) TXxIF bit (Interrupt Reg. Flag) TRMT bit (Transmit Shift Reg.
PIC18F87K90 FAMILY TABLE 22-5: Name INTCON REGISTERS ASSOCIATED WITH ASYNCHRONOUS TRANSMISSION Bit 7 Bit 6 GIE/GIEH PEIE/GIEL Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: TMR0IE INT0IE RBIE TMR0IF INT0IF RBIF 75 PIR1 — ADIF RC1IF TX1IF SSP1IF TMR1GIF TMR2IF TMR1IF 77 PIE1 — ADIE RC1IE TX1IE SSP1IE TMR1GIE TMR2IE TMR1IE 77 IPR1 — ADIP RC1IP TX1IP SSP1IP TMR1GIP TMR2IP TMR1IP 77 PIR3 TMR5GIF LCDIF RC2IF TX2IF CTMUIF CCP2IF CCP1IF RTCCIF 77
PIC18F87K90 FAMILY 22.2.2 EUSART ASYNCHRONOUS RECEIVER 22.2.3 The receiver block diagram is shown in Figure 22-6. The data is received on the RXx pin and drives the data recovery block. The data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at FOSC. This mode would typically be used in RS-232 systems. This mode would typically be used in RS-485 systems.
PIC18F87K90 FAMILY FIGURE 22-7: ASYNCHRONOUS RECEPTION Start bit RXx (pin) bit 0 bit 7/8 Stop bit bit 1 Rcv Shift Reg Rcv Buffer Reg Start bit bit 0 Stop bit Start bit bit 7/8 Stop bit Word 2 RCREGx Word 1 RCREGx Read Rcv Buffer Reg RCREGx bit 7/8 RCxIF (Interrupt Flag) OERR bit CREN Note: This timing diagram shows three words appearing on the RXx input. The RCREGx (Receive Buffer) is read after the third word causing the OERR (Overrun) bit to be set.
PIC18F87K90 FAMILY 22.2.4 AUTO-WAKE-UP ON SYNC BREAK CHARACTER During Sleep mode, all clocks to the EUSART are suspended. Because of this, the Baud Rate Generator is inactive and a proper byte reception cannot be performed. The auto-wake-up feature allows the controller to wake-up due to activity on the RXx/DTx line while the EUSART is operating in Asynchronous mode. The auto-wake-up feature is enabled by setting the WUE bit (BAUDCONx<1>).
PIC18F87K90 FAMILY 22.2.4.2 Special Considerations Using the WUE Bit The timing of WUE and RCxIF events may cause some confusion when it comes to determining the validity of received data. As noted, setting the WUE bit places the EUSART in an Idle mode. The wake-up event causes a receive interrupt by setting the RCxIF bit. The WUE bit is cleared after this when a rising edge is seen on RXx/DTx. The interrupt condition is then cleared by reading the RCREGx register.
PIC18F87K90 FAMILY 22.2.5 BREAK CHARACTER SEQUENCE The EUSART module has the capability of sending the special Break character sequences that are required by the LIN/J2602 bus standard. The Break character transmit consists of a Start bit, followed by twelve ‘0’ bits and a Stop bit. The Frame Break character is sent whenever the SENDB and TXEN bits (TXSTAx<3> and TXSTAx<5>, respectively) are set while the Transmit Shift Register is loaded with data.
PIC18F87K90 FAMILY 22.3 Once the TXREGx register transfers the data to the TSR register (occurs in one TCY), the TXREGx is empty and the TXxIF flag bit is set. The interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, TXxIE. TXxIF is set regardless of the state of enable bit, TXxIE; it cannot be cleared in software. It will reset only when new data is loaded into the TXREGx register.
PIC18F87K90 FAMILY FIGURE 22-12: SYNCHRONOUS TRANSMISSION (THROUGH TXEN) RC7/RX1/DT1/SEG28 Pin bit 0 bit 1 bit 2 bit 6 bit 7 RC6/TX1/CK1/SEG27 Pin Write to TXREG1 reg TX1IF bit TRMT bit TXEN bit Note: This example is equally applicable to EUSART2 (RG1/TX2/CK2/AN19/C3OUT and RG2/RX2/DT2/AN18/C3INA).
PIC18F87K90 FAMILY 22.3.2 EUSART SYNCHRONOUS MASTER RECEPTION 3. 4. 5. 6. Ensure bits, CREN and SREN, are clear. If interrupts are desired, set enable bit, RCxIE. If 9-bit reception is desired, set bit, RX9. If a single reception is required, set bit, SREN. For continuous reception, set bit, CREN. 7. Interrupt flag bit, RCxIF, will be set when reception is complete and an interrupt will be generated if the enable bit, RCxIE, was set. 8.
PIC18F87K90 FAMILY TABLE 22-8: Name INTCON REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER RECEPTION Bit 7 Bit 6 Bit 5 GIE/GIEH PEIE/GIEL TMR0IE Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: INT0IE RBIE TMR0IF INT0IF RBIF 75 TMR1GIF PIR1 — ADIF RC1IF TX1IF SSP1IF TMR2IF TMR1IF 77 PIE1 — ADIE RC1IE TX1IE SSP1IE TMR1GIE TMR2IE TMR1IE 77 IPR1 — ADIP RC1IP TX1IP SSP1IP TMR1GIP TMR2IP TMR1IP 77 PIR3 TMR5GIF LCDIF RC2IF TX2IF CTMUIF CCP2IF CCP1IF RTCCIF 77 P
PIC18F87K90 FAMILY 22.4 e) EUSART Synchronous Slave Mode Synchronous Slave mode is entered by clearing bit, CSRC (TXSTAx<7>). This mode differs from the Synchronous Master mode in that the shift clock is supplied externally at the CKx pin (instead of being supplied internally in Master mode). This allows the device to transfer or receive data while in any low-power mode. 22.4.
PIC18F87K90 FAMILY 22.4.2 EUSART SYNCHRONOUS SLAVE RECEPTION To set up a Synchronous Slave Reception: 1. The operation of the Synchronous Master and Slave modes is identical, except in the case of Sleep, or any Idle mode, and bit, SREN, which is a “don’t care” in Slave mode. If receive is enabled by setting the CREN bit prior to entering Sleep or any Idle mode, then a word may be received while in this low-power mode.
PIC18F87K90 FAMILY 23.0 12-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE The Analog-to-Digital (A/D) Converter module in the PIC18F87K90 family of devices has 16 inputs for the 64-pin devices and 24 inputs for the 80-pin devices. This module allows conversion of an analog input signal to a corresponding signed 12-bit digital number.
PIC18F87K90 FAMILY 23.2 A/D Registers 23.2.
PIC18F87K90 FAMILY REGISTER 23-2: ADCON1: A/D CONTROL REGISTER 1 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 TRIGSEL1 TRIGSEL0 VCFG1 VCFG0 VNCFG CHSN2 CHSN1 CHSN0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7-6 TRIGSEL<1:0>: Special Trigger Select bits 11 = Selects the special trigger from the RTCC 10 = Selects the special trigger from the Timer1 01 = Se
PIC18F87K90 FAMILY REGISTER 23-3: ADCON2: A/D CONTROL REGISTER 2 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 ADFM — ACQT2 ACQT1 ACQT0 ADCS2 ADCS1 ADCS0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 ADFM: A/D Result Format Select bit 1 = Right justified 0 = Left justified bit 6 Unimplemented: Read as ‘0’ bit 5-3 ACQT<2:0>: A/D Acquisition Time Select bits 111 = 20 TAD 110
PIC18F87K90 FAMILY 23.2.2 A/D RESULT REGISTERS The ADRESH:ADRESL register pair is where the 12-bit A/D result and extended sign bits (ADSGN) are loaded at the completion of a conversion. This register pair is 16 bits wide. The A/D module gives the flexibility of left or right justifying the 12-bit result in the 16-Bit Result register. The A/D Format Select bit (ADFM) controls this justification. performed on the result. The results are represented as a two's compliment binary value.
PIC18F87K90 FAMILY REGISTER 23-4: ADRESH: A/D RESULT HIGH BYTE REGISTER, LEFT JUSTIFIED (ADFM = 0) R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x ADRES11 ADRES10 ADRES9 ADRES8 ADRES7 ADRES6 ADRES5 ADRES4 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-0 x = Bit is unknown ADRES<11:4>: A/D Result High Byte bits REGISTER 23-5: ADRESL: A/D RESULT LOW BYTE REGISTER, LEFT JUSTIFI
PIC18F87K90 FAMILY REGISTER 23-6: ADRESH: A/D RESULT HIGH BYTE REGISTER, RIGHT JUSTIFIED (ADFM = 1) R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x ADSGN ADSGN ADSGN ADSGN ADRES11 ADRES10 ADRES9 ADRES8 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-4 ADSGN: A/D Result Sign bits 1 = A/D result is negative 0 = A/D result is positive bit 3-0 ADRES<11:8>: A/D Result High Byte bit
PIC18F87K90 FAMILY The ANCONx registers are used to configure the operation of the I/O pin associated with each analog channel. Clearing a ANSELx bit configures the corresponding pin (ANx) to operate as a digital only I/O. Setting a bit configures the pin to operate as an analog REGISTER 23-8: input for either the A/D Converter or the comparator module, with all digital peripherals disabled and digital inputs read as ‘0’.
PIC18F87K90 FAMILY REGISTER 23-10: ANCON2: A/D PORT CONFIGURATION REGISTER 2 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 ANSEL23(1) ANSEL22(1) ANSEL21(1) ANSEL20(1) ANSEL19 ANSEL18 ANSEL17 ANSEL16 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-0 Note 1: x = Bit is unknown ANSEL<23:16>: Analog Port Configuration bits (AN23 through AN16) 0 = Pin configured as a digital port 1
PIC18F87K90 FAMILY FIGURE 23-4: A/D BLOCK DIAGRAM CHS<4:0> 11111 VDDCORE 11101 Reserved Temperature Diode Reserved CTMU 11100 12-Bit A/D Converter 1.
PIC18F87K90 FAMILY After the A/D module has been configured as desired, the selected channel must be acquired before the conversion can start. The analog input channels must have their corresponding TRIS bits selected as inputs. To determine acquisition time, see Section 23.3 “A/D Acquisition Requirements”. After this acquisition time has elapsed, the A/D conversion can be started. An acquisition time can be programmed to occur between setting the GO/DONE bit and the actual start of the conversion. 2.
PIC18F87K90 FAMILY 23.3 A/D Acquisition Requirements For the A/D Converter to meet its specified accuracy, the charge holding capacitor (CHOLD) must be allowed to fully charge to the input channel voltage level. The analog input model is shown in Figure 23-5. The source impedance (RS) and the internal sampling switch (RSS) impedance directly affect the time required to charge the capacitor CHOLD. The sampling switch (RSS) impedance varies over the device voltage (VDD).
PIC18F87K90 FAMILY 23.4 Selecting and Configuring Automatic Acquisition Time The ADCON2 register allows the user to select an acquisition time that occurs each time the GO/DONE bit is set. When the GO/DONE bit is set, sampling is stopped and a conversion begins. The user is responsible for ensuring the required acquisition time has passed between selecting the desired input channel and setting the GO/DONE bit.
PIC18F87K90 FAMILY 23.7 ADRESH:ADRESL registers will continue to contain the value of the last completed conversion (or the last value written to the ADRESH:ADRESL registers). A/D Conversions Figure 23-6 shows the operation of the A/D Converter after the GO/DONE bit has been set and the ACQT<2:0> bits are cleared. A conversion is started after the following instruction to allow entry into Sleep mode before the conversion begins.
PIC18F87K90 FAMILY 23.
PIC18F87K90 FAMILY TABLE 23-2: Name INTCON SUMMARY OF A/D REGISTERS Bit 7 Bit 6 Bit 5 GIE/GIEH PEIE/GIEL TMR0IE Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Values on Page: INT0IE RBIE TMR0IF INT0IF RBIF 75 PIR1 — ADIF RC1IF TX1IF SSP1IF TMR1GIF TMR2IF TMR1IF 77 PIE1 — ADIE RC1IE TX1IE SSP1IE TMR1GIE TMR2IE TMR1IE 77 IPR1 — ADIP RC1IP TX1IP SSP1IP TMR1GIP TMR2IP TMR1IP 77 ADRESH A/D Result Register High Byte 76 ADRESL A/D Result Register Low Byte 76 ADCON0 ADCON1
PIC18F87K90 FAMILY 24.0 COMPARATOR MODULE 24.1 The analog comparator module contains three comparators that can be independently configured in a variety of ways. The inputs can be selected from the analog inputs and two internal voltage references. The digital outputs are available at the pin level and can also be read through the control register. Multiple output and interrupt event generation are also available. A generic single comparator from the module is shown in Figure 24-1.
PIC18F87K90 FAMILY REGISTER 24-1: CMxCON: COMPARATOR CONTROL x REGISTER R/W-0 R/W-0 R/W-0 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 CON COE CPOL EVPOL1 EVPOL0 CREF CCH1 CCH0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 CON: Comparator Enable bit 1 = Comparator is enabled 0 = Comparator is disabled bit 6 COE: Comparator Output Enable bit 1 = Comparator output is pres
PIC18F87K90 FAMILY REGISTER 24-2: CMSTAT: COMPARATOR STATUS REGISTER R-1 R-1 R-1 U-0 U-0 U-0 U-0 U-0 CMP3OUT CMP2OUT CMP1OUT — — — — — bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 CMPxOUT<3:1>: Comparator x Status bits If CPOL (CMxCON<5>)= 0 (non-inverted polarity): 1 = Comparator x’s VIN+ > VIN0 = Comparator x’s VIN+ < VINIf CPOL = 1 (inverted polarity): 1 = Comparator x’s
PIC18F87K90 FAMILY 24.2 Comparator Operation 24.3 Comparator Response Time A single comparator is shown in Figure 24-2, along with the relationship between the analog input levels and the digital output. When the analog input at VIN+ is less than the analog input, VIN-, the output of the comparator is a digital low level. When the analog input at VIN+ is greater than the analog input, VIN-, the output of the comparator is a digital high level.
PIC18F87K90 FAMILY 24.5 Comparator Control and Configuration Each comparator has up to eight possible combinations of inputs: up to four external analog inputs and one of two internal voltage references. All of the comparators allow a selection of the signal from pin, CxINA, or the voltage from the Comparator Voltage Reference (CVREF) on the non-inverting channel. This is compared to either CxINB, CxINC, C2INB/C2IND or the microcontroller’s fixed internal reference voltage (VBG, 1.
PIC18F87K90 FAMILY FIGURE 24-4: COMPARATOR CONFIGURATIONS Comparator Off CON = 0, CREF = x, CCH<1:0> = xx COE VINCx VIN+ Off (Read as ‘0’) CxOUT Pin Comparator CxINC > CxINA Compare(2,3) CON = 1, CREF = 0, CCH<1:0> = 01 Comparator CxINB > CxINA Compare CON = 1, CREF = 0, CCH<1:0> = 00 COE CxINB CxINA COE VINVIN+ CxINC Cx CxOUT Pin Comparator CxIND > CxINA Compare(3) CON = 1, CREF = 0, CCH<1:0> = 10 CxINA VINVIN+ Cx Comparator VIRV > CxINA Compare CON = 1, CREF = 0, CCH<1:0> = 11 COE C2INB
PIC18F87K90 FAMILY 24.6 Comparator Interrupts The comparator interrupt flag is set whenever any of the following occurs: • Low-to-high transition of the comparator output • High-to-low transition of the comparator output • Any change in the comparator output The comparator interrupt selection is done by the EVPOL<1:0> bits in the CMxCON register (CMxCON<4:3>). In order to provide maximum flexibility, the output of the comparator may be inverted using the CPOL bit in the CMxCON register (CMxCON<5>).
PIC18F87K90 FAMILY 24.7 To minimize power consumption while in Sleep mode, turn off the comparators (CON = 0) before entering Sleep. If the device wakes up from Sleep, the contents of the CMxCON register are not affected. Comparator Operation During Sleep When a comparator is active and the device is placed in Sleep mode, the comparator remains active and the interrupt is functional, if enabled. This interrupt will wake up the device from Sleep mode, when enabled.
PIC18F87K90 FAMILY 25.0 COMPARATOR VOLTAGE REFERENCE MODULE EQUATION 25-1: If CVRSS = 1: The comparator voltage reference is a 32-tap resistor ladder network that provides a selectable reference voltage. Although its primary purpose is to provide a reference for the analog comparators, it may also be used independently of them. A block diagram of the module is shown in Figure 25-1.
PIC18F87K90 FAMILY FIGURE 25-1: COMPARATOR VOLTAGE REFERENCE BLOCK DIAGRAM VREF+ AVDD CVRSS = 1 CVRSS = 0 CVR<4:0> CVREN R R 32-to-1 MUX R 32 Steps R CVREF R R VREF- CVRSS = 1 CVRSS = 0 25.2 Voltage Reference Accuracy/Error The full range of voltage reference cannot be realized due to the construction of the module. The transistors on the top and bottom of the resistor ladder network (Figure 25-1) keep CVREF from approaching the reference source rails.
PIC18F87K90 FAMILY FIGURE 25-2: COMPARATOR VOLTAGE REFERENCE OUTPUT BUFFER EXAMPLE PIC18F87K90 CVREF Module R(1) Voltage Reference Output Impedance Note 1: TABLE 25-1: + – RF5 CVREF Output R is dependent upon the Voltage Reference Configuration bits, CVRCON<3:0> and CVRCON<5>.
PIC18F87K90 FAMILY NOTES: DS39957D-page 400 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 26.0 HIGH/LOW-VOLTAGE DETECT (HLVD) The PIC18F87K90 family of devices has a High/LowVoltage Detect module (HLVD). This is a programmable circuit that sets both a device voltage trip point and the direction of change from that point. If the device experiences an excursion past the trip point in that direction, an interrupt flag is set. If the interrupt is enabled, the program execution branches to the interrupt vector address and the software responds to the interrupt.
PIC18F87K90 FAMILY The module is enabled by setting the HLVDEN bit (HLVDCON<4>). Each time the HLVD module is enabled, the circuitry requires some time to stabilize. The IRVST bit (HLVDCON<5>) is a read-only bit used to indicate when the circuit is stable. The module can only generate an interrupt after the circuit is stable and IRVST is set. trip point voltage.
PIC18F87K90 FAMILY 26.2 Depending on the application, the HLVD module does not need to operate constantly. To reduce current requirements, the HLVD circuitry may only need to be enabled for short periods where the voltage is checked. After such a check, the module could be disabled. HLVD Setup To set up the HLVD module: 1. 2. 3. 4. 5. Select the desired HLVD trip point by writing the value to the HLVDL<3:0> bits. Set the VDIRMAG bit to detect high voltage (VDIRMAG = 1) or low voltage (VDIRMAG = 0).
PIC18F87K90 FAMILY FIGURE 26-3: HIGH-VOLTAGE DETECT OPERATION (VDIRMAG = 1) CASE 1: HLVDIF May Not be Set VHLVD VDD HLVDIF Enable HLVD TIRVST IRVST HLVDIF Cleared in Software Internal Reference is Stable CASE 2: VHLVD VDD HLVDIF Enable HLVD TIRVST IRVST Internal Reference is Stable HLVDIF Cleared in Software HLVDIF Cleared in Software, HLVDIF remains Set since HLVD Condition still Exists Applications In many applications, it is desirable to detect a drop below, or rise above, a particular voltage
PIC18F87K90 FAMILY 26.6 Operation During Sleep 26.7 When enabled, the HLVD circuitry continues to operate during Sleep. If the device voltage crosses the trip point, the HLVDIF bit will be set and the device will wake-up from Sleep. Device execution will continue from the interrupt vector address if interrupts have been globally enabled. TABLE 26-1: Name A device Reset forces all registers to their Reset state. This forces the HLVD module to be turned off.
PIC18F87K90 FAMILY NOTES: DS39957D-page 406 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 27.0 • • • • Control of response to edges Time measurement resolution of 1 nanosecond High-precision time measurement Time delay of external or internal signal asynchronous to system clock • Accurate current source suitable for capacitive measurement CHARGE TIME MEASUREMENT UNIT (CTMU) The Charge Time Measurement Unit (CTMU) is a flexible analog module that provides accurate differential time measurement between pulse sources, as well as asynchronous pulse generation.
PIC18F87K90 FAMILY 27.1 The CTMUCONH and CTMUCONL registers (Register 27-1 and Register 27-2) contain control bits for configuring the CTMU module edge source selection, edge source polarity selection, edge sequencing, A/D trigger, analog circuit capacitor discharge and enables. The CTMUICON register (Register 27-3) has bits for selecting the current source range and current source trim.
PIC18F87K90 FAMILY REGISTER 27-2: CTMUCONL: CTMU CONTROL LOW REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 EDG2POL EDG2SEL1 EDG2SEL0 EDG1POL EDG1SEL1 EDG1SEL0 EDG2STAT EDG1STAT bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 EDG2POL: Edge 2 Polarity Select bit 1 = Edge 2 is programmed for a positive edge response 0 = Edge 2 is programmed for a negative edge response
PIC18F87K90 FAMILY REGISTER 27-3: CTMUICON: CTMU CURRENT CONTROL REGISTER R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 ITRIM5 ITRIM4 ITRIM3 ITRIM2 ITRIM1 ITRIM0 IRNG1 IRNG0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-2 ITRIM<5:0>: Current Source Trim bits 011111 = Maximum positive change from nominal current 011110 . . .
PIC18F87K90 FAMILY 27.2 CTMU Operation The CTMU works by using a fixed current source to charge a circuit. The type of circuit depends on the type of measurement being made. In the case of charge measurement, the current is fixed and the amount of time the current is applied to the circuit is fixed. The amount of voltage read by the A/D becomes a measurement of the circuit’s capacitance. In the case of time measurement, the current, as well as the capacitance of the circuit, is fixed.
PIC18F87K90 FAMILY 27.2.5 INTERRUPTS The CTMU sets its interrupt flag (PIR3<3>) whenever the current source is enabled, then disabled. An interrupt is generated only if the corresponding interrupt enable bit (PIE3<3>) is also set. If edge sequencing is not enabled (i.e., Edge 1 must occur before Edge 2), it is necessary to monitor the edge status bits and determine which edge occurred last and caused the interrupt. 27.
PIC18F87K90 FAMILY The CTMU current source may be trimmed with the trim bits in CTMUICON using an iterative process to get the exact current desired. Alternatively, the nominal value without adjustment may be used. That value may be stored by software for use in all subsequent capacitive or time measurements. To calculate the value for RCAL, the nominal current must be chosen. Then, the resistance can be calculated. For example, if the A/D Converter reference voltage is 3.3V, use 70% of full scale (or 2.
PIC18F87K90 FAMILY EXAMPLE 27-1: SETUP FOR CTMU CALIBRATION ROUTINES #include "p18cxxx.
PIC18F87K90 FAMILY EXAMPLE 27-2: CURRENT CALIBRATION ROUTINE #include "p18cxxx.h" #define COUNT 500 #define DELAY for(i=0;i
PIC18F87K90 FAMILY 27.4.2 CAPACITANCE CALIBRATION There is a small amount of capacitance from the internal A/D Converter sample capacitor, as well as stray capacitance from the circuit board traces and pads that affect the precision of capacitance measurements. A measurement of the stray capacitance can be taken by making sure the desired capacitance to be measured has been removed. After removing the capacitance to be measured: 1. 2. 3. 4. 5. 6. Initialize the A/D Converter and the CTMU.
PIC18F87K90 FAMILY EXAMPLE 27-3: CAPACITANCE CALIBRATION ROUTINE #include "p18cxxx.h" #define #define #define #define #define #define COUNT 25 ETIME COUNT*2.5 DELAY for(i=0;i
PIC18F87K90 FAMILY 27.5 Measuring Capacitance with the CTMU There are two ways to measure capacitance with the CTMU. The absolute method measures the actual capacitance value. The relative method only measures for any change in the capacitance. 27.5.1 ABSOLUTE CAPACITANCE MEASUREMENT For absolute capacitance measurements, both the current and capacitance calibration steps, found in Section 27.4 “Calibrating the CTMU Module”, should be followed. To perform these measurements: 1. 2. 3. 4. 5. 6. 7. 8.
PIC18F87K90 FAMILY EXAMPLE 27-4: ROUTINE FOR CAPACITIVE TOUCH SWITCH #include "p18cxxx.h" #define #define #define #define COUNT 500 DELAY for(i=0;i
PIC18F87K90 FAMILY 27.6 Measuring Time with the CTMU Module Time can be precisely measured after the ratio (C/I) is measured from the current and capacitance calibration step. To do that: 1. 2. 3. 4. 5. Initialize the A/D Converter and the CTMU. Set EDG1STAT. Set EDG2STAT. Perform an A/D conversion. Calculate the time between edges as T = (C/I) • V, where: • I is calculated in the current calibration step (Section 27.4.
PIC18F87K90 FAMILY 27.7 An example use of the external capacitor feature is interfacing with variable capacitive-based sensors, such as a humidity sensor. As the humidity varies, the pulse-width output on CTPLS will vary. An example use of the CTDIN feature is interfacing with a digital sensor. The CTPLS output pin can be connected to an input capture pin and the varying pulse width measured to determine the humidity in the application.
PIC18F87K90 FAMILY 27.8 Measuring Temperature Using the CTMU Module The CTMU, along with an internal diode, can be used to measure the temperature. The ADC can be connected to the internal diode and the CTMU module can EXAMPLE 27-5: source the current to the diode. The ADC reading will reflect the temperature. With the increase, the ADC readings will go low. This can be used for low-cost temperature measurement applications.
PIC18F87K90 FAMILY 27.9 Operation During Sleep/Idle Modes 27.9.1 SLEEP MODE When the device enters any Sleep mode, the CTMU module current source is always disabled. If the CTMU is performing an operation that depends on the current source when Sleep mode is invoked, the operation may not terminate correctly. Capacitance and time measurements may return erroneous values. 27.9.2 IDLE MODE The behavior of the CTMU in Idle mode is determined by the CTMUSIDL bit (CTMUCONH<5>).
PIC18F87K90 FAMILY NOTES: DS39957D-page 424 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 28.0 SPECIAL FEATURES OF THE CPU The PIC18F87K90 family of devices includes several features intended to maximize reliability and minimize cost through elimination of external components.
PIC18F87K90 FAMILY TABLE 28-1: CONFIGURATION BITS AND DEVICE IDs File Name Bit 7 Bit 6 Bit 5 300000h CONFIG1L — XINST — 300001h CONFIG1H IESO FCMEN — 300002h CONFIG2L — 300003h CONFIG2H — WDTPS4 300004h CONFIG3L — 300005h CONFIG3H MCLRE 300006h CONFIG4L Bit 4 Bit 3 Bit 2 SOSCSEL1 SOSCSEL0 INTOSCSEL Bit 1 Bit 0 Default/ Unprogrammed Value — RETEN -1-1 1--1 PLLCFG FOSC3 FOSC2 FOSC1 FOSC0 0000 1000 BORV1 BORV0 BOREN1 BOREN0 PWRTEN -111 1111 WDTPS3 WDTPS2 WDTPS1
PIC18F87K90 FAMILY REGISTER 28-1: CONFIG1L: CONFIGURATION REGISTER 1 LOW (BYTE ADDRESS 300000h) U-0 R/P-1 U-0 — XINST — R/P-1 R/P-1 R/P-1 U-0 R/P-1 — RETEN SOSCSEL1 SOSCSEL0 INTOSCSEL0 bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6 XINST: Extended Instruction Set Enable bit 1 = Instruction set extension
PIC18F87K90 FAMILY REGISTER 28-2: CONFIG1H: CONFIGURATION REGISTER 1 HIGH (BYTE ADDRESS 300001h) R/P-0 R/P-0 U-0 U-0 R/P-1 R/P-0 R/P-0 R/P-0 IESO FCMEN — PLLCFG(1) FOSC3(2) FOSC2(2) FOSC1(2) FOSC0(2) bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 IESO: Internal/External Oscillator Switchover bit 1 = Two-Speed Start-up is enabled 0 = Two
PIC18F87K90 FAMILY REGISTER 28-3: U-0 — CONFIG2L: CONFIGURATION REGISTER 2 LOW (BYTE ADDRESS 300002h) R/P-1 R/P-1 (1) BORPWR1 R/P-1 (1) BORPWR0 BORV1 R/P-1 (1) BORV0 (1) R/P-1 R/P-1 (2) BOREN1 BOREN0 R/P-1 (2) PWRTEN(2) bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6-5 BORPWR<1:0>: BORMV Power Level bit
PIC18F87K90 FAMILY REGISTER 28-4: CONFIG2H: CONFIGURATION REGISTER 2 HIGH (BYTE ADDRESS 300003h) U-0 R/P-1 R/P-1 R/P-1 R/P-1 R/P-1 R/P-1 R/P-1 — WDTPS4 WDTPS3 WDTPS2 WDTPS1 WDTPS0 WDTEN1 WDTEN0 bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6-2 WDTPS<4:0>: Watchdog Timer Postscale Select bits 11111 = 1:1
PIC18F87K90 FAMILY REGISTER 28-5: CONFIG3L: CONFIGURATION REGISTER 3 LOW (BYTE ADDRESS 300004h) U-0 U-0 U-0 U-0 U-0 U-0 U-0 R/P-1 — — — — — — — RTCOSC bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-1 Unimplemented: Read as ‘0’ bit 0 RTCOSC: RTCC Reference Clock Select bit 1 = RTCC uses SOSC as a reference clock 0 = RTCC uses LF-INTOSC as a reference cloc
PIC18F87K90 FAMILY REGISTER 28-7: CONFIG4L: CONFIGURATION REGISTER 4 LOW (BYTE ADDRESS 300006h) R/P-1 U-0 U-0 R/P-0 U-0 R/P-0 U-0 R/P-1 DEBUG — — BBSIZ0 — — — STVREN bit 7 bit 0 Legend: P = Programmable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 DEBUG: Background Debugger Enable bit 1 = Background debugger is disabled, RB6 and RB7 are configured as general purpose I/O
PIC18F87K90 FAMILY REGISTER 28-8: CONFIG5L: CONFIGURATION REGISTER 5 LOW (BYTE ADDRESS 300008h)(2) R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 CP7(1) CP6(1) CP5(1) CP4(1) CP3 CP2 CP1 CP0 bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 CP7: Code Protection bit(1) 1 = Block 7 is not code-protected 0 = Block 7 is code-protected bit 6 CP6: Code Protection bi
PIC18F87K90 FAMILY REGISTER 28-9: CONFIG5H: CONFIGURATION REGISTER 5 HIGH (BYTE ADDRESS 300009h)(1) R/C-1 R/C-1 U-0 U-0 U-0 U-0 U-0 U-0 CPD CPB — — — — — — bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 CPD: Data EEPROM Code Protection bit 1 = Data EEPROM is not code-protected 0 = Data EEPROM is code-protected bit 6 CPB: Boot Block Code Protection bit 1 = B
PIC18F87K90 FAMILY REGISTER 28-10: CONFIG6L: CONFIGURATION REGISTER 6 LOW (BYTE ADDRESS 30000Ah)(2) R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 WRT7(1) WRT6(1) WRT5(1) WRT4(1) WRT3 WRT2 WRT1 WRT0 bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 WRT7: Write Protection bit(1) 1 = Block 7 is not write-protected 0 = Block 7 is write-protected bit 6 WRT6: Write
PIC18F87K90 FAMILY REGISTER 28-11: CONFIG6H: CONFIGURATION REGISTER 6 HIGH (BYTE ADDRESS 30000Bh)(2) R/C-1 R/C-1 R-1 U-0 U-0 U-0 U-0 U-0 WRTD WRTB WRTC(1) — — — — — bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 WRTD: Data EEPROM Write Protection bit 1 = Data EEPROM is not write-protected 0 = Data EEPROM is write-protected bit 6 WRTB: Boot Block Write Protect
PIC18F87K90 FAMILY REGISTER 28-12: CONFIG7L: CONFIGURATION REGISTER 7 LOW (BYTE ADDRESS 30000Ch)(3) R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 R/C-1 EBTR7(1) EBTR6(1) EBTR5(1) EBTR4(1) EBTR3 EBTR2 EBTR1 EBTR0 bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7 EBTR7: Table Read Protection bit(1) 1 = Block 7 is not protected from table reads executed in other blocks 0
PIC18F87K90 FAMILY REGISTER 28-13: CONFIG7H: CONFIGURATION REGISTER 7 HIGH (BYTE ADDRESS 30000Dh)(1) U-0 R/C-1 U-0 U-0 U-0 U-0 U-0 U-0 — EBTRB — — — — — — bit 7 bit 0 Legend: C = Clearable bit R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown bit 7 Unimplemented: Read as ‘0’ bit 6 EBTRB: Boot Block Table Read Protection bit 1 = Boot block is not protected from table reads executed in o
PIC18F87K90 FAMILY REGISTER 28-14: DEVID1: DEVICE ID REGISTER 1 FOR THE PIC18F87K90 FAMILY R R R R R R R R DEV2 DEV1 DEV0 REV4 REV3 REV2 REV1 REV0 bit 7 bit 0 Legend: R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’ -n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared bit 7-5 DEV<2:0>: Device ID bits Devices with DEV<10:3> of 0101 0010 (see DEVID2): 010 = PIC18F65K90 000 = PIC18F66K90 101 = PIC18F85K90 011 = PIC18F86K90 Devices with DEV<10:3> of 0101 0001: 00
PIC18F87K90 FAMILY 28.2 Watchdog Timer (WDT) For the PIC18F87K90 family of devices, the WDT is driven by the LF-INTOSC source. When the WDT is enabled, the clock source is also enabled. The nominal WDT period is 4 ms and has the same stability as the LF-INTOSC oscillator. The 4 ms period of the WDT is multiplied by a 16-bit postscaler. Any output of the WDT postscaler is selected by a multiplexer, controlled by bits in Configuration Register 2H.
PIC18F87K90 FAMILY 28.2.1 CONTROL REGISTER Register 28-16 shows the WDTCON register. This is a readable and writable register which contains a control bit that allows software to override the WDT Enable Configuration bit, but only if the Configuration bit has disabled the WDT.
PIC18F87K90 FAMILY 28.3 On-Chip Voltage Regulator All of the PIC18F87K90 family devices power their core digital logic at a nominal 3.3V. For designs that are required to operate at a higher typical voltage, such as 5V, all family devices incorporate two on-chip regulators that allow the device to run its core logic from VDD.
PIC18F87K90 FAMILY 28.3.2 OPERATION OF REGULATOR IN SLEEP The difference in the two regulators’ operation arises with Sleep mode. The ultra low-power regulator gives the device the lowest current in the Regulator Enabled mode. The on-chip regulator can go into a lower power mode, when the device goes to Sleep, by setting the REGSLP bit (WDTCON<7>). This puts the regulator in a standby mode so that the device consumes much less current.
PIC18F87K90 FAMILY 28.4 In all other power-managed modes, Two-Speed Startup is not used. The device will be clocked by the currently selected clock source until the primary clock source becomes available. The setting of the IESO bit is ignored.
PIC18F87K90 FAMILY 28.5 Fail-Safe Clock Monitor The Fail-Safe Clock Monitor (FSCM) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switching the device clock to the internal oscillator block. The FSCM function is enabled by setting the FCMEN Configuration bit. When FSCM is enabled, the LF-INTOSC oscillator runs at all times to monitor clocks to peripherals and provide a backup clock in the event of a clock failure.
PIC18F87K90 FAMILY FIGURE 28-5: FSCM TIMING DIAGRAM Sample Clock Oscillator Failure Device Clock Output CM Output (Q) Failure Detected OSCFIF CM Test Note: 28.5.3 FSCM INTERRUPTS IN POWER-MANAGED MODES By entering a power-managed mode, the clock multiplexer selects the clock source selected by the OSCCON register. Fail-Safe Monitoring of the powermanaged clock source resumes in the power-managed mode.
PIC18F87K90 FAMILY 28.6 Each of the blocks has three code protection bits associated with them. They are: Program Verification and Code Protection • Code-Protect bit (CPn) • Write-Protect bit (WRTn) • External Block Table Read bit (EBTRn) The user program memory is divided into four blocks for the PIC18FX5K90 device and PIC18FX6K90 devices, and eight blocks for PIC18FX7K90 devices. One of these is a boot block of 1 or 2 Kbytes. The remainder of the memory is divided into blocks on binary boundaries.
PIC18F87K90 FAMILY TABLE 28-4: SUMMARY OF CODE PROTECTION REGISTERS File Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 300008h CONFIG5L CP7(1) CP6(1) CP5(1) CP4(1) CP3 CP2 CP1 CP0 300009h CONFIG5H CPD CPB — — — — — — WRT3 WRT2 WRT1 WRT0 — — — — EBTR3 EBTR2 EBTR1 EBTR0 — — — — 30000Ah CONFIG6L WRT7 (1) 30000Bh CONFIG6H WRTD 30000Ch CONFIG7L EBRT7(1) 30000Dh CONFIG7H — (1) WRT6 WRTB EBRT6 (1) EBTRB WRT5 (1) WRT4 WRTC EBTR5 (1) (1) — (1)
PIC18F87K90 FAMILY FIGURE 28-8: EXTERNAL BLOCK TABLE READ (EBTRn) DISALLOWED Register Values Program Memory Configuration Bit Settings 000000h 0007FFh 000800h TBLPTR = 0008FFh WRTB, EBTRB = 11 WRT0, EBTR0 = 10 003FFFh 004000h PC = 007FFEh WRT1, EBTR1 = 11 TBLRD* 007FFFh 008000h WRT2, EBTR2 = 11 00BFFFh 00C000h WRT3, EBTR3 = 11 00FFFFh Results: All table reads from external blocks to Blockn are disabled whenever EBTRn = 0. The TABLAT register returns a value of ‘0’.
PIC18F87K90 FAMILY 28.6.2 DATA EEPROM CODE PROTECTION The entire data EEPROM is protected from external reads and writes by two bits: CPD and WRTD. CPD inhibits external reads and writes of data EEPROM. WRTD inhibits internal and external writes to data EEPROM. The CPU can always read data EEPROM under normal operation, regardless of the protection bit settings. 28.6.3 CONFIGURATION REGISTER PROTECTION The Configuration registers can be write-protected.
PIC18F87K90 FAMILY 29.0 INSTRUCTION SET SUMMARY The PIC18F87K90 family of devices incorporates the standard set of 75 PIC18 core instructions, as well as an extended set of 8 new instructions for the optimization of code that is recursive or that utilizes a software stack. The extended set is discussed later in this section. 29.
PIC18F87K90 FAMILY TABLE 29-1: OPCODE FIELD DESCRIPTIONS Field a bbb BSR C, DC, Z, OV, N d dest f fs fd GIE k label mm * *+ *+* n PC PCL PCH PCLATH PCLATU PD PRODH PRODL s TBLPTR TABLAT TO TOS u WDT WREG x zs zd { } [text] (text) [expr] < > italics DS39957D-page 452 Description RAM access bit: a = 0: RAM location in Access RAM (BSR register is ignored) a = 1: RAM bank is specified by BSR register Bit address within an 8-bit file register (0 to 7). Bank Select Register.
PIC18F87K90 FAMILY FIGURE 29-1: GENERAL FORMAT FOR INSTRUCTIONS Byte-oriented file register operations 15 10 9 OPCODE Example Instruction 8 7 d 0 a f (FILE #) ADDWF MYREG, W, B d = 0 for result destination to be WREG register d = 1 for result destination to be file register (f) a = 0 to force Access Bank a = 1 for BSR to select bank f = 8-bit file register address Byte to Byte move operations (2-word) 15 12 11 0 OPCODE 15 f (Source FILE #) 12 11 MOVFF MYREG1, MYREG2 0 f (Destination FIL
PIC18F87K90 FAMILY TABLE 29-2: PIC18F87K90 FAMILY INSTRUCTION SET Mnemonic, Operands 16-Bit Instruction Word Description Cycles MSb LSb Status Affected Notes BYTE-ORIENTED OPERATIONS ADDWF ADDWFC ANDWF CLRF COMF CPFSEQ CPFSGT CPFSLT DECF DECFSZ DCFSNZ INCF INCFSZ INFSNZ IORWF MOVF MOVFF f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a fs, fd MOVWF MULWF NEGF RLCF RLNCF RRCF RRNCF SETF SUBFWB f, a f, a f, a f, d, a f, d, a f, d, a
PIC18F87K90 FAMILY TABLE 29-2: PIC18F87K90 FAMILY INSTRUCTION SET (CONTINUED) 16-Bit Instruction Word Mnemonic, Operands Description Cycles MSb LSb Status Affected Notes BIT-ORIENTED OPERATIONS BCF BSF BTFSC BTFSS BTG f, b, a f, b, a f, b, a f, b, a f, b, a Bit Clear f Bit Set f Bit Test f, Skip if Clear Bit Test f, Skip if Set Bit Toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff None None None None None
PIC18F87K90 FAMILY TABLE 29-2: PIC18F87K90 FAMILY INSTRUCTION SET (CONTINUED) 16-Bit Instruction Word Mnemonic, Operands Description Cycles MSb LSb Status Affected Notes LITERAL OPERATIONS ADDLW ANDLW IORLW LFSR k k k f, k MOVLB MOVLW MULLW RETLW SUBLW XORLW k k k k k k Add Literal and WREG AND Literal with WREG Inclusive OR Literal with WREG Move literal (12-bit) 2nd word 1st word to FSR(f) Move Literal to BSR<3:0> Move Literal to WREG Multiply Literal with WREG Return with Literal in WREG Sub
PIC18F87K90 FAMILY 29.1.1 STANDARD INSTRUCTION SET ADDLW ADD Literal to W ADDWF ADD W to f Syntax: ADDLW Syntax: ADDWF Operands: 0 f 255 d [0,1] a [0,1] Operation: (W) + (f) dest Status Affected: N, OV, C, DC, Z k Operands: 0 k 255 Operation: (W) + k W Status Affected: N, OV, C, DC, Z Encoding: 0000 1111 kkkk kkkk Description: The contents of W are added to the 8-bit literal ‘k’ and the result is placed in W.
PIC18F87K90 FAMILY ADDWFC ADD W and Carry bit to f ANDLW AND Literal with W Syntax: ADDWFC Syntax: ANDLW Operands: 0 f 255 d [0,1] a [0,1] f {,d {,a}} Operation: (W) + (f) + (C) dest Status Affected: N,OV, C, DC, Z Encoding: 0010 Description: 00da ffff Add W, the Carry flag and data memory location ‘f’. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed in data memory location ‘f’. If ‘a’ is ‘0’, the Access Bank is selected.
PIC18F87K90 FAMILY ANDWF AND W with f BC Branch if Carry Syntax: ANDWF Syntax: BC Operands: 0 f 255 d [0,1] a [0,1] f {,d {,a}} Operation: (W) .AND. (f) dest Status Affected: N, Z Encoding: Description: 0001 Operands: -128 n 127 Operation: if Carry bit is ‘1’, (PC) + 2 + 2n PC Status Affected: None Encoding: 01da ffff ffff Description: The contents of W are ANDed with register ‘f’. If ‘d’ is ‘0’, the result is stored in W.
PIC18F87K90 FAMILY BCF Bit Clear f BN Branch if Negative Syntax: BCF Syntax: BN Operands: 0 f 255 0b7 a [0,1] f, b {,a} Operation: 0 f Status Affected: None Encoding: 1001 Description: Operands: -128 n 127 Operation: if Negative bit is ‘1’, (PC) + 2 + 2n PC Status Affected: None Encoding: bbba ffff ffff Description: Bit ‘b’ in register ‘f’ is cleared.
PIC18F87K90 FAMILY BNC Branch if Not Carry BNN Branch if Not Negative Syntax: BNC Syntax: BNN n n Operands: -128 n 127 Operands: -128 n 127 Operation: if Carry bit is ‘0’, (PC) + 2 + 2n PC Operation: if Negative bit is ‘0’, (PC) + 2 + 2n PC Status Affected: None Status Affected: None Encoding: Description: 1110 0011 nnnn nnnn If the Carry bit is ‘0’, then the program will branch. Encoding: Description: The 2’s complement number ‘2n’ is added to the PC.
PIC18F87K90 FAMILY BNOV Branch if Not Overflow BNZ Branch if Not Zero Syntax: BNOV Syntax: BNZ n n Operands: -128 n 127 Operands: -128 n 127 Operation: if Overflow bit is ‘0’, (PC) + 2 + 2n PC Operation: if Zero bit is ‘0’, (PC) + 2 + 2n PC Status Affected: None Status Affected: None Encoding: 1110 Description: 0101 nnnn nnnn If the Overflow bit is ‘0’, then the program will branch. Encoding: Description: The 2’s complement number ‘2n’ is added to the PC.
PIC18F87K90 FAMILY BRA Unconditional Branch BSF Bit Set f Syntax: BRA Syntax: BSF Operands: 0 f 255 0b7 a [0,1] Operation: 1 f Status Affected: None n Operands: -1024 n 1023 Operation: (PC) + 2 + 2n PC Status Affected: None Encoding: Description: 1101 1 Cycles: 2 No operation Example: nnnn nnnn Add the 2’s complement number ‘2n’ to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n.
PIC18F87K90 FAMILY BTFSC Bit Test File, Skip if Clear BTFSS Bit Test File, Skip if Set Syntax: BTFSC f, b {,a} Syntax: BTFSS f, b {,a} Operands: 0 f 255 0b7 a [0,1] Operands: 0 f 255 0b<7 a [0,1] Operation: skip if (f) = 0 Operation: skip if (f) = 1 Status Affected: None Status Affected: None Encoding: Description: 1011 bbba ffff ffff If bit ‘b’ in register ‘f’ is ‘0’, then the next instruction is skipped.
PIC18F87K90 FAMILY BTG Bit Toggle f BOV Branch if Overflow Syntax: BTG f, b {,a} Syntax: BOV Operands: 0 f 255 0b<7 a [0,1] Operation: (f) f Status Affected: None Encoding: Description: 0111 Operands: -128 n 127 Operation: if Overflow bit is ‘1’, (PC) + 2 + 2n PC Status Affected: None Encoding: bbba ffff ffff Description: Bit ‘b’ in data memory location, ‘f’, is inverted.
PIC18F87K90 FAMILY BZ Branch if Zero CALL Subroutine Call Syntax: BZ Syntax: CALL k {,s} n Operands: -128 n 127 Operands: Operation: if Zero bit is ‘1’, (PC) + 2 + 2n PC 0 k 1048575 s [0,1] Operation: Status Affected: None (PC) + 4 TOS, k PC<20:1>; if s = 1, (W) WS, (STATUS) STATUSS, (BSR) BSRS Status Affected: None Encoding: 1110 Description: 0000 nnnn nnnn If the Zero bit is ‘1’, then the program will branch.
PIC18F87K90 FAMILY CLRF Clear f Syntax: CLRF Operands: 0 f 255 a [0,1] f {,a} Operation: 000h f, 1Z Status Affected: Z Encoding: Description: 0110 101a ffff ffff Clears the contents of the specified register.
PIC18F87K90 FAMILY COMF Complement f CPFSEQ Syntax: COMF Syntax: CPFSEQ Operands: 0 f 255 a [0,1] Operation: (f) – (W), skip if (f) = (W) (unsigned comparison) Status Affected: None f {,d {,a}} Operands: 0 f 255 d [0,1] a [0,1] Operation: f dest Status Affected: N, Z Encoding: 0001 Description: 11da ffff ffff The contents of register ‘f’ are complemented. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in register ‘f’.
PIC18F87K90 FAMILY CPFSGT Compare f with W, Skip if f > W CPFSLT Compare f with W, Skip if f < W Syntax: CPFSGT Syntax: CPFSLT Operands: 0 f 255 a [0,1] Operands: 0 f 255 a [0,1] Operation: (f) –W), skip if (f) > (W) (unsigned comparison) Operation: (f) –W), skip if (f) < (W) (unsigned comparison) Status Affected: None Status Affected: None Encoding: Description: 0110 f {,a} 010a ffff ffff Compares the contents of data memory location ‘f’ to the contents of the W by
PIC18F87K90 FAMILY DAW Decimal Adjust W Register DECF Decrement f Syntax: DAW Syntax: DECF f {,d {,a}} Operands: None Operands: Operation: If [W<3:0> > 9] or [DC = 1], then (W<3:0>) + 6 W<3:0>; else, (W<3:0>) W<3:0>; 0 f 255 d [0,1] a [0,1] Operation: (f) – 1 dest Status Affected: C, DC, N, OV, Z Encoding: If [W<7:4> > 9] or [C = 1], then (W<7:4>) + 6 W<7:4>; C =1; else, (W<7:4>) W<7:4> Status Affected: Description: 0000 0000 0000 0111 Description: DAW adjusts th
PIC18F87K90 FAMILY DECFSZ Decrement f, Skip if 0 DCFSNZ Decrement f, Skip if Not 0 Syntax: DECFSZ f {,d {,a}} Syntax: DCFSNZ Operands: 0 f 255 d [0,1] a [0,1] Operands: 0 f 255 d [0,1] a [0,1] Operation: (f) – 1 dest, skip if result = 0 Operation: (f) – 1 dest, skip if result 0 Status Affected: None Status Affected: None Encoding: Description: 0010 11da ffff ffff The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in W.
PIC18F87K90 FAMILY GOTO Unconditional Branch INCF Increment f Syntax: GOTO k Syntax: INCF Operands: 0 f 255 d [0,1] a [0,1] Operation: (f) + 1 dest Status Affected: C, DC, N, OV, Z Operands: 0 k 1048575 Operation: k PC<20:1> Status Affected: None Encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k19kkk k7kkk kkkk kkkk0 kkkk8 Description: GOTO allows an unconditional branch anywhere within entire 2-Mbyte memory range.
PIC18F87K90 FAMILY INCFSZ Increment f, Skip if 0 INFSNZ Increment f, Skip if Not 0 Syntax: INCFSZ Syntax: INFSNZ 0 f 255 d [0,1] a [0,1] f {,d {,a}} f {,d {,a}} Operands: 0 f 255 d [0,1] a [0,1] Operands: Operation: (f) + 1 dest, skip if result = 0 Operation: (f) + 1 dest, skip if result 0 Status Affected: None Status Affected: None Encoding: Description: 0011 11da ffff ffff The contents of register ‘f’ are incremented.
PIC18F87K90 FAMILY IORLW Inclusive OR Literal with W IORWF Inclusive OR W with f Syntax: IORLW k Syntax: IORWF Operands: 0 f 255 d [0,1] a [0,1] Operation: (W) .OR. (f) dest Status Affected: N, Z Operands: 0 k 255 Operation: (W) .OR. k W Status Affected: N, Z Encoding: 0000 1001 kkkk kkkk Description: The contents of W are ORed with the 8-bit literal ‘k’. The result is placed in W.
PIC18F87K90 FAMILY LFSR Load FSR MOVF Move f Syntax: LFSR f, k Syntax: MOVF Operands: 0f2 0 k 4095 Operands: Operation: k FSRf 0 f 255 d [0,1] a [0,1] Status Affected: None Operation: f dest Status Affected: N, Z Encoding: 1110 1111 1110 0000 00ff k7kkk k11kkk kkkk Description: The 12-bit literal ‘k’ is loaded into the file select register pointed to by ‘f’.
PIC18F87K90 FAMILY MOVFF Move f to f MOVLB Move Literal to Low Nibble in BSR Syntax: MOVFF fs,fd Syntax: MOVLB k Operands: 0 fs 4095 0 fd 4095 Operands: 0 k 255 Operation: k BSR Operation: (fs) fd Status Affected: None Status Affected: None Encoding: 1st word (source) 2nd word (destin.) Encoding: 1100 1111 Description: ffff ffff ffff ffff ffffs ffffd The contents of source register ‘fs’ are moved to destination register ‘fd’.
PIC18F87K90 FAMILY MOVLW Move Literal to W MOVWF Move W to f Syntax: MOVLW k Syntax: MOVWF Operands: 0 f 255 a [0,1] Operation: (W) f Status Affected: None Operands: 0 k 255 Operation: kW Status Affected: None Encoding: 0000 1110 kkkk kkkk The 8-bit literal ‘k’ is loaded into W.
PIC18F87K90 FAMILY MULLW Multiply Literal with W MULWF Multiply W with f Syntax: MULLW Syntax: MULWF Operands: 0 f 255 a [0,1] Operation: (W) x (f) PRODH:PRODL Status Affected: None k Operands: 0 k 255 Operation: (W) x k PRODH:PRODL Status Affected: None Encoding: Description: 0000 1101 kkkk kkkk An unsigned multiplication is carried out between the contents of W and the 8-bit literal ‘k’. The 16-bit result is placed in the PRODH:PRODL register pair.
PIC18F87K90 FAMILY NEGF Negate f Syntax: NEGF Operands: 0 f 255 a [0,1] f {,a} Operation: (f) + 1 f Status Affected: N, OV, C, DC, Z Encoding: Description: 0110 110a ffff If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f 95 (5Fh). See Section 29.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.
PIC18F87K90 FAMILY POP Pop Top of Return Stack PUSH Push Top of Return Stack Syntax: POP Syntax: PUSH Operands: None Operands: None Operation: (TOS) bit bucket Operation: (PC + 2) TOS Status Affected: None Status Affected: None Encoding: 0000 0000 0000 0110 Encoding: 0000 0000 0000 0101 Description: The TOS value is pulled off the return stack and is discarded. The TOS value then becomes the previous value that was pushed onto the return stack.
PIC18F87K90 FAMILY RCALL Relative Call RESET Reset Syntax: RCALL Syntax: RESET n Operands: -1024 n 1023 Operands: None Operation: (PC) + 2 TOS, (PC) + 2 + 2n PC Operation: Reset all registers and flags that are affected by a MCLR Reset. Status Affected: None Status Affected: All Encoding: Description: 1101 Words: 1 Cycles: 2 Q Cycle Activity: Q1 Decode No operation Example: 1nnn nnnn nnnn Subroutine call with a jump up to 1K from the current location.
PIC18F87K90 FAMILY RETFIE Return from Interrupt RETLW Return Literal to W Syntax: RETFIE {s} Syntax: RETLW k Operands: s [0,1] Operands: 0 k 255 Operation: (TOS) PC, 1 GIE/GIEH or PEIE/GIEL; if s = 1, (WS) W, (STATUSS) STATUS, (BSRS) BSR, PCLATU, PCLATH are unchanged Operation: k W, (TOS) PC, PCLATU, PCLATH are unchanged Status Affected: None Status Affected: 0000 Description: 0000 0001 1 Cycles: 2 1100 kkkk kkkk Description: W is loaded with the 8-bit liter
PIC18F87K90 FAMILY RETURN Return from Subroutine RLCF Rotate Left f through Carry Syntax: RETURN {s} Syntax: RLCF Operands: s [0,1] Operands: Operation: (TOS) PC; if s = 1, (WS) W, (STATUSS) STATUS, (BSRS) BSR, PCLATU, PCLATH are unchanged 0 f 255 d [0,1] a [0,1] Operation: (f) dest, (f<7>) C, (C) dest<0> Status Affected: C, N, Z Status Affected: None Encoding: Description: 0000 1 Cycles: 2 No operation Example: 0000 0001 001s Description: Ret
PIC18F87K90 FAMILY RLNCF Rotate Left f (No Carry) RRCF Rotate Right f through Carry Syntax: RLNCF Syntax: RRCF Operands: 0 f 255 d [0,1] a [0,1] Operands: 0 f 255 d [0,1] a [0,1] Operation: (f) dest, (f<7>) dest<0> Operation: Status Affected: N, Z (f) dest, (f<0>) C, (C) dest<7> Status Affected: C, N, Z Encoding: 0100 Description: f {,d {,a}} 01da ffff ffff The contents of register ‘f’ are rotated one bit to the left.
PIC18F87K90 FAMILY RRNCF Rotate Right f (No Carry) SETF Set f Syntax: RRNCF Syntax: SETF Operands: 0 f 255 d [0,1] a [0,1] Operands: 0 f 255 a [0,1] Operation: FFh f Operation: (f) dest, (f<0>) dest<7> Status Affected: None Status Affected: N, Z Encoding: Description: 0100 f {,d {,a}} 00da Encoding: ffff ffff Description: The contents of register ‘f’ are rotated one bit to the right. If ‘d’ is ‘0’, the result is placed in W.
PIC18F87K90 FAMILY SLEEP Enter Sleep Mode SUBFWB Subtract f from W with Borrow Syntax: SLEEP Syntax: SUBFWB Operands: None Operands: Operation: 00h WDT, 0 WDT postscaler, 1 TO, 0 PD 0 f 255 d [0,1] a [0,1] Operation: (W) – (f) – (C) dest Status Affected: N, OV, C, DC, Z Status Affected: TO, PD Encoding: 0000 Description: Encoding: 0000 0000 0011 Description: The Power-Down status bit (PD) is cleared. The Time-out status bit (TO) is set.
PIC18F87K90 FAMILY SUBLW Subtract W from Literal SUBWF Subtract W from f Syntax: SUBLW k Syntax: SUBWF Operands: 0 f 255 d [0,1] a [0,1] Operation: (f) – (W) dest Status Affected: N, OV, C, DC, Z Operands: 0 k 255 Operation: k – (W) W Status Affected: N, OV, C, DC, Z Encoding: 0000 1000 kkkk kkkk Description: W is subtracted from the 8-bit literal ‘k’. The result is placed in W.
PIC18F87K90 FAMILY SUBWFB Subtract W from f with Borrow SWAPF Swap f Syntax: SUBWFB Syntax: SWAPF f {,d {,a}} Operands: 0 f 255 d [0,1] a [0,1] Operands: 0 f 255 d [0,1] a [0,1] Operation: (f) – (W) – (C) dest Operation: Status Affected: N, OV, C, DC, Z (f<3:0>) dest<7:4>, (f<7:4>) dest<3:0> Status Affected: None Encoding: 0101 Description: f {,d {,a}} 10da ffff ffff Subtract W and the Carry flag (borrow) from register ‘f’ (2’s complement method).
PIC18F87K90 FAMILY TBLRD Table Read TBLRD Table Read (Continued) Syntax: TBLRD ( *; *+; *-; +*) Example 1: TBLRD Operands: None Operation: if TBLRD *, (Prog Mem (TBLPTR)) TABLAT, TBLPTR – No Change; if TBLRD *+, (Prog Mem (TBLPTR)) TABLAT, (TBLPTR) + 1 TBLPTR; if TBLRD *-, (Prog Mem (TBLPTR)) TABLAT, (TBLPTR) – 1 TBLPTR; if TBLRD +*, (TBLPTR) + 1 TBLPTR, (Prog Mem (TBLPTR)) TABLAT Status Affected: None Encoding: Description: 0000 0000 0000 Before Instruction TABLAT TBLPTR MEMO
PIC18F87K90 FAMILY TBLWT Table Write TBLWT Table Write (Continued) Syntax: TBLWT ( *; *+; *-; +*) Example 1: TBLWT *+; Operands: None Operation: if TBLWT*, (TABLAT) Holding Register, TBLPTR – No Change; if TBLWT*+, (TABLAT) Holding Register, (TBLPTR) + 1 TBLPTR; if TBLWT*-, (TABLAT) Holding Register, (TBLPTR) – 1 TBLPTR; if TBLWT+*, (TBLPTR) + 1 TBLPTR, (TABLAT) Holding Register Status Affected: Example 2: None Encoding: Description: Before Instruction TABLAT = 55h TBLPTR = 00
PIC18F87K90 FAMILY TSTFSZ Test f, Skip if 0 XORLW Exclusive OR Literal with W Syntax: TSTFSZ f {,a} Syntax: XORLW k Operands: 0 f 255 a [0,1] Operands: 0 k 255 Operation: (W) .XOR. k W Operation: skip if f = 0 Status Affected: N, Z Status Affected: None Encoding: Description: Encoding: 0110 011a ffff ffff If ‘f’ = 0, the next instruction fetched during the current instruction execution is discarded and a NOP is executed, making this a two-cycle instruction.
PIC18F87K90 FAMILY XORWF Exclusive OR W with f Syntax: XORWF Operands: 0 f 255 d [0,1] a [0,1] Operation: (W) .XOR. (f) dest Status Affected: N, Z Encoding: 0001 Description: f {,d {,a}} 10da ffff ffff Exclusive OR the contents of W with register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’. If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank.
PIC18F87K90 FAMILY 29.2 A summary of the instructions in the extended instruction set is provided in Table 29-3. Detailed descriptions are provided in Section 29.2.2 “Extended Instruction Set”. The opcode field descriptions in Table 29-1 (page 452) apply to both the standard and extended PIC18 instruction sets.
PIC18F87K90 FAMILY 29.2.2 EXTENDED INSTRUCTION SET ADDFSR Add Literal to FSR ADDULNK Add Literal to FSR2 and Return Syntax: Operands: ADDFSR f, k 0 k 63 f [ 0, 1, 2 ] FSR(f) + k FSR(f) None 1110 1000 ffkk Syntax: Operands: Operation: ADDULNK k 0 k 63 FSR2 + k FSR2, (TOS) PC None 1110 1000 11kk Operation: Status Affected: Encoding: Description: Words: Cycles: Q Cycle Activity: Q1 Decode Example: kkkk The 6-bit literal ‘k’ is added to the contents of the FSR specified by ‘f’.
PIC18F87K90 FAMILY CALLW Subroutine Call Using WREG MOVSF Move Indexed to f Syntax: CALLW Syntax: MOVSF [zs], fd Operands: None Operands: Operation: (PC + 2) TOS, (W) PCL, (PCLATH) PCH, (PCLATU) PCU 0 zs 127 0 fd 4095 Operation: ((FSR2) + zs) fd Status Affected: None Status Affected: None Encoding: Description 0000 0000 0001 0100 First, the return address (PC + 2) is pushed onto the return stack.
PIC18F87K90 FAMILY MOVSS Move Indexed to Indexed PUSHL Store Literal at FSR2, Decrement FSR2 Syntax: MOVSS [zs], [zd] Syntax: PUSHL k Operands: 0 zs 127 0 zd 127 Operation: ((FSR2) + zs) ((FSR2) + zd) Status Affected: None Encoding: 1st word (source) 2nd word (dest.) 1110 1111 Description 1011 xxxx 1zzz xzzz zzzzs zzzzd The contents of the source register are moved to the destination register.
PIC18F87K90 FAMILY SUBFSR Subtract Literal from FSR SUBULNK Subtract Literal from FSR2 and Return Syntax: Operands: SUBFSR f, k 0 k 63 f [ 0, 1, 2 ] FSRf – k FSRf None 1110 1001 Syntax: Operands: Operation: SUBULNK k 0 k 63 FSR2 – k FSR2, (TOS) PC None 1110 1001 Operation: Status Affected: Encoding: Description: Words: Cycles: Q Cycle Activity: Q1 Decode ffkk kkkk The 6-bit literal ‘k’ is subtracted from the contents of the FSR specified by ‘f’.
PIC18F87K90 FAMILY 29.2.3 Note: BYTE-ORIENTED AND BIT-ORIENTED INSTRUCTIONS IN INDEXED LITERAL OFFSET MODE Enabling the PIC18 instruction set extension may cause legacy applications to behave erratically or fail entirely. In addition to eight new commands in the extended set, enabling the extended instruction set also enables Indexed Literal Offset Addressing (Section 6.6.1 “Indexed Addressing with Literal Offset”).
PIC18F87K90 FAMILY ADD W to Indexed (Indexed Literal Offset mode) BSF Syntax: ADDWF Syntax: BSF [k], b Operands: 0 k 95 d [0,1] Operands: 0 f 95 0b7 Operation: (W) + ((FSR2) + k) dest Operation: 1 ((FSR2) + k) Status Affected: N, OV, C, DC, Z Status Affected: None ADDWF Encoding: Description: [k] {,d} 0010 01d0 kkkk kkkk The contents of W are added to the contents of the register indicated by FSR2, offset by the value ‘k’. If ‘d’ is ‘0’, the result is stored in W.
PIC18F87K90 FAMILY 29.2.5 SPECIAL CONSIDERATIONS WITH MICROCHIP MPLAB® IDE TOOLS The latest versions of Microchip’s software tools have been designed to fully support the extended instruction set for the PIC18F87K90 family family. This includes the MPLAB C18 C Compiler, MPASM assembly language and MPLAB Integrated Development Environment (IDE). When selecting a target device for software development, MPLAB IDE will automatically set default Configuration bits for that device.
PIC18F87K90 FAMILY 30.
PIC18F87K90 FAMILY 30.2 MPLAB C Compilers for Various Device Families The MPLAB C Compiler code development systems are complete ANSI C compilers for Microchip’s PIC18, PIC24 and PIC32 families of microcontrollers and the dsPIC30 and dsPIC33 families of digital signal controllers. These compilers provide powerful integration capabilities, superior code optimization and ease of use. For easy source level debugging, the compilers provide symbol information that is optimized to the MPLAB IDE debugger. 30.
PIC18F87K90 FAMILY 30.7 MPLAB SIM Software Simulator The MPLAB SIM Software Simulator allows code development in a PC-hosted environment by simulating the PIC MCUs and dsPIC® DSCs on an instruction level. On any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. Registers can be logged to files for further run-time analysis.
PIC18F87K90 FAMILY 30.11 PICkit 2 Development Programmer/Debugger and PICkit 2 Debug Express 30.13 Demonstration/Development Boards, Evaluation Kits, and Starter Kits The PICkit™ 2 Development Programmer/Debugger is a low-cost development tool with an easy to use interface for programming and debugging Microchip’s Flash families of microcontrollers.
PIC18F87K90 FAMILY 31.0 ELECTRICAL CHARACTERISTICS Absolute Maximum Ratings(†) Ambient temperature under bias.............................................................................................................-40°C to +125°C Storage temperature .............................................................................................................................. -65°C to +150°C Voltage on any digital only I/O pin with respect to VSS (except VDD).............................................
PIC18F87K90 FAMILY FIGURE 31-1: VOLTAGE-FREQUENCY GRAPH, REGULATOR ENABLED (INDUSTRIAL/EXTENDED)(1) 6V 5.5V Voltage (VDD) 5V PIC18F87K90 Family (Extended) 4V 3V 3V 1.8V 0 Note 1: PIC18F87K90 Family (Industrial Only) 4 MHz 48 MHz Frequency 64 MHz(1) FMAX = 64 MHz in all other modes. For VDD values, 1.8V to 3V, FMAX = (VDD – 1.72)/0.02 MHz. FIGURE 31-2: VOLTAGE-FREQUENCY GRAPH, REGULATOR DISABLED (INDUSTRIAL/EXTENDED)(1,2) 4V 3.75V Voltage (VDD) 3.25V 3.
PIC18F87K90 FAMILY 31.1 DC Characteristics: Supply Voltage PIC18F87K90 Family (Industrial/Extended) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended PIC18F87K90 Family Param Symbol No. D001 VDD Characteristic Min Typ Max Units Conditions 1.8 — 3.6 V ENVREG tied to VSS 1.8 — 5.5 V ENVREG tied to VDD D001C AVDD Analog Supply Voltage VDD – 0.3 — VDD + 0.3 V Analog Ground Potential VSS – 0.3 — VSS + 0.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Device Typ Max Units Conditions Power-Down Current (IPD)(1) All devices Note 1: 2: 3: 4: 5: 6: 7: 10 500 nA -40°C 20 500 nA +25°C VDD = 1.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Device Typ Max Units Conditions Supply Current (IDD)(2,3) All devices Note 1: 2: 3: 4: 5: 6: 7: 5.3 10 A -40°C 5.5 10 A +25°C VDD = 1.8V(4) Regulator Disabled 5.
PIC18F87K90 FAMILY 31.2 DC Characteristics: Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended PIC18F87K90 Family Param No. Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Device Typ Max Units Conditions 760 1300 A -40°C 760 1400 A +25°C VDD = 1.8V(4) Regulator Disabled 770 1500 A +85°C A +125°C 800 1700 All devices 1.4 2.5 mA -40°C FOSC = 4 MHz 1.4 2.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Note 1: 2: 3: 4: 5: 6: 7: Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Device Typ Max Units Conditions Supply Current (IDD) Cont.(2,3) All devices 2.1 5.5 A -40°C 2.1 5.7 A +25°C VDD = 1.8V(4) Regulator Disabled A +85°C 2.2 6.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Device Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Typ Max Units Conditions Supply Current (IDD) Cont.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Device Typ Max Units Conditions Supply Current (IDD) Cont.(2,3) All devices 3.3 3.3 3.3 3.6 All devices 3.5 3.5 3.5 3.8 All devices 12 12 12 Note 1: 2: 3: 4: 5: 6: 7: 5.6 mA -40°C 5.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Device Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Typ Max Units Conditions Supply Current (IDD) Cont.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. Note 1: 2: 3: 4: 5: 6: 7: Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Device Typ Max Units Conditions Supply Current (IDD) Cont.(2,3) All devices 3.7 8.5 µA -40°C 5.4 10 µA +25°C VDD = 1.8V(4) Regulator Disabled 6.
PIC18F87K90 FAMILY 31.2 DC Characteristics: Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended PIC18F87K90 Family Param No. D022 (IWDT) D022A (IBOR) (IBOR) Device Note 1: 2: 3: 4: 5: 6: 7: Typ Max Units Conditions Module Differential Currents (IWDT, IBOR, IHLVD, IOSCB, IAD) Watchdog Timer All devices 0.3 1 A -40°C 0.3 1 A +25°C A +85°C 0.3 1 0.5 2 µA +125°C All devices 0.
PIC18F87K90 FAMILY 31.2 DC Characteristics: Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended PIC18F87K90 Family Param No. Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Device Typ Max Units D025 Real-Time Clock/Calendar with SOSC Oscillator (IRTCC) All devices 0.7 2.
PIC18F87K90 FAMILY 31.2 DC Characteristics: PIC18F87K90 Family Param No. D025B (ILCD) Note 1: 2: 3: 4: 5: 6: 7: Device LCD External Biasing PIC18FXXK90 Power-Down and Supply Current PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Typ Max Units Conditions 0.3 1.4 µA -40°C 0.3 1.4 µA +25°C 0.7 1.7 µA +85°C VDD = 1.
PIC18F87K90 FAMILY 31.3 DC Characteristics: PIC18F87K90 Family (Industrial/Extended) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended DC CHARACTERISTICS Param Symbol No. VIL Characteristic Min Max Units Conditions VSS 0.15 VDD V VDD < 4.5V — 0.8 V 4.5 VDD 5.5V Input Low Voltage All I/O Ports: D030 with TTL Buffer D031 with Schmitt Trigger Buffer RC3, RC4 VSS 0.2 VDD V VDD < 4.
PIC18F87K90 FAMILY 31.3 DC Characteristics: PIC18F87K90 Family (Industrial/Extended) (Continued) Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended DC CHARACTERISTICS Param Symbol No. VOL D080 Characteristic Min Max Units Conditions PORTA,PORTB,PORTC — 0.6 V IOL = 8.5 mA, VDD = 4.5V, -40C to +125C PORTD, PORTE, PORTF, PORTG, PORTH, PORTJ — 0.6 V IOL = 3.5 mA, VDD = 4.5V, -40C to +125C — 0.
PIC18F87K90 FAMILY TABLE 31-1: MEMORY PROGRAMMING REQUIREMENTS Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended DC CHARACTERISTICS Param No. Sym Characteristic Min Typ† Max Units Conditions Internal Program Memory Programming Specifications(1) D110 VPP Voltage on MCLR/VPP/RE5 pin D113 IDDP Supply Current during Programming D120 ED Byte Endurance D121 VDRW VDD for Read/Write VDD + 1.
PIC18F87K90 FAMILY TABLE 31-2: COMPARATOR SPECIFICATIONS Operating Conditions: 1.8V VDD 5V, -40°C TA +125°C (unless otherwise stated) Param No. Sym Characteristics Min Typ Max Units D300 VIOFF Input Offset Voltage — ±5.0 40 mV D301 VICM Input Common-Mode Voltage — — AVDD – 1.
PIC18F87K90 FAMILY 31.5 31.5.1 AC (Timing) Characteristics TIMING PARAMETER SYMBOLOGY The timing parameter symbols have been created following one of the following formats: 1. TppS2ppS 2.
PIC18F87K90 FAMILY 31.5.2 TIMING CONDITIONS The temperature and voltages specified in Table 31-5 apply to all timing specifications unless otherwise noted. Figure 31-3 specifies the load conditions for the timing specifications.
PIC18F87K90 FAMILY 31.5.3 TIMING DIAGRAMS AND SPECIFICATIONS FIGURE 31-4: EXTERNAL CLOCK TIMING Q4 Q1 Q2 Q3 Q4 Q1 OSC1 1 3 4 3 4 2 CLKO TABLE 31-6: Param. No.
PIC18F87K90 FAMILY TABLE 31-7: Param No. PLL CLOCK TIMING SPECIFICATIONS (VDD = 1.8V TO 5.5V) Sym F10 Characteristic FOSC Oscillator Frequency Range F11 FSYS F12 F13 On-Chip VCO System Frequency Min Typ† Max Units 4 — 5 MHz VDD = 1.8-5.5V 4 — 16 MHz VDD = 3.0-5.5V, -40°C to +85°C 4 — 12 MHz VDD = 3.0-5.5V, -40°C to +125°C 16 — 20 MHz VDD = 1.8-5.5V 16 — 64 MHz VDD = 3.0-5.5V, -40°C to +85°C 16 — 48 MHz VDD = 3.0-5.
PIC18F87K90 FAMILY FIGURE 31-5: CLKO AND I/O TIMING Q1 Q4 Q2 Q3 OSC1 11 10 CLKO 13 14 19 12 18 16 I/O Pin (Input) 15 17 I/O Pin (Output) New Value Old Value 20, 21 Refer to Figure 31-3 for load conditions. Note: TABLE 31-9: Param No.
PIC18F87K90 FAMILY FIGURE 31-6: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER AND POWER-UP TIMER TIMING VDD MCLR 30 Internal POR 33 PWRT Time-out 32 Oscillator Time-out Internal Reset Watchdog Timer Reset 31 34 34 I/O Pins Note: Refer to Figure 31-3 for load conditions. FIGURE 31-7: VDD BROWN-OUT RESET TIMING BVDD 35 VBGAP = 1.2V VIRVST Enable Internal Reference Voltage Internal Reference Voltage Stable DS39957D-page 528 36 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY TABLE 31-10: RESET, WATCHDOG TIMER, OSCILLATOR START-UP TIMER, POWER-UP TIMER AND BROWN-OUT RESET REQUIREMENTS Param. Symbol No. 30 TmcL Characteristic MCLR Pulse Width (low) Min Typ Max Units 2 — — s VDD = 3.3-5.0V, -40°C to +85°C 5 — — s VDD = 3.3-5.0V 31 TWDT Watchdog Timer Time-out Period (no postscaler) — 4.00 — ms 32 TOST Oscillation Start-up Timer Period 1024 TOSC — 1024 TOSC — 33 TPWRT Power-up Timer Period — 65.
PIC18F87K90 FAMILY FIGURE 31-8: HIGH/LOW-VOLTAGE DETECT CHARACTERISTICS For VDIRMAG = 1: VDD VHLVD (HLVDIF set by hardware) (HLVDIF can be cleared in software) VHLVD For VDIRMAG = 0: VDD HLVDIF TABLE 31-11: HIGH/LOW-VOLTAGE DETECT CHARACTERISTICS Standard Operating Conditions (unless otherwise stated) Operating temperature -40°C TA +85°C for industrial -40°C TA +125°C for extended Param Sym No.
PIC18F87K90 FAMILY FIGURE 31-9: TIMER0 AND TIMER1 EXTERNAL CLOCK TIMINGS T0CKI 41 40 42 SOSCO/T1CKI 46 45 47 48 TMR0 or TMR1 Note: Refer to Figure 31-3 for load conditions. TABLE 31-12: TIMER0 AND TIMER1 EXTERNAL CLOCK REQUIREMENTS Param No.
PIC18F87K90 FAMILY FIGURE 31-10: CAPTURE/COMPARE/PWM TIMINGS (ECCP1, ECCP2 MODULES) CCPx (Capture Mode) 50 51 52 CCPx (Compare or PWM Mode) 53 54 Refer to Figure 31-3 for load conditions. Note: TABLE 31-13: CAPTURE/COMPARE/PWM REQUIREMENTS (ECCP1, ECCP2 MODULES) Param Symbol No. 50 51 TCCL TCCH Characteristic Min Max Units CCPx Input Low No prescaler Time With prescaler 0.5 TCY + 20 — ns 10 — ns CCPx Input High Time 0.
PIC18F87K90 FAMILY FIGURE 31-11: EXAMPLE SPI MASTER MODE TIMING (CKE = 0) SCKx (CKP = 0) 78 79 79 78 SCKx (CKP = 1) 80 bit 6 - - - - - - 1 MSb SDOx LSb 75, 76 SDIx MSb In bit 6 - - - - 1 LSb In 74 73 Note: Refer to Figure 31-3 for load conditions. TABLE 31-14: EXAMPLE SPI MODE REQUIREMENTS (MASTER MODE, CKE = 0) Param No.
PIC18F87K90 FAMILY FIGURE 31-12: EXAMPLE SPI MASTER MODE TIMING (CKE = 1) 81 SCKx (CKP = 0) 79 73 SCKx (CKP = 1) 80 78 MSb SDOx bit 6 - - - - - - 1 LSb bit 6 - - - - 1 LSb In 75, 76 SDIx MSb In 74 Note: Refer to Figure 31-3 for load conditions. TABLE 31-15: EXAMPLE SPI MODE REQUIREMENTS (MASTER MODE, CKE = 1) Param. No. Symbol Characteristic Min Max Units 1.
PIC18F87K90 FAMILY FIGURE 31-13: EXAMPLE SPI SLAVE MODE TIMING (CKE = 0) SSx 70 SCKx (CKP = 0) 83 71 72 78 79 79 78 SCKx (CKP = 1) 80 MSb SDOx bit 6 - - - - - - 1 LSb 75, 76 MSb In SDIx 77 bit 6 - - - - 1 LSb In 74 73 Refer to Figure 31-3 for load conditions. Note: TABLE 31-16: EXAMPLE SPI MODE REQUIREMENTS (SLAVE MODE TIMING, CKE = 0) Param No.
PIC18F87K90 FAMILY FIGURE 31-14: EXAMPLE SPI SLAVE MODE TIMING (CKE = 1) 82 SSx SCKx (CKP = 0) 70 83 71 72 SCKx (CKP = 1) 80 MSb SDOx bit 6 - - - - - - 1 LSb 75, 76 SDIx MSb In 77 bit 6 - - - - 1 LSb In 74 Note: Refer to Figure 31-3 for load conditions. TABLE 31-17: EXAMPLE SPI SLAVE MODE REQUIREMENTS (CKE = 1) Param No.
PIC18F87K90 FAMILY I2C™ BUS START/STOP BITS TIMING FIGURE 31-15: SCLx 91 93 90 92 SDAx Stop Condition Start Condition Note: Refer to Figure 31-3 for load conditions. TABLE 31-18: I2C™ BUS START/STOP BITS REQUIREMENTS (SLAVE MODE) Param. Symbol No.
PIC18F87K90 FAMILY FIGURE 31-16: I2C™ BUS DATA TIMING 103 102 100 101 SCLx 90 106 107 91 92 SDAx In 110 109 109 SDAx Out Note: Refer to Figure 31-3 for load conditions. TABLE 31-19: I2C™ BUS DATA REQUIREMENTS (SLAVE MODE) Param. No. 100 Symbol THIGH 101 TLOW 102 TR Characteristic Clock High Time Clock Low Time Min Max Units 100 kHz mode 4.0 — s 400 kHz mode 0.6 — s MSSP module 1.5 TCY — 100 kHz mode 4.7 — s 400 kHz mode 1.3 — s MSSP module 1.
PIC18F87K90 FAMILY MSSP I2C™ BUS START/STOP BITS TIMING WAVEFORMS FIGURE 31-17: SCLx 93 91 90 92 SDAx Stop Condition Start Condition Note: Refer to Figure 31-3 for load conditions. TABLE 31-20: MSSP I2C™ BUS START/STOP BITS REQUIREMENTS Param. Symbol No.
PIC18F87K90 FAMILY TABLE 31-21: MSSP I2C™ BUS DATA REQUIREMENTS Param. Symbol No. 100 101 THIGH TLOW Characteristic Min Max Units Clock High Time 100 kHz mode 2(TOSC)(BRG + 1) — — 400 kHz mode 2(TOSC)(BRG + 1) — — 1 MHz mode(1) 2(TOSC)(BRG + 1) — — Clock Low Time 100 kHz mode 2(TOSC)(BRG + 1) — — 400 kHz mode 2(TOSC)(BRG + 1) — — mode(1) 2(TOSC)(BRG + 1) — — — 1000 ns 20 + 0.
PIC18F87K90 FAMILY FIGURE 31-19: EUSART SYNCHRONOUS TRANSMISSION (MASTER/SLAVE) TIMING TXx/CKx Pin 121 121 RXx/DTx Pin 120 Note: 122 Refer to Figure 31-3 for load conditions. TABLE 31-22: EUSART/AUSART SYNCHRONOUS TRANSMISSION REQUIREMENTS Param No.
PIC18F87K90 FAMILY TABLE 31-25: A/D CONVERTER CHARACTERISTICS: PIC18F87K90 FAMILY (INDUSTRIAL/EXTENDED) Param No. Sym Characteristic Min Typ Max Units Conditions A01 NR Resolution — — 12 bit VREF 5.0V A03 EIL Integral Linearity Error — ±1 ±6.0 LSB VREF = 5.0V A04 EDL Differential Linearity Error — ±1 +3.0/-1.0 LSB VREF = 5.0V A06 EOFF Offset Error — ±1 ±9.0 LSB VREF = 5.0V A07 EGN Gain Error — ±1 ±8.0 LSB VREF = 5.
PIC18F87K90 FAMILY FIGURE 31-21: A/D CONVERSION TIMING BSF ADCON0, GO (Note 2) 131 Q4 130 132 A/D CLK 11 A/D DATA 10 9 ... ... 2 1 0 NEW_DATA OLD_DATA ADRES TCY (Note 1) ADIF GO DONE SAMPLING STOPPED SAMPLE Note 1: If the A/D clock source is selected as RC, a time of TCY is added before the A/D clock starts. This allows the SLEEP instruction to be executed. 2: This is a minimal RC delay (typically 100 ns), which also disconnects the holding capacitor from the analog input.
PIC18F87K90 FAMILY NOTES: DS39957D-page 544 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY 32.0 PACKAGING INFORMATION 32.1 Package Marking Information 64-Lead QFN (9x9x0.9 mm) XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX YYWWNNN 64-Lead TQFP 80-Lead TQFP e3 Note: 18F67K90 -I/PT e3 1110017 Example XXXXXXXXXXXX XXXXXXXXXXXX YYWWNNN * PIC18F67K90 -I/MR e3 1110017 Example XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX YYWWNNN Legend: XX...
PIC18F87K90 FAMILY 32.2 Package Details The following sections give the technical details of the packages. Note: For the most current package drawings, please see the Microchip Packaging Specification located at http://www.microchip.com/packaging DS39957D-page 546 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY Note: For the most current package drawings, please see the Microchip Packaging Specification located at http://www.microchip.com/packaging 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY Note: For the most current package drawings, please see the Microchip Packaging Specification located at http://www.microchip.com/packaging DS39957D-page 548 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY /HDG 3ODVWLF 7KLQ 4XDG )ODWSDFN 37 ± [ [ PP %RG\ PP >74)3@ 1RWH )RU WKH PRVW FXUUHQW SDFNDJH GUDZLQJV SOHDVH VHH WKH 0LFURFKLS 3DFNDJLQJ 6SHFLILFDWLRQ ORFDWHG DW KWWS ZZZ PLFURFKLS FRP SDFNDJLQJ D D1 E e E1 N b NOTE 1 123 NOTE 2 α A φ c A2 β A1 L L1 8QLWV 'LPHQVLRQ /LPLWV 1XPEHU RI /HDGV 0,//,0(7(56 0,1 1 120 0$; /HDG 3LWFK H 2YHUDOO +HLJKW $ ± %6& ± 0ROGHG 3DFNDJH 7KLFNQHVV $ 6WDQGRII $ ± )RRW /HQJ
PIC18F87K90 FAMILY /HDG 3ODVWLF 7KLQ 4XDG )ODWSDFN 37 ± [ [ PP %RG\ PP >74)3@ 1RWH )RU WKH PRVW FXUUHQW SDFNDJH GUDZLQJV SOHDVH VHH WKH 0LFURFKLS 3DFNDJLQJ 6SHFLILFDWLRQ ORFDWHG DW KWWS ZZZ PLFURFKLS FRP SDFNDJLQJ DS39957D-page 550 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY /HDG 3ODVWLF 7KLQ 4XDG )ODWSDFN 37 ± [ [ PP %RG\ PP >74)3@ 1RWH )RU WKH PRVW FXUUHQW SDFNDJH GUDZLQJV SOHDVH VHH WKH 0LFURFKLS 3DFNDJLQJ 6SHFLILFDWLRQ ORFDWHG DW KWWS ZZZ PLFURFKLS FRP SDFNDJLQJ D D1 E e E1 N b NOTE 1 12 3 α NOTE 2 A c β φ A2 A1 L1 L 8QLWV 'LPHQVLRQ /LPLWV 1XPEHU RI /HDGV 0,//,0(7(56 0,1 1 120 0$; /HDG 3LWFK H 2YHUDOO +HLJKW $ ± %6& ± 0ROGHG 3DFNDJH 7KLFNQHVV $ 6WDQGRII $ ± )RRW
PIC18F87K90 FAMILY /HDG 3ODVWLF 7KLQ 4XDG )ODWSDFN 37 ± [ [ PP %RG\ PP >74)3@ 1RWH )RU WKH PRVW FXUUHQW SDFNDJH GUDZLQJV SOHDVH VHH WKH 0LFURFKLS 3DFNDJLQJ 6SHFLILFDWLRQ ORFDWHG DW KWWS ZZZ PLFURFKLS FRP SDFNDJLQJ DS39957D-page 552 2009-2011 Microchip Technology Inc.
PIC18F87K90 FAMILY APPENDIX A: REVISION HISTORY Revision A (September 2009) Original data sheet for PIC18F87K90 family devices. Revision B (April 2010) Changes to Section 32.0 “Packaging Information”, including new packaging diagrams. Changes to some of the values in Section 31.0 “Electrical Characteristics”. The new Section 2.0 “Guidelines for Getting Started with PIC18FXXKXX Microcontrollers” has been added. Minor text edits throughout the document.
PIC18F87K90 FAMILY TABLE B-1: NOTABLE DIFFERENCES BETWEEN PIC18F87K90, PIC18F87J90 AND PIC18F85J90 FAMILIES Characteristic PIC18F87K90 Family PIC18F87J90 Family PIC18F85J90 Family 64 MHz 48 MHz 40 MHz 128 Kbytes 128 Kbytes 32 Kbytes 4 Kbytes 4 Kbytes 2 Kbytes Program Memory Endurance 10,000 Write/Erase (minimum) 10,000 Write/Erase (minimum) 1,000 Write/Erase (minimum) Single-Word Write for Flash Yes Yes No PLL can be used with INTOSC Yes PLL cannot be used with INTOSC CTMU Yes Ye
PIC18F87K90 FAMILY INDEX A A/D .................................................................................... 373 A/D Converter Interrupt, Configuring ........................ 383 Acquisition Requirements ......................................... 384 ADRESH Register..................................................... 381 Analog Port Pins, Configuring................................... 385 Associated Registers ................................................ 388 Automatic Acquisition Time.............
PIC18F87K90 FAMILY Brown-out Reset (BOR) ...................................................... 71 Detecting ..................................................................... 71 BSF ................................................................................... 463 BTFSC .............................................................................. 464 BTFSS............................................................................... 464 BTG.........................................................
PIC18F87K90 FAMILY Core Features Easy Migration .............................................................. 9 Extended Instruction Set............................................... 9 Memory Options............................................................ 9 nanoWatt Technology ................................................... 9 Oscillator Options and Features ................................... 9 CPFSEQ ........................................................................... 468 CPFSGT ..........
PIC18F87K90 FAMILY Synchronous Slave Mode ......................................... 371 Associated Registers, Receive ......................... 372 Associated Registers, Transmit ........................ 371 Reception.......................................................... 372 Transmission..................................................... 371 Extended Instruction Set ADDFSR ................................................................... 494 ADDULNK...................................................
PIC18F87K90 FAMILY Instruction Set ................................................................... 451 ADDLW ..................................................................... 457 ADDWF..................................................................... 457 ADDWF (Indexed Literal Offset Mode) ..................... 499 ADDWFC .................................................................. 458 ANDLW ..................................................................... 458 ANDWF.....................
PIC18F87K90 FAMILY Operation During Sleep ............................................ 299 Pixel Control.............................................................. 285 Prescaler ................................................................... 280 Segment Enables...................................................... 285 Waveform Generation ............................................... 286 LCD Driver .......................................................................... 10 LCDCON Register.........
PIC18F87K90 FAMILY RC3/SCK1/SCL1/SEG17...................................... 17, 26 RC4/SDI1/SDA1/SEG16....................................... 17, 26 RC5/SDO1/SEG12 ............................................... 17, 26 RC6/TX1/CK1/SEG27........................................... 17, 26 RC7/RX1/DT1/SEG28 .......................................... 17, 26 RD0/SEG0/CTPLS................................................ 18, 27 RD1/SEG1/T5CKI/T7G ......................................... 18, 27 RD2/SEG2 .........
PIC18F87K90 FAMILY Multiple Sleep Commands .......................................... 54 Run Modes.................................................................. 54 PRI_RUN ............................................................ 54 RC_RUN ............................................................. 55 SEC_RUN........................................................... 54 Selecting ..................................................................... 53 Sleep Mode ....................................
PIC18F87K90 FAMILY CMSTAT (Comparator Status).................................. 391 CMxCON (Comparator Control x)............................. 390 CONFIG1H (Configuration 1 High) ........................... 428 CONFIG1L (Configuration 1 Low)............................. 427 CONFIG2H (Configuration 2 High) ........................... 430 CONFIG2L (Configuration 2 Low)............................. 429 CONFIG3H (Configuration 3 High) ........................... 431 CONFIG3L (Configuration 3 Low)...............
PIC18F87K90 FAMILY S T SCKx ................................................................................. 303 SDIx .................................................................................. 303 SDOx................................................................................. 303 SEC_IDLE Mode................................................................. 59 SEC_RUN Mode ................................................................. 54 Secondary Oscillator (SOSC) ......................
PIC18F87K90 FAMILY Timing Diagrams A/D Conversion......................................................... 543 Automatic Baud Rate Calculation ............................. 358 Auto-Wake-up Bit (WUE) During Normal Operation .......................................................... 365 Auto-Wake-up Bit (WUE) During Sleep .................... 365 Baud Rate Generator with Clock Arbitration ............. 336 BRG Overflow Sequence..........................................
PIC18F87K90 FAMILY Type-A in 1/2 MUX, 1/3 Bias Drive ........................... 290 Type-A in 1/3 MUX, 1/2 Bias Drive ........................... 292 Type-A in 1/3 MUX, 1/3 Bias Drive ........................... 294 Type-A in 1/4 MUX, 1/3 Bias Drive ........................... 296 Type-A/Type-B in Static Drive................................... 287 Type-B in 1/2 MUX, 1/2 Bias Drive ........................... 289 Type-B in 1/2 MUX, 1/3 Bias Drive ...........................
PIC18F87K90 FAMILY THE MICROCHIP WEB SITE CUSTOMER SUPPORT Microchip provides online support via our WWW site at www.microchip.com. This web site is used as a means to make files and information easily available to customers.
PIC18F87K90 FAMILY READER RESPONSE It is our intention to provide you with the best documentation possible to ensure successful use of your Microchip product. If you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please FAX your comments to the Technical Publications Manager at (480) 792-4150. Please list the following information, and use this outline to provide us with your comments about this document.
PIC18F87K90 FAMILY PRODUCT IDENTIFICATION SYSTEM To order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office. PART NO.
Worldwide Sales and Service AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://www.microchip.com/ support Web Address: www.microchip.