PIC18F2420-I/ML Microchip Technology, PIC18F2420-I/ML Datasheet

IC PIC MCU FLASH 8KX16 28QFN

PIC18F2420-I/ML

Manufacturer Part Number
PIC18F2420-I/ML
Description
IC PIC MCU FLASH 8KX16 28QFN
Manufacturer
Microchip Technology
Series
PIC® 18Fr

Specifications of PIC18F2420-I/ML

Program Memory Type
FLASH
Program Memory Size
16KB (8K x 16)
Package / Case
28-VQFN Exposed Pad, 28-HVQFN, 28-SQFN, 28-DHVQFN
Core Processor
PIC
Core Size
8-Bit
Speed
40MHz
Connectivity
I²C, SPI, UART/USART
Peripherals
Brown-out Detect/Reset, HLVD, POR, PWM, WDT
Number Of I /o
25
Eeprom Size
256 x 8
Ram Size
768 x 8
Voltage - Supply (vcc/vdd)
4.2 V ~ 5.5 V
Data Converters
A/D 10x10b
Oscillator Type
Internal
Operating Temperature
-40°C ~ 85°C
Processor Series
PIC18F
Core
PIC
Data Bus Width
8 bit
Data Ram Size
768 B
Interface Type
EUSART, I2C, MSSP, SPI
Maximum Clock Frequency
40 MHz
Number Of Programmable I/os
25
Number Of Timers
1 x 8
Operating Supply Voltage
2 V to 5.5 V
Maximum Operating Temperature
+ 85 C
Mounting Style
SMD/SMT
3rd Party Development Tools
52715-96, 52716-328, 52717-734, 52712-325, EWPIC18
Development Tools By Supplier
PG164130, DV164035, DV244005, DV164005, PG164120, ICE2000, ICE4000, DM163014, DV164136
Minimum Operating Temperature
- 40 C
On-chip Adc
10 bit
Package
28QFN EP
Device Core
PIC
Family Name
PIC18
Maximum Speed
40 MHz
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With
XLT28QFN4 - SOCKET TRANS ICE 28QFN W/CABLEAC164322 - MODULE SOCKET MPLAB PM3 28/44QFN
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
PIC18F2420-I/ML
Manufacturer:
MICROCHIP/微芯
Quantity:
20 000
PIC18F2420/2520/4420/4520
Data Sheet
28/40/44-Pin Enhanced Flash
Microcontrollers with 10-Bit A/D
and nanoWatt Technology
© 2008 Microchip Technology Inc.
DS39631E

Related parts for PIC18F2420-I/ML

PIC18F2420-I/ML Summary of contents

Page 1

... PIC18F2420/2520/4420/4520 Microcontrollers with 10-Bit A/D © 2008 Microchip Technology Inc. Data Sheet 28/40/44-Pin Enhanced Flash and nanoWatt Technology DS39631E ...

Page 2

... PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. ...

Page 3

... PIC18F4520 32K 16384 © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Peripheral Highlights (Continued): • Master Synchronous Serial Port (MSSP) module Supporting 3-Wire SPI (all 4 modes) and I Master and Slave modes • Enhanced Addressable USART module: - Supports RS-485, RS-232 and LIN/J2602 ...

Page 4

... REF RA3/AN3/V RA4/T0CKI/C1OUT RA5/AN4/SS/HLVDIN/C2OUT RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7 OSC1/CLKI/RA7 OSC2/CLKO/RA6 RC0/T1OSO/T13CKI RC1/T1OSI/CCP2 RC2/CCP1/P1A RC3/SCK/SCL RD0/PSP0 RD1/PSP1 Note 1: RB3 is the alternate pin for CCP2 multiplexing. DS39631E-page /RE3 REF + 5 24 REF ( REF + 2 20 REF 3 19 PIC18F2420 4 18 PIC18F2520 /RE3 -/CV 4 REF 37 + REF ( RB7/KBI3/PGD RB6//KBI2/PGC ...

Page 5

... RD6/PSP6/P1C RD7/PSP7/P1D RB0/INT0/FLT0/AN12 RB1/INT1/AN10 RB2/INT2/AN8 (1) RB3/AN9/CCP2 44-pin QFN RC7/RX/DT RD4/PSP4 RD5/PSP5/P1B RD6/PSP6/P1C RD7/PSP7/P1D RB0/INT0/FLT0/AN12 RB1/INT1/AN10 RB2/INT2/AN8 Note 1: RB3 is the alternate pin for CCP2 multiplexing. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 RC0/T1OSO/T13CKI 2 OSC2/CLKO/RA6 31 3 OSC1/CLKI/RA7 PIC18F4420 PIC18F4520 RE2/CS/AN7 27 7 RE1/WR/AN6 26 8 RE0/RD/AN5 ...

Page 6

... Appendix C: Migration from Mid-Range to Enhanced Devices .......................................................................................................... 396 Appendix D: Migration from High-End to Enhanced Devices............................................................................................................. 396 Index .................................................................................................................................................................................................. 397 The Microchip Web Site ..................................................................................................................................................................... 407 Customer Change Notification Service .............................................................................................................................................. 407 Customer Support .............................................................................................................................................................................. 407 Reader Response .............................................................................................................................................................................. 408 PIC18F2420/2520/4420/4520 Product Identification System ............................................................................................................ 409 DS39631E-page 4 © 2008 Microchip Technology Inc. ...

Page 7

... When contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are using. Customer Notification System Register on our web site at www.microchip.com to receive the most current information on all of our products. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 DS39631E-page 5 ...

Page 8

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 6 © 2008 Microchip Technology Inc. ...

Page 9

... Microchip Technology Inc. PIC18F2420/2520/4420/4520 1.1.2 MULTIPLE OSCILLATOR OPTIONS AND FEATURES All of the devices in the PIC18F2420/2520/4420/4520 family offer ten different oscillator options, allowing users a wide range of choices in developing application hardware. These include: • Four Crystal modes, using crystals or ceramic resonators • ...

Page 10

... Like all Microchip PIC18 devices, members of the PIC18F2420/2520/4420/4520 family are available as both standard and low-voltage devices. Standard devices with Enhanced Flash memory, designated with an “F” in the part number (such as PIC18F2420), accommodate an operating V range of 4.2V to 5.5V. DD Low-voltage parts, designated by “LF” (such as PIC18LF2420), function over an extended ...

Page 11

... MCLR (optional), WDT Programmable High/Low-Voltage Detect Programmable Brown-out Reset Instruction Set 75 Instructions; 83 with Extended Instruction Set Enabled Packages 28-Pin SPDIP 28-Pin SOIC 28-Pin QFN © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 PIC18F2520 DC – 40 MHz 16384 32768 8192 16384 768 1536 256 256 19 19 ...

Page 12

... PIC18F2420/2520/4420/4520 FIGURE 1-1: PIC18F2420/2520 (28-PIN) BLOCK DIAGRAM Table Pointer<21> 8 inc/dec logic PCLATH PCLATU 21 20 PCU PCH Program Counter 31-Level Stack Address Latch Program Memory STKPTR (16/32 Kbytes) Data Latch 8 Table Latch ROM Latch Instruction Bus <16> IR State Machine Instruction Control Signals ...

Page 13

... OSC1/CLKI and OSC2/CLKO are only available in select oscillator modes and when these pins are not being used as digital I/O. 3: Refer to Section 2.0 “Oscillator Configurations” for additional information. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Data Bus<8> Data Latch 8 Data Memory ( 3.9 Kbytes ) ...

Page 14

... PIC18F2420/2520/4420/4520 TABLE 1-2: PIC18F2420/2520 PINOUT I/O DESCRIPTIONS Pin Number Pin Name SPDIP, QFN SOIC MCLR/V /RE3 MCLR V PP RE3 OSC1/CLKI/RA7 9 6 OSC1 CLKI RA7 OSC2/CLKO/RA6 10 7 OSC2 CLKO RA6 Legend: TTL = TTL compatible input ST = Schmitt Trigger input with CMOS levels O = Output Note 1: Default assignment for CCP2 when Configuration bit, CCP2MX, is set ...

Page 15

... TABLE 1-2: PIC18F2420/2520 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name SPDIP, QFN SOIC RA0/AN0 2 27 RA0 AN0 RA1/AN1 3 28 RA1 AN1 RA2/AN2/V -/ REF REF RA2 AN2 V - REF CV REF RA3/AN3 REF RA3 AN3 V + REF RA4/T0CKI/C1OUT 6 3 RA4 T0CKI C1OUT RA5/AN4/SS/HLVDIN C2OUT ...

Page 16

... PIC18F2420/2520/4420/4520 TABLE 1-2: PIC18F2420/2520 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name SPDIP, QFN SOIC RB0/INT0/FLT0/AN12 21 18 RB0 INT0 FLT0 AN12 RB1/INT1/AN10 22 19 RB1 INT1 AN10 RB2/INT2/AN8 23 20 RB2 INT2 AN8 RB3/AN9/CCP2 24 21 RB3 AN9 (1) CCP2 RB4/KBI0/AN11 25 22 RB4 KBI0 AN11 ...

Page 17

... TABLE 1-2: PIC18F2420/2520 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name SPDIP, QFN SOIC RC0/T1OSO/T13CKI 11 8 RC0 T1OSO T13CKI RC1/T1OSI/CCP2 12 9 RC1 T1OSI (2) CCP2 RC2/CCP1 13 10 RC2 CCP1 RC3/SCK/SCL 14 11 RC3 SCK SCL RC4/SDI/SDA 15 12 RC4 SDI SDA RC5/SDO 16 13 RC5 ...

Page 18

... PIC18F2420/2520/4420/4520 TABLE 1-3: PIC18F4420/4520 PINOUT I/O DESCRIPTIONS Pin Number Pin Name PDIP QFN TQFP MCLR/V /RE3 MCLR V PP RE3 OSC1/CLKI/RA7 13 32 OSC1 CLKI RA7 OSC2/CLKO/RA6 14 33 OSC2 CLKO RA6 Legend: TTL = TTL compatible input ST = Schmitt Trigger input with CMOS levels O = Output Note 1: Default assignment for CCP2 when Configuration bit, CCP2MX, is set ...

Page 19

... ST = Schmitt Trigger input with CMOS levels O = Output Note 1: Default assignment for CCP2 when Configuration bit, CCP2MX, is set. 2: Alternate assignment for CCP2 when Configuration bit, CCP2MX, is cleared. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Pin Buffer Type Type PORTA is a bidirectional I/O port. ...

Page 20

... PIC18F2420/2520/4420/4520 TABLE 1-3: PIC18F4420/4520 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name PDIP QFN TQFP RB0/INT0/FLT0/AN12 33 9 RB0 INT0 FLT0 AN12 RB1/INT1/AN10 34 10 RB1 INT1 AN10 RB2/INT2/AN8 35 11 RB2 INT2 AN8 RB3/AN9/CCP2 36 12 RB3 AN9 (1) CCP2 RB4/KBI0/AN11 37 14 RB4 KBI0 AN11 ...

Page 21

... ST = Schmitt Trigger input with CMOS levels O = Output Note 1: Default assignment for CCP2 when Configuration bit, CCP2MX, is set. 2: Alternate assignment for CCP2 when Configuration bit, CCP2MX, is cleared. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Pin Buffer Type Type PORTC is a bidirectional I/O port. ...

Page 22

... PIC18F2420/2520/4420/4520 TABLE 1-3: PIC18F4420/4520 PINOUT I/O DESCRIPTIONS (CONTINUED) Pin Number Pin Name PDIP QFN TQFP RD0/PSP0 19 38 RD0 PSP0 RD1/PSP1 20 39 RD1 PSP1 RD2/PSP2 21 40 RD2 PSP2 RD3/PSP3 22 41 RD3 PSP3 RD4/PSP4 27 2 RD4 PSP4 RD5/PSP5/P1B 28 3 RD5 PSP5 P1B RD6/PSP6/P1C ...

Page 23

... ST = Schmitt Trigger input with CMOS levels O = Output Note 1: Default assignment for CCP2 when Configuration bit, CCP2MX, is set. 2: Alternate assignment for CCP2 when Configuration bit, CCP2MX, is cleared. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Pin Buffer Type Type PORTE is a bidirectional I/O port. ...

Page 24

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 22 © 2008 Microchip Technology Inc. ...

Page 25

... OSCILLATOR CONFIGURATIONS 2.1 Oscillator Types PIC18F2420/2520/4420/4520 devices can be operated in ten different oscillator modes. The user can program the Configuration bits, FOSC<3:0>, in Configuration Register 1H to select one of these ten modes Low-Power Crystal 2. XT Crystal/Resonator 3. HS High-Speed Crystal/Resonator 4. HSPLL High-Speed Crystal/Resonator with PLL Enabled 5 ...

Page 26

... PIC18F2420/2520/4420/4520 TABLE 2-2: CAPACITOR SELECTION FOR CRYSTAL OSCILLATOR Typical Capacitor Values Crystal Tested: Osc Type Freq kHz MHz MHz MHz MHz MHz MHz MHz 15 pF Capacitor values are for design guidance only. These capacitors were tested with the crystals listed below for basic start-up and operation. These values are not optimized ...

Page 27

... EXT C > EXT © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 2.5 PLL Frequency Multiplier A Phase Locked Loop (PLL) circuit is provided as an option for users who wish to use a lower frequency oscillator circuit or to clock the device up to its highest rated frequency from a crystal oscillator. This may be ...

Page 28

... PIC18F2420/2520/4420/4520 2.6 Internal Oscillator Block The PIC18F2420/2520/4420/4520 devices include an internal oscillator block which generates two different clock signals; either can be used as the micro- controller’s clock source. This may eliminate the need for external oscillator circuits on the OSC1 and/or OSC2 pins. ...

Page 29

... If the internally clocked timer value is greater than expected, then the internal oscillator block is running too fast. To adjust for this, decrement the OSCTUNE register. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 R/W-0 TUN4 TUN3 TUN2 U = Unimplemented bit, read as ‘ ...

Page 30

... The INTRC source is also used as the clock source for several special features, such as the WDT and Fail-Safe Clock Monitor. The clock sources for the PIC18F2420/2520/4420/4520 devices are shown in Figure 2-8. See Section 23.0 “Special Features of the CPU” for Configuration register details ...

Page 31

... Timer1 oscillator starts. 2.7.2 OSCILLATOR TRANSITIONS PIC18F2420/2520/4420/4520 devices contain circuitry to prevent clock “glitches” when switching between clock sources. A short pause in the device clock occurs during the clock switch. The length of this pause is the sum of two cycles of the old clock source and three to four cycles of the new clock source ...

Page 32

... PIC18F2420/2520/4420/4520 REGISTER 2-2: OSCCON: OSCILLATOR CONTROL REGISTER R/W-0 R/W-1 R/W-0 IDLEN IRCF2 IRCF1 bit 7 Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 IDLEN: Idle Enable bit 1 = Device enters an Idle mode on SLEEP instruction 0 = Device enters Sleep mode on SLEEP instruction bit 6-4 IRCF< ...

Page 33

... See Table 4-2 in Section 4.0 “Reset” for time-outs due to Sleep and MCLR Reset. Note: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 not require a device clock source (i.e., MSSP slave, PSP, INTx pins and others). Peripherals that may add significant current Section 26.2 “ ...

Page 34

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 32 © 2008 Microchip Technology Inc. ...

Page 35

... POWER-MANAGED MODES PIC18F2420/2520/4420/4520 devices offer 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 (i.e., battery-powered devices). There are three categories of power-managed modes: • Run modes • ...

Page 36

... PIC18F2420/2520/4420/4520 3.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. Three bits indicate the current clock source and its status. They are: • ...

Page 37

... PRI_RUN RC_RUN modes during execution. However, a clock switch delay will occur during entry to and exit from RC_RUN mode. Therefore, if the primary clock source is the internal oscillator block, the use of RC_RUN mode is not recommended. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 n-1 n (1) ...

Page 38

... PIC18F2420/2520/4420/4520 If the IRCF bits and the INTSRC bit are all clear, the INTOSC output is not enabled and the IOFS bit will remain clear; there will be no indication of the current clock source. The INTRC source is providing the device clocks. If the IRCF bits are changed from all clear (thus, ...

Page 39

... Sleep Mode The power-managed Sleep mode in the PIC18F2420/ 2520/4420/4520 devices is identical to the legacy Sleep mode offered in all other PIC devices entered by clearing the IDLEN bit (the default state on device Reset) and executing the SLEEP instruction. This shuts down the selected oscillator (Figure 3-5). All clock source status bits are cleared ...

Page 40

... PIC18F2420/2520/4420/4520 3.4.1 PRI_IDLE MODE 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 “ ...

Page 41

... INTCON or PIE registers. The exit sequence is initiated when the corresponding interrupt flag bit is set. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 On all exits from Idle or Sleep modes by interrupt, code execution branches to the interrupt vector if the GIE/ GIEH bit (INTCON<7>) is set. Otherwise, code execu- tion continues or resumes without branching (see Section 9.0 “ ...

Page 42

... PIC18F2420/2520/4420/4520 3.5.4 EXIT WITHOUT AN OSCILLATOR START-UP DELAY Certain exits from power-managed modes do not invoke the OST at all. There are two cases: • PRI_IDLE mode, where the primary clock source is not stopped and • the primary clock source is not any of the LP, XT HSPLL modes ...

Page 43

... RESET The PIC18F2420/2520/4420/4520 devices differentiate between various kinds of Reset: a) Power-on Reset (POR) b) MCLR Reset during normal operation c) MCLR Reset during power-managed modes d) Watchdog Timer (WDT) Reset (during execution) e) Programmable Brown-out Reset (BOR) f) RESET Instruction g) Stack Full Reset h) Stack Underflow Reset ...

Page 44

... PIC18F2420/2520/4420/4520 REGISTER 4-1: RCON: RESET CONTROL REGISTER (1) R/W-0 R/W-1 U-0 IPEN SBOREN — bit 7 Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 IPEN: Interrupt Priority Enable bit 1 = Enable priority levels on interrupts 0 = Disable priority levels on interrupts (PIC16CXXX Compatibility mode) ...

Page 45

... MCLR Reset path which detects and ignores small pulses. The MCLR pin is not driven low by any internal Resets, including the WDT. In PIC18F2420/2520/4420/4520 devices, the MCLR input can be disabled with the MCLRE Configuration bit. When MCLR is disabled, the pin becomes a digital input. See Section 10.5 “PORTE, TRISE and LATE Registers” ...

Page 46

... PIC18F2420/2520/4420/4520 4.4 Brown-out Reset (BOR) PIC18F2420/2520/4420/4520 devices implement a BOR circuit that provides the user with a number of configuration and power-saving options. The BOR is controlled by the BORV<1:0> and BOREN<1:0> Configuration bits. There are a total of four BOR configurations which are summarized in Table 4-1. The BOR threshold is set by the BORV<1:0> bits. If BOR is enabled (any values of BOREN< ...

Page 47

... Oscillator Start-up Timer (OST) • PLL Lock Time-out 4.5.1 POWER-UP TIMER (PWRT) The Power-up Timer (PWRT) of PIC18F2420/2520/ 4420/4520 devices is an 11-bit counter which uses the INTRC source as the clock input. This yields an approximate time interval of 2048 x 32 μs = 65.6 ms. ...

Page 48

... PIC18F2420/2520/4420/4520 FIGURE 4-3: TIME-OUT SEQUENCE ON POWER-UP (MCLR TIED MCLR INTERNAL POR PWRT TIME-OUT OST TIME-OUT INTERNAL RESET FIGURE 4-4: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED MCLR INTERNAL POR PWRT TIME-OUT OST TIME-OUT INTERNAL RESET FIGURE 4-5: TIME-OUT SEQUENCE ON POWER-UP (MCLR NOT TIED TO V ...

Page 49

... TIME-OUT SEQUENCE ON POR W/PLL ENABLED (MCLR TIED MCLR INTERNAL POR PWRT TIME-OUT OST TIME-OUT PLL TIME-OUT INTERNAL RESET T = 1024 clock cycles. Note: OST ≈ max. First three stages of the PWRT timer. T PLL © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 , V RISE > PWRT PWRT T OST T PWRT T OST T ...

Page 50

... PIC18F2420/2520/4420/4520 4.6 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. Most registers are not affected by a WDT wake-up, since this is viewed as the resumption of normal oper- ation ...

Page 51

... PORTA pins, they are disabled and read ‘0’. The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When 6: PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 MCLR Resets, Power-on Reset, WDT Reset, Brown-out Reset ...

Page 52

... PIC18F2420/2520/4420/4520 TABLE 4-4: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Register Applicable Devices FSR1H 2420 2520 4420 FSR1L 2420 2520 4420 BSR 2420 2520 4420 INDF2 2420 2520 4420 POSTINC2 2420 2520 4420 POSTDEC2 2420 2520 4420 PREINC2 2420 2520 4420 PLUSW2 ...

Page 53

... PORTA pins, they are disabled and read ‘0’. The Reset value of the PCFG bits depends on the value of the PBADEN Configuration bit (CONFIG3H<1>). When 6: PBADEN = 1, PCFG<2:0> = 000; when PBADEN = 0, PCFG<2:0> = 111. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 MCLR Resets, Power-on Reset, WDT Reset, Brown-out Reset ...

Page 54

... PIC18F2420/2520/4420/4520 TABLE 4-4: INITIALIZATION CONDITIONS FOR ALL REGISTERS (CONTINUED) Register Applicable Devices IPR2 2420 2520 4420 PIR2 2420 2520 4420 PIE2 2420 2520 4420 2420 2520 4420 IPR1 2420 2520 4420 2420 2520 4420 PIR1 2420 2520 4420 2420 2520 4420 ...

Page 55

... NOP instruction). The PIC18F2420 and PIC18F4420 each have 16 Kbytes of Flash memory and can store up to 8,192 single-word instructions. The PIC18F2520 and PIC18F4520 each have 32 Kbytes of Flash memory and can store up to 16,384 single-word instructions ...

Page 56

... PIC18F2420/2520/4420/4520 5.1.1 PROGRAM COUNTER The Program Counter (PC) specifies the address of the instruction to fetch for execution. The bits wide and is 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< ...

Page 57

... Bit 7 and bit 6 are cleared by user software POR. Note 1: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 When the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the PC and sets the STKUNF bit, while the Stack Pointer remains at zero ...

Page 58

... PIC18F2420/2520/4420/4520 5.1.2.4 Stack Full and Underflow Resets Device Resets on stack overflow and stack underflow conditions are enabled by setting the STVREN bit in Configuration Register 4L. When STVREN is set, a full or underflow will set the appropriate STKFUL or STKUNF bit and then cause a device Reset. When ...

Page 59

... All instructions are single cycle, except for any program branches. These take two cycles since the fetch instruction is “flushed” from the pipeline while the new instruction is being fetched and then executed. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 5.2.2 INSTRUCTION FLOW/PIPELINING An “ ...

Page 60

... PIC18F2420/2520/4420/4520 5.2.3 INSTRUCTIONS IN PROGRAM MEMORY The program memory is addressed in bytes. Instruc- tions are stored as two bytes or four bytes in program memory. The Least Significant Byte 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 2 and the LSb will always read ‘ ...

Page 61

... RAM. Each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. The memory space is divided into as many as 16 banks that contain 256 bytes each; PIC18F2420/ 2520/4420/4520 devices implement all 16 banks. Figure 5-5 shows the data memory organization for the PIC18F2420/2520/4420/4520 devices ...

Page 62

... PIC18F2420/2520/4420/4520 FIGURE 5-5: DATA MEMORY MAP FOR PIC18F2420/4420 DEVICES BSR<3:0> 00h = 0000 Bank 0 FFh 00h = 0001 Bank 1 FFh 00h = 0010 Bank 2 FFh 00h = 0011 Bank 3 FFh 00h = 0100 Bank 4 FFh 00h = 0101 Bank 5 FFh 00h = 0110 Bank 6 FFh 00h = 0111 Bank 7 ...

Page 63

... Bank 12 FFh = 1101 00h Bank 13 FFh 00h = 1110 Bank 14 FFh 00h = 1111 Bank 15 FFh © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Data Memory Map 000h Access RAM 07Fh 080h GPR 0FFh 100h GPR 1FFh 200h GPR 2FFh 300h GPR 3FFh ...

Page 64

... PIC18F2420/2520/4420/4520 FIGURE 5-7: USE OF THE BANK SELECT REGISTER (DIRECT ADDRESSING) BSR ( (2) Bank Select The Access RAM bit of the instruction can be used to force an override of the selected bank (BSR<3:0>) to Note 1: the registers of the Access Bank. The MOVFF instruction embeds the entire 12-bit address in the instruction. ...

Page 65

... RAM. SFRs start at the top of data memory (FFFh) and extend downward to occupy the top half of Bank 15 (F80h to FFFh). A list of these registers is given in Table 5-1 and Table 5-2. TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2420/2520/4420/4520 DEVICES Address Name Address FFFh ...

Page 66

... PIC18F2420/2520/4420/4520 TABLE 5-2: PIC18F2420/2520/4420/4520 REGISTER FILE SUMMARY File Name Bit 7 Bit 6 Bit 5 TOSU — — — TOSH Top-of-Stack High Byte (TOS<15:8>) TOSL Top-of-Stack Low Byte (TOS<7:0>) STKPTR STKFUL STKUNF — PCLATU — — — PCLATH Holding Register for PC<15:8> PCL PC Low Byte (PC<7:0>) TBLPTRU — ...

Page 67

... TABLE 5-2: PIC18F2420/2520/4420/4520 REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 TMR0H Timer0 Register High Byte TMR0L Timer0 Register Low Byte T0CON TMR0ON T08BIT T0CS OSCCON IDLEN IRCF2 IRCF1 HLVDCON VDIRMAG — IRVST WDTCON — — — (1) RCON IPEN SBOREN — ...

Page 68

... PIC18F2420/2520/4420/4520 TABLE 5-2: PIC18F2420/2520/4420/4520 REGISTER FILE SUMMARY (CONTINUED) File Name Bit 7 Bit 6 Bit 5 SPBRGH EUSART Baud Rate Generator Register High Byte SPBRG EUSART Baud Rate Generator Register Low Byte RCREG EUSART Receive Register TXREG EUSART Transmit Register TXSTA CSRC TX9 TXEN ...

Page 69

... For rotate (RRF, RLF) instructions, this bit is loaded with either the high or low-order bit of the source register. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 It is recommended that only BCF, BSF, SWAPF, MOVFF and MOVWF instructions are used to alter the STATUS register, because these instructions do not affect the bits in the STATUS register ...

Page 70

... PIC18F2420/2520/4420/4520 5.4 Data Addressing Modes The execution of some instructions in the Note: core PIC18 instruction set are changed when the PIC18 extended instruction set is enabled. See Section 5.5 “Data Memory and the Extended Instruction Set” for more information. While the program memory can be addressed in only one way – ...

Page 71

... ECCh. This means the contents of location ECCh will be added to that of the W register and stored back in ECCh. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 5.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 “ ...

Page 72

... PIC18F2420/2520/4420/4520 The PLUSW register can be used to implement a form of Indexed Addressing in the data memory space. By manipulating the value in the W register, users can reach addresses that are fixed offsets from pointer addresses. In some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory ...

Page 73

... The bank is designated by the Bank Select Register (BSR). The address can be in any implemented bank in the data memory space. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 000h 060h 080h Bank 0 100h Bank 1 through Bank 14 ...

Page 74

... PIC18F2420/2520/4420/4520 5.5.3 MAPPING THE ACCESS BANK IN INDEXED LITERAL OFFSET MODE The use of Indexed Literal Offset Addressing mode effectively changes how the first 96 locations of Access RAM (00h to 5Fh) are mapped. Rather than containing just the contents of the bottom half of Bank 0, this mode maps the contents from Bank 0 and a user-defined “ ...

Page 75

... Program Memory (TBLPTR) Note 1: The Table Pointer register points to a byte in program memory. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 6.1 Table Reads and Table Writes In order to read and write program memory, there are two operations that allow the processor to move bytes ...

Page 76

... PIC18F2420/2520/4420/4520 FIGURE 6-2: TABLE WRITE OPERATION (1) Table Pointer TBLPTRU TBLPTRH TBLPTRL Program Memory (TBLPTR) Note1: The Table Pointer actually points to one of 32 holding registers, the address of which is determined by TBLPTRL<4:0>. The process for physically writing data to the program memory array is discussed in Section 6.5 “Writing to Flash Program Memory”. ...

Page 77

... RD bit cannot be set when EEPGD = 1 or CFGS = 1 Does not initiate an EEPROM read When a WRERR occurs, the EEPGD and CFGS bits are not cleared. This allows tracing of the error Note 1: condition. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-x R/W-0 (1) FREE ...

Page 78

... PIC18F2420/2520/4420/4520 6.2.2 TABLAT – TABLE LATCH REGISTER The Table Latch (TABLAT 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. 6.2.3 TBLPTR – TABLE POINTER REGISTER The Table Pointer (TBLPTR) register addresses a byte within the program memory ...

Page 79

... MOVFW TABLAT, W MOVF WORD_ODD © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 TBLPTR points to a byte address in program 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 ...

Page 80

... PIC18F2420/2520/4420/4520 6.4 Erasing Flash Program Memory The minimum erase block is 32 words or 64 bytes. Only through the use of an external programmer, or through ICSP control, can larger blocks of program memory be bulk erased. Word erase in the Flash array is not supported. When initiating an erase sequence from the micro- controller itself, a block of 64 bytes of program memory is erased ...

Page 81

... CFGS bit to access program memory; • set WREN to enable byte writes. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 The long write is necessary for programming the inter- nal Flash. Instruction execution is halted while in a long write cycle. The long write will be terminated by the internal programming timer ...

Page 82

... PIC18F2420/2520/4420/4520 EXAMPLE 6-3: WRITING TO FLASH PROGRAM MEMORY MOVLW D'64 MOVWF COUNTER MOVLW BUFFER_ADDR_HIGH MOVWF FSR0H MOVLW BUFFER_ADDR_LOW MOVWF FSR0L MOVLW CODE_ADDR_UPPER MOVWF TBLPTRU MOVLW CODE_ADDR_HIGH MOVWF TBLPTRH MOVLW CODE_ADDR_LOW MOVWF TBLPTRL READ_BLOCK TBLRD*+ MOVF TABLAT, W MOVWF POSTINC0 DECFSZ COUNTER BRA READ_BLOCK ...

Page 83

... CMIF PIE2 OSCFIE CMIE Legend: — = unimplemented, read as ‘0’. Shaded cells are not used during Flash/EEPROM access. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 ; point to Flash program memory ; access Flash program memory ; enable write to memory ; disable interrupts ; write 55h ; write 0AAh ...

Page 84

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 82 © 2008 Microchip Technology Inc. ...

Page 85

... EEPROM. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 The EECON1 register (Register 7-1) is the control register for data and program memory access. Control bit EEPGD determines if the access will be to program or data EEPROM memory ...

Page 86

... PIC18F2420/2520/4420/4520 REGISTER 7-1: EECON1: EEPROM CONTROL REGISTER 1 R/W-x R/W-x U-0 EEPGD CFGS — bit Settable bit (cannot be cleared in software) Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 EEPGD: Flash Program or Data EEPROM Memory Select bit 1 = Access Flash program memory ...

Page 87

... BSF INTCON, GIE BCF EECON1, WREN © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Additionally, the WREN bit in EECON1 must be set to enable writes. This mechanism prevents accidental writes to data EEPROM due to unexpected code exe- cution (i.e., runaway programs). The WREN bit should be kept clear at all times, except when updating the EEPROM ...

Page 88

... PIC18F2420/2520/4420/4520 7.6 Operation During Code-Protect Data EEPROM memory has its own code-protect bits in Configuration Words. External read 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 23.0 “ ...

Page 89

... CFGS IPR2 OSCFIP CMIP PIR2 OSCFIF CMIF PIE2 OSCFIE CMIE Legend: — = unimplemented, read as ‘0’. Shaded cells are not used during Flash/EEPROM access. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Bit 5 Bit 4 Bit 3 Bit 2 TMR0IE INT0IE RBIE TMR0IF — FREE WRERR WREN — ...

Page 90

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 88 © 2008 Microchip Technology Inc. ...

Page 91

... Hardware multiply Without hardware multiply signed Hardware multiply Without hardware multiply unsigned Hardware multiply Without hardware multiply signed Hardware multiply © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 EXAMPLE 8-1: MOVF ARG1, W MULWF ARG2 EXAMPLE 8-2: MOVF ARG1, W MULWF ARG2 BTFSC ARG2, SB ...

Page 92

... PIC18F2420/2520/4420/4520 Example 8-3 shows the sequence unsigned multiplication. Equation 8-1 shows the algorithm that is used. The 32-bit result is stored in four registers (RES<3:0>). EQUATION 8- UNSIGNED MULTIPLICATION ALGORITHM ARG1H:ARG1L • ARG2H:ARG2L RES<3:0> = (ARG1H • ARG2H • (ARG1H • ARG2L • (ARG1L • ARG2H • 2 ...

Page 93

... Individual interrupts can be disabled through their corresponding enable bits. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 When the IPEN bit is cleared (default state), the interrupt priority feature is disabled and interrupts are devices ...

Page 94

... PIC18F2420/2520/4420/4520 FIGURE 9-1: PIC18 INTERRUPT LOGIC SSPIF SSPIE SSPIP ADIF ADIE ADIP RCIF RCIE RCIP Additional Peripheral Interrupts High-Priority Interrupt Generation Low-Priority Interrupt Generation SSPIF SSPIE SSPIP ADIF ADIE ADIP RCIF RCIE RCIP Additional Peripheral Interrupts DS39631E-page 92 TMR0IF TMR0IE TMR0IP RBIF ...

Page 95

... A mismatch condition will continue to set this bit. Reading PORTB will end the mismatch condition and Note 1: allow the bit to be cleared. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Interrupt flag bits are set when an interrupt Note: condition occurs, regardless of the state of its corresponding enable bit or the global enable bit ...

Page 96

... PIC18F2420/2520/4420/4520 REGISTER 9-2: INTCON2: INTERRUPT CONTROL REGISTER 2 R/W-1 R/W-1 R/W-1 RBPU INTEDG0 INTEDG1 bit 7 Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 RBPU: PORTB Pull-up Enable bit 1 = All PORTB pull-ups are disabled 0 = PORTB pull-ups are enabled by individual port latch values ...

Page 97

... Interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding Note: enable bit or the global enable bit. User software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. This feature allows for software polling. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 U-0 INT2IE INT1IE — ...

Page 98

... PIC18F2420/2520/4420/4520 9.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 two Peripheral Interrupt Request Flag registers (PIR1 and PIR2). REGISTER 9-4: PIR1: PERIPHERAL INTERRUPT REQUEST (FLAG) REGISTER 1 ...

Page 99

... No TMR1 register capture occurred Compare mode TMR1 register compare match occurred (must be cleared in software TMR1 register compare match occurred PWM mode: Unused in this mode. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 R/W-0 EEIF BCLIF HLVDIF U = Unimplemented bit, read as ‘0’ ...

Page 100

... PIC18F2420/2520/4420/4520 9.3 PIE Registers The PIE registers contain the individual enable bits for the peripheral interrupts. Due to the number of periph- eral interrupt sources, there are two Peripheral Interrupt Enable registers (PIE1 and PIE2). When IPEN = 0, the PEIE bit must be set to enable any of these peripheral interrupts ...

Page 101

... Disabled bit 1 TMR3IE: TMR3 Overflow Interrupt Enable bit 1 = Enabled 0 = Disabled bit 0 CCP2IE: CCP2 Interrupt Enable bit 1 = Enabled 0 = Disabled © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 R/W-0 EEIE BCLIE HLVDIE U = Unimplemented bit, read as ‘0’ ‘0’ = Bit is cleared R/W-0 R/W-0 ...

Page 102

... PIC18F2420/2520/4420/4520 9.4 IPR Registers The IPR registers contain the individual priority bits for the peripheral interrupts. Due to the number of periph- eral interrupt sources, there are two Peripheral Interrupt Priority registers (IPR1 and IPR2). Using the priority bits requires that the Interrupt Priority Enable (IPEN) bit be set ...

Page 103

... TMR3IP: TMR3 Overflow Interrupt Priority bit 1 = High priority 0 = Low priority bit 0 CCP2IP: CCP2 Interrupt Priority bit 1 = High priority 0 = Low priority © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-1 R/W-1 R/W-1 EEIP BCLIP HLVDIP U = Unimplemented bit, read as ‘0’ ‘0’ = Bit is cleared ...

Page 104

... PIC18F2420/2520/4420/4520 9.5 RCON Register The RCON register contains flag bits which are used to determine the cause of the last Reset or wake-up from Idle or Sleep modes. RCON also contains the IPEN bit which enables interrupt priorities. REGISTER 9-10: RCON: RESET CONTROL REGISTER (1) R/W-0 ...

Page 105

... BSR_TEMP, BSR MOVF W_TEMP, W MOVFF STATUS_TEMP, STATUS © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 9.7 TMR0 Interrupt In 8-bit mode (which is the default), an overflow in the TMR0 register (FFh → 00h) will set flag bit, TMR0IF. In 16-bit mode, an overflow in the TMR0H:TMR0L regis- ter pair (FFFFh → 0000h) will set TMR0IF. The interrupt can be enabled/disabled by setting/clearing enable bit, TMR0IE (INTCON< ...

Page 106

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 104 © 2008 Microchip Technology Inc. ...

Page 107

... PORTA pin an output (i.e., put the contents of the output latch on the selected pin). © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Reading the PORTA register reads the status of the pins, whereas writing to it, will write to the port latch. The Data Latch (LATA) register is also memory mapped. ...

Page 108

... PIC18F2420/2520/4420/4520 TABLE 10-1: PORTA I/O SUMMARY TRIS Pin Function Setting RA0/AN0 RA0 0 1 AN0 1 RA1/AN1 RA1 0 1 AN1 1 RA2/AN2/ RA2 0 V -/CV REF REF 1 AN2 REF 1 CV REF x RA3/AN3/V + RA3 REF 0 1 AN3 REF 1 RA4/T0CKI/C1OUT RA4 0 1 T0CKI 1 C1OUT 0 RA5/AN4/SS/ RA5 0 HLVDIN/C2OUT ...

Page 109

... Legend: — = unimplemented, read as ‘0’. Shaded cells are not used by PORTA. RA<7:6> and their associated latch and data direction bits are enabled as I/O pins based on oscillator Note 1: configuration; otherwise, they are read as ‘0’. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Bit 5 Bit 4 Bit 3 Bit 2 ...

Page 110

... PIC18F2420/2520/4420/4520 10.2 PORTB, TRISB and LATB Registers PORTB is an 8-bit wide, bidirectional port. The corre- sponding Data Direction register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output (i ...

Page 111

... PBADEN is set and digital inputs when PBADEN is cleared. Alternate assignment for CCP2 when the CCP2MX Configuration bit is ‘0’. Default assignment is RC1. 2: All other pin functions are disabled when ICSP or ICD are enabled. 3: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 I/O I/O Type O DIG LATB< ...

Page 112

... PIC18F2420/2520/4420/4520 TABLE 10-4: SUMMARY OF REGISTERS ASSOCIATED WITH PORTB Name Bit 7 Bit 6 PORTB RB7 RB6 LATB PORTB Data Latch Register (Read and Write to Data Latch) TRISB PORTB Data Direction Register INTCON GIE/GIEH PEIE/GIEL TMR0IE INTCON2 RBPU INTEDG0 INTEDG1 INTEDG2 INTCON3 INT2IP INT1IP ADCON1 — ...

Page 113

... TRIS bit to make a pin an input. The user should refer to the corresponding peripheral section for additional information. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 On a Power-on Reset, these pins are Note: configured as digital inputs. The contents of the TRISC register are affected by peripheral overrides ...

Page 114

... PIC18F2420/2520/4420/4520 TABLE 10-5: PORTC I/O SUMMARY TRIS Pin Function Setting RC0/T1OSO/ RC0 0 T13CKI 1 T1OSO x T13CKI 1 RC1/T1OSI/CCP2 RC1 0 1 T1OSI x (1) CCP2 0 1 RC2/CCP1/P1A RC2 0 1 CCP1 0 1 (2) P1A 0 RC3/SCK/SCL RC3 0 1 SCK 0 1 SCL 0 1 RC4/SDI/SDA RC4 0 1 SDI 1 SDA 1 1 RC5/SDO ...

Page 115

... SUMMARY OF REGISTERS ASSOCIATED WITH PORTC Name Bit 7 Bit 6 PORTC RC7 RC6 LATC PORTC Data Latch Register (Read and Write to Data Latch) TRISC PORTC Data Direction Register © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Bit 5 Bit 4 Bit 3 Bit 2 RC5 RC4 RC3 RC2 Reset Bit 1 Bit 0 ...

Page 116

... PIC18F2420/2520/4420/4520 10.4 PORTD, TRISD and LATD Registers PORTD is only available on 40/44-pin Note: devices. PORTD is an 8-bit wide, bidirectional port. The corre- sponding Data Direction register is TRISD. Setting a TRISD bit (= 1) will make the corresponding PORTD pin an input (i.e., put the corresponding output driver in a high-impedance mode) ...

Page 117

... P1D 0 DIG = Digital level output; TTL = TTL input buffer Schmitt Trigger input buffer Don’t care Legend: (TRIS bit does not affect port direction or is overridden for this option). © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 I/O I/O Type O DIG LATD<0> data output. ...

Page 118

... PIC18F2420/2520/4420/4520 TABLE 10-8: SUMMARY OF REGISTERS ASSOCIATED WITH PORTD Name Bit 7 Bit 6 PORTD RD7 RD6 LATD PORTD Data Latch Register (Read and Write to Data Latch) TRISD PORTD Data Direction Register (1) TRISE IBF OBF (1) (1) CCP1CON P1M1 P1M0 Legend: — = unimplemented, read as ‘0’. Shaded cells are not used by PORTD. ...

Page 119

... PORTE, TRISE and LATE Registers Depending on the particular PIC18F2420/2520/4420/ 4520 device selected, PORTE is implemented in two different ways. For 40/44-pin devices, PORTE is a 4-bit wide port. Three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/ AN7) are individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers. When selected as an analog input, these pins will read as ‘ ...

Page 120

... PIC18F2420/2520/4420/4520 REGISTER 10-1: TRISE REGISTER (40/44-PIN DEVICES ONLY) R-0 R-0 R/W-0 IBF OBF IBOV bit 7 Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 IBF: Input Buffer Full Status bit word has been received and waiting to be read by the CPU ...

Page 121

... Implemented only when Master Clear functionality is disabled (MCLRE Configuration bit = 0). Note 1: RE3 is the only PORTE bit implemented on both 28-pin and 40/44-pin devices. All other bits are 2: implemented only when PORTE is implemented (i.e., 40/44-pin devices). © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 I/O I/O Type O DIG LATE< ...

Page 122

... PIC18F2420/2520/4420/4520 10.6 Parallel Slave Port The Parallel Slave Port is only available on Note: 40/44-pin devices. In addition to its function as a general I/O port, PORTD can also operate as an 8-bit wide Parallel Slave Port (PSP) or microprocessor port. PSP operation is con- trolled by the 4 upper bits of the TRISE register (Register 10-1) ...

Page 123

... GIE/GIEH PEIE/GIEL TMR0IF PIR1 PSPIF ADIF PIE1 PSPIE ADIE IPR1 PSPIP ADIP ADCON1 — — Legend: — = unimplemented, read as ‘0’. Shaded cells are not used by the Parallel Slave Port. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Bit 5 Bit 4 Bit 3 Bit 2 RD5 ...

Page 124

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 122 © 2008 Microchip Technology Inc. ...

Page 125

... Prescale value 000 = 1:2 Prescale value © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 The T0CON register (Register 11-1) controls all aspects of the module’s operation, including the prescale selection both readable and writable. A simplified block diagram of the Timer0 module in 8-bit mode is shown in Figure 11-1 ...

Page 126

... PIC18F2420/2520/4420/4520 11.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 11.3 “Prescaler”). If the TMR0 register is written to, the increment is inhibited for the following two instruction cycles ...

Page 127

... Legend: Shaded cells are not used by Timer0. PORTA<7:6> and their direction bits are individually configured as port pins based on various primary Note 1: oscillator modes. When disabled, these bits read as ‘0’. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 11.3.1 SWITCHING PRESCALER ASSIGNMENT The prescaler assignment is fully under software control and can be changed “ ...

Page 128

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 126 © 2008 Microchip Technology Inc. ...

Page 129

... TMR1ON: Timer1 On bit 1 = Enables Timer1 0 = Stops Timer1 © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 A simplified block diagram of the Timer1 module is shown in Figure 12-1. A block diagram of the module’s operation in Read/Write mode is shown in Figure 12-2. The module incorporates its own low-power oscillator to provide an additional clocking option ...

Page 130

... PIC18F2420/2520/4420/4520 12.1 Timer1 Operation Timer1 can operate in one of these modes: • Timer • Synchronous Counter • Asynchronous Counter The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>). When TMR1CS is cleared (= 0), Timer1 increments on every internal instruction FIGURE 12-1: TIMER1 BLOCK DIAGRAM ...

Page 131

... XTAL 32.768 kHz T1OSO See the Notes with Table 12-1 for additional Note: information about capacitor selection. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 TABLE 12-1: CAPACITOR SELECTION FOR THE TIMER OSCILLATOR Osc Type Freq LP 32 kHz Note 1: Microchip suggests these values as a starting point in validating the oscillator circuit ...

Page 132

... PIC18F2420/2520/4420/4520 12.3.3 TIMER1 OSCILLATOR LAYOUT CONSIDERATIONS The Timer1 oscillator circuit draws very little power during operation. Due to the low-power nature of the oscillator, it may also be sensitive to rapidly changing signals in close proximity. The oscillator circuit, shown in Figure 12-3, should be located as close as possible to the microcontroller. ...

Page 133

... RETURN CLRF hours RETURN © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 monitoring TMR1L within the interrupt routine until it increments, and then updating the TMR1H:TMR1L register pair while the clock is low, or one-half of the period of the clock source. Assuming that Timer1 is being used as a Real-Time Clock, the clock source is a 32.768 kHz crystal oscillator ...

Page 134

... PIC18F2420/2520/4420/4520 TABLE 12-2: REGISTERS ASSOCIATED WITH TIMER1 AS A TIMER/COUNTER Name Bit 7 Bit 6 INTCON GIE/GIEH PEIE/GIEL TMR0IE (1) PIR1 PSPIF ADIF (1) PIE1 PSPIE ADIE (1) IPR1 PSPIP ADIP TMR1L Timer1 Register Low Byte TMR1H Timer1 Register High Byte T1CON RD16 T1RUN T1CKPS1 T1CKPS0 T1OSCEN T1SYNC Legend: Shaded cells are not used by the Timer1 module. These bits are unimplemented on 28-pin devices ...

Page 135

... Timer2 is off bit 1-0 T2CKPS<1:0>: Timer2 Clock Prescale Select bits 00 = Prescaler Prescaler Prescaler is 16 © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 13.1 Timer2 Operation In normal operation, TMR2 is incremented from 00h on each clock (F /4). A 4-bit counter/prescaler on the OSC clock input gives direct input, divide-by-4 and divide-by- 16 prescale options ...

Page 136

... PIC18F2420/2520/4420/4520 13.2 Timer2 Interrupt Timer2 also can generate an optional device interrupt. The Timer2 output signal (TMR2 to PR2 match) pro- vides 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< ...

Page 137

... TMR3ON: Timer3 On bit 1 = Enables Timer3 0 = Stops Timer3 © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 A simplified block diagram of the Timer3 module is shown in Figure 14-1. A block diagram of the module’s operation in Read/Write mode is shown in Figure 14-2. The Timer3 module is controlled through the T3CON register (Register 14-1) ...

Page 138

... PIC18F2420/2520/4420/4520 14.1 Timer3 Operation Timer3 can operate in one of three modes: • Timer • Synchronous Counter • Asynchronous Counter FIGURE 14-1: TIMER3 BLOCK DIAGRAM Timer1 Oscillator T1OSO/T13CKI T1OSI T1OSCEN (1) T3CKPS<1:0> T3SYNC TMR3ON CCP1/CCP2 Special Event Trigger CCP1/CCP2 Select from T3CON<6,3> Note 1: When enable bit, T1OSCEN, is cleared, the inverter and feedback resistor are turned off to eliminate power drain. ...

Page 139

... RD16 T3CCP2 T3CKPS1 T3CKPS0 T3CCP1 Legend: — = unimplemented, read as ‘0’. Shaded cells are not used by the Timer3 module. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 14.4 Timer3 Interrupt The TMR3 register pair (TMR3H:TMR3L) increments from 0000h to FFFFh and overflows to 0000h. The Timer3 interrupt, if enabled, is generated on overflow and is latched in interrupt flag bit, TMR3IF (PIR2< ...

Page 140

... PIC18F2420/2520/4420/4520 NOTES: DS39631E-page 138 © 2008 Microchip Technology Inc. ...

Page 141

... CAPTURE/COMPARE/PWM (CCP) MODULES PIC18F2420/2520/4420/4520 devices all have two CCP (Capture/Compare/PWM) modules. Each module contains 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. In 28-pin devices, the two standard CCP modules (CCP1 and CCP2) operate as described in this chapter ...

Page 142

... PIC18F2420/2520/4420/4520 15.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. 15.1.1 ...

Page 143

... Q1:Q4 CCP2CON<3:0> CCP2 pin Prescaler ÷ © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 15.2.3 SOFTWARE INTERRUPT When the Capture mode is changed, a false capture interrupt may be generated. The user should keep the CCPxIE interrupt enable bit clear to avoid false inter- rupts. The interrupt flag bit, CCPxIF, should also be cleared following any such change in operating mode ...

Page 144

... PIC18F2420/2520/4420/4520 15.3 Compare Mode 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 CCPx pin can be: • driven high • driven low • toggled (high-to-low or low-to-high) • remain unchanged (that is, reflects the state of the ...

Page 145

... CCP2CON — — Legend: — = unimplemented, read as ‘0’. Shaded cells are not used by Capture/Compare, Timer1 or Timer3. These bits are unimplemented on 28-pin devices; always maintain these bits clear. Note 1: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Bit 5 Bit 4 Bit 3 Bit 2 INT0IE RBIE TMR0IF — ...

Page 146

... PIC18F2420/2520/4420/4520 15.4 PWM Mode In Pulse-Width Modulation (PWM) mode, the CCPx pin produces 10-bit resolution PWM output. Since the CCP2 pin is multiplexed with a PORTB or PORTC data latch, the appropriate TRIS bit must be cleared to make the CCP2 pin an output. Clearing the CCP2CON register will force ...

Page 147

... CCP1 in 28-pin devices. The operation of this feature is discussed in detail in Section 16.4.7 “Enhanced PWM Auto-Shutdown”. Auto-shutdown features are not available for CCP2. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 EQUATION 15-3: PWM Resolution (max) If the PWM duty cycle value is longer than Note: the PWM period, the CCPx pin will not be cleared ...

Page 148

... PIC18F2420/2520/4420/4520 TABLE 15-5: REGISTERS ASSOCIATED WITH PWM AND TIMER2 Name Bit 7 Bit 6 INTCON GIE/GIEH PEIE/GIEL RCON IPEN SBOREN (1) PIR1 PSPIF ADIF (1) PIE1 PSPIE ADIE (1) IPR1 PSPIP ADIP TRISB PORTB Data Direction Register TRISC PORTC Data Direction Register TMR2 Timer2 Register PR2 ...

Page 149

... PWM functions of the ECCP module are the same as described for the standard CCP module. The control register for the Enhanced CCP module is shown in Register 16-2. It differs from the CCPxCON registers in PIC18F2420/2520 devices in that the two Most Significant bits are implemented to control PWM functionality. R/W-0 ...

Page 150

... PIC18F2420/2520/4420/4520 In addition to the expanded range of modes available through the CCP1CON register and ECCP1AS register, the ECCP module has an additional register associated with Enhanced PWM operation and auto-shutdown features. It is: • PWM1CON (PWM Dead-Band Delay) 16.1 ECCP Outputs and Configuration The Enhanced CCP module may have up to four PWM outputs, depending on the selected operating mode ...

Page 151

... PR2 Note: The 8-bit TMR2 register is concatenated with the 2-bit internal Q clock bits of the prescaler, to create the 10-bit time base. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 16.4.1 PWM PERIOD The PWM period is specified by writing to the PR2 register. The PWM period can be calculated using the following equation ...

Page 152

... PIC18F2420/2520/4420/4520 16.4.2 PWM DUTY CYCLE The PWM duty cycle is specified by writing to the CCPR1L register and to the CCP1CON<5:4> bits 10-bit resolution is available. The CCPR1L contains the eight MSbs and the CCP1CON<5:4> bits contain the two LSbs. This 10-bit value is represented by CCPR1L:CCP1CON<5:4>. The PWM duty cycle is calculated by the following equation ...

Page 153

... Duty Cycle = T * (CCPR1L<7:0>:CCP1CON<5:4>) * (TMR2 Prescale Value) OSC • Delay = (PWM1CON<6:0>) OSC Dead-band delay is programmed using the PWM1CON register (see Section 16.4.6 “Programmable Note 1: Dead-Band Delay”). © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 0 Duty Cycle Period (1) Delay Delay 0 Duty Cycle ...

Page 154

... PIC18F2420/2520/4420/4520 16.4.4 HALF-BRIDGE MODE In the Half-Bridge Output mode, two pins are used as outputs to drive push-pull loads. The PWM output signal is output on the P1A pin, while the complementary PWM output signal is output on the P1B pin (Figure 16-4). This mode can be used for half-bridge applications, as shown ...

Page 155

... Note 1: At this time, the TMR2 register is equal to the PR2 register. 2: Output signal is shown as active-high. Note © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 P1A, P1B, P1C and P1D outputs are multiplexed with the PORTC<2> and PORTD<7:5> data latches. The TRISC<2> and TRISD<7:5> bits must be cleared to make the P1A, P1B, P1C and P1D pins outputs ...

Page 156

... PIC18F2420/2520/4420/4520 FIGURE 16-7: EXAMPLE OF FULL-BRIDGE OUTPUT MODE APPLICATION PIC18F4X2X P1A P1B P1C P1D 16.4.5.1 Direction Change in Full-Bridge Mode In the Full-Bridge Output mode, the P1M1 bit in the CCP1CON register allows user to control the forward/ reverse direction. When the application firmware changes this direction control bit, the module will assume the new direction on the next PWM cycle ...

Page 157

... Note 1: All signals are shown as active-high the turn-on delay of power switch, QC, and its driver the turn-off delay of power switch, QD, and its driver. OFF © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 (1) Period DC (Note 2) , depending on the Timer2 prescaler value. The modulated P1B and P1D signals Forward Period t1 ...

Page 158

... PIC18F2420/2520/4420/4520 16.4.6 PROGRAMMABLE DEAD-BAND DELAY Programmable dead-band delay is not Note: implemented in 28-pin devices with standard CCP modules. In half-bridge applications where all power switches are modulated at the PWM frequency at all times, the power switches normally require more time to turn off than to turn on. If both the upper and lower power ...

Page 159

... PSSBD<1:0>: Pins B and D Shutdown State Control bits 1x = Pins B and D tri-state 01 = Drive Pins B and D to ‘1’ Drive Pins B and D to ‘0’ Reserved on 28-pin devices; maintain these bits clear. Note 1: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 R/W-0 ECCPAS0 PSSAC1 PSSAC0 U = Unimplemented bit, read as ‘ ...

Page 160

... PIC18F2420/2520/4420/4520 16.4.7.1 Auto-Shutdown and Automatic Restart The auto-shutdown feature can be configured to allow automatic restarts of the module following a shutdown event. This is enabled by setting the PRSEN bit of the PWM1CON register (PWM1CON<7>). In Shutdown mode with PRSEN = 1 (Figure 16-10), the ECCPASE bit will remain set for as long as the cause of the shutdown continues ...

Page 161

... Enable the CCP1/P1A, P1B, P1C and/or P1D pin outputs by clearing the respective TRIS bits. • Clear the ECCPASE bit (ECCP1AS<7>). © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 16.4.10 OPERATION IN POWER-MANAGED MODES In Sleep mode, all clock sources are disabled. Timer2 will not increment and the state of the module will not change ...

Page 162

... PIC18F2420/2520/4420/4520 TABLE 16-3: REGISTERS ASSOCIATED WITH ECCP MODULE AND TIMER1 TO TIMER3 Name Bit 7 Bit 6 INTCON GIE/GIEH PEIE/GIEL RCON IPEN SBOREN PIR1 PSPIF ADIF PIE1 PSPIE ADIE IPR1 PSPIP ADIP PIR2 OSCFIF CMIF PIE2 OSCFIE CMIE IPR2 OSCFIP CMIP TRISB PORTB Data Direction Register ...

Page 163

... MSSP 2 module is operated in SPI mode. Additional details are provided under the individual sections. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.3 SPI Mode The SPI mode allows 8 bits of data to be synchronously transmitted and received simultaneously. All four modes of ...

Page 164

... PIC18F2420/2520/4420/4520 17.3.1 REGISTERS The MSSP module has four registers for SPI mode operation. These are: • MSSP Control Register 1 (SSPCON1) • MSSP Status Register (SSPSTAT) • Serial Receive/Transmit Buffer Register (SSPBUF) • MSSP Shift Register (SSPSR) – Not directly accessible SSPCON1 and SSPSTAT are the control and status registers in SPI mode operation ...

Page 165

... In Master mode, the overflow bit is not set since each new reception (and transmission) is initiated by Note 1: writing to the SSPBUF register. When enabled, these pins must be properly configured as input or output. 2: Bit combinations not specifically listed here are either reserved or implemented © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 R/W-0 R/W-0 (2) (3) CKP SSPM3 SSPM2 U = Unimplemented bit, read as ‘ ...

Page 166

... PIC18F2420/2520/4420/4520 17.3.2 OPERATION When initializing the SPI, several options need to be specified. This is done by programming the appropriate control bits (SSPCON1<5:0> and SSPSTAT<7:6>). These control bits allow the following to be specified: • Master mode (SCK is the clock output) • Slave mode (SCK is the clock input) • ...

Page 167

... Shift Register (SSPSR) LSb MSb PROCESSOR 1 © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.3.4 TYPICAL CONNECTION Figure 17-2 shows a typical connection between two microcontrollers. The master controller (Processor 1) initiates the data transfer by sending the SCK signal. Data is shifted out of both shift registers on their pro- grammed clock edge and latched on the opposite edge of the clock ...

Page 168

... PIC18F2420/2520/4420/4520 17.3.5 MASTER MODE The master can initiate the data transfer at any time because it controls the SCK. The master determines when the slave (Processor 2, Figure 17- broadcast data by the software protocol. In Master mode, the data is transmitted/received as soon as the SSPBUF register is written to. If the SPI is only going to receive, the SDO output could be dis- abled (programmed as an input) ...

Page 169

... Flag SSPSR to SSPBUF © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 must be high. When the SS pin is low, transmission and reception are enabled and the SDO pin is driven. When the SS pin goes high, the SDO pin is no longer driven, even if in the middle of a transmitted byte and becomes a floating output ...

Page 170

... PIC18F2420/2520/4420/4520 FIGURE 17-5: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = SS Optional SCK (CKP = 0 CKE = 0) SCK (CKP = 1 CKE = 0) Write to SSPBUF SDO bit 7 SDI (SMP = 0) bit 7 Input Sample (SMP = 0) SSPIF Interrupt Flag SSPSR to SSPBUF FIGURE 17-6: SPI MODE WAVEFORM (SLAVE MODE WITH CKE = 1) ...

Page 171

... PORTA<7:6> and their direction bits are individually configured as port pins based on various primary 2: oscillator modes. When disabled, these bits read as ‘0’. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.3.9 EFFECTS OF A RESET A Reset disables the MSSP module and terminates the current transfer. ...

Page 172

... PIC18F2420/2520/4420/4520 2 17 Mode 2 The MSSP module 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 modes ...

Page 173

... This bit holds the R/W bit information following the last address match. This bit is only valid from the 2: address match to the next Start bit, Stop bit or not ACK bit. ORing this bit with SEN, RSEN, PEN, RCEN or ACKEN will indicate if the MSSP is in Active mode. 3: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 2 C™ MODE) R-0 R-0 R-0 ...

Page 174

... PIC18F2420/2520/4420/4520 REGISTER 17-4: SSPCON1: MSSP CONTROL REGISTER 1 (I R/W-0 R/W-0 R/W-0 WCOL SSPOV SSPEN bit 7 Legend Readable bit W = Writable bit -n = Value at POR ‘1’ = Bit is set bit 7 WCOL: Write Collision Detect bit In Master Transmit mode write to the SSPBUF register was attempted while the I ...

Page 175

... For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I Note 1: set (no spooling) and the SSPBUF may not be written (or writes to the SSPBUF are disabled). Value that will be transmitted when the user initiates an Acknowledge sequence at the end of a receive. 2: © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 2 C™ MODE) R/W-0 R/W-0 (2) ...

Page 176

... PIC18F2420/2520/4420/4520 17.4.2 OPERATION The MSSP module functions are enabled by setting the MSSP Enable bit, SSPEN (SSPCON1<5>). The SSPCON1 register allows control of the I operation. Four mode selection bits (SSPCON1<3:0>) 2 allow one of the following I C modes to be selected: 2 • Master mode, clock = (F /4) x (SSPADD + 1) ...

Page 177

... The clock must be released by setting bit, CKP (SSPCON<4>). See Section 17.4.4 “Clock Stretching” for more details. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.4.3.3 Transmission When the R/W bit of the incoming address byte is set and an address match occurs, the R/W bit of the SSPSTAT register is set ...

Page 178

... PIC18F2420/2520/4420/4520 2 FIGURE 17-8: I C™ SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 7-BIT ADDRESSING) DS39631E-page 176 © 2008 Microchip Technology Inc. ...

Page 179

... FIGURE 17-9: I C™ SLAVE MODE TIMING (TRANSMISSION, 7-BIT ADDRESSING) © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 DS39631E-page 177 ...

Page 180

... PIC18F2420/2520/4420/4520 2 FIGURE 17-10: I C™ SLAVE MODE TIMING WITH SEN = 0 (RECEPTION, 10-BIT ADDRESSING) DS39631E-page 178 © 2008 Microchip Technology Inc. ...

Page 181

... FIGURE 17-11: I C™ SLAVE MODE TIMING (TRANSMISSION, 10-BIT ADDRESSING) © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 DS39631E-page 179 ...

Page 182

... PIC18F2420/2520/4420/4520 17.4.4 CLOCK STRETCHING Both 7-Bit and 10-Bit Slave modes implement automatic clock stretching during a transmit sequence. The SEN bit (SSPCON2<0>) allows clock stretching to be enabled during receives. Setting SEN will cause the SCL pin to be held low at the end of each data receive sequence ...

Page 183

... DX SCL CKP WR SSPCONx © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 already asserted the SCL line. The SCL output will remain low until the CKP bit is set and all other 2 devices on the I C bus have deasserted SCL. This ensures that a write to the CKP bit will not violate the minimum high time requirement for SCL (see Figure 17-12) ...

Page 184

... PIC18F2420/2520/4420/4520 2 FIGURE 17-13: I C™ SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 7-BIT ADDRESSING) DS39631E-page 182 © 2008 Microchip Technology Inc. ...

Page 185

... FIGURE 17-14: I C™ SLAVE MODE TIMING WITH SEN = 1 (RECEPTION, 10-BIT ADDRESSING) © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 DS39631E-page 183 ...

Page 186

... PIC18F2420/2520/4420/4520 17.4.5 GENERAL CALL ADDRESS SUPPORT 2 The addressing procedure for the I C 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. When this address is used, all devices should, in theory, respond with an Acknowledge ...

Page 187

... FIGURE 17-16: MSSP BLOCK DIAGRAM (I SDA SDA In SCL SCL In Bus Collision © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 The MSSP module, when configured in Note Master mode, does not allow queueing of events. For instance, the user is not allowed to initiate a Start condition and immediately write the SSPBUF register to initiate transmission before the Start condi- tion is complete ...

Page 188

... PIC18F2420/2520/4420/4520 2 17.4.6 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 I not be released ...

Page 189

... Note 1: 100 kHz) in all details, but may be used with care where higher rates are required by the application. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 Once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ACK), the internal clock will automatically stop counting and the SCL pin will remain in its last state ...

Page 190

... PIC18F2420/2520/4420/4520 17.4.7.1 Clock Arbitration Clock arbitration occurs when the master, during any receive, transmit or Repeated Start/Stop condition, deasserts the SCL pin (SCL allowed to float high). When the SCL pin is allowed to float high, the Baud Rate Generator (BRG) is suspended from counting until the SCL pin is actually sampled high. When the ...

Page 191

... FIRST START BIT TIMING Write to SEN bit occurs here SDA SCL © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 If, at the beginning of the Start condition, Note: the SDA and SCL pins are already sam- pled low during the Start condition, the SCL line is sampled low before the SDA ...

Page 192

... PIC18F2420/2520/4420/4520 2 17.4 MASTER MODE REPEATED START CONDITION TIMING A Repeated Start condition occurs when the RSEN bit (SSPCON2<1>) is programmed high and the I module is in the Idle state. When the RSEN bit is set, the SCL pin is asserted low. When the SCL pin is sam- pled low, the Baud Rate Generator is loaded with the contents of SSPADD< ...

Page 193

... WCOL is set and the contents of the buffer are unchanged (the write doesn’t occur). WCOL must be cleared in software. © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.4.10.3 ACKSTAT Status Flag In Transmit mode, the ACKSTAT bit (SSPCON2<6>) is cleared when the slave has sent an Acknowledge (ACK = 0) and is set when the slave does not Acknowl- edge (ACK = 1) ...

Page 194

... PIC18F2420/2520/4420/4520 2 FIGURE 17-21 MASTER MODE WAVEFORM (TRANSMISSION 10-BIT ADDRESSING) DS39631E-page 192 © 2008 Microchip Technology Inc. ...

Page 195

... FIGURE 17-22 MASTER MODE WAVEFORM (RECEPTION, 7-BIT ADDRESSING) © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 DS39631E-page 193 ...

Page 196

... PIC18F2420/2520/4420/4520 17.4.12 ACKNOWLEDGE SEQUENCE TIMING An Acknowledge sequence is enabled by setting the Acknowledge Sequence Enable (SSPCON2<4>). When this bit is set, the SCL pin is pulled low and the contents of the Acknowledge data bit are presented on the SDA pin. If the user wishes to gen- erate an Acknowledge, then the ACKDT bit should be cleared ...

Page 197

... BUS COLLISION TIMING FOR TRANSMIT AND ACKNOWLEDGE Data changes while SCL = 0 SDA SCL BCLIF © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 17.4.17 MULTI -MASTER COMMUNICATION, BUS COLLISION AND BUS ARBITRATION Multi-Master mode support is achieved by bus arbitra- tion. When the master outputs address/data bits onto the SDA pin, arbitration takes place when the master outputs a ‘ ...

Page 198

... PIC18F2420/2520/4420/4520 17.4.17.1 Bus Collision During a Start Condition During a Start condition, a bus collision occurs if: a) SDA or SCL is sampled low at the beginning of the Start condition (Figure 17-26). b) SCL is sampled low before SDA is asserted low (Figure 17-27). During a Start condition, both the SDA and the SCL pins are monitored ...

Page 199

... BRG RESET DUE TO SDA ARBITRATION DURING START CONDITION Less than T SDA pulled low by other master. SDA Reset BRG and assert SDA. SCL SEN BCLIF S SSPIF © 2008 Microchip Technology Inc. PIC18F2420/2520/4420/4520 SDA = 0, SCL = BRG BRG SCL = 0 before SDA = 0, bus collision occurs. Set BCLIF. SDA = 0, SCL = 1 Set S Set SSPIF ...

Page 200

... PIC18F2420/2520/4420/4520 17.4.17.2 Bus Collision During a Repeated Start Condition During a Repeated Start condition, a bus collision occurs if low level is sampled on SDA when SCL goes from low level to high level. b) SCL goes low before SDA is asserted low, indicating that another master is attempting to transmit a data ‘1’. ...

Related keywords