图片仅供参考

详细数据请看参考数据手册

Datasheet下载
  • 型号: C8051F020-GQR
  • 制造商: Silicon Laboratories
  • 库位|库存: xxxx|xxxx
  • 要求:
数量阶梯 香港交货 国内含税
+xxxx $xxxx ¥xxxx

查看当月历史价格

查看今年历史价格

C8051F020-GQR产品简介:

ICGOO电子元器件商城为您提供C8051F020-GQR由Silicon Laboratories设计生产,在icgoo商城现货销售,并且可以通过原厂、代理商等渠道进行代购。 C8051F020-GQR价格参考。Silicon LaboratoriesC8051F020-GQR封装/规格:嵌入式 - 微控制器, 8051 C8051F02x Microcontroller IC 8-Bit 25MHz 64KB (64K x 8) FLASH 100-TQFP (14x14)。您可以下载C8051F020-GQR参考资料、Datasheet数据手册功能说明书,资料中有C8051F020-GQR 详细功能的应用电路图电压和使用方法及教程。

产品参数 图文手册 常见问题
参数 数值
A/D位大小

12 bit

产品目录

集成电路 (IC)半导体

描述

IC 8051 MCU 64K FLASH 100TQFP8位微控制器 -MCU 64KB 12ADC 100P MCU Tape and Reel

EEPROM容量

-

产品分类

嵌入式 - 微控制器

I/O数

64

品牌

Silicon LabsSilicon Laboratories Inc

产品手册

点击此处下载产品Datasheet

产品图片

rohs

符合RoHS无铅 / 符合限制有害物质指令(RoHS)规范要求

产品系列

嵌入式处理器和控制器,微控制器 - MCU,8位微控制器 -MCU,Silicon Labs C8051F020-GQRC8051F02x

数据手册

点击此处下载产品Datasheet点击此处下载产品Datasheet

产品型号

C8051F020-GQRC8051F020-GQR

RAM容量

4.25K x 8

产品培训模块

http://www.digikey.cn/PTM/IndividualPTM.page?site=cn&lang=zhs&ptm=25245

产品种类

8位微控制器 -MCU

供应商器件封装

100-TQFP(14x14)

包装

带卷 (TR)

单位重量

638.060 mg

可用A/D通道

8

可编程输入/输出端数量

64

商标

Silicon Labs

处理器系列

C8051

外设

欠压检测/复位,POR,PWM,温度传感器,WDT

安装风格

SMD/SMT

定时器数量

5 Timer

封装

Reel

封装/外壳

100-TQFP

封装/箱体

TQFP-100

工作温度

-40°C ~ 85°C

工作电源电压

2.7 V to 3.6 V

工厂包装数量

250

振荡器类型

内部

接口类型

I2C, SMBus, SPI, UART

数据RAM大小

4.25 kB

数据ROM大小

64 kB

数据Rom类型

Flash

数据总线宽度

8 bit

数据转换器

A/D 8x8b,8x12b; D/A 2x12b

最大工作温度

+ 85 C

最大时钟频率

25 MHz

最小工作温度

- 40 C

标准包装

250

核心

8051

核心处理器

8051

核心尺寸

8-位

片上ADC

Yes

片上DAC

With DAC

电压-电源(Vcc/Vdd)

2.7 V ~ 3.6 V

电源电压-最大

3.6 V

电源电压-最小

2.7 V

程序存储器大小

64 kB

程序存储器类型

Flash闪存

程序存储容量

64KB(64K x 8)

系列

C8051F020

输入/输出端数量

64 I/O

连接性

EBI/EMI, SMBus (2 线/I²C), SPI, UART/USART

速度

25MHz

配用

/product-detail/zh/C8051F020DK/336-1200-ND/819500

推荐商品

型号:S9S08SG16E1CTLR

品牌:NXP USA Inc.

产品名称:集成电路(IC)

获取报价

型号:MSP430F47126IPZR

品牌:Texas Instruments

产品名称:集成电路(IC)

获取报价

型号:MC908QY2AMDWER

品牌:NXP USA Inc.

产品名称:集成电路(IC)

获取报价

型号:PIC18F87J90-I/PT

品牌:Microchip Technology

产品名称:集成电路(IC)

获取报价

型号:STM32F100VET6

品牌:STMicroelectronics

产品名称:集成电路(IC)

获取报价

型号:TSC87251G2D-L16CB

品牌:Microchip Technology

产品名称:集成电路(IC)

获取报价

型号:ATXMEGA32A4U-CU

品牌:Microchip Technology

产品名称:集成电路(IC)

获取报价

型号:PIC16LC74B-04I/PQ

品牌:Microchip Technology

产品名称:集成电路(IC)

获取报价

样品试用

万种样品免费试用

去申请
C8051F020-GQR 相关产品

ML610Q431-NNNTCZ0AGL

品牌:Rohm Semiconductor

价格:

DSPIC30F3013-20I/SO

品牌:Microchip Technology

价格:

DS89C450-MNL+

品牌:Maxim Integrated

价格:

HD64F3687DV

品牌:Renesas Electronics America

价格:

MSP430F438IPNR

品牌:Texas Instruments

价格:¥35.88-¥60.13

MSP430F249TPMR

品牌:Texas Instruments

价格:

MC9S08AC60CFUER

品牌:NXP USA Inc.

价格:

PIC32MX575F512LT-80V/PT

品牌:Microchip Technology

价格:

PDF Datasheet 数据手册内容提取

C8051F020/1/2/3 8K ISP FLASH MCU Family ANALOG PERIPHERALS HIGH SPEED 8051 μC CORE - SAR ADC - Pipelined Instruction Architecture; Executes 70% of • 12-Bit (C8051F020/1) Instruction Set in 1 or 2 System Clocks • 10-Bit (C8051F022/3) - Up to 25 MIPS Throughput with 25 MHz Clock • ± 1 LSB INL - 22 Vectored Interrupt Sources • Programmable Throughput up to 100 ksps MEMORY • Up to 8 External Inputs; Programmable as Single-Ended or - 4352 Bytes Internal Data RAM (4k + 256) Differential - 64k Bytes FLASH; In-System programmable in 512-byte • Programmable Amplifier Gain: 16, 8, 4, 2, 1, 0.5 Sectors • Data-Dependent Windowed Interrupt Generator - External 64k Byte Data Memory Interface (programma- • Built-in Temperature Sensor (± 3°C) ble multiplexed or non-multiplexed modes) - 8-bit ADC DIGITAL PERIPHERALS • Programmable Throughput up to 500 ksps - 8 Byte-Wide Port I/O (C8051F020/2); 5V tolerant • 8 External Inputs - 4 Byte-Wide Port I/O (C8051F021/3); 5V tolerant • Programmable Amplifier Gain: 4, 2, 1, 0.5 - Hardware SMBus™ (I2C™ Compatible), SPI™, and - Two 12-bit DACs Two UART Serial Ports Available Concurrently • Can Synchronize Outputs to Timers for Jitter-Free Wave- - Programmable 16-bit Counter/Timer Array with form Generation 5 Capture/Compare Modules - Two Analog Comparators - 5 General Purpose 16-bit Counter/Timers - Voltage Reference - Dedicated Watch-Dog Timer; Bi-directional Reset Pin - Precision VDD Monitor/Brown-Out Detector CLOCK SOURCES ON-CHIP JTAG DEBUG & BOUNDARY SCAN - Internal Programmable Oscillator: 2-to-16 MHz - On-Chip Debug Circuitry Facilitates Full- Speed, Non- - External Oscillator: Crystal, RC, C, or Clock Intrusive In-Circuit/In-System Debugging - Real-Time Clock Mode using Timer 3 or PCA - Provides Breakpoints, Single-Stepping, Watchpoints, SUPPLY VOLTAGE .......................... 2.7V TO 3.6V Stack Monitor; Inspect/Modify Memory and Registers - Typical Operating Current: 10 mA @ 20 MHz - Superior Performance to Emulation Systems Using ICE- - Multiple Power Saving Sleep and Shutdown Modes Chips, Target Pods, and Sockets 100-Pin TQFP and 64-Pin TQFP Packages Available - IEEE1149.1 Compliant Boundary Scan Temperature Range: -40°C to +85°C - Low-Cost, Complete Development Kit ANALOG PERIPHERALS DIGITAL I/O TEMP UART0 Port 0 SENSOR 10/12-bit UART1 AR X B Port 1 MU PGA 100ksps SMBus SS ce A ADC SPI Bus RO erfa Port 2 VREF PCA C y Int Port 3 Timer 0 or m UX 8-bit Timer 1 Me Port 4 12-Bit AM PGA 500AksDpCs Timer 2 ernal Port 5 DAC + + Timer 3 Ext Timer 4 Port 6 - - 12-Bit Port 7 DAC VOLTAGE COMPARATORS 64 pin 100 pin HIGH-SPEED CONTROLLER CORE 8051 CPU 64KB 4352 B JTAG (25MIPS) ISP FLASH SRAM 22 DEBUG CLOCK SANITY INTERRUPTS CIRCUITRY CIRCUIT CONTROL Rev. 1.4 12/03 Copyright © 2003 by Silicon Laboratories C8051F020/1/2/3

C8051F020/1/2/3 Notes 2 Rev. 1.4

C8051F020/1/2/3 TABLE OF CONTENTS 1. SYSTEM OVERVIEW.........................................................................................................17 1.1. CIP-51™ Microcontroller Core ......................................................................................22 1.1.1. Fully 8051 Compatible..........................................................................................22 1.1.2. Improved Throughput............................................................................................22 1.1.3. Additional Features................................................................................................23 1.2. On-Chip Memory............................................................................................................24 1.3. JTAG Debug and Boundary Scan...................................................................................25 1.4. Programmable Digital I/O and Crossbar.........................................................................26 1.5. Programmable Counter Array.........................................................................................27 1.6. Serial Ports.......................................................................................................................27 1.7. 12-Bit Analog to Digital Converter.................................................................................28 1.8. 8-Bit Analog to Digital Converter...................................................................................29 1.9. Comparators and DACs...................................................................................................30 2. ABSOLUTE MAXIMUM RATINGS..................................................................................31 3. GLOBAL DC ELECTRICAL CHARACTERISTICS......................................................32 4. PINOUT AND PACKAGE DEFINITIONS........................................................................33 5. ADC0 (12-BIT ADC, C8051F020/1 ONLY)........................................................................43 5.1. Analog Multiplexer and PGA..........................................................................................43 5.2. ADC Modes of Operation...............................................................................................44 5.2.1. Starting a Conversion.............................................................................................44 5.2.2. Tracking Modes.....................................................................................................45 5.2.3. Settling Time Requirements..................................................................................46 5.3. ADC0 Programmable Window Detector.........................................................................53 6. ADC0 (10-BIT ADC, C8051F022/3 ONLY)........................................................................59 6.1. Analog Multiplexer and PGA..........................................................................................59 6.2. ADC Modes of Operation...............................................................................................60 6.2.1. Starting a Conversion.............................................................................................60 6.2.2. Tracking Modes.....................................................................................................61 6.2.3. Settling Time Requirements..................................................................................62 6.3. ADC0 Programmable Window Detector.........................................................................69 7. ADC1 (8-BIT ADC)...............................................................................................................75 7.1. Analog Multiplexer and PGA..........................................................................................75 7.2. ADC1 Modes of Operation.............................................................................................76 7.2.1. Starting a Conversion.............................................................................................76 7.2.2. Tracking Modes.....................................................................................................76 7.2.3. Settling Time Requirements..................................................................................78 8. DACS, 12-BIT VOLTAGE MODE......................................................................................83 8.1. DAC Output Scheduling..................................................................................................83 8.1.1. Update Output On-Demand...................................................................................84 8.1.2. Update Output Based on Timer Overflow.............................................................84 8.2. DAC Output Scaling/Justification...................................................................................84 9. VOLTAGE REFERENCE (C8051F020/2)..........................................................................91 Rev. 1.4 3

C8051F020/1/2/3 10.VOLTAGE REFERENCE (C8051F021/3)..........................................................................93 11.COMPARATORS..................................................................................................................95 12.CIP-51 MICROCONTROLLER........................................................................................101 12.1.Instruction Set................................................................................................................102 12.1.1.Instruction and CPU Timing................................................................................102 12.1.2.MOVX Instruction and Program Memory...........................................................102 12.2.Memory Organization...................................................................................................107 12.2.1.Program Memory.................................................................................................107 12.2.2.Data Memory.......................................................................................................108 12.2.3.General Purpose Registers...................................................................................108 12.2.4.Bit Addressable Locations...................................................................................108 12.2.5.Stack .................................................................................................................108 12.2.6.Special Function Registers...................................................................................109 12.2.7.Register Descriptions...........................................................................................113 12.3.Interrupt Handler...........................................................................................................116 12.3.1.MCU Interrupt Sources and Vectors...................................................................116 12.3.2.External Interrupts...............................................................................................116 12.3.3.Interrupt Priorities................................................................................................118 12.3.4.Interrupt Latency..................................................................................................118 12.3.5.Interrupt Register Descriptions............................................................................119 12.4.Power Management Modes...........................................................................................125 12.4.1.Idle Mode.............................................................................................................125 12.4.2.Stop Mode............................................................................................................125 13.RESET SOURCES..............................................................................................................127 13.1.Power-on Reset..............................................................................................................128 13.2.Power-fail Reset............................................................................................................128 13.3.External Reset................................................................................................................129 13.4.Software Forced Reset...................................................................................................129 13.5.Missing Clock Detector Reset.......................................................................................129 13.6.Comparator0 Reset........................................................................................................129 13.7.External CNVSTR Pin Reset.........................................................................................129 13.8.Watchdog Timer Reset..................................................................................................129 13.8.1.Enable/Reset WDT..............................................................................................130 13.8.2.Disable WDT.......................................................................................................130 13.8.3.Disable WDT Lockout.........................................................................................130 13.8.4.Setting WDT Interval...........................................................................................130 14.OSCILLATORS...................................................................................................................135 14.1.External Crystal Example..............................................................................................138 14.2.External RC Example....................................................................................................138 14.3.External Capacitor Example..........................................................................................138 15.FLASH MEMORY..............................................................................................................139 15.1.Programming The FLASH Memory.............................................................................139 15.2.Non-volatile Data Storage.............................................................................................140 15.3.Security Options............................................................................................................140 16.EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM.......................145 4 Rev. 1.4

C8051F020/1/2/3 16.1.Accessing XRAM..........................................................................................................145 16.1.1.16-Bit MOVX Example.......................................................................................145 16.1.2.8-Bit MOVX Example.........................................................................................145 16.2.Configuring the External Memory Interface.................................................................146 16.3.Port Selection and Configuration..................................................................................146 16.4.Multiplexed and Non-multiplexed Selection.................................................................148 16.4.1.Multiplexed Configuration..................................................................................148 16.4.2.Non-multiplexed Configuration...........................................................................149 16.5.Memory Mode Selection...............................................................................................150 16.5.1.Internal XRAM Only...........................................................................................150 16.5.2.Split Mode without Bank Select..........................................................................150 16.5.3.Split Mode with Bank Select...............................................................................151 16.5.4.External Only.......................................................................................................151 16.6.Timing .......................................................................................................................151 16.6.1.Non-multiplexed Mode........................................................................................153 16.6.1.1.16-bit MOVX: EMI0CF[4:2] = ‘101’, ‘110’, or ‘111’................................153 16.6.1.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = ‘101’ or ‘111’............154 16.6.1.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = ‘110’...............................155 16.6.2.Multiplexed Mode................................................................................................156 16.6.2.1.16-bit MOVX: EMI0CF[4:2] = ‘001’, ‘010’, or ‘011’................................156 16.6.2.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = ‘001’ or ‘011’............157 16.6.2.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = ‘010’...............................158 17.PORT INPUT/OUTPUT.....................................................................................................161 17.1.Ports 0 through 3 and the Priority Crossbar Decoder....................................................163 17.1.1.Crossbar Pin Assignment and Allocation............................................................163 17.1.2.Configuring the Output Modes of the Port Pins..................................................164 17.1.3.Configuring Port Pins as Digital Inputs...............................................................165 17.1.4.External Interrupts (IE6 and IE7)........................................................................165 17.1.5.Weak Pull-ups......................................................................................................165 17.1.6.Configuring Port 1 Pins as Analog Inputs (AIN1.[7:0])......................................165 17.1.7.External Memory Interface Pin Assignments......................................................166 17.1.8.Crossbar Pin Assignment Example......................................................................168 17.2.Ports 4 through 7 (C8051F020/2 only)..........................................................................177 17.2.1.Configuring Ports which are not Pinned Out.......................................................177 17.2.2.Configuring the Output Modes of the Port Pins..................................................177 17.2.3.Configuring Port Pins as Digital Inputs...............................................................178 17.2.4.Weak Pull-ups......................................................................................................178 17.2.5.External Memory Interface..................................................................................178 18.SYSTEM MANAGEMENT BUS / I2C BUS (SMBUS0).................................................183 18.1.Supporting Documents..................................................................................................184 18.2.SMBus Protocol.............................................................................................................185 18.2.1.Arbitration............................................................................................................185 18.2.2.Clock Low Extension...........................................................................................185 18.2.3.SCL Low Timeout...............................................................................................186 18.2.4.SCL High (SMBus Free) Timeout.......................................................................186 Rev. 1.4 5

C8051F020/1/2/3 18.3.SMBus Transfer Modes.................................................................................................187 18.3.1.Master Transmitter Mode....................................................................................187 18.3.2.Master Receiver Mode.........................................................................................187 18.3.3.Slave Transmitter Mode.......................................................................................188 18.3.4.Slave Receiver Mode...........................................................................................188 18.4.SMBus Special Function Registers...............................................................................189 18.4.1.Control Register...................................................................................................189 18.4.2.Clock Rate Register.............................................................................................192 18.4.3.Data Register........................................................................................................193 18.4.4.Address Register..................................................................................................193 18.4.5.Status Register.....................................................................................................194 19.SERIAL PERIPHERAL INTERFACE BUS (SPI0)........................................................197 19.1.Signal Descriptions........................................................................................................198 19.1.1.Master Out, Slave In (MOSI)..............................................................................198 19.1.2.Master In, Slave Out (MISO)..............................................................................198 19.1.3.Serial Clock (SCK)..............................................................................................198 19.1.4.Slave Select (NSS)...............................................................................................198 19.2.SPI0 Operation..............................................................................................................199 19.3.Serial Clock Timing......................................................................................................200 19.4.SPI Special Function Registers.....................................................................................201 20.UART0..................................................................................................................................205 20.1.UART0 Operational Modes..........................................................................................206 20.1.1.Mode 0: Synchronous Mode................................................................................206 20.1.2.Mode 1: 8-Bit UART, Variable Baud Rate.........................................................207 20.1.3.Mode 2: 9-Bit UART, Fixed Baud Rate..............................................................208 20.1.4.Mode 3: 9-Bit UART, Variable Baud Rate.........................................................209 20.2.Multiprocessor Communications...................................................................................210 20.3.Frame and Transmission Error Detection......................................................................211 21.UART1..................................................................................................................................215 21.1.UART1 Operational Modes..........................................................................................216 21.1.1.Mode 0: Synchronous Mode................................................................................216 21.1.2.Mode 1: 8-Bit UART, Variable Baud Rate.........................................................217 21.1.3.Mode 2: 9-Bit UART, Fixed Baud Rate..............................................................218 21.1.4.Mode 3: 9-Bit UART, Variable Baud Rate.........................................................219 21.2.Multiprocessor Communications...................................................................................220 21.3.Frame and Transmission Error Detection......................................................................221 22.TIMERS................................................................................................................................225 22.1.Timer 0 and Timer 1......................................................................................................227 22.1.1.Mode 0: 13-bit Counter/Timer.............................................................................227 22.1.2.Mode 1: 16-bit Counter/Timer.............................................................................228 22.1.3.Mode 2: 8-bit Counter/Timer with Auto-Reload.................................................229 22.1.4.Mode 3: Two 8-bit Counter/Timers (Timer 0 Only)...........................................230 22.2.Timer 2 .......................................................................................................................234 22.2.1.Mode 0: 16-bit Counter/Timer with Capture.......................................................235 22.2.2.Mode 1: 16-bit Counter/Timer with Auto-Reload...............................................236 6 Rev. 1.4

C8051F020/1/2/3 22.2.3.Mode 2: Baud Rate Generator.............................................................................237 22.3.Timer 3 .......................................................................................................................240 22.4.Timer 4 .......................................................................................................................243 22.4.1.Mode 0: 16-bit Counter/Timer with Capture.......................................................244 22.4.2.Mode 1: 16-bit Counter/Timer with Auto-Reload...............................................245 22.4.3.Mode 2: Baud Rate Generator.............................................................................246 23.PROGRAMMABLE COUNTER ARRAY.......................................................................249 23.1.PCA Counter/Timer.......................................................................................................250 23.2.Capture/Compare Modules............................................................................................252 23.2.1.Edge-triggered Capture Mode.............................................................................253 23.2.2.Software Timer (Compare) Mode........................................................................254 23.2.3.High Speed Output Mode....................................................................................255 23.2.4.Frequency Output Mode......................................................................................256 23.2.5.8-Bit Pulse Width Modulator Mode....................................................................257 23.2.6.16-Bit Pulse Width Modulator Mode..................................................................258 23.3.Register Descriptions for PCA0....................................................................................259 24.JTAG (IEEE 1149.1)............................................................................................................265 24.1.Boundary Scan...............................................................................................................266 24.1.1.EXTEST Instruction............................................................................................267 24.1.2.SAMPLE Instruction...........................................................................................267 24.1.3.BYPASS Instruction............................................................................................267 24.1.4.IDCODE Instruction............................................................................................267 24.2.Flash Programming Commands....................................................................................268 24.3.Debug Support...............................................................................................................271 Rev. 1.4 7

C8051F020/1/2/3 Notes 8 Rev. 1.4

C8051F020/1/2/3 LIST OF FIGURES AND TABLES 1. SYSTEM OVERVIEW.........................................................................................................17 Table 1.1. Product Selection Guide......................................................................................17 Figure 1.1. C8051F020 Block Diagram.................................................................................18 Figure 1.2. C8051F021 Block Diagram.................................................................................19 Figure 1.3. C8051F022 Block Diagram.................................................................................20 Figure 1.4. C8051F023 Block Diagram.................................................................................21 Figure 1.5. Comparison of Peak MCU Execution Speeds.....................................................22 Figure 1.6. On-Board Clock and Reset..................................................................................23 Figure 1.7. On-Chip Memory Map........................................................................................24 Figure 1.8. Development/In-System Debug Diagram...........................................................25 Figure 1.9. Digital Crossbar Diagram....................................................................................26 Figure 1.10. PCA Block Diagram............................................................................................27 Figure 1.11. 12-Bit ADC Block Diagram................................................................................28 Figure 1.12. 8-Bit ADC Diagram............................................................................................29 Figure 1.13. Comparator and DAC Diagram...........................................................................30 2. ABSOLUTE MAXIMUM RATINGS..................................................................................31 Table 2.1. Absolute Maximum Ratings*..............................................................................31 3. GLOBAL DC ELECTRICAL CHARACTERISTICS......................................................32 Table 3.1. Global DC Electrical Characteristics...................................................................32 4. PINOUT AND PACKAGE DEFINITIONS........................................................................33 Table 4.1. Pin Definitions.....................................................................................................33 Figure 4.1. TQFP-100 Pinout Diagram..................................................................................38 Figure 4.2. TQFP-100 Package Drawing...............................................................................39 Figure 4.3. TQFP-64 Pinout Diagram....................................................................................40 Figure 4.4. TQFP-64 Package Drawing.................................................................................41 5. ADC0 (12-BIT ADC, C8051F020/1 ONLY)........................................................................43 Figure 5.1. 12-Bit ADC0 Functional Block Diagram............................................................43 Figure 5.2. Temperature Sensor Transfer Function...............................................................44 Figure 5.3. 12-Bit ADC Track and Conversion Example Timing.........................................45 Figure 5.4. ADC0 Equivalent Input Circuits.........................................................................46 Figure 5.5. AMX0CF: AMUX0 Configuration Register (C8051F020/1).............................47 Figure 5.6. AMX0SL: AMUX0 Channel Select Register (C8051F020/1)............................48 Figure 5.7. ADC0CF: ADC0 Configuration Register (C8051F020/1)..................................49 Figure 5.8. ADC0CN: ADC0 Control Register (C8051F020/1)...........................................50 Figure 5.9. ADC0H: ADC0 Data Word MSB Register (C8051F020/1)...............................51 Figure 5.10. ADC0L: ADC0 Data Word LSB Register (C8051F020/1).................................51 Figure 5.11. ADC0 Data Word Example (C8051F020/1).......................................................52 Figure 5.12. ADC0GTH: ADC0 Greater-Than Data High Byte Register (C8051F020/1).....53 Figure 5.13. ADC0GTL: ADC0 Greater-Than Data Low Byte Register (C8051F020/1)......53 Figure 5.14. ADC0LTH: ADC0 Less-Than Data High Byte Register (C8051F020/1)..........53 Figure 5.15. ADC0LTL: ADC0 Less-Than Data Low Byte Register (C8051F020/1)...........53 Figure 5.16. 12-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended Data.54 Rev. 1.4 9

C8051F020/1/2/3 Figure 5.17. 12-Bit ADC0 Window Interrupt Example: Right Justified Differential Data.....55 Figure 5.18. 12-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended Data....56 Figure 5.19. 12-Bit ADC0 Window Interrupt Example: Left Justified Differential Data.......57 Table 5.1. 12-Bit ADC0 Electrical Characteristics (C8051F020/1).....................................58 6. ADC0 (10-BIT ADC, C8051F022/3 ONLY)........................................................................59 Figure 6.1. 10-Bit ADC0 Functional Block Diagram............................................................59 Figure 6.2. Temperature Sensor Transfer Function...............................................................60 Figure 6.3. 10-Bit ADC Track and Conversion Example Timing.........................................61 Figure 6.4. ADC0 Equivalent Input Circuits.........................................................................62 Figure 6.5. AMX0CF: AMUX0 Configuration Register (C8051F022/3).............................63 Figure 6.6. AMX0SL: AMUX0 Channel Select Register (C8051F022/3)............................64 Figure 6.7. ADC0CF: ADC0 Configuration Register (C8051F022/3)..................................65 Figure 6.8. ADC0CN: ADC0 Control Register (C8051F022/3)...........................................66 Figure 6.9. ADC0H: ADC0 Data Word MSB Register (C8051F022/3)...............................67 Figure 6.10. ADC0L: ADC0 Data Word LSB Register (C8051F022/3).................................67 Figure 6.11. ADC0 Data Word Example (C8051F022/3).......................................................68 Figure 6.12. ADC0GTH: ADC0 Greater-Than Data High Byte Register (C8051F022/3).....69 Figure 6.13. ADC0GTL: ADC0 Greater-Than Data Low Byte Register (C8051F022/3)......69 Figure 6.14. ADC0LTH: ADC0 Less-Than Data High Byte Register (C8051F022/3)..........69 Figure 6.15. ADC0LTL: ADC0 Less-Than Data Low Byte Register (C8051F022/3)...........69 Figure 6.16. 10-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended Data.70 Figure 6.17. 10-Bit ADC0 Window Interrupt Example: Right Justified Differential Data.....71 Figure 6.18. 10-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended Data....72 Figure 6.19. 10-Bit ADC0 Window Interrupt Example: Left Justified Differential Data.......73 Table 6.1. 10-Bit ADC0 Electrical Characteristics (C8051F022/3).....................................74 7. ADC1 (8-BIT ADC)...............................................................................................................75 Figure 7.1. ADC1 Functional Block Diagram.......................................................................75 Figure 7.2. ADC1 Track and Conversion Example Timing..................................................77 Figure 7.3. ADC1 Equivalent Input Circuit...........................................................................78 Figure 7.4. ADC1CF: ADC1 Configuration Register (C8051F020/1/2/3)............................79 Figure 7.5. AMX1SL: AMUX1 Channel Select Register (C8051F020/1/2/3).....................79 Figure 7.6. ADC1CN: ADC1 Control Register (C8051F020/1/2/3).....................................80 Figure 7.7. ADC1: ADC1 Data Word Register.....................................................................81 Figure 7.8. ADC1 Data Word Example.................................................................................81 Table 7.1. ADC1 Electrical Characteristics..........................................................................82 8. DACS, 12-BIT VOLTAGE MODE......................................................................................83 Figure 8.1. DAC Functional Block Diagram.........................................................................83 Figure 8.2. DAC0H: DAC0 High Byte Register...................................................................85 Figure 8.3. DAC0L: DAC0 Low Byte Register....................................................................85 Figure 8.4. DAC0CN: DAC0 Control Register.....................................................................86 Figure 8.5. DAC1H: DAC1 High Byte Register...................................................................87 Figure 8.6. DAC1L: DAC1 Low Byte Register....................................................................87 Figure 8.7. DAC1CN: DAC1 Control Register.....................................................................88 Table 8.1. DAC Electrical Characteristics............................................................................89 9. VOLTAGE REFERENCE (C8051F020/2)..........................................................................91 10 Rev. 1.4

C8051F020/1/2/3 Figure 9.1. Voltage Reference Functional Block Diagram....................................................91 Figure 9.2. REF0CN: Reference Control Register................................................................92 Table 9.1. Voltage Reference Electrical Characteristics......................................................92 10.VOLTAGE REFERENCE (C8051F021/3)..........................................................................93 Figure 10.1. Voltage Reference Functional Block Diagram...................................................93 Figure 10.2. REF0CN: Reference Control Register................................................................94 Table 10.1. Voltage Reference Electrical Characteristics......................................................94 11.COMPARATORS..................................................................................................................95 Figure 11.1. Comparator Functional Block Diagram..............................................................95 Figure 11.2. Comparator Hysteresis Plot.................................................................................96 Figure 11.3. CPT0CN: Comparator0 Control Register...........................................................97 Figure 11.4. CPT1CN: Comparator1 Control Register...........................................................98 Table 11.1. Comparator Electrical Characteristics.................................................................99 12.CIP-51 MICROCONTROLLER........................................................................................101 Figure 12.1. CIP-51 Block Diagram......................................................................................101 Table 12.1. CIP-51 Instruction Set Summary.......................................................................103 Figure 12.2. Memory Map.....................................................................................................107 Table 12.2. Special Function Register (SFR) Memory Map................................................109 Table 12.3. Special Function Registers................................................................................109 Figure 12.3. SP: Stack Pointer...............................................................................................113 Figure 12.4. DPL: Data Pointer Low Byte............................................................................113 Figure 12.5. DPH: Data Pointer High Byte...........................................................................113 Figure 12.6. PSW: Program Status Word..............................................................................114 Figure 12.7. ACC: Accumulator............................................................................................115 Figure 12.8. B: B Register.....................................................................................................115 Table 12.4. Interrupt Summary.............................................................................................117 Figure 12.9. IE: Interrupt Enable...........................................................................................119 Figure 12.10. IP: Interrupt Priority........................................................................................120 Figure 12.11. EIE1: Extended Interrupt Enable 1.................................................................121 Figure 12.12. EIE2: Extended Interrupt Enable 2.................................................................122 Figure 12.13. EIP1: Extended Interrupt Priority 1.................................................................123 Figure 12.14. EIP2: Extended Interrupt Priority 2.................................................................124 Figure 12.15. PCON: Power Control.....................................................................................126 13.RESET SOURCES..............................................................................................................127 Figure 13.1. Reset Sources....................................................................................................127 Figure 13.2. Reset Timing.....................................................................................................128 Figure 13.3. WDTCN: Watchdog Timer Control Register...................................................131 Figure 13.4. RSTSRC: Reset Source Register.......................................................................132 Table 13.1. Reset Electrical Characteristics.........................................................................133 14.OSCILLATORS...................................................................................................................135 Figure 14.1. Oscillator Diagram............................................................................................135 Figure 14.2. OSCICN: Internal Oscillator Control Register.................................................136 Table 14.1. Internal Oscillator Electrical Characteristics.....................................................136 Figure 14.3. OSCXCN: External Oscillator Control Register...............................................137 15.FLASH MEMORY..............................................................................................................139 Rev. 1.4 11

C8051F020/1/2/3 Table 15.1. FLASH Electrical Characteristics.....................................................................140 Figure 15.1. FLASH Program Memory Map and Security Bytes.........................................141 Figure 15.2. FLACL: FLASH Access Limit.........................................................................142 Figure 15.3. FLSCL: FLASH Memory Control....................................................................143 Figure 15.4. PSCTL: Program Store Read/Write Control.....................................................144 16.EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM.......................145 Figure 16.1. EMI0CN: External Memory Interface Control.................................................147 Figure 16.2. EMI0CF: External Memory Configuration.......................................................147 Figure 16.3. Multiplexed Configuration Example.................................................................148 Figure 16.4. Non-multiplexed Configuration Example.........................................................149 Figure 16.5. EMIF Operating Modes.....................................................................................150 Figure 16.6. EMI0TC: External Memory Timing Control....................................................152 Figure 16.7. Non-multiplexed 16-bit MOVX Timing...........................................................153 Figure 16.8. Non-multiplexed 8-bit MOVX without Bank Select Timing............................154 Figure 16.9. Non-multiplexed 8-bit MOVX with Bank Select Timing.................................155 Figure 16.10. Multiplexed 16-bit MOVX Timing.................................................................156 Figure 16.11. Multiplexed 8-bit MOVX without Bank Select Timing.................................157 Figure 16.12. Multiplexed 8-bit MOVX with Bank Select Timing.......................................158 Table 16.1. AC Parameters for External Memory Interface.................................................159 17.PORT INPUT/OUTPUT.....................................................................................................161 Figure 17.1. Port I/O Cell Block Diagram.............................................................................161 Table 17.1. Port I/O DC Electrical Characteristics..............................................................161 Figure 17.2. Lower Port I/O Functional Block Diagram.......................................................162 Figure 17.3. Priority Crossbar Decode Table........................................................................163 Figure 17.4. Priority Crossbar Decode Table........................................................................166 Figure 17.5. Priority Crossbar Decode Table........................................................................167 Figure 17.6. Crossbar Example:............................................................................................169 Figure 17.7. XBR0: Port I/O Crossbar Register 0.................................................................170 Figure 17.8. XBR1: Port I/O Crossbar Register 1.................................................................171 Figure 17.9. XBR2: Port I/O Crossbar Register 2.................................................................172 Figure 17.10. P0: Port0 Data Register...................................................................................173 Figure 17.11. P0MDOUT: Port0 Output Mode Register.......................................................173 Figure 17.12. P1: Port1 Data Register...................................................................................174 Figure 17.13. P1MDIN: Port1 Input Mode Register.............................................................174 Figure 17.14. P1MDOUT: Port1 Output Mode Register.......................................................175 Figure 17.15. P2: Port2 Data Register...................................................................................175 Figure 17.16. P2MDOUT: Port2 Output Mode Register.......................................................175 Figure 17.17. P3: Port3 Data Register...................................................................................176 Figure 17.18. P3MDOUT: Port3 Output Mode Register.......................................................176 Figure 17.19. P3IF: Port3 Interrupt Flag Register.................................................................177 Figure 17.20. P74OUT: Ports 7 - 4 Output Mode Register...................................................179 Figure 17.21. P4: Port4 Data Register...................................................................................180 Figure 17.22. P5: Port5 Data Register...................................................................................180 Figure 17.23. P6: Port6 Data Register...................................................................................181 Figure 17.24. P7: Port7 Data Register...................................................................................181 12 Rev. 1.4

C8051F020/1/2/3 18.SYSTEM MANAGEMENT BUS / I2C BUS (SMBUS0).................................................183 Figure 18.1. SMBus0 Block Diagram...................................................................................183 Figure 18.2. Typical SMBus Configuration..........................................................................184 Figure 18.3. SMBus Transaction...........................................................................................185 Figure 18.4. Typical Master Transmitter Sequence...............................................................187 Figure 18.5. Typical Master Receiver Sequence...................................................................187 Figure 18.6. Typical Slave Transmitter Sequence.................................................................188 Figure 18.7. Typical Slave Receiver Sequence.....................................................................188 Figure 18.8. SMB0CN: SMBus0 Control Register...............................................................191 Figure 18.9. SMB0CR: SMBus0 Clock Rate Register..........................................................192 Figure 18.10. SMB0DAT: SMBus0 Data Register...............................................................193 Figure 18.11. SMB0ADR: SMBus0 Address Register..........................................................193 Figure 18.12. SMB0STA: SMBus0 Status Register..............................................................194 Table 18.1. SMB0STA Status Codes and States..................................................................195 19.SERIAL PERIPHERAL INTERFACE BUS (SPI0)........................................................197 Figure 19.1. SPI Block Diagram............................................................................................197 Figure 19.2. Typical SPI Interconnection..............................................................................198 Figure 19.3. Full Duplex Operation.......................................................................................199 Figure 19.4. Data/Clock Timing Diagram.............................................................................200 Figure 19.5. SPI0CFG: SPI0 Configuration Register............................................................201 Figure 19.6. SPI0CN: SPI0 Control Register........................................................................202 Figure 19.7. SPI0CKR: SPI0 Clock Rate Register................................................................203 Figure 19.8. SPI0DAT: SPI0 Data Register..........................................................................203 20.UART0..................................................................................................................................205 Figure 20.1. UART0 Block Diagram.....................................................................................205 Table 20.1. UART0 Modes..................................................................................................206 Figure 20.2. UART0 Mode 0 Interconnect............................................................................206 Figure 20.3. UART0 Mode 0 Timing Diagram.....................................................................206 Figure 20.4. UART0 Mode 1 Timing Diagram.....................................................................207 Figure 20.5. UART Modes 2 and 3 Timing Diagram............................................................208 Figure 20.6. UART Modes 1, 2, and 3 Interconnect Diagram..............................................209 Figure 20.7. UART Multi-Processor Mode Interconnect Diagram.......................................210 Table 20.2. Oscillator Frequencies for Standard Baud Rates...............................................212 Figure 20.8. SCON0: UART0 Control Register....................................................................213 Figure 20.9. SBUF0: UART0 Data Buffer Register..............................................................214 Figure 20.10. SADDR0: UART0 Slave Address Register....................................................214 Figure 20.11. SADEN0: UART0 Slave Address Enable Register........................................214 21.UART1..................................................................................................................................215 Figure 21.1. UART1 Block Diagram.....................................................................................215 Table 21.1. UART1 Modes..................................................................................................216 Figure 21.2. UART1 Mode 0 Interconnect............................................................................216 Figure 21.3. UART1 Mode 0 Timing Diagram.....................................................................216 Figure 21.4. UART1 Mode 1 Timing Diagram.....................................................................217 Figure 21.5. UART Modes 2 and 3 Timing Diagram............................................................218 Figure 21.6. UART Modes 1, 2, and 3 Interconnect Diagram..............................................219 Rev. 1.4 13

C8051F020/1/2/3 Figure 21.7. UART Multi-Processor Mode Interconnect Diagram.......................................220 Table 21.2. Oscillator Frequencies for Standard Baud Rates...............................................222 Figure 21.8. SCON1: UART1 Control Register....................................................................223 Figure 21.9. SBUF1: UART1 Data Buffer Register..............................................................224 Figure 21.10. SADDR1: UART1 Slave Address Register....................................................224 Figure 21.11. SADEN1: UART1 Slave Address Enable Register........................................224 22.TIMERS................................................................................................................................225 Figure 22.1. CKCON: Clock Control Register......................................................................226 Figure 22.2. T0 Mode 0 Block Diagram................................................................................228 Figure 22.3. T0 Mode 2 (8-bit Auto-Reload) Block Diagram...............................................229 Figure 22.4. T0 Mode 3 (Two 8-bit Timers) Block Diagram................................................230 Figure 22.5. TCON: Timer Control Register.........................................................................231 Figure 22.6. TMOD: Timer Mode Register...........................................................................232 Figure 22.7. TL0: Timer 0 Low Byte....................................................................................233 Figure 22.8. TL1: Timer 1 Low Byte....................................................................................233 Figure 22.9. TH0 Timer 0 High Byte....................................................................................233 Figure 22.10. TH1: Timer 1 High Byte.................................................................................233 Figure 22.11. T2 Mode 0 Block Diagram..............................................................................235 Figure 22.12. T2 Mode 1 Block Diagram..............................................................................236 Figure 22.13. T2 Mode 2 Block Diagram..............................................................................237 Figure 22.14. T2CON: Timer 2 Control Register..................................................................238 Figure 22.15. RCAP2L: Timer 2 Capture Register Low Byte..............................................239 Figure 22.16. RCAP2H: Timer 2 Capture Register High Byte.............................................239 Figure 22.17. TL2: Timer 2 Low Byte..................................................................................239 Figure 22.18. TH2 Timer 2 High Byte..................................................................................239 Figure 22.19. Timer 3 Block Diagram...................................................................................240 Figure 22.20. TMR3CN: Timer 3 Control Register..............................................................241 Figure 22.21. TMR3RLL: Timer 3 Reload Register Low Byte............................................241 Figure 22.22. TMR3RLH: Timer 3 Reload Register High Byte...........................................242 Figure 22.23. TMR3L: Timer 3 Low Byte............................................................................242 Figure 22.24. TMR3H: Timer 3 High Byte...........................................................................242 Figure 22.25. T4 Mode 0 Block Diagram..............................................................................244 Figure 22.26. T4 Mode 1 Block Diagram..............................................................................245 Figure 22.27. T4 Mode 2 Block Diagram..............................................................................246 Figure 22.28. T4CON: Timer 4 Control Register..................................................................247 Figure 22.29. RCAP4L: Timer 4 Capture Register Low Byte..............................................248 Figure 22.30. RCAP4H: Timer 4 Capture Register High Byte.............................................248 Figure 22.31. TL4: Timer 4 Low Byte..................................................................................248 Figure 22.32. TH4 Timer 4 High Byte..................................................................................248 23.PROGRAMMABLE COUNTER ARRAY.......................................................................249 Figure 23.1. PCA Block Diagram..........................................................................................249 Figure 23.2. PCA Counter/Timer Block Diagram.................................................................250 Table 23.1. PCA Timebase Input Options............................................................................250 Figure 23.3. PCA Interrupt Block Diagram...........................................................................252 Table 23.2. PCA0CPM Register Settings for PCA Capture/Compare Modules..................252 14 Rev. 1.4

C8051F020/1/2/3 Figure 23.4. PCA Capture Mode Diagram............................................................................253 Figure 23.5. PCA Software Timer Mode Diagram................................................................254 Figure 23.6. PCA High Speed Output Mode Diagram..........................................................255 Figure 23.7. PCA Frequency Output Mode...........................................................................256 Figure 23.8. PCA 8-Bit PWM Mode Diagram......................................................................257 Figure 23.9. PCA 16-Bit PWM Mode...................................................................................258 Figure 23.10. PCA0CN: PCA Control Register....................................................................259 Figure 23.11. PCA0MD: PCA0 Mode Register....................................................................260 Figure 23.12. PCA0CPMn: PCA0 Capture/Compare Mode Registers.................................261 Figure 23.13. PCA0L: PCA0 Counter/Timer Low Byte.......................................................262 Figure 23.14. PCA0H: PCA0 Counter/Timer High Byte......................................................262 Figure 23.15. PCA0CPLn: PCA0 Capture Module Low Byte..............................................263 Figure 23.16. PCA0CPHn: PCA0 Capture Module High Byte.............................................263 24.JTAG (IEEE 1149.1)............................................................................................................265 Figure 24.1. IR: JTAG Instruction Register..........................................................................265 Table 24.1. Boundary Data Register Bit Definitions............................................................266 Figure 24.2. DEVICEID: JTAG Device ID Register............................................................267 Figure 24.3. FLASHCON: JTAG Flash Control Register.....................................................269 Figure 24.4. FLASHADR: JTAG Flash Address Register....................................................270 Figure 24.5. FLASHDAT: JTAG Flash Data Register..........................................................270 Rev. 1.4 15

C8051F020/1/2/3 Notes 16 Rev. 1.4

C8051F020/1/2/3 1. SYSTEM OVERVIEW The C8051F020/1/2/3 devices are fully integrated mixed-signal System-on-a-Chip MCUs with 64 digital I/O pins (C8051F020/2) or 32 digital I/O pins (C8051F021/3). Highlighted features are listed below; refer to Table 1.1 for specific product feature selection. • High-Speed pipelined 8051-compatible CIP-51 microcontroller core (up to 25 MIPS) • In-system, full-speed, non-intrusive debug interface (on-chip) • True 12-bit (C8051F020/1) or 10-bit (C8051F022/3) 100 ksps 8-channel ADC with PGA and analog multiplexer • True 8-bit ADC 500 ksps 8-channel ADC with PGA and analog multiplexer • Two 12-bit DACs with programmable update scheduling • 64k bytes of in-system programmable FLASH memory • 4352 (4096 + 256) bytes of on-chip RAM • External Data Memory Interface with 64k byte address space • SPI, SMBus/I2C, and (2) UART serial interfaces implemented in hardware • Five general purpose 16-bit Timers • Programmable Counter/Timer Array with five capture/compare modules • On-chip Watchdog Timer, VDD Monitor, and Temperature Sensor With on-chip VDD monitor, Watchdog Timer, and clock oscillator, the C8051F020/1/2/3 devices are truly stand- alone System-on-a-Chip solutions. All analog and digital peripherals are enabled/disabled and configured by user firmware. The FLASH memory can be reprogrammed even in-circuit, providing non-volatile data storage, and also allowing field upgrades of the 8051 firmware. On-board JTAG debug circuitry allows non-intrusive (uses no on-chip resources), full speed, in-circuit debugging using the production MCU installed in the final application. This debug system supports inspection and modification of memory and registers, setting breakpoints, watchpoints, single stepping, run and halt commands. All analog and digital peripherals are fully functional while debugging using JTAG. Each MCU is specified for 2.7 V-to-3.6 V operation over the industrial temperature range (-45° C to +85° C). The Port I/Os, /RST, and JTAG pins are tolerant for input signals up to 5 V. The C8051F020/2 are available in a 100-pin TQFP package (see block diagrams in Figure 1.1 and Figure 1.3). The C8051F021/3 are available in a 64-pin TQFP package (see block diagrams in Figure 1.2 and Figure 1.4). Table 1.1. Product Selection Guide y a MIPS (Peak) FLASH Memory RAM External Memory Interface 2SMBus/IC SPI UARTS Timers (16-bit) Programmable Counter Arr Digital Port I/O’s 12-bit 100ksps ADC Inputs 10-bit 100ksps ADC Inputs 8-bit 500ksps ADC Inputs Voltage Reference Temperature Sensor DAC Resolution (bits) DAC Outputs Analog Comparators Package C8051F020 25 64k 4352    2 5  64 8 - 8   12 2 2 100TQFP C8051F021 25 64k 4352    2 5  32 8 - 8   12 2 2 64TQFP C8051F022 25 64k 4352    2 5  64 - 8 8   12 2 2 100TQFP C8051F023 25 64k 4352    2 5  32 - 8 8   12 2 2 64TQFP Rev. 1.4 17

C8051F020/1/2/3 Figure 1.1. C8051F020 Block Diagram VDD Port I/O VDD VDD Digital Power Config. DDGGNNDD 8 UART0 P0 P0.0 DGND UART1 Drv P0.7 AV+ 0 AV+ Analog Power SMBus C AAGGNNDD 5 SPI Bus R P1 P1.0/AIN1.0 TTCMKS JTAG Boundary Scan 1 PCA OS Drv P1.7/AIN1.7 TDI Logic Debug HW Timers 0, S TDO SFR Bus 1, 2, 4 B P2 P2.0 /RST Reset Timer 3/ A Drv P2.7 RTC R MONEN MVoDniDtor WDT C 64kbyte P0, P1, P3 P3.0 FLASH P2, P3 Drv P3.7 External o Latches XTAL1 Oscillator 256 byte XTAL2 Circuit System r RAM CCroosnsfibga.r Clock OInstceilrlnaatolr e 4kbyte VREF1 RAM A50D0Cksps Prog MA 8:1 VVRREEFFD VREF (8-Bit) Gain UX DAC1 External Data Memory Bus P4.0 DAC1 (12-Bit) Bus Control C P4 Latch P4 P4.4 T DRV P4.5/ALE DAC0 L P4.6/RD DAC0 (12-Bit) P4.7/WR VREF0 P5 Latch P5 P5.0/A8 AAIINN00..01 Address Bus Ad DRV P5.7/A15 AAAIIINNN000...234 MUA PGraoign 100kAsDpCs dr P6 Latch DPR6V PP66..07//AA07 AIN0.5 X (12-Bit) AIN0.6 AINC0P.07+ CP0 SETENMSOPR Data Bus Dat P7 Latch DPR7V PP77..07//DD07 CP0- a CP1+ CP1 CP1- 18 Rev. 1.4

C8051F020/1/2/3 Figure 1.2. C8051F021 Block Diagram VDD Port I/O VDD VDD Digital Power Config. DDGGNNDD 8 UART0 P0 P0.0 DGND UART1 Drv P0.7 0 AV+ SMBus C AGND Analog Power 5 SPI Bus R P1 P1.0/AIN1.0 TTCMKS JTAG Boundary Scan 1 PCA OS Drv P1.7/AIN1.7 TDI Logic Debug HW Timers 0, S TDO SFR Bus 1, 2, 4 B P2 P2.0 /RST Reset Timer 3/ A Drv P2.7 RTC R MONEN MVoDniDtor WDT C 64kbyte P0, P1, P3 P3.0 FLASH P2, P3 Drv P3.7 External o Latches XTAL1 Oscillator 256 byte XTAL2 Circuit System r RAM CCroosnsfibga.r Clock OInstceilrlnaatolr e 4RkbAyMte A50D0Cksps PGraoing MUA 8:1 VREF VREF (8-Bit) X AV+ External Data Memory Bus VREFA DAC1 DAC1 (12-Bit) Bus Control C P4 Latch P4 T DRV DAC0 (1D2A-BCit0) L VREFA P5 Latch P5 AAAAAIIIIINNNNN00000.....01234 MUA PGraoign 100kAsDpCs Address Bus Addr P6 Latch DDPRR6VV AIN0.5 X (12-Bit) AIN0.6 AINC0P.07+ CP0 SETNEMSOPR Data Bus Dat P7 Latch DPR7V CP0- a CP1+ CP1 CP1- Rev. 1.4 19

C8051F020/1/2/3 Figure 1.3. C8051F022 Block Diagram VDD Port I/O VDD VDD Digital Power Config. DDGGNNDD 8 UART0 P0 P0.0 DGND UART1 Drv P0.7 AV+ 0 AV+ Analog Power SMBus C AAGGNNDD 5 SPI Bus R P1 P1.0/AIN1.0 TTCMKS JTAG Boundary Scan 1 PCA OS Drv P1.7/AIN1.7 TDI Logic Debug HW Timers 0, S TDO SFR Bus 1, 2, 4 B P2 P2.0 /RST Reset Timer 3/ A Drv P2.7 RTC R MONEN MVoDniDtor WDT C 64kbyte P0, P1, P3 P3.0 FLASH P2, P3 Drv P3.7 External o Latches XTAL1 Oscillator 256 byte XTAL2 Circuit System r RAM CCroosnsfibga.r Clock OInstceilrlnaatolr e 4kbyte VREF1 RAM A50D0Cksps Prog MA 8:1 VVRREEFFD VREF (8-Bit) Gain UX DAC1 External Data Memory Bus P4.0 DAC1 (12-Bit) Bus Control C P4 Latch P4 P4.4 T DRV P4.5/ALE DAC0 L P4.6/RD DAC0 (12-Bit) P4.7/WR VREF0 P5 Latch P5 P5.0/A8 AAIINN00..01 Address Bus Ad DRV P5.7/A15 AAAIIINNN000...234 MUA PGraoign 100kAsDpCs dr P6 Latch DPR6V PP66..07//AA07 AIN0.5 X (10-Bit) AIN0.6 AINC0P.07+ CP0 SETENMSOPR Data Bus Dat P7 Latch DPR7V PP77..07//DD07 CP0- a CP1+ CP1 CP1- 20 Rev. 1.4

C8051F020/1/2/3 Figure 1.4. C8051F023 Block Diagram VDD Port I/O VDD VDD Digital Power Config. DDGGNNDD 8 UART0 P0 P0.0 DGND UART1 Drv P0.7 0 AV+ SMBus C AGND Analog Power 5 SPI Bus R P1 P1.0/AIN1.0 TTCMKS JTAG Boundary Scan 1 PCA OS Drv P1.7/AIN1.7 TDI Logic Debug HW Timers 0, S TDO SFR Bus 1, 2, 4 B P2 P2.0 /RST Reset Timer 3/ A Drv P2.7 RTC R MONEN MVoDniDtor WDT C 64kbyte P0, P1, P3 P3.0 FLASH P2, P3 Drv P3.7 External o Latches XTAL1 Oscillator 256 byte XTAL2 Circuit System r RAM CCroosnsfibga.r Clock OInstceilrlnaatolr e 4RkbAyMte A50D0Cksps PGraoing MUA 8:1 VREF VREF (8-Bit) X AV+ External Data Memory Bus VREFA DAC1 DAC1 (12-Bit) Bus Control C P4 Latch P4 T DRV DAC0 (1D2A-BCit0) L VREFA P5 Latch P5 AAAAAIIIIINNNNN00000.....01234 MUA PGraoign 100kAsDpCs Address Bus Addr P6 Latch DDPRR6VV AIN0.5 X (10-Bit) AIN0.6 AINC0P.07+ CP0 SETENMSOPR Data Bus Dat P7 Latch DPR7V CP0- a CP1+ CP1 CP1- Rev. 1.4 21

C8051F020/1/2/3 1.1. CIP-51™ Microcontroller Core 1.1.1. Fully 8051 Compatible The C8051F020 family utilizes Silicon Labs' proprietary CIP-51 microcontroller core. The CIP-51 is fully compati- ble with the MCS-51™ instruction set; standard 803x/805x assemblers and compilers can be used to develop soft- ware. The core has all the peripherals included with a standard 8052, including five 16-bit counter/timers, two full- duplex UARTs, 256 bytes of internal RAM, 128 byte Special Function Register (SFR) address space, and 8/4 byte- wide I/O Ports. 1.1.2. Improved Throughput The CIP-51 employs a pipelined architecture that greatly increases its instruction throughput over the standard 8051 architecture. In a standard 8051, all instructions except for MUL and DIV take 12 or 24 system clock cycles to exe- cute with a maximum system clock of 12-to-24 MHz. By contrast, the CIP-51 core executes 70% of its instructions in one or two system clock cycles, with only four instructions taking more than four system clock cycles. The CIP-51 has a total of 109 instructions. The table below shows the total number of instructions that require each execution time. Clocks to Execute 1 2 2/3 3 3/4 4 4/5 5 8 Number of Instructions 26 50 5 14 7 3 1 2 1 With the CIP-51's maximum system clock at 25 MHz, it has a peak throughput of 25 MIPS. Figure 1.5 shows a com- parison of peak throughputs of various 8-bit microcontroller cores with their maximum system clocks. Figure 1.5. Comparison of Peak MCU Execution Speeds 25 20 S P I 15 M 10 5 Silicon Labs Microchip Philips ADuC812 CIP-51 PIC17C75x 80C51 8051 (25MHz clk) (33MHz clk) (33MHz clk) (16MHz clk) 22 Rev. 1.4

C8051F020/1/2/3 1.1.3. Additional Features The C8051F020 MCU family includes several key enhancements to the CIP-51 core and peripherals to improve over- all performance and ease of use in end applications. The extended interrupt handler provides 22 interrupt sources into the CIP-51 (as opposed to 7 for the standard 8051), allowing the numerous analog and digital peripherals to interrupt the controller. An interrupt driven system requires less intervention by the MCU, giving it more effective throughput. The extra interrupt sources are very useful when building multi-tasking, real-time systems. There are up to seven reset sources for the MCU: an on-board VDD monitor, a Watchdog Timer, a missing clock detector, a voltage level detection from Comparator0, a forced software reset, the CNVSTR input pin, and the /RST pin. The /RST pin is bi-directional, accommodating an external reset, or allowing the internally generated POR to be output on the /RST pin. Each reset source except for the VDD monitor and Reset Input pin may be disabled by the user in software; the VDD monitor is enabled/disabled via the MONEN pin. The Watchdog Timer may be perma- nently enabled in software after a power-on reset during MCU initialization. The MCU has an internal, stand alone clock generator which is used by default as the system clock after any reset. If desired, the clock source may be switched on the fly to the external oscillator, which can use a crystal, ceramic reso- nator, capacitor, RC, or external clock source to generate the system clock. This can be extremely useful in low power applications, allowing the MCU to run from a slow (power saving) external crystal source, while periodically switch- ing to the fast (up to 16 MHz) internal oscillator as needed. Figure 1.6. On-Board Clock and Reset VDD (Port CNVSTR Crossbar Supply I/O) (CNVSTR Monitor erneasbelet) + SRuepspelty /RST - Timeout (wired-OR) Comparator0 CP0+ + - CP0- (CP0 reset enable) Reset Missing WDT Funnel Clock Detector (one- shot) EN EN PRE Internal MCDEnable WDTEnable WDTStrobe Clock Generator System Software Reset Clock CIP-51 XTAL1 OSC Microcontroller XTAL2 Clock Select Core System Reset Extended Interrupt Handler Rev. 1.4 23

C8051F020/1/2/3 1.2. On-Chip Memory The CIP-51 has a standard 8051 program and data address configuration. It includes 256 bytes of data RAM, with the upper 128 bytes dual-mapped. Indirect addressing accesses the upper 128 bytes of general purpose RAM, and direct addressing accesses the 128 byte SFR address space. The lower 128 bytes of RAM are accessible via direct and indi- rect addressing. The first 32 bytes are addressable as four banks of general purpose registers, and the next 16 bytes can be byte addressable or bit addressable. The CIP-51 in the C8051F020/1/2/3 MCUs additionally has an on-chip 4k byte RAM block and an external memory interface (EMIF) for accessing off-chip data memory. The on-chip 4k byte block can be addressed over the entire 64k external data memory address range (overlapping 4k boundaries). External data memory address space can be mapped to on-chip memory only, off-chip memory only, or a combination of the two (addresses up to 4k directed to on-chip, above 4k directed to EMIF). The EMIF is also configurable for multiplexed or non-multiplexed address/data lines. The MCU’s program memory consists of 64k bytes of FLASH. This memory may be reprogrammed in-system in 512 byte sectors, and requires no special off-chip programming voltage. The 512 bytes from addresses 0xFE00 to 0xFFFF are reserved for factory use. There is also a single 128 byte sector at address 0x10000 to 0x1007F, which may be useful as a small table for software constants. See Figure 1.7 for the MCU system memory map. Figure 1.7. On-Chip Memory Map PROGRAM/DATA MEMORY DATA MEMORY (RAM) (FLASH) INTERNAL DATA ADDRESS SPACE 0x1007F Scrachpad Memory 0xFF Upper 128 RAM Special Function 0x10000 (DATA only) (Indirect Addressing Register's 0xFFFF 0x80 Only) (Direct Addressing Only) RESERVED 0xFE00 0x7F 0xFDFF (Direct and Indirect Addressing) Lower 128 RAM 0x30 (Direct and Indirect FLASH 0x2F Addressing) Bit Addressable 0x20 (In-System 0x1F General Purpose Programmable in 512 0x00 Registers Byte Sectors) EXTERNAL DATA ADDRESS SPACE 0x0000 0xFFFF Off-chip XRAM space 0x1000 0x0FFF XRAM - 4096 Bytes (accessable using MOVX 0x0000 instruction) 24 Rev. 1.4

C8051F020/1/2/3 1.3. JTAG Debug and Boundary Scan The C8051F020 family has on-chip JTAG boundary scan and debug circuitry that provides non-intrusive, full speed, in-circuit debugging using the production part installed in the end application, via the four-pin JTAG interface. The JTAG port is fully compliant to IEEE 1149.1, providing full boundary scan for test and manufacturing purposes. Silicon Labs' debugging system supports inspection and modification of memory and registers, breakpoints, watch- points, a stack monitor, and single stepping. No additional target RAM, program memory, timers, or communications channels are required. All the digital and analog peripherals are functional and work correctly while debugging. All the peripherals (except for the ADC and SMBus) are stalled when the MCU is halted, during single stepping, or at a breakpoint in order to keep them synchronized. The C8051F020DK development kit provides all the hardware and software necessary to develop application code and perform in-circuit debugging with the C8051F020/1/2/3 MCUs. The kit includes software with a developer's stu- dio and debugger, an integrated 8051 assembler, and an RS-232 to JTAG serial adapter. It also has a target application board with the associated MCU installed, plus the RS-232 and JTAG cables, and wall-mount power supply. The Development Kit requires a Windows 95/98/NT/ME/2000 computer with one available RS-232 serial port. As shown in Figure 1.8, the PC is connected via RS-232 to the Serial Adapter. A six-inch ribbon cable connects the Serial Adapter to the user's application board, picking up the four JTAG pins and VDD and GND. The Serial Adapter takes its power from the application board; it requires roughly 20 mA at 2.7-3.6 V. For applications where there is not suf- ficient power available from the target system, the provided power supply can be connected directly to the Serial Adapter. Silicon Labs’ debug environment is a vastly superior configuration for developing and debugging embedded applica- tions compared to standard MCU emulators, which use on-board "ICE Chips" and target cables and require the MCU in the application board to be socketed. Silicon Labs' debug environment both increases ease of use and preserves the performance of the precision analog peripherals. Figure 1.8. Development/In-System Debug Diagram Silicon Labs Integrated Development Environment WINDOWS 95/98/NT/ME/2000 RS-232 Serial Adapter JTAG (x4), VDD, GND TARGET PCB VDD GND C8051 F020 Rev. 1.4 25

C8051F020/1/2/3 1.4. Programmable Digital I/O and Crossbar The standard 8051 Ports (0, 1, 2, and 3) are available on the MCUs. The C8051F020/2 have 4 additional ports (4, 5, 6, and 7) for a total of 64 general-purpose port I/O. The Port I/O behave like the standard 8051 with a few enhance- ments. Each Port I/O pin can be configured as either a push-pull or open-drain output. Also, the "weak pull-ups" which are normally fixed on an 8051 can be globally disabled, providing additional power saving capabilities for low-power applications. Perhaps the most unique enhancement is the Digital Crossbar. This is essentially a large digital switching network that allows mapping of internal digital system resources to Port I/O pins on P0, P1, P2, and P3. (See Figure 1.9) Unlike microcontrollers with standard multiplexed digital I/O, all combinations of functions are supported. The on-chip counter/timers, serial buses, HW interrupts, ADC Start of Conversion input, comparator outputs, and other digital signals in the controller can be configured to appear on the Port I/O pins specified in the Crossbar Con- trol registers. This allows the user to select the exact mix of general purpose Port I/O and digital resources needed for the particular application. Figure 1.9. Digital Crossbar Diagram Highest UART0 2 XBR0, XBR1, P0MDOUT, P1MDOUT, Priority XBR2, P1MDIN P2MDOUT, P3MDOUT 4 Registers Registers SPI 2 External SMBus Priority Pins Decoder 2 Signals) UPACRAT1 6 8 CIPe/O0lls PP00..07 HPirgiohreitsyt al git Comptr. 2 Di Outputs Digital nal Crossbar 8 P1 P1.0 er I/O (Int T0, T1, Cells P1.7 T2, T2EX, 8 T4,T4EX /INT0, /INT1 8 P2 P2.0 I/O Cells P2.7 Lowest /SYSCLK Priority CNVSTR 8 8 IP/O3 P3.0 Lowest P0 Cells P3.7 Priority (P0.0-P0.7) 8 P1 (P1.0-P1.7) To External To Port Memory Latches 8 Interface ADC1 Input (EMIF) P2 (P2.0-P2.7) 8 P3 (P3.0-P3.7) 26 Rev. 1.4

C8051F020/1/2/3 1.5. Programmable Counter Array The C8051F020 MCU family includes an on-board Programmable Counter/Timer Array (PCA) in addition to the five 16-bit general purpose counter/timers. The PCA consists of a dedicated 16-bit counter/timer time base with 5 pro- grammable capture/compare modules. The timebase is clocked from one of six sources: the system clock divided by 12, the system clock divided by 4, Timer 0 overflow, an External Clock Input (ECI pin), the system clock, or the external oscillator source divided by 8. Each capture/compare module can be configured to operate in one of six modes: Edge-Triggered Capture, Software Timer, High Speed Output, Frequency Output, 8-Bit Pulse Width Modulator, or 16-Bit Pulse Width Modulator. The PCA Capture/Compare Module I/O and External Clock Input are routed to the MCU Port I/O via the Digital Cross- bar. Figure 1.10. PCA Block Diagram SYSCLK/12 SYSCLK/4 Timer 0 Overflow PCA 16-Bit Counter/Timer ECI CLOCK MUX SYSCLK External Clock/8 Capture/Compare Capture/Compare Capture/Compare Capture/Compare Capture/Compare Module 0 Module 1 Module 2 Module 3 Module 4 E C C C C C C E E E E E I X X X X X 0 1 2 3 4 Crossbar Port I/O 1.6. Serial Ports The C8051F020 MCU Family includes two Enhanced Full-Duplex UARTs, SPI Bus, and SMBus/I2C. Each of the serial buses is fully implemented in hardware and makes extensive use of the CIP-51's interrupts, thus requiring very little intervention by the CPU. The serial buses do not "share" resources such as timers, interrupts, or Port I/O, so any or all of the serial buses may be used together with any other. Rev. 1.4 27

C8051F020/1/2/3 1.7. 12-Bit Analog to Digital Converter The C8051F020/1 has an on-chip 12-bit SAR ADC (ADC0) with a 9-channel input multiplexer and programmable gain amplifier. With a maximum throughput of 100 ksps, the ADC offers true 12-bit accuracy with an INL of ±1LSB. C8051F022/3 devices include a 10-bit SAR ADC with similar specifications and configuration options. The ADC0 voltage reference is selected between the DAC0 output and an external VREF pin. On C8051F020/2 devices, ADC0 has its own dedicated VREF0 input pin; on C8051F021/3 devices, the ADC0 shares the VREFA input pin with the 8- bit ADC1. The on-chip 15 ppm/°C voltage reference may generate the voltage reference for other system components or the on-chip ADCs via the VREF output pin. The ADC is under full control of the CIP-51 microcontroller via its associated Special Function Registers. One input channel is tied to an internal temperature sensor, while the other eight channels are available externally. Each pair of the eight external input channels can be configured as either two single-ended inputs or a single differential input. The system controller can also put the ADC into shutdown mode to save power. A programmable gain amplifier follows the analog multiplexer. The gain can be set in software from 0.5 to 16 in powers of 2. The gain stage can be especially useful when different ADC input channels have widely varied input voltage signals, or when it is necessary to "zoom in" on a signal with a large DC offset (in differential mode, a DAC could be used to provide the DC offset). Conversions can be started in four ways; a software command, an overflow of Timer 2, an overflow of Timer 3, or an external signal input. This flexibility allows the start of conversion to be triggered by software events, external HW signals, or a periodic timer overflow signal. Conversion completions are indicated by a status bit and an interrupt (if enabled). The resulting 10 or 12-bit data word is latched into two SFRs upon completion of a conversion. The data can be right or left justified in these registers under software control. Window Compare registers for the ADC data can be configured to interrupt the controller when ADC data is within or outside of a specified range. The ADC can monitor a key voltage continuously in background mode, but not inter- rupt the controller unless the converted data is within the specified window. Figure 1.11. 12-Bit ADC Block Diagram Analog Multiplexer Window Configuration, Control, and Data Window Compare Compare Registers Logic Interrupt AIN0.0 + AIN0.1 - Programmable Gain AIN0.2 + Amplifier AIN0.3 - 9-to-1 12-Bit AV+ AMUX AIN0.4 + (SE or X + SAR 12 ADC Data AIN0.5 - DIFF) - Registers ADC AIN0.6 + Conversion AIN0.7 - Complete TEMP Interrupt SENSOR Write to AD0BUSY External VREF Start Pin VREF Conversion Timer 3 Overflow AGND CNVSTR DAC0 Output Timer 2 Overflow 28 Rev. 1.4

C8051F020/1/2/3 1.8. 8-Bit Analog to Digital Converter The C8051F020/1/2/3 has an on-board 8-bit SAR ADC (ADC1) with an 8-channel input multiplexer and programma- ble gain amplifier. This ADC features a 500 ksps maximum throughput and true 8-bit accuracy with an INL of ±1LSB. Eight input pins are available for measurement. The ADC is under full control of the CIP-51 microcontroller via the Special Function Registers. The ADC1 voltage reference is selected between the analog power supply (AV+) and an external VREF pin. On C8051F020/2 devices, ADC1 has its own dedicated VREF1 input pin; on C8051F021/3 devices, ADC1 shares the VREFA input pin with the 12/10-bit ADC0. User software may put ADC1 into shutdown mode to save power. A programmable gain amplifier follows the analog multiplexer. The gain stage can be especially useful when differ- ent ADC input channels have widely varied input voltage signals, or when it is necessary to "zoom in" on a signal with a large DC offset (in differential mode, a DAC could be used to provide the DC offset). The PGA gain can be set in software to 0.5, 1, 2, or 4. A flexible conversion scheduling system allows ADC1 conversions to be initiated by software commands, timer overflows, or an external input signal. ADC1 conversions may also be synchronized with ADC0 software-com- manded conversions. Conversion completions are indicated by a status bit and an interrupt (if enabled), and the resulting 8-bit data word is latched into an SFR upon completion. Figure 1.12. 8-Bit ADC Diagram Analog Multiplexer Configuration, Control, and Data Registers AIN1.0 AIN1.1 Programmable Gain AIN1.2 Amplifier Conversion AIN1.3 8-Bit Complete AV+ 8-to-1 Interrupt AIN1.4 AMUX X + SAR 8 ADC Data AIN1.5 - Register ADC AIN1.6 AIN1.7 Write to AD1BUSY External VREF Timer 3 Overflow Pin VREF Start Conversion CNVSTR Input AV+ Timer 2 Overflow Write to AD0BUSY (synchronized with ADC0) Rev. 1.4 29

C8051F020/1/2/3 1.9. Comparators and DACs Each C8051F020/1/2/3 MCU has two 12-bit DACs and two comparators on chip. The MCU data and control inter- face to each comparator and DAC is via the Special Function Registers. The MCU can place any DAC or comparator in low power shutdown mode. The comparators have software programmable hysteresis. Each comparator can generate an interrupt on its rising edge, falling edge, or both; these interrupts are capable of waking up the MCU from sleep mode. The comparators' output state can also be polled in software. The comparator outputs can be programmed to appear on the Port I/O pins via the Crossbar. The DACs are voltage output mode, and include a flexible output scheduling mechanism. This scheduling mecha- nism allows DAC output updates to be forced by a software write or a Timer 2, 3, or 4 overflow. The DAC voltage reference is supplied via the dedicated VREFD input pin on C8051F020/2 devices or via the internal voltage refer- ence on C8051F021/3 devices. The DACs are especially useful as references for the comparators or offsets for the differential inputs of the ADC. Figure 1.13. Comparatora ndD ACD iagram CP0 (Port I/O) CROSSBAR CP1 (Port I/O) CP0+ + CP0 CP0- - CP1+ CP0 + CP1 CP1- - CP1 SFR's CIP-51 (Data and and Interrupt Cntrl) Handler REF DAC0 DAC0 REF DAC1 DAC1 30 Rev. 1.4

C8051F020/1/2/3 2. ABSOLUTE MAXIMUM RATINGS Table 2.1. Absolute Maximum Ratings* PARAMETER CONDITIONS MIN TYP MAX UNITS Ambient temperature under bias -55 125 °C Storage Temperature -65 150 °C Voltage on any Pin (except VDD and Port I/O) with VDD + -0.3 V respect to DGND 0.3 Voltage on any Port I/O Pin or /RST with respect to -0.3 5.8 V DGND Voltage on VDD with respect to DGND -0.3 4.2 V Maximum Total current through VDD, AV+, DGND, 800 mA and AGND Maximum output current sunk by any Port pin 100 mA Maximum output current sunk by any other I/O pin 50 mA Maximum output current sourced by any Port pin 100 mA Maximum output current sourced by any other I/O pin 50 mA * Stresses above those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and functional operation of the devices at those or any other conditions above those indicated in the operation listings of this specification is not implied. Exposure to maximum rating conditions for extended periods may affect device reliability. Rev. 1.4 31

C8051F020/1/2/3 3. GLOBAL DC ELECTRICAL CHARACTERISTICS Table 1.1. Global DC Electrical Characteristics -40°C to +85°C, 25 MHz System Clock unless otherwise specified. PARAMETER CONDITIONS MIN TYP MAX UNITS Analog Supply Voltage 2.7† 3.0 3.6 V Analog Supply Current AV+=2.7 V, Internal REF, ADC, 1.7 mA DAC, Comparators all active Analog Supply Current with AV+=2.7 V, Internal REF, ADC, analog sub-systems inactive DAC, Comparators all disabled, 0.2 µA oscillator disabled, VDD Monitor disabled Analog-to-Digital Supply Delta 0.5 V (|VDD - AV+|) Digital Supply Voltage 2.7 3.0 3.6 V Digital Supply Current with VDD=2.7 V, Clock=25 MHz 10 mA CPU active VDD=2.7 V, Clock=1 MHz 0.5 mA VDD=2.7 V, Clock=32 kHz 20 µA Digital Supply Current with VDD=2.7 V, Clock=25 MHz 5 mA CPU inactive (not accessing VDD=2.7 V, Clock=1 MHz 0.2 mA FLASH) VDD=2.7 V, Clock=32 kHz 10 µA Digital Supply Current (shut- VDD=2.7 V, Oscillator not running, 0.2 µA down) VDD Monitor disabled Digital Supply RAM Data 1.5 V Retention Voltage Specified Operating Tempera- -40 +85 °C ture Range SYSCLK (system clock fre- 0‡ 25 MHz quency) Tsysl (SYSCLK low time) 18 ns Tsysh (SYSCLK high time) 18 ns † Analog Supply AV+ must be greater than 1 V for VDD monitor to operate. ‡ SYSCLK must be at least 32 kHz to enable debugging. 32 Rev. 1.4

C8051F020/1/2/3 4. PINOUT AND PACKAGE DEFINITIONS Table 4.1. Pin Definitions Pin Numbers Name F020 F021 Type Description F022 F023 VDD 37, 64, 24, 41, Digital Supply Voltage. Must be tied to +2.7 to +3.6 V. 90 57 DGND 38, 63, 25, 40, Digital Ground. Must be tied to Ground. 89 56 AV+ 11, 14 6 Analog Supply Voltage. Must be tied to +2.7 to +3.6 V. AGND 10, 13 5 Analog Ground. Must be tied to Ground. TMS 1 58 D In JTAG Test Mode Select with internal pull-up. TCK 2 59 D In JTAG Test Clock with internal pull-up. TDI 3 60 D In JTAG Test Data Input with internal pull-up. TDI is latched on the rising edge of TCK. TDO 4 61 D Out JTAG Test Data Output with internal pull-up. Data is shifted out on TDO on the falling edge of TCK. TDO output is a tri-state driver. /RST 5 62 D I/O Device Reset. Open-drain output of internal VDD monitor. Is driven low when VDD is <2.7 V and MONEN is high. An external source can initiate a system reset by driving this pin low. XTAL1 26 17 A In Crystal Input. This pin is the return for the internal oscillator circuit for a crystal or ceramic resonator. For a precision internal clock, connect a crystal or ceramic resonator from XTAL1 to XTAL2. If overdriven by an external CMOS clock, this becomes the system clock. XTAL2 27 18 A Out Crystal Output. This pin is the excitation driver for a crystal or ceramic resonator. MONEN 28 19 D In VDD Monitor Enable. When tied high, this pin enables the internal VDD monitor, which forces a system reset when VDD is < 2.7 V. When tied low, the internal VDD monitor is disabled. VREF 12 7 A I/O Bandgap Voltage Reference Output (all devices). DAC Voltage Reference Input (F021/3 only). VREFA 8 A In ADC0 and ADC1 Voltage Reference Input. VREF0 16 A In ADC0 Voltage Reference Input. VREF1 17 A In ADC1 Voltage Reference Input. VREFD 15 A In DAC Voltage Reference Input. Rev. 1.4 33

C8051F020/1/2/3 Table 4.1. Pin Definitions Pin Numbers Name F020 F021 Type Description F022 F023 AIN0.0 18 9 A In ADC0 Input Channel 0 (See ADC0 Specification for complete description). AIN0.1 19 10 A In ADC0 Input Channel 1 (See ADC0 Specification for complete description). AIN0.2 20 11 A In ADC0 Input Channel 2 (See ADC0 Specification for complete description). AIN0.3 21 12 A In ADC0 Input Channel 3 (See ADC0 Specification for complete description). AIN0.4 22 13 A In ADC0 Input Channel 4 (See ADC0 Specification for complete description). AIN0.5 23 14 A In ADC0 Input Channel 5 (See ADC0 Specification for complete description). AIN0.6 24 15 A In ADC0 Input Channel 6 (See ADC0 Specification for complete description). AIN0.7 25 16 A In ADC0 Input Channel 7 (See ADC0 Specification for complete description). CP0+ 9 4 A In Comparator 0 Non-Inverting Input. CP0- 8 3 A In Comparator 0 Inverting Input. CP1+ 7 2 A In Comparator 1 Non-Inverting Input. CP1- 6 1 A In Comparator 1 Inverting Input. DAC0 100 64 A Out Digital to Analog Converter 0 Voltage Output. (See DAC Specifica- tion for complete description). DAC1 99 63 A Out Digital to Analog Converter 1 Voltage Output. (See DAC Specifica- tion for complete description). P0.0 62 55 D I/O Port 0.0. See Port Input/Output section for complete description. P0.1 61 54 D I/O Port 0.1. See Port Input/Output section for complete description. P0.2 60 53 D I/O Port 0.2. See Port Input/Output section for complete description. P0.3 59 52 D I/O Port 0.3. See Port Input/Output section for complete description. P0.4 58 51 D I/O Port 0.4. See Port Input/Output section for complete description. ALE/P0.5 57 50 D I/O ALE Strobe for External Memory Address bus (multiplexed mode) Port 0.5 See Port Input/Output section for complete description. 34 Rev. 1.4

C8051F020/1/2/3 Table 4.1. Pin Definitions Pin Numbers Name F020 F021 Type Description F022 F023 /RD/P0.6 56 49 D I/O /RD Strobe for External Memory Address bus Port 0.6 See Port Input/Output section for complete description. /WR/P0.7 55 48 D I/O /WR Strobe for External Memory Address bus Port 0.7 See Port Input/Output section for complete description. AIN1.0/A8/P1.0 36 29 A In ADC1 Input Channel 0 (See ADC1 Specification for complete D I/O description). Bit 8 External Memory Address bus (Non-multiplexed mode) Port 1.0 See Port Input/Output section for complete description. AIN1.1/A9/P1.1 35 28 A In Port 1.1. See Port Input/Output section for complete description. D I/O AIN1.2/A10/P1.2 34 27 A In Port 1.2. See Port Input/Output section for complete description. D I/O AIN1.3/A11/P1.3 33 26 A In Port 1.3. See Port Input/Output section for complete description. D I/O AIN1.4/A12/P1.4 32 23 A In Port 1.4. See Port Input/Output section for complete description. D I/O AIN1.5/A13/P1.5 31 22 A In Port 1.5. See Port Input/Output section for complete description. D I/O AIN1.6/A14/P1.6 30 21 A In Port 1.6. See Port Input/Output section for complete description. D I/O AIN1.7/A15/P1.7 29 20 A In Port 1.7. See Port Input/Output section for complete description. D I/O A8m/A0/P2.0 46 37 D I/O Bit 8 External Memory Address bus (Multiplexed mode) Bit 0 External Memory Address bus (Non-multiplexed mode) Port 2.0 See Port Input/Output section for complete description. A9m/A1/P2.1 45 36 D I/O Port 2.1. See Port Input/Output section for complete description. A10m/A2/P2.2 44 35 D I/O Port 2.2. See Port Input/Output section for complete description. A11m/A3/P2.3 43 34 D I/O Port 2.3. See Port Input/Output section for complete description. A12m/A4/P2.4 42 33 D I/O Port 2.4. See Port Input/Output section for complete description. A13m/A5/P2.5 41 32 D I/O Port 2.5. See Port Input/Output section for complete description. Rev. 1.4 35

C8051F020/1/2/3 Table 4.1. Pin Definitions Pin Numbers Name F020 F021 Type Description F022 F023 A14m/A6/P2.6 40 31 D I/O Port 2.6. See Port Input/Output section for complete description. A15m/A7/P2.7 39 30 D I/O Port 2.7. See Port Input/Output section for complete description. AD0/D0/P3.0 54 47 D I/O Bit 0 External Memory Address/Data bus (Multiplexed mode) Bit 0 External Memory Data bus (Non-multiplexed mode) Port 3.0 See Port Input/Output section for complete description. AD1/D1/P3.1 53 46 D I/O Port 3.1. See Port Input/Output section for complete description. AD2/D2/P3.2 52 45 D I/O Port 3.2. See Port Input/Output section for complete description. AD3/D3/P3.3 51 44 D I/O Port 3.3. See Port Input/Output section for complete description. AD4/D4/P3.4 50 43 D I/O Port 3.4. See Port Input/Output section for complete description. AD5/D5/P3.5 49 42 D I/O Port 3.5. See Port Input/Output section for complete description. AD6/D6/P3.6/IE6 48 39 D I/O Port 3.6. See Port Input/Output section for complete description. AD7/D7/P3.7/IE7 47 38 D I/O Port 3.7. See Port Input/Output section for complete description. P4.0 98 D I/O Port 4.0. See Port Input/Output section for complete description. P4.1 97 D I/O Port 4.1. See Port Input/Output section for complete description. P4.2 96 D I/O Port 4.2. See Port Input/Output section for complete description. P4.3 95 D I/O Port 4.3. See Port Input/Output section for complete description. P4.4 94 D I/O Port 4.4. See Port Input/Output section for complete description. ALE/P4.5 93 D I/O ALE Strobe for External Memory Address bus (multiplexed mode) Port 4.5 See Port Input/Output section for complete description. /RD/P4.6 92 D I/O /RD Strobe for External Memory Address bus Port 4.6 See Port Input/Output section for complete description. /WR/P4.7 91 D I/O /WR Strobe for External Memory Address bus Port 4.7 See Port Input/Output section for complete description. A8/P5.0 88 D I/O Bit 8 External Memory Address bus (Non-multiplexed mode) Port 5.0 See Port Input/Output section for complete description. A9/P5.1 87 D I/O Port 5.1. See Port Input/Output section for complete description. A10/P5.2 86 D I/O Port 5.2. See Port Input/Output section for complete description. 36 Rev. 1.4

C8051F020/1/2/3 Table 4.1. Pin Definitions Pin Numbers Name F020 F021 Type Description F022 F023 A11/P5.3 85 D I/O Port 5.3. See Port Input/Output section for complete description. A12/P5.4 84 D I/O Port 5.4. See Port Input/Output section for complete description. A13/P5.5 83 D I/O Port 5.5. See Port Input/Output section for complete description. A14/P5.6 82 D I/O Port 5.6. See Port Input/Output section for complete description. A15/P5.7 81 D I/O Port 5.7. See Port Input/Output section for complete description. A8m/A0/P6.0 80 D I/O Bit 8 External Memory Address bus (Multiplexed mode) Bit 0 External Memory Address bus (Non-multiplexed mode) Port 6.0 See Port Input/Output section for complete description. A9m/A1/P6.1 79 D I/O Port 6.1. See Port Input/Output section for complete description. A10m/A2/P6.2 78 D I/O Port 6.2. See Port Input/Output section for complete description. A11m/A3/P6.3 77 D I/O Port 6.3. See Port Input/Output section for complete description. A12m/A4/P6.4 76 D I/O Port 6.4. See Port Input/Output section for complete description. A13m/A5/P6.5 75 D I/O Port 6.5. See Port Input/Output section for complete description. A14m/A6/P6.6 74 D I/O Port 6.6. See Port Input/Output section for complete description. A15m/A7/P6.7 73 D I/O Port 6.7. See Port Input/Output section for complete description. AD0/D0/P7.0 72 D I/O Bit 0 External Memory Address/Data bus (Multiplexed mode) Bit 0 External Memory Data bus (Non-multiplexed mode) Port 7.0 See Port Input/Output section for complete description. AD1/D1/P7.1 71 D I/O Port 7.1. See Port Input/Output section for complete description. AD2/D2/P7.2 70 D I/O Port 7.2. See Port Input/Output section for complete description. AD3/D3/P7.3 69 D I/O Port 7.3. See Port Input/Output section for complete description. AD4/D4/P7.4 68 D I/O Port 7.4. See Port Input/Output section for complete description. AD5/D5/P7.5 67 D I/O Port 7.5. See Port Input/Output section for complete description. AD6/D6/P7.6 66 D I/O Port 7.6. See Port Input/Output section for complete description. AD7/D7/P7.7 65 D I/O Port 7.7. See Port Input/Output section for complete description. Rev. 1.4 37

C8051F020/1/2/3 Figure 4.1. TQFP-100 Pinout Diagram 2 3 4 6.0 6.1 P6. P6. P6. DAC0 DAC1 P4.0 P4.1 P4.2 P4.3 P4.4 ALE/P4.5 /RD/P4.6 /WR/P4.7 VDD DGND A8/P5.0 A9/P5.1 A10/P5.2 A11/P5.3 A12/P5.4 A13/P5.5 A14/P5.6 A15/P5.7 A8m/A0/P A9m/A1/P A10m/A2/ A11m/A3/ A12m/A4/ 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 TMS 1 75 A13m/A5/P6.5 TCK 2 74 A14m/A6/P6.6 TDI 3 73 A15m/A7/P6.7 TDO 4 72 AD0/D0/P7.0 /RST 5 71 AD1/D1/P7.1 CP1- 6 70 AD2/D2/P7.2 CP1+ 7 69 AD3/D3/P7.3 CP0- 8 68 AD4/D4/P7.4 CP0+ 9 67 AD5/D5/P7.5 AGND 10 66 AD6/D6/P7.6 AV+ 11 65 AD7/D7/P7.7 VREF 12 C8051F020 64 VDD AGND 13 63 DGND C8051F022 AV+ 14 62 P0.0 VREFD 15 61 P0.1 VREF0 16 60 P0.2 VREF1 17 59 P0.3 AIN0.0 18 58 P0.4 AIN0.1 19 57 ALE/P0.5 AIN0.2 20 56 /RD/P0.6 AIN0.3 21 55 /WR/P0.7 AIN0.4 22 54 AD0/D0/P3.0 AIN0.5 23 53 AD1/D1/P3.1 AIN0.6 24 52 AD2/D2/P3.2 AIN0.7 25 51 AD3/D3/P3.3 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 1 2 N 7 6 5 4 3 2 1 0 D D 7 6 5 4 3 2 1 0 7 6 5 4 XTAL XTAL MONE AIN1.7/A15/P1. AIN1.6/A14/P1. AIN1.5/A13/P1. AIN1.4/A12/P1. AIN1.3/A11/P1. AIN1.2/A10/P1. AIN1.1/A9/P1. AIN1.0/A8/P1. VD DGN A15m/A7/P2. A14m/A6/P2. A13m/A5/P2. A12m/A4/P2. A11m/A3/P2. A10m/A2/P2. A9m/A1/P2. A8m/A0/P2. AD7/D7/P3.7/IE AD6/D6/P3.6/IE AD5/D5/P3. AD4/D4/P3. 38 Rev. 1.4

C8051F020/1/2/3 Figure 4.2. TQFP-100 Package Drawing D MIN NOM MAX (mm) (mm) (mm) D1 A - - 1.20 A1 0.05 - 0.15 A2 0.95 1.00 1.05 b 0.17 0.22 0.27 D - 16.00 - E1 E D1 - 14.00 - e - 0.50 - E - 16.00 - E1 - 14.00 - 100 PIN 1 DESIGNATOR 1 A2 e A b A1 Rev. 1.4 39

C8051F020/1/2/3 Figure 4.3. TQFP-64 Pinout Diagram 5 6 0 1 D P0. P0. DAC DAC /RST TDO TDI TCK TMS VDD DGN P0.0 P0.1 P0.2 P0.3 P0.4 ALE/ /RD/ 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 CP1- 1 48 /WR/P0.7 CP1+ 2 47 AD0/D0/P3.0 CP0- 3 46 AD1/D1/P3.1 CP0+ 4 45 AD2/D2/P3.2 AGND 5 44 AD3/D3/P3.3 AV+ 6 43 AD4/D4/P3.4 VREF 7 42 AD5/D5/P3.5 C8051F021 VREFA 8 41 VDD AIN0.0 9 C8051F023 40 DGND AIN0.1 10 39 AD6/D6/P3.6/IE6 AIN0.2 11 38 AD7/D7/P3.7/IE7 AIN0.3 12 37 A8m/A0/P2.0 AIN0.4 13 36 A9m/A1/P2.1 AIN0.5 14 35 A10m/A2/P2.2 AIN0.6 15 34 A11m/A3/P2.3 AIN0.7 16 33 A12m/A4/P2.4 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 1 2 N 7 6 5 4 D D 3 2 1 0 7 6 5 AL AL NE P1. P1. P1. P1. VD GN P1. P1. P1. P1. P2. P2. P2. XT XT O 5/ 4/ 3/ 2/ D 1/ 0/ 9/ 8/ 7/ 6/ 5/ M 1 1 1 1 1 1 A A A A A 1.7/A 1.6/A 1.5/A 1.4/A 1.3/A 1.2/A N1.1/ N1.0/ 15m/ 14m/ 13m/ AIN AIN AIN AIN AIN AIN AI AI A A A 40 Rev. 1.4

C8051F020/1/2/3 Figure 4.4. TQFP-64 Package Drawing D D1 MIN NOM MAX (mm) (mm) (mm) A - - 1.20 A1 0.05 - 0.15 E1 A2 0.95 - 1.05 E b 0.17 0.22 0.27 D - 12.00 - 64 D1 - 10.00 - PIN 1 DESIGNATOR e - 0.50 - 1 A2 e E - 12.00 - A E1 - 10.00 - b A1 Rev. 1.4 41

C8051F020/1/2/3 Notes 42 Rev. 1.4

C8051F020/1 5. ADC0 (12-BIT ADC, C8051F020/1 ONLY) The ADC0 subsystem for the C8051F020/1 consists of a 9-channel, configurable analog multiplexer (AMUX0), a programmable gain amplifier (PGA0), and a 100 ksps, 12-bit successive-approximation-register ADC with integrated track-and-hold and Programmable Window Detector (see block diagram in Figure 5.1). The AMUX0, PGA0, Data Conversion Modes, and Window Detector are all configurable under software control via the Special Function Regis- ters shown in Figure 5.1. The voltage reference used by ADC0 is selected as described in Section “9. VOLTAGE REFERENCE (C8051F020/2)” on page 91 for C8051F020/2 devices, or Section “10. VOLTAGE REFERENCE (C8051F021/3)” on page 93 for C8051F021/3 devices. The ADC0 subsystem (ADC0, track-and-hold and PGA0) is enabled only when the AD0EN bit in the ADC0 Control register (ADC0CN) is set to logic 1. The ADC0 subsystem is in low power shutdown when this bit is logic 0. Figure 5.1. 12-Bit ADC0 Functional Block Diagram ADC0GTH ADC0GTL ADC0LTH ADC0LTL 24 Comb. AD0WINT Logic AIN0 + AV+ K 12 AIN1 - AD0EN YSCL REF S AIN2 + AV+ H 0 C AIN3 - 9-to-1 12-Bit D A AMUX AIN4 + (SE or X + SAR 12 AIN5 - DIFF) - ADC AIN6 + AGND L 0 AIN7 - C D A TEMP M SENSOR 0C 00 AD0BUSY (W) D A Start Conversion 01 Timer 3 Overflow AGND 10 CNVSTR AIN67ICAIN45ICAIN23ICAIN01IC AMX0AD3AMX0AD2AMX0AD1AMX0AD0 AD0SC4AD0SC3AD0SC2AD0SC1AD0SC0AMP0GN2AMP0GN1AMP0GN0 AD0ENAD0TMAD0INTAD0BUSYAD0CM1AD0CM0AD0WINTAD0LJST CM11 Timer 2 Overflow AMX0CF AMX0SL ADC0CF ADC0CN D0 A 5.1. Analog Multiplexer and PGA Eight of the AMUX channels are available for external measurements while the ninth channel is internally connected to an on-chip temperature sensor (temperature transfer function is shown in Figure 5.2). AMUX input pairs can be programmed to operate in either differential or single-ended mode. This allows the user to select the best measure- ment technique for each input channel, and even accommodates mode changes "on-the-fly". The AMUX defaults to all single-ended inputs upon reset. There are two registers associated with the AMUX: the Channel Selection register AMX0SL (Figure 5.6), and the Configuration register AMX0CF (Figure 5.7). The table in Figure 5.6 shows AMUX functionality by channel, for each possible configuration. The PGA amplifies the AMUX output signal by an amount determined by the states of the AMP0GN2-0 bits in the ADC0 Configuration register, ADC0CF (Figure 5.7). The PGA can be software-programmed for gains of 0.5, 2, 4, 8 or 16. Gain defaults to unity on reset. Rev. 1.4 43

C8051F020/1 The Temperature Sensor transfer function is shown in Figure 5.2. The output voltage (V ) is the PGA input when TEMP the Temperature Sensor is selected by bits AMX0AD3-0 in register AMX0SL; this voltage will be amplified by the PGA according to the user-programmed PGA settings. Figure 5.2. Temperature Sensor Transfer Function (Volts) 1.000 0.900 0.800 V = 0.00286(TEMP ) + 0.776 TEMP C 0.700 for PGA Gain = 1 0.600 0.500 -50 0 50 100 (Celsius) 5.2. ADC Modes of Operation ADC0 has a maximum conversion speed of 100 ksps. The ADC0 conversion clock is derived from the system clock divided by the value held in the ADCSC bits of register ADC0CF. 5.2.1. Starting a Conversion A conversion can be initiated in one of four ways, depending on the programmed states of the ADC0 Start of Conver- sion Mode bits (AD0CM1, AD0CM0) in ADC0CN. Conversions may be initiated by: 1. Writing a ‘1’ to the AD0BUSY bit of ADC0CN; 2. A Timer 3 overflow (i.e. timed continuous conversions); 3. A rising edge detected on the external ADC convert start signal, CNVSTR; 4. A Timer 2 overflow (i.e. timed continuous conversions). The AD0BUSY bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete. The fall- ing edge of AD0BUSY triggers an interrupt (when enabled) and sets the AD0INT interrupt flag (ADC0CN.5). Con- verted data is available in the ADC0 data word MSB and LSB registers, ADC0H, ADC0L. Converted data can be either left or right justified in the ADC0H:ADC0L register pair (see example in Figure 5.11) depending on the pro- grammed state of the AD0LJST bit in the ADC0CN register. When initiating conversions by writing a ‘1’ to AD0BUSY, the AD0INT bit should be polled to determine when a conversion has completed (ADC0 interrupts may also be used). The recommended polling procedure is shown below. Step 1. Write a ‘0’ to AD0INT; Step 2. Write a ‘1’ to AD0BUSY; Step 3. Poll AD0INT for ‘1’; Step 4. Process ADC0 data. 44 Rev. 1.4

C8051F020/1 5.2.2. Tracking Modes The AD0TM bit in register ADC0CN controls the ADC0 track-and-hold mode. In its default state, the ADC0 input is continuously tracked when a conversion is not in progress. When the AD0TM bit is logic 1, ADC0 operates in low- power track-and-hold mode. In this mode, each conversion is preceded by a tracking period of 3 SAR clocks (after the start-of-conversion signal). When the CNVSTR signal is used to initiate conversions in low-power tracking mode, ADC0 tracks only when CNVSTR is low; conversion begins on the rising edge of CNVSTR (see Figure 5.3). Track- ing can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. Low-power track- and-hold mode is also useful when AMUX or PGA settings are frequently changed, to ensure that settling time requirements are met (see Section “5.2.3. Settling Time Requirements” on page 46). Figure 5.3. 12-Bit ADC Track and Conversion Example Timing A. ADC Timing for External Trigger Source CNVSTR (AD0STM[1:0]=10 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 SAR Clocks Low Power ADC0TM=1 Track Convert Low Power Mode or Convert ADC0TM=0 Track Or Convert Convert Track B. ADC Timing for Internal Trigger Sources Timer 2, Timer 3 Overflow; Write '1' to AD0BUSY (AD0STM[1:0]=00, 01, 11) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 SAR Clocks Low Power ADC0TM=1 Track Convert Low Power Mode or Convert 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 SAR Clocks Track or ADC0TM=0 Convert Track Convert Rev. 1.4 45

C8051F020/1 5.2.3. Settling Time Requirements When the ADC0 input configuration is changed (i.e., a different MUX or PGA selection is made), a minimum settling (or tracking) time is required before an accurate conversion can be performed. This settling time is determined by the ADC0 MUX resistance, the ADC0 sampling capacitance, any external source resistance, and the accuracy required for the conversion. Figure 5.4 shows the equivalent ADC0 input circuits for both Differential and Single-ended modes. Notice that the equivalent time constant for both input circuits is the same. The required settling time for a given settling accuracy (SA) may be approximated by Equation 5.1. When measuring the Temperature Sensor output, R reduces to R . Note that in low-power tracking mode, three SAR clocks are used for tracking at the start of TOTAL MUX every conversion. For most applications, these three SAR clocks will meet the tracking requirements. See Table 5.1 on page 58 for absolute minimum settling/tracking time requirements. Equation 5.1. ADC0 Settling Time Requirements t = ln-2----n-- × R C SA TOTAL SAMPLE Where: SA is the settling accuracy, given as a fraction of an LSB (for example, 0.25 to settle within 1/4 LSB) t is the required settling time in seconds R is the sum of the ADC0 MUX resistance and any external source resistance. TOTAL n is the ADC resolution in bits (12). Figure 5.4. ADC0 Equivalent Input Circuits Differential Mode Single-Ended Mode MUX Select MUX Select AIN0.x AIN0.x R = 5k R = 5k MUX MUX C = 10pF C = 10pF SAMPLE SAMPLE RC = R * C RC = R * C Input MUX SAMPLE Input MUX SAMPLE C = 10pF SAMPLE AIN0.y R = 5k MUX MUX Select 46 Rev. 1.4

C8051F020/1 Figure 5.5. AMX0CF: AMUX0 Configuration Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - AIN67IC AIN45IC AIN23IC AIN01IC 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBA Bits7-4: UNUSED. Read = 0000b; Write = don’t care Bit3: AIN67IC: AIN6, AIN7 Input Pair Configuration Bit 0: AIN6 and AIN7 are independent single-ended inputs 1: AIN6, AIN7 are (respectively) +, - differential input pair Bit2: AIN45IC: AIN4, AIN5 Input Pair Configuration Bit 0: AIN4 and AIN5 are independent single-ended inputs 1: AIN4, AIN5 are (respectively) +, - differential input pair Bit1: AIN23IC: AIN2, AIN3 Input Pair Configuration Bit 0: AIN2 and AIN3 are independent single-ended inputs 1: AIN2, AIN3 are (respectively) +, - differential input pair Bit0: AIN01IC: AIN0, AIN1 Input Pair Configuration Bit 0: AIN0 and AIN1 are independent single-ended inputs 1: AIN0, AIN1 are (respectively) +, - differential input pair NOTE: The ADC0 Data Word is in 2’s complement format for channels configured as differential. Rev. 1.4 47

C8051F020/1 Figure 5.6. AMX0SL: AMUX0 Channel Select Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - AMX0AD3AMX0AD2AMX0AD1AMX0AD0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBB Bits7-4: UNUSED. Read = 0000b; Write = don’t care Bits3-0: AMX0AD3-0: AMX0 Address Bits 0000-1111b: ADC Inputs selected per chart below AMX0AD3-0 0000 0001 0010 0011 0100 0101 0110 0111 1xxx TEMP 0000 AIN0 AIN1 AIN2 AIN3 AIN4 AIN5 AIN6 AIN7 SENSOR +(AIN0) TEMP 0001 AIN2 AIN3 AIN4 AIN5 AIN6 AIN7 -(AIN1) SENSOR +(AIN2) TEMP 0010 AIN0 AIN1 AIN4 AIN5 AIN6 AIN7 -(AIN3) SENSOR +(AIN0) +(AIN2) TEMP 0011 AIN4 AIN5 AIN6 AIN7 -(AIN1) -(AIN3) SENSOR +(AIN4) TEMP 0100 AIN0 AIN1 AIN2 AIN3 AIN6 AIN7 -(AIN5) SENSOR +(AIN0) +(AIN4) TEMP 0101 AIN2 AIN3 AIN6 AIN7 -(AIN1) -(AIN5) SENSOR +(AIN2) +(AIN4) TEMP -0 0110 AIN0 AIN1 -(AIN3) -(AIN5) AIN6 AIN7 SENSOR 3 s +(AIN0) +(AIN2) +(AIN4) TEMP Bit 0111 -(AIN1) -(AIN3) -(AIN5) AIN6 AIN7 SENSOR F C 1000 AIN0 AIN1 AIN2 AIN3 AIN4 AIN5 +(AIN6) TEMP 0 -(AIN7) SENSOR X M +(AIN0) +(AIN6) TEMP 1001 AIN2 AIN3 AIN4 AIN5 A -(AIN1) -(AIN7) SENSOR +(AIN2) +(AIN6) TEMP 1010 AIN0 AIN1 AIN4 AIN5 -(AIN3) -(AIN7) SENSOR +(AIN0) +(AIN2) +(AIN6) TEMP 1011 AIN4 AIN5 -(AIN1) -(AIN3) -(AIN7) SENSOR +(AIN4) +(AIN6) TEMP 1100 AIN0 AIN1 AIN2 AIN3 -(AIN5) -(AIN7) SENSOR +(AIN0) +(AIN4) +(AIN6) TEMP 1101 AIN2 AIN3 -(AIN1) -(AIN5) -(AIN7) SENSOR +(AIN2) +(AIN4) +(AIN6) TEMP 1110 AIN0 AIN1 -(AIN3) -(AIN5) -(AIN7) SENSOR +(AIN0) +(AIN2) +(AIN4) +(AIN6) TEMP 1111 -(AIN1) -(AIN3) -(AIN5) -(AIN7) SENSOR 48 Rev. 1.4

C8051F020/1 Figure 5.7. ADC0CF: ADC0 Configuration Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD0SC4 AD0SC3 AD0SC2 AD0SC1 AD0SC0 AMP0GN2 AMP0GN1 AMP0GN0 11111000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBC Bits7-3: AD0SC4-0: ADC0 SAR Conversion Clock Period Bits SAR Conversion clock is derived from system clock by the following equation, where AD0SC refers to the 5-bit value held in AD0SC4-0, and CLK refers to the desired ADC0 SAR clock. See SAR0 Table 5.1 on page 58 for SAR clock setting requirements. SYSCLK AD0SC = ----------------------- –1 CLK SAR0 Bits2-0: AMP0GN2-0: ADC0 Internal Amplifier Gain (PGA) 000: Gain = 1 001: Gain = 2 010: Gain = 4 011: Gain = 8 10x: Gain = 16 11x: Gain = 0.5 Rev. 1.4 49

C8051F020/1 Figure 5.8. ADC0CN: ADC0 Control Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD0EN AD0TM AD0INT AD0BUSY AD0CM1 AD0CM0 AD0WINT AD0LJST 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xE8 Bit7: AD0EN: ADC0 Enable Bit. 0: ADC0 Disabled. ADC0 is in low-power shutdown. 1: ADC0 Enabled. ADC0 is active and ready for data conversions. Bit6: AD0TM: ADC Track Mode Bit 0: When the ADC is enabled, tracking is continuous unless a conversion is in process 1: Tracking Defined by ADSTM1-0 bits Bit5: AD0INT: ADC0 Conversion Complete Interrupt Flag. This flag must be cleared by software. 0: ADC0 has not completed a data conversion since the last time this flag was cleared. 1: ADC0 has completed a data conversion. Bit4: AD0BUSY: ADC0 Busy Bit. Read: 0: ADC0 Conversion is complete or a conversion is not currently in progress. AD0INT is set to logic 1 on the falling edge of AD0BUSY. 1: ADC0 Conversion is in progress. Write: 0: No Effect. 1: Initiates ADC0 Conversion if AD0STM1-0 = 00b Bit3-2: AD0CM1-0: ADC0 Start of Conversion Mode Select. If AD0TM = 0: 00: ADC0 conversion initiated on every write of ‘1’ to AD0BUSY. 01: ADC0 conversion initiated on overflow of Timer 3. 10: ADC0 conversion initiated on rising edge of external CNVSTR. 11: ADC0 conversion initiated on overflow of Timer 2. If AD0TM = 1: 00: Tracking starts with the write of ‘1’ to AD0BUSY and lasts for 3 SAR clocks, followed by con- version. 01: Tracking started by the overflow of Timer 3 and last for 3 SAR clocks, followed by conversion. 10: ADC0 tracks only when CNVSTR input is logic low; conversion starts on rising CNVSTR edge. 11: Tracking started by the overflow of Timer 2 and last for 3 SAR clocks, followed by conversion. Bit1: AD0WINT: ADC0 Window Compare Interrupt Flag. This bit must be cleared by software. 0: ADC0 Window Comparison Data match has not occurred since this flag was last cleared. 1: ADC0 Window Comparison Data match has occurred. Bit0: AD0LJST: ADC0 Left Justify Select. 0: Data in ADC0H:ADC0L registers are right-justified. 1: Data in ADC0H:ADC0L registers are left-justified. 50 Rev. 1.4

C8051F020/1 Figure 5.9. ADC0H: ADC0 Data Word MSB Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBF Bits7-0: ADC0 Data Word High-Order Bits. For AD0LJST = 0: Bits 7-4 are the sign extension of Bit3. Bits 3-0 are the upper 4 bits of the 12-bit ADC0 Data Word. For AD0LJST = 1: Bits 7-0 are the most-significant bits of the 12-bit ADC0 Data Word. Figure 5.10. ADC0L: ADC0 Data Word LSB Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBE Bits7-0: ADC0 Data Word Low-Order Bits. For AD0LJST = 0: Bits 7-0 are the lower 8 bits of the 12-bit ADC0 Data Word. For AD0LJST = 1: Bits 7-4 are the lower 4 bits of the 12-bit ADC0 Data Word. Bits3-0 will always read ‘0’. Rev. 1.4 51

C8051F020/1 Figure 5.11. ADC0 Data Word Example (C8051F020/1) 12-bit ADC0 Data Word appears in the ADC0 Data Word Registers as follows: ADC0H[3:0]:ADC0L[7:0], if AD0LJST = 0 (ADC0H[7:4] will be sign-extension of ADC0H.3 for a differential reading, otherwise = 0000b). ADC0H[7:0]:ADC0L[7:4], if AD0LJST = 1 (ADC0L[3:0] = 0000b). Example: ADC0 Data Word Conversion Map, AIN0 Input in Single-Ended Mode (AMX0CF = 0x00, AMX0SL = 0x00) ADC0H:ADC0L ADC0H:ADC0L AIN0-AGND (Volts) (AD0LJST = 0) (AD0LJST = 1) VREF * (4095/4096) 0x0FFF 0xFFF0 VREF / 2 0x0800 0x8000 VREF * (2047/4096) 0x07FF 0x7FF0 0 0x0000 0x0000 Example: ADC0 Data Word Conversion Map, AIN0-AIN1 Differential Input Pair (AMX0CF = 0x01, AMX0SL = 0x00) ADC0H:ADC0L ADC0H:ADC0L AIN0-AGND (Volts) (AD0LJST = 0) (AD0LJST = 1) VREF * (2047/2048) 0x07FF 0x7FF0 VREF / 2 0x0400 0x4000 VREF * (1/2048) 0x0001 0x0010 0 0x0000 0x0000 -VREF * (1/2048) 0xFFFF (-1d) 0xFFF0 -VREF / 2 0xFC00 (-1024d) 0xC000 -VREF 0xF800 (-2048d) 0x8000 For AD0LJST = 0: Gain Code = Vin× --------------- × 2n; ‘n’ = 12 for Single-Ended; ‘n’=11 for Differential. VREF 52 Rev. 1.4

C8051F020/1 5.3. ADC0 Programmable Window Detector The ADC0 Programmable Window Detector continuously compares the ADC0 output to user-programmed limits, and notifies the system when an out-of-bound condition is detected. This is especially effective in an interrupt-driven system, saving code space and CPU bandwidth while delivering faster system response times. The window detector interrupt flag (AD0WINT in ADC0CN) can also be used in polled mode. The high and low bytes of the reference words are loaded into the ADC0 Greater-Than and ADC0 Less-Than registers (ADC0GTH, ADC0GTL, ADC0LTH, and ADC0LTL). Reference comparisons are shown starting on page 54. Notice that the window detector flag can be asserted when the measured data is inside or outside the user-programmed limits, depending on the programming of the ADC0GTx and ADC0LTx registers. Figure 5.12. ADC0GTH: ADC0 Greater-Than Data High Byte Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC5 Bits7-0: High byte of ADC0 Greater-Than Data Word. Figure 5.13. ADC0GTL: ADC0 Greater-Than Data Low Byte Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC4 Bits7-0: Low byte of ADC0 Greater-Than Data Word. Figure 5.14. ADC0LTH: ADC0 Less-Than Data High Byte Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC7 Bits7-0: High byte of ADC0 Less-Than Data Word. Figure 5.15. ADC0LTL: ADC0 Less-Than Data Low Byte Register (C8051F020/1) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC6 Bits7-0: Low byte of ADC0 Less-Than Data Word. Rev. 1.4 53

C8051F020/1 Figure 5.16. 12-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AGND) Word (AD0 - AGND) Word REF x (4095/4096) 0x0FFF REF x (4095/4096) 0x0FFF AD0WINT AD0WINT=1 not affected 0x0201 0x0201 REF x (512/4096) 0x0200 ADC0LTH:ADC0LTL REF x (512/4096) 0x0200 ADC0GTH:ADC0GTL 0x01FF 0x01FF AD0WINT AD0WINT=1 not affected 0x0101 0x0101 REF x (256/4096) 0x0100 ADC0GTH:ADC0GTL REF x (256/4096) 0x0100 ADC0LTH:ADC0LTL 0x00FF 0x00FF AD0WINT AD0WINT=1 not affected 0 0x0000 0 0x0000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x00 AMX0SL = 0x00, AMX0CF = 0x00, AD0LJST = ‘0’, AD0LJST = ‘0’, ADC0LTH:ADC0LTL = 0x0200, ADC0LTH:ADC0LTL = 0x0100, ADC0GTH:ADC0GTL = 0x0100. ADC0GTH:ADC0GTL = 0x0200. An ADC0 End of Conversion will cause an ADC0 An ADC0 End of Conversion will cause an ADC0 Window Compare Interrupt (AD0WINT = ‘1’) if Window Compare Interrupt (AD0WINT = ‘1’) if the resulting ADC0 Data Word is < 0x0200 and the resulting ADC0 Data Word is > 0x0200 or > 0x0100. < 0x0100. 54 Rev. 1.4

C8051F020/1 Figure 5.17. 12-Bit ADC0 Window Interrupt Example: Right Justified Differential Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AD1) Word (AD0 - AD1) Word REF x (2047/2048) 0x07FF REF x (2047/2048) 0x07FF AD0WINT AD0WINT=1 not affected 0x0101 0x0101 REF x (256/2048) 0x0100 ADC0LTH:ADC0LTL REF x (256/2048) 0x0100 ADC0GTH:ADC0GTL 0x00FF 0x00FF AD0WINT AD0WINT=1 not affected 0x0000 0x0000 REF x (-1/2048) 0xFFFF ADC0GTH:ADC0GTL REF x (-1/2048) 0xFFFF ADC0LTH:ADC0LTL 0xFFFE 0xFFFE AD0WINT AD0WINT=1 not affected -REF 0xF800 -REF 0xF800 Given: Given: AMX0SL = 0x00, AMX0CF = 0x01, AMX0SL = 0x00, AMX0CF = 0x01, AD0LJST = ‘0’, AD0LJST = ‘0’, ADC0LTH:ADC0LTL = 0x0100, ADC0LTH:ADC0LTL = 0xFFFF, ADC0GTH:ADC0GTL = 0xFFFF. ADC0GTH:ADC0GTL = 0x0100. An ADC0 End of Conversion will cause an ADC0 An ADC0 End of Conversion will cause an ADC0 Window Compare Interrupt (AD0WINT = ‘1’) if Window Compare Interrupt (AD0WINT = ‘1’) if the resulting ADC0 Data Word is < 0x0100 and the resulting ADC0 Data Word is < 0xFFFF or > 0xFFFF. (In two’s-complement math, > 0x0100. (In two’s-complement math, 0xFFFF = -1.) 0xFFFF = -1.) Rev. 1.4 55

C8051F020/1 Figure 5.18. 12-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AGND) Word (AD0 - AGND) Word REF x (4095/4096) 0xFFF0 REF x (4095/4096) 0xFFF0 AD0WINT AD0WINT=1 not affected 0x2010 0x2010 REF x (512/4096) 0x2000 ADC0LTH:ADC0LTL REF x (512/4096) 0x2000 ADC0GTH:ADC0GTL 0x1FF0 0x1FF0 AD0WINT AD0WINT=1 not affected 0x1010 0x1010 REF x (256/4096) 0x1000 ADC0GTH:ADC0GTL REF x (256/4096) 0x1000 ADC0LTH:ADC0LTL 0x0FF0 0x0FF0 AD0WINT AD0WINT=1 not affected 0 0x0000 0 0x0000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x00, AMX0SL = 0x00, AMX0CF = 0x00, AD0LJST = ‘1’, AD0LJST = ‘1’ ADC0LTH:ADC0LTL = 0x2000, ADC0LTH:ADC0LTL = 0x1000, ADC0GTH:ADC0GTL = 0x1000. ADC0GTH:ADC0GTL = 0x2000. An ADC0 End of Conversion will cause an ADC0 An ADC0 End of Conversion will cause an ADC0 Window Compare Interrupt (AD0WINT = ‘1’) if Window Compare Interrupt (AD0WINT = ‘1’) if the resulting ADC0 Data Word is < 0x2000 and the resulting ADC0 Data Word is < 0x1000 or > 0x1000. > 0x2000. 56 Rev. 1.4

C8051F020/1 Figure 5.19. 12-Bit ADC0 Window Interrupt Example: Left Justified Differential Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AD1) Word (AD0 - AD1) Word REF x (2047/2048) 0x7FF0 REF x (2047/2048) 0x7FF0 AD0WINT AD0WINT=1 not affected 0x1010 0x1010 REF x (256/2048) 0x1000 ADC0LTH:ADC0LTL REF x (256/2048) 0x1000 ADC0GTH:ADC0GTL 0x0FF0 0x0FF0 AD0WINT AD0WINT=1 not affected 0x0000 0x0000 REF x (-1/2048) 0xFFF0 ADC0GTH:ADC0GTL REF x (-1/2048) 0xFFF0 ADC0LTH:ADC0LTL 0xFFE0 0xFFE0 AD0WINT AD0WINT=1 not affected -REF 0x8000 -REF 0x8000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x01, AMX0SL = 0x00, AMX0CF = 0x01, AD0LJST = ‘1’, AD0LJST = ‘1’, ADC0LTH:ADC0LTL = 0x1000, ADC0LTH:ADC0LTL = 0xFFF0, ADC0GTH:ADC0GTL = 0xFFF0. ADC0GTH:ADC0GTL = 0x1000. An ADC0 End of Conversion will cause an ADC0 An ADC0 End of Conversion will cause an ADC0 Window Compare Interrupt (AD0WINT = ‘1’) if Window Compare Interrupt (AD0WINT = ‘1’) if the resulting ADC0 Data Word is < 0x1000 and the resulting ADC0 Data Word is < 0xFFF0 or > 0xFFF0. (Two’s-complement math.) > 0x1000. (Two’s-complement math.) Rev. 1.4 57

C8051F020/1 Table 5.1. 12-Bit ADC0 Electrical Characteristics (C8051F020/1) VDD = 3.0V, AV+ = 3.0V, VREF = 2.40V (REFBE=0), PGA Gain = 1, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS DC ACCURACY Resolution 12 bits Integral Nonlinearity ±1 LSB Differential Nonlinearity Guaranteed Monotonic ±1 LSB Offset Error -3±1 LSB Full Scale Error Differential mode -7±3 LSB Offset Temperature Coefficient ±0.25 ppm/°C DYNAMIC PERFORMANCE (10 kHz sine-wave input, 0 to 1 dB below Full Scale, 100 ksps Signal-to-Noise Plus Distortion 66 dB Total Harmonic Distortion Up to the 5th harmonic -75 dB Spurious-Free Dynamic Range 80 dB CONVERSION RATE SAR Clock Frequency 2.5 MHz Conversion Time in SAR Clocks 16 clocks Track/Hold Acquisition Time 1.5 µs Throughput Rate 100 ksps ANALOG INPUTS Input Voltage Range Single-ended operation 0 VREF V *Common-mode Voltage Range Differential operation AGND AV+ V Input Capacitance 10 pF TEMPERATURE SENSOR Nonlinearity -1.0 +1.0 °C Absolute Accuracy ±3 °C Gain PGA Gain = 1 2.86 mV/°C Offset PGA Gain = 1, Temp = 0°C 0.776 V POWER SPECIFICATIONS Power Supply Current (AV+ sup- Operating Mode, 100 ksps 450 900 µA plied to ADC) Power Supply Rejection ±0.3 mV/V 58 Rev. 1.4

C8051F022/3 6. ADC0 (10-BIT ADC, C8051F022/3 ONLY) The ADC0 subsystem for the C8051F022/3 consists of a 9-channel, configurable analog multiplexer (AMUX0), a programmable gain amplifier (PGA0), and a 100 ksps, 10-bit successive-approximation-register ADC with integrated track-and-hold and Programmable Window Detector (see block diagram in Figure 6.1). The AMUX0, PGA0, Data Conversion Modes, and Window Detector are all configurable under software control via the Special Function Regis- ters shown in Figure 6.1. The voltage reference used by ADC0 is selected as described in Section “9. VOLTAGE REFERENCE (C8051F020/2)” on page 91 for C8051F020/2 devices, or Section “10. VOLTAGE REFERENCE (C8051F021/3)” on page 93 for C8051F021/3 devices. The ADC0 subsystem (ADC0, track-and-hold and PGA0) is enabled only when the AD0EN bit in the ADC0 Control register (ADC0CN) is set to logic 1. The ADC0 subsystem is in low power shutdown when this bit is logic 0. Figure 6.1. 10-Bit ADC0 Functional Block Diagram ADC0GTH ADC0GTL ADC0LTH ADC0LTL 20 Comb. AD0WINT Logic AIN0 + AV+ K 10 L C AIN1 - AD0EN SYS REF AIN2 + AV+ H 0 C AIN3 - 9-to-1 10-Bit D A AMUX AIN4 + (SE or X + SAR 10 AIN5 - DIFF) - ADC AIN6 + AGND L 0 AIN7 - C D A TEMP M SENSOR 0C 00 AD0BUSY (W) D A Start Conversion 01 Timer 3 Overflow AGND 10 CNVSTR AIN67ICAIN45ICAIN23ICAIN01IC AMX0AD3AMX0AD2AMX0AD1AMX0AD0 AD0SC4AD0SC3AD0SC2AD0SC1AD0SC0AMP0GN2AMP0GN1AMP0GN0 AD0ENAD0TMAD0INTAD0BUSYAD0CM1AD0CM0AD0WINTAD0LJST CM11 Timer 2 Overflow AMX0CF AMX0SL ADC0CF ADC0CN D0 A 6.1. Analog Multiplexer and PGA Eight of the AMUX channels are available for external measurements while the ninth channel is internally connected to an on-chip temperature sensor (temperature transfer function is shown in Figure 6.2). AMUX input pairs can be programmed to operate in either differential or single-ended mode. This allows the user to select the best measure- ment technique for each input channel, and even accommodates mode changes "on-the-fly". The AMUX defaults to all single-ended inputs upon reset. There are two registers associated with the AMUX: the Channel Selection register AMX0SL (Figure 6.6), and the Configuration register AMX0CF (Figure 6.7). The table in Figure 6.6 shows AMUX functionality by channel, for each possible configuration. The PGA amplifies the AMUX output signal by an amount determined by the states of the AMP0GN2-0 bits in the ADC0 Configuration register, ADC0CF (Figure 6.7). The PGA can be software-programmed for gains of 0.5, 2, 4, 8 or 16. Gain defaults to unity on reset. Rev. 1.4 59

C8051F022/3 The Temperature Sensor transfer function is shown in Figure 6.2. The output voltage (V ) is the PGA input when TEMP the Temperature Sensor is selected by bits AMX0AD3-0 in register AMX0SL; this voltage will be amplified by the PGA according to the user-programmed PGA settings. Figure 6.2. Temperature Sensor Transfer Function (Volts) 1.000 0.900 0.800 V = 0.00286(TEMP ) + 0.776 TEMP C 0.700 for PGA Gain = 1 0.600 0.500 -50 0 50 100 (Celsius) 6.2. ADC Modes of Operation ADC0 has a maximum conversion speed of 100 ksps. The ADC0 conversion clock is derived from the system clock divided by the value held in the ADCSC bits of register ADC0CF. 6.2.1. Starting a Conversion A conversion can be initiated in one of four ways, depending on the programmed states of the ADC0 Start of Conver- sion Mode bits (AD0CM1, AD0CM0) in ADC0CN. Conversions may be initiated by: 1. Writing a ‘1’ to the AD0BUSY bit of ADC0CN; 2. A Timer 3 overflow (i.e. timed continuous conversions); 3. A rising edge detected on the external ADC convert start signal, CNVSTR; 4. A Timer 2 overflow (i.e. timed continuous conversions). The AD0BUSY bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete. The fall- ing edge of AD0BUSY triggers an interrupt (when enabled) and sets the AD0INT interrupt flag (ADC0CN.5). Con- verted data is available in the ADC0 data word MSB and LSB registers, ADC0H, ADC0L. Converted data can be either left or right justified in the ADC0H:ADC0L register pair (see example in Figure 6.11) depending on the pro- grammed state of the AD0LJST bit in the ADC0CN register. When initiating conversions by writing a ‘1’ to AD0BUSY, the AD0INT bit should be polled to determine when a conversion has completed (ADC0 interrupts may also be used). The recommended polling procedure is shown below. Step 1. Write a ‘0’ to AD0INT; Step 2. Write a ‘1’ to AD0BUSY; Step 3. Poll AD0INT for ‘1’; Step 4. Process ADC0 data. 60 Rev. 1.4

C8051F022/3 6.2.2. Tracking Modes The AD0TM bit in register ADC0CN controls the ADC0 track-and-hold mode. In its default state, the ADC0 input is continuously tracked when a conversion is not in progress. When the AD0TM bit is logic 1, ADC0 operates in low- power track-and-hold mode. In this mode, each conversion is preceded by a tracking period of 3 SAR clocks (after the start-of-conversion signal). When the CNVSTR signal is used to initiate conversions in low-power tracking mode, ADC0 tracks only when CNVSTR is low; conversion begins on the rising edge of CNVSTR (see Figure 6.3). Track- ing can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. Low-power track- and-hold mode is also useful when AMUX or PGA settings are frequently changed, to ensure that settling time requirements are met (see Section “6.2.3. Settling Time Requirements” on page 62). Figure 6.3. 10-Bit ADC Track and Conversion Example Timing A. ADC Timing for External Trigger Source CNVSTR (AD0STM[1:0]=10 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 SAR Clocks Low Power ADC0TM=1 Track Convert Low Power Mode or Convert ADC0TM=0 Track Or Convert Convert Track B. ADC Timing for Internal Trigger Sources Timer 2, Timer 3 Overflow; Write '1' to AD0BUSY (AD0STM[1:0]=00, 01, 11) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 SAR Clocks Low Power ADC0TM=1 Track Convert Low Power Mode or Convert 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 SAR Clocks Track or ADC0TM=0 Convert Track Convert Rev. 1.4 61

C8051F022/3 6.2.3. Settling Time Requirements When the ADC0 input configuration is changed (i.e., a different MUX or PGA selection is made), a minimum settling (or tracking) time is required before an accurate conversion can be performed. This settling time is determined by the ADC0 MUX resistance, the ADC0 sampling capacitance, any external source resistance, and the accuracy required for the conversion. Figure 6.4 shows the equivalent ADC0 input circuits for both Differential and Single-ended modes. Notice that the equivalent time constant for both input circuits is the same. The required settling time for a given settling accuracy (SA) may be approximated by Equation 6.1. When measuring the Temperature Sensor output, R reduces to R . Note that in low-power tracking mode, three SAR clocks are used for tracking at the start of TOTAL MUX every conversion. For most applications, these three SAR clocks will meet the settling time requirements. See Table 6.1 on page 74 for minimum settling/tracking time requirements. Equation 6.1. ADC0 Settling Time Requirements t = ln-2----n-- × R C SA TOTAL SAMPLE Where: SA is the settling accuracy, given as a fraction of an LSB (for example, 0.25 to settle within 1/4 LSB) t is the required settling time in seconds R is the sum of the ADC0 MUX resistance and any external source resistance. TOTAL n is the ADC resolution in bits (10). Figure 6.4. ADC0 Equivalent Input Circuits Differential Mode Single-Ended Mode MUX Select MUX Select AIN0.x AIN0.x R = 5k R = 5k MUX MUX C = 10pF C = 10pF SAMPLE SAMPLE RC = R * C RC = R * C Input MUX SAMPLE Input MUX SAMPLE C = 10pF SAMPLE AIN0.y R = 5k MUX MUX Select 62 Rev. 1.4

C8051F022/3 Figure 6.5. AMX0CF: AMUX0 Configuration Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - AIN67IC AIN45IC AIN23IC AIN01IC 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBA Bits7-4: UNUSED. Read = 0000b; Write = don’t care Bit3: AIN67IC: AIN6, AIN7 Input Pair Configuration Bit 0: AIN6 and AIN7 are independent single-ended inputs 1: AIN6, AIN7 are (respectively) +, - differential input pair Bit2: AIN45IC: AIN4, AIN5 Input Pair Configuration Bit 0: AIN4 and AIN5 are independent single-ended inputs 1: AIN4, AIN5 are (respectively) +, - differential input pair Bit1: AIN23IC: AIN2, AIN3 Input Pair Configuration Bit 0: AIN2 and AIN3 are independent single-ended inputs 1: AIN2, AIN3 are (respectively) +, - differential input pair Bit0: AIN01IC: AIN0, AIN1 Input Pair Configuration Bit 0: AIN0 and AIN1 are independent single-ended inputs 1: AIN0, AIN1 are (respectively) +, - differential input pair NOTE: The ADC0 Data Word is in 2’s complement format for channels configured as differential. Rev. 1.4 63

C8051F022/3 Figure 6.6. AMX0SL: AMUX0 Channel Select Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - AMX0AD3AMX0AD2AMX0AD1AMX0AD0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBB Bits7-4: UNUSED. Read = 0000b; Write = don’t care Bits3-0: AMX0AD3-0: AMX0 Address Bits 0000-1111b: ADC Inputs selected per chart below AMX0AD3-0 0000 0001 0010 0011 0100 0101 0110 0111 1xxx TEMP 0000 AIN0 AIN1 AIN2 AIN3 AIN4 AIN5 AIN6 AIN7 SENSOR +(AIN0) TEMP 0001 AIN2 AIN3 AIN4 AIN5 AIN6 AIN7 -(AIN1) SENSOR +(AIN2) TEMP 0010 AIN0 AIN1 AIN4 AIN5 AIN6 AIN7 -(AIN3) SENSOR +(AIN0) +(AIN2) TEMP 0011 AIN4 AIN5 AIN6 AIN7 -(AIN1) -(AIN3) SENSOR +(AIN4) TEMP 0100 AIN0 AIN1 AIN2 AIN3 AIN6 AIN7 -(AIN5) SENSOR +(AIN0) +(AIN4) TEMP 0101 AIN2 AIN3 AIN6 AIN7 -(AIN1) -(AIN5) SENSOR +(AIN2) +(AIN4) TEMP -0 0110 AIN0 AIN1 -(AIN3) -(AIN5) AIN6 AIN7 SENSOR 3 s +(AIN0) +(AIN2) +(AIN4) TEMP Bit 0111 -(AIN1) -(AIN3) -(AIN5) AIN6 AIN7 SENSOR F C 1000 AIN0 AIN1 AIN2 AIN3 AIN4 AIN5 +(AIN6) TEMP 0 -(AIN7) SENSOR X M +(AIN0) +(AIN6) TEMP 1001 AIN2 AIN3 AIN4 AIN5 A -(AIN1) -(AIN7) SENSOR +(AIN2) +(AIN6) TEMP 1010 AIN0 AIN1 AIN4 AIN5 -(AIN3) -(AIN7) SENSOR +(AIN0) +(AIN2) +(AIN6) TEMP 1011 AIN4 AIN5 -(AIN1) -(AIN3) -(AIN7) SENSOR +(AIN4) +(AIN6) TEMP 1100 AIN0 AIN1 AIN2 AIN3 -(AIN5) -(AIN7) SENSOR +(AIN0) +(AIN4) +(AIN6) TEMP 1101 AIN2 AIN3 -(AIN1) -(AIN5) -(AIN7) SENSOR +(AIN2) +(AIN4) +(AIN6) TEMP 1110 AIN0 AIN1 -(AIN3) -(AIN5) -(AIN7) SENSOR +(AIN0) +(AIN2) +(AIN4) +(AIN6) TEMP 1111 -(AIN1) -(AIN3) -(AIN5) -(AIN7) SENSOR 64 Rev. 1.4

C8051F022/3 Figure 6.7. ADC0CF: ADC0 Configuration Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD0SC4 AD0SC3 AD0SC2 AD0SC1 AD0SC0 AMP0GN2 AMP0GN1 AMP0GN0 11111000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBC Bits7-3: AD0SC4-0: ADC0 SAR Conversion Clock Period Bits SAR Conversion clock is derived from system clock by the following equation, where AD0SC refers to the 5-bit value held in AD0SC4-0, and CLK refers to the desired ADC0 SAR clock. See SAR0 Table 6.1 on page 74 for SAR clock setting requirements. SYSCLK AD0SC = ----------------------- –1 CLK SAR0 Bits2-0: AMP0GN2-0: ADC0 Internal Amplifier Gain (PGA) 000: Gain = 1 001: Gain = 2 010: Gain = 4 011: Gain = 8 10x: Gain = 16 11x: Gain = 0.5 Rev. 1.4 65

C8051F022/3 Figure 6.8. ADC0CN: ADC0 Control Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD0EN AD0TM AD0INT AD0BUSY AD0CM1 AD0CM0 AD0WINT AD0LJST 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xE8 Bit7: AD0EN: ADC0 Enable Bit. 0: ADC0 Disabled. ADC0 is in low-power shutdown. 1: ADC0 Enabled. ADC0 is active and ready for data conversions. Bit6: AD0TM: ADC Track Mode Bit 0: When the ADC is enabled, tracking is continuous unless a conversion is in process 1: Tracking Defined by ADSTM1-0 bits Bit5: AD0INT: ADC0 Conversion Complete Interrupt Flag. This flag must be cleared by software. 0: ADC0 has not completed a data conversion since the last time this flag was cleared. 1: ADC0 has completed a data conversion. Bit4: AD0BUSY: ADC0 Busy Bit. Read: 0: ADC0 Conversion is complete or a conversion is not currently in progress. AD0INT is set to logic 1 on the falling edge of AD0BUSY. 1: ADC0 Conversion is in progress. Write: 0: No Effect. 1: Initiates ADC0 Conversion if AD0STM1-0 = 00b Bit3-2: AD0CM1-0: ADC0 Start of Conversion Mode Select. If AD0TM = 0: 00: ADC0 conversion initiated on every write of ‘1’ to AD0BUSY. 01: ADC0 conversion initiated on overflow of Timer 3. 10: ADC0 conversion initiated on rising edge of external CNVSTR. 11: ADC0 conversion initiated on overflow of Timer 2. If AD0TM = 1: 00: Tracking starts with the write of ‘1’ to AD0BUSY and lasts for 3 SAR clocks, followed by con- version. 01: Tracking started by the overflow of Timer 3 and last for 3 SAR clocks, followed by conversion. 10: ADC0 tracks only when CNVSTR input is logic low; conversion starts on rising CNVSTR edge. 11: Tracking started by the overflow of Timer 2 and last for 3 SAR clocks, followed by conversion. Bit1: AD0WINT: ADC0 Window Compare Interrupt Flag. This bit must be cleared by software. 0: ADC0 Window Comparison Data match has not occurred since this flag was last cleared. 1: ADC0 Window Comparison Data match has occurred. Bit0: AD0LJST: ADC0 Left Justify Select. 0: Data in ADC0H:ADC0L registers are right-justified. 1: Data in ADC0H:ADC0L registers are left-justified. 66 Rev. 1.4

C8051F022/3 Figure 6.9. ADC0H: ADC0 Data Word MSB Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBF Bits7-0: ADC Data Word High-Order Bits. For ADLJST = 0: Bits 7-2 are the sign extension of Bit1. Bits 1-0 are the upper 2 bits of the 10-bit ADC Data Word. For ADLJST = 1: Bits 7-0 are the most-significant bits of the 10-bit ADC Data Word. Figure 6.10. ADC0L: ADC0 Data Word LSB Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBE Bits7-0: ADC Data Word Low-Order Bits. For ADLJST = 0: Bits 7-0 are the lower 8 bits of the 10-bit ADC Data Word. For ADLJST = 1: Bits 7-6 are the lower 2 bits of the 10-bit ADC Data Word. Bits 5-0 will always read ‘0’. Rev. 1.4 67

C8051F022/3 Figure 6.11. ADC0 Data Word Example (C8051F022/3) 10-bit ADC Data Word appears in the ADC Data Word Registers as follows: ADC0H[1:0]:ADC0L[7:0], if ADLJST = 0 (ADC0H[7:2] will be sign-extension of ADC0H.1 for a differential reading, otherwise = 000000b). ADC0H[7:0]:ADC0L[7:6], if ADLJST = 1 (ADC0L[5:0] = 000000b). Example: ADC Data Word Conversion Map, AIN0 Input in Single-Ended Mode (AMX0CF = 0x00, AMX0SL = 0x00) ADC0H:ADC0L ADC0H:ADC0L AIN0-AGND (Volts) (ADLJST = 0) (ADLJST = 1) VREF * (1023/1024) 0x03FF 0xFFC0 VREF / 2 0x0200 0x8000 VREF * (511/1024) 0x01FF 0x7FC0 0 0x0000 0x0000 Example: ADC Data Word Conversion Map, AIN0-AIN1 Differential Input Pair (AMX0CF = 0x01, AMX0SL = 0x00) ADC0H:ADC0L ADC0H:ADC0L AIN0-AGND (Volts) (ADLJST = 0) (ADLJST = 1) VREF * (511/512) 0x01FF 0x7FC0 VREF / 2 0x0100 0x4000 VREF * (1/512) 0x0001 0x0040 0 0x0000 0x0000 -VREF * (1/512) 0xFFFF (-1) 0xFFC0 -VREF / 2 0xFF00 (-256) 0xC000 -VREF 0xFE00 (-512) 0x8000 ADLJST = 0: Gain Code = Vin× --------------- × 2n; ‘n’ = 10 for Single-Ended; ‘n’=9 for Differential. VREF 68 Rev. 1.4

C8051F022/3 6.3. ADC0 Programmable Window Detector The ADC0 Programmable Window Detector continuously compares the ADC0 output to user-programmed limits, and notifies the system when an out-of-bound condition is detected. This is especially effective in an interrupt-driven system, saving code space and CPU bandwidth while delivering faster system response times. The window detector interrupt flag (AD0WINT in ADC0CN) can also be used in polled mode. The high and low bytes of the reference words are loaded into the ADC0 Greater-Than and ADC0 Less-Than registers (ADC0GTH, ADC0GTL, ADC0LTH, and ADC0LTL). Reference comparisons are shown starting on page 70. Notice that the window detector flag can be asserted when the measured data is inside or outside the user-programmed limits, depending on the programming of the ADC0GTx and ADC0LTx registers. Figure 6.12. ADC0GTH: ADC0 Greater-Than Data High Byte Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC5 Bits7-0: High byte of ADC0 Greater-Than Data Word. Figure 6.13. ADC0GTL: ADC0 Greater-Than Data Low Byte Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC4 Bits7-0: Low byte of ADC0 Greater-Than Data Word. Figure 6.14. ADC0LTH: ADC0 Less-Than Data High Byte Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC7 Bits7-0: High byte of ADC0 Less-Than Data Word. Figure 6.15. ADC0LTL: ADC0 Less-Than Data Low Byte Register (C8051F022/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC6 Bits7-0: Low byte of ADC0 Less-Than Data Word. Rev. 1.4 69

C8051F022/3 Figure 6.16. 10-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AGND) Word (AD0 - AGND) Word REF x (1023/1024) 0x03FF REF x (1023/1024) 0x03FF ADWINT ADWINT=1 not affected 0x0201 0x0201 REF x (512/1024) 0x0200 ADC0LTH:ADC0LTL REF x (512/1024) 0x0200 ADC0GTH:ADC0GTL 0x01FF 0x01FF ADWINT ADWINT=1 not affected 0x0101 0x0101 REF x (256/1024) 0x0100 ADC0GTH:ADC0GTL REF x (256/1024) 0x0100 ADC0LTH:ADC0LTL 0x00FF 0x00FF ADWINT ADWINT=1 not affected 0 0x0000 0 0x0000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 0, AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 0, ADC0LTH:ADC0LTL = 0x0200, ADC0LTH:ADC0LTL = 0x0100, ADC0GTH:ADC0GTL = 0x0100. ADC0GTH:ADC0GTL = 0x0200. An ADC End of Conversion will cause an ADC An ADC End of Conversion will cause an ADC Window Compare Interrupt (ADWINT=1) if the Window Compare Interrupt (ADWINT=1) if the resulting ADC Data Word is < 0x0200 and resulting ADC Data Word is > 0x0200 or < 0x0100. > 0x0100. 70 Rev. 1.4

C8051F022/3 Figure 6.17. 10-Bit ADC0 Window Interrupt Example: Right Justified Differential Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AD1) Word (AD0 - AD1) Word REF x (511/512) 0x01FF REF x (511/512) 0x01FF ADWINT ADWINT=1 not affected 0x0101 0x0101 REF x (256/512) 0x0100 ADC0LTH:ADC0LTL REF x (256/512) 0x0100 ADC0GTH:ADC0GTL 0x00FF 0x00FF ADWINT ADWINT=1 not affected 0x0000 0x0000 REF x (-1/512) 0xFFFF ADC0GTH:ADC0GTL REF x (-1/512) 0xFFFF ADC0LTH:ADC0LTL 0xFFFE 0xFFFE ADWINT ADWINT=1 not affected -REF 0xFE00 -REF 0xFE00 Given: Given: AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 0, AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 0, ADC0LTH:ADC0LTL = 0x0100, ADC0LTH:ADC0LTL = 0xFFFF, ADC0GTH:ADC0GTL = 0xFFFF. ADC0GTH:ADC0GTL = 0x0100. An ADC End of Conversion will cause an ADC An ADC End of Conversion will cause an ADC Window Compare Interrupt (ADWINT=1) if the Window Compare Interrupt (ADWINT=1) if the resulting ADC Data Word is < 0x0100 and resulting ADC Data Word is < 0xFFFF or > 0xFFFF. (In two’s-complement math, > 0x0100. (In two’s-complement math, 0xFFFF = -1.) 0xFFFF = -1.) Rev. 1.4 71

C8051F022/3 Figure 6.18. 10-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AGND) Word (AD0 - AGND) Word REF x (1023/1024) 0xFFC0 REF x (1023/1024) 0xFFC0 ADWINT ADWINT=1 not affected 0x8040 0x8040 REF x (512/1024) 0x8000 ADC0LTH:ADC0LTL REF x (512/1024) 0x8000 ADC0GTH:ADC0GTL 0x7FC0 0x7FC0 ADWINT ADWINT=1 not affected 0x4040 0x4040 REF x (256/1024) 0x4000 ADC0GTH:ADC0GTL REF x (256/1024) 0x4000 ADC0LTH:ADC0LTL 0x3FC0 0x3FC0 ADWINT ADWINT=1 not affected 0 0x0000 0 0x0000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 1, AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 1, ADC0LTH:ADC0LTL = 0x8000, ADC0LTH:ADC0LTL = 0x4000, ADC0GTH:ADC0GTL = 0x4000. ADC0GTH:ADC0GTL = 0x8000. An ADC End of Conversion will cause an ADC An ADC End of Conversion will cause an ADC Window Compare Interrupt (ADWINT=1) if the Window Compare Interrupt (ADWINT=1) if the resulting ADC Data Word is < 0x8000 and resulting ADC Data Word is < 0x4000 or > 0x8000. > 0x4000. 72 Rev. 1.4

C8051F022/3 Figure 6.19. 10-Bit ADC0 Window Interrupt Example: Left Justified Differential Data Input Voltage ADC Data Input Voltage ADC Data (AD0 - AD1) Word (AD0 - AD1) Word REF x (511/512) 0x7FC0 REF x (511/512) 0x7FC0 ADWINT ADWINT=1 not affected 0x2040 0x2040 REF x (128/512) 0x2000 ADC0LTH:ADC0LTL REF x (128/512) 0x2000 ADC0GTH:ADC0GTL 0x1FC0 0x1FC0 ADWINT ADWINT=1 not affected 0x0000 0x0000 REF x (-1/512) 0xFFC0 ADC0GTH:ADC0GTL REF x (-1/512) 0xFFC0 ADC0LTH:ADC0LTL 0xFF80 0xFF80 ADWINT ADWINT=1 not affected -REF 0x8000 -REF 0x8000 Given: Given: AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 1, AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 1, ADC0LTH:ADC0LTL = 0x2000, ADC0LTH:ADC0LTL = 0xFFC0, ADC0GTH:ADC0GTL = 0xFFC0. ADC0GTH:ADC0GTL = 0x2000. An ADC End of Conversion will cause an ADC An ADC End of Conversion will cause an ADC Window Compare Interrupt (ADWINT=1) if the Window Compare Interrupt (ADWINT=1) if the resulting ADC Data Word is < 0x2000 and resulting ADC Data Word is < 0xFFC0 or > 0xFFC0. (Two’s-complement math.) > 0x2000. (Two’s-complement math.) Rev. 1.4 73

C8051F022/3 Table 6.1. 10-Bit ADC0 Electrical Characteristics (C8051F022/3) VDD = 3.0V, AV+ = 3.0V, VREF = 2.40V (REFBE=0), PGA Gain = 1, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS DC ACCURACY Resolution 10 bits Integral Nonlinearity ±1 LSB Differential Nonlinearity Guaranteed Monotonic ±1 LSB Offset Error ±0.5 LSB Full Scale Error Differential mode -1.5±0.5 LSB Offset Temperature Coefficient ±0.25 ppm/°C DYNAMIC PERFORMANCE (10 kHz sine-wave input, 0 to 1 dB below Full Scale, 100 ksps Signal-to-Noise Plus Distortion 59 dB Total Harmonic Distortion Up to the 5th harmonic -70 dB Spurious-Free Dynamic Range 80 dB CONVERSION RATE SAR Clock Frequency 2.5 MHz Conversion Time in SAR Clocks 16 clocks Track/Hold Acquisition Time 1.5 µs Throughput Rate 100 ksps ANALOG INPUTS Input Voltage Range Single-ended operation 0 VREF V *Common-mode Voltage Range Differential operation AGND AV+ V Input Capacitance 10 pF TEMPERATURE SENSOR Nonlinearity -1.0 +1.0 °C Absolute Accuracy ±3 °C Gain PGA Gain = 1 2.86 mV/°C Offset PGA Gain = 1, Temp = 0°C 0.776 V POWER SPECIFICATIONS Power Supply Current (AV+ sup- Operating Mode, 100 ksps 450 900 µA plied to ADC) Power Supply Rejection ±0.3 mV/V 74 Rev. 1.4

C8051F020/1/2/3 7. ADC1 (8-BIT ADC) The ADC1 subsystem for the C8051F020/1/2/3 consists of an 8-channel, configurable analog multiplexer (AMUX1), a programmable gain amplifier (PGA1), and a 500 ksps, 8-bit successive-approximation-register ADC with inte- grated track-and-hold (see block diagram in Figure 7.1). The AMUX1, PGA1, and Data Conversion Modes, are all configurable under software control via the Special Function Registers shown in Figure 7.1. The ADC1 subsystem (8-bit ADC, track-and-hold and PGA) is enabled only when the AD1EN bit in the ADC1 Control register (ADC1CN) is set to logic 1. The ADC1 subsystem is in low power shutdown when this bit is logic 0. The voltage reference used by ADC1 is selected as described in Section “9. VOLTAGE REFERENCE (C8051F020/2)” on page 91 for C8051F020/2 devices, or Section “10. VOLTAGE REFERENCE (C8051F021/3)” on page 93 for C8051F021/3 devices. Figure 7.1. ADC1 Functional Block Diagram K AV+ L AIN1.0 (P1.0) AD1EN SYSCREF AIN1.1 (P1.1) AV+ AIN1.2 (P1.2) 8-Bit AIN1.3 (P1.3) 8-to-1 X + SAR 8 C1 AIN1.4 (P1.4) AMUX - ADC AD AIN1.5 (P1.5) AGND AIN1.6 (P1.6) 000 Write to AD1BUSY AIN1.7 (P1.7) M 001 Timer 3 Overflow C Start Conversion 1 010 CNVSTR D A 011 Timer 2 Overflow 1xx Write to AD0BUSY (synchronized with MX1AD2MX1AD1MX1AD0 D1SC4D1SC3D1SC2D1SC1D1SC0 MP1GN1MP1GN0 D1END1TMD1INTD1BUSYD1CM2D1CM1D1CM0 D1CM ADC0) AAA AAAAA AA AAAAAAA A AMX1SL ADC1CF ADC1CN 7.1. Analog Multiplexer and PGA Eight ADC1 channels are available for measurement, as selected by the AMX1SL register (see Figure 7.5). The PGA amplifies the ADC1 output signal by an amount determined by the states of the AMP1GN2-0 bits in the ADC1 Con- figuration register, ADC1CF (Figure 7.4). The PGA can be software-programmed for gains of 0.5, 1, 2, or 4. Gain defaults to 0.5 on reset. Important Note: AIN1 pins also function as Port 1 I/O pins, and must be configured as analog inputs when used as ADC1 inputs. To configure an AIN1 pin for analog input, set to ‘0’ the corresponding bit in register P1MDIN. Port 1 pins selected as analog inputs are skipped by the Digital I/O Crossbar. See Section “17.1.6. Configuring Port 1 Pins as Analog Inputs (AIN1.[7:0])” on page 165 for more information on configuring the AIN1 pins. Rev. 1.4 75

C8051F020/1/2/3 7.2. ADC1 Modes of Operation ADC1 has a maximum conversion speed of 500 ksps. The ADC1 conversion clock (SAR1 clock) is a divided version of the system clock, determined by the AD1SC bits in the ADC1CF register (system clock divided by (AD1SC + 1) for 0 ≤ AD1SC ≤ 31). The maximum ADC1 conversion clock is 6 MHz. 7.2.1. Starting a Conversion A conversion can be initiated in one of five ways, depending on the programmed states of the ADC1 Start of Conver- sion Mode bits (AD1CM2-0) in register ADC1CN. Conversions may be initiated by: 1. Writing a ‘1’ to the AD1BUSY bit of ADC1CN; 2. A Timer 3 overflow (i.e. timed continuous conversions); 3. A rising edge detected on the external ADC convert start signal, CNVSTR; 4. A Timer 2 overflow (i.e. timed continuous conversions); 5. Writing a ‘1’ to the AD0BUSY of register ADC0CN (initiate conversion of ADC1 and ADC0 with a single software command). During conversion, the AD1BUSY bit is set to logic 1 and restored to 0 when conversion is complete. The falling edge of AD1BUSY triggers an interrupt (when enabled) and sets the interrupt flag in ADC1CN. Converted data is available in the ADC1 data word, ADC1. When a conversion is initiated by writing a ‘1’ to AD1BUSY, it is recommended to poll AD1INT to determine when the conversion is complete. The recommended procedure is: Step 1. Write a ‘0’ to AD1INT; Step 2. Write a ‘1’ to AD1BUSY; Step 3. Poll AD1INT for ‘1’; Step 4. Process ADC1 data. 7.2.2. Tracking Modes The AD1TM bit in register ADC1CN controls the ADC1 track-and-hold mode. In its default state, the ADC1 input is continuously tracked, except when a conversion is in progress. When the AD1TM bit is logic 1, ADC1 operates in low-power track-and-hold mode. In this mode, each conversion is preceded by a tracking period of 3 SAR clocks (after the start-of-conversion signal). When the CNVSTR signal is used to initiate conversions in low-power tracking mode, ADC1 tracks only when CNVSTR is low; conversion begins on the rising edge of CNVSTR (see Figure 7.2). Tracking can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. Low-power Track-and-Hold mode is also useful when AMUX or PGA settings are frequently changed, due to the settling time requirements described in Section “7.2.3. Settling Time Requirements” on page 78. 76 Rev. 1.4

C8051F020/1/2/3 Figure 7.2. ADC1 Track and Conversion Example Timing A. ADC Timing for External Trigger Source CNVSTR (AD1CM[2:0]=010) 1 2 3 4 5 6 7 8 9 SAR1 Clocks Low Power AD1TM=1 Track Convert Low Power Mode or Convert AD1TM=0 Track or Convert Convert Track B. ADC Timing for Internal Trigger Source Write '1' to AD1BUSY, Timer 3 Overflow, Timer 2 Overflow, Write '1' to AD0BUSY (AD1CM[2:0]=000, 001, 011, 1xx) 1 2 3 4 5 6 7 8 9 10 11 12 SAR1 Clocks Low Power AD1TM=1 Track Convert Low Power Mode or Convert 1 2 3 4 5 6 7 8 9 SAR1 Clocks Track or AD1TM=0 Convert Track Convert Rev. 1.4 77

C8051F020/1/2/3 7.2.3. Settling Time Requirements When the ADC1 input configuration is changed (i.e., a different MUX or PGA selection), a minimum settling (or tracking) time is required before an accurate conversion can be performed. This settling time is determined by the ADC1 MUX resistance, the ADC1 sampling capacitance, any external source resistance, and the accuracy required for the conversion. Figure 7.3 shows the equivalent ADC1 input circuit. The required ADC1 settling time for a given settling accuracy (SA) may be approximated by Equation 7.1. Note that in low-power tracking mode, three SAR1 clocks are used for tracking at the start of every conversion. For most applications, these three SAR1 clocks will meet the tracking requirements. See Table 7.1 for absolute minimum settling time requirements. Equation 7.1. ADC1 Settling Time Requirements t = ln-2----n-- × R C SA TOTAL SAMPLE Where: SA is the settling accuracy, given as a fraction of an LSB (for example, 0.25 to settle within 1/4 LSB) t is the required tracking time in seconds R is the sum of the ADC1 MUX resistance and any external source resistance. TOTAL n is the ADC resolution in bits (8). Figure 7.3. ADC1 Equivalent Input Circuit MUX Select AIN1.x R = 5k MUX C = 10pF SAMPLE RC = R * C Input MUX SAMPLE 78 Rev. 1.4

C8051F020/1/2/3 Figure 7.4. ADC1CF: ADC1 Configuration Register (C8051F020/1/2/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD1SC4 AD1SC3 AD1SC2 AD1SC1 AD1SC0 - AMP1GN1 AMP1GN0 11111000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAB Bits7-3: AD1SC4-0: ADC1 SAR Conversion Clock Period Bits SAR Conversion clock is derived from system clock by the following equation, where AD1SC refers to the 5-bit value held in AD1SC4-0. SAR conversion clock requirements are given in Table 7.1. SYSCLK AD1SC = ----------------------- –1 CLK SAR1 Bit2: UNUSED. Read = 0b. Write = don’t care. Bits1-0: AMP1GN1-0: ADC1 Internal Amplifier Gain (PGA) 00: Gain = 0.5 01: Gain = 1 10: Gain = 2 11: Gain = 4 Figure 7.5. AMX1SL: AMUX1 Channel Select Register (C8051F020/1/2/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - - AMX1AD2AMX1AD1AMX1AD0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAC Bits7-3: UNUSED. Read = 00000b; Write = don’t care Bits2-0: AMX1AD2-0: AMX1 Address Bits 000-111b: ADC1 Inputs selected as follows: 000: AIN1.0 selected 001: AIN1.1 selected 010: AIN1.2 selected 011: AIN1.3 selected 100: AIN1.4 selected 101: AIN1.5 selected 110: AIN1.6 selected 111: AIN1.7 selected Rev. 1.4 79

C8051F020/1/2/3 Figure 7.6. ADC1CN: ADC1 Control Register (C8051F020/1/2/3) R/W R/W R/W R/W R/W R/W R/W R/W Reset Value AD1EN AD1TM AD1INT AD1BUSY AD1CM2 AD1CM1 AD1CM0 - 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAA Bit7: AD1EN: ADC1 Enable Bit. 0: ADC1 Disabled. ADC1 is in low-power shutdown. 1: ADC1 Enabled. ADC1 is active and ready for data conversions. Bit6: AD1TM: ADC1 Track Mode Bit. 0: Normal Track Mode: When ADC1 is enabled, tracking is continuous unless a conversion is in pro- cess. 1: Low-power Track Mode: Tracking Defined by AD1STM2-0 bits (see below). Bit5: AD1INT: ADC1 Conversion Complete Interrupt Flag. This flag must be cleared by software. 0: ADC1 has not completed a data conversion since the last time this flag was cleared. 1: ADC1 has completed a data conversion. Bit4: AD1BUSY: ADC1 Busy Bit. Read: 0: ADC1 Conversion is complete or a conversion is not currently in progress. AD1INT is set to logic 1 on the falling edge of AD1BUSY. 1: ADC1 Conversion is in progress. Write: 0: No Effect. 1: Initiates ADC1 Conversion if AD1STM2-0 = 000b Bit3-1: AD1CM2-0: ADC1 Start of Conversion Mode Select. AD1TM = 0: 000: ADC1 conversion initiated on every write of ‘1’ to AD1BUSY. 001: ADC1 conversion initiated on overflow of Timer 3. 010: ADC1 conversion initiated on rising edge of external CNVSTR. 011: ADC1 conversion initiated on overflow of Timer 2. 1xx: ADC1 conversion initiated on write of ‘1’ to AD0BUSY (synchronized with ADC0 software- commanded conversions). AD1TM = 1: 000: Tracking initiated on write of ‘1’ to AD1BUSY and lasts 3 SAR1 clocks, followed by conver- sion. 001: Tracking initiated on overflow of Timer 3 and lasts 3 SAR1 clocks, followed by conversion. 010: ADC1 tracks only when CNVSTR input is logic low; conversion starts on rising CNVSTR edge. 011: Tracking initiated on overflow of Timer 2 and lasts 3 SAR1 clocks, followed by conversion. 1xx: Tracking initiated on write of ‘1’ to AD0BUSY and lasts 3 SAR1 clocks, followed by conver- sion. Bit0: UNUSED. Read = 0b. Write = don’t care. 80 Rev. 1.4

C8051F020/1/2/3 Figure 7.7. ADC1: ADC1 Data Word Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9C Bits7-0: ADC1 Data Word. Figure 7.8. ADC1 Data Word Example 8-bit ADC Data Word appears in the ADC1 Data Word Register as follows: Example: ADC1 Data Word Conversion Map, AIN1.0 Input (AMX1SL = 0x00) AIN1.0-AGND ADC1 (Volts) VREF * (255/256) 0xFF VREF / 2 0x80 VREF * (127/256) 0x7F 0 0x00 Gain Code = Vin × --------------- × 256 VREF Rev. 1.4 81

C8051F020/1/2/3 Table 7.1. ADC1 Electrical Characteristics VDD = 3.0 V, AV+ = 3.0 V, VREF1 = 2.40 V (REFBE=0), PGA1 = 1, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS DC ACCURACY Resolution 8 bits Integral Nonlinearity ±1 LSB Differential Nonlinearity Guaranteed Monotonic ±1 LSB Offset Error 0.5±0.3 LSB Full Scale Error Differential mode -1±0.2 LSB Offset Temperature Coefficient TBD ppm/°C DYNAMIC PERFORMANCE (10 kHz sine-wave input, 0 to 1 dB below Full Scale, 500 ksps Signal-to-Noise Plus Distortion 45 47 dB Total Harmonic Distortion Up to the 5th harmonic -51 dB Spurious-Free Dynamic Range 52 dB CONVERSION RATE SAR Conversion Clock 6 MHz Conversion Time in SAR Clocks 8 clocks Track/Hold Acquisition Time 300 ns Throughput Rate 500 ksps ANALOG INPUTS Input Voltage Range 0 VREF V Input Capacitance 10 pF POWER SPECIFICATIONS Power Supply Current (AV+ sup- Operating Mode, 500 ksps 420 900 µA plied to ADC1) Power Supply Rejection ±0.3 mV/V 82 Rev. 1.4

C8051F020/1/2/3 8. DACS, 12-BIT VOLTAGE MODE Each C8051F020/1/2/3 device includes two on-chip 12-bit voltage-mode Digital-to-Analog Converters (DACs). Each DAC has an output swing of 0V to (VREF-1LSB) for a corresponding input code range of 0x000 to 0xFFF. The DACs may be enabled/disabled via their corresponding control registers, DAC0CN and DAC1CN. While disabled, the DAC output is maintained in a high-impedance state, and the DAC supply current falls to 1 µA or less. The volt- age reference for each DAC is supplied at the VREFD pin (C8051F020/2 devices) or the VREF pin (C8051F021/3 devices). Note that the VREF pin on C8051F021/3 devices may be driven by the internal voltage reference or an external source. If the internal voltage reference is used it must be enabled in order for the DAC outputs to be valid. See Section “9. VOLTAGE REFERENCE (C8051F020/2)” on page 91 or Section “10. VOLTAGE REFER- ENCE (C8051F021/3)” on page 93 for more information on configuring the voltage reference for the DACs. 8.1. DAC Output Scheduling Each DAC features a flexible output update mechanism which allows for seamless full-scale changes and supports jitter-free updates for waveform generation. The following examples are written in terms of DAC0, but DAC1 opera- tion is identical. Note that reads from DAC0L return pre-latch data, meaning the value read is the same as the last value written to this register, not the value at the DAC0L latch. Reads from DAC0H always return the value at the DAC0H latch. Figure 8.1. DAC Functional Block Diagram H 3 4 2 DAC0EN C0 er er er A m m m D Ti Ti Ti N C DAC0MD1 0 C DAC0MD0 A D DAC0DF2 REF DAC0DF1 AV+ DAC0DF0 H DAC0 8 Latch 8 MUX 12 DAC0 g. DAC0 Di AC0L 8 atch 8 AGND D L H 3 4 2 DAC1EN C1 er er er A m m m D Ti Ti Ti N C DAC1MD1 1 C DAC1MD0 A D DAC1DF2 REF DAC1DF1 DAC1DF0 AV+ H DAC1 8 Latch 8 MUX 12 DAC1 g. DAC1 Di AC1L 8 atch 8 AGND D L Rev. 1.4 83

C8051F020/1/2/3 8.1.1. Update Output On-Demand In its default mode (DAC0CN.[4:3] = ‘00’) the DAC0 output is updated “on-demand” on a write to the high-byte of the DAC0 data register (DAC0H). It’s important to note that writes to DAC0L are held, and have no effect on the DAC0 output until a write to DAC0H takes place. If writing a full 12-bit word to the DAC data registers, the 12-bit data word is written to the low byte (DAC0L) and high byte (DAC0H) data registers. Data is latched into DAC0 after a write to the corresponding DAC0H register, so the write sequence should be DAC0L followed by DAC0H if the full 12-bit resolution is required. The DAC can be used in 8-bit mode by initializing DAC0L to the desired value (typ- ically 0x00), and writing data to only DAC0H (also see Section 8.2 for information on formatting the 12-bit DAC data word within the 16-bit SFR space). 8.1.2. Update Output Based on Timer Overflow Similar to the ADC operation, in which an ADC conversion can be initiated by a timer overflow independently of the processor, the DAC outputs can use a Timer overflow to schedule an output update event. This feature is useful in systems where the DAC is used to generate a waveform of a defined sampling rate by eliminating the effects of vari- able interrupt latency and instruction execution on the timing of the DAC output. When the DAC0MD bits (DAC0CN.[4:3]) are set to ‘01’, ‘10’, or ‘11’, writes to both DAC data registers (DAC0L and DAC0H) are held until an associated Timer overflow event (Timer 3, Timer 4, or Timer 2, respectively) occurs, at which time the DAC0H:DAC0L contents are copied to the DAC input latches allowing the DAC output to change to the new value. 8.2. DAC Output Scaling/Justification In some instances, input data should be shifted prior to a DAC0 write operation to properly justify data within the DAC input registers. This action would typically require one or more load and shift operations, adding software over- head and slowing DAC throughput. To alleviate this problem, the data-formatting feature provides a means for the user to program the orientation of the DAC0 data word within data registers DAC0H and DAC0L. The three DAC0DF bits (DAC0CN.[2:0]) allow the user to specify one of five data word orientations as shown in the DAC0CN register definition. DAC1 is functionally the same as DAC0 described above. The electrical specifications for both DAC0 and DAC1 are given in Table 8.1. 84 Rev. 1.4

C8051F020/1/2/3 Figure 8.2. DAC0H: DAC0 High Byte Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD3 Bits7-0: DAC0 Data Word Most Significant Byte. Figure 8.3. DAC0L: DAC0 Low Byte Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD2 Bits7-0: DAC0 Data Word Least Significant Byte. Rev. 1.4 85

C8051F020/1/2/3 Figure 8.4. DAC0CN: DAC0 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value DAC0EN - - DAC0MD1DAC0MD0 DAC0DF2 DAC0DF1 DAC0DF0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD4 Bit7: DAC0EN: DAC0 Enable Bit. 0: DAC0 Disabled. DAC0 Output pin is disabled; DAC0 is in low-power shutdown mode. 1: DAC0 Enabled. DAC0 Output pin is active; DAC0 is operational. Bits6-5: UNUSED. Read = 00b; Write = don’t care. Bits4-3: DAC0MD1-0: DAC0 Mode Bits. 00: DAC output updates occur on a write to DAC0H. 01: DAC output updates occur on Timer 3 overflow. 10: DAC output updates occur on Timer 4 overflow. 11: DAC output updates occur on Timer 2 overflow. Bits2-0: DAC0DF2-0: DAC0 Data Format Bits: 000: The most significant nibble of the DAC0 Data Word is in DAC0H[3:0], while the least significant byte is in DAC0L. DAC0H DAC0L MSB LSB 001: The most significant 5-bits of the DAC0 Data Word is in DAC0H[4:0], while the least significant 7-bits are in DAC0L[7:1]. DAC0H DAC0L MSB LSB 010: The most significant 6-bits of the DAC0 Data Word is in DAC0H[5:0], while the least significant 6-bits are in DAC0L[7:2]. DAC0H DAC0L MSB LSB 011: The most significant 7-bits of the DAC0 Data Word is in DAC0H[6:0], while the least significant 5-bits are in DAC0L[7:3]. DAC0H DAC0L MSB LSB 1xx: The most significant 8-bits of the DAC0 Data Word is in DAC0H[7:0], while the least significant 4-bits are in DAC0L[7:4]. DAC0H DAC0L MSB LSB 86 Rev. 1.4

C8051F020/1/2/3 Figure 8.5. DAC1H: DAC1 High Byte Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD6 Bits7-0: DAC1 Data Word Most Significant Byte. Figure 8.6. DAC1L: DAC1 Low Byte Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD5 Bits7-0: DAC1 Data Word Least Significant Byte. Rev. 1.4 87

C8051F020/1/2/3 Figure 8.7. DAC1CN: DAC1 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value DAC1EN - - DAC1MD1DAC1MD0 DAC1DF2 DAC1DF1 DAC1DF0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD7 Bit7: DAC1EN: DAC1 Enable Bit. 0: DAC1 Disabled. DAC1 Output pin is disabled; DAC1 is in low-power shutdown mode. 1: DAC1 Enabled. DAC1 Output pin is active; DAC1 is operational. Bits6-5: UNUSED. Read = 00b; Write = don’t care. Bits4-3: DAC1MD1-0: DAC1 Mode Bits: 00: DAC output updates occur on a write to DAC1H. 01: DAC output updates occur on Timer 3 overflow. 10: DAC output updates occur on Timer 4 overflow. 11: DAC output updates occur on Timer 2 overflow. Bits2-0: DAC1DF2: DAC1 Data Format Bits: 000: The most significant nibble of the DAC1 Data Word is in DAC1H[3:0], while the least significant byte is in DAC1L. DAC1H DAC1L MSB LSB 001: The most significant 5-bits of the DAC1 Data Word is in DAC1H[4:0], while the least significant 7-bits are in DAC1L[7:1]. DAC1H DAC1L MSB LSB 010: The most significant 6-bits of the DAC1 Data Word is in DAC1H[5:0], while the least significant 6-bits are in DAC1L[7:2]. DAC1H DAC1L MSB LSB 011: The most significant 7-bits of the DAC1 Data Word is in DAC1H[6:0], while the least significant 5-bits are in DAC1L[7:3]. DAC1H DAC1L MSB LSB 1xx: The most significant 8-bits of the DAC1 Data Word is in DAC1H[7:0], while the least significant 4-bits are in DAC1L[7:4]. DAC1H DAC1L MSB LSB 88 Rev. 1.4

C8051F020/1/2/3 Table 8.1. DAC Electrical Characteristics VDD = 3.0 V, AV+ = 3.0 V, VREF = 2.40 V (REFBE = 0), No Output Load unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS STATIC PERFORMANCE Resolution 12 bits Integral Nonlinearity ±2 LSB Differential Nonlinearity ±1 LSB Output Noise No Output Filter 250 µVrms 100 kHz Output Filter 128 10 kHz Output Filter 41 Offset Error Data Word = 0x014 ±3 ±30 mV Offset Tempco 6 ppm/°C Gain Error ±20 ±60 mV Gain-Error Tempco 10 ppm/°C VDD Power Supply Rejection -60 dB Ratio Output Impedance in Shutdown DACnEN = 0 100 kΩ Mode Output Sink Current 300 µA Output Short-Circuit Current Data Word = 0xFFF 15 mA DYNAMIC PERFORMANCE Voltage Output Slew Rate Load = 40pF 0.44 V/µs Output Settling Time to 1/2 LSB Load = 40pF, Output swing from code 10 µs 0xFFF to 0x014 Output Voltage Swing 0 VREF- V 1LSB Startup Time 10 µs ANALOG OUTPUTS Load Regulation I = 0.01mA to 0.3mA at code 0xFFF 60 ppm L POWER CONSUMPTION (each DAC) Power Supply Current (AV+ sup- Data Word = 0x7FF 110 400 µA plied to DAC) Rev. 1.4 89

C8051F020/1/2/3 Notes 90 Rev. 1.4

C8051F020/1/2/3 9. VOLTAGE REFERENCE (C8051F020/2) The voltage reference circuit offers full flexibility in operating the ADC and DAC modules. Three voltage reference input pins allow each ADC and the two DACs to reference an external voltage reference or the on-chip voltage refer- ence output. ADC0 may also reference the DAC0 output internally, and ADC1 may reference the analog power sup- ply voltage, via the VREF multiplexers shown in Figure 9.1. The internal voltage reference circuit consists of a 1.2 V, 15 ppm/°C (typical) bandgap voltage reference generator and a gain-of-two output buffer amplifier. The internal reference may be routed via the VREF pin to external system components or to the voltage reference input pins shown in Figure 9.1. Bypass capacitors of 0.1 µF and 4.7 µF are recommended from the VREF pin to AGND, as shown in Figure 9.1. See Table 9.1 for voltage reference specifica- tions. The Reference Control Register, REF0CN (defined in Figure 9.2) enables/disables the internal reference generator and selects the reference inputs for ADC0 and ADC1. The BIASE bit in REF0CN enables the on-board reference generator while the REFBE bit enables the gain-of-two buffer amplifier which drives the VREF pin. When disabled, the supply current drawn by the bandgap and buffer amplifier falls to less than 1 µA (typical) and the output of the buffer amplifier enters a high impedance state. If the internal bandgap is used as the reference voltage generator, BIASE and REFBE must both be set to logic 1. If the internal reference is not used, REFBE may be set to logic 0. Note that the BIASE bit must be set to logic 1 if either DAC or ADC is used, regardless of whether the voltage refer- ence is derived from the on-chip reference or supplied by an off-chip source. If neither the ADC nor the DAC are being used, both of these bits can be set to logic 0 to conserve power. Bits AD0VRS and AD1VRS select the ADC0 and ADC1 voltage reference sources, respectively. The electrical specifications for the Voltage Reference circuit are given in Table 9.1. Figure 9.1. Voltage Reference Functional Block Diagram REF0CN AD0VRSAD1VRSTEMPEBIASEREFBE ADC1 AV+ Ref 1 VREF1 VDD 0 External Voltage R1 Reference Circuit ADC0 DGND VREF0 Ref 0 1 DAC0 VREFD Ref DAC1 BIASE Bias to EN ADCs, VREF DACs x2 1.2V 4.7μF 0.1μF Band-Gap REFBE Recommended Bypass Capacitors Rev. 1.4 91

C8051F020/1/2/3 The temperature sensor connects to the highest order input of the ADC0 input multiplexer (see Section “5.1. Analog Multiplexer and PGA” on page 43 for C8051F020/1 devices, or Section “6.1. Analog Multiplexer and PGA” on page 59 for C8051F022/3 devices). The TEMPE bit within REF0CN enables and disables the temperature sensor. While disabled, the temperature sensor defaults to a high impedance state and any A/D measurements performed on the sensor while disabled result in undefined data. Figure 9.2. REF0CN: Reference Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - AD0VRS AD1VRS TEMPE BIASE REFBE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD1 Bits7-5: UNUSED. Read = 000b; Write = don’t care. Bit4: AD0VRS: ADC0 Voltage Reference Select 0: ADC0 voltage reference from VREF0 pin. 1: ADC0 voltage reference from DAC0 output. Bit3: AD1VRS: ADC1 Voltage Reference Select 0: ADC1 voltage reference from VREF1 pin. 1: ADC1 voltage reference from AV+. Bit2: TEMPE: Temperature Sensor Enable Bit. 0: Internal Temperature Sensor Off. 1: Internal Temperature Sensor On. Bit1: BIASE: ADC/DAC Bias Generator Enable Bit. (Must be ‘1’ if using ADC or DAC). 0: Internal Bias Generator Off. 1: Internal Bias Generator On. Bit0: REFBE: Internal Reference Buffer Enable Bit. 0: Internal Reference Buffer Off. 1: Internal Reference Buffer On. Internal voltage reference is driven on the VREF pin. Table 9.1. Voltage Reference Electrical Characteristics VDD = 3.0 V, AV+ = 3.0 V, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS INTERNAL REFERENCE (REFBE = 1) Output Voltage 25°C ambient 2.36 2.43 2.48 V VREF Short-Circuit Current 30 mA VREF Temperature Coefficient 15 ppm/°C Load Regulation Load = 0 to 200 µA to AGND 0.5 ppm/µA VREF Turn-on Time 1 4.7µF tantalum, 0.1µF ceramic bypass 2 ms VREF Turn-on Time 2 0.1µF ceramic bypass 20 µs VREF Turn-on Time 3 no bypass cap 10 µs EXTERNAL REFERENCE (REFBE = 0) Input Voltage Range 1.00 (AV+) - V 0.3 Input Current 0 1 µA 92 Rev. 1.4

C8051F020/1/2/3 10. VOLTAGE REFERENCE (C8051F021/3) The internal voltage reference circuit consists of a 1.2 V, 15 ppm/°C (typical) bandgap voltage reference generator and a gain-of-two output buffer amplifier. The internal reference may be routed via the VREF pin to external system components or to the VREFA input pin shown in Figure 10.1. Bypass capacitors of 0.1 µF and 4.7 µF are recom- mended from the VREF pin to AGND, as shown in Figure 10.1. See Table 10.1 for voltage reference specifications. The VREFA pin provides a voltage reference input for ADC0 and ADC1. ADC0 may also reference the DAC0 out- put internally, and ADC1 may reference the analog power supply voltage, via the VREF multiplexers shown in Figure 10.1. The Reference Control Register, REF0CN (defined in Figure 10.2) enables/disables the internal reference generator and selects the reference inputs for ADC0 and ADC1. The BIASE bit in REF0CN enables the on-board reference generator while the REFBE bit enables the gain-of-two buffer amplifier which drives the VREF pin. When disabled, the supply current drawn by the bandgap and buffer amplifier falls to less than 1 µA (typical) and the output of the buffer amplifier enters a high impedance state. If the internal bandgap is used as the reference voltage generator, BIASE and REFBE must both be set to 1 (this includes any time a DAC is used). If the internal reference is not used, REFBE may be set to logic 0. Note that the BIASE bit must be set to logic 1 if either ADC is used, regardless of whether the voltage reference is derived from the on-chip reference or supplied by an off-chip source. If neither the ADC nor the DAC are being used, both of these bits can be set to logic 0 to conserve power. Bits AD0VRS and AD1VRS select the ADC0 and ADC1 voltage reference sources, respectively. The electrical specifications for the Voltage Reference are given in Table 10.1. Figure 10.1. Voltage Reference Functional Block Diagram REF0CN AD0VRSAD1VRSTEMPEBIASEREFBE ADC1 AV+ VDD Ref 1 External Voltage R1 Reference 0 Circuit VREFA DGND ADC0 Ref 0 1 DAC0 Ref DAC1 BIASE Bias to EN ADCs, VREF DACs x2 1.2V 4.7μF 0.1μF Band-Gap REFBE Recommended Bypass Capacitors Rev. 1.4 93

C8051F020/1/2/3 The temperature sensor connects to the highest order input of the ADC0 input multiplexer (see Section “5.1. Analog Multiplexer and PGA” on page 43 for C8051F020/1 devices, or Section “6.1. Analog Multiplexer and PGA” on page 59 for C8051F022/3 devices). The TEMPE bit within REF0CN enables and disables the temperature sensor. While disabled, the temperature sensor defaults to a high impedance state and any A/D measurements performed on the sensor while disabled result in undefined data. Figure 10.2. REF0CN: Reference Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - AD0VRS AD1VRS TEMPE BIASE REFBE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD1 Bits7-5: UNUSED. Read = 000b; Write = don’t care. Bit4: AD0VRS: ADC0 Voltage Reference Select 0: ADC0 voltage reference from VREFA pin. 1: ADC0 voltage reference from DAC0 output. Bit3: AD1VRS: ADC1 Voltage Reference Select 0: ADC1 voltage reference from VREFA pin. 1: ADC1 voltage reference from AV+. Bit2: TEMPE: Temperature Sensor Enable Bit. 0: Internal Temperature Sensor Off. 1: Internal Temperature Sensor On. Bit1: BIASE: ADC/DAC Bias Generator Enable Bit. (Must be ‘1’ if using ADC or DAC). 0: Internal Bias Generator Off. 1: Internal Bias Generator On. Bit0: REFBE: Internal Reference Buffer Enable Bit. 0: Internal Reference Buffer Off. 1: Internal Reference Buffer On. Internal voltage reference is driven on the VREF pin. Table 10.1. Voltage Reference Electrical Characteristics VDD = 3.0 V, AV+ = 3.0 V, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS INTERNAL REFERENCE (REFBE = 1) Output Voltage 25°C ambient 2.36 2.43 2.48 V VREF Short-Circuit Current 30 mA VREF Temperature Coefficient 15 ppm/°C Load Regulation Load = 0 to 200 µA to AGND 0.5 ppm/µA VREF Turn-on Time 1 4.7µF tantalum, 0.1µF ceramic bypass 2 ms VREF Turn-on Time 2 0.1µF ceramic bypass 20 µs VREF Turn-on Time 3 no bypass cap 10 µs EXTERNAL REFERENCE (REFBE = 0) Input Voltage Range 1.00 (AV+) - V 0.3 Input Current 0 1 µA 94 Rev. 1.4

C8051F020/1/2/3 11. COMPARATORS Each MCU includes two on-board voltage comparators as shown in Figure 11.1. The inputs of each Comparator are available at the package pins. The output of each comparator is optionally available at the package pins via the I/O crossbar. When assigned to package pins, each comparator output can be programmed to operate in open drain or push-pull modes. See Section “17. PORT INPUT/OUTPUT” on page 161 for Crossbar and port initialization details. The hysteresis of each comparator is software-programmable via its respective Comparator control register (CPT0CN and CPT1CN for Comparator0 and Comparator1, respectively). The user can program both the amount of hysteresis voltage (referred to the input voltage) and the positive and negative-going symmetry of this hysteresis around the threshold voltage. The output of the comparator can be polled in software, or can be used as an interrupt source. Each comparator can be individually enabled or disabled (shutdown). When disabled, the comparator output (if assigned to a Port I/O pin via the Crossbar) defaults to the logic low state, its interrupt capability is suspended and its supply cur- rent falls to less than 1 µA. Comparator inputs can be externally driven from -0.25 V to (AV+) + 0.25 V without dam- age or upset. The Comparator0 hysteresis is programmed using bits 3-0 in the Comparator0 Control Register CPT0CN (shown in Figure 11.1). The amount of negative hysteresis voltage is determined by the settings of the CP0HYN bits; In a simi- lar way, the amount of positive hysteresis is determined by the setting the CP0HYP bits. See Table 11.1 on page 99 for hysteresis level specifications. Comparator interrupts can be generated on rising-edge and/or falling-edge output transitions. (For interrupt enable and priority control, see Section “12.3. Interrupt Handler” on page 116). The CP0FIF flag is set upon a Compara- tor0 falling-edge interrupt, and the CP0RIF flag is set upon the Comparator0 rising-edge interrupt. Once set, these bits remain set until cleared by software. The Output State of Comparator0 can be obtained at any time by reading the CP0OUT bit. Comparator0 is enabled by setting the CP0EN bit to logic 1, and is disabled by clearing this bit to logic Figure 11.1. Comparator Functional Block Diagram CP0EN CP0OUT N CP0RIF AV+ C CP0FIF 0 PT CP0HYP1 C CP0HYP0 Reset CP0HYN1 Decision CP0HYN0 Tree CP0+ + DSETQ DSETQ Crossbar CP0- - CLRQ CLRQ Interrupt Handler (SYNCHRONIZER) AGND CP1EN CP1OUT N CP1RIF AV+ C CP1FIF 1 PT CP1HYP1 C CP1HYP0 CP1HYN1 CP1HYN0 CP1+ + DSETQ DSETQ Crossbar CP1- - CLRQ CLRQ Interrupt Handler (SYNCHRONIZER) AGND Rev. 1.4 95

C8051F020/1/2/3 Figure 11.2. Comparator Hysteresis Plot CP0+ VIN+ + CP0 OUT CP0- _ VIN- CIRCUIT CONFIGURATION Positive Hysteresis Voltage (Programmed with CP0HYP Bits) VIN- INPUTS Negative Hysteresis Voltage (Programmed by CP0HYN Bits) VIN+ VOH OUTPUT VOL Negative Hysteresis Maximum Disabled Negative Hysteresis Positive Hysteresis Maximum Disabled Positive Hysteresis 0. Comparator0 can also be programmed as a reset source; for details, see Section “13.6. Comparator0 Reset” on page 129. The operation of Comparator1 is identical to that of Comparator0, though Comparator1 may not be configured as a reset source. Comparator1 is controlled by the CPT1CN Register (Figure 11.4). The complete electrical specifications for the Comparators are given in Table 11.1. 96 Rev. 1.4

C8051F020/1/2/3 Figure 11.3. CPT0CN: Comparator0 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value CP0EN CP0OUT CP0RIF CP0FIF CP0HYP1 CP0HYP0 CP0HYN1 CP0HYN0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9E Bit7: CP0EN: Comparator0 Enable Bit. 0: Comparator0 Disabled. 1: Comparator0 Enabled. Bit6: CP0OUT: Comparator0 Output State Flag. 0: Voltage on CP0+ < CP0-. 1: Voltage on CP0+ > CP0-. Bit5: CP0RIF: Comparator0 Rising-Edge Interrupt Flag. 0: No Comparator0 Rising Edge Interrupt has occurred since this flag was last cleared. 1: Comparator0 Rising Edge Interrupt has occurred. Bit4: CP0FIF: Comparator0 Falling-Edge Interrupt Flag. 0: No Comparator0 Falling-Edge Interrupt has occurred since this flag was last cleared. 1: Comparator0 Falling-Edge Interrupt has occurred. Bits3-2: CP0HYP1-0: Comparator0 Positive Hysteresis Control Bits. 00: Positive Hysteresis Disabled. 01: Positive Hysteresis = 2 mV. 10: Positive Hysteresis = 4 mV. 11: Positive Hysteresis = 10 mV. Bits1-0: CP0HYN1-0: Comparator0 Negative Hysteresis Control Bits. 00: Negative Hysteresis Disabled. 01: Negative Hysteresis = 2 mV. 10: Negative Hysteresis = 4 mV. 11: Negative Hysteresis = 10 mV. Rev. 1.4 97

C8051F020/1/2/3 Figure 11.4. CPT1CN: Comparator1 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value CP1EN CP1OUT CP1RIF CP1FIF CP1HYP1 CP1HYP0 CP1HYN1 CP1HYN0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9F Bit7: CP1EN: Comparator1 Enable Bit. 0: Comparator1 Disabled. 1: Comparator1 Enabled. Bit6: CP1OUT: Comparator1 Output State Flag. 0: Voltage on CP1+ < CP1-. 1: Voltage on CP1+ > CP1-. Bit5: CP1RIF: Comparator1 Rising-Edge Interrupt Flag. 0: No Comparator1 Rising Edge Interrupt has occurred since this flag was last cleared. 1: Comparator1 Rising Edge Interrupt has occurred. Bit4: CP1FIF: Comparator1 Falling-Edge Interrupt Flag. 0: No Comparator1 Falling-Edge Interrupt has occurred since this flag was last cleared. 1: Comparator1 Falling-Edge Interrupt has occurred. Bits3-2: CP1HYP1-0: Comparator1 Positive Hysteresis Control Bits. 00: Positive Hysteresis Disabled. 01: Positive Hysteresis = 2 mV. 10: Positive Hysteresis = 4 mV. 11: Positive Hysteresis = 10 mV. Bits1-0: CP1HYN1-0: Comparator1 Negative Hysteresis Control Bits. 00: Negative Hysteresis Disabled. 01: Negative Hysteresis = 2 mV. 10: Negative Hysteresis = 4 mV. 11: Negative Hysteresis = 10 mV. 98 Rev. 1.4

C8051F020/1/2/3 Table 11.1. Comparator Electrical Characteristics VDD = 3.0 V, AV+ = 3.0 V, -40°C to +85°C unless otherwise specified PARAMETER CONDITIONS MIN TYP MAX UNITS Response Time 1 CP+ - CP- = 100 mV 4 µs Response Time 2 CP+ - CP- = 10 mV 12 µs Common-Mode Rejection Ratio 1.5 4 mV/V Positive Hysteresis 1 CPnHYP1-0 = 00 0 1 mV Positive Hysteresis 2 CPnHYP1-0 = 01 2 4.5 7 mV Positive Hysteresis 3 CPnHYP1-0 = 10 4 9 13 mV Positive Hysteresis 4 CPnHYP1-0 = 11 10 17 25 mV Negative Hysteresis 1 CPnHYN1-0 = 00 0 1 mV Negative Hysteresis 2 CPnHYN1-0 = 01 2 4.5 7 mV Negative Hysteresis 3 CPnHYN1-0 = 10 4 9 13 mV Negative Hysteresis 4 CPnHYN1-0 = 11 10 17 25 mV Inverting or Non-Inverting Input -0.25 (AV+) V Voltage Range + 0.25 Input Capacitance 7 pF Input Bias Current -5 0.001 +5 nA Input Offset Voltage -10 +10 mV POWER SUPPLY Power-up Time CPnEN from 0 to 1 20 µs Power Supply Rejection 0.1 1 mV/V Supply Current Operating Mode (each comparator) at DC 1.5 10 µA Rev. 1.4 99

C8051F020/1/2/3 Notes 100 Rev. 1.4

C8051F020/1/2/3 12. CIP-51 MICROCONTROLLER The MCU system controller core is the CIP-51 microcontroller. The CIP-51 is fully compatible with the MCS-51™ instruction set; standard 803x/805x assemblers and compilers can be used to develop software. The MCU family has a superset of all the peripherals included with a standard 8051. Included are five 16-bit counter/timers (see descrip- tion in Section 22), two full-duplex UARTs (see description in Section 20 and Section 21), 256 bytes of internal RAM, 128 byte Special Function Register (SFR) address space (see Section 12.2.6), and 8/4 byte-wide I/O Ports (see description in Section 17). The CIP-51 also includes on-chip debug hardware (see description in Section 24), and interfaces directly with the MCUs' analog and digital subsystems providing a complete data acquisition or control- system solution in a single integrated circuit. The CIP-51 Microcontroller core implements the standard 8051 organization and peripherals as well as additional custom peripherals and functions to extend its capability (see Figure 12.1 for a block diagram). The CIP-51 includes the following features: - Fully Compatible with MCS-51 Instruction Set - Extended Interrupt Handler - 25 MIPS Peak Throughput with 25 MHz Clock - Reset Input - 0 to 25 MHz Clock Frequency - Power Management Modes - 256 Bytes of Internal RAM - On-chip Debug Logic - 8/4 Byte-Wide I/O Ports - Program and Data Memory Security Figure 12.1. CIP-51 Block Diagram DATA BUS D8 D8 D8 D8 D8 ACCUMULATOR B REGISTER STACK POINTER S U B TMP1 TMP2 A T A SRAM D PSW ADDRESS SRAM (256 X 8) ALU REGISTER D8 D8 D8 D8 DATA BUS SFR_ADDRESS BUFFER D8 SFR_CONTROL SFR DATA POINTER D8 D8 INTEBRUFSACE SFR_WRITE_DATA SFR_READ_DATA PC INCREMENTER PROGRAM COUNTER (PC) US D8 MEM_ADDRESS B PRGM. ADDRESS REG. ATA A16 INMTEEMROFARCYE MEMM_EWMR_CITOEN_TDRAOTAL D MEM_READ_DATA PIPELINE D8 RESET CONTROL LOGIC SYSTEM_IRQs CLOCK INTERRUPT INTERFACE EMULATION_IRQ STOP D8 POWER CONTROL IDLE REGISTER D8 Rev. 1.4 101

C8051F020/1/2/3 Performance The CIP-51 employs a pipelined architecture that greatly increases its instruction throughput over the standard 8051 architecture. In a standard 8051, all instructions except for MUL and DIV take 12 or 24 system clock cycles to exe- cute, and usually have a maximum system clock of 12 MHz. By contrast, the CIP-51 core executes 70% of its instruc- tions in one or two system clock cycles, with no instructions taking more than eight system clock cycles. With the CIP-51's maximum system clock at 25 MHz, it has a peak throughput of 25 MIPS. The CIP-51 has a total of 109 instructions. The table below shows the total number of instructions that require each execution time. Clocks to Execute 1 2 2/3 3 3/4 4 4/5 5 8 Number of Instructions 26 50 5 14 7 3 1 2 1 Programming and Debugging Support A JTAG-based serial interface is provided for in-system programming of the FLASH program memory and commu- nication with on-chip debug support logic. The re-programmable FLASH can also be read and changed a single byte at a time by the application software using the MOVC and MOVX instructions. This feature allows program memory to be used for non-volatile data storage as well as updating program code under software control. The on-chip debug support logic facilitates full speed in-circuit debugging, allowing the setting of hardware break- points and watch points, starting, stopping and single stepping through program execution (including interrupt service routines), examination of the program's call stack, and reading/writing the contents of registers and memory. This method of on-chip debug is completely non-intrusive and non-invasive, requiring no RAM, Stack, timers, or other on-chip resources. The CIP-51 is supported by development tools from Silicon Labs and third party vendors. Silicon Labs provides an integrated development environment (IDE) including editor, macro assembler, debugger and programmer. The IDE's debugger and programmer interface to the CIP-51 via its JTAG interface to provide fast and efficient in-system device programming and debugging. Third party macro assemblers and C compilers are also available. 12.1. Instruction Set The instruction set of the CIP-51 System Controller is fully compatible with the standard MCS-51™ instruction set; standard 8051 development tools can be used to develop software for the CIP-51. All CIP-51 instructions are the binary and functional equivalent of their MCS-51™ counterparts, including opcodes, addressing modes and effect on PSW flags. However, instruction timing is different than that of the standard 8051. 12.1.1. Instruction and CPU Timing In many 8051 implementations, a distinction is made between machine cycles and clock cycles, with machine cycles varying from 2 to 12 clock cycles in length. However, the CIP-51 implementation is based solely on clock cycle tim- ing. All instruction timings are specified in terms of clock cycles. Due to the pipelined architecture of the CIP-51, most instructions execute in the same number of clock cycles as there are program bytes in the instruction. Conditional branch instructions take one less clock cycle to complete when the branch is not taken as opposed to when the branch is taken. Table 12.1 is the CIP-51 Instruction Set Summary, which includes the mnemonic, number of bytes, and number of clock cycles for each instruction. 12.1.2. MOVX Instruction and Program Memory In the CIP-51, the MOVX instruction serves three purposes: accessing on-chip XRAM, accessing off-chip XRAM, and accessing on-chip program FLASH memory. The FLASH access feature provides a mechanism for user software to update program code and use the program memory space for non-volatile data storage (see Section “15. FLASH 102 Rev. 1.4

C8051F020/1/2/3 MEMORY” on page 139). The External Memory Interface provides a fast access to off-chip XRAM (or memory- mapped peripherals) via the MOVX instruction. Refer to Section “16. EXTERNAL DATA MEMORY INTER- FACE AND ON-CHIP XRAM” on page 145 for details. Table 12.1. CIP-51 Instruction Set Summary Clock Mnemonic Description Bytes Cycles ARITHMETIC OPERATIONS ADD A, Rn Add register to A 1 1 ADD A, direct Add direct byte to A 2 2 ADD A, @Ri Add indirect RAM to A 1 2 ADD A, #data Add immediate to A 2 2 ADDC A, Rn Add register to A with carry 1 1 ADDC A, direct Add direct byte to A with carry 2 2 ADDC A, @Ri Add indirect RAM to A with carry 1 2 ADDC A, #data Add immediate to A with carry 2 2 SUBB A, Rn Subtract register from A with borrow 1 1 SUBB A, direct Subtract direct byte from A with borrow 2 2 SUBB A, @Ri Subtract indirect RAM from A with borrow 1 2 SUBB A, #data Subtract immediate from A with borrow 2 2 INC A Increment A 1 1 INC Rn Increment register 1 1 INC direct Increment direct byte 2 2 INC @Ri Increment indirect RAM 1 2 DEC A Decrement A 1 1 DEC Rn Decrement register 1 1 DEC direct Decrement direct byte 2 2 DEC @Ri Decrement indirect RAM 1 2 INC DPTR Increment Data Pointer 1 1 MUL AB Multiply A and B 1 4 DIV AB Divide A by B 1 8 DA A Decimal adjust A 1 1 LOGICAL OPERATIONS ANL A, Rn AND Register to A 1 1 ANL A, direct AND direct byte to A 2 2 ANL A, @Ri AND indirect RAM to A 1 2 ANL A, #data AND immediate to A 2 2 ANL direct, A AND A to direct byte 2 2 ANL direct, #data AND immediate to direct byte 3 3 ORL A, Rn OR Register to A 1 1 ORL A, direct OR direct byte to A 2 2 ORL A, @Ri OR indirect RAM to A 1 2 ORL A, #data OR immediate to A 2 2 ORL direct, A OR A to direct byte 2 2 ORL direct, #data OR immediate to direct byte 3 3 XRL A, Rn Exclusive-OR Register to A 1 1 XRL A, direct Exclusive-OR direct byte to A 2 2 XRL A, @Ri Exclusive-OR indirect RAM to A 1 2 Rev. 1.4 103

C8051F020/1/2/3 Table 12.1. CIP-51 Instruction Set Summary Clock Mnemonic Description Bytes Cycles XRL A, #data Exclusive-OR immediate to A 2 2 XRL direct, A Exclusive-OR A to direct byte 2 2 XRL direct, #data Exclusive-OR immediate to direct byte 3 3 CLR A Clear A 1 1 CPL A Complement A 1 1 RL A Rotate A left 1 1 RLC A Rotate A left through Carry 1 1 RR A Rotate A right 1 1 RRC A Rotate A right through Carry 1 1 SWAP A Swap nibbles of A 1 1 DATA TRANSFER MOV A, Rn Move Register to A 1 1 MOV A, direct Move direct byte to A 2 2 MOV A, @Ri Move indirect RAM to A 1 2 MOV A, #data Move immediate to A 2 2 MOV Rn, A Move A to Register 1 1 MOV Rn, direct Move direct byte to Register 2 2 MOV Rn, #data Move immediate to Register 2 2 MOV direct, A Move A to direct byte 2 2 MOV direct, Rn Move Register to direct byte 2 2 MOV direct, direct Move direct byte to direct byte 3 3 MOV direct, @Ri Move indirect RAM to direct byte 2 2 MOV direct, #data Move immediate to direct byte 3 3 MOV @Ri, A Move A to indirect RAM 1 2 MOV @Ri, direct Move direct byte to indirect RAM 2 2 MOV @Ri, #data Move immediate to indirect RAM 2 2 MOV DPTR, #data16 Load DPTR with 16-bit constant 3 3 MOVC A, @A+DPTR Move code byte relative DPTR to A 1 3 MOVC A, @A+PC Move code byte relative PC to A 1 3 MOVX A, @Ri Move external data (8-bit address) to A 1 3 MOVX @Ri, A Move A to external data (8-bit address) 1 3 MOVX A, @DPTR Move external data (16-bit address) to A 1 3 MOVX @DPTR, A Move A to external data (16-bit address) 1 3 PUSH direct Push direct byte onto stack 2 2 POP direct Pop direct byte from stack 2 2 XCH A, Rn Exchange Register with A 1 1 XCH A, direct Exchange direct byte with A 2 2 XCH A, @Ri Exchange indirect RAM with A 1 2 XCHD A, @Ri Exchange low nibble of indirect RAM with A 1 2 BOOLEAN MANIPULATION CLR C Clear Carry 1 1 CLR bit Clear direct bit 2 2 SETB C Set Carry 1 1 SETB bit Set direct bit 2 2 CPL C Complement Carry 1 1 104 Rev. 1.4

C8051F020/1/2/3 Table 12.1. CIP-51 Instruction Set Summary Clock Mnemonic Description Bytes Cycles CPL bit Complement direct bit 2 2 ANL C, bit AND direct bit to Carry 2 2 ANL C, /bit AND complement of direct bit to Carry 2 2 ORL C, bit OR direct bit to carry 2 2 ORL C, /bit OR complement of direct bit to Carry 2 2 MOV C, bit Move direct bit to Carry 2 2 MOV bit, C Move Carry to direct bit 2 2 JC rel Jump if Carry is set 2 2/3 JNC rel Jump if Carry is not set 2 2/3 JB bit, rel Jump if direct bit is set 3 3/4 JNB bit, rel Jump if direct bit is not set 3 3/4 JBC bit, rel Jump if direct bit is set and clear bit 3 3/4 PROGRAM BRANCHING ACALL addr11 Absolute subroutine call 2 3 LCALL addr16 Long subroutine call 3 4 RET Return from subroutine 1 5 RETI Return from interrupt 1 5 AJMP addr11 Absolute jump 2 3 LJMP addr16 Long jump 3 4 SJMP rel Short jump (relative address) 2 3 JMP @A+DPTR Jump indirect relative to DPTR 1 3 JZ rel Jump if A equals zero 2 2/3 JNZ rel Jump if A does not equal zero 2 2/3 CJNE A, direct, rel Compare direct byte to A and jump if not equal 3 3/4 CJNE A, #data, rel Compare immediate to A and jump if not equal 3 3/4 CJNE Rn, #data, rel Compare immediate to Register and jump if not equal 3 3/4 CJNE @Ri, #data, rel Compare immediate to indirect and jump if not equal 3 4/5 DJNZ Rn, rel Decrement Register and jump if not zero 2 2/3 DJNZ direct, rel Decrement direct byte and jump if not zero 3 3/4 NOP No operation 1 1 Rev. 1.4 105

C8051F020/1/2/3 Notes on Registers, Operands and Addressing Modes: Rn - Register R0-R7 of the currently selected register bank. @Ri - Data RAM location addressed indirectly through R0 or R1. rel - 8-bit, signed (two’s complement) offset relative to the first byte of the following instruction. Used by SJMP and all conditional jumps. direct - 8-bit internal data location’s address. This could be a direct-access Data RAM location (0x00-0x7F) or an SFR (0x80-0xFF). #data - 8-bit constant #data16 - 16-bit constant bit - Direct-accessed bit in Data RAM or SFR addr11 - 11-bit destination address used by ACALL and AJMP. The destination must be within the same 2K-byte page of program memory as the first byte of the following instruction. addr16 - 16-bit destination address used by LCALL and LJMP. The destination may be anywhere within the 64K- byte program memory space. There is one unused opcode (0xA5) that performs the same function as NOP. All mnemonics copyrighted © Intel Corporation 1980. 106 Rev. 1.4

C8051F020/1/2/3 12.2. Memory Organization The memory organization of the CIP-51 System Controller is similar to that of a standard 8051. There are two sepa- rate memory spaces: program memory and data memory. Program and data memory share the same address space but are accessed via different instruction types. There are 256 bytes of internal data memory and 64k bytes of internal program memory address space implemented within the CIP-51. The CIP-51 memory organization is shown in Figure 12.2. Figure 12.2. Memory Map PROGRAM/DATA MEMORY DATA MEMORY (RAM) (FLASH) INTERNAL DATA ADDRESS SPACE 0x1007F Scrachpad Memory 0xFF Upper 128 RAM Special Function 0x10000 (DATA only) (Indirect Addressing Register's 0xFFFF 0x80 Only) (Direct Addressing Only) RESERVED 0xFE00 0x7F 0xFDFF (Direct and Indirect Addressing) Lower 128 RAM 0x30 (Direct and Indirect FLASH 0x2F Addressing) Bit Addressable 0x20 (In-System 0x1F General Purpose Programmable in 512 0x00 Registers Byte Sectors) EXTERNAL DATA ADDRESS SPACE 0x0000 0xFFFF Off-chip XRAM space 0x1000 0x0FFF XRAM - 4096 Bytes (accessable using MOVX 0x0000 instruction) 12.2.1. Program Memory The CIP-51 has a 64k byte program memory space. The MCU implements 65536 bytes of this program memory space as in-system re-programmed FLASH memory, organized in a contiguous block from addresses 0x0000 to 0xFFFF. Note: 512 bytes (0xEE00 to 0xFFFF) of this memory are reserved for factory use and are not available for user program storage. Program memory is normally assumed to be read-only. However, the CIP-51 can write to program memory by setting the Program Store Write Enable bit (PSCTL.0) and using the MOVX instruction. This feature provides a mechanism for the CIP-51 to update program code and use the program memory space for non-volatile data storage. Refer to Sec- tion “15. FLASH MEMORY” on page 139 for further details. Rev. 1.4 107

C8051F020/1/2/3 12.2.2. Data Memory The CIP-51 implements 256 bytes of internal RAM mapped into the data memory space from 0x00 through 0xFF. The lower 128 bytes of data memory are used for general purpose registers and scratch pad memory. Either direct or indirect addressing may be used to access the lower 128 bytes of data memory. Locations 0x00 through 0x1F are addressable as four banks of general purpose registers, each bank consisting of eight byte-wide registers. The next 16 bytes, locations 0x20 through 0x2F, may either be addressed as bytes or as 128 bit locations accessible with the direct addressing mode. The upper 128 bytes of data memory are accessible only by indirect addressing. This region occupies the same address space as the Special Function Registers (SFR) but is physically separate from the SFR space. The addressing mode used by an instruction when accessing locations above 0x7F determines whether the CPU accesses the upper 128 bytes of data memory space or the SFRs. Instructions that use direct addressing will access the SFR space. Instructions using indirect addressing above 0x7F access the upper 128 bytes of data memory. Figure 12.2 illustrates the data memory organization of the CIP-51. 12.2.3. General Purpose Registers The lower 32 bytes of data memory, locations 0x00 through 0x1F, may be addressed as four banks of general-purpose registers. Each bank consists of eight byte-wide registers designated R0 through R7. Only one of these banks may be enabled at a time. Two bits in the program status word, RS0 (PSW.3) and RS1 (PSW.4), select the active register bank (see description of the PSW in Figure 12.6). This allows fast context switching when entering subroutines and inter- rupt service routines. Indirect addressing modes use registers R0 and R1 as index registers. 12.2.4. Bit Addressable Locations In addition to direct access to data memory organized as bytes, the sixteen data memory locations at 0x20 through 0x2F are also accessible as 128 individually addressable bits. Each bit has a bit address from 0x00 to 0x7F. Bit 0 of the byte at 0x20 has bit address 0x00 while bit 7 of the byte at 0x20 has bit address 0x07. Bit 7 of the byte at 0x2F has bit address 0x7F. A bit access is distinguished from a full byte access by the type of instruction used (bit source or destination operands as opposed to a byte source or destination). The MCS-51™ assembly language allows an alternate notation for bit addressing of the form XX.B where XX is the byte address and B is the bit position within the byte. For example, the instruction: MOV C, 22.3h moves the Boolean value at 0x13 (bit 3 of the byte at location 0x22) into the Carry flag. 12.2.5. Stack A programmer's stack can be located anywhere in the 256 byte data memory. The stack area is designated using the Stack Pointer (SP, address 0x81) SFR. The SP will point to the last location used. The next value pushed on the stack is placed at SP+1 and then SP is incremented. A reset initializes the stack pointer to location 0x07; therefore, the first value pushed on the stack is placed at location 0x08, which is also the first register (R0) of register bank 1. Thus, if more than one register bank is to be used, the SP should be initialized to a location in the data memory not being used for data storage. The stack depth can extend up to 256 bytes. The MCUs also have built-in hardware for a stack record. The stack record is a 32-bit shift register, where each PUSH or increment SP pushes one record bit onto the register, and each CALL pushes two record bits onto the regis- ter. (A POP or decrement SP pops one record bit, and a RET pops two record bits, also.) The stack record circuitry can also detect an overflow or underflow on the 32-bit shift register, and can notify the debug software even with the MCU running at speed. 108 Rev. 1.4

C8051F020/1/2/3 12.2.6. Special Function Registers The direct-access data memory locations from 0x80 to 0xFF constitute the special function registers (SFRs). The SFRs provide control and data exchange with the CIP-51's resources and peripherals. The CIP-51 duplicates the SFRs found in a typical 8051 implementation as well as implementing additional SFRs used to configure and access the sub-systems unique to the MCU. This allows the addition of new functionality while retaining compatibility with the MCS-51™ instruction set. Table 12.2 lists the SFRs implemented in the CIP-51 System Controller. The SFR registers are accessed anytime the direct addressing mode is used to access memory locations from 0x80 to 0xFF. SFRs with addresses ending in 0x0 or 0x8 (e.g. P0, TCON, P1, SCON, IE, etc.) are bit-addressable as well as byte-addressable. All other SFRs are byte-addressable only. Unoccupied addresses in the SFR space are reserved for future use. Accessing these areas will have an indeterminate effect and should be avoided. Refer to the corresponding pages of the datasheet, as indicated in Table 12.3, for a detailed description of each register. Table 12.2. Special Function Register (SFR) Memory Map F8 SPI0CN PCA0H PCA0CPH0 PCA0CPH1 PCA0CPH2 PCA0CPH3 PCA0CPH4 WDTCN F0 B SCON1 SBUF1 SADDR1 TL4 TH4 EIP1 EIP2 E8 ADC0CN PCA0L PCA0CPL0 PCA0CPL1 PCA0CPL2 PCA0CPL3 PCA0CPL4 RSTSRC E0 ACC XBR0 XBR1 XBR2 RCAP4L RCAP4H EIE1 EIE2 D8 PCA0CN PCA0MD PCA0CPM0 PCA0CPM1 PCA0CPM2 PCA0CPM3 PCA0CPM4 D0 PSW REF0CN DAC0L DAC0H DAC0CN DAC1L DAC1H DAC1CN C8 T2CON T4CON RCAP2L RCAP2H TL2 TH2 SMB0CR C0 SMB0CN SMB0STA SMB0DAT SMB0ADR ADC0GTL ADC0GTH ADC0LTL ADC0LTH B8 IP SADEN0 AMX0CF AMX0SL ADC0CF P1MDIN ADC0L ADC0H B0 P3 OSCXCN OSCICN P74OUT† FLSCL FLACL A8 IE SADDR0 ADC1CN ADC1CF AMX1SL P3IF SADEN1 EMI0CN A0 P2 EMI0TC EMI0CF P0MDOUT P1MDOUT P2MDOUT P3MDOUT 98 SCON0 SBUF0 SPI0CFG SPI0DAT ADC1 SPI0CKR CPT0CN CPT1CN 90 P1 TMR3CN TMR3RLL TMR3RLH TMR3L TMR3H P7† 88 TCON TMOD TL0 TL1 TH0 TH1 CKCON PSCTL 80 P0 SP DPL DPH P4† P5† P6† PCON 0(8) 1(9) 2(A) 3(B) 4(C) 5(D) 6(E) 7(F) (bit addressable) Table 12.3. Special Function Registers SFRs are listed in alphabetical order. All undefined SFR locations are reserved. Register Address Description Page No. ACC 0xE0 Accumulator page 115 ADC0CF 0xBC ADC0 Configuration page 49*, page 65** ADC0CN 0xE8 ADC0 Control page 50*, page 66** ADC0GTH 0xC5 ADC0 Greater-Than High page 53*, page 69** ADC0GTL 0xC4 ADC0 Greater-Than Low page 53*, page 69** ADC0H 0xBF ADC0 Data Word High page 51*, page 67** ADC0L 0xBE ADC0 Data Word Low page 51*, page 67** Rev. 1.4 109

C8051F020/1/2/3 Table 12.3. Special Function Registers SFRs are listed in alphabetical order. All undefined SFR locations are reserved. Register Address Description Page No. ADC0LTH 0xC7 ADC0 Less-Than High page 53*, page 69** ADC0LTL 0xC6 ADC0 Less-Than Low page 53*, page 69** ADC1CF 0xAB ADC1 Analog Multiplexer Configuration page 79 ADC1CN 0xAA ADC1 Control page 80 ADC1 0x9C ADC1 Data Word page 81 AMX0CF 0xBA ADC0 Multiplexer Configuration page 47*, page 63** AMX0SL 0xBB ADC0 Multiplexer Channel Select page 48*, page 64** AMX1SL 0xAC ADC1 Analog Multiplexer Channel Select page 79 B 0xF0 B Register page 115 CKCON 0x8E Clock Control page 226 CPT0CN 0x9E Comparator 0 Control page 97 CPT1CN 0x9F Comparator 1 Control page 98 DAC0CN 0xD4 DAC0 Control page 86 DAC0H 0xD3 DAC0 High page 85 DAC0L 0xD2 DAC0 Low page 85 DAC1CN 0xD7 DAC1 Control page 88 DAC1H 0xD6 DAC1 High Byte page 87 DAC1L 0xD5 DAC1 Low Byte page 87 DPH 0x83 Data Pointer High page 113 DPL 0x82 Data Pointer Low page 113 EIE1 0xE6 Extended Interrupt Enable 1 page 121 EIE2 0xE7 Extended Interrupt Enable 2 page 122 EIP1 0xF6 External Interrupt Priority 1 page 123 EIP2 0xF7 External Interrupt Priority 2 page 124 EMI0CN 0xAF External Memory Interface Control page 147 EMI0CF 0xA3 EMIF Configuration page 147 EMI0TC 0xA1 EMIF Timing Control page 152 FLACL 0xB7 FLASH Access Limit page 142 FLSCL 0xB6 FLASH Scale page 143 IE 0xA8 Interrupt Enable page 119 IP 0xB8 Interrupt Priority page 120 OSCICN 0xB2 Internal Oscillator Control page 136 OSCXCN 0xB1 External Oscillator Control page 137 P0 0x80 Port 0 Latch page 173 P0MDOUT 0xA4 Port 0 Output Mode Configuration page 173 P1 0x90 Port 1 Latch page 174 P1MDIN 0xBD Port 1 Input Mode page 174 P1MDOUT 0xA5 Port 1 Output Mode Configuration page 175 P2 0xA0 Port 2 Latch page 175 P2MDOUT 0xA6 Port 2 Output Mode Configuration page 175 P3 0xB0 Port 3 Latch page 176 P3IF 0xAD Port 3 Interrupt Flags page 177 P3MDOUT 0xA7 Port 3 Output Mode Configuration page 176 †P4 0x84 Port 4 Latch page 180† †P5 0x85 Port 5 Latch page 180† 110 Rev. 1.4

C8051F020/1/2/3 Table 12.3. Special Function Registers SFRs are listed in alphabetical order. All undefined SFR locations are reserved. Register Address Description Page No. †P6 0x86 Port 6 Latch page 181† †P7 0x96 Port 7 Latch page 181† †P74OUT 0xB5 Port 4 through 7 Output Mode page 179† PCA0CN 0xD8 PCA Control page 259 PCA0CPH0 0xFA PCA Capture 0 High page 263 PCA0CPH1 0xFB PCA Capture 1 High page 263 PCA0CPH2 0xFC PCA Capture 2 High page 263 PCA0CPH3 0xFD PCA Capture 3 High page 263 PCA0CPH4 0xFE PCA Capture 4 High page 263 PCA0CPL0 0xEA PCA Capture 0 Low page 263 PCA0CPL1 0xEB PCA Capture 1 Low page 263 PCA0CPL2 0xEC PCA Capture 2 Low page 263 PCA0CPL3 0xED PCA Capture 3 Low page 263 PCA0CPL4 0xEE PCA Capture 4 Low page 263 PCA0CPM0 0xDA PCA Module 0 Mode Register page 261 PCA0CPM1 0xDB PCA Module 1 Mode Register page 261 PCA0CPM2 0xDC PCA Module 2 Mode Register page 261 PCA0CPM3 0xDD PCA Module 3 Mode Register page 261 PCA0CPM4 0xDE PCA Module 4 Mode Register page 261 PCA0H 0xF9 PCA Counter High page 262 PCA0L 0xE9 PCA Counter Low page 262 PCA0MD 0xD9 PCA Mode page 260 PCON 0x87 Power Control page 126 PSCTL 0x8F Program Store R/W Control page 144 PSW 0xD0 Program Status Word page 114 RCAP2H 0xCB Timer/Counter 2 Capture High page 239 RCAP2L 0xCA Timer/Counter 2 Capture Low page 239 RCAP4H 0xE5 Timer/Counter 4 Capture High page 248 RCAP4L 0xE4 Timer/Counter 4 Capture Low page 248 REF0CN 0xD1 Programmable Voltage Reference Control page 92†, page 94†† RSTSRC 0xEF Reset Source Register page 132 SADDR0 0xA9 UART0 Slave Address page 214 SADDR1 0xF3 UART1 Slave Address page 224 SADEN0 0xB9 UART0 Slave Address Enable page 214 SADEN1 0xAE UART1 Slave Address Enable page 224 SBUF0 0x99 UART0 Data Buffer page 214 SBUF1 0xF2 UART1 Data Buffer page 224 SCON0 0x98 UART0 Control page 213 SCON1 0xF1 UART1 Control page 223 SMB0ADR 0xC3 SMBus Slave Address page 193 SMB0CN 0xC0 SMBus Control page 191 SMB0CR 0xCF SMBus Clock Rate page 192 SMB0DAT 0xC2 SMBus Data page 193 SMB0STA 0xC1 SMBus Status page 194 SP 0x81 Stack Pointer page 113 Rev. 1.4 111

C8051F020/1/2/3 Table 12.3. Special Function Registers SFRs are listed in alphabetical order. All undefined SFR locations are reserved. Register Address Description Page No. SPI0CFG 0x9A SPI Configuration page 201 SPI0CKR 0x9D SPI Clock Rate Control page 203 SPI0CN 0xF8 SPI Control page 202 SPI0DAT 0x9B SPI Data page 203 T2CON 0xC8 Timer/Counter 2 Control page 238 T4CON 0xC9 Timer/Counter 4 Control page 247 TCON 0x88 Timer/Counter Control page 231 TH0 0x8C Timer/Counter 0 High page 233 TH1 0x8D Timer/Counter 1 High page 233 TH2 0xCD Timer/Counter 2 High page 239 TH4 0xF5 Timer/Counter 4 High page 248 TL0 0x8A Timer/Counter 0 Low page 233 TL1 0x8B Timer/Counter 1 Low page 233 TL2 0xCC Timer/Counter 2 Low page 239 TL4 0xF4 Timer/Counter 4 Low page 248 TMOD 0x89 Timer/Counter Mode page 232 TMR3CN 0x91 Timer 3 Control page 241 TMR3H 0x95 Timer 3 High page 242 TMR3L 0x94 Timer 3 Low page 242 TMR3RLH 0x93 Timer 3 Reload High page 242 TMR3RLL 0x92 Timer 3 Reload Low page 241 WDTCN 0xFF Watchdog Timer Control page 131 XBR0 0xE1 Port I/O Crossbar Control 0 page 170 XBR1 0xE2 Port I/O Crossbar Control 1 page 171 XBR2 0xE3 Port I/O Crossbar Control 2 page 172 0x97, 0xA2, 0xB3, 0xB4, Reserved 0xCE, 0xDF * Refers to a register in the C8051F020/1 only. ** Refers to a register in the C8051F022/3 only. † Refers to a register in the C8051F020/2 only. †† Refers to a register in the C8051F021/3 only. 112 Rev. 1.4

C8051F020/1/2/3 12.2.7. Register Descriptions Following are descriptions of SFRs related to the operation of the CIP-51 System Controller. Reserved bits should not be set to logic l. Future product versions may use these bits to implement new features in which case the reset value of the bit will be logic 0, selecting the feature's default state. Detailed descriptions of the remaining SFRs are included in the sections of the datasheet associated with their corresponding system function. Figure 12.3. SP: Stack Pointer R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x81 Bits7-0: SP: Stack Pointer. The Stack Pointer holds the location of the top of the stack. The stack pointer is incremented before every PUSH operation. The SP register defaults to 0x07 after reset. Figure 12.4. DPL: Data Pointer Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x82 Bits7-0: DPL: Data Pointer Low. The DPL register is the low byte of the 16-bit DPTR. DPTR is used to access indirectly addressed XRAM and FLASH memory. Figure 12.5. DPH: Data Pointer High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x83 Bits7-0: DPH: Data Pointer High. The DPH register is the high byte of the 16-bit DPTR. DPTR is used to access indirectly addressed XRAM and FLASH memory. Rev. 1.4 113

C8051F020/1/2/3 Figure 12.6. PSW: Program Status Word R/W R/W R/W R/W R/W R/W R/W R Reset Value CY AC F0 RS1 RS0 OV F1 PARITY 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xD0 Bit7: CY: Carry Flag. This bit is set when the last arithmetic operation resulted in a carry (addition) or a borrow (subtrac- tion). It is cleared to 0 by all other arithmetic operations. Bit6: AC: Auxiliary Carry Flag This bit is set when the last arithmetic operation resulted in a carry into (addition) or a borrow from (subtraction) the high order nibble. It is cleared to 0 by all other arithmetic operations. Bit5: F0: User Flag 0. This is a bit-addressable, general purpose flag for use under software control. Bits4-3: RS1-RS0: Register Bank Select. These bits select which register bank is used during register accesses. RS1 RS0 Register Bank Address 0 0 0 0x00 - 0x07 0 1 1 0x08 - 0x0F 1 0 2 0x10 - 0x17 1 1 3 0x18 - 0x1F Bit2: OV: Overflow Flag. This bit is set to 1 if the last arithmetic operation resulted in a carry (addition), borrow (subtraction), or overflow (multiply or divide). It is cleared to 0 by all other arithmetic operations. Bit1: F1: User Flag 1. This is a bit-addressable, general purpose flag for use under software control. Bit0: PARITY: Parity Flag. This bit is set to 1 if the sum of the eight bits in the accumulator is odd and cleared if the sum is even. 114 Rev. 1.4

C8051F020/1/2/3 Figure 12.7. ACC: Accumulator R/W R/W R/W R/W R/W R/W R/W R/W Reset Value ACC.7 ACC.6 ACC.5 ACC.4 ACC.3 ACC.2 ACC.1 ACC.0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xE0 Bits7-0: ACC: Accumulator. This register is the accumulator for arithmetic operations. Figure 12.8. B: B Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value B.7 B.6 B.5 B.4 B.3 B.2 B.1 B.0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xF0 Bits7-0: B: B Register. This register serves as a second accumulator for certain arithmetic operations. Rev. 1.4 115

C8051F020/1/2/3 12.3. Interrupt Handler The CIP-51 includes an extended interrupt system supporting a total of 22 interrupt sources with two priority levels. The allocation of interrupt sources between on-chip peripherals and external inputs pins varies according to the spe- cific version of the device. Each interrupt source has one or more associated interrupt-pending flag(s) located in an SFR. When a peripheral or external source meets a valid interrupt condition, the associated interrupt-pending flag is set to logic 1. If interrupts are enabled for the source, an interrupt request is generated when the interrupt-pending flag is set. As soon as execution of the current instruction is complete, the CPU generates an LCALL to a predetermined address to begin execution of an interrupt service routine (ISR). Each ISR must end with an RETI instruction, which returns pro- gram execution to the next instruction that would have been executed if the interrupt request had not occurred. If interrupts are not enabled, the interrupt-pending flag is ignored by the hardware and program execution continues as normal. (The interrupt-pending flag is set to logic 1 regardless of the interrupt's enable/disable state.) Each interrupt source can be individually enabled or disabled through the use of an associated interrupt enable bit in an SFR (IE-EIE2). However, interrupts must first be globally enabled by setting the EA bit (IE.7) to logic 1 before the individual interrupt enables are recognized. Setting the EA bit to logic 0 disables all interrupt sources regardless of the individual interrupt-enable settings. Some interrupt-pending flags are automatically cleared by the hardware when the CPU vectors to the ISR. However, most are not cleared by the hardware and must be cleared by software before returning from the ISR. If an interrupt- pending flag remains set after the CPU completes the return-from-interrupt (RETI) instruction, a new interrupt request will be generated immediately and the CPU will re-enter the ISR after the completion of the next instruction. 12.3.1. MCU Interrupt Sources and Vectors The MCUs support 22 interrupt sources. Software can simulate an interrupt event by setting any interrupt-pending flag to logic 1. If interrupts are enabled for the flag, an interrupt request will be generated and the CPU will vector to the ISR address associated with the interrupt-pending flag. MCU interrupt sources, associated vector addresses, prior- ity order and control bits are summarized in Table 12.4. Refer to the datasheet section associated with a particular on- chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its inter- rupt-pending flag(s). 12.3.2. External Interrupts Two of the external interrupt sources (/INT0 and /INT1) are configurable as active-low level-sensitive or active-low edge-sensitive inputs depending on the setting of bits IT0 (TCON.0) and IT1 (TCON.2). IE0 (TCON.1) and IE1 (TCON.3) serve as the interrupt-pending flag for the /INT0 and /INT1 external interrupts, respectively. If an /INT0 or /INT1 external interrupt is configured as edge-sensitive, the corresponding interrupt-pending flag is automatically cleared by the hardware when the CPU vectors to the ISR. When configured as level sensitive, the interrupt-pending flag follows the state of the external interrupt's input pin. The external interrupt source must hold the input active until the interrupt request is recognized. It must then deactivate the interrupt request before execution of the ISR completes or another interrupt request will be generated. The remaining 2 external interrupts (External Interrupts 6-7) are edge-sensitive inputs configurable as active-low or active-high. The interrupt-pending flags and configuration bits for these interrupts are in the Port 3 Interrupt Flag Register shown in Figure “17.19 P3IF: Port3 Interrupt Flag Register” on page 177. 116 Rev. 1.4

C8051F020/1/2/3 Table 12.4. Interrupt Summary ? ? e W bl H a Interrupt Source Interrupt Priority Pending Flag ess by Enable Priority Vector Order dr d Flag Control ad are t e Bi Cl Always Always Reset 0x0000 Top None N/A N/A Enabled Highest External Interrupt 0 (/INT0) 0x0003 0 IE0 (TCON.1) Y Y EX0 (IE.0) PX0 (IP.0) Timer 0 Overflow 0x000B 1 TF0 (TCON.5) Y Y ET0 (IE.1) PT0 (IP.1) External Interrupt 1 (/INT1) 0x0013 2 IE1 (TCON.3) Y Y EX1 (IE.2) PX1 (IP.2) Timer 1 Overflow 0x001B 3 TF1 (TCON.7) Y Y ET1 (IE.3) PT1 (IP.3) RI0 (SCON0.0) UART0 0x0023 4 Y ES0 (IE.4) PS0 (IP.4) TI0 (SCON0.1) Timer 2 Overflow (or EXF2) 0x002B 5 TF2 (T2CON.7) Y ET2 (IE.5) PT2 (IP.5) ESPI0 PSPI0 Serial Peripheral Interface 0x0033 6 SPIF (SPI0CN.7) Y (EIE1.0) (EIP1.0) ESMB0 PSMB0 SMBus Interface 0x003B 7 SI (SMB0CN.3) Y (EIE1.1) (EIP1.1) AD0WINT EWADC0 PWADC0 ADC0 Window Comparator 0x0043 8 Y (ADC0CN.2) (EIE1.2) (EIP1.2) CF (PCA0CN.7) EPCA0 PPCA0 Programmable Counter Array 0x004B 9 CCFn Y (EIE1.3) (EIP1.3) (PCA0CN.n) CP0FIF ECP0F PCP0F Comparator 0 Falling Edge 0x0053 10 (CPT0CN.4) (EIE1.4) (EIP1.4) CP0RIF ECP0R PCP0R Comparator 0 Rising Edge 0x005B 11 (CPT0CN.5) (EIE1.5) (EIP1.5) CP1FIF ECP1F PCP1F Comparator 1 Falling Edge 0x0063 12 (CPT1CN.4) (EIE1.6) (EIP1.6) CP1RIF ECP1R PCP1F Comparator 1 Rising Edge 0x006B 13 (CPT1CN.5) (EIE1.7) (EIP1.7) ET3 PT3 Timer 3 Overflow 0x0073 14 TF3 (TMR3CN.7) (EIE2.0) (EIP2.0) AD0INT EADC0 PADC0 ADC0 End of Conversion 0x007B 15 Y (ADC0CN.5) (EIE2.1) (EIP2.1) ET4 PT4 Timer 4 Overflow 0x0083 16 TF4 (T4CON.7) (EIE2.2) (EIP2.2) AD1INT EADC1 PADC1 ADC1 End of Conversion 0x008B 17 (ADC1CN.5) (EIE2.3) (EIP2.3) EX6 PX6 External Interrupt 6 0x0093 18 IE6 (P3IF.5) (EIE2.4) (EIP2.4) EX7 PX7 External Interrupt 7 0x009B 19 IE7 (P3IF.6) (EIE2.5) (EIP2.5) RI1 (SCON1.0) UART1 0x00A3 20 ES1 PS1 TI1 (SCON1.1) XTLVLD EXVLD PXVLD External Crystal OSC Ready 0x00AB 21 (OSCXCN.7) (EIE2.7) (EIP2.7) Rev. 1.4 117

C8051F020/1/2/3 12.3.3. Interrupt Priorities Each interrupt source can be individually programmed to one of two priority levels: low or high. A low priority inter- rupt service routine can be preempted by a high priority interrupt. A high priority interrupt cannot be preempted. Each interrupt has an associated interrupt priority bit in an SFR (IP-EIP2) used to configure its priority level. Low priority is the default. If two interrupts are recognized simultaneously, the interrupt with the higher priority is serviced first. If both interrupts have the same priority level, a fixed priority order is used to arbitrate, given in Table 12.4. 12.3.4. Interrupt Latency Interrupt response time depends on the state of the CPU when the interrupt occurs. Pending interrupts are sampled and priority decoded each system clock cycle. Therefore, the fastest possible response time is 5 system clock cycles: 1 clock cycle to detect the interrupt and 4 clock cycles to complete the LCALL to the ISR. If an interrupt is pending when a RETI is executed, a single instruction is executed before an LCALL is made to service the pending interrupt. Therefore, the maximum response time for an interrupt (when no other interrupt is currently being serviced or the new interrupt is of greater priority) occurs when the CPU is performing an RETI instruction followed by a DIV as the next instruction. In this case, the response time is 18 system clock cycles: 1 clock cycle to detect the interrupt, 5 clock cycles to execute the RETI, 8 clock cycles to complete the DIV instruction and 4 clock cycles to execute the LCALL to the ISR. If the CPU is executing an ISR for an interrupt with equal or higher priority, the new interrupt will not be serviced until the current ISR completes, including the RETI and following instruction. 118 Rev. 1.4

C8051F020/1/2/3 12.3.5. Interrupt Register Descriptions The SFRs used to enable the interrupt sources and set their priority level are described below. Refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). Figure 12.9. IE: Interrupt Enable R/W R/W R/W R/W R/W R/W R/W R/W Reset Value EA IEGF0 ET2 ES0 ET1 EX1 ET0 EX0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xA8 Bit7: EA: Enable All Interrupts. This bit globally enables/disables all interrupts. When set to ‘0’, individual interrupt mask settings are overridden. 0: Disable all interrupt sources. 1: Enable each interrupt according to its individual mask setting. Bit6: IEGF0: General Purpose Flag 0. This is a general purpose flag for use under software control. Bit5: ET2: Enabler Timer 2 Interrupt. This bit sets the masking of the Timer 2 interrupt. 0: Disable Timer 2 interrupt. 1: Enable interrupt requests generated by the TF2 flag (T2CON.7). Bit4: ES0: Enable UART0 Interrupt. This bit sets the masking of the UART0 interrupt. 0: Disable UART0 interrupt. 1: Enable UART0 interrupt. Bit3: ET1: Enable Timer 1 Interrupt. This bit sets the masking of the Timer 1 interrupt. 0: Disable all Timer 1 interrupt. 1: Enable interrupt requests generated by the TF1 flag (TCON.7). Bit2: EX1: Enable External Interrupt 1. This bit sets the masking of external interrupt 1. 0: Disable external interrupt 1. 1: Enable interrupt requests generated by the /INT1 pin. Bit1: ET0: Enable Timer 0 Interrupt. This bit sets the masking of the Timer 0 interrupt. 0: Disable all Timer 0 interrupt. 1: Enable interrupt requests generated by the TF0 flag (TCON.5). Bit0: EX0: Enable External Interrupt 0. This bit sets the masking of external interrupt 0. 0: Disable external interrupt 0. 1: Enable interrupt requests generated by the /INT0 pin. Rev. 1.4 119

C8051F020/1/2/3 Figure 12.10. IP: Interrupt Priority R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - PT2 PS0 PT1 PX1 PT0 PX0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xB8 Bits7-6: UNUSED. Read = 11b, Write = don't care. Bit5: PT2: Timer 2 Interrupt Priority Control. This bit sets the priority of the Timer 2 interrupt. 0: Timer 2 interrupt priority determined by default priority order. 1: Timer 2 interrupts set to high priority level. Bit4: PS0: UART0 Interrupt Priority Control. This bit sets the priority of the UART0 interrupt. 0: UART0 interrupt priority determined by default priority order. 1: UART0 interrupts set to high priority level. Bit3: PT1: Timer 1 Interrupt Priority Control. This bit sets the priority of the Timer 1 interrupt. 0: Timer 1 interrupt priority determined by default priority order. 1: Timer 1 interrupts set to high priority level. Bit2: PX1: External Interrupt 1 Priority Control. This bit sets the priority of the External Interrupt 1 interrupt. 0: External Interrupt 1 priority determined by default priority order. 1: External Interrupt 1 set to high priority level. Bit1: PT0: Timer 0 Interrupt Priority Control. This bit sets the priority of the Timer 0 interrupt. 0: Timer 0 interrupt priority determined by default priority order. 1: Timer 0 interrupt set to high priority level. Bit0: PX0: External Interrupt 0 Priority Control. This bit sets the priority of the External Interrupt 0 interrupt. 0: External Interrupt 0 priority determined by default priority order. 1: External Interrupt 0 set to high priority level. 120 Rev. 1.4

C8051F020/1/2/3 Figure 12.11. EIE1: Extended Interrupt Enable 1 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value ECP1R ECP1F ECP0R ECP0F EPCA0 EWADC0 ESMB0 ESPI0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE6 Bit7: ECP1R: Enable Comparator1 (CP1) Rising Edge Interrupt. This bit sets the masking of the CP1 interrupt. 0: Disable CP1 Rising Edge interrupt. 1: Enable interrupt requests generated by the CP1RIF flag (CPT1CN.5). Bit6: ECP1F: Enable Comparator (CP1) Falling Edge Interrupt. This bit sets the masking of the CP1 interrupt. 0: Disable CP1 Falling Edge interrupt. 1: Enable interrupt requests generated by the CP1FIF flag (CPT1CN.4). Bit5: ECP0R: Enable Comparator0 (CP0) Rising Edge Interrupt. This bit sets the masking of the CP0 interrupt. 0: Disable CP0 Rising Edge interrupt. 1: Enable interrupt requests generated by the CP0RIF flag (CPT0CN.5). Bit4: ECP0F: Enable Comparator0 (CP0) Falling Edge Interrupt. This bit sets the masking of the CP0 interrupt. 0: Disable CP0 Falling Edge interrupt. 1: Enable interrupt requests generated by the CP0FIF flag (CPT0CN.4). Bit3: EPCA0: Enable Programmable Counter Array (PCA0) Interrupt. This bit sets the masking of the PCA0 interrupts. 0: Disable all PCA0 interrupts. 1: Enable interrupt requests generated by PCA0. Bit2: EWADC0: Enable Window Comparison ADC0 Interrupt. This bit sets the masking of ADC0 Window Comparison interrupt. 0: Disable ADC0 Window Comparison Interrupt. 1: Enable Interrupt requests generated by ADC0 Window Comparisons. Bit1: ESMB0: Enable System Management Bus (SMBus0) Interrupt. This bit sets the masking of the SMBus interrupt. 0: Disable all SMBus interrupts. 1: Enable interrupt requests generated by the SI flag (SMB0CN.3). Bit0: ESPI0: Enable Serial Peripheral Interface (SPI0) Interrupt. This bit sets the masking of SPI0 interrupt. 0: Disable all SPI0 interrupts. 1: Enable Interrupt requests generated by the SPIF flag (SPI0CN.7). Rev. 1.4 121

C8051F020/1/2/3 Figure 12.12. EIE2: Extended Interrupt Enable 2 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value EXVLD ES1 EX7 EX6 EADC1 ET4 EADC0 ET3 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE7 Bit7: EXVLD: Enable External Clock Source Valid (XTLVLD) Interrupt. This bit sets the masking of the XTLVLD interrupt. 0: Disable XTLVLD interrupt. 1: Enable interrupt requests generated by the XTLVLD flag (OSCXCN.7) Bit6: ES1: Enable UART1 Interrupt. This bit sets the masking of the UART1 interrupt. 0: Disable UART1 interrupt. 1: Enable UART1 interrupt. Bit5: EX7: Enable External Interrupt 7. This bit sets the masking of External Interrupt 7. 0: Disable External Interrupt 7. 1: Enable interrupt requests generated by the External Interrupt 7 input pin. Bit4: EX6: Enable External Interrupt 6. This bit sets the masking of External Interrupt 6. 0: Disable External Interrupt 6. 1: Enable interrupt requests generated by the External Interrupt 6 input pin. Bit3: EADC1: Enable ADC1 End Of Conversion Interrupt. This bit sets the masking of the ADC1 End of Conversion interrupt. 0: Disable ADC1 End of Conversion interrupt. 1: Enable interrupt requests generated by the ADC1 End of Conversion Interrupt. Bit2: ET4: Enable Timer 4 Interrupt This bit sets the masking of the Timer 4 interrupt. 0: Disable Timer 4 interrupt. 1: Enable interrupt requests generated by the TF4 flag (T4CON.7). Bit1: EADC0: Enable ADC0 End of Conversion Interrupt. This bit sets the masking of the ADC0 End of Conversion Interrupt. 0: Disable ADC0 Conversion Interrupt. 1: Enable interrupt requests generated by the ADC0 Conversion Interrupt. Bit0: ET3: Enable Timer 3 Interrupt. This bit sets the masking of the Timer 3 interrupt. 0: Disable all Timer 3 interrupts. 1: Enable interrupt requests generated by the TF3 flag (TMR3CN.7). 122 Rev. 1.4

C8051F020/1/2/3 Figure 12.13. EIP1: Extended Interrupt Priority 1 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value PCP1R PCP1F PCP0R PCP0F PPCA0 PWADC0 PSMB0 PSPI0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF6 Bit7: PCP1R: Comparator1 (CP1) Rising Interrupt Priority Control. This bit sets the priority of the CP1 interrupt. 0: CP1 rising interrupt set to low priority level. 1: CP1 rising interrupt set to high priority level. Bit6: PCP1F: Comparator1 (CP1) Falling Interrupt Priority Control. This bit sets the priority of the CP1 interrupt. 0: CP1 falling interrupt set to low priority level. 1: CP1 falling interrupt set to high priority level. Bit5: PCP0R: Comparator0 (CP0) Rising Interrupt Priority Control. This bit sets the priority of the CP0 interrupt. 0: CP0 rising interrupt set to low priority level. 1: CP0 rising interrupt set to high priority level. Bit4: PCP0F: Comparator0 (CP0) Falling Interrupt Priority Control. This bit sets the priority of the CP0 interrupt. 0: CP0 falling interrupt set to low priority level. 1: CP0 falling interrupt set to high priority level. Bit3: PPCA0: Programmable Counter Array (PCA0) Interrupt Priority Control. This bit sets the priority of the PCA0 interrupt. 0: PCA0 interrupt set to low priority level. 1: PCA0 interrupt set to high priority level. Bit2: PWADC0: ADC0 Window Comparator Interrupt Priority Control. This bit sets the priority of the ADC0 Window interrupt. 0: ADC0 Window interrupt set to low priority level. 1: ADC0 Window interrupt set to high priority level. Bit1: PSMB0: System Management Bus (SMBus0) Interrupt Priority Control. This bit sets the priority of the SMBus0 interrupt. 0: SMBus interrupt set to low priority level. 1: SMBus interrupt set to high priority level. Bit0: PSPI0: Serial Peripheral Interface (SPI0) Interrupt Priority Control. This bit sets the priority of the SPI0 interrupt. 0: SPI0 interrupt set to low priority level. 1: SPI0 interrupt set to high priority level. Rev. 1.4 123

C8051F020/1/2/3 Figure 12.14. EIP2: Extended Interrupt Priority 2 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value PXVLD EP1 PX7 PX6 PADC1 PT4 PADC0 PT3 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF7 Bit7: PXVLD: External Clock Source Valid (XTLVLD) Interrupt Priority Control. This bit sets the priority of the XTLVLD interrupt. 0: XTLVLD interrupt set to low priority level. 1: XTLVLD interrupt set to high priority level. Bit6: EP1: UART1 Interrupt Priority Control. This bit sets the priority of the UART1 interrupt. 0: UART1 interrupt set to low priority. 1: UART1 interrupt set to high priority. Bit5: PX7: External Interrupt 7 Priority Control. This bit sets the priority of the External Interrupt 7. 0: External Interrupt 7 set to low priority level. 1: External Interrupt 7 set to high priority level. Bit4: PX6: External Interrupt 6 Priority Control. This bit sets the priority of the External Interrupt 6. 0: External Interrupt 6 set to low priority level. 1: External Interrupt 6 set to high priority level. Bit3: PADC1: ADC1 End Of Conversion Interrupt Priority Control. This bit sets the priority of the ADC1 End of Conversion interrupt. 0: ADC1 End of Conversion interrupt set to low priority. 1: ADC1 End of Conversion interrupt set to low priority. Bit2: PT4: Timer 4 Interrupt Priority Control. This bit sets the priority of the Timer 4 interrupt. 0: Timer 4 interrupt set to low priority. 1: Timer 4 interrupt set to low priority. Bit1: PADC0: ADC End of Conversion Interrupt Priority Control. This bit sets the priority of the ADC0 End of Conversion Interrupt. 0: ADC0 End of Conversion interrupt set to low priority level. 1: ADC0 End of Conversion interrupt set to high priority level. Bit0: PT3: Timer 3 Interrupt Priority Control. This bit sets the priority of the Timer 3 interrupts. 0: Timer 3 interrupt priority determined by default priority order. 1: Timer 3 interrupt set to high priority level. 124 Rev. 1.4

C8051F020/1/2/3 12.4. Power Management Modes The CIP-51 core has two software programmable power management modes: Idle and Stop. Idle mode halts the CPU while leaving the external peripherals and internal clocks active. In Stop mode, the CPU is halted, all interrupts and timers (except the Missing Clock Detector) are inactive, and the system clock is stopped. Since clocks are running in Idle mode, power consumption is dependent upon the system clock frequency and the number of peripherals left in active mode before entering Idle. Stop mode consumes the least power. Figure 12.15 describes the Power Control Register (PCON) used to control the CIP-51's power management modes. Although the CIP-51 has Idle and Stop modes built in (as with any standard 8051 architecture), power management of the entire MCU is better accomplished by enabling/disabling individual peripherals as needed. Each analog periph- eral can be disabled when not in use and put into low power mode. Digital peripherals, such as timers or serial buses, draw little power whenever they are not in use. Turning off the Flash memory saves power, similar to entering Idle mode. Turning off the oscillator saves even more power, but requires a reset to restart the MCU. 12.4.1. Idle Mode Setting the Idle Mode Select bit (PCON.0) causes the CIP-51 to halt the CPU and enter Idle mode as soon as the instruction that sets the bit completes. All internal registers and memory maintain their original data. All analog and digital peripherals can remain active during Idle mode. Idle mode is terminated when an enabled interrupt or /RST is asserted. The assertion of an enabled interrupt will cause the Idle Mode Selection bit (PCON.0) to be cleared and the CPU to resume operation. The pending interrupt will be serviced and the next instruction to be executed after the return from interrupt (RETI) will be the instruction immediately following the one that set the Idle Mode Select bit. If Idle mode is terminated by an internal or external reset, the CIP-51 performs a normal reset sequence and begins program execution at address 0x0000. If enabled, the WDT will eventually cause an internal watchdog reset and thereby terminate the Idle mode. This fea- ture protects the system from an unintended permanent shutdown in the event of an inadvertent write to the PCON register. If this behavior is not desired, the WDT may be disabled by software prior to entering the Idle mode if the WDT was initially configured to allow this operation. This provides the opportunity for additional power savings, allowing the system to remain in the Idle mode indefinitely, waiting for an external stimulus to wake up the system. Refer to Section “13.8. Watchdog Timer Reset” on page 129 for more information on the use and configuration of the WDT. 12.4.2. Stop Mode Setting the Stop Mode Select bit (PCON.1) causes the CIP-51 to enter Stop mode as soon as the instruction that sets the bit completes. In Stop mode, the CPU and internal oscillator are stopped, effectively shutting down all digital peripherals. Each analog peripheral must be shut down individually prior to entering Stop Mode. Stop mode can only be terminated by an internal or external reset. On reset, the CIP-51 performs the normal reset sequence and begins program execution at address 0x0000. If enabled, the Missing Clock Detector will cause an internal reset and thereby terminate the Stop mode. The Missing Clock Detector should be disabled if the CPU is to be put to sleep for longer than the MCD timeout of 100 µs. Rev. 1.4 125

C8051F020/1/2/3 Figure 12.15. PCON: Power Control R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SMOD0 SSTAT0 Reserved SMOD1 SSTAT1 Reserved STOP IDLE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x87 Bit7: SMOD0: UART0 Baud Rate Doubler Enable. This bit enables/disables the divide-by-two function of the UART0 baud rate logic for configurations described in the UART0 section. 0: UART0 baud rate divide-by-two enabled. 1: UART0 baud rate divide-by-two disabled. Bit6: SSTAT0: UART0 Enhanced Status Mode Select. This bit controls the access mode of the SM20-SM00 bits in register SCON0. 0: Reads/writes of SM20-SM00 access the SM20-SM00 UART0 mode setting. 1: Reads/writes of SM20-SM00 access the Framing Error (FE0), RX Overrun (RXOV0), and TX Collision (TXCOL0) status bits. Bit5: Reserved. Read is undefined. Must write 0. Bit4: SMOD1: UART1 Baud Rate Doubler Enable. This bit enables/disables the divide-by-two function of the UART1 baud rate logic for configurations described in the UART1 section. 0: UART1 baud rate divide-by-two enabled. 1: UART1 baud rate divide-by-two disabled. Bit3: SSTAT1: UART1 Enhanced Status Mode Select. This bit controls the access mode of the SM21-SM01 bits in SCON1. 0: Reads/writes of SM21-SM01 access the SM21-SM01 UART1 mode setting. 1: Reads/writes of SM21-SM01 access the Framing Error (FE1), RX Overrun (RXOV1), and TX Collision (TXCOL1) status bits. Bit2: Reserved. Read is undefined. Must write 0. Bit1: STOP: STOP Mode Select. Writing a ‘1’ to this bit will place the CIP-51 into STOP mode. This bit will always read ‘0’. 1: CIP-51 forced into power-down mode. (Turns off internal oscillator). Bit0: IDLE: IDLE Mode Select. Writing a ‘1’ to this bit will place the CIP-51 into IDLE mode. This bit will always read ‘0’. 1: CIP-51 forced into idle mode. (Shuts off clock to CPU, but clock to Timers, Interrupts, and all peripherals remain active.) 126 Rev. 1.4

C8051F020/1/2/3 13. RESET SOURCES Reset circuitry allows the controller to be easily placed in a predefined default condition. On entry to this reset state, the following occur: • CIP-51 halts program execution • Special Function Registers (SFRs) are initialized to their defined reset values • External port pins are forced to a known state • Interrupts and timers are disabled. All SFRs are reset to the predefined values noted in the SFR detailed descriptions. The contents of internal data mem- ory are unaffected during a reset; any previously stored data is preserved. However, since the stack pointer SFR is reset, the stack is effectively lost even though the data on the stack are not altered. The I/O port latches are reset to 0xFF (all logic 1’s), activating internal weak pull-ups which take the external I/O pins to a high state. Note that weak pull-ups are disabled during the reset, and enabled when the device exits the reset state. This allows power to be conserved while the part is held in reset. For VDD Monitor resets, the /RST pin is driven low until the end of the VDD reset timeout. On exit from the reset state, the program counter (PC) is reset, and the system clock defaults to the internal oscillator running at 2 MHz. Refer to Section “14. OSCILLATORS” on page 135 for information on selecting and configuring the system clock source. The Watchdog Timer is enabled using its longest timeout interval (see Section “13.8. Watchdog Timer Reset” on page 129). Once the system clock source is stable, program execution begins at location 0x0000. There are seven sources for putting the MCU into the reset state: power-on/power-fail, external /RST pin, external CNVSTR signal, software command, Comparator0, Missing Clock Detector, and Watchdog Timer. Each reset source is described in the following sections. Figure 13.1. Reset Sources VDD (Port CNVSTR I/O) Crossbar Supply (CNVSTR Monitor erneasbelet) +- TSRimuepespoeluytt (wired-OR) /RST Comparator0 CP0+ + - CP0- (CP0 reset enable) Reset Missing WDT Funnel Clock Detector (one- shot) EN EN PRE Internal MCDEnable WDTEnable WDTStrobe Clock Generator System Software Reset XTAL1 Clock CIP-51 OSC Microcontroller XTAL2 Clock Select Core System Reset Extended Interrupt Handler Rev. 1.4 127

C8051F020/1/2/3 13.1. Power-on Reset The C8051F020/1/2/3 family incorporates a power supply monitor that holds the MCU in the reset state until VDD rises above the V level during power-up. See Figure 13.2 for timing diagram, and refer to Table 13.1 for the Elec- RST trical Characteristics of the power supply monitor circuit. The /RST pin is asserted low until the end of the 100 ms VDD Monitor timeout in order to allow the VDD supply to stabilize. On exit from a power-on reset, the PORSF flag (RSTSRC.1) is set by hardware to logic 1. All of the other reset flags in the RSTSRC Register are indeterminate. PORSF is cleared by all other resets. Since all resets cause program exe- cution to begin at the same location (0x0000), software can read the PORSF flag to determine if a power-up was the cause of reset. The contents of internal data memory should be assumed to be undefined after a power-on reset. The VDD monitor function is enabled by tying the MONEN pin directly to VDD. This is the recommended configuration for the MONEN pin. . Figure 13.2. Reset Timing s olt v 2.70 V RST 2.55 2.0 D D V 1.0 t /RST Logic HIGH 100ms 100ms Logic LOW Power-On Reset VDD Monitor Reset 13.2. Power-fail Reset When a power-down transition or power irregularity causes VDD to drop below V , the power supply monitor will RST drive the /RST pin low and return the CIP-51 to the reset state. When VDD returns to a level above VRST, the CIP-51 will leave the reset state in the same manner as that for the power-on reset (see Figure 13.2). Note that even though internal data memory contents are not altered by the power-fail reset, it is impossible to determine if VDD dropped below the level required for data retention. If the PORSF flag is set to logic 1, the data may no longer be valid. 128 Rev. 1.4

C8051F020/1/2/3 13.3. External Reset The external /RST pin provides a means for external circuitry to force the MCU into a reset state. Asserting the /RST pin low will cause the MCU to enter the reset state. It may be desirable to provide an external pull-up and/or decou- pling of the /RST pin to avoid erroneous noise-induced resets. The MCU will remain in reset until at least 12 clock cycles after the active-low /RST signal is removed. The PINRSF flag (RSTSRC.0) is set on exit from an external reset. 13.4. Software Forced Reset Writing a ‘1’ to the SWRSEF bit forces a Software Reset as described in Section 13.1. 13.5. Missing Clock Detector Reset The Missing Clock Detector is essentially a one-shot circuit that is triggered by the MCU system clock. If the system clock goes away for more than 100 µs, the one-shot will time out and generate a reset. After a Missing Clock Detector reset, the MCDRSF flag (RSTSRC.2) will be set, signifying the MSD as the reset source; otherwise, this bit reads ‘0’. The state of the /RST pin is unaffected by this reset. Setting the MSCLKE bit in the OSCICN register (see Section “14. OSCILLATORS” on page 135) enables the Missing Clock Detector. 13.6. Comparator0 Reset Comparator0 can be configured as a reset input by writing a ‘1’ to the C0RSEF flag (RSTSRC.5). Comparator0 should be enabled using CPT0CN.7 (see Section “11. COMPARATORS” on page 95) prior to writing to C0RSEF to prevent any turn-on chatter on the output from generating an unwanted reset. The Comparator0 reset is active-low: if the non-inverting input voltage (CP0+ pin) is less than the inverting input voltage (CP0- pin), the MCU is put into the reset state. After a Comparator0 Reset, the C0RSEF flag (RSTSRC.5) will read ‘1’ signifying Comparator0 as the reset source; otherwise, this bit reads ‘0’. The state of the /RST pin is unaffected by this reset. 13.7. External CNVSTR Pin Reset The external CNVSTR signal can be configured as a reset input by writing a ‘1’ to the CNVRSEF flag (RSTSRC.6). The CNVSTR signal can appear on any of the P0, P1, P2 or P3 I/O pins as described in Section “17.1. Ports 0 through 3 and the Priority Crossbar Decoder” on page 163. Note that the Crossbar must be configured for the CNVSTR signal to be routed to the appropriate Port I/O. The Crossbar should be configured and enabled before the CNVRSEF is set. When configured as a reset, CNVSTR is active-low and level sensitive. After a CNVSTR reset, the CNVRSEF flag (RSTSRC.6) will read ‘1’ signifying CNVSTR as the reset source; otherwise, this bit reads ‘0’. The state of the /RST pin is unaffected by this reset. 13.8. Watchdog Timer Reset The MCU includes a programmable Watchdog Timer (WDT) running off the system clock. A WDT overflow will force the MCU into the reset state. To prevent the reset, the WDT must be restarted by application software before overflow. If the system experiences a software/hardware malfunction preventing the software from restarting the WDT, the WDT will overflow and cause a reset. This should prevent the system from running out of control. Following a reset the WDT is automatically enabled and running with the default maximum time interval. If desired the WDT can be disabled by system software or locked on to prevent accidental disabling. Once locked, the WDT cannot be disabled until the next system reset. The state of the /RST pin is unaffected by this reset. The WDT consists of a 21-bit timer running from the programmed system clock. The timer measures the period between specific writes to its control register. If this period exceeds the programmed limit, a WDT reset is generated. The WDT can be enabled and disabled as needed in software, or can be permanently enabled if desired. Watchdog features are controlled via the Watchdog Timer Control Register (WDTCN) shown in Figure 13.3. Rev. 1.4 129

C8051F020/1/2/3 13.8.1. Enable/Reset WDT The watchdog timer is both enabled and reset by writing 0xA5 to the WDTCN register. The user's application soft- ware should include periodic writes of 0xA5 to WDTCN as needed to prevent a watchdog timer overflow. The WDT is enabled and reset as a result of any system reset. 13.8.2. Disable WDT Writing 0xDE followed by 0xAD to the WDTCN register disables the WDT. The following code segment illustrates disabling the WDT: CLR EA ; disable all interrupts MOV WDTCN,#0DEh ; disable software watchdog timer MOV WDTCN,#0ADh SETB EA ; re-enable interrupts The writes of 0xDE and 0xAD must occur within 4 clock cycles of each other, or the disable operation is ignored. Interrupts should be disabled during this procedure to avoid delay between the two writes. 13.8.3. Disable WDT Lockout Writing 0xFF to WDTCN locks out the disable feature. Once locked out, the disable operation is ignored until the next system reset. Writing 0xFF does not enable or reset the watchdog timer. Applications always intending to use the watchdog should write 0xFF to WDTCN in the initialization code. 13.8.4. Setting WDT Interval WDTCN.[2:0] control the watchdog timeout interval. The interval is given by the following equation: 43+WDTCN[2–0]× T ; where T is the system clock period. sysclk sysclk For a 2 MHz system clock, this provides an interval range of 0.032 ms to 524 ms. WDTCN.7 must be logic 0 when setting this interval. Reading WDTCN returns the programmed interval. WDTCN.[2:0] reads 111b after a system reset. 130 Rev. 1.4

C8051F020/1/2/3 Figure 13.3. WDTCN: Watchdog Timer Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value xxxxx111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xFF Bits7-0: WDT Control Writing 0xA5 both enables and reloads the WDT. Writing 0xDE followed within 4 system clocks by 0xAD disables the WDT. Writing 0xFF locks out the disable feature. Bit4: Watchdog Status Bit (when Read) Reading the WDTCN.[4] bit indicates the Watchdog Timer Status. 0: WDT is inactive 1: WDT is active Bits2-0: Watchdog Timeout Interval Bits The WDTCN.[2:0] bits set the Watchdog Timeout Interval. When writing these bits, WDTCN.7 must be set to 0. Rev. 1.4 131

C8051F020/1/2/3 Figure 13.4. RSTSRC: Reset Source Register R R/W R/W R/W R R R/W R Reset Value - CNVRSEF C0RSEF SWRSEF WDTRSF MCDRSF PORSF PINRSF Variable Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xEF (Note: Do not use read-modify-write operations on this register.) Bit7: Reserved. Bit6: CNVRSEF: Convert Start Reset Source Enable and Flag Write: 0: CNVSTR is not a reset source. 1: CNVSTR is a reset source (active low). Read: 0: Source of prior reset was not CNVSTR. 1: Source of prior reset was CNVSTR. Bit5: C0RSEF: Comparator0 Reset Enable and Flag Write: 0: Comparator0 is not a reset source. 1: Comparator0 is a reset source (active low). Read: 0: Source of prior reset was not Comparator0. 1: Source of prior reset was Comparator0. Bit4: SWRSF: Software Reset Force and Flag Write: 0: No Effect. 1: Forces an internal reset. /RST pin is not affected. Read: 0: Prior reset source was not a write to the SWRSF bit. 1: Prior reset source was a write to the SWRSF bit. Bit3: WDTRSF: Watchdog Timer Reset Flag 0: Source of prior reset was not WDT timeout. 1: Source of prior reset was WDT timeout. Bit2: MCDRSF: Missing Clock Detector Flag 0: Source of prior reset was not Missing Clock Detector timeout. 1: Source of prior reset was Missing Clock Detector timeout. Bit1: PORSF: Power-On Reset Force and Flag Write: 0: No effect. 1: Forces a Power-On Reset. /RST is driven low. Read: 0: Source of prior reset was not POR. 1: Source of prior reset was POR. Bit0: PINRSF: HW Pin Reset Flag 0: Source of prior reset was not /RST pin. 1: Source of prior reset was /RST pin. 132 Rev. 1.4

C8051F020/1/2/3 Table 13.1. Reset Electrical Characteristics -40°C to +85°C unless otherwise specified. PARAMETER CONDITIONS MIN TYP MAX UNITS VDD - /RST Output High Voltage I = -3 mA V OH 0.7 /RST Output Low Voltage I = 8.5 mA, VDD = 2.7 V to 3.6 V 0.6 V OL 0.7 x /RST Input High Voltage V VDD 0.3 x /RST Input Low Voltage VDD /RST Input Leakage Current /RST = 0.0 V 50 µA VDD for /RST Output Valid 1.0 V AV+ for /RST Output Valid 1.0 V VDD POR Threshold (V ) 2.40 2.55 2.70 V RST Minimum /RST Low Time to 10 ns Generate a System Reset /RST rising edge after VDD crosses Reset Time Delay 80 100 120 ms V threshold RST Time from last system clock to reset Missing Clock Detector Timeout 100 220 500 µs initiation Rev. 1.4 133

C8051F020/1/2/3 Notes 134 Rev. 1.4

C8051F020/1/2/3 14. OSCILLATORS Each MCU includes an internal oscillator and an external oscillator drive circuit, either of which can generate the sys- tem clock. The MCUs operate from the internal oscillator after any reset. This internal oscillator can be enabled/dis- abled and its frequency can be set using the Internal Oscillator Control Register (OSCICN) as shown in Figure 14.1. The internal oscillator's electrical specifications are given in Table 14.1. Both oscillators are disabled when the /RST pin is held low. The MCUs can run from the internal oscillator perma- nently, or can switch to the external oscillator if desired using CLKSL bit in the OSCICN Register. The external oscil- lator requires an external resonator, crystal, capacitor, or RC network connected to the XTAL1/XTAL2 pins (see Table 14.1). The oscillator circuit must be configured for one of these sources in the OSCXCN register. An external CMOS clock can also provide the system clock; in this configuration, the XTAL1 pin is used as the CMOS clock input. The XTAL1 and XTAL2 pins are NOT 5V tolerant. Figure 14.1. Oscillator Diagram OSCICN MSCLKE IFRDYCLKSLIOSCENIFCN1IFCN0 VDD EN Internal Clock opt. 2 Generator AV+ SYSCLK AV+ opt. 4 opt. 3 opt. 1 XTAL1 XTAL1 XTAL1 XTAL1 Input OSC XTAL2 XTAL2 Circuit AGND 210 XTLVLDOSCMDOSCMDOSCMD XFCN2XFCN1XFCN0 XXX OSCXCN Rev. 1.4 135

C8051F020/1/2/3 Figure 14.2. OSCICN: Internal Oscillator Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value MSCLKE - - IFRDY CLKSL IOSCEN IFCN1 IFCN0 00010100 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB2 Bit7: MSCLKE: Missing Clock Enable Bit 0: Missing Clock Detector Disabled 1: Missing Clock Detector Enabled; reset triggered if clock is missing for more than 100 µs Bits6-5: UNUSED. Read = 00b, Write = don't care Bit4: IFRDY: Internal Oscillator Frequency Ready Flag 0: Internal Oscillator Frequency not running at speed specified by the IFCN bits. 1: Internal Oscillator Frequency running at speed specified by the IFCN bits. Bit3: CLKSL: System Clock Source Select Bit 0: Uses Internal Oscillator as System Clock. 1: Uses External Oscillator as System Clock. Bit2: IOSCEN: Internal Oscillator Enable Bit 0: Internal Oscillator Disabled 1: Internal Oscillator Enabled Bits1-0: IFCN1-0: Internal Oscillator Frequency Control Bits 00: Internal Oscillator typical frequency is 2 MHz. 01: Internal Oscillator typical frequency is 4 MHz. 10: Internal Oscillator typical frequency is 8 MHz. 11: Internal Oscillator typical frequency is 16 MHz. Table 14.1. Internal Oscillator Electrical Characteristics VDD = 2.7V to 3.6V; T = -40°C to +85°C a PARAMETER CONDITIONS MIN TYP MAX UNITS OSCICN.[1:0] = 00 1.5 2 2.4 OSCICN.[1:0] = 01 3.1 4 4.8 Internal Oscillator Frequency MHz OSCICN.[1:0] = 10 6.2 8 9.6 OSCICN.[1:0] = 11 12.3 16 19.2 Internal Oscillator Current OSCICN.2 = 1 200 µA Consumption (from VDD) 136 Rev. 1.4

C8051F020/1/2/3 Figure 14.3. OSCXCN: External Oscillator Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value XTLVLD XOSCMD2XOSCMD1XOSCMD0 - XFCN2 XFCN1 XFCN0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB1 Bit7: XTLVLD: Crystal Oscillator Valid Flag (Valid only when XOSCMD = 11x.) 0: Crystal Oscillator is unused or not yet stable 1: Crystal Oscillator is running and stable Bits6-4: XOSCMD2-0: External Oscillator Mode Bits 00x: Off. XTAL1 pin is grounded internally. 010: System Clock from External CMOS Clock on XTAL1 pin. 011: System Clock from External CMOS Clock on XTAL1 pin divided by 2. 10x: RC/C Oscillator Mode with divide by 2 stage. 110: Crystal Oscillator Mode 111: Crystal Oscillator Mode with divide by 2 stage. Bit3: RESERVED. Read = undefined, Write = don't care Bits2-0: XFCN2-0: External Oscillator Frequency Control Bits 000-111: XFCN Crystal (XOSCMD = 11x) RC (XOSCMD = 10x) C (XOSCMD = 10x) 000 f < 12 kHz f < 25 kHz K Factor = 0.44 001 12 kHz < f ≤ 30 kHz 25 kHz < f ≤ 50 kHz K Factor = 1.4 010 30 kHz < f ≤ 95 kHz 50 kHz < f ≤ 100 kHz K Factor = 4.4 011 95 kHz < f ≤ 270 kHz 100 kHz < f ≤ 200 kHz K Factor = 13 100 270 kHz < f ≤ 720 kHz 200 kHz < f ≤ 400 kHz K Factor = 38 101 720 kHz < f ≤ 2.2 MHz 400 kHz < f ≤ 800 kHz K Factor = 100 110 2.2 MHz < f ≤ 6.7 MHz 800 kHz < f ≤ 1.6 MHz K Factor = 420 111 f > 6.7 MHz 1.6 MHz < f ≤ 3.2 MHz K Factor = 1400 CRYSTAL MODE (Circuit from Figure 14.1, Option 1; XOSCMD = 11x) Choose XFCN value to match the crystal or ceramic resonator frequency. RC MODE (Circuit from Figure 14.1, Option 2; XOSCMD = 10x) Choose oscillation frequency range where: f = 1.23(103) / (R * C), where f = frequency of oscillation in MHz C = capacitor value in pF R = Pull-up resistor value in kΩ C MODE (Circuit from Figure 14.1, Option 3; XOSCMD = 10x) Choose K Factor (KF) for the oscillation frequency desired: f = KF / (C * AV+), where f = frequency of oscillation in MHz C = capacitor value on XTAL1, XTAL2 pins in pF AV+ = Analog Power Supply on MCU in volts Rev. 1.4 137

C8051F020/1/2/3 14.1. External Crystal Example If a crystal or ceramic resonator is used as an external oscillator source for the MCU, the circuit should be as shown in Figure 14.1, Option 1. The External Oscillator Frequency Control value (XFCN) should be chosen from the Crys- tal column of the table in Figure 14.3 (OSCXCN register). For example, an 11.0592 MHz crystal requires an XFCN setting of 111b. The Crystal Oscillator Valid Flag (XTLVLD in register OSCXCN) is set to logic 1 by hardware when the external crystal oscillator is running and stable. The XTLVLD detection circuit requires a startup time of at least 1 ms between enabling the oscillator and checking the XTLVLD bit. Switching to the external oscillator before the crystal oscillator has stabilized can result in unpredictable behavior. The recommended procedure is: Step 1. Enable the external oscillator. Step 2. Wait at least 1 ms. Step 3. Poll for XTLVLD => ‘1’. Step 4. Switch the system clock to the external oscillator. Important Note: Crystal oscillator circuits are quite sensitive to PCB layout. The crystal should be placed as close as possible to the XTAL pins on the device, as should the loading capacitors on the crystal pins. The traces should be as short as possible and shielded with ground plane from any other traces which could introduce noise or interference. 14.2. External RC Example If an RC network is used as an external oscillator source for the MCU, the circuit should be as shown in Figure 14.1, Option 2. The capacitor must be no greater than 100 pF; however for small capacitors (less than ~20 pF), the total capacitance may be dominated by PWB parasitic capacitance. To determine the required External Oscillator Fre- quency Control value (XFCN) in the OSCXCN Register, first select the RC network value to produce the desired fre- quency of oscillation. If the frequency desired is 100 kHz, let R = 246 kΩ and C = 50 pF: f = 1.23( 103 ) / RC = 1.23 ( 103 ) / [ 246 * 50 ] = 0.1 MHz = 100 kHz XFCN ≥ log ( f / 25 kHz ) 2 XFCN ≥ log ( 100 kHz / 25 kHz ) = log ( 4 ) 2 2 XFCN ≥ 2, or code 010b 14.3. External Capacitor Example If a capacitor is used as an external oscillator for the MCU, the circuit should be as shown in Figure 14.1, Option 3. The capacitor must be no greater than 100 pF; however for small capacitors (less than ~20 pF), the total capacitance may be dominated by PWB parasitic capacitance. To determine the required External Oscillator Frequency Control value (XFCN) in the OSCXCN Register, select the capacitor to be used and find the frequency of oscillation from the equations below. Assume VDD = 3.0 V and C = 50 pF: f = KF / ( C * VDD ) = KF / ( 50 * 3 ) f = KF / 150 If a frequency of roughly 90 kHz is desired, select the K Factor from the table in Figure 14.3 as KF = 13: f = 13 / 150 = 0.087 MHz, or 87 kHz Therefore, the XFCN value to use in this example is 011b. 138 Rev. 1.4

C8051F020/1/2/3 15. FLASH MEMORY The C8051F020/1/2/3 family includes 64k + 128 bytes of on-chip, reprogrammable FLASH memory for program code and non-volatile data storage. The FLASH memory can be programmed in-system, a single byte at a time, through the JTAG interface or by software. Once cleared to logic 0, a FLASH bit must be erased to set it back to logic 1. The bytes would typically be erased (set to 0xFF) before being reprogrammed. FLASH write and erase oper- ations are automatically timed by hardware for proper execution; data polling to determine the end of the write/erase operation is not required. Refer to Table 15.1 for the electrical characteristics of the FLASH memory. 15.1. Programming The FLASH Memory The simplest means of programming the FLASH memory is through the JTAG interface using programming tools provided by Silicon Labs or a third party vendor. This is the only means for programming a non-initialized device. For details on the JTAG commands to program FLASH memory, see Section “24.2. Flash Programming Com- mands” on page 268. The FLASH memory can be programmed by software using a MOVX write instruction, with the address and data byte to be programmed provided as normal operands. Before writing to FLASH memory using a MOVX write, FLASH write operations must be enabled by setting the PSWE Program Store Write Enable bit (PSCTL.0) to logic 1. This directs the MOVX writes to FLASH memory instead of XRAM. The PSWE bit remains set until cleared by soft- ware. To avoid errant FLASH writes, it is recommended that interrupts be disabled while the PSWE bit is logic 1. FLASH memory is read using the MOVC read instruction. MOVX reads are always directed to XRAM, regardless of the state of PSWE. To ensure the integrity of FLASH contents, it is strongly recommended that the on-chip VDD monitor be enabled by tying the MONEN pin to VDD in any system which includes code that writes to or erases FLASH memory from software. A write to FLASH memory can clear bits but cannot set them; only an erase operation can set bits in FLASH. A byte location to be programmed must be erased before a new value can be written. The 64k byte FLASH memory is organized in 512-byte pages. The erase operation applies to an entire page (setting all bytes in the page to 0xFF). The following steps illustrate the algorithm for programming FLASH by user software. Step 1. Disable interrupts. Step 2. Set FLWE (FLSCL.0) to enable FLASH writes/erases via user software. Step 3. Set PSEE (PSCTL.1) to enable FLASH erases. Step 4. Set PSWE (PSCTL.0) to redirect MOVX commands to write to FLASH. Step 5. Use the MOVX command to write a data byte to any location within the 512-byte page to be erased. Step 6. Clear PSEE to disable FLASH erases Step 7. Use the MOVX command to write a data byte to the desired byte location within the erased 512-byte page. Repeat this step until all desired bytes are written (within the target page). Step 8. Clear the PSWE bit to redirect MOVX commands to the XRAM data space. Step 9. Re-enable interrupts. Rev. 1.4 139

C8051F020/1/2/3 Write/Erase timing is automatically controlled by hardware. Note that code execution in the 8051 is stalled while the FLASH is being programmed or erased. Interrupts that are posted during a FLASH write or erase operation are held pending until the FLASH operation has completed, at which time they are serviced by the CPU in priority order. Table 15.1. FLASH Electrical Characteristics VDD = 2.7V to 3.6V; T = -40°C to +85°C a PARAMETER CONDITIONS MIN TYP MAX UNITS Endurance 20k 100k Erase/Write Erase Cycle Time 10 12 14 ms Write Cycle Time 40 50 60 µs 15.2. Non-volatile Data Storage The FLASH memory can be used for non-volatile data storage as well as program code. This allows data such as cal- ibration coefficients to be calculated and stored at run time. Data is written using the MOVX write instruction (as described in the previous section) and read using the MOVC read instruction. An additional 128-byte sector of FLASH memory is included for non-volatile data storage. Its smaller sector size makes it particularly well suited as general purpose, non-volatile scratchpad memory. Even though FLASH memory can be written a single byte at a time, an entire sector must be erased first. In order to change a single byte of a multi- byte data set, the data must be moved to temporary storage. The 128-byte sector-size facilitates updating data without wasting program memory or RAM space. The 128-byte sector is double-mapped over the 64k byte FLASH memory; its address ranges from 0x00 to 0x7F (see Figure 15.1). To access this 128-byte sector, the SFLE bit in PSCTL must be set to logic 1. Code execution from this 128-byte scratchpad sector is not permitted. 15.3. Security Options The CIP-51 provides security options to protect the FLASH memory from inadvertent modification by software as well as prevent the viewing of proprietary program code and constants. The Program Store Write Enable (PSCTL.0) and the Program Store Erase Enable (PSCTL.1) bits protect the FLASH memory from accidental modification by software. These bits must be explicitly set to logic 1 before software can modify the FLASH memory. Additional security features prevent proprietary program code and data constants from being read or altered across the JTAG interface or by software running on the system controller. A set of security lock bytes stored at 0xFDFE and 0xFDFF protect the FLASH program memory from being read or altered across the JTAG interface. Each bit in a security lock-byte protects one 8k-byte block of memory. Clearing a bit to logic 0 in a Read Lock Byte prevents the corresponding block of FLASH memory from being read across the JTAG interface. Clearing a bit in the Write/Erase Lock Byte protects the block from JTAG erasures and/or writes. The 128-byte scratchpad sector is locked only when all other sectors are locked. The Read Lock Byte is at location 0xFDFF. The Write/Erase Lock Byte is located at 0xFDFE. Figure 15.1 shows the location and bit definitions of the security bytes. The 512-byte sector containing the lock bytes can be written to, but not erased by software. An attempted read of a read-locked byte returns undefined data. Debugging code in a read- locked sector is not possible through the JTAG port. 140 Rev. 1.4

C8051F020/1/2/3 Figure 15.1. FLASH Program Memory Map and Security Bytes Read and Write/Erase Security Bits. SFLE = 0 SFLE = 1 (Bit 7 is MSB.) Bit Memory Block 0xFFFF Scratchpad Memory 0x007F Reserved 7 0xE000 - 0xFDFD (Data only) 0x0000 0xFE00 6 0xC000 - 0xDFFF Read Lock Byte 0xFDFF 5 0xA000 - 0xBFFF 4 0x8000 - 0x9FFF Write/Erase Lock Byte 0xFDFE 3 0x6000 - 0x7FFF 0xFDFD 2 0x4000 - 0x5FFF Program/Data 1 0x2000 - 0x3FFF Memory Space 0 0x0000 - 0x1FFF Software Read Limit 0x0000 FLASH Read Lock Byte Bits7-0: Each bit locks a corresponding block of memory. (Bit7 is MSB). 0: Read operations are locked (disabled) for corresponding block across the JTAG interface. 1: Read operations are unlocked (enabled) for corresponding block across the JTAG interface. FLASH Write/Erase Lock Byte Bits7-0: Each bit locks a corresponding block of memory. 0: Write/Erase operations are locked (disabled) for corresponding block across the JTAG interface. 1: Write/Erase operations are unlocked (enabled) for corresponding block across the JTAG interface. NOTE: When the highest block is locked, the security bytes may be written but not erased. FLASH access Limit Register (FLACL) The content of this register is used as the high byte of the 16-bit software read limit address. This 16- bit read limit address value is calculated as 0xNN00 where NN is replaced by content of this register on reset. Software running at or above this address is prohibited from using the MOVX and MOVC instructions to read, write, or erase FLASH locations below this address. Any attempts to read loca- tions below this limit will return the value 0x00. The lock bits can always be read and cleared to logic 0 regardless of the security setting applied to the block contain- ing the security bytes. This allows additional blocks to be protected after the block containing the security bytes has been locked. Important Note: The only means of removing a lock once set is to erase the entire program mem- ory space by performing a JTAG erase operation (i.e. cannot be done in user firmware). Addressing either security byte while performing a JTAG erase operation will automatically initiate erasure of the entire pro- gram memory space (except for the reserved area). This erasure can only be performed via JTAG. If a non- security byte in the 0xFBFF-0xFDFF page is addressed during the JTAG erasure, only that page (including the security bytes) will be erased. The FLASH Access Limit security feature (see Figure 15.1) protects proprietary program code and data from being read by software running on the C8051F020/1/2/3. This feature provides support for OEMs that wish to program the Rev. 1.4 141

C8051F020/1/2/3 MCU with proprietary value-added firmware before distribution. The value-added firmware can be protected while allowing additional code to be programmed in remaining program memory space later. The Software Read Limit (SRL) is a 16-bit address that establishes two logical partitions in the program memory space. The first is an upper partition consisting of all the program memory locations at or above the SRL address, and the second is a lower partition consisting of all the program memory locations starting at 0x0000 up to (but exclud- ing) the SRL address. Software in the upper partition can execute code in the lower partition, but is prohibited from reading locations in the lower partition using the MOVC instruction. (Executing a MOVC instruction from the upper partition with a source address in the lower partition will always return a data value of 0x00.) Software running in the lower partition can access locations in both the upper and lower partition without restriction. The Value-added firmware should be placed in the lower partition. On reset, control is passed to the value-added firmware via the reset vector. Once the value-added firmware completes its initial execution, it branches to a predeter- mined location in the upper partition. If entry points are published, software running in the upper partition may exe- cute program code in the lower partition, but it cannot read the contents of the lower partition. Parameters may be passed to the program code running in the lower partition either through the typical method of placing them on the stack or in registers before the call or by placing them in prescribed memory locations in the upper partition. The SRL address is specified using the contents of the FLASH Access Register. The 16-bit SRL address is calculated as 0xNN00, where NN is the contents of the SRL Security Register. Thus, the SRL can be located on 256-byte bound- aries anywhere in program memory space. However, the 512-byte erase sector size essentially requires that a 512 boundary be used. The contents of a non-initialized SRL security byte is 0x00, thereby setting the SRL address to 0x0000 and allowing read access to all locations in program memory space by default. Figure 15.2. FLACL: FLASH Access Limit R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB7 Bits 7-0: FLACL: FLASH Access Limit. This register holds the high byte of the 16-bit program memory read/write/erase limit address. The entire 16-bit access limit address value is calculated as 0xNN00 where NN is replaced by contents of FLACL. A write to this register sets the FLASH Access Limit. This register can only be written once after any reset. Any subsequent writes are ignored until the next reset. 142 Rev. 1.4

C8051F020/1/2/3 Figure 15.3. FLSCL: FLASH Memory Control R/W R/W R/W R/W R/W R/W R/W R/W Reset Value FOSE FRAE Reserved Reserved Reserved Reserved Reserved FLWE 10000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB6 Bit7: FOSE: FLASH One-Shot Timer Enable This is the timer that turns off the sense amps after a FLASH read. 0: FLASH One-Shot Timer disabled. 1: FLASH One-Shot Timer enabled. Bit6: FRAE: FLASH Read Always Enable 0: FLASH reads per One-Shot Timer. 1: FLASH always in read mode. Bits5-1: RESERVED. Read = 00000b. Must Write 00000b. Bit0: FLWE: FLASH Read/Write Enable This bit must be set to allow FLASH writes from user software. 0: FLASH writes disabled. 1: FLASH writes enabled. Rev. 1.4 143

C8051F020/1/2/3 Figure 15.4. PSCTL: Program Store Read/Write Control R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - - - - SFLE PSEE PSWE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8F Bits7-3: UNUSED. Read = 00000b, Write = don't care. Bit2: SFLE: Scratchpad FLASH Memory Access Enable. When this bit is set, FLASH reads and writes from user software are directed to the 128-byte Scratch- pad FLASH sector. When SFLE is set to logic 1, FLASH accesses out of the address range 0x00- 0x7F should not be attempted. Reads/Writes out of this range will yield unpredictable results. 0: FLASH access from user software directed to the 64k byte Program/Data FLASH sector. 1: FLASH access from user software directed to the 128 byte Scratchpad sector. Bit1: PSEE: Program Store Erase Enable. Setting this bit allows an entire page of the FLASH program memory to be erased provided the PSWE bit is also set. After setting this bit, a write to FLASH memory using the MOVX instruction will erase the entire page that contains the location addressed by the MOVX instruction. The value of the data byte written does not matter. 0: FLASH program memory erasure disabled. 1: FLASH program memory erasure enabled. Bit0: PSWE: Program Store Write Enable. Setting this bit allows writing a byte of data to the FLASH program memory using the MOVX instruction. The location must be erased before writing data. 0: Write to FLASH program memory disabled. 1: Write to FLASH program memory enabled. 144 Rev. 1.4

C8051F020/1/2/3 16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM The C8051F020/1/2/3 MCUs include 4k bytes of on-chip RAM mapped into the external data memory space (XRAM), as well as an External Data Memory Interface which can be used to access off-chip memories and memory- mapped devices connected to the GPIO ports. The external memory space may be accessed using the external move instruction (MOVX) and the data pointer (DPTR), or using the MOVX indirect addressing mode using R0 or R1. If the MOVX instruction is used with an 8-bit address operand (such as @R1), then the high byte of the 16-bit address is provided by the External Memory Interface Control Register (EMI0CN, shown in Figure 16.1). Note: the MOVX instruction can also be used for writing to the FLASH memory. See Section “15. FLASH MEMORY” on page 139 for details. The MOVX instruction accesses XRAM by default. The EMIF can be configured to appear on the lower I/O ports (P0-P3) or the upper I/O ports (P4-P7). 16.1. Accessing XRAM The XRAM memory space is accessed using the MOVX instruction. The MOVX instruction has two forms, both of which use an indirect addressing method. The first method uses the Data Pointer, DPTR, a 16-bit register which con- tains the effective address of the XRAM location to be read or written. The second method uses R0 or R1 in combina- tion with the EMI0CN register to generate the effective XRAM address. Examples of both of these methods are given below. 16.1.1. 16-Bit MOVX Example The 16-bit form of the MOVX instruction accesses the memory location pointed to by the contents of the DPTR reg- ister. The following series of instructions reads the value of the byte at address 0x1234 into the accumulator A: MOV DPTR, #1234h ; load DPTR with 16-bit address to read (0x1234) MOVX A, @DPTR ; load contents of 0x1234 into accumulator A The above example uses the 16-bit immediate MOV instruction to set the contents of DPTR. Alternately, the DPTR can be accessed through the SFR registers DPH, which contains the upper 8-bits of DPTR, and DPL, which contains the lower 8-bits of DPTR. 16.1.2. 8-Bit MOVX Example The 8-bit form of the MOVX instruction uses the contents of the EMI0CN SFR to determine the upper 8-bits of the effective address to be accessed and the contents of R0 or R1 to determine the lower 8-bits of the effective address to be accessed. The following series of instructions read the contents of the byte at address 0x1234 into the accumulator A. MOV EMI0CN, #12h ; load high byte of address into EMI0CN MOV R0, #34h ; load low byte of address into R0 (or R1) MOVX a, @R0 ; load contents of 0x1234 into accumulator A Rev. 1.4 145

C8051F020/1/2/3 16.2. Configuring the External Memory Interface Configuring the External Memory Interface consists of four steps: 1. Select EMIF on Low Ports (P3, P2, P1, and P0) or High Ports (P7, P6, P5, and P4). 2. Select Multiplexed mode or Non-multiplexed mode. 3. Select the memory mode (on-chip only, split mode without bank select, split mode with bank select, or off-chip only). 4. Set up timing to interface with off-chip memory or peripherals. 5. Select the desired output mode for the associated Ports (registers PnMDOUT, P74OUT). Each of these four steps is explained in detail in the following sections. The Port selection, Multiplexed mode selec- tion, and Mode bits are located in the EMI0CF register shown in Figure 16.2. 16.3. Port Selection and Configuration The External Memory Interface can appear on Ports 3, 2, 1, and 0 (C8051F020/1/2/3 devices) or on Ports 7, 6, 5, and 4 (C8051F020/2 devices only), depending on the state of the PRTSEL bit (EMI0CF.5). If the lower Ports are selected, the EMIFLE bit (XBR2.1) must be set to a ‘1’ so that the Crossbar will skip over P0.7 (/WR), P0.6 (/RD), and if mul- tiplexed mode is selected P0.5 (ALE). For more information about the configuring the Crossbar, see Section “17. PORT INPUT/OUTPUT” on page 161. The External Memory Interface claims the associated Port pins for memory operations ONLY during the execution of an off-chip MOVX instruction. Once the MOVX instruction has completed, control of the Port pins reverts to the Port latches or to the Crossbar (on Ports 3, 2, 1, and 0). See Section “17. PORT INPUT/OUTPUT” on page 161 for more information about the Crossbar and Port operation and configuration. The Port latches should be explicitly configured to ‘park’ the External Memory Interface pins in a dormant state, most commonly by setting them to a logic 1. During the execution of the MOVX instruction, the External Memory Interface will explicitly disable the drivers on all Port pins that are acting as Inputs (Data[7:0] during a READ operation, for example). The Output mode of the Port pins (whether the pin is configured as Open-Drain or Push-Pull) is unaffected by the External Memory Interface oper- ation, and remains controlled by the PnMDOUT registers. See Section “17. PORT INPUT/OUTPUT” on page 161 for more information about Port output mode configuration. 146 Rev. 1.4

C8051F020/1/2/3 Figure 16.1. EMI0CN: External Memory Interface Control R/W R/W R/W R/W R/W R/W R/W R/W Reset Value PGSEL7 PGSEL6 PGSEL5 PGSEL4 PGSEL3 PGSEL2 PGSEL1 PGSEL0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAF Bits7-0: PGSEL[7:0]: XRAM Page Select Bits. The XRAM Page Select Bits provide the high byte of the 16-bit external data memory address when using an 8-bit MOVX command, effectively selecting a 256-byte page of RAM. 0x00: 0x0000 to 0x00FF 0x01: 0x0100 to 0x01FF ... 0xFE: 0xFE00 to 0xFEFF 0xFF: 0xFF00 to 0xFFFF Figure 16.2. EMI0CF: External Memory Configuration R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - - PRTSEL EMD2 EMD1 EMD0 EALE1 EALE0 00000011 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA3 Bits7-6: Unused. Read = 00b. Write = don’t care. Bit5: PRTSEL: EMIF Port Select. 0: EMIF active on P0-P3. 1: EMIF active on P4-P7. Bit4: EMD2: EMIF Multiplex Mode Select. 0: EMIF operates in multiplexed address/data mode. 1: EMIF operates in non-multiplexed mode (separate address and data pins). Bits3-2: EMD1-0: EMIF Operating Mode Select. These bits control the operating mode of the External Memory Interface. 00: Internal Only: MOVX accesses on-chip XRAM only. All effective addresses alias to on-chip memory space. 01: Split Mode without Bank Select: Accesses below the 4k boundary are directed on-chip. Accesses above the 4k boundary are directed off-chip. 8-bit off-chip MOVX operations use the current contents of the Address High port latches to resolve upper address byte. Note that in order to access off-chip space, EMI0CN must be set to a page that is not contained in the on-chip address space. 10: Split Mode with Bank Select: Accesses below the 4k boundary are directed on-chip. Accesses above the 4k boundary are directed off-chip. 8-bit off-chip MOVX operations use the contents of EMI0CN to determine the high-byte of the address. 11: External Only: MOVX accesses off-chip XRAM only. On-chip XRAM is not visible to the CPU. Bits1-0: EALE1-0: ALE Pulse-Width Select Bits (only has effect when EMD2 = 0). 00: ALE high and ALE low pulse width = 1 SYSCLK cycle. 01: ALE high and ALE low pulse width = 2 SYSCLK cycles. 10: ALE high and ALE low pulse width = 3 SYSCLK cycles. 11: ALE high and ALE low pulse width = 4 SYSCLK cycles. Rev. 1.4 147

C8051F020/1/2/3 16.4. Multiplexed and Non-multiplexed Selection The External Memory Interface is capable of acting in a Multiplexed mode or a Non-multiplexed mode, depending on the state of the EMD2 (EMI0CF.4) bit. 16.4.1. Multiplexed Configuration In Multiplexed mode, the Data Bus and the lower 8-bits of the Address Bus share the same Port pins: AD[7:0]. In this mode, an external latch (74HC373 or equivalent logic gate) is used to hold the lower 8-bits of the RAM address. The external latch is controlled by the ALE (Address Latch Enable) signal, which is driven by the External Memory Inter- face logic. An example of a Multiplexed Configuration is shown in Figure 16.3. In Multiplexed mode, the external MOVX operation can be broken into two phases delineated by the state of the ALE signal. During the first phase, ALE is high and the lower 8-bits of the Address Bus are presented to AD[7:0]. During this phase, the address latch is configured such that the ‘Q’ outputs reflect the states of the ‘D’ inputs. When ALE falls, signaling the beginning of the second phase, the address latch outputs remain fixed and are no longer dependent on the latch inputs. Later in the second phase, the Data Bus controls the state of the AD[7:0] port at the time /RD or /WR is asserted. See Section “16.6.2. Multiplexed Mode” on page 156 for more information. Figure 16.3. Multiplexed Configuration Example A[15:8] ADDRESS BUS A[15:8] 74HC373 E ALE G AD[7:0] ADDRESS/DATA BUS D Q A[7:0] M V 64K X 8 DD I SRAM 8 F I/O[7:0] CE /WR WE /RD OE 148 Rev. 1.4

C8051F020/1/2/3 16.4.2. Non-multiplexed Configuration In Non-multiplexed mode, the Data Bus and the Address Bus pins are not shared. An example of a Non-multiplexed Configuration is shown in Figure 16.4. See Section “16.6.1. Non-multiplexed Mode” on page 153 for more infor- mation about Non-multiplexed operation. Figure 16.4. Non-multiplexed Configuration Example A[15:0] ADDRESS BUS A[15:0] E V DD M 64K X 8 8 I SRAM D[7:0] DATA BUS I/O[7:0] F CE /WR WE /RD OE Rev. 1.4 149

C8051F020/1/2/3 16.5. Memory Mode Selection The external data memory space can be configured in one of four modes, shown in Figure 16.5, based on the EMIF Mode bits in the EMI0CF register (Figure 16.2). These modes are summarized below. More information about the different modes can be found in Section “ .” on page 152. 16.5.1. Internal XRAM Only When EMI0CF.[3:2] are set to ‘00’, all MOVX instructions will target the internal XRAM space on the device. Mem- ory accesses to addresses beyond the populated space will wrap on 4k boundaries. As an example, the addresses 0x1000 and 0x2000 both evaluate to address 0x0000 in on-chip XRAM space. • 8-bit MOVX operations use the contents of EMI0CN to determine the high-byte of the effective address and R0 or R1 to determine the low-byte of the effective address. • 16-bit MOVX operations use the contents of the 16-bit DPTR to determine the effective address. 16.5.2. Split Mode without Bank Select When EMI0CF.[3:2] are set to ‘01’, the XRAM memory map is split into two areas, on-chip space and off-chip space. • Effective addresses below the 4k boundary will access on-chip XRAM space. • Effective addresses beyond the 4k boundary will access off-chip space. • 8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is on-chip or off- chip. The lower 8-bits of the Address Bus A[7:0] are driven as defined by R0 or R1. However, in the “No Bank Select” mode, an 8-bit MOVX operation will not drive the upper 8-bits A[15:8] of the Address Bus during an off-chip access. This allows the user to manipulate the upper address bits at will by setting the Port state directly. This behavior is in contrast with “Split Mode with Bank Select” described below. • 16-bit MOVX operations use the contents of DPTR to determine whether the memory access is on-chip or off- chip, and unlike 8-bit MOVX operations, the full 16-bits of the Address Bus A[15:0] are driven during the off- chip transaction. Figure 16.5. EMIF Operating Modes EMI0CF[3:2] = 00 EMI0CF[3:2] = 01 EMI0CF[3:2] = 10 EMI0CF[3:2] = 11 0xFFFF 0xFFFF 0xFFFF 0xFFFF On-Chip XRAM On-Chip XRAM Off-Chip Off-Chip Memory Memory (No Bank Select) (Bank Select) On-Chip XRAM Off-Chip Memory On-Chip XRAM On-Chip XRAM On-Chip XRAM On-Chip XRAM On-Chip XRAM 0x0000 0x0000 0x0000 0x0000 150 Rev. 1.4

C8051F020/1/2/3 16.5.3. Split Mode with Bank Select When EMI0CF.[3:2] are set to ‘10’, the XRAM memory map is split into two areas, on-chip space and off-chip space. • Effective addresses below the 4k boundary will access on-chip XRAM space. • Effective addresses beyond the 4k boundary will access off-chip space. • 8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is on-chip or off- chip. The upper 8-bits of the Address Bus A[15:8] are determined by EMI0CN, and the lower 8-bits of the Address Bus A[7:0] are determined by R0 or R1. All 16-bits of the Address Bus A[15:0] are driven in “Bank Select” mode. • 16-bit MOVX operations use the contents of DPTR to determine whether the memory access is on-chip or off- chip, and the full 16-bits of the Address Bus A[15:0] are driven during the off-chip transaction. 16.5.4. External Only When EMI0CF[3:2] are set to ‘11’, all MOVX operations are directed to off-chip space. On-chip XRAM is not visi- ble to the CPU. This mode is useful for accessing off-chip memory located between 0x0000 and the 4k boundary. • 8-bit MOVX operations ignore the contents of EMI0CN. The upper Address bits A[15:8] are not driven (identi- cal behavior to an off-chip access in “Split Mode without Bank Select” described above). This allows the user to manipulate the upper address bits at will by setting the Port state directly. The lower 8-bits of the effective address A[7:0] are determined by the contents of R0 or R1. • 16-bit MOVX operations use the contents of DPTR to determine the effective address A[15:0]. The full 16-bits of the Address Bus A[15:0] are driven during the off-chip transaction. 16.6. Timing The timing parameters of the External Memory Interface can be configured to enable connection to devices having different setup and hold time requirements. The Address Setup time, Address Hold time, /RD and /WR strobe widths, and in multiplexed mode, the width of the ALE pulse are all programmable in units of SYSCLK periods through EMI0TC, shown in Figure 16.6, and EMI0CF[1:0]. The timing for an off-chip MOVX instruction can be calculated by adding 4 SYSCLK cycles to the timing parameters defined by the EMI0TC register. Assuming non-multiplexed operation, the minimum execution time for an off-chip XRAM operation is 5 SYSCLK cycles (1 SYSCLK for /RD or /WR pulse + 4 SYSCLKs). For multiplexed opera- tions, the Address Latch Enable signal will require a minimum of 2 additional SYSCLK cycles. Therefore, the mini- mum execution time of an off-chip XRAM operation in multiplexed mode is 7 SYSCLK cycles (2 SYSCLKs for /ALE, 1 for /RD or /WR + 4 SYSCLKs). The programmable setup and hold times default to the maximum delay set- tings after a reset. Table 16.1 lists the AC parameters for the External Memory Interface, and Figure 16.7 through Figure 16.11 show the timing diagrams for the different External Memory Interface modes and MOVX operations Rev. 1.4 151

C8051F020/1/2/3 . Figure 16.6. EMI0TC: External Memory Timing Control R/W R/W R/W R/W R/W R/W R/W R/W Reset Value EAS1 EAS0 EWR3 EWR2 EWR1 EWR0 EAH1 EAH0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA1 Bits7-6: EAS1-0: EMIF Address Setup Time Bits. 00: Address setup time = 0 SYSCLK cycles. 01: Address setup time = 1 SYSCLK cycle. 10: Address setup time = 2 SYSCLK cycles. 11: Address setup time = 3 SYSCLK cycles. Bits5-2: EWR3-0: EMIF /WR and /RD Pulse-Width Control Bits. 0000: /WR and /RD pulse width = 1 SYSCLK cycle. 0001: /WR and /RD pulse width = 2 SYSCLK cycles. 0010: /WR and /RD pulse width = 3 SYSCLK cycles. 0011: /WR and /RD pulse width = 4 SYSCLK cycles. 0100: /WR and /RD pulse width = 5 SYSCLK cycles. 0101: /WR and /RD pulse width = 6 SYSCLK cycles. 0110: /WR and /RD pulse width = 7 SYSCLK cycles. 0111: /WR and /RD pulse width = 8 SYSCLK cycles. 1000: /WR and /RD pulse width = 9 SYSCLK cycles. 1001: /WR and /RD pulse width = 10 SYSCLK cycles. 1010: /WR and /RD pulse width = 11 SYSCLK cycles. 1011: /WR and /RD pulse width = 12 SYSCLK cycles. 1100: /WR and /RD pulse width = 13 SYSCLK cycles. 1101: /WR and /RD pulse width = 14 SYSCLK cycles. 1110: /WR and /RD pulse width = 15 SYSCLK cycles. 1111: /WR and /RD pulse width = 16 SYSCLK cycles. Bits1-0: EAH1-0: EMIF Address Hold Time Bits. 00: Address hold time = 0 SYSCLK cycles. 01: Address hold time = 1 SYSCLK cycle. 10: Address hold time = 2 SYSCLK cycles. 11: Address hold time = 3 SYSCLK cycles. 152 Rev. 1.4

C8051F020/1/2/3 16.6.1. Non-multiplexed Mode 16.6.1.1.16-bit MOVX: EMI0CF[4:2] = ‘101’, ‘110’, or ‘111’. Figure 16.7. Non-multiplexed 16-bit MOVX Timing Nonmuxed 16-bit WRITE ADDR[15:8] P1/P5 EMIF ADDRESS (8 MSBs) from DPH P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from DPL P2/P6 DATA[7:0] P3/P7 EMIF WRITE DATA P3/P7 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Nonmuxed 16-bit READ ADDR[15:8] P1/P5 EMIF ADDRESS (8 MSBs) from DPH P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from DPL P2/P6 DATA[7:0] P3/P7 EMIF READ DATA P3/P7 T T RDS RDH T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 Rev. 1.4 153

C8051F020/1/2/3 16.6.1.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = ‘101’ or ‘111’. Figure 16.8. Non-multiplexed 8-bit MOVX without Bank Select Timing Nonmuxed 8-bit WRITE without Bank Select ADDR[15:8] P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from R0 or R1 P2/P6 DATA[7:0] P3/P7 EMIF WRITE DATA P3/P7 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Nonmuxed 8-bit READ without Bank Select ADDR[15:8] P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from R0 or R1 P2/P6 DATA[7:0] P3/P7 EMIF READ DATA P3/P7 T T RDS RDH T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 154 Rev. 1.4

C8051F020/1/2/3 16.6.1.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = ‘110’. Figure 16.9. Non-multiplexed 8-bit MOVX with Bank Select Timing Nonmuxed 8-bit WRITE with Bank Select ADDR[15:8] P1/P5 EMIF ADDRESS (8 MSBs) from EMI0CN P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from R0 or R1 P2/P6 DATA[7:0] P3/P7 EMIF WRITE DATA P3/P7 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Nonmuxed 8-bit READ with Bank Select ADDR[15:8] P1/P5 EMIF ADDRESS (8 MSBs) from EMI0CN P1/P5 ADDR[7:0] P2/P6 EMIF ADDRESS (8 LSBs) from R0 or R1 P2/P6 DATA[7:0] P3/P7 EMIF READ DATA P3/P7 T T RDS RDH T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 Rev. 1.4 155

C8051F020/1/2/3 16.6.2. Multiplexed Mode 16.6.2.1.16-bit MOVX: EMI0CF[4:2] = ‘001’, ‘010’, or ‘011’. Figure 16.10. Multiplexed 16-bit MOVX Timing Muxed 16-bit WRITE ADDR[15:8] P2/P6 EMIF ADDRESS (8 MSBs) from DPH P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF WRITE DATA P3/P7 DPL T T ALEH ALEL ALE P0.5/P4.5 P0.5/P4.5 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Muxed 16-bit READ ADDR[15:8] P2/P6 EMIF ADDRESS (8 MSBs) from DPH P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF READ DATA P3/P7 DPL T T ALEH ALEL T T RDS RDH ALE P0.5/P4.5 P0.5/P4.5 T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 156 Rev. 1.4

C8051F020/1/2/3 16.6.2.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = ‘001’ or ‘011’. Figure 16.11. Multiplexed 8-bit MOVX without Bank Select Timing Muxed 8-bit WRITE Without Bank Select ADDR[15:8] P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF WRITE DATA P3/P7 R0 or R1 T T ALEH ALEL ALE P0.5/P4.5 P0.5/P4.5 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Muxed 8-bit READ Without Bank Select ADDR[15:8] P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF READ DATA P3/P7 R0 or R1 T T ALEH ALEL T T RDS RDH ALE P0.5/P4.5 P0.5/P4.5 T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 Rev. 1.4 157

C8051F020/1/2/3 16.6.2.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = ‘010’. Figure 16.12. Multiplexed 8-bit MOVX with Bank Select Timing Muxed 8-bit WRITE with Bank Select ADDR[15:8] P2/P6 EMIF ADDRESS (8 MSBs) from EMI0CN P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF WRITE DATA P3/P7 R0 or R1 T T ALEH ALEL ALE P0.5/P4.5 P0.5/P4.5 T T WDS WDH T T T ACS ACW ACH /WR P0.7/P4.7 P0.7/P4.7 /RD P0.6/P4.6 P0.6/P4.6 Muxed 8-bit READ with Bank Select ADDR[15:8] P2/P6 EMIF ADDRESS (8 MSBs) from EMI0CN P2/P6 EMIF ADDRESS (8 LSBs) from AD[7:0] P3/P7 EMIF READ DATA P3/P7 R0 or R1 T T ALEH ALEL T T RDS RDH ALE P0.5/P4.5 P0.5/P4.5 T T T ACS ACW ACH /RD P0.6/P4.6 P0.6/P4.6 /WR P0.7/P4.7 P0.7/P4.7 158 Rev. 1.4

C8051F020/1/2/3 Table 16.1. AC Parameters for External Memory Interface PARAMETER DESCRIPTION MIN MAX UNITS T System Clock Period 40 ns SYSCLK T Address / Control Setup Time 0 3*T ns ACS SYSCLK T Address / Control Pulse Width 1*T 16*T ns ACW SYSCLK SYSCLK T Address / Control Hold Time 0 3*T ns ACH SYSCLK T Address Latch Enable High Time 1*T 4*T ns ALEH SYSCLK SYSCLK T Address Latch Enable Low Time 1*T 4*T ns ALEL SYSCLK SYSCLK T Write Data Setup Time 1*T 19*T ns WDS SYSCLK SYSCLK T Write Data Hold Time 0 3*T ns WDH SYSCLK T Read Data Setup Time 20 ns RDS T Read Data Hold Time 0 ns RDH Rev. 1.4 159

C8051F020/1/2/3 Notes 160 Rev. 1.4

C8051F020/1/2/3 17. PORT INPUT/OUTPUT The C8051F020/1/2/3 are fully integrated mixed-signal System on a Chip MCUs with 64 digital I/O pins (C8051F020/2) or 32 digital I/O pins (C8051F021/3), organized as 8-bit Ports. The lower ports: P0, P1, P2, and P3, are both bit- and byte-addressable through their corresponding Port Data registers. The upper ports: P4, P5, P6, and P7 are byte-addressable. All Port pins are 5 V-tolerant, and all support configurable Open-Drain or Push-Pull output modes and weak pull-ups. A block diagram of the Port I/O cell is shown in Figure 17.1. Complete Electrical Specifi- cations for the Port I/O pins are given in Table 16.1. Figure 17.1. Port I/O Cell Block Diagram /WEAK-PULLUP PUSH-PULL VDD VDD /PORT-OUTENABLE (WEAK) PORT PAD PORT-OUTPUT DGND Analog Select (Port 1 Only) ANALOG INPUT PORT-INPUT Table 17.1. Port I/O DC Electrical Characteristics VDD = 2.7 V to 3.6 V, -40°C to +85°C unless otherwise specified. PARAMETER CONDITIONS MIN TYP MAX UNITS Output High Voltage (V ) I = -10 µA, Port I/O Push-Pull VDD - 0.1 OH OH I = -3 mA, Port I/O Push-Pull VDD - 0.7 V OH I = -10 mA, Port I/O Push-Pull VDD - 0.8 OH Output Low Voltage (V ) I = 10 µA 0.1 OL OL I = 8.5 mA 0.6 V OL I = 25 mA 1.0 OL Input High Voltage (VIH) 0.7 x VDD V Input Low Voltage (VIL) 0.3 x V VDD Input Leakage Current DGND < Port Pin < VDD, Pin Tri-state µA Weak Pull-up Off ± 1 Weak Pull-up On 10 Input Capacitance 5 pF Rev. 1.4 161

C8051F020/1/2/3 The C8051F020/1/2/3 devices have a wide array of digital resources which are available through the four lower I/O Ports: P0, P1, P2, and P3. Each of the pins on P0, P1, P2, and P3, can be defined as a General-Purpose I/O (GPIO) pin or can be controlled by a digital peripheral or function (like UART0 or /INT1 for example), as shown in Figure 17.2. The system designer controls which digital functions are assigned pins, limited only by the number of pins available. This resource assignment flexibility is achieved through the use of a Priority Crossbar Decoder. Note that the state of a Port I/O pin can always be read from its associated Data register regardless of whether that pin has been assigned to a digital peripheral or behaves as GPIO. The Port pins on Port 1 can be used as Analog Inputs to ADC1. An External Memory Interface which is active during the execution of a MOVX instruction whose target address resides in off-chip memory can be active on either the lower Ports or the upper Ports. See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. The upper Ports (available on C8051F020/2) can be byte-accessed as GPIO pins. Figure 17.2. Lower Port I/O Functional Block Diagram Highest UART0 2 XBR0, XBR1, P0MDOUT, P1MDOUT, Priority XBR2, P1MDIN P2MDOUT, P3MDOUT 4 Registers Registers SPI 2 External SMBus Priority Pins Decoder 2 Signals) UPACRAT1 6 8 CIP/eO0lls PP00..07 HPirgiohreitsyt al git Comptr. 2 Di Outputs Digital nal Crossbar 8 P1 P1.0 er I/O (Int T0, T1, Cells P1.7 T2, T2EX, 8 T4,T4EX /INT0, /INT1 P2 P2.0 8 I/O Cells P2.7 Lowest /SYSCLK Priority CNVSTR P3 P3.0 8 8 I/O Lowest P0 Cells P3.7 Priority (P0.0-P0.7) 8 P1 (P1.0-P1.7) To External To Port Memory Latches 8 Interface ADC1 Input (EMIF) P2 (P2.0-P2.7) 8 P3 (P3.0-P3.7) 162 Rev. 1.4

C8051F020/1/2/3 17.1. Ports 0 through 3 and the Priority Crossbar Decoder The Priority Crossbar Decoder, or “Crossbar”, allocates and assigns Port pins on Port 0 through Port 3 to the digital peripherals (UARTs, SMBus, PCA, Timers, etc.) on the device using a priority order. The Port pins are allocated in order starting with P0.0 and continue through P3.7 if necessary. The digital peripherals are assigned Port pins in a pri- ority order which is listed in Figure 17.3, with UART0 having the highest priority and CNVSTR having the lowest priority. 17.1.1. Crossbar Pin Assignment and Allocation The Crossbar assigns Port pins to a peripheral if the corresponding enable bits of the peripheral are set to a logic 1 in the Crossbar configuration registers XBR0, XBR1, and XBR2, shown in Figure 17.7, Figure 17.8, and Figure 17.9. For example, if the UART0EN bit (XBR0.2) is set to a logic 1, the TX0 and RX0 pins will be mapped to P0.0 and P0.1 respectively. Because UART0 has the highest priority, its pins will always be mapped to P0.0 and P0.1 when UART0EN is set to a logic 1. If a digital peripheral’s enable bits are not set to a logic 1, then its ports are not accessi- ble at the Port pins of the device. Also note that the Crossbar assigns pins to all associated functions when a serial communication peripheral is selected (i.e. SMBus, SPI, UART). It would be impossible, for example, to assign TX0 Figure 17.3. Priority Crossbar Decode Table (EMIFLE = 0; P1MDIN = 0xFF) P0 P1 P2 P3 Crossbar Register Bits PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 TX0  UART0EN:XBR0.2 RX0  SCK   MISO   SPI0EN:XBR0.1 MOSI   NSS   SDA     SMB0EN:XBR0.0 SCL     TX1      UART1EN:XBR2.2 RX1       CEX0        CEX1         CEX2         PCA0ME:XBR0.[5:3] CEX3          CEX4          ECI                 ECI0E:XBR0.6 CP0                  CP0E:XBR0.7 CP1                   CP1E:XBR1.0 T0                    T0E:XBR1.1 /INT0                     INT0E:XBR1.2 T1                      T1E:XBR1.3 /INT1                       INT1E:XBR1.4 T2                        T2E:XBR1.5 T2EX                         T2EXE:XBR1.6 T4                          T4E:XBR2.3 T4EX                           T4EXE:XBR2.4 /SYSCLK                            SYSCKE:XBR1.7 CNVSTR                             CNVSTE:XBR2.0 ALE /RD /WR AIN1.0/A8 AIN1.1/A9 AIN1.2/A1 AIN1.3/A1 AIN1.4/A1 AIN1.5/A1 AIN1.6/A1 AIN1.7/A1 A8m/A0 A9m/A1 A10m/A2 A11m/A3 A12m/A4 A13m/A5 A14m/A6 A15m/A7 AD0/D0 AD1/D1 AD2/D2 AD3/D3 AD4/D4 AD5/D5 AD6/D6 AD7/D7 AIN1 Inputs/Non-muxed Addr H Muxed Addr H/Non-muxed Addr L Muxed Data/Non-muxed Data Rev. 1.4 163

C8051F020/1/2/3 to a Port pin without assigning RX0 as well. Each combination of enabled peripherals results in a unique device pin- out. All Port pins on Ports 0 through 3 that are not allocated by the Crossbar can be accessed as General-Purpose I/O (GPIO) pins by reading and writing the associated Port Data registers (See Figure 17.10, Figure 17.12, Figure 17.15, and Figure 17.17), a set of SFRs which are both byte- and bit-addressable. The output states of Port pins that are allo- cated by the Crossbar are controlled by the digital peripheral that is mapped to those pins. Writes to the Port Data reg- isters (or associated Port bits) will have no effect on the states of these pins. A Read of a Port Data register (or Port bit) will always return the logic state present at the pin itself, regardless of whether the Crossbar has allocated the pin for peripheral use or not. An exception to this occurs during the execution of a read-modify-write instruction (ANL, ORL, XRL, CPL, INC, DEC, DJNZ, JBC, CLR, SET, and the bitwise MOV operation). During the read cycle of the read-modify-write instruction, it is the contents of the Port Data register, not the state of the Port pins themselves, which is read. Because the Crossbar registers affect the pinout of the peripherals of the device, they are typically configured in the initialization code of the system before the peripherals themselves are configured. Once configured, the Crossbar reg- isters are typically left alone. Once the Crossbar registers have been properly configured, the Crossbar is enabled by setting XBARE (XBR2.6) to a logic 1. Until XBARE is set to a logic 1, the output drivers on Ports 0 through 3 are explicitly disabled in order to prevent possible contention on the Port pins while the Crossbar registers and other registers which can affect the device pinout are being written. The output drivers on Crossbar-assigned input signals (like RX0, for example) are explicitly disabled; thus the values of the Port Data registers and the PnMDOUT registers have no effect on the states of these pins. 17.1.2. Configuring the Output Modes of the Port Pins The output drivers on Ports 0 through 3 remain disabled until the Crossbar is enabled by setting XBARE (XBR2.6) to a logic 1. The output mode of each port pin can be configured as either Open-Drain or Push-Pull; the default state is Open- Drain. In the Push-Pull configuration, writing a logic 0 to the associated bit in the Port Data register will cause the Port pin to be driven to GND, and writing a logic 1 will cause the Port pin to be driven to VDD. In the Open-Drain configuration, writing a logic 0 to the associated bit in the Port Data register will cause the Port pin to be driven to GND, and a logic 1 will cause the Port pin to assume a high-impedance state. The Open-Drain configuration is useful to prevent contention between devices in systems where the Port pin participates in a shared interconnection in which multiple outputs are connected to the same physical wire (like the SDA signal on an SMBus connection). The output modes of the Port pins on Ports 0 through 3 are determined by the bits in the associated PnMDOUT regis- ters (See Figure 17.11, Figure 17.14, Figure 17.16, and Figure 17.18). For example, a logic 1 in P3MDOUT.7 will configure the output mode of P3.7 to Push-Pull; a logic 0 in P3MDOUT.7 will configure the output mode of P3.7 to Open-Drain. All Port pins default to Open-Drain output. The PnMDOUT registers control the output modes of the port pins regardless of whether the Crossbar has allocated the Port pin for a digital peripheral or not. The exceptions to this rule are: the Port pins connected to SDA, SCL, RX0 (if UART0 is in Mode 0), and RX1 (if UART1 is in Mode 0) are always configured as Open-Drain outputs, regardless of the settings of the associated bits in the PnMDOUT registers. 164 Rev. 1.4

C8051F020/1/2/3 17.1.3. Configuring Port Pins as Digital Inputs A Port pin is configured as a digital input by setting its output mode to “Open-Drain” and writing a logic 1 to the associated bit in the Port Data register. For example, P3.7 is configured as a digital input by setting P3MDOUT.7 to a logic 0 and P3.7 to a logic 1. If the Port pin has been assigned to a digital peripheral by the Crossbar and that pin functions as an input (for example RX0, the UART0 receive pin), then the output drivers on that pin are automatically disabled. 17.1.4. External Interrupts (IE6 and IE7) In addition to the external interrupts /INT0 and /INT1, whose Port pins are allocated and assigned by the Crossbar, P3.6 and P3.7 can be configured to generate edge sensitive interrupts; these interrupts are configurable as falling- or rising-edge sensitive using the IE6CF (P3IF.2) and IE7CF (P3IF.3) bits. When an active edge is detected on P3.6 or P3.7, a corresponding External Interrupt flag (IE6 or IE7) will be set to a logic 1 in the P3IF register (See Figure 17.19). If the associated interrupt is enabled, an interrupt will be generated and the CPU will vector to the associated interrupt vector location. See Section “12.3. Interrupt Handler” on page 116 for more information about interrupts. 17.1.5. Weak Pull-ups By default, each Port pin has an internal weak pull-up device enabled which provides a resistive connection (about 100 kΩ) between the pin and VDD. The weak pull-up devices can be globally disabled by writing a logic 1 to the Weak Pull-up Disable bit, (WEAKPUD, XBR2.7). The weak pull-up is automatically deactivated on any pin that is driving a logic 0; that is, an output pin will not contend with its own pull-up device. The weak pull-up device can also be explicitly disabled on a Port 1 pin by configuring the pin as an Analog Input, as described below. 17.1.6. Configuring Port 1 Pins as Analog Inputs (AIN1.[7:0]) The pins on Port 1 can serve as analog inputs to the ADC1 analog MUX. A Port pin is configured as an Analog Input by writing a logic 0 to the associated bit in the P1MDIN register (see Figure 17.13). All Port pins default to a Digital Input mode. Configuring a Port pin as an analog input: 1. Disables the digital input path from the pin. This prevents additional power supply current from being drawn when the voltage at the pin is near VDD / 2. A read of the Port Data bit will return a logic 0 regardless of the voltage at the Port pin. 2. Disables the weak pull-up device on the pin. 3. Causes the Crossbar to “skip over” the pin when allocating Port pins for digital peripherals. Note that the output drivers on a pin configured as an Analog Input are not explicitly disabled. Therefore, the associated P1MDOUT bits of pins configured as Analog Inputs should explicitly be set to logic 0 (Open-Drain output mode), and the associated Port Data bits should be set to logic 1 (high-impedance). Also note that it is not required to configure a Port pin as an Analog Input in order to use it as an input to the ADC1 MUX; however, it is strongly rec- ommended. See Section “7. ADC1 (8-Bit ADC)” on page 75 for more information about ADC1. Rev. 1.4 165

C8051F020/1/2/3 17.1.7. External Memory Interface Pin Assignments If the External Memory Interface (EMIF) is enabled on the Low ports (Ports 0 through 3), EMIFLE (XBR2.1) should be set to a logic 1 so that the Crossbar will not assign peripherals to P0.7 (/WR), P0.6 (/RD), and if the External Mem- ory Interface is in Multiplexed mode, P0.5 (ALE). Figure 17.4 shows an example Crossbar Decode Table with EMIFLE=1 and the EMIF in Multiplexed mode. Figure 17.5 shows an example Crossbar Decode Table with EMIFLE=1 and the EMIF in Non-multiplexed mode. If the External Memory Interface is enabled on the Low ports and an off-chip MOVX operation occurs, the External Memory Interface will control the output states of the affected Port pins during the execution phase of the MOVX instruction, regardless of the settings of the Crossbar registers or the Port Data registers. The output configuration of the Port pins is not affected by the EMIF operation, except that Read operations will explicitly disable the output drivers on the Data Bus. See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Figure 17.4. Priority Crossbar Decode Table EMIFLE = 1; EMIF in Multiplexed Mode; P1MDIN = 0xFF) P0 P1 P2 P3 Crossbar Register Bits PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 TX0  UART0EN:XBR0.2 RX0  SCK   MISO   SPI0EN:XBR0.1 MOSI   NSS   SDA     SMB0EN:XBR0.0 SCL     TX1      UART1EN:XBR2.2 RX1       CEX0        CEX1         CEX2         PCA0ME:XBR0.[5:3] CEX3          CEX4          ECI                 ECI0E:XBR0.6 CP0                  CP0E:XBR0.7 CP1                   CP1E:XBR1.0 T0                    T0E:XBR1.1 /INT0                     INT0E:XBR1.2 T1                      T1E:XBR1.3 /INT1                       INT1E:XBR1.4 T2                        T2E:XBR1.5 T2EX                         T2EXE:XBR1.6 T4                          T4E:XBR2.3 T4EX                           T4EXE:XBR2.4 /SYSCLK                            SYSCKE:XBR1.7 CNVSTR                             CNVSTE:XBR2.0 ALE /RD /WR AIN1.0/A8 AIN1.1/A9 AIN1.2/A1 AIN1.3/A1 AIN1.4/A1 AIN1.5/A1 AIN1.6/A1 AIN1.7/A1 A8m/A0 A9m/A1 A10m/A2 A11m/A3 A12m/A4 A13m/A5 A14m/A6 A15m/A7 AD0/D0 AD1/D1 AD2/D2 AD3/D3 AD4/D4 AD5/D5 AD6/D6 AD7/D7 AIN1 Inputs/Non-muxed Addr H Muxed Addr H/Non-muxed Addr L Muxed Data/Non-muxed Data 166 Rev. 1.4

C8051F020/1/2/3 Figure 17.5. Priority Crossbar Decode Table (EMIFLE = 1; EMIF in Non-multiplexed Mode; P1MDIN = 0xFF) P0 P1 P2 P3 Crossbar Register Bits PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 TX0  UART0EN:XBR0.2 RX0  SCK   MISO   SPI0EN:XBR0.1 MOSI   NSS   SDA     SMB0EN:XBR0.0 SCL     TX1      UART1EN:XBR2.2 RX1       CEX0        CEX1         CEX2         PCA0ME:XBR0.[5:3] CEX3          CEX4          ECI                 ECI0E:XBR0.6 CP0                  CP0E:XBR0.7 CP1                   CP1E:XBR1.0 T0                    T0E:XBR1.1 /INT0                     INT0E:XBR1.2 T1                      T1E:XBR1.3 /INT1                       INT1E:XBR1.4 T2                        T2E:XBR1.5 T2EX                         T2EXE:XBR1.6 T4                          T4E:XBR2.3 T4EX                           T4EXE:XBR2.4 /SYSCLK                            SYSCKE:XBR1.7 CNVSTR                             CNVSTE:XBR2.0 ALE /RD /WR AIN1.0/A8 AIN1.1/A9 AIN1.2/A1 AIN1.3/A1 AIN1.4/A1 AIN1.5/A1 AIN1.6/A1 AIN1.7/A1 A8m/A0 A9m/A1 A10m/A2 A11m/A3 A12m/A4 A13m/A5 A14m/A6 A15m/A7 AD0/D0 AD1/D1 AD2/D2 AD3/D3 AD4/D4 AD5/D5 AD6/D6 AD7/D7 AIN1 Inputs/Non-muxed Addr H Muxed Addr H/Non-muxed Addr L Muxed Data/Non-muxed Data Rev. 1.4 167

C8051F020/1/2/3 17.1.8. Crossbar Pin Assignment Example In this example (Figure 17.6), we configure the Crossbar to allocate Port pins for UART0, the SMBus, UART1, /INT0, and /INT1 (8 pins total). Additionally, we configure the External Memory Interface to operate in Multiplexed mode and to appear on the Low ports. Further, we configure P1.2, P1.3, and P1.4 for Analog Input mode so that the voltages at these pins can be measured by ADC1. The configuration steps are as follows: 1. XBR0, XBR1, and XBR2 are set such that UART0EN = 1, SMB0EN = 1, INT0E = 1, INT1E = 1, and EMIFLE = 1. Thus: XBR0 = 0x05, XBR1 = 0x14, and XBR2 = 0x02. 2. We configure the External Memory Interface to use Multiplexed mode and to appear on the Low ports. PRTSEL = 0, EMD2 = 0. 3. We configure the desired Port 1 pins to Analog Input mode by setting P1MDIN to 0xE3 (P1.4, P1.3, and P1.2 are Analog Inputs, so their associated P1MDIN bits are set to logic 0). 4. We enable the Crossbar by setting XBARE = 1: XBR2 = 0x46. - UART0 has the highest priority, so P0.0 is assigned to TX0, and P0.1 is assigned to RX0. - The SMBus is next in priority order, so P0.2 is assigned to SDA, and P0.3 is assigned to SCL. - UART1 is next in priority order, so P0.4 is assigned to TX1. Because the External Memory Inter- face is selected on the lower Ports, EMIFLE = 1, which causes the Crossbar to skip P0.6 (/RD) and P0.7 (/WR). Because the External Memory Interface is configured in Multiplexed mode, the Cross- bar will also skip P0.5 (ALE). RX1 is assigned to the next non-skipped pin, which in this case is P1.0. - /INT0 is next in priority order, so it is assigned to P1.1. - P1MDIN is set to 0xE3, which configures P1.2, P1.3, and P1.4 as Analog Inputs, causing the Crossbar to skip these pins. - /INT1 is next in priority order, so it is assigned to the next non-skipped pin, which is P1.5. - The External Memory Interface will drive Ports 2 and 3 (denoted by red dots in Figure 17.6) during the execution of an off-chip MOVX instruction. 5. We set the UART0 TX pin (TX0, P0.0), UART1 TX pin (TX1, P0.4), ALE, /RD, /WR (P0.[7:3]) outputs to Push-Pull by setting P0MDOUT = 0xF1. 6. We configure the output modes of the EMIF Ports (P2, P3) to Push-Pull by setting P2MDOUT = 0xFF and P3MDOUT = 0xFF. 7. We explicitly disable the output drivers on the 3 Analog Input pins by setting P1MDOUT = 0x00 (configure outputs to Open-Drain) and P1 = 0xFF (a logic 1 selects the high-impedance state). 168 Rev. 1.4

C8051F020/1/2/3 Figure 17.6. Crossbar Example: (EMIFLE = 1; EMIF in Multiplexed Mode; P1MDIN = 0xE3; XBR0 = 0x05; XBR1 = 0x14; XBR2 = 0x46) P0 P1 P2 P3 Crossbar Register Bits PIN I/O 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 TX0  UART0EN:XBR0.2 RX0  SCK   MISO   SPI0EN:XBR0.1 MOSI   NSS   SDA     SMB0EN:XBR0.0 SCL     TX1      UART1EN:XBR2.2 RX1       CEX0        CEX1         CEX2         PCA0ME:XBR0.[5:3] CEX3          CEX4          ECI                 ECI0E:XBR0.6 CP0                  CP0E:XBR0.7 CP1                   CP1E:XBR1.0 T0                    T0E:XBR1.1 /INT0                     INT0E:XBR1.2 T1                      T1E:XBR1.3 /INT1                       INT1E:XBR1.4 T2                        T2E:XBR1.5 T2EX                         T2EXE:XBR1.6 T4                          T4E:XBR2.3 T4EX                           T4EXE:XBR2.4 /SYSCLK                           SYSCKE:XBR1.7 CNVSTR                           CNVSTE:XBR2.0 ALE /RD /WR AIN1.0/A8 AIN1.1/A9 AIN1.2/A1 AIN1.3/A1 AIN1.4/A1 AIN1.5/A1 AIN1.6/A1 AIN1.7/A1 A8m/A0 A9m/A1 A10m/A2 A11m/A3 A12m/A4 A13m/A5 A14m/A6 A15m/A7 AD0/D0 AD1/D1 AD2/D2 AD3/D3 AD4/D4 AD5/D5 AD6/D6 AD7/D7 AIN1 Inputs/Non-muxed Addr H Muxed Addr H/Non-muxed Addr L Muxed Data/Non-muxed Data Rev. 1.4 169

C8051F020/1/2/3 Figure 17.7. XBR0: Port I/O Crossbar Register 0 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value CP0E ECI0E PCA0ME UART0EN SPI0EN SMB0EN 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE1 Bit7: CP0E: Comparator 0 Output Enable Bit. 0: CP0 unavailable at Port pin. 1: CP0 routed to Port pin. Bit6: ECI0E: PCA0 External Counter Input Enable Bit. 0: PCA0 External Counter Input unavailable at Port pin. 1: PCA0 External Counter Input (ECI0) routed to Port pin. Bits5-3: PCA0ME: PCA0 Module I/O Enable Bits. 000: All PCA0 I/O unavailable at Port pins. 001: CEX0 routed to Port pin. 010: CEX0, CEX1 routed to 2 Port pins. 011: CEX0, CEX1, and CEX2 routed to 3 Port pins. 100: CEX0, CEX1, CEX2, and CEX3 routed to 4 Port pins. 101: CEX0, CEX1, CEX2, CEX3, and CEX4 routed to 5 Port pins. 110: RESERVED 111: RESERVED Bit2: UART0EN: UART0 I/O Enable Bit. 0: UART0 I/O unavailable at Port pins. 1: UART0 TX routed to P0.0, and RX routed to P0.1. Bit1: SPI0EN: SPI0 Bus I/O Enable Bit. 0: SPI0 I/O unavailable at Port pins. 1: SPI0 SCK, MISO, MOSI, and NSS routed to 4 Port pins. Bit0: SMB0EN: SMBus0 Bus I/O Enable Bit. 0: SMBus0 I/O unavailable at Port pins. 1: SMBus0 SDA and SCL routed to 2 Port pins. 170 Rev. 1.4

C8051F020/1/2/3 Figure 17.8. XBR1: Port I/O Crossbar Register 1 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SYSCKE T2EXE T2E INT1E T1E INT0E T0E CP1E 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE2 Bit7: SYSCKE: /SYSCLK Output Enable Bit. 0: /SYSCLK unavailable at Port pin. 1: /SYSCLK routed to Port pin. Bit6: T2EXE: T2EX Input Enable Bit. 0: T2EX unavailable at Port pin. 1: T2EX routed to Port pin. Bit5: T2E: T2 Input Enable Bit. 0: T2 unavailable at Port pin. 1: T2 routed to Port pin. Bit4: INT1E: /INT1 Input Enable Bit. 0: /INT1 unavailable at Port pin. 1: /INT1 routed to Port pin. Bit3: T1E: T1 Input Enable Bit. 0: T1 unavailable at Port pin. 1: T1 routed to Port pin. Bit2: INT0E: /INT0 Input Enable Bit. 0: /INT0 unavailable at Port pin. 1: /INT1 routed to Port pin. Bit1: T0E: T0 Input Enable Bit. 0: T0 unavailable at Port pin. 1: T0 routed to Port pin. Bit0: CP1E: CP1 Output Enable Bit. 0: CP1 unavailable at Port pin. 1: CP1 routed to Port pin. Rev. 1.4 171

C8051F020/1/2/3 Figure 17.9. XBR2: Port I/O Crossbar Register 2 R/W R/W R/W R/W R/W R/W R/W R/W Reset Value WEAKPUD XBARE - T4EXE T4E UART1E EMIFLE CNVSTE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE3 Bit7: WEAKPUD: Weak Pull-Up Disable Bit. 0: Weak pull-ups globally enabled. 1: Weak pull-ups globally disabled. Bit6: XBARE: Crossbar Enable Bit. 0: Crossbar disabled. All pins on Ports 0, 1, 2, and 3, are forced to Input mode. 1: Crossbar enabled. Bit5: UNUSED. Read = 0, Write = don't care. Bit4: T4EXE: T4EX Input Enable Bit. 0: T4EX unavailable at Port pin. 1: T4EX routed to Port pin. Bit3: T4E: T4 Input Enable Bit. 0: T4 unavailable at Port pin. 1: T4 routed to Port pin. Bit2: UART1E: UART1 I/O Enable Bit. 0: UART1 I/O unavailable at Port pins. 1: UART1 TX and RX routed to 2 Port pins. Bit1: EMIFLE: External Memory Interface Low-Port Enable Bit. 0: P0.7, P0.6, and P0.5 functions are determined by the Crossbar or the Port latches. 1: If EMI0CF.4 = ‘0’ (External Memory Interface is in Multiplexed mode) P0.7 (/WR), P0.6 (/RD), and P0.5 (ALE) are ‘skipped’ by the Crossbar and their output states are determined by the Port latches and the External Memory Interface. 1: If EMI0CF.4 = ‘1’ (External Memory Interface is in Non-multiplexed mode) P0.7 (/WR) and P0.6 (/RD) are ‘skipped’ by the Crossbar and their output states are determined by the Port latches and the External Memory Interface. Bit0: CNVSTE: External Convert Start Input Enable Bit. 0: CNVSTR unavailable at Port pin. 1: CNVSTR routed to Port pin. 172 Rev. 1.4

C8051F020/1/2/3 Figure 17.10. P0: Port0 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0x80 Bits7-0: P0.[7:0]: Port0 Output Latch Bits. (Write - Output appears on I/O pins per XBR0, XBR1, XBR2, and XBR3 Registers) 0: Logic Low Output. 1: Logic High Output (open if corresponding P0MDOUT.n bit = 0). (Read - Regardless of XBR0, XBR1, XBR2, and XBR3 Register settings). 0: P0.n pin is logic low. 1: P0.n pin is logic high. Note: P0.7 (/WR), P0.6 (/RD), and P0.5 (ALE) can be driven by the External Data Memory Interface. See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information. See also Figure 17.9 for information about configuring the Crossbar for External Memory accesses. Figure 17.11. P0MDOUT: Port0 Output Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA4 Bits7-0: P0MDOUT.[7:0]: Port0 Output Mode Bits. 0: Port Pin output mode is configured as Open-Drain. 1: Port Pin output mode is configured as Push-Pull. Note: SDA, SCL, and RX0 (when UART0 is in Mode 0) and RX1 (when UART1 is in Mode 0) are always configured as Open-Drain when they appear on Port pins. Rev. 1.4 173

C8051F020/1/2/3 Figure 17.12. P1: Port1 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0x90 Bits7-0: P1.[7:0]: Port1 Output Latch Bits. (Write - Output appears on I/O pins per XBR0, XBR1, XBR2, and XBR3 Registers) 0: Logic Low Output. 1: Logic High Output (open if corresponding P1MDOUT.n bit = 0). (Read - Regardless of XBR0, XBR1, XBR2, and XBR3 Register settings). 0: P1.n pin is logic low. 1: P1.n pin is logic high. Notes: 1. P1.[7:0] can be configured as inputs to ADC1 as AIN1.[7:0], in which case they are ‘skipped’ by the Crossbar assignment process and their digital input paths are disabled, depending on P1MDIN (See Figure 17.13). Note that in analog mode, the output mode of the pin is determined by the Port 1 latch and P1MDOUT (Figure 17.14). See Section “7. ADC1 (8-Bit ADC)” on page 75 for more informa- tion about ADC1. 2. P1.[7:0] can be driven by the External Data Memory Interface (as Address[15:8] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Figure 17.13. P1MDIN: Port1 Input Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xBD Bits7-0: P1MDIN.[7:0]: Port 1 Input Mode Bits. 0: Port Pin is configured in Analog Input mode. The digital input path is disabled (a read from the Port bit will always return ‘0’). The weak pull-up on the pin is disabled. 1: Port Pin is configured in Digital Input mode. A read from the Port bit will return the logic level at the Pin. The state of the weak pull-up is determined by the WEAKPUD bit (XBR2.7, see Figure 17.9). 174 Rev. 1.4

C8051F020/1/2/3 Figure 17.14. P1MDOUT: Port1 Output Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA5 Bits7-0: P1MDOUT.[7:0]: Port1 Output Mode Bits. 0: Port Pin output mode is configured as Open-Drain. 1: Port Pin output mode is configured as Push-Pull. Note: SDA, SCL, and RX0 (when UART0 is in Mode 0) and RX1 (when UART1 is in Mode 0) are always configured as Open-Drain when they appear on Port pins. Figure 17.15. P2: Port2 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xA0 Bits7-0: P2.[7:0]: Port2 Output Latch Bits. (Write - Output appears on I/O pins per XBR0, XBR1, XBR2, and XBR3 Registers) 0: Logic Low Output. 1: Logic High Output (open if corresponding P2MDOUT.n bit = 0). (Read - Regardless of XBR0, XBR1, XBR2, and XBR3 Register settings). 0: P2.n pin is logic low. 1: P2.n pin is logic high. Note: P2.[7:0] can be driven by the External Data Memory Interface (as Address[15:8] in Multiplexed mode, or as Address[7:0] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEM- ORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Figure 17.16. P2MDOUT: Port2 Output Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA6 Bits7-0: P2MDOUT.[7:0]: Port2 Output Mode Bits. 0: Port Pin output mode is configured as Open-Drain. 1: Port Pin output mode is configured as Push-Pull. Note: SDA, SCL, and RX0 (when UART0 is in Mode 0) and RX1 (when UART1 is in Mode 0) are always configured as Open-Drain when they appear on Port pins. Rev. 1.4 175

C8051F020/1/2/3 Figure 17.17. P3: Port3 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xB0 Bits7-0: P3.[7:0]: Port3 Output Latch Bits. (Write - Output appears on I/O pins per XBR0, XBR1, XBR2, and XBR3 Registers) 0: Logic Low Output. 1: Logic High Output (open if corresponding P3MDOUT.n bit = 0). (Read - Regardless of XBR0, XBR1, XBR2, and XBR3 Register settings). 0: P3.n pin is logic low. 1: P3.n pin is logic high. Note: P3.[7:0] can be driven by the External Data Memory Interface (as AD[7:0] in Multiplexed mode, or as D[7:0] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEMORY INTER- FACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Figure 17.18. P3MDOUT: Port3 Output Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA7 Bits7-0: P3MDOUT.[7:0]: Port3 Output Mode Bits. 0: Port Pin output mode is configured as Open-Drain. 1: Port Pin output mode is configured as Push-Pull. Note: SDA, SCL, and RX0 (when UART0 is in Mode 0) and RX1 (when UART1 is in Mode 0) are always configured as Open-Drain when they appear on Port pins. 176 Rev. 1.4

C8051F020/1/2/3 Figure 17.19. P3IF: Port3 Interrupt Flag Register R/W R/W R R R/W R/W R/W R/W Reset Value IE7 IE6 - - IE7CF IE6CF - - 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAD Bit7: IE7: External Interrupt 7 Pending Flag 0: No falling edge has been detected on P3.7 since this bit was last cleared. 1: This flag is set by hardware when a falling edge on P3.7 is detected. Bit6: IE6: External Interrupt 6 Pending Flag 0: No falling edge has been detected on P3.6 since this bit was last cleared. 1: This flag is set by hardware when a falling edge on P3.6 is detected. Bits5-4: UNUSED. Read = 00b, Write = don’t care. Bit3: IE7CF: External Interrupt 7 Edge Configuration 0: External Interrupt 7 triggered by a falling edge on the IE7 input. 1: External Interrupt 7 triggered by a rising edge on the IE7 input. Bit2: IE6CF: External Interrupt 6 Edge Configuration 0: External Interrupt 6 triggered by a falling edge on the IE6 input. 1: External Interrupt 6 triggered by a rising edge on the IE6 input. Bits1-0: UNUSED. Read = 00b, Write = don’t care. 17.2. Ports 4 through 7 (C8051F020/2 only) All Port pins on Ports 4 through 7 can be accessed as General-Purpose I/O (GPIO) pins by reading and writing the associated Port Data registers (See Figure 17.21, Figure 17.22, Figure 17.23, and Figure 17.24), a set of SFRs which are byte-addressable. A Read of a Port Data register (or Port bit) will always return the logic state present at the pin itself, regardless of whether the Crossbar has allocated the pin for peripheral use or not. An exception to this occurs during the execution of a read-modify-write instruction (ANL, ORL, XRL, CPL, INC, DEC, DJNZ, JBC, CLR, SET, and the bitwise MOV operation). During the read cycle of the read-modify-write instruction, it is the contents of the Port Data register, not the state of the Port pins themselves, which is read. 17.2.1. Configuring Ports which are not Pinned Out Although P4, P5, P6, and P7 are not brought out to pins on the C8051F021/3 devices, the Port Data registers are still present and can be used by software. Because the digital input paths also remain active, it is recommended that these pins not be left in a ‘floating’ state in order to avoid unnecessary power dissipation arising from the inputs floating to non-valid logic levels. This condition can be prevented by any of the following: 1. Leave the weak pull-up devices enabled by setting WEAKPUD (XBR2.7) to a logic 0. 2. Configure the output modes of P4, P5, P6, and P7 to “Push-Pull” by writing P74OUT = 0xFF. 3. Force the output states of P4, P5, P6, and P7 to logic 0 by writing zeros to the Port Data regis- ters: P4 = 0x00, P5 = 0x00, P6= 0x00, and P7 = 0x00. 17.2.2. Configuring the Output Modes of the Port Pins The output mode of each port pin can be configured to be either Open-Drain or Push-Pull. In the Push-Pull configura- tion, a logic 0 in the associated bit in the Port Data register will cause the Port pin to be driven to GND, and a logic 1 will cause the Port pin to be driven to VDD. In the Open-Drain configuration, a logic 0 in the associated bit in the Rev. 1.4 177

C8051F020/1/2/3 Port Data register will cause the Port pin to be driven to GND, and a logic 1 will cause the Port pin to assume a high- impedance state. The Open-Drain configuration is useful to prevent contention between devices in systems where the Port pin participates in a shared interconnection in which multiple outputs are connected to the same physical wire. The output modes of the Port pins on Ports 4 through 7 are determined by the bits in the P74OUT register (see Figure 17.20). Each bit in P74OUT controls the output mode of a 4-bit bank of Port pins on Ports 4, 5, 6, and 7. A logic 1 in P74OUT.7 will configure the output modes of 4 most-significant bits of Port 7, P7.[7:4], to Push-Pull; a logic 0 in P74OUT.7 will configure the output modes of P7.[7:4] to Open-Drain. 17.2.3. Configuring Port Pins as Digital Inputs A Port pin is configured as a digital input by setting its output mode to “Open-Drain” and writing a logic 1 to the associated bit in the Port Data register. For example, P7.7 is configured as a digital input by setting P74OUT.7 to a logic 0 and P7.7 to a logic 1. 17.2.4. Weak Pull-ups By default, each Port pin has an internal weak pull-up device enabled which provides a resistive connection (about 100 kΩ) between the pin and VDD. The weak pull-up devices can be globally disabled by writing a logic 1 to the Weak Pull-up Disable bit, (WEAKPUD, XBR2.7). The weak pull-up is automatically deactivated on any pin that is driving a logic 0; that is, an output pin will not contend with its own pull-up device. 17.2.5. External Memory Interface If the External Memory Interface (EMIF) is enabled on the High ports (Ports 4 through 7), EMIFLE (XBR2.1) should be set to a logic 0. If the External Memory Interface is enabled on the High ports and an off-chip MOVX operation occurs, the External Memory Interface will control the output states of the affected Port pins during the execution phase of the MOVX instruction, regardless of the settings of the Port Data registers. The output configuration of the Port pins is not affected by the EMIF operation, except that Read operations will explicitly disable the output drivers on the Data Bus during the MOVX execution. See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. 178 Rev. 1.4

C8051F020/1/2/3 Figure 17.20. P74OUT: Ports 7 - 4 Output Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P7H P7L P6H P6L P5H P5L P4H P4L 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB5 Bit7: P7H: Port7 Output Mode High Nibble Bit. 0: P7.[7:4] configured as Open-Drain. 1: P7.[7:4] configured as Push-Pull. Bit6: P7L: Port7 Output Mode Low Nibble Bit. 0: P7.[3:0] configured as Open-Drain. 1: P7.[3:0] configured as Push-Pull. Bit5: P6H: Port6 Output Mode High Nibble Bit. 0: P6.[7:4] configured as Open-Drain. 1: P6.[7:4] configured as Push-Pull. Bit4: P6L: Port6 Output Mode Low Nibble Bit. 0: P6.[3:0] configured as Open-Drain. 1: P6.[3:0] configured as Push-Pull. Bit3: P5H: Port5 Output Mode High Nibble Bit. 0: P5.[7:4] configured as Open-Drain. 1: P5.[7:4] configured as Push-Pull. Bit2: P5L: Port5 Output Mode Low Nibble Bit. 0: P5.[3:0] configured as Open-Drain. 1: P5.[3:0] configured as Push-Pull. Bit1: P4H: Port4 Output Mode High Nibble Bit. 0: P4.[7:4] configured as Open-Drain. 1: P4.[7:4] configured as Push-Pull. Bit0: P4L: Port4 Output Mode Low Nibble Bit. 0: P4.[3:0] configured as Open-Drain. 1: P4.[3:0] configured as Push-Pull. Rev. 1.4 179

C8051F020/1/2/3 Figure 17.21. P4: Port4 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P4.7 P4.6 P4.5 P4.4 P4.3 P4.2 P4.1 P4.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x84 Bits7-0: P4.[7:0]: Port4 Output Latch Bits. Write - Output appears on I/O pins. 0: Logic Low Output. 1: Logic High Output (Open-Drain if corresponding P74OUT bit = 0). See Figure 17.20. Read - Returns states of I/O pins. 0: P4.n pin is logic low. 1: P4.n pin is logic high. Note: P4.7 (/WR), P4.6 (/RD), and P4.5 (ALE) can be driven by the External Data Memory Interface. See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information. Figure 17.22. P5: Port5 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P5.7 P5.6 P5.5 P5.4 P5.3 P5.2 P5.1 P5.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x85 Bits7-0: P5.[7:0]: Port5 Output Latch Bits. Write - Output appears on I/O pins. 0: Logic Low Output. 1: Logic High Output (Open-Drain if corresponding P74OUT bit = 0). See Figure 17.20. Read - Returns states of I/O pins. 0: P5.n pin is logic low. 1: P5.n pin is logic high. Note: P5.[7:0] can be driven by the External Data Memory Interface (as Address[15:8] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEMORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. 180 Rev. 1.4

C8051F020/1/2/3 Figure 17.23. P6: Port6 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P6.7 P6.6 P6.5 P6.4 P6.3 P6.2 P6.1 P6.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x86 Bits7-0: P6.[7:0]: Port6 Output Latch Bits. Write - Output appears on I/O pins. 0: Logic Low Output. 1: Logic High Output (Open-Drain if corresponding P74OUT bit = 0). See Figure 17.20. Read - Returns states of I/O pins. 0: P6.n pin is logic low. 1: P6.n pin is logic high. Note: P6.[7:0] can be driven by the External Data Memory Interface (as Address[15:8] in Multiplexed mode, or as Address[7:0] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEM- ORY INTERFACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Figure 17.24. P7: Port7 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value P7.7 P7.6 P7.5 P7.4 P7.3 P7.2 P7.1 P7.0 11111111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x96 Bits7-0: P7.[7:0]: Port7 Output Latch Bits. Write - Output appears on I/O pins. 0: Logic Low Output. 1: Logic High Output (Open-Drain if corresponding P74OUT bit = 0). See Figure 17.20. Read - Returns states of I/O pins. 0: P7.n pin is logic low. 1: P7.n pin is logic high. Note: P7.[7:0] can be driven by the External Data Memory Interface (as AD[7:0] in Multiplexed mode, or as D[7:0] in Non-multiplexed mode). See Section “16. EXTERNAL DATA MEMORY INTER- FACE AND ON-CHIP XRAM” on page 145 for more information about the External Memory Interface. Rev. 1.4 181

C8051F020/1/2/3 Notes 182 Rev. 1.4

C8051F020/1/2/3 2 18. SYSTEM MANAGEMENT BUS / I C BUS (SMBUS0) The SMBus0 I/O interface is a two-wire, bi-directional serial bus. SMBus0 is compliant with the System Manage- ment Bus Specification, version 1.1, and compatible with the I2C serial bus. Reads and writes to the interface by the system controller are byte oriented with the SMBus0 interface autonomously controlling the serial transfer of the data. Data can be transferred at up to 1/8th of the system clock if desired (this can be faster than allowed by the SMBus specification, depending on the system clock used). A method of extending the clock-low duration is avail- able to accommodate devices with different speed capabilities on the same bus. SMBus0 may operate as a master and/or slave, and may function on a bus with multiple masters. SMBus0 provides control of SDA (serial data), SCL (serial clock) generation and synchronization, arbitration logic, and START/STOP control and generation. SMBus0 is controlled by SFRs as described in Section 18.4 on page 189. Figure 18.1. SMBus0 Block Diagram SFR Bus SMB0CN SMB0STA SMB0CR B E S S S A F T S S S S S S S S C C C C C C C C U N T T I A T O T T T T T T T T R R R R R R R R S S A O E E A A A A A A A A 7 6 5 4 3 2 1 0 Y M 7 6 5 4 3 2 1 0 B Clock Divide SYSCLK Logic SCL FILTER SMBUS CONTROL LOGIC SMBUS Interrupt ASrCbLit rSaytinocnhronization SCL IRQ Request Status Generation Control N SCL Generation (Master Mode) IRQ Generation Data Path SDA Control Control C R O S Port I/O S A=B A=B B B A B A A R 0000000b 7 MSBs 8 7 SMB0DAT SDA 7 6 5 4 3 2 1 0 FILTER 8 8 1 S S S S S S S N L L L L L L L 0 V V V V V V V G 6 5 4 3 2 1 0 C SMB0ADR Read Write to SMB0DAT SMB0DAT SFR Bus Rev. 1.4 183

C8051F020/1/2/3 Figure 18.2 shows a typical SMBus configuration. The SMBus0 interface will work at any voltage between 3.0 V and 5.0 V and different devices on the bus may operate at different voltage levels. The bi-directional SCL (serial clock) and SDA (serial data) lines must be connected to a positive power supply voltage through a pull-up resistor or similar circuit. Every device connected to the bus must have an open-drain or open-collector output for both the SCL and SDA lines, so that both are pulled high when the bus is free. The maximum number of devices on the bus is limited only by the requirement that the rise and fall times on the bus will not exceed 300 ns and 1000 ns, respectively. Figure 18.2. Typical SMBus Configuration VDD = 5V VDD = 3V VDD = 5V VDD = 3V Master Slave Slave Device Device 1 Device 2 SDA SCL 18.1. Supporting Documents It is assumed the reader is familiar with or has access to the following supporting documents: 1. The I2C-bus and how to use it (including specifications), Philips Semiconductor. 2. The I2C-Bus Specification -- Version 2.0, Philips Semiconductor. 3. System Management Bus Specification -- Version 1.1, SBS Implementers Forum. 184 Rev. 1.4

C8051F020/1/2/3 18.2. SMBus Protocol Two types of data transfers are possible: data transfers from a master transmitter to an addressed slave receiver (WRITE), and data transfers from an addressed slave transmitter to a master receiver (READ). The master device ini- tiates both types of data transfers and provides the serial clock pulses on SCL. Note: multiple master devices on the same bus are supported. If two or more masters attempt to initiate a data transfer simultaneously, an arbitration scheme is employed with a single master always winning the arbitration. Note that it is not necessary to specify one device as the master in a system; any device who transmits a START and a slave address becomes the master for that transfer. A typical SMBus transaction consists of a START condition followed by an address byte (Bits7-1: 7-bit slave address; Bit0: R/W direction bit), one or more bytes of data, and a STOP condition. Each byte that is received (by a master or slave) must be acknowledged (ACK) with a low SDA during a high SCL (see Figure 18.3). If the receiving device does not ACK, the transmitting device will read a “not acknowledge” (NACK), which is a high SDA during a high SCL. The direction bit (R/W) occupies the least-significant bit position of the address. The direction bit is set to logic 1 to indicate a "READ" operation and cleared to logic 0 to indicate a "WRITE" operation. All transactions are initiated by a master, with one or more addressed slave devices as the target. The master gener- ates the START condition and then transmits the slave address and direction bit. If the transaction is a WRITE opera- tion from the master to the slave, the master transmits the data a byte at a time waiting for an ACK from the slave at the end of each byte. For READ operations, the slave transmits the data waiting for an ACK from the master at the end of each byte. At the end of the data transfer, the master generates a STOP condition to terminate the transaction and free the bus. Figure 18.3 illustrates a typical SMBus transaction. Figure 18.3. SMBus Transaction SCL SDA SLA6 SLA5-0 R/W D7 D6-0 START Slave Address + R/W ACK Data Byte NACK STOP 18.2.1. Arbitration A master may start a transfer only if the bus is free. The bus is free after a STOP condition or after the SCL and SDA lines remain high for a specified time (see Section 18.2.4). In the event that two or more devices attempt to begin a transfer at the same time, an arbitration scheme is employed to force one master to give up the bus. The master devices continue transmitting until one attempts a HIGH while the other transmits a LOW. Since the bus is open- drain, the bus will be pulled LOW. The master attempting the HIGH will detect a LOW SDA and give up the bus. The winning master continues its transmission without interruption; the losing master becomes a slave and receives the rest of the transfer. This arbitration scheme is non-destructive: one device always wins, and no data is lost. 18.2.2. Clock Low Extension SMBus provides a clock synchronization mechanism, similar to I2C, which allows devices with different speed capa- bilities to coexist on the bus. A clock-low extension is used during a transfer in order to allow slower slave devices to communicate with faster masters. The slave may temporarily hold the SCL line LOW to extend the clock low period, effectively decreasing the serial clock frequency. Rev. 1.4 185

C8051F020/1/2/3 18.2.3. SCL Low Timeout If the SCL line is held low by a slave device on the bus, no further communication is possible. Furthermore, the mas- ter cannot force the SCL line high to correct the error condition. To solve this problem, the SMBus protocol specifies that devices participating in a transfer must detect any clock cycle held low longer than 25 ms as a “timeout” condi- tion. Devices that have detected the timeout condition must reset the communication no later than 10 ms after detect- ing the timeout condition. 18.2.4. SCL High (SMBus Free) Timeout The SMBus specification stipulates that if the SCL and SDA lines remain high for more that 50 µs, the bus is desig- nated as free. If an SMBus device is waiting to generate a Master START, the START will be generated following a bus free timeout. 186 Rev. 1.4

C8051F020/1/2/3 18.3. SMBus Transfer Modes The SMBus0 interface may be configured to operate as a master and/or a slave. At any particular time, the interface will be operating in one of the following modes: Master Transmitter, Master Receiver, Slave Transmitter, or Slave Receiver. See Table 18.1 for transfer mode status decoding using the SMB0STA status register. The following mode descriptions illustrate an interrupt-driven SMBus0 application; SMBus0 may alternatively be operated in polled mode. 18.3.1. Master Transmitter Mode Serial data is transmitted on SDA while the serial clock is output on SCL. SMBus0 generates a START condition and then transmits the first byte containing the address of the target slave device and the data direction bit. In this case the data direction bit (R/W) will be logic 0 to indicate a "WRITE" operation. The SMBus0 interface transmits one or more bytes of serial data, waiting for an acknowledge (ACK) from the slave after each byte. To indicate the end of the serial transfer, SMBus0 generates a STOP condition. Figure 18.4. Typical Master Transmitter Sequence S SLA W A Data Byte A Data Byte A P Interrupt Interrupt Interrupt Interrupt Received by SMBus S = START Interface P = STOP A = ACK Transmitted by W = WRITE SMBus Interface SLA = Slave Address 18.3.2. Master Receiver Mode Serial data is received on SDA while the serial clock is output on SCL. The SMBus0 interface generates a START followed by the first data byte containing the address of the target slave and the data direction bit. In this case the data direction bit (R/W) will be logic 1 to indicate a "READ" operation. The SMBus0 interface receives serial data from the slave and generates the clock on SCL. After each byte is received, SMBus0 generates an ACK or NACK depend- ing on the state of the AA bit in register SMB0CN. SMBus0 generates a STOP condition to indicate the end of the serial transfer. Figure 18.5. Typical Master Receiver Sequence S SLA R A Data Byte A Data Byte N P Interrupt Interrupt Interrupt Interrupt Received by SMBus S = START Interface P = STOP A = ACK N = NACK Transmitted by R = READ SMBus Interface SLA = Slave Address Rev. 1.4 187

C8051F020/1/2/3 18.3.3. Slave Transmitter Mode Serial data is transmitted on SDA while the serial clock is received on SCL. The SMBus0 interface receives a START followed by data byte containing the slave address and direction bit. If the received slave address matches the address held in register SMB0ADR, the SMBus0 interface generates an ACK. SMBus0 will also ACK if the general call address (0x00) is received and the General Call Address Enable bit (SMB0ADR.0) is set to logic 1. In this case the data direction bit (R/W) will be logic 1 to indicate a "READ" operation. The SMBus0 interface receives the clock on SCL and transmits one or more bytes of serial data, waiting for an ACK from the master after each byte. SMBus0 exits slave mode after receiving a STOP condition from the master. Figure 18.6. Typical Slave Transmitter Sequence Interrupt S SLA R A Data Byte A Data Byte N P Interrupt Interrupt Interrupt Received by SMBus S = START Interface P = STOP N = NACK W = WRITE Transmitted by SLA = Slave Address SMBus Interface 18.3.4. Slave Receiver Mode Serial data is received on SDA while the serial clock is received on SCL. The SMBus0 interface receives a START followed by data byte containing the slave address and direction bit. If the received slave address matches the address held in register SMB0ADR, the interface generates an ACK. SMBus0 will also ACK if the general call address (0x00) is received and the General Call Address Enable bit (SMB0ADR.0) is set to logic 1. In this case the data direc- tion bit (R/W) will be logic 0 to indicate a "WRITE" operation. The SMBus0 interface receives one or more bytes of serial data; after each byte is received, the interface transmits an ACK or NACK depending on the state of the AA bit in SMB0CN. SMBus0 exits Slave Receiver Mode after receiving a STOP condition from the master. Figure 18.7. Typical Slave Receiver Sequence Interrupt S SLA W A Data Byte A Data Byte A P Interrupt Interrupt Interrupt Received by SMBus S = START Interface P = STOP A = ACK R = READ Transmitted by SLA = Slave Address SMBus Interface 188 Rev. 1.4

C8051F020/1/2/3 18.4. SMBus Special Function Registers The SMBus0 serial interface is accessed and controlled through five SFRs: SMB0CN Control Register, SMB0CR Clock Rate Register, SMB0ADR Address Register, SMB0DAT Data Register and SMB0STA Status Register. The five special function registers related to the operation of the SMBus0 interface are described in the following sec- tions. 18.4.1. Control Register The SMBus0 Control register SMB0CN is used to configure and control the SMBus0 interface. All of the bits in the register can be read or written by software. Two of the control bits are also affected by the SMBus0 hardware. The Serial Interrupt flag (SI, SMB0CN.3) is set to logic 1 by the hardware when a valid serial interrupt condition occurs. It can only be cleared by software. The Stop flag (STO, SMB0CN.4) is cleared to logic 0 by hardware when a STOP condition is detected on the bus. Setting the ENSMS flag to logic 1 enables the SMBus0 interface. Clearing the ENSMB flag to logic 0 disables the SMBus0 interface and removes it from the bus. Momentarily clearing the ENSMB flag and then resetting it to logic 1 will reset SMBus0 communication. However, ENSMB should not be used to temporarily remove a device from the bus since the bus state information will be lost. Instead, the Assert Acknowledge (AA) flag should be used to tempo- rarily remove the device from the bus (see description of AA flag below). Setting the Start flag (STA, SMB0CN.5) to logic 1 will put SMBus0 in a master mode. If the bus is free, SMBus0 will generate a START condition. If the bus is not free, SMBus0 waits for a STOP condition to free the bus and then gen- erates a START condition after a 5 µs delay per the SMB0CR value (In accordance with the SMBus protocol, the SMBus0 interface also considers the bus free if the bus is idle for 50 µs and no STOP condition was recognized). If STA is set to logic 1 while SMBus0 is in master mode and one or more bytes have been transferred, a repeated START condition will be generated. To ensure proper operation, the STO bit should be explicitly cleared to ‘0’ before setting the STA bit to ‘1’. When the Stop flag (STO, SMB0CN.4) is set to logic 1 while the SMBus0 interface is in master mode, the interface generates a STOP condition. In a slave mode, the STO flag may be used to recover from an error condition. In this case, a STOP condition is not generated on the bus, but the SMBus hardware behaves as if a STOP condition has been received and enters the "not addressed" slave receiver mode. Note that this simulated STOP will not cause the bus to appear free to SMBus0. The bus will remain occupied until a STOP appears on the bus or a Bus Free Timeout occurs. Hardware automatically clears the STO flag to logic 0 when a STOP condition is detected on the bus. The Serial Interrupt flag (SI, SMB0CN.3) is set to logic 1 by hardware when the SMBus0 interface enters one of 27 possible states. If interrupts are enabled for the SMBus0 interface, an interrupt request is generated when the SI flag is set. The SI flag must be cleared by software. Important Note: If SI is set to logic 1 while the SCL line is low, the clock-low period of the serial clock will be stretched and the serial transfer is suspended until SI is cleared to logic 0. A high level on SCL is not affected by the setting of the SI flag. The Assert Acknowledge flag (AA, SMB0CN.2) is used to set the level of the SDA line during the acknowledge clock cycle on the SCL line. Setting the AA flag to logic 1 will cause an ACK (low level on SDA) to be sent during the acknowledge cycle if the device has been addressed. Setting the AA flag to logic 0 will cause a NACK (high level on SDA) to be sent during acknowledge cycle. After the transmission of a byte in slave mode, the slave can be tempo- rarily removed from the bus by clearing the AA flag. The slave's own address and general call address will be ignored. To resume operation on the bus, the AA flag must be reset to logic 1 to allow the slave's address to be recog- nized. Rev. 1.4 189

C8051F020/1/2/3 Setting the SMBus0 Free Timer Enable bit (FTE, SMB0CN.1) to logic 1 enables the timer in SMB0CR. When SCL goes high, the timer in SMB0CR counts up. A timer overflow indicates a free bus timeout: if SMBus0 is waiting to generate a START, it will do so after this timeout. The bus free period should be less than 50 µs (see Figure 18.9, SMBus0 Clock Rate Register). When the TOE bit in SMB0CN is set to logic 1, Timer 3 is used to detect SCL low timeouts. If Timer 3 is enabled (see Section “22.2. Timer 3” on page 240), Timer 3 is forced to reload when SCL is high, and forced to count when SCL is low. With Timer 3 enabled and configured to overflow after 25 ms (and TOE set), a Timer 3 overflow indi- cates a SCL low timeout; the Timer 3 interrupt service routine can then be used to reset SMBus0 communication in the event of an SCL low timeout. 190 Rev. 1.4

C8051F020/1/2/3 Figure 18.8. SMB0CN: SMBus0 Control Register R R/W R/W R/W R/W R/W R/W R/W Reset Value BUSY ENSMB STA STO SI AA FTE TOE 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xC0 Bit7: BUSY: Busy Status Flag. 0: SMBus0 is free 1: SMBus0 is busy Bit6: ENSMB: SMBus Enable. This bit enables/disables the SMBus serial interface. 0: SMBus0 disabled. 1: SMBus0 enabled. Bit5: STA: SMBus Start Flag. 0: No START condition is transmitted. 1: When operating as a master, a START condition is transmitted if the bus is free. (If the bus is not free, the START is transmitted after a STOP is received.) If STA is set after one or more bytes have been transmitted or received and before a STOP is received, a repeated START condition is transmit- ted. To ensure proper operation, the STO bit should be explicitly cleared to ‘0’ before setting the STA bit to ‘1’. Bit4: STO: SMBus Stop Flag. 0: No STOP condition is transmitted. 1: Setting STO to logic 1 causes a STOP condition to be transmitted. When a STOP condition is received, hardware clears STO to logic 0. If both STA and STO are set, a STOP condition is transmit- ted followed by a START condition. In slave mode, setting the STO flag causes SMBus to behave as if a STOP condition was received. Bit3: SI: SMBus Serial Interrupt Flag. This bit is set by hardware when one of 27 possible SMBus0 states is entered. (Status code 0xF8 does not cause SI to be set.) When the SI interrupt is enabled, setting this bit causes the CPU to vector to the SMBus interrupt service routine. This bit is not automatically cleared by hardware and must be cleared by software. Bit2: AA: SMBus Assert Acknowledge Flag. This bit defines the type of acknowledge returned during the acknowledge cycle on the SCL line. 0: A "not acknowledge" (high level on SDA) is returned during the acknowledge cycle. 1: An "acknowledge" (low level on SDA) is returned during the acknowledge cycle. Bit1: FTE: SMBus Free Timer Enable Bit 0: No timeout when SCL is high 1: Timeout when SCL high time exceeds limit specified by the SMB0CR value. Bit0: TOE: SMBus Timeout Enable Bit 0: No timeout when SCL is low. Rev. 1.4 191

C8051F020/1/2/3 18.4.2. Clock Rate Register Figure 18.9. SMB0CR: SMBus0 Clock Rate Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xCF Bits7-0: SMB0CR.[7:0]: SMBus0 Clock Rate Preset The SMB0CR Clock Rate register controls the frequency of the serial clock SCL in master mode. The 8-bit word stored in the SMB0CR Register preloads a dedicated 8-bit timer. The timer counts up, and when it rolls over to 0x00, the SCL logic state toggles. The SMB0CR setting should be bounded by the following equation , where SMB0CR is the unsigned 8-bit value in register SMB0CR, and SYSCLK is the system clock frequency in Hz: SMB0CR< ((288 –0.85⋅SYSCLK)⁄1.125) The resulting SCL signal high and low times are given by the following equations: T = (256–SMB0CR)⁄ SYSCLK LOW T ≅ (258–SMB0CR)⁄SYSCLK + 625ns HIGH Using the same value of SMB0CR from above, the Bus Free Timeout period is given in the following equation: (256 –SMB0CR) + 1 T ≅ 10× ----------------------------------------------------- BFT SYSCLK 192 Rev. 1.4

C8051F020/1/2/3 18.4.3. Data Register The SMBus0 Data register SMB0DAT holds a byte of serial data to be transmitted or one that has just been received. Software can read or write to this register while the SI flag is set to logic 1; software should not attempt to access the SMB0DAT register when the SMBus is enabled and the SI flag is cleared to logic 0 since the hardware may be in the process of shifting a byte of data in or out of the register. Data in SMB0DAT is always shifted out MSB first. After a byte has been received, the first bit of received data is located at the MSB of SMB0DAT. While data is being shifted out, data on the bus is simultaneously being shifted in. Therefore, SMB0DAT always contains the last data byte present on the bus. In the event of lost arbitration, the transi- tion from master transmitter to slave receiver is made with the correct data in SMB0DAT. Figure 18.10. SMB0DAT: SMBus0 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC2 Bits7-0: SMB0DAT: SMBus0 Data. The SMB0DAT register contains a byte of data to be transmitted on the SMBus0 serial interface or a byte that has just been received on the SMBus0 serial interface. The CPU can read from or write to this register whenever the SI serial interrupt flag (SMB0CN.3) is set to logic 1. When the SI flag is not set, the system may be in the process of shifting data in/out and the CPU should not attempt to access this register. 18.4.4. Address Register The SMB0ADR Address register holds the slave address for the SMBus0 interface. In slave mode, the seven most- significant bits hold the 7-bit slave address. The least significant bit (Bit0) is used to enable the recognition of the general call address (0x00). If Bit0 is set to logic 1, the general call address will be recognized. Otherwise, the general call address is ignored. The contents of this register are ignored when SMBus0 is operating in master mode. Figure 18.11. SMB0ADR: SMBus0 Address Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SLV6 SLV5 SLV4 SLV3 SLV2 SLV1 SLV0 GC 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC3 Bits7-1: SLV6-SLV0: SMBus0 Slave Address. These bits are loaded with the 7-bit slave address to which SMBus0 will respond when operating as a slave transmitter or slave receiver. SLV6 is the most significant bit of the address and corresponds to the first bit of the address byte received. Bit0: GC: General Call Address Enable. This bit is used to enable general call address (0x00) recognition. 0: General call address is ignored. 1: General call address is recognized. Rev. 1.4 193

C8051F020/1/2/3 18.4.5. Status Register The SMB0STA Status register holds an 8-bit status code indicating the current state of the SMBus0 interface. There are 28 possible SMBus0 states, each with a corresponding unique status code. The five most significant bits of the status code vary while the three least-significant bits of a valid status code are fixed at zero when SI = ‘1’. Therefore, all possible status codes are multiples of eight. This facilitates the use of status codes in software as an index used to branch to appropriate service routines (allowing 8 bytes of code to service the state or jump to a more extensive ser- vice routine). For the purposes of user software, the contents of the SMB0STA register is only defined when the SI flag is logic 1. Software should never write to the SMB0STA register; doing so will yield indeterminate results. The 28 SMBus0 states, along with their corresponding status codes, are given in Table 1.1. Figure 18.12. SMB0STA: SMBus0 Status Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value STA7 STA6 STA5 STA4 STA3 STA2 STA1 STA0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC1 Bits7-3: STA7-STA3: SMBus0 Status Code. These bits contain the SMBus0 Status Code. There are 28 possible status codes; each status code cor- responds to a single SMBus state. A valid status code is present in SMB0STA when the SI flag (SMB0CN.3) is set to logic 1. The content of SMB0STA is not defined when the SI flag is logic 0. Writing to the SMB0STA register at any time will yield indeterminate results. Bits2-0: STA2-STA0: The three least significant bits of SMB0STA are always read as logic 0 when the SI flag is logic 1. 194 Rev. 1.4

C8051F020/1/2/3 Table 18.1. SMB0STA Status Codes and States Status Mode SMBus State Typical Action Code 0x08 START condition transmitted. Load SMB0DAT with Slave Address + R/W. Clear STA. T/R MM 0x10 Repeated START condition transmitted. Load SMB0DAT with Slave Address + R/W. Clear STA. 0x18 Slave Address + W transmitted. ACK Load SMB0DAT with data to be transmit- received. ted. r e 0x20 Slave Address + W transmitted. NACK Acknowledge poll to retry. Set STO + t mit received. STA. s n 1) Load SMB0DAT with next byte, OR a 0x28 Data byte transmitted. ACK received. 2) Set STO, OR r T 3) Clear STO then set STA for repeated r e START. t s a 0x30 Data byte transmitted. NACK received. 1) Retry transfer OR M 2) Set STO. 0x38 Arbitration Lost. Save current data. 0x40 Slave Address + R transmitted. ACK received. If only receiving one byte, clear AA (send r NACK after received byte). Wait for e v received data. ei c e 0x48 Slave Address + R transmitted. NACK Acknowledge poll to retry. Set STO + R received. STA. r e t 0x50 Data byte received. ACK transmitted. Read SMB0DAT. Wait for next byte. If s a next byte is last byte, clear AA. M 0x58 Data byte received. NACK transmitted. Set STO. Rev. 1.4 195

C8051F020/1/2/3 Table 18.1. SMB0STA Status Codes and States Status Mode SMBus State Typical Action Code 0x60 Own slave address + W received. ACK trans- Wait for data. mitted. 0x68 Arbitration lost in sending SLA + R/W as mas- Save current data for retry when bus is ter. Own address + W received. ACK transmit- free. Wait for data. ted. 0x70 General call address received. ACK transmit- Wait for data. ted. r e v 0x78 Arbitration lost in sending SLA + R/W as mas- Save current data for retry when bus is ei ter. General call address received. ACK trans- free. c e mitted. R e 0x80 Data byte received. ACK transmitted. Read SMB0DAT. Wait for next byte or v a STOP. Sl 0x88 Data byte received. NACK transmitted. Set STO to reset SMBus. 0x90 Data byte received after general call address. Read SMB0DAT. Wait for next byte or ACK transmitted. STOP. 0x98 Data byte received after general call address. Set STO to reset SMBus. NACK transmitted. 0xA0 STOP or repeated START received. No action necessary. 0xA8 Own address + R received. ACK transmitted. Load SMB0DAT with data to transmit. r e 0xB0 Arbitration lost in transmitting SLA + R/W as Save current data for retry when bus is t t mi master. Own address + R received. ACK free. Load SMB0DAT with data to trans- s transmitted. mit. n a r 0xB8 Data byte transmitted. ACK received. Load SMB0DAT with data to transmit. T e 0xC0 Data byte transmitted. NACK received. Wait for STOP. v a Sl 0xC8 Last data byte transmitted (AA=0). ACK Set STO to reset SMBus. received. e v a 0xD0 SCL Clock High Timer per SMB0CR timed out Set STO to reset SMBus. Sl 0x00 Bus Error (illegal START or STOP) Set STO to reset SMBus. All 0xF8 Idle State does not set SI. 196 Rev. 1.4

C8051F020/1/2/3 19. SERIAL PERIPHERAL INTERFACE BUS (SPI0) The Serial Peripheral Interface (SPI0) provides access to a four-wire, full-duplex, serial bus. SPI0 may operate as a master or a slave, and supports the connection of multiple slaves and masters on the same bus. A slave-select input (NSS) is included in the SPI0 interface to select SPI0 as a slave; additional general purpose port I/O can be used as slave-select outputs when SPI0 is operating as a master. Collision detection is provided when two or more masters attempt a data transfer at the same time. When the SPI is configured as a master, the maximum data transfer rate (bits/ sec) is one-half the system clock frequency. When the SPI is configured as a slave, the maximum data transfer rate (bits/sec) for full-duplex operation is 1/10 the system clock frequency, provided that the master issues SCK, NSS, and the serial input data synchronously with the system clock. If the master issues SCK, NSS, and the serial input data asynchronously, the maximum data transfer rate (bits/sec) must be less that 1/10 the system clock frequency. In the special case where the master only wants to transmit data to the slave and does not need to receive data from the slave (i.e. half-duplex operation), the SPI slave can receive data at a maximum data transfer rate (bits/sec) of 1/4 the system clock frequency. This is provided that the master issues SCK, NSS, and the serial input data synchronously with the system clock. Figure 19.1. SPI Block Diagram SFR Bus SPI0CKR SPI0CFG SPI0CN S S S S S S S S C C B B B F F F S W M R T S M S C C C C C C C C K K C C C R R R P C O X X L S P R R R R R R R R P P 2 1 0 S S S I O D O B V T I 7 6 5 4 3 2 1 0 H O 2 1 0 F L F V S S E E A L R Y E N N N L Clock Divide Bit Count SYSCLK Logic Logic SPI CONTROL LOGIC SPI IRQ Data Path SPI Clock Pin Control Control (Master Mode) Interface SCK C R Tx Data MOSI O Pin S SPI0DAT Control Port I/O S 7 6S5hift4 Re3gist2er1 0 Rx Data Logic MISO B A R Receive Data Register NSS Write to Read SPI0DAT SPI0DAT SFR Bus Rev. 1.4 197

C8051F020/1/2/3 19.1. Signal Descriptions The four signals used by SPI0 (MOSI, MISO, SCK, NSS) are described below. 19.1.1. Master Out, Slave In (MOSI) The master-out, slave-in (MOSI) signal is an output from a master device and an input to slave devices. It is used to serially transfer data from the master to the slave. This signal is an output when SPI0 is operating as a master, and an input when SPI0 is operating as a slave. Data is transferred most-significant bit first. 19.1.2. Master In, Slave Out (MISO) The master-in, slave-out (MISO) signal is an output from a slave device and an input to the master device. It is used to serially transfer data from the slave to the master. This signal is an input when SPI0 is operating as a master, and an output when SPI0 is operating as a slave. Data is transferred most-significant bit first. A SPI slave places the MISO pin in a high-impedance state when the slave is not selected. 19.1.3. Serial Clock (SCK) The serial clock (SCK) signal is an output from the master device and an input to slave devices. It is used to synchro- nize the transfer of data between the master and slave on the MOSI and MISO lines. SPI0 generates this signal when operating as a master. 19.1.4. Slave Select (NSS) The slave select (NSS) signal is an input used to select SPI0 as a slave, or to disable SPI0 as a master. Note that the NSS signal is always an input to SPI0; with SPI0 operating as a master, slave select signals must be output via general purpose port I/O pins. See Figure 19.2 for a typical configuration; see Section “17.1. Ports 0 through 3 and the Pri- ority Crossbar Decoder” on page 163 for general purpose port configuration. The NSS signal must be low to initiate a transfer with SPI0 as a slave; SPI0 will exit slave mode when NSS is released high. Note that received data is not latched into the receive buffer until NSS is high. For multiple-byte trans- fers, NSS must be released high for at least 4 system clocks following each byte that is received by the SPI0 slave. Figure 19.2. Typical SPI Interconnection NSS NSS NSS Slave Slave Slave Device Device Device VDD GPIO Master Device MISO MISO MOSI MOSI SCK SCK 198 Rev. 1.4

C8051F020/1/2/3 19.2. SPI0 Operation Only a SPI master device can initiate a data transfer. SPI0 is placed in master mode by setting the Master Enable flag (MSTEN, SPI0CN.1). Writing a byte of data to the SPI0 data register (SPI0DAT) when in Master Mode starts a data transfer. The SPI0 master immediately shifts out the data serially on the MOSI line while providing the serial clock on SCK. The SPIF (SPI0CN.7) flag is set to logic 1 at the end of the transfer. If interrupts are enabled, an interrupt request is generated when the SPIF flag is set. The SPI0 master can be configured to shift in/out from one to eight bits in a transfer operation in order to accommodate slave devices with different word lengths. The SPIFRS bits in the SP0I Configuration Register (SPI0CFG.[2:0]) are used to select the number of bits to shift in/out in a transfer opera- tion. While the SPI0 master transfers data to a slave on the MOSI line, the addressed SPI slave device simultaneously transfers the contents of its shift register to the SPI master on the MISO line in a full-duplex operation. The data byte received from the slave replaces the data in the master's data register. Therefore, the SPIF flag serves as both a trans- mit-complete and receive-data-ready flag. The data transfer in both directions is synchronized with the serial clock generated by the master. Figure 19.3 illustrates the full-duplex operation of an SPI master and an addressed slave. Figure 19.3. Full Duplex Operation MASTER DEVICE SLAVE DEVICE MOSI MOSI SPI SHIFT REGISTER SPI SHIFT REGISTER MISO MISO 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 VDD Receive Buffer NSS NSS Receive Buffer Baud Rate SCK SCK Generator Px.y When SPI0 is enabled and not configured as a master, it will operate as an SPI slave. Another SPI device acting as a master will initiate a transfer by driving the NSS input signal low. The master then shifts data out of the shift register on the MOSI pin using the its serial clock. The SPIF flag is set to logic 1 when the NSS signal goes high, indicating the end of a data transfer. Note that following a rising edge on NSS, the receive buffer will always contain the last 8 bits of data in the slave shift register. The slave can load its shift register for the next data transfer by writing to the SPI0 data register. The slave must make the write to the data register at least one SPI serial clock cycle before the master starts the next transmission. Otherwise, the byte of data already in the slave's shift register will be transferred. Note that the NSS signal must be driven low at least 2 system clocks before the first active edge of SCK for each byte transfer. The SPI0 data register is double buffered on reads, but not on writes. If a write to SPI0DAT is attempted during a data transfer, the WCOL flag (SPI0CN.6) will be set to logic 1 and the write will be ignored. The current data transfer will continue uninterrupted. A read of the SPI0 data register by the system controller actually reads the receive buffer. The receive overrun flag (RXOVRN in register SPI0CN) is set anytime a SPI0 slave detects a rising edge on NSS while the receive buffer still holds unread data from a previous transfer. The new data is not transferred to the receive buf- fer, allowing the previously received data byte to be read. The data byte causing the overrun is lost. Rev. 1.4 199

C8051F020/1/2/3 Multiple masters may reside on the same bus. A Mode Fault flag (MODF, SPI0CN.5) is set to logic 1 when SPI0 is configured as a master (MSTEN = 1) and its slave select signal NSS is pulled low. When the Mode Fault flag is set, the MSTEN and SPIEN bits of the SPI control register are cleared by hardware, thereby placing the SPI0 module in an "off-line" state. In a multiple-master environment, the system controller should check the state of the SLVSEL flag (SPI0CN.2) to ensure the bus is free before setting the MSTEN bit and initiating a data transfer. 19.3. Serial Clock Timing As shown in Figure 19.4, four combinations of serial clock phase and polarity can be selected using the clock control bits in the SPI0 Configuration Register (SPI0CFG). The CKPHA bit (SPI0CFG.7) selects one of two clock phases (edge used to latch the data). The CKPOL bit (SPI0CFG.6) selects between an active-high or active-low clock. Both master and slave devices must be configured to use the same clock phase and polarity. Note: SPI0 should be disabled (by clearing the SPIEN bit, SPI0CN.0) while changing the clock phase and polarity. The SPI0 Clock Rate Register (SPI0CKR) as shown in Figure 19.7 controls the master mode serial clock frequency. This register is ignored when operating in slave mode. Figure 19.4. Data/Clock Timing Diagram SCK (CKPOL=0, CKPHA=0) SCK (CKPOL=0, CKPHA=1) SCK (CKPOL=1, CKPHA=0) SCK (CKPOL=1, CKPHA=1) MISO/MOSI MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 NSS 200 Rev. 1.4

C8051F020/1/2/3 19.4. SPI Special Function Registers SPI0 is accessed and controlled through four special function registers in the system controller: SPI0CN Control Reg- ister, SPI0DAT Data Register, SPI0CFG Configuration Register, and SPI0CKR Clock Rate Register. The four special function registers related to the operation of the SPI0 Bus are described in the following section. Figure 19.5. SPI0CFG: SPI0 Configuration Register R/W R/W R R R R/W R/W R/W Reset Value CKPHA CKPOL BC2 BC1 BC0 SPIFRS2 SPIFRS1 SPIFRS0 00000111 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9A Bit7: CKPHA: SPI0 Clock Phase. This bit controls the SPI0 clock phase. 0: Data sampled on first edge of SCK period. 1: Data sampled on second edge of SCK period. Bit6: CKPOL: SPI0 Clock Polarity. This bit controls the SPI0 clock polarity. 0: SCK line low in idle state. 1: SCK line high in idle state. Bits5-3: BC2-BC0: SPI0 Bit Count. Indicates which of the up to 8 bits of the SPI0 word have been transmitted. BC2-BC0 BIT Transmitted 0 0 0 Bit 0 (LSB) 0 0 1 Bit 1 0 1 0 Bit 2 0 1 1 Bit 3 1 0 0 Bit 4 1 0 1 Bit 5 1 1 0 Bit 6 1 1 1 Bit 7 (MSB) Bits2-0: SPIFRS2-SPIFRS0: SPI0 Frame Size. These three bits determine the number of bits to shift in/out of the SPI0 shift register during a data transfer in master mode. They are ignored in slave mode. SPIFRS Bits Shifted 0 0 0 1 0 0 1 2 0 1 0 3 0 1 1 4 1 0 0 5 1 0 1 6 1 1 0 7 1 1 1 8 Rev. 1.4 201

C8051F020/1/2/3 Figure 19.6. SPI0CN: SPI0 Control Register R/W R/W R/W R/W R R R/W R/W Reset Value SPIF WCOL MODF RXOVRN TXBSY SLVSEL MSTEN SPIEN 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xF8 Bit7: SPIF: SPI0 Interrupt Flag. This bit is set to logic 1 by hardware at the end of a data transfer. If interrupts are enabled, setting this bit causes the CPU to vector to the SPI0 interrupt service routine. This bit is not automatically cleared by hardware. It must be cleared by software. Bit6: WCOL: Write Collision Flag. This bit is set to logic 1 by hardware (and generates a SPI0 interrupt) to indicate a write to the SPI0 data register was attempted while a data transfer was in progress. If interrupts are enabled, setting this bit causes the CPU to vector to the SPI0 interrupt service routine. This bit is not automatically cleared by hardware. It must be cleared by software. Bit5: MODF: Mode Fault Flag. This bit is set to logic 1 by hardware (and generates a SPI0 interrupt) when a master mode collision is detected (NSS is low and MSTEN = 1). If interrupts are enabled, setting this bit causes the CPU to vector to the SPI0 interrupt service routine. This bit is not automatically cleared by hardware. It must be cleared by software. Bit4: RXOVRN: Receive Overrun Flag. This bit is set to logic 1 by hardware (and generates a SPI0 interrupt) when the receive buffer still holds unread data from a previous transfer and the last bit of the current transfer is shifted into the SPI0 shift register. If interrupts are enabled, setting this bit causes the CPU to vector to the SPI0 inter- rupt service routine. This bit is not automatically cleared by hardware. It must be cleared by software. Bit3: TXBSY: Transmit Busy Flag. This bit is set to logic 1 by hardware while a master mode transfer is in progress. It is cleared by hard- ware at the end of the transfer. Bit2: SLVSEL: Slave Selected Flag. This bit is set to logic 1 whenever the NSS pin is low indicating it is enabled as a slave. It is cleared to logic 0 when NSS is high (slave disabled). Bit1: MSTEN: Master Mode Enable. 0: Disable master mode. Operate in slave mode. 1: Enable master mode. Operate as a master. Bit0: SPIEN: SPI0 Enable. This bit enables/disables the SPI. 0: SPI disabled. 202 Rev. 1.4

C8051F020/1/2/3 Figure 19.7. SPI0CKR: SPI0 Clock Rate Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SCR7 SCR6 SCR5 SCR4 SCR3 SCR2 SCR1 SCR0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9D Bits7-0: SCR7-SCR0: SPI0 Clock Rate These bits determine the frequency of the SCK output when the SPI0 module is configured for master mode operation. The SCK clock frequency is a divided down version of the system clock, and is given in the following equation, where SYSCLK is the system clock frequency and SPI0CR is the 8- bit value held in the SPI0CR register. SYSCLK f = ------------------------------------------------- SCK 2× (SPI0CKR +1) for 0 <= SPI0CKR <= 255 Example: If SYSCLK = 2 MHz and SPI0CKR = 0x04, 2000000 f = -------------------------- SCK 2× (4+ 1) f = 200kHz SCK Figure 19.8. SPI0DAT: SPI0 Data Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x9B Bits7-0: SPI0DAT: SPI0 Transmit and Receive Data. The SPI0DAT register is used to transmit and receive SPI0 data. Writing data to SPI0DAT places the data immediately into the shift register and initiates a transfer when in Master Mode. A read of SPI0- DAT returns the contents of the receive buffer. Rev. 1.4 203

C8051F020/1/2/3 Notes 204 Rev. 1.4

C8051F020/1/2/3 20. UART0 UART0 is an enhanced serial port with frame error detection and address recognition hardware. UART0 may operate in full-duplex asynchronous or half-duplex synchronous modes, and mutiproccessor communication is fully sup- ported. Receive data is buffered in a holding register, allowing UART0 to start reception of a second incoming data byte before software has finished reading the previous data byte. A Receive Overrun bit indicates when new received data is latched into the receive buffer before the previous received byte is read. UART0 is accessed via its associated SFRs, Serial Control (SCON0) and Serial Data Buffer (SBUF0). The single SBUF0 location provides access to both transmit and receive registers. Reads access the Receive register and writes access the Transmit register automatically. UART0 may be operated in polled or interrupt mode. UART0 has two sources of interrupts: a Transmit Interrupt flag, TI0 (SCON0.1) set when transmission of a data byte is complete, and a Receive Interrupt flag, RI0 (SCON0.0) set when reception of a data byte is complete. UART0 interrupt flags are not cleared by hardware when the CPU vectors to the interrupt service routine; they must be cleared manually by software. This allows software to determine the cause of the UART0 interrupt (transmit complete or receive complete). Figure 20.1. UART0 Block Diagram SFR Bus Write to SBUF TB8 SET SBUF D Q (Transmit Shift) TX CLR Crossbar Zero Detector StGoepn B.it Shift Data Start Tx Control Tx Clock Send Tx IRQ UART SCON TI Baud Rate S S S R T R T R Serial Port Generation M0 M1 M2 NE B8 B8 I I (UInAteRrTru0p/1t) Logic RI EN Rx IRQ Rx Clock Load SBUF Rx Control Address Start Match Port I/O Shift 0x1FF Frame Error Input Shift Register Detection (9 bits) Load SBUF RB8 SADDR SBUF Match Detect (Receive Latch) SADEN Read SBUF SFR Bus RX Crossbar Rev. 1.4 205

C8051F020/1/2/3 20.1. UART0 Operational Modes UART0 provides four operating modes (one synchronous and three asynchronous) selected by setting configuration bits in the SCON0 register. These four modes offer different baud rates and communication protocols. The four modes are summarized in Table 20.1. Table 20.1. UART0 Modes Mode Synchronization Baud Clock Data Bits Start/Stop Bits 0 Synchronous SYSCLK / 12 8 None 1 Asynchronous Timer 1 or 2 Overflow 8 1 Start, 1 Stop 2 Asynchronous SYSCLK / 32 or SYSCLK / 64 9 1 Start, 1 Stop 3 Asynchronous Timer 1 or 2 Overflow 9 1 Start, 1 Stop 20.1.1. Mode 0: Synchronous Mode Mode 0 provides synchronous, half-duplex communication. Serial data is transmitted and received on the RX0 pin. The TX0 pin provides the shift clock for both transmit and receive. The MCU must be the master since it generates the shift clock for transmission in both directions (see the interconnect diagram in Figure 20.2). Data transmission begins when an instruction writes a data byte to the SBUF0 register. Eight data bits are transferred LSB first (see the timing diagram in Figure 20.3), and the TI0 Transmit Interrupt Flag (SCON0.1) is set at the end of the eighth bit time. Data reception begins when the REN0 Receive Enable bit (SCON0.4) is set to logic 1 and the RI0 Receive Interrupt Flag (SCON0.0) is cleared. One cycle after the eighth bit is shifted in, the RI0 flag is set and recep- tion stops until software clears the RI0 bit. An interrupt will occur if enabled when either TI0 or RI0 are set. The Mode 0 baud rate is SYSCLK / 12. RX0 is forced to open-drain in Mode 0, and an external pull-up will typically be required. Figure 20.2. UART0 Mode 0 Interconnect TX CLK Shift C8051Fxxx Reg. RX DATA 8 Extra Outputs Figure 20.3. UART0 Mode 0 Timing Diagram MODE 0 TRANSMIT RX (data out) D0 D1 D2 D3 D4 D5 D6 D7 TX (clk out) MODE 0 RECEIVE RX (data in) D0 D1 D2 D3 D4 D5 D6 D7 TX (clk out) 206 Rev. 1.4

C8051F020/1/2/3 20.1.2. Mode 1: 8-Bit UART, Variable Baud Rate Mode 1 provides standard asynchronous, full duplex communication using a total of 10 bits per data byte: one start bit, eight data bits (LSB first), and one stop bit. Data are transmitted from the TX0 pin and received at the RX0 pin. On receive, the eight data bits are stored in SBUF0 and the stop bit goes into RB80 (SCON0.2). Data transmission begins when an instruction writes a data byte to the SBUF0 register. The TI0 Transmit Interrupt Flag (SCON0.1) is set at the end of the transmission (the beginning of the stop-bit time). Data reception can begin any time after the REN0 Receive Enable bit (SCON0.4) is set to logic 1. After the stop bit is received, the data byte will be loaded into the SBUF0 receive register if the following conditions are met: RI0 must be logic 0, and if SM20 is logic 1, the stop bit must be logic 1. If these conditions are met, the eight bits of data are stored in SBUF0, the stop bit is stored in RB80 and the RI0 flag is set. If these conditions are not met, SBUF0 and RB80 will not be loaded and the RI0 flag will not be set. An inter- rupt will occur if enabled when either TI0 or RI0 is set. Figure 20.4. UART0 Mode 1 Timing Diagram MARK START BIT D0 D1 D2 D3 D4 D5 D6 D7 STOP SPACE BIT BIT TIMES BIT SAMPLING The baud rate generated in Mode 1 is a function of timer overflow, shown in Equation 20.1 and Equation 20.2. UART0 can use Timer 1 operating in 8-Bit Auto-Reload Mode, or Timer 2 operating in Baud Rate Generator Mode to generate the baud rate (note that the TX and RX clocks are selected separately). On each timer overflow event (a roll- over from all ones - (0xFF for Timer 1, 0xFFFF for Timer 2) - to zero) a clock is sent to the baud rate logic. Timer 2 is selected as TX and/or RX baud clock source by setting the TCLK0 (T2CON.4) and/or RCLK0 (T2CON.5) bits, respectively (see Section “22. TIMERS” on page 225 for complete timer configuration details). When either TCLK0 or RCLK0 is set to logic 1, Timer 2 is forced into Baud Rate Generator Mode, with SYSCLK / 2 as its clock source. If TCLK0 and/or RCLK0 is logic 0, Timer 1 acts as the baud clock source for the TX and/or RX circuits, respectively. The Mode 1 baud rate equations are shown below, where T1M is the Timer 1 Clock Select bit (register CKCON), TH1 is the 8-bit reload register for Timer 1, SMOD0 is the UART0 baud rate doubler (register PCON) and [RCAP2H , RCAP2L] is the 16-bit reload register for Timer 2. Equation 20.1. Mode 1 Baud Rate using Timer 1 BaudRate = 2----S--M----O----D---0-- × S----Y----S---C----L----K-----×-----1---2----(-T---1---M----–----1---)--)  32   (256–TH1)  Equation 20.2. Mode 1 Baud Rate using Timer 2 SYSCLK BaudRate = --------------------------------------------------------------------------------------------- 32× (65536–[RCAP2H,RCAP2L]) Rev. 1.4 207

C8051F020/1/2/3 20.1.3. Mode 2: 9-Bit UART, Fixed Baud Rate Mode 2 provides asynchronous, full-duplex communication using a total of eleven bits per data byte: a start bit, 8 data bits (LSB first), a programmable ninth data bit, and a stop bit. Mode 2 supports multiprocessor communications and hardware address recognition (see Section “20.2. Multiprocessor Communications” on page 210). On transmit, the ninth data bit is determined by the value in TB80 (SCON0.3). It can be assigned the value of the parity flag P in the PSW or used in multiprocessor communications. On receive, the ninth data bit goes into RB80 (SCON0.2) and the stop bit is ignored. Data transmission begins when an instruction writes a data byte to the SBUF0 register. The TI0 Transmit Interrupt Flag (SCON0.1) is set at the end of the transmission (the beginning of the stop-bit time). Data reception can begin any time after the REN0 Receive Enable bit (SCON0.4) is set to logic 1. After the stop bit is received, the data byte will be loaded into the SBUF0 receive register if RI0 is logic 0 and one of the following requirements are met: 1. SM20 is logic 0 2. SM20 is logic 1, the received 9th bit is logic 1, and the received address matches the UART0 address as described in Section 20.2. If the above conditions are satisfied, the eight bits of data are stored in SBUF0, the ninth bit is stored in RB80 and the RI0 flag is set. If these conditions are not met, SBUF0 and RB80 will not be loaded and the RI0 flag will not be set. An interrupt will occur if enabled when either TI0 or RI0 is set. The baud rate in Mode 2 is either SYSCLK / 32 or SYSCLK / 64, depending on the value of the SMOD0 bit in regis- ter PCON. Equation 20.3. Mode 2 Baud Rate BaudRate = 2SMOD0 ×S----Y----S---C----L----K---  64  Figure 20.5. UART Modes 2 and 3 Timing Diagram MARK START BIT D0 D1 D2 D3 D4 D5 D6 D7 D8 STOP SPACE BIT BIT TIMES BIT SAMPLING 208 Rev. 1.4

C8051F020/1/2/3 Figure 20.6. UART Modes 1, 2, and 3 Interconnect Diagram TX RS-232 RS-232 LEVEL RX C8051Fxxx XLTR OR TX TX MCU C8051Fxxx RX RX 20.1.4. Mode 3: 9-Bit UART, Variable Baud Rate Mode 3 uses the Mode 2 transmission protocol with the Mode 1 baud rate generation. Mode 3 operation transmits 11 bits: a start bit, 8 data bits (LSB first), a programmable ninth data bit, and a stop bit. The baud rate is derived from Timer 1 or Timer 2 overflows, as defined by Equation 20.1 and Equation 20.2. Multiprocessor communications and hardware address recognition are supported, as described in Section 20.2. Rev. 1.4 209

C8051F020/1/2/3 20.2. Multiprocessor Communications Modes 2 and 3 support multiprocessor communication between a master processor and one or more slave processors by special use of the ninth data bit and the built-in UART0 address recognition hardware. A master processor begins a transfer with an address byte to select one or more target slave devices. An address byte differs from a data byte in that its ninth bit is logic 1; in a data byte, the ninth bit is always set to logic 0. The UART0 address is configured via two SFRs: SADDR0 (Serial Address) and SADEN0 (Serial Address Enable). SADEN0 sets the bit mask for the address held in SADDR0: bits set to logic 1 in SADEN0 correspond to bits in SADDR0 that are checked against the received address byte; bits set to logic 0 in SADEN0 correspond to “don’t care” bits in SADDR0. Example 1 Example 2 Example 3 SADDR0 = 00110101 SADDR0 = 00110101 SADDR0 = 00110101 SADEN0 = 00001111 SADEN0 = 11110011 SADEN0 = 11000000 UART0 Address = xxxx0101 UART0 Address = 0011xx01 UART0 Address = 00xxxxxx Setting the SM20 bit (SCON0.5) configures UART0 such that when a stop bit is received, UART0 will generate an interrupt only if the ninth bit is logic 1 (RB80 = 1) and the received data byte matches the UART0 slave address. Fol- lowing the received address interrupt, the slave should clear its SM20 bit to enable interrupts on the reception of the following data byte(s). Once the entire message is received, the addressed slave should reset its SM20 bit to ignore all transmissions until it receives the next address byte. While SM20 is logic 1, UART0 ignores all bytes that do not match the UART0 address and include a ninth bit that is logic 1. Multiple addresses can be assigned to a single slave and/or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. The broadcast address is the logi- cal OR of registers SADDR0 and SADEN0, and ‘0’s of the result are treated as “don’t cares”. Typically a broadcast address of 0xFF (hexadecimal) is acknowledged by all slaves, assuming “don’t care” bits as ‘1’s. The master proces- sor can be configured to receive all transmissions or a protocol can be implemented such that the master/slave role is temporarily reversed to enable half-duplex transmission between the original master and slave(s). Figure 20.7. UART Multi-Processor Mode Interconnect Diagram Master Slave Slave Slave Device Device Device Device +5V RX TX RX TX RX TX RX TX 210 Rev. 1.4

C8051F020/1/2/3 20.3. Frame and Transmission Error Detection Frame error detection is available in the following modes when the SSTAT0 bit in register PCON is set to logic 1. Note: The SSTAT0 bit must be logic 1 to access any of the status bits (FE0, RXOVR0, and TXCOL0). To access the UART0 Mode Select bits (SM00, SM10, and SM20), the SSTAT0 bit must be logic 0. All Modes: The Transmit Collision bit (TXCOL0 bit in register SCON0) reads ‘1’ if user software writes data to the SBUF0 reg- ister while a transmit is in progress. Note that the TXCOL0 bit also functions as the SM20 bit when the SSTAT0 bit in register PCON is logic 0. Modes 1, 2, and 3: The Receive Overrun bit (RXOVR0 in register SCON0) reads ‘1’ if a new data byte is latched into the receive buffer before software has read the previous byte. Note that the RXOVR0 bit also functions as the SM10 bit when the SSTAT0 bit in register PCON is logic 0. The Frame Error bit (FE0 in register SCON0) reads ‘1’ if an invalid (low) STOP bit is detected. Note that the FE0 bit also functions as the SM00 bit when the SSTAT0 bit in register PCON is logic 0. Rev. 1.4 211

C8051F020/1/2/3 Table 20.2. Oscillator Frequencies for Standard Baud Rates Oscillator frequency (MHz) Divide Factor Timer 1 Load Value* Resulting Baud Rate (Hz)** 25.0 434 0xE5 57600 (57870) 25.0 868 0xCA 28800 24.576 320 0xEC 76800 24.576 848 0xCB 28800 (28921) 24.0 208 0XF3 115200 (115384) 24.0 833 0xCC 28800 (28846) 23.592 205 0xF3 115200 (113423) 23.592 819 0xCD 28800 (28911) 22.1184 192 0xF4 115200 22.1184 768 0xD0 28800 18.432 160 0xF6 115200 18.432 640 0xD8 28800 16.5888 144 0xF7 115200 16.5888 576 0xDC 28800 14.7456 128 0xF8 115200 14.7456 512 0xE0 28800 12.9024 112 0xF9 115200 12.9024 448 0xE4 28800 11.0592 96 0xFA 115200 11.0592 348 0xE8 28800 9.216 80 0xFB 115200 9.216 320 0xEC 28800 7.3728 64 0xFC 115200 7.3728 256 0xF0 28800 5.5296 48 0xFD 115200 5.5296 192 0xF4 28800 3.6864 32 0xFE 115200 3.6864 128 0xF8 28800 1.8432 16 0xFF 115200 1.8432 64 0xFC 28800 * Assumes SMOD0=1 and T1M=1. ** Numbers in parenthesis show the actual baud rate. 212 Rev. 1.4

C8051F020/1/2/3 Figure 20.8. SCON0: UART0 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SM00/FE0 SM10/RXOV0 SM20/TXCOL0 REN0 TB80 RB80 TI0 RI0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x98 Bits7-6: The function of these bits is determined by the SSTAT0 bit in register PCON. If SSTAT0 is logic 1, these bits are UART0 status indicators as described in Section 20.3. If SSTAT0 is logic 0, these bits select the Serial Port Operation Mode as shown below. SM00-SM10: Serial Port Operation Mode: SM00 SM10 Mode 0 0 Mode 0: Synchronous Mode 0 1 Mode 1: 8-Bit UART, Variable Baud Rate 1 0 Mode 2: 9-Bit UART, Fixed Baud Rate 1 1 Mode 3: 9-Bit UART, Variable Baud Rate Bit5: SM20: Multiprocessor Communication Enable. If SSTAT0 is logic 1, this bit is a UART0 status indicator as described in Section 20.3. If SSTAT0 is logic 0, the function of this bit is dependent on the Serial Port Operation Mode. Mode 0: No effect. Mode 1: Checks for valid stop bit. 0: Logic level of stop bit is ignored. 1: RI0 will only be activated if stop bit is logic level 1. Modes 2 and 3: Multiprocessor Communications Enable. 0: Logic level of ninth bit is ignored. 1: RI0 is set and an interrupt is generated only when the ninth bit is logic 1 and the received address matches the UART0 address or the broadcast address. Bit4: REN0: Receive Enable. This bit enables/disables the UART0 receiver. 0: UART0 reception disabled. 1: UART0 reception enabled. Bit3: TB80: Ninth Transmission Bit. The logic level of this bit will be assigned to the ninth transmission bit in Modes 2 and 3. It is not used in Modes 0 and 1. Set or cleared by software as required. Bit2: RB80: Ninth Receive Bit. The bit is assigned the logic level of the ninth bit received in Modes 2 and 3. In Mode 1, if SM20 is logic 0, RB80 is assigned the logic level of the received stop bit. RB8 is not used in Mode 0. Bit1: TI0: Transmit Interrupt Flag. Set by hardware when a byte of data has been transmitted by UART0 (after the 8th bit in Mode 0, or at the beginning of the stop bit in other modes). When the UART0 interrupt is enabled, setting this bit causes the CPU to vector to the UART0 interrupt service routine. This bit must be cleared manually by software Bit0: RI0: Receive Interrupt Flag. Set by hardware when a byte of data has been received by UART0 (as selected by the SM20 bit). When the UART0 interrupt is enabled, setting this bit causes the CPU to vector to the UART0 inter- rupt service routine. This bit must be cleared manually by software. Rev. 1.4 213

C8051F020/1/2/3 Figure 20.9. SBUF0: UART0 Data Buffer Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x99 Bits7-0: SBUF0.[7:0]: UART0 Buffer Bits 7-0 (MSB-LSB) This SFR accesses two registers; a transmit shift register and a receive latch register. When data is written to SBUF0, it goes to the transmit shift register and is held for serial transmission. Writing a byte to SBUF0 is what initiates the transmission. A read of SBUF0 returns the contents of the receive latch. Figure 20.10. SADDR0: UART0 Slave Address Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xA9 Bits7-0: SADDR0.[7:0]: UART0 Slave Address The contents of this register are used to define the UART0 slave address. Register SADEN0 is a bit mask to determine which bits of SADDR0 are checked against a received address: corresponding bits set to logic 1 in SADEN0 are checked; corresponding bits set to logic 0 are “don’t cares”. Figure 20.11. SADEN0: UART0 Slave Address Enable Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xB9 Bits7-0: SADEN0.[7:0]: UART0 Slave Address Enable Bits in this register enable corresponding bits in register SADDR0 to determine the UART0 slave address. 0: Corresponding bit in SADDR0 is a “don’t care”. 1: Corresponding bit in SADDR0 is checked against a received address. 214 Rev. 1.4

C8051F020/1/2/3 21. UART1 UART1 is an enhanced serial port with frame error detection and address recognition hardware. UART1 may operate in full-duplex asynchronous or half-duplex synchronous modes, and mutiproccessor communication is fully sup- ported. Receive data is buffered in a holding register, allowing UART1 to start reception of a second incoming data byte before software has finished reading the previous data byte. A Receive Overrun bit indicates when new received data is latched into the receive buffer before the previous received byte is read. UART1 is accessed via its associated SFRs, Serial Control (SCON1) and Serial Data Buffer (SBUF1). The single SBUF1 location provides access to both transmit and receive registers. Reads access the Receive register and writes access the Transmit register automatically. UART1 may be operated in polled or interrupt mode. UART1 has two sources of interrupts: a Transmit Interrupt flag, TI1 (SCON1.1) set when transmission of a data byte is complete, and a Receive Interrupt flag, RI1 (SCON1.0) set when reception of a data byte is complete. UART1 interrupt flags are not cleared by hardware when the CPU vectors to the interrupt service routine; they must be cleared manually by software. This allows software to determine the cause of the UART1 interrupt (transmit complete or receive complete). Figure 21.1. UART1 Block Diagram SFR Bus Write to SBUF TB8 SET SBUF D Q (Transmit Shift) TX CLR Crossbar Zero Detector StGoepn B.it Shift Data Start Tx Control Tx Clock Send Tx IRQ UART SCON TI Baud Rate S S S R T R T R Serial Port Generation M0 M1 M2 NE B8 B8 I I (UInAteRrTru0p/1t) Logic RI EN Rx IRQ Rx Clock Load SBUF Rx Control Address Start Match Port I/O Shift 0x1FF Frame Error Input Shift Register Detection (9 bits) Load SBUF RB8 SADDR SBUF Match Detect (Receive Latch) SADEN Read SBUF SFR Bus RX Crossbar Rev. 1.4 215

C8051F020/1/2/3 21.1. UART1 Operational Modes UART1 provides four operating modes (one synchronous and three asynchronous) selected by setting configuration bits in the SCON1 register. These four modes offer different baud rates and communication protocols. The four modes are summarized in Table 21.1. Table 21.1. UART1 Modes Mode Synchronization Baud Clock Data Bits Start/Stop Bits 0 Synchronous SYSCLK / 12 8 None 1 Asynchronous Timer 1 or 4 Overflow 8 1 Start, 1 Stop 2 Asynchronous SYSCLK / 32 or SYSCLK / 64 9 1 Start, 1 Stop 3 Asynchronous Timer 1 or 4 Overflow 9 1 Start, 1 Stop 21.1.1. Mode 0: Synchronous Mode Mode 0 provides synchronous, half-duplex communication. Serial data is transmitted and received on the RX1 pin. The TX1 pin provides the shift clock for both transmit and receive. The MCU must be the master since it generates the shift clock for transmission in both directions (see the interconnect diagram in Figure 21.2). Data transmission begins when an instruction writes a data byte to the SBUF1 register. Eight data bits are transferred LSB first (see the timing diagram in Figure 21.3), and the TI1 Transmit Interrupt Flag (SCON1.1) is set at the end of the eighth bit time. Data reception begins when the REN1 Receive Enable bit (SCON1.4) is set to logic 1 and the RI1 Receive Interrupt Flag (SCON1.0) is cleared. One cycle after the eighth bit is shifted in, the RI1 flag is set and recep- tion stops until software clears the RI1 bit. An interrupt will occur if enabled when either TI1 or RI1 are set. The Mode 0 baud rate is SYSCLK / 12. RX1 is forced to open-drain in Mode 0, and an external pull-up will typically be required. Figure 21.2. UART1 Mode 0 Interconnect TX CLK Shift C8051Fxxx Reg. RX DATA 8 Extra Outputs Figure 21.3. UART1 Mode 0 Timing Diagram MODE 0 TRANSMIT RX (data out) D0 D1 D2 D3 D4 D5 D6 D7 TX (clk out) MODE 0 RECEIVE RX (data in) D0 D1 D2 D3 D4 D5 D6 D7 TX (clk out) 216 Rev. 1.4

C8051F020/1/2/3 21.1.2. Mode 1: 8-Bit UART, Variable Baud Rate Mode 1 provides standard asynchronous, full duplex communication using a total of 10 bits per data byte: one start bit, eight data bits (LSB first), and one stop bit. Data are transmitted from the TX1 pin and received at the RX1 pin. On receive, the eight data bits are stored in SBUF1 and the stop bit goes into RB81 (SCON1.2). Data transmission begins when an instruction writes a data byte to the SBUF1 register. The TI1 Transmit Interrupt Flag (SCON1.1) is set at the end of the transmission (the beginning of the stop-bit time). Data reception can begin any time after the REN1 Receive Enable bit (SCON1.4) is set to logic 1. After the stop bit is received, the data byte will be loaded into the SBUF1 receive register if the following conditions are met: RI1 must be logic 0, and if SM21 is logic 1, the stop bit must be logic 1. If these conditions are met, the eight bits of data are stored in SBUF1, the stop bit is stored in RB81 and the RI1 flag is set. If these conditions are not met, SBUF1 and RB81 will not be loaded and the RI1 flag will not be set. An inter- rupt will occur if enabled when either TI1 or RI1 is set. Figure 21.4. UART1 Mode 1 Timing Diagram MARK START BIT D0 D1 D2 D3 D4 D5 D6 D7 STOP SPACE BIT BIT TIMES BIT SAMPLING The baud rate generated in Mode 1 is a function of timer overflow, shown in Equation 21.1 and Equation 21.2. UART1 can use Timer 1 operating in 8-Bit Auto-Reload Mode, or Timer 4 operating in Baud Rate Generator Mode to generate the baud rate (note that the TX and RX clocks are selected separately). On each timer overflow event (a roll- over from all ones - (0xFF for Timer 1, 0xFFFF for Timer 4) - to zero) a clock is sent to the baud rate logic. Timer 4 is selected as TX and/or RX baud clock source by setting the TCLK1 (T4CON.4) and/or RCLK1 (T4CON.5) bits, respectively (see Section “22. TIMERS” on page 225 for complete timer configuration details). When either TCLK1 or RCLK1 is set to logic 1, Timer 4 is forced into Baud Rate Generator Mode, with SYSCLK / 2 as its clock source. If TCLK1 and/or RCLK1 is logic 0, Timer 1 acts as the baud clock source for the TX and/or RX circuits, respectively. The Mode 1 baud rate equations are shown below, where T1M is the Timer 1 Clock Select bit (register CKCON), TH1 is the 8-bit reload register for Timer 1, SMOD1 is the UART1 baud rate doubler (register PCON), and [RCAP4H , RCAP4L] is the 16-bit reload register for Timer 4. Equation 21.1. Mode 1 Baud Rate using Timer 1 BaudRate = 2----S--M----O----D---1-- × S----Y----S---C----L----K-----×-----1---2----(-T---1---M----–----1---)--)  32   (256–TH1)  Equation 21.2. Mode 1 Baud Rate using Timer 4 SYSCLK BaudRate = -------------------------------------------------------------------------------------------------- [32× (65536–[RCAP4H,RCAP4L])] Rev. 1.4 217

C8051F020/1/2/3 21.1.3. Mode 2: 9-Bit UART, Fixed Baud Rate Mode 2 provides asynchronous, full-duplex communication using a total of eleven bits per data byte: a start bit, 8 data bits (LSB first), a programmable ninth data bit, and a stop bit. Mode 2 supports multiprocessor communications and hardware address recognition (see Section “21.2. Multiprocessor Communications” on page 220). On transmit, the ninth data bit is determined by the value in TB81 (SCON1.3). It can be assigned the value of the parity flag P in the PSW or used in multiprocessor communications. On receive, the ninth data bit goes into RB81 (SCON1.2) and the stop bit is ignored. Data transmission begins when an instruction writes a data byte to the SBUF1 register. The TI1 Transmit Interrupt Flag (SCON1.1) is set at the end of the transmission (the beginning of the stop-bit time). Data reception can begin any time after the REN1 Receive Enable bit (SCON1.4) is set to logic 1. After the stop bit is received, the data byte will be loaded into the SBUF1 receive register if RI1 is logic 0 and one of the following requirements are met: 1. SM21 is logic 0 2. SM21 is logic 1, the received 9th bit is logic 1, and the received address matches the UART1 address as described in Section 21.2. If the above conditions are satisfied, the eight bits of data are stored in SBUF1, the ninth bit is stored in RB81 and the RI1 flag is set. If these conditions are not met, SBUF1 and RB81 will not be loaded and the RI1 flag will not be set. An interrupt will occur if enabled when either TI1 or RI1 is set. The baud rate in Mode 2 is either SYSCLK / 32 or SYSCLK / 64, depending on the value of the SMOD1 bit in regis- ter PCON. Equation 21.3. Mode 2 Baud Rate BaudRate = 2SMOD1 ×S----Y----S---C----L----K---  64  Figure 21.5. UART Modes 2 and 3 Timing Diagram MARK START BIT D0 D1 D2 D3 D4 D5 D6 D7 D8 STOP SPACE BIT BIT TIMES BIT SAMPLING 218 Rev. 1.4

C8051F020/1/2/3 Figure 21.6. UART Modes 1, 2, and 3 Interconnect Diagram TX RS-232 RS-232 LEVEL RX C8051Fxxx XLTR OR TX TX MCU C8051Fxxx RX RX 21.1.4. Mode 3: 9-Bit UART, Variable Baud Rate Mode 3 uses the Mode 2 transmission protocol with the Mode 1 baud rate generation. Mode 3 operation transmits 11 bits: a start bit, 8 data bits (LSB first), a programmable ninth data bit, and a stop bit. The baud rate is derived from Timer 1 or Timer 4 overflows, as defined by Equation 21.1 and Equation 21.2. Multiprocessor communications and hardware address recognition are supported, as described in Section 21.2. Rev. 1.4 219

C8051F020/1/2/3 21.2. Multiprocessor Communications Modes 2 and 3 support multiprocessor communication between a master processor and one or more slave processors by special use of the ninth data bit and the built-in UART1 address recognition hardware. A master processor begins a transfer with an address byte to select one or more target slave devices. An address byte differs from a data byte in that its ninth bit is logic 1; in a data byte, the ninth bit is always set to logic 0. The UART1 address is configured via two SFRs: SADDR1 (Serial Address) and SADEN1 (Serial Address Enable). SADEN1 sets the bit mask for the address held in SADDR1: bits set to logic 1 in SADEN1 correspond to bits in SADDR1 that are checked against the received address byte; bits set to logic 0 in SADEN1 correspond to “don’t care” bits in SADDR1. Example 1 Example 2 Example 3 SADDR1 = 00110101 SADDR1 = 00110101 SADDR1 = 00110101 SADEN1 = 00001111 SADEN1 = 11110011 SADEN1 = 11000000 UART1 Address = xxxx0101 UART1 Address = 0011xx01 UART1 Address = 00xxxxxx Setting the SM21 bit (SCON1.5) configures UART1 such that when a stop bit is received, UART1 will generate an interrupt only if the ninth bit is logic 1 (RB81 = 1) and the received data byte matches the UART1 slave address. Fol- lowing the received address interrupt, the slave should clear its SM21 bit to enable interrupts on the reception of the following data byte(s). Once the entire message is received, the addressed slave should reset its SM21 bit to ignore all transmissions until it receives the next address byte. While SM21 is logic 1, UART1 ignores all bytes that do not match the UART1 address and include a ninth bit that is logic 1. Multiple addresses can be assigned to a single slave and/or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. The broadcast address is the logi- cal OR of registers SADDR1 and SADEN1, and ‘0’s of the result are treated as “don’t cares”. Typically a broadcast address of 0xFF (hexadecimal) is acknowledged by all slaves, assuming “don’t care” bits as ‘1’s. The master proces- sor can be configured to receive all transmissions or a protocol can be implemented such that the master/slave role is temporarily reversed to enable half-duplex transmission between the original master and slave(s). Figure 21.7. UART Multi-Processor Mode Interconnect Diagram Master Slave Slave Slave Device Device Device Device +5V RX TX RX TX RX TX RX TX 220 Rev. 1.4

C8051F020/1/2/3 21.3. Frame and Transmission Error Detection Frame error detection is available in the following modes when the SSTAT1 bit in register PCON is set to logic 1. Note: The SSTAT1 bit must be logic 1 to access any of the status bits (FE1, RXOVR1, and TXCOL1). To access the UART1 Mode Select bits (SM01, SM11, and SM21), the SSTAT1 bit must be logic 0. All Modes: The Transmit Collision bit (TXCOL1 bit in register SCON1) reads ‘1’ if user software writes data to the SBUF1 reg- ister while a transmit is in progress. Note that the TXCOL1 bit also functions as the SM21 bit when the SSTAT1 bit in register PCON is logic 0. Modes 1, 2, and 3: The Receive Overrun bit (RXOVR1 in register SCON1) reads ‘1’ if a new data byte is latched into the receive buffer before software has read the previous byte. Note that the RXOVR1 bit also functions as the SM11 bit when the SSTAT1 bit in register PCON is logic 0. The Frame Error bit (FE1 in register SCON1) reads ‘1’ if an invalid (low) STOP bit is detected. Note that the FE1 bit also functions as the SM01 bit when the SSTAT1 bit in register PCON is logic 0. Rev. 1.4 221

C8051F020/1/2/3 Table 21.2. Oscillator Frequencies for Standard Baud Rates Oscillator frequency (MHz) Divide Factor Timer 1 Load Value* Resulting Baud Rate (Hz)** 25.0 434 0xE5 57600 (57870) 25.0 868 0xCA 28800 24.576 320 0xEC 76800 24.576 848 0xCB 28800 (28921) 24.0 208 0XF3 115200 (115384) 24.0 833 0xCC 28800 (28846) 23.592 205 0xF3 115200 (113423) 23.592 819 0xCD 28800 (28911) 22.1184 192 0xF4 115200 22.1184 768 0xD0 28800 18.432 160 0xF6 115200 18.432 640 0xD8 28800 16.5888 144 0xF7 115200 16.5888 576 0xDC 28800 14.7456 128 0xF8 115200 14.7456 512 0xE0 28800 12.9024 112 0xF9 115200 12.9024 448 0xE4 28800 11.0592 96 0xFA 115200 11.0592 348 0xE8 28800 9.216 80 0xFB 115200 9.216 320 0xEC 28800 7.3728 64 0xFC 115200 7.3728 256 0xF0 28800 5.5296 48 0xFD 115200 5.5296 192 0xF4 28800 3.6864 32 0xFE 115200 3.6864 128 0xF8 28800 1.8432 16 0xFF 115200 1.8432 64 0xFC 28800 * Assumes SMOD1=1 and T1M=1. ** Numbers in parenthesis show the actual baud rate. 222 Rev. 1.4

C8051F020/1/2/3 Figure 21.8. SCON1: UART1 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value SM01/FE1 SM11/RXOV1 SM21/TXCOL1 REN1 TB81 RB81 TI1 RI1 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF1 Bits7-6: The function of these bits is determined by the SSTAT1 bit in register PCON. If SSTAT1 is logic 1, these bits are UART1 status indicators as described in Section 21.3. If SSTAT1 is logic 0, these bits select the Serial Port Operation Mode as shown below. SM01-SM11: Serial Port Operation Mode: SM01 SM11 Mode 0 0 Mode 0: Synchronous Mode 0 1 Mode 1: 8-Bit UART, Variable Baud Rate 1 0 Mode 2: 9-Bit UART, Fixed Baud Rate 1 1 Mode 3: 9-Bit UART, Variable Baud Rate Bit5: SM21: Multiprocessor Communication Enable. If SSTAT1 is logic 1, this bit is a UART1 status indicator as described in Section 21.3. If SSTAT1 is logic 0, the function of this bit is dependent on the Serial Port Operation Mode. Mode 0: No effect. Mode 1: Checks for valid stop bit. 0: Logic level of stop bit is ignored. 1: RI1 will only be activated if stop bit is logic level 1. Modes 2 and 3: Multiprocessor Communications Enable. 0: Logic level of ninth bit is ignored. 1: RI1 is set and an interrupt is generated only when the ninth bit is logic 1 and the received address matches the UART1 address or the broadcast address. Bit4: REN1: Receive Enable. This bit enables/disables the UART1 receiver. 0: UART1 reception disabled. 1: UART1 reception enabled. Bit3: TB81: Ninth Transmission Bit. The logic level of this bit will be assigned to the ninth transmission bit in Modes 2 and 3. It is not used in Modes 0 and 1. Set or cleared by software as required. Bit2: RB81: Ninth Receive Bit. The bit is assigned the logic level of the ninth bit received in Modes 2 and 3. In Mode 1, if SM21 is logic 0, RB81 is assigned the logic level of the received stop bit. RB8 is not used in Mode 0. Bit1: TI1: Transmit Interrupt Flag. Set by hardware when a byte of data has been transmitted by UART1 (after the 8th bit in Mode 0, or at the beginning of the stop bit in other modes). When the UART1 interrupt is enabled, setting this bit causes the CPU to vector to the UART1 interrupt service routine. This bit must be cleared manually by software Bit0: RI1: Receive Interrupt Flag. Set by hardware when a byte of data has been received by UART1 (as selected by the SM21 bit). When the UART1 interrupt is enabled, setting this bit causes the CPU to vector to the UART1 inter- rupt service routine. This bit must be cleared manually by software. Rev. 1.4 223

C8051F020/1/2/3 Figure 21.9. SBUF1: UART1 Data Buffer Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF2 Bits7-0: SBUF1.[7:0]: UART1 Buffer Bits 7-0 (MSB-LSB) This SFR accesses two registers; a transmit shift register and a receive latch register. When data is written to SBUF1, it goes to the transmit shift register and is held for serial transmission. Writing a byte to SBUF1 is what initiates the transmission. A read of SBUF1 returns the contents of the receive latch. Figure 21.10. SADDR1: UART1 Slave Address Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF3 Bits7-0: SADDR1.[7:0]: UART1 Slave Address The contents of this register are used to define the UART1 slave address. Register SADEN1 is a bit mask to determine which bits of SADDR1 are checked against a received address: corresponding bits set to logic 1 in SADEN1 are checked; corresponding bits set to logic 0 are “don’t cares”. Figure 21.11. SADEN1: UART1 Slave Address Enable Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xAE Bits7-0: SADEN1.[7:0]: UART1 Slave Address Enable Bits in this register enable corresponding bits in register SADDR1 to determine the UART1 slave address. 0: Corresponding bit in SADDR1 is a “don’t care”. 1: Corresponding bit in SADDR1 is checked against a received address. 224 Rev. 1.4

C8051F020/1/2/3 22. TIMERS The C8051F020/1/2/3 devices contain 5 counter/timers: three are 16-bit counter/timers compatible with those found in the standard 8051, and two are 16-bit auto-reload timers for use with the ADCs, SMBus, UART1, or for general purpose use. These can be used to measure time intervals, count external events and generate periodic interrupt requests. Timer 0 and Timer 1 are nearly identical and have four primary modes of operation. Timer 2 offers addi- tional capabilities not available in Timers 0 and 1. Timer 3 is similar to Timer 2, but without the capture or Baud Rate Generator modes. Timer 4 is identical to Timer 2, and can supply baud-rate generation capabilities to UART1. Timer 0 and Timer 1: Timer 2: Timer 3: Timer 4 16-bit counter/timer with 16-bit timer with auto- 16-bit counter/timer with 13-bit counter/timer auto-reload reload auto-reload 16-bit counter/timer with 16-bit counter/timer with 16-bit counter/timer capture capture 8-bit counter/timer with Baud rate generator for Baud rate generator for auto-reload UART0 UART1 Two 8-bit counter/timers (Timer 0 only) When functioning as a timer, the counter/timer registers are incremented on each clock tick. Clock ticks are derived from the system clock divided by either one or twelve as specified by the Timer Clock Select bits (T4M-T0M) in CKCON, shown in Figure 22.1. The twelve-clocks-per-tick option provides compatibility with the older generation of the 8051 family. Applications that require a faster timer can use the one-clock-per-tick option. When functioning as a counter, a counter/timer register is incremented on each high-to-low transition at the selected input pin. Events with a frequency of up to one-fourth the system clock's frequency can be counted. The input signal need not be periodic, but it should be held at a given level for at least two full system clock cycles to ensure the level is sampled. Rev. 1.4 225

C8051F020/1/2/3 Figure 22.1. CKCON: Clock Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value - T4M T2M T1M T0M Reserved Reserved Reserved 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8E Bit7: UNUSED. Read = 0b, Write = don’t care. Bit6: T4M: Timer 4 Clock Select. This bit controls the division of the system clock supplied to Timer 4. This bit is ignored when the timer is in baud rate generator mode or counter mode (i.e. C/T4 = 1). 0: Timer 4 uses the system clock divided by 12. 1: Timer 4 uses the system clock. Bit5: T2M: Timer 2 Clock Select. This bit controls the division of the system clock supplied to Timer 2. This bit is ignored when the timer is in baud rate generator mode or counter mode (i.e. C/T2 = 1). 0: Timer 2 uses the system clock divided by 12. 1: Timer 2 uses the system clock. Bit4: T1M: Timer 1 Clock Select. This bit controls the division of the system clock supplied to Timer 1. 0: Timer 1 uses the system clock divided by 12. 1: Timer 1 uses the system clock. Bit3: T0M: Timer 0 Clock Select. This bit controls the division of the system clock supplied to Counter/Timer 0. 0: Counter/Timer uses the system clock divided by 12. 1: Counter/Timer uses the system clock. Bits2-0: Reserved. Read = 000b, Must Write = 000. 226 Rev. 1.4

C8051F020/1/2/3 22.1. Timer 0 and Timer 1 Timer 0 and Timer 1 are accessed and controlled through SFRs. Each counter/timer is implemented as a 16-bit regis- ter accessed as two separate bytes: a low byte (TL0 or TL1) and a high byte (TH0 or TH1). The Counter/Timer Con- trol (TCON) register is used to enable Timer 0 and Timer 1 as well as indicate their status. Both counter/timers operate in one of four primary modes selected by setting the Mode Select bits M1-M0 in the Counter/Timer Mode (TMOD) register. Each timer can be configured independently. Following is a detailed description of each operating mode. 22.1.1. Mode 0: 13-bit Counter/Timer Timer 0 and Timer 1 operate as a 13-bit counter/timer in Mode 0. The following describes the configuration and oper- ation of Timer 0. However, both timers operate identically and Timer 1 is configured in the same manner as described for Timer 0. The TH0 register holds the eight MSBs of the 13-bit counter/timer. TL0 holds the five LSBs in bit positions TL0.4- TL0.0. The three upper bits of TL0 (TL0.7-TL0.5) are indeterminate and should be masked out or ignored when read- ing. As the 13-bit timer register increments and overflows from 0x1FFF (all ones) to 0x0000, the timer overflow flag TF0 (TCON.5) is set and an interrupt will occur if enabled. The C/T0 bit (TMOD.2) selects the counter/timer's clock source. Clearing C/T selects the system clock as the input for the timer. When C/T0 is set to logic 1, high-to-low transitions at the selected input pin (T0) increment the timer register. (Refer to Section “17.1. Ports 0 through 3 and the Priority Crossbar Decoder” on page 163 for informa- tion on selecting and configuring external I/O pins for digital peripherals.) Setting the TR0 bit (TCON.4) enables the timer when either GATE0 (TMOD.3) is 0 or the input signal /INT0 is logic-level one. Setting GATE0 to logic 1 allows the timer to be controlled by the external input signal /INT0, facili- tating pulse width measurements. TR0 GATE0 /INT0 Counter/Timer 0 X X Disabled 1 0 X Enabled 1 1 0 Disabled 1 1 1 Enabled X = Don't Care Setting TR0 does not reset the timer register. The timer register should be initialized to the desired value before enabling the timer. TL1 and TH1 form the 13-bit register for Timer 1 in the same manner as described above for TL0 and TH0. Timer 1 is configured and controlled using the relevant TCON and TMOD bits just as with Timer 0. Rev. 1.4 227

C8051F020/1/2/3 Figure 22.2. T0 Mode 0 Block Diagram CKCON TMOD TTTT GCT TGCT T 4 2 1 0 A / 1 1 A / 0 0 MMMM T TMMT TMM E 1 1 0 E 0 1 0 1 0 12 0 SYSCLK 0 1 1 TF1 T0 TR1 TCLK TL0 TH0 TF0 Interrupt Crossbar TR0 (5 bits) (8 bits) N IE1 O IT1 /INT0 TR0 C IE0 T IT0 GATE0 22.1.2. Mode 1: 16-bit Counter/Timer Mode 1 operation is the same as Mode 0, except that the counter/timer registers use all 16 bits. The counter/timers are enabled and configured in Mode 1 in the same manner as for Mode 0. 228 Rev. 1.4

C8051F020/1/2/3 22.1.3. Mode 2: 8-bit Counter/Timer with Auto-Reload Mode 2 configures Timer 0 and Timer 1 to operate as 8-bit counter/timers with automatic reload of the start value. The TL0 holds the count and TH0 holds the reload value. When the counter in TL0 overflows from all ones to 0x00, the timer overflow flag TF0 (TCON.5) is set and the counter value in TL0 is reloaded from TH0. If enabled, an inter- rupt will occur when the TF0 flag is set. The reload value in TH0 is not changed. TL0 must be initialized to the desired value before enabling the timer for the first count to be correct. When in Mode 2, Timer 1 operates identically to Timer 0. Both counter/timers are enabled and configured in Mode 2 in the same manner as Mode 0. Figure 22.3. T0 Mode 2 (8-bit Auto-Reload) Block Diagram CKCON TMOD TTTT GCT TGCT T 4 2 1 0 A / 1 1 A / 0 0 MMMM T TMMT TMM E 1 1 0 E 0 1 0 1 0 12 0 SYSCLK 0 1 1 T0 TF1 TCLK TL0 TR1 Crossbar TF0 Interrupt (8 bits) TR0 N IE1 /INT0 TR0 O IT1 C IE0 T IT0 GATE0 TH0 Reload (8 bits) Rev. 1.4 229

C8051F020/1/2/3 22.1.4. Mode 3: Two 8-bit Counter/Timers (Timer 0 Only) Timer 0 and Timer 1 behave differently in Mode 3. Timer 0 is configured as two separate 8-bit counter/timers held in TL0 and TH0. The counter/timer in TL0 is controlled using the Timer 0 control/status bits in TCON and TMOD: TR0, C/T0, GATE0 and TF0. It can use either the system clock or an external input signal as its timebase. The timer in the TH0 register is restricted to a timer function sourced by the system clock. TH0 is enabled using the Timer 1 run control bit TR1. TH0 sets the Timer 1 overflow flag TF1 on overflow and thus controls the Timer 1 interrupt. Timer 1 is inactive in Mode 3, so with Timer 0 in Mode 3, Timer 1 can be turned off and on by switching it into and out of its Mode 3. When Timer 0 is in Mode 3, Timer 1 can be operated in Modes 0, 1 or 2, but cannot be clocked by external signals nor set the TF1 flag and generate an interrupt. However, the Timer 1 overflow can be used to gener- ate the baud clock for UART0 and/or UART1. Refer to Section “20. UART0” on page 205 and Section “21. UART1” on page 215 for information on configuring Timer 1 for baud rate generation. Figure 22.4. T0 Mode 3 (Two 8-bit Timers) Block Diagram CKCON TMOD TTTT GCT TGCT T 4 2 1 0 A / 1 1 A / 0 0 MMMM T TMMT TMM E 1 1 0 E 0 1 0 1 0 12 0 TR1 TH0 SYSCLK (8 bits) TTRF11 Interrupt TF0 Interrupt 1 TR0 0 N IE1 O IT1 C IE0 T IT0 1 T0 TL0 Crossbar (8 bits) /INT0 TR0 GATE0 230 Rev. 1.4

C8051F020/1/2/3 Figure 22.5. TCON: Timer Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0x88 Bit7: TF1: Timer 1 Overflow Flag. Set by hardware when Timer 1 overflows. This flag can be cleared by software but is automatically cleared when the CPU vectors to the Timer 1 interrupt service routine. 0: No Timer 1 overflow detected. 1: Timer 1 has overflowed. Bit6: TR1: Timer 1 Run Control. 0: Timer 1 disabled. 1: Timer 1 enabled. Bit5: TF0: Timer 0 Overflow Flag. Set by hardware when Timer 0 overflows. This flag can be cleared by software but is automatically cleared when the CPU vectors to the Timer 0 interrupt service routine. 0: No Timer 0 overflow detected. 1: Timer 0 has overflowed. Bit4: TR0: Timer 0 Run Control. 0: Timer 0 disabled. 1: Timer 0 enabled. Bit3: IE1: External Interrupt 1. This flag is set by hardware when an edge/level of type defined by IT1 is detected. It can be cleared by software but is automatically cleared when the CPU vectors to the External Interrupt 1 service rou- tine if IT1 = 1. This flag is the inverse of the /INT1 input signal's logic level when IT1 = 0. Bit2: IT1: Interrupt 1 Type Select. This bit selects whether the configured /INT1 signal will detect falling edge or active-low level-sensi- tive interrupts. 0: /INT1 is level triggered. 1: /INT1 is edge triggered. Bit1: IE0: External Interrupt 0. This flag is set by hardware when an edge/level of type defined by IT0 is detected. It can be cleared by software but is automatically cleared when the CPU vectors to the External Interrupt 0 service rou- tine if IT0 = 1. This flag is the inverse of the /INT0 input signal's logic level when IT0 = 0. Bit0: IT0: Interrupt 0 Type Select. This bit selects whether the configured /INT0 signal will detect falling edge or active-low level-sensi- tive interrupts. 0: /INT0 is level triggered. 1: /INT0 is edge triggered. Rev. 1.4 231

C8051F020/1/2/3 Figure 22.6. TMOD: Timer Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value GATE1 C/T1 T1M1 T1M0 GATE0 C/T0 T0M1 T0M0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x89 Bit7: GATE1: Timer 1 Gate Control. 0: Timer 1 enabled when TR1 = 1 irrespective of /INT1 logic level. 1: Timer 1 enabled only when TR1 = 1 AND /INT1 = logic 1. Bit6: C/T1: Counter/Timer 1 Select. 0: Timer Function: Timer 1 incremented by clock defined by T1M bit (CKCON.4). 1: Counter Function: Timer 1 incremented by high-to-low transitions on external input pin (T1). Bits5-4: T1M1-T1M0: Timer 1 Mode Select. These bits select the Timer 1 operation mode. T1M1 T1M0 Mode 0 0 Mode 0: 13-bit counter/timer 0 1 Mode 1: 16-bit counter/timer 1 0 Mode 2: 8-bit counter/timer with auto-reload 1 1 Mode 3: Timer 1 inactive Bit3: GATE0: Timer 0 Gate Control. 0: Timer 0 enabled when TR0 = 1 irrespective of /INT0 logic level. 1: Timer 0 enabled only when TR0 = 1 AND /INT0 = logic 1. Bit2: C/T0: Counter/Timer Select. 0: Timer Function: Timer 0 incremented by clock defined by T0M bit (CKCON.3). 1: Counter Function: Timer 0 incremented by high-to-low transitions on external input pin (T0). Bits1-0: T0M1-T0M0: Timer 0 Mode Select. These bits select the Timer 0 operation mode. T0M1 T0M0 Mode 0 0 Mode 0: 13-bit counter/timer 0 1 Mode 1: 16-bit counter/timer 1 0 Mode 2: 8-bit counter/timer with auto-reload 1 1 Mode 3: Two 8-bit counter/timers 232 Rev. 1.4

C8051F020/1/2/3 Figure 22.7. TL0: Timer 0 Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8A Bits 7-0: TL0: Timer 0 Low Byte. The TL0 register is the low byte of the 16-bit Timer 0. Figure 22.8. TL1: Timer 1 Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8B Bits 7-0: TH0: Timer 0 High Byte. The TH0 register is the low byte of the 16-bit Timer 1. Figure 22.9. TH0 Timer 0 High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8C Bits 7-0: TH0: Timer 0 High Byte. The TH0 register is the high byte of the 16-bit Timer 0. Figure 22.10. TH1: Timer 1 High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x8D Bits 7-0: TH1: Timer 1 High Byte. The TH1 register is the high byte of the 16-bit Timer 1. Rev. 1.4 233

C8051F020/1/2/3 22.1. Timer 2 Timer 2 is a 16-bit counter/timer formed by the two 8-bit SFRs: TL2 (low byte) and TH2 (high byte). As with Timers 0 and 1, Timer 2 can use either the system clock or transitions on an external input pin (T2) as its clock source. The Counter/Timer Select bit C/T2 bit (T2CON.1) selects the clock source for Timer 2. Clearing C/T2 selects the system clock as the input for the timer (divided by either one or twelve as specified by the Timer Clock Select bit T2M in CKCON). When C/T2 is set to 1, high-to-low transitions at the T2 input pin increment the counter/timer reg- ister. (Refer to Section “17.1. Ports 0 through 3 and the Priority Crossbar Decoder” on page 163 for information on selecting and configuring external I/O pins for digital peripherals.) Timer 2 can also be used to start an ADC Data Conversion. Timer 2 offers capabilities not found in Timer 0 and Timer 1. It operates in one of three modes: 16-bit Counter/Timer with Capture, 16-bit Counter/Timer with Auto-Reload or Baud Rate Generator Mode. Timer 2's operating mode is selected by setting configuration bits in the Timer 2 Control register (T2CON). Below is a summary of the Timer 2 operating modes and the T2CON bits used to configure the counter/timer. Detailed descriptions of each mode follow. RCLK0 TCLK0 CP/RL2 TR2 Mode 0 0 1 1 16-bit Counter/Timer with Capture 0 0 0 1 16-bit Counter/Timer with Auto-Reload 0 1 X 1 Baud Rate Generator for UART0 1 0 X 1 Baud Rate Generator for UART0 1 1 X 1 Baud Rate Generator for UART0 X X X 0 Off 234 Rev. 1.4

C8051F020/1/2/3 22.1.1. Mode 0: 16-bit Counter/Timer with Capture In this mode, Timer 2 operates as a 16-bit counter/timer with capture facility. A high-to-low transition on the T2EX input pin causes the following to occur: 1. The 16-bit value in Timer 2 (TH2, TL2) is loaded into the capture registers (RCAP2H, RCAP2L). 2. The Timer 2 External Flag (EXF2) is set to ‘1’. 3. A Timer 2 interrupt is generated if enabled. Timer 2 can use either SYSCLK, SYSCLK divided by 12, or high-to-low transitions on the T2 input pin as its clock source when operating in Capture mode. Clearing the C/T2 bit (T2CON.1) selects the system clock as the input for the timer (divided by one or twelve as specified by the Timer Clock Select bit T2M in CKCON). When C/T2 is set to logic 1, a high-to-low transition at the T2 input pin increments the counter/timer register. As the 16-bit counter/timer register increments and overflows from 0xFFFF to 0x0000, the TF2 timer overflow flag (T2CON.7) is set and an interrupt will occur if the interrupt is enabled. Counter/Timer with Capture mode is selected by setting the Capture/Reload Select bit CP/RL2 (T2CON.0) and the Timer 2 Run Control bit TR2 (T2CON.2) to logic 1. The Timer 2 External Enable EXEN2 (T2CON.3) must also be set to logic 1 to enable a capture. If EXEN2 is cleared, transitions on T2EX will be ignored. Figure 22.11. T2 Mode 0 Block Diagram CKCON TTTT 4210 MMMM 12 0 SYSCLK 1 0 T2 1 TCLK TL2 TH2 CP/RL2 C/T2 Crossbar TR2 N TR2 O EXEN2 C TCLK0 T2 RCLK0 T2EX EXF2 Interrupt Capture RCAP2L RCAP2H TF2 EXEN2 Rev. 1.4 235

C8051F020/1/2/3 22.1.2. Mode 1: 16-bit Counter/Timer with Auto-Reload The Counter/Timer with Auto-Reload mode sets the TF2 timer overflow flag when the counter/timer register over- flows from 0xFFFF to 0x0000. An interrupt is generated if enabled. On overflow, the 16-bit value held in the two capture registers (RCAP2H, RCAP2L) is automatically loaded into the counter/timer register and the timer is restarted. Counter/Timer with Auto-Reload mode is selected by clearing the CP/RL2 bit. Setting TR2 to logic 1 enables and starts the timer. Timer 2 can use either the system clock or transitions on an external input pin (T2) as its clock source, as specified by the C/T2 bit. If EXEN2 is set to logic 1, a high-to-low transition on T2EX will also cause a Timer 2 reload, and a Timer 2 interrupt if enabled. If EXEN2 is logic 0, transitions on T2EX will be ignored. Figure 22.12. T2 Mode 1 Block Diagram CKCON TTTT 4210 MMMM 12 0 SYSCLK 1 0 T2 1 TCLK TL2 TH2 CP/RL2 C/T2 Crossbar TR2 ON EXTREN22 C TCLK0 T2EX T2 RECXLFK20 Interrupt Reload RCAP2L RCAP2H TF2 EXEN2 236 Rev. 1.4

C8051F020/1/2/3 22.1.3. Mode 2: Baud Rate Generator Timer 2 can be used as a baud rate generator for UART0 when UART0 is operated in modes 1 or 3 (refer to Section “20.1. UART0 Operational Modes” on page 206 for more information on the UART0 operational modes). In Baud Rate Generator mode, Timer 2 works similarly to the auto-reload mode. On overflow, the 16-bit value held in the two capture registers (RCAP2H, RCAP2L) is automatically loaded into the counter/timer register. However, the TF2 overflow flag is not set and no interrupt is generated. Instead, the overflow event is used as the input to the UART's shift clock. Timer 2 overflows can be selected to generate baud rates for transmit and/or receive independently. The Baud Rate Generator mode is selected by setting RCLK0 (T2CON.5) and/or TCLK0 (T2CON.2) to ‘1’. When RCLK0 or TCLK0 is set to logic 1, Timer 2 operates in the auto-reload mode regardless of the state of the CP/RL2 bit. Note that in Baud Rate Generator mode, the Timer 2 timebase is the system clock divided by two. When selected as the UART0 baud clock source, Timer 2 defines the UART0 baud rate as follows: Baud Rate = SYSCLK / ((65536 - [RCAP2H, RCAP2L] ) * 32) If a different time base is required, setting the C/T2 bit to logic 1 will allow the timebase to be derived from the exter- nal input pin T2. In this case, the baud rate for the UART is calculated as: Baud Rate = F / ( (65536 - [RCAP2H, RCAP2L] ) * 16) CLK Where F is the frequency of the signal (TCLK) supplied to Timer 2 and [RCAP2H, RCAP2L] is the 16-bit value CLK held in the capture registers. As explained above, in Baud Rate Generator mode, Timer 2 does not set the TF2 overflow flag and therefore cannot generate an interrupt. However, if EXEN2 is set to logic 1, a high-to-low transition on the T2EX input pin will set the EXF2 flag and a Timer 2 interrupt will occur if enabled. Therefore, the T2EX input may be used as an additional external interrupt source. Figure 22.13. T2 Mode 2 Block Diagram C/T2 SYSCLK 2 0 RCLK0 Timer 2 Overflow T2 Crossbar 1 TCLK TL2 TH2 0 16 RX0 Clock TR2 PCON Reload 1 SS SS S I MS MS TD RCAP2L RCAP2H OT OT OL DA DA PE 0T 1T 0 1 0 16 TX0 Clock 2 0 1 Timer 1 Overflow 1 CCP//TR2L2 TCLK0 N TR2 O EXEN2 C TCLK0 EXEN2 T2 RCLK0 EXF2 Interrupt TF2 T2EX Crossbar Rev. 1.4 237

C8051F020/1/2/3 Figure 22.14. T2CON: Timer 2 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value TF2 EXF2 RCLK0 TCLK0 EXEN2 TR2 C/T2 CP/RL2 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xC8 Bit7: TF2: Timer 2 Overflow Flag. Set by hardware when Timer 2 overflows. When the Timer 2 interrupt is enabled, setting this bit causes the CPU to vector to the Timer 2 interrupt service routine. This bit is not automatically cleared by hardware and must be cleared by software. TF2 will not be set when RCLK0 and/or TCLK0 are logic 1. Bit6: EXF2: Timer 2 External Flag. Set by hardware when either a capture or reload is caused by a high-to-low transition on the T2EX input pin and EXEN2 is logic 1. When the Timer 2 interrupt is enabled, setting this bit causes the CPU to vector to the Timer 2 Interrupt service routine. This bit is not automatically cleared by hard- ware and must be cleared by software. Bit5: RCLK0: Receive Clock Flag for UART0. Selects which timer is used for the UART0 receive clock in modes 1 or 3. 0: Timer 1 overflows used for receive clock. 1: Timer 2 overflows used for receive clock. Bit4: TCLK0: Transmit Clock Flag for UART0. Selects which timer is used for the UART0 transmit clock in modes 1 or 3. 0: Timer 1 overflows used for transmit clock. 1: Timer 2 overflows used for transmit clock. Bit3: EXEN2: Timer 2 External Enable. Enables high-to-low transitions on T2EX to trigger captures or reloads when Timer 2 is not operating in Baud Rate Generator mode. 0: High-to-low transitions on T2EX ignored. 1: High-to-low transitions on T2EX cause a capture or reload. Bit2: TR2: Timer 2 Run Control. This bit enables/disables Timer 2. 0: Timer 2 disabled. 1: Timer 2 enabled. Bit1: C/T2: Counter/Timer Select. 0: Timer Function: Timer 2 incremented by clock defined by T2M (CKCON.5). 1: Counter Function: Timer 2 incremented by high-to-low transitions on external input pin (T2). Bit0: CP/RL2: Capture/Reload Select. This bit selects whether Timer 2 functions in capture or auto-reload mode. EXEN2 must be logic 1 for high-to-low transitions on T2EX to be recognized and used to trigger captures or reloads. If RCLK0 or TCLK0 is set, this bit is ignored and Timer 2 will function in auto-reload mode. 0: Auto-reload on Timer 2 overflow or high-to-low transition at T2EX (EXEN2 = 1). 1: Capture on high-to-low transition at T2EX (EXEN2 = 1). 238 Rev. 1.4

C8051F020/1/2/3 Figure 22.15. RCAP2L: Timer 2 Capture Register Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xCA Bits 7-0: RCAP2L: Timer 2 Capture Register Low Byte. The RCAP2L register captures the low byte of Timer 2 when Timer 2 is configured in capture mode. When Timer 2 is configured in auto-reload mode, it holds the low byte of the reload value. Figure 22.16. RCAP2H: Timer 2 Capture Register High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xCB Bits 7-0: RCAP2H: Timer 2 Capture Register High Byte. The RCAP2H register captures the high byte of Timer 2 when Timer 2 is configured in capture mode. When Timer 2 is configured in auto-reload mode, it holds the high byte of the reload value. Figure 22.17. TL2: Timer 2 Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xCC Bits 7-0: TL2: Timer 2 Low Byte. The TL2 register contains the low byte of the 16-bit Timer 2. Figure 22.18. TH2 Timer 2 High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xCD Bits 7-0: TH2: Timer 2 High Byte. The TH2 register contains the high byte of the 16-bit Timer 2. Rev. 1.4 239

C8051F020/1/2/3 22.2. Timer 3 Timer 3 is a 16-bit timer formed by the two 8-bit SFRs, TMR3L (low byte) and TMR3H (high byte). Timer 3 may be clocked by the external oscillator source (divided by eight) or the system clock (divided by either one or twelve as specified by the Timer 3 Clock Select bit T3M in the Timer 3 Control Register TMR3CN). Timer 3 is always config- ured as an auto-reload timer, with the reload value held in the TMR3RLL (low byte) and TMR3RLH (high byte) reg- isters. The Timer 3 external clock source feature offers a real-time clock (RTC) mode. When bit T3XCLK (TMR3CN.0) is set to logic 1, Timer 3 is clocked by the external oscillator input (divided by 8) regardless of the system clock selec- tion. This split clock domain allows Timer 3 to be clocked by a precision external source while the system clock is derived from the high-speed internal oscillator. When T3XCLK is logic 0, the Timer 3 clock source is specified by bit T3M (TMR3CN.1). Timer 3 can also be used to start an ADC Data Conversion, for SMBus timing (see Section “18. SYSTEM MAN- AGEMENT BUS / I2C BUS (SMBUS0)” on page 183), or as a general-purpose timer. Timer 3 does not have a counter mode. Figure 22.19. Timer 3 Block Diagram T3XCLK External 8 (to ADC) Oscillator Source 1 12 0 TCLK TMR3L TMR3H TF3 Interrupt SYSCLK 1 0 TR3 R3CN TM TR3 (from SMBus)TOE Reload T3TX3CMLK T3M SCL Crossbar TMR3RLL TMR3RLH 240 Rev. 1.4

C8051F020/1/2/3 Figure 22.20. TMR3CN: Timer 3 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value TF3 - - - - TR3 T3M T3XCLK 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x91 Bit7: TF3: Timer3 Overflow Flag. Set by hardware when Timer 3 overflows from 0xFFFF to 0x0000. When the Timer 3 interrupt is enabled, setting this bit causes the CPU to vector to the Timer 3 Interrupt service routine. This bit is not automatically cleared by hardware and must be cleared by software. Bits6-3: UNUSED. Read = 0000b, Write = don't care. Bit2: TR3: Timer 3 Run Control. This bit enables/disables Timer 3. 0: Timer 3 disabled. 1: Timer 3 enabled. Bit1: T3M: Timer 3 Clock Select. This bit controls the division of the system clock supplied to Counter/Timer 3. 0: Counter/Timer 3 uses the system clock divided by 12. 1: Counter/Timer 3 uses the system clock. Bit0: T3XCLK: Timer 3 External Clock Select This bit selects the external oscillator input divided by 8 as the Timer 3 clock source. When T3XCLK is logic 1, bit T3M (TMR3CN.1) is ignored. 0: Timer 3 clock source defined by bit T3M (TMR3CN.1). 1: Timer 3 clock source is the external oscillator input divided by 8. Figure 22.21. TMR3RLL: Timer 3 Reload Register Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x92 Bits 7-0: TMR3RLL: Timer 3 Reload Register Low Byte. Timer 3 is configured as an auto-reload timer. This register holds the low byte of the reload value. Rev. 1.4 241

C8051F020/1/2/3 Figure 22.22. TMR3RLH: Timer 3 Reload Register High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x93 Bits 7-0: TMR3RLH: Timer 3 Reload Register High Byte. Timer 3 is configured as an auto-reload timer. This register holds the high byte of the reload value. Figure 22.23. TMR3L: Timer 3 Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x94 Bits 7-0: TMR3L: Timer 3 Low Byte. The TMR3L register is the low byte of Timer 3. Figure 22.24. TMR3H: Timer 3 High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0x95 Bits 7-0: TMR3H: Timer 3 High Byte. The TMR3H register is the high byte of Timer 3. 242 Rev. 1.4

C8051F020/1/2/3 22.3. Timer 4 Timer 4 is a 16-bit counter/timer formed by the two 8-bit SFRs: TL4 (low byte) and TH4 (high byte). As with Timers 0 and 1, Timer 4 can use either the system clock or transitions on an external input pin (T4) as its clock source. The Counter/Timer Select bit C/T4 bit (T4CON.1) selects the clock source for Timer 4. Clearing C/T4 selects the system clock as the input for the timer (divided by either one or twelve as specified by the Timer Clock Select bit T4M in CKCON). When C/T4 is set to 1, high-to-low transitions at the T4 input pin increment the counter/timer reg- ister. Refer to Section “17.1. Ports 0 through 3 and the Priority Crossbar Decoder” on page 163 for information on selecting and configuring external I/O pins for digital peripherals. Timer 4 offers capabilities not found in Timer 0 and Timer 1. It operates in one of three modes: 16-bit Counter/Timer with Capture, 16-bit Counter/Timer with Auto-Reload or Baud Rate Generator Mode. Timer 4's operating mode is selected by setting configuration bits in the Timer 4 Control register (T4CON). Below is a summary of the Timer 4 operating modes and the T4CON bits used to configure the counter/timer. Detailed descriptions of each mode follow. RCLK1 TCLK1 CP/RL4 TR4 Mode 0 0 1 1 16-bit Counter/Timer with Capture 0 0 0 1 16-bit Counter/Timer with Auto-Reload 0 1 X 1 Baud Rate Generator for UART1 1 0 X 1 Baud Rate Generator for UART1 1 1 X 1 Baud Rate Generator for UART1 X X X 0 Off Rev. 1.4 243

C8051F020/1/2/3 22.3.1. Mode 0: 16-bit Counter/Timer with Capture In this mode, Timer 4 operates as a 16-bit counter/timer with capture facility. A high-to-low transition on the T4EX input pin causes the following to occur: 1. The 16-bit value in Timer 4 (TH4, TL4) is loaded into the capture registers (RCAP4H, RCAP4L). 2. The Timer 4 External Flag (EXF2) is set to ‘1’. 3. A Timer 4 interrupt is generated if enabled. Timer 4 can use either SYSCLK, SYSCLK divided by 12, or high-to-low transitions on the T4 input pin as its clock source when operating in Capture mode. Clearing the C/T4 bit (T4CON.1) selects the system clock as the input for the timer (divided by one or twelve as specified by the Timer Clock Select bit T4M in CKCON). When C/T4 is set to logic 1, a high-to-low transition at the T4 input pin increments the counter/timer register. As the 16-bit counter/timer register increments and overflows from 0xFFFF to 0x0000, the TF4 timer overflow flag (T4CON.7) is set and an interrupt will occur if the interrupt is enabled. Counter/Timer with Capture mode is selected by setting the Capture/Reload Select bit CP/RL4 (T4CON.0) and the Timer 4 Run Control bit TR4 (T4CON.2) to logic 1. The Timer 4 External Enable EXEN4 (T4CON.3) must also be set to logic 1 to enable a capture. If EXEN4 is cleared, transitions on T4EX will be ignored. Figure 22.25. T4 Mode 0 Block Diagram CKCON TTTT 4210 MMMM 12 0 SYSCLK 1 0 T4 1 TCLK TL4 TH4 CP/RL4 C/T4 Crossbar TR4 N TR4 O EXEN4 C TCLK0 T4 RCLK0 T4EX EXF4 Interrupt Capture RCAP4L RCAP4H TF4 EXEN4 244 Rev. 1.4

C8051F020/1/2/3 22.3.2. Mode 1: 16-bit Counter/Timer with Auto-Reload The Counter/Timer with Auto-Reload mode sets the TF4 timer overflow flag when the counter/timer register over- flows from 0xFFFF to 0x0000. An interrupt is generated if enabled. On overflow, the 16-bit value held in the two capture registers (RCAP4H, RCAP4L) is automatically loaded into the counter/timer register and the timer is restarted. Counter/Timer with Auto-Reload mode is selected by clearing the CP/RL4 bit. Setting TR4 to logic 1 enables and starts the timer. Timer 4 can use either the system clock or transitions on an external input pin (T2) as its clock source, as specified by the C/T4 bit. If EXEN4 is set to logic 1, a high-to-low transition on T4EX will also cause a Timer 4 reload, and a Timer 4 interrupt if enabled. If EXEN4 is logic 0, transitions on T4EX will be ignored. Figure 22.26. T4 Mode 1 Block Diagram CKCON TTTT 4210 MMMM 12 0 SYSCLK 1 0 T4 1 TCLK TL4 TH4 CP/RL4 C/T4 Crossbar TR4 ON EXTREN44 C TCLK0 T4EX T4 RECXLFK40 Interrupt Reload RCAP4L RCAP4H TF4 EXEN4 Rev. 1.4 245

C8051F020/1/2/3 22.3.3. Mode 2: Baud Rate Generator Timer 4 can be used as a baud rate generator for UART1 when UART1 is operated in modes 1 or 3 (refer to Section “21.1. UART1 Operational Modes” on page 216 for more information on the UART1 operational modes). In Baud Rate Generator mode, Timer 4 works similarly to the auto-reload mode. On overflow, the 16-bit value held in the two capture registers (RCAP4H, RCAP4L) is automatically loaded into the counter/timer register. However, the TF4 overflow flag is not set and no interrupt is generated. Instead, the overflow event is used as the input to the UART's shift clock. Timer 4 overflows can be selected to generate baud rates for transmit and/or receive independently. The Baud Rate Generator mode is selected by setting RCLK1 (T4CON.5) and/or TCLK1 (T4CON.4) to ‘1’. When RCLK1 or TCLK1 is set to logic 1, Timer 4 operates in the auto-reload mode regardless of the state of the CP/RL4 bit. Note that in Baud Rate Generator mode, the Timer 4 timebase is the system clock divided by two. When selected as the UART1 baud clock source, Timer 4 defines the UART1 baud rate as follows: Baud Rate = SYSCLK / ((65536 - [RCAP4H, RCAP4L] ) * 32) If a different time base is required, setting the C/T4 bit to logic 1 will allow the timebase to be derived from the exter- nal input pin T4. In this case, the baud rate for the UART is calculated as: Baud Rate = F / ( (65536 - [RCAP4H, RCAP4L] ) * 16) CLK Where F is the frequency of the signal (TCLK) supplied to Timer 4 and [RCAP4H, RCAP4L] is the 16-bit value CLK held in the capture registers. As explained above, in Baud Rate Generator mode, Timer 4 does not set the TF4 overflow flag and therefore cannot generate an interrupt. However, if EXEN4 is set to logic 1, a high-to-low transition on the T4EX input pin will set the EXF4 flag and a Timer 4 interrupt will occur if enabled. Therefore, the T4EX input may be used as an additional external interrupt source. Figure 22.27. T4 Mode 2 Block Diagram C/T2 SYSCLK 2 0 RCLK0 Timer 2 Overflow T2 Crossbar 1 TCLK TL2 TH2 0 16 RX0 Clock TR2 Reload 1 PCON S RCAP2L RCAP2H S I M TD O OL D 0 PE 0 16 TX0 Clock 2 0 1 Timer 1 Overflow 1 CCP//TR2L2 TCLK0 N TR2 O EXEN2 C TCLK0 EXEN2 T2 RCLK0 EXF2 Interrupt TF2 T2EX Crossbar 246 Rev. 1.4

C8051F020/1/2/3 Figure 22.28. T4CON: Timer 4 Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value TF4 EXF4 RCLK1 TCLK1 EXEN4 TR4 C/T4 CP/RL4 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xC9 Bit7: TF4: Timer 4 Overflow Flag. Set by hardware when Timer 4 overflows. When the Timer 4 interrupt is enabled, setting this bit causes the CPU to vector to the Timer 4 interrupt service routine. This bit is not automatically cleared by hardware and must be cleared by software. TF4 will not be set when RCLK1 and/or TCLK1 are logic 1. Bit6: EXF4: Timer 4 External Flag. Set by hardware when either a capture or reload is caused by a high-to-low transition on the T4EX input pin and EXEN4 is logic 1. When the Timer 4 interrupt is enabled, setting this bit causes the CPU to vector to the Timer 4 Interrupt service routine. This bit is not automatically cleared by hard- ware and must be cleared by software. Bit5: RCLK1: Receive Clock Flag for UART1. Selects which timer is used for the UART1 receive clock in modes 1 or 3. 0: Timer 1 overflows used for receive clock. 1: Timer 4 overflows used for receive clock. Bit4: TCLK1: Transmit Clock Flag for UART1. Selects which timer is used for the UART1 transmit clock in modes 1 or 3. 0: Timer 1 overflows used for transmit clock. 1: Timer 4 overflows used for transmit clock. Bit3: EXEN4: Timer 4 External Enable. Enables high-to-low transitions on T4EX to trigger captures or reloads when Timer 4 is not operating in Baud Rate Generator mode. 0: High-to-low transitions on T4EX ignored. 1: High-to-low transitions on T4EX cause a capture or reload. Bit2: TR4: Timer 4 Run Control. This bit enables/disables Timer 4. 0: Timer 4 disabled. 1: Timer 4 enabled. Bit1: C/T4: Counter/Timer Select. 0: Timer Function: Timer 4 incremented by clock defined by T4M (CKCON.6). 1: Counter Function: Timer 4 incremented by high-to-low transitions on external input pin (T2). Bit0: CP/RL4: Capture/Reload Select. This bit selects whether Timer 4 functions in capture or auto-reload mode. EXEN4 must be logic 1 for high-to-low transitions on T4EX to be recognized and used to trigger captures or reloads. If RCLK1 or TCLK1 is set, this bit is ignored and Timer 4 will function in auto-reload mode. 0: Auto-reload on Timer 4 overflow or high-to-low transition at T4EX (EXEN4 = 1). 1: Capture on high-to-low transition at T4EX (EXEN4 = 1). Rev. 1.4 247

C8051F020/1/2/3 Figure 22.29. RCAP4L: Timer 4 Capture Register Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE4 Bits 7-0: RCAP4L: Timer 4 Capture Register Low Byte. The RCAP4L register captures the low byte of Timer 4 when Timer 4 is configured in capture mode. When Timer 4 is configured in auto-reload mode, it holds the low byte of the reload value. Figure 22.30. RCAP4H: Timer 4 Capture Register High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE5 Bits 7-0: RCAP4H: Timer 4 Capture Register High Byte. The RCAP4H register captures the high byte of Timer 4 when Timer 4 is configured in capture mode. When Timer 4 is configured in auto-reload mode, it holds the high byte of the reload value. Figure 22.31. TL4: Timer 4 Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF4 Bits 7-0: TL4: Timer 4 Low Byte. The TL4 register contains the low byte of the 16-bit Timer 4. Figure 22.32. TH4 Timer 4 High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF5 Bits 7-0: TH4: Timer 4 High Byte. The TH4 register contains the high byte of the 16-bit Timer 4. 248 Rev. 1.4

C8051F020/1/2/3 23. PROGRAMMABLE COUNTER ARRAY The Programmable Counter Array (PCA0) provides enhanced timer functionality while requiring less CPU interven- tion than the standard 8051 counter/timers. PCA0 consists of a dedicated 16-bit counter/timer and five 16-bit capture/ compare modules. Each capture/compare module has its own associated I/O line (CEXn) which is routed through the Crossbar to Port I/O when enabled (See Section “17.1. Ports 0 through 3 and the Priority Crossbar Decoder” on page 163). The counter/timer is driven by a programmable timebase that can select between six inputs as its source: system clock, system clock divided by four, system clock divided by twelve, the external oscillator clock source divided by 8, Timer 0 overflow, or an external clock signal on the ECI line. Each capture/compare module may be configured to operate independently in one of six modes: Edge-Triggered Capture, Software Timer, High-Speed Out- put, Frequency Output, 8-Bit PWM, or 16-Bit PWM (each is described in Section 23.2). The PCA is configured and controlled through the system controller's Special Function Registers. The basic PCA block diagram is shown in Figure 23.1. Figure 23.1. PCA Block Diagram SYSCLK/12 SYSCLK/4 Timer 0 Overflow PCA 16-Bit Counter/Timer ECI CLOCK MUX SYSCLK External Clock/8 Capture/Compare Capture/Compare Capture/Compare Capture/Compare Capture/Compare Module 0 Module 1 Module 2 Module 3 Module 4 E C C C C C C E E E E E I X X X X X 0 1 2 3 4 Crossbar Port I/O Rev. 1.4 249

C8051F020/1/2/3 23.1. PCA Counter/Timer The 16-bit PCA counter/timer consists of two 8-bit SFRs: PCA0L and PCA0H. PCA0H is the high byte (MSB) of the 16-bit counter/timer and PCA0L is the low byte (LSB). Reading PCA0L automatically latches the value of PCA0H into a “snapshot” register; the following PCA0H read accesses this “snapshot” register. Reading the PCA0L Register first guarantees an accurate reading of the entire 16-bit PCA0 counter. Reading PCA0H or PCA0L does not disturb the counter operation. The CPS2-CPS0 bits in the PCA0MD register select the timebase for the counter/timer as shown in Table 23.1. Note that in ‘External oscillator source divided by 8’ mode, the external oscillator source is synchronized with the system clock, and must have a frequency less than or equal to the system clock. When the counter/timer overflows from 0xFFFF to 0x0000, the Counter Overflow Flag (CF) in PCA0MD is set to logic 1 and an interrupt request is generated if CF interrupts are enabled. Setting the ECF bit in PCA0MD to logic 1 enables the CF flag to generate an interrupt request. The CF bit is not automatically cleared by hardware when the CPU vectors to the interrupt service routine, and must be cleared by software (Note: PCA0 interrupts must be glob- ally enabled before CF interrupts are recognized. PCA0 interrupts are globally enabled by setting the EA bit (IE.7) and the EPCA0 bit in EIE1 to logic 1). Clearing the CIDL bit in the PCA0MD register allows the PCA to continue normal operation while the CPU is in Idle mode. Table 23.1. PCA Timebase Input Options CPS2 CPS1 CPS0 Timebase 0 0 0 System clock divided by 12 0 0 1 System clock divided by 4 0 1 0 Timer 0 overflow 0 1 1 High-to-low transitions on ECI‡ (max rate = system clock divided by 4) 1 0 0 System clock 1 0 1 External oscillator source divided by 8† †External oscillator source divided by 8 is synchronized with the system clock. ‡The minimum high or low time for the ECI input signal is at least 2 system clock cycles. Figure 23.2. PCA Counter/Timer Block Diagram IDLE PCA0MD PCA0CN CWW CCCE CC CCCCC I DD PPPC FR CCCCC DT L SSSF FFFFF LEC 210 43210 To SFR Bus K PCA0L read Snapshot Register SYSCLK/12 000 SYSCLK/4 001 Timer 0 Overflow ECI 001101 01 PCA0H PCA0L Overflow To PCA Interrupt System SYSCLK 100 CF External Clock/8 101 To PCA Modules 250 Rev. 1.4

C8051F020/1/2/3 Important Note About the PCA0CN Register: If the main PCA counter (PCA0H : PCA0L) overflows during the execution phase of a read-modify-write instruction (bit-wise SETB or CLR, ANL, ORL, XRL) that targets the PCA0CN register, the CF (Counter Overflow) bit will not be set. The following steps should be taken when perform- ing a bit-wise operation on the PCA0CN register: Step 1. Disable global interrupts (EA = 0). Step 2. Read PCA0L. This will latch the value of PCA0H. Step 3. Read PCA0H, saving the value. Step 4. Execute the bit-wise operation on CCFn (for example, CLR CCF0, or CCF0 = 0;). Step 5. Read PCA0L. Step 6. Read PCA0H, saving the value. Step 7. If the value of PCA0H read in Step 3 is 0xFF and the value for PCA0H read in Step 6 is 0x00, then manually set the CF bit in software (for example, SETB CF, or CF = 1;). Step 8. Re-enable interrupts (EA = 1). Rev. 1.4 251

C8051F020/1/2/3 23.2. Capture/Compare Modules Each module can be configured to operate independently in one of six operation modes: Edge-triggered Capture, Software Timer, High Speed Output, Frequency Output, 8-Bit Pulse Width Modulator, or 16-Bit Pulse Width Modu- lator. Each module has Special Function Registers (SFRs) associated with it in the CIP-51 system controller. These registers are used to exchange data with a module and configure the module's mode of operation. Table 23.2 summarizes the bit settings in the PCA0CPMn registers used to select the PCA0 capture/compare mod- ule’s operating modes. Setting the ECCFn bit in a PCA0CPMn register enables the module's CCFn interrupt. Note: PCA0 interrupts must be globally enabled before individual CCFn interrupts are recognized. PCA0 interrupts are globally enabled by setting the EA bit (IE.7) and the EPCA0 bit (EIE1.3) to logic 1. See Figure 23.3 for details on the PCA interrupt configuration. Table 23.2. PCA0CPM Register Settings for PCA Capture/Compare Modules PWM16 ECOM CAPP CAPN MAT TOG PWM ECCF Operation Mode Capture triggered by positive edge on X X 1 0 0 0 0 X CEXn Capture triggered by negative edge on X X 0 1 0 0 0 X CEXn Capture triggered by transition on X X 1 1 0 0 0 X CEXn X 1 0 0 1 0 0 X Software Timer X 1 0 0 1 1 0 X High Speed Output X 1 0 0 X 1 1 X Frequency Output 0 1 0 0 X 0 1 X 8-Bit Pulse Width Modulator 1 1 0 0 X 0 1 X 16-Bit Pulse Width Modulator X = Don’t Care Figure 23.3. PCA Interrupt Block Diagram (for n = 0 to 4) PCA0CPMn PCA0CN PCA0MD PECCMTPE CC CCCCC C CCCE WCAAAOWC FR CCCCC I PPPC MOPPTGMC FFFFF D SSSF 1MPNnnnF 43210 L 210 6nnn n n PCA Counter/ 0 Timer Overflow 1 ECCF0 EPCA0 EA PCA Module 0 0 (EIE1.3) (IE.7) (CCF0) 1 0 0 Interrupt Priority 1 1 Decoder ECCF1 PCA Module 1 0 (CCF1) 1 ECCF2 PCA Module 2 0 (CCF2) 1 ECCF3 PCA Module 3 0 (CCF3) 1 ECCF4 PCA Module 4 0 (CCF4) 1 252 Rev. 1.4

C8051F020/1/2/3 23.2.1. Edge-triggered Capture Mode In this mode, a valid transition on the CEXn pin causes PCA0 to capture the value of the PCA0 counter/timer and load it into the corresponding module's 16-bit capture/compare register (PCA0CPLn and PCA0CPHn). The CAPPn and CAPNn bits in the PCA0CPMn register are used to select the type of transition that triggers the capture: low-to- high transition (positive edge), high-to-low transition (negative edge), or either transition (positive or negative edge). When a capture occurs, the Capture/Compare Flag (CCFn) in PCA0CN is set to logic 1 and an interrupt request is generated if CCF interrupts are enabled. The CCFn bit is not automatically cleared by hardware when the CPU vec- tors to the interrupt service routine, and must be cleared by software. Figure 23.4. PCA Capture Mode Diagram PCA Interrupt PCA0CPMn PCA0CN PECCMTPE WCAAAOWC CC CCCCC MOPPTGMC FR CCCCC 1MPNn n n F FFFFF 6 n n n n 4 3 2 1 0 n Fn) PCA0CPLn PCA0CPHn C C 0 o (t 1 Port I/O Crossbar CEXn Capture 0 1 PCA PCA0L PCA0H Timebase Note: The CEXn input signal must remain high or low for at least 2 system clock cycles in order to be valid. Rev. 1.4 253

C8051F020/1/2/3 23.2.2. Software Timer (Compare) Mode In Software Timer mode, the PCA0 counter/timer is compared to the module's 16-bit capture/compare register (PCA0CPHn and PCA0CPLn). When a match occurs, the Capture/Compare Flag (CCFn) in PCA0CN is set to logic 1 and an interrupt request is generated if CCF interrupts are enabled. The CCFn bit is not automatically cleared by hardware when the CPU vectors to the interrupt service routine, and must be cleared by software. Setting the ECOMn and MATn bits in the PCA0CPMn register enables Software Timer mode. Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’. Figure 23.5. PCA Software Timer Mode Diagram Write to PCA0CPLn 0 Reset ENB Write to PCA Interrupt PCA0CPHn ENB 1 PCA0CPMn PCA0CN PECCMTPE WCAAAOWC CC CCCCC MOPPTGMC PCA0CPLn PCA0CPHn FR CCCCC 1MPNnn n F FFFFF 6 nnn n 43210 n x 0 0 0 0 x 0 Enable 16-bit Comparator Match 1 PCA PCA0L PCA0H Timebase 254 Rev. 1.4

C8051F020/1/2/3 23.2.3. High Speed Output Mode In High Speed Output mode, a module’s associated CEXn pin is toggled each time a match occurs between the PCA Counter and the module's 16-bit capture/compare register (PCA0CPHn and PCA0CPLn) Setting the TOGn, MATn, and ECOMn bits in the PCA0CPMn register enables the High-Speed Output mode. Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’. Figure 23.6. PCA High Speed Output Mode Diagram Write to PCA0CPLn 0 ENB Reset PCA0CPMn Write to PCA0CPHn ENB PECCMTPE 1 WCAAAOWC MOPPTGMC 1MPNn n n F 6 n n n n n x 0 0 0 x PCA Interrupt PCA0CN CC CCCCC FR CCCCC PCA0CPLn PCA0CPHn FFFFF 4 3 21 0 0 Enable 16-bit Comparator Match 1 TOGn Toggle 0 CEXn Crossbar Port I/O 1 PCA PCA0L PCA0H Timebase Rev. 1.4 255

C8051F020/1/2/3 23.2.4. Frequency Output Mode Frequency Output Mode produces a programmable-frequency square wave on the module’s associated CEXn pin. The capture/compare module high byte holds the number of PCA clocks to count before the output is toggled. The frequency of the square wave is then defined by Equation 23.1. Equation 23.1. Square Wave Frequency Output F F = -------------------P---C---A---------------- CEXn 2× PCA0CPHn Note: A value of 0x00 in the PCA0CPHn register is equal to 256 for this equation. Where F is the frequency of the clock selected by the CPS2-0 bits in the PCA mode register, PCA0MD. The PCA lower byte of the capture/compare module is compared to the PCA0 counter low byte; on a match, CEXn is toggled and the offset held in the high byte is added to the matched value in PCA0CPLn. Frequency Output Mode is enabled by setting the ECOMn, TOGn, and PWMn bits in the PCA0CPMn register. Figure 23.7. PCA Frequency Output Mode Write to PCA0CPLn 0 ENB Reset PCA0CPMn Write to PECCMTPE PCA0CPHn ENB WCAAAOWC PCA0CPLn 8-bit Adder PCA0CPHn 1 MOPPTGMC 1MPNnnnF Adder 6nnn n Enable n TOGn x 000 x Toggle Enable 8-bit match 0 CEXn Crossbar Port I/O Comparator 1 PCA Timebase PCA0L 256 Rev. 1.4

C8051F020/1/2/3 23.2.5. 8-Bit Pulse Width Modulator Mode Each module can be used independently to generate pulse width modulated (PWM) outputs on its associated CEXn pin. The frequency of the output is dependent on the timebase for the PCA0 counter/timer. The duty cycle of the PWM output signal is varied using the module's PCA0CPLn capture/compare register. When the value in the low byte of the PCA0 counter/timer (PCA0L) is equal to the value in PCA0CPLn, the output on the CEXn pin will be asserted high. When the count value in PCA0L overflows, the CEXn output will be asserted low (see Figure 23.8). Also, when the counter/timer low byte (PCA0L) overflows from 0xFF to 0x00, PCA0CPLn is reloaded automatically with the value stored in the counter/timer's high byte (PCA0H) without software intervention. Setting the ECOMn and PWMn bits in the PCA0CPMn register enables 8-Bit Pulse Width Modulator mode. The duty cycle for 8-Bit PWM Mode is given by Equation 23.2. Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’. Equation 23.2. 8-Bit PWM Duty Cycle (256–PCA0CPHn) DutyCycle = --------------------------------------------------- 256 Using Equation 23.2, the largest duty cycle is 100% (PCA0CPHn = 0), and the smallest duty cycle is 0.39% (PCA0CPHn = 0xFF). A 0% duty cycle may be generated by clearing the ECOMn bit to ‘0’. Figure 23.8. PCA 8-Bit PWM Mode Diagram PCA0CPHn Write to PCA0CPLn 0 Reset ENB PCA0CPMn Write to PCA0CPHn ENB PECCMTPE 1 WCAAAOWC PCA0CPLn MOPPTGMC 1MPNnnnF 6nnn n n 0 00 x 0 x Enable 8-bit match S SET Q CEXn Crossbar Port I/O Comparator R Q CLR PCA Timebase PCA0L Overflow Rev. 1.4 257

C8051F020/1/2/3 23.2.6. 16-Bit Pulse Width Modulator Mode Each PCA0 module may also be operated in 16-Bit PWM mode. In this mode, the 16-bit capture/compare module defines the number of PCA0 clocks for the low time of the PWM signal. When the PCA0 counter matches the module contents, the output on CEXn is asserted high; when the counter overflows, CEXn is asserted low. To output a vary- ing duty cycle, new value writes should be synchronized with PCA0 CCFn match interrupts. 16-Bit PWM Mode is enabled by setting the ECOMn, PWMn, and PWM16n bits in the PCA0CPMn register. For a varying duty cycle, CCFn should also be set to logic 1 to enable match interrupts. The duty cycle for 16-Bit PWM Mode is given by Equation 23.3. Important Note About Capture/Compare Registers: When writing a 16-bit value to the PCA0 Capture/Compare registers, the low byte should always be written first. Writing to PCA0CPLn clears the ECOMn bit to ‘0’; writing to PCA0CPHn sets ECOMn to ‘1’ Equation 23.3. 16-Bit PWM Duty Cycle (65536–PCA0CPn) DutyCycle = ----------------------------------------------------- 65536 Using Equation 23.3, the largest duty cycle is 100% (PCA0CPn = 0), and the smallest duty cycle is 0.0015% (PCA0CPn = 0xFFFF). A 0% duty cycle may be generated by clearing the ECOMn bit to ‘0’. Figure 23.9. PCA 16-Bit PWM Mode PCA0CPMn PECCMTPE WCAAAOWC PCA0CPHn PCA0CPLn MOPPTGMC 1MPNnn n F 6 nnn n n 1 0 0 0 0 0 Enable 16-bit Comparator match S SET Q CEXn Crossbar Port I/O R Q CLR PCA Timebase PCA0H PCA0L Overflow 258 Rev. 1.4

C8051F020/1/2/3 23.3. Register Descriptions for PCA0 Following are detailed descriptions of the special function registers related to the operation of PCA0. Figure 23.10. PCA0CN: PCA Control Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value CF CR - CCF4 CCF3 CCF2 CCF1 CCF0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: (bit addressable) 0xD8 Bit7: CF: PCA Counter/Timer Overflow Flag. Set by hardware when the PCA0 Counter/Timer overflows from 0xFFFF to 0x0000. When the Counter/Timer Overflow (CF) interrupt is enabled, setting this bit causes the CPU to vector to the CF interrupt service routine. This bit is not automatically cleared by hardware and must be cleared by software. See “Important Note About the PCA0CN Register” on page 251. Bit6: CR: PCA0 Counter/Timer Run Control. This bit enables/disables the PCA0 Counter/Timer. 0: PCA0 Counter/Timer disabled. 1: PCA0 Counter/Timer enabled. Bit5: UNUSED. Read = 0b, Write = don't care. Bit4: CCF4: PCA0 Module 4 Capture/Compare Flag. This bit is set by hardware when a match or capture occurs. When the CCF interrupt is enabled, set- ting this bit causes the CPU to vector to the CCF interrupt service routine. This bit is not automati- cally cleared by hardware and must be cleared by software. Bit3: CCF3: PCA0 Module 3 Capture/Compare Flag. This bit is set by hardware when a match or capture occurs. When the CCF interrupt is enabled, set- ting this bit causes the CPU to vector to the CCF interrupt service routine. This bit is not automati- cally cleared by hardware and must be cleared by software. Bit2: CCF2: PCA0 Module 2 Capture/Compare Flag. This bit is set by hardware when a match or capture occurs. When the CCF interrupt is enabled, set- ting this bit causes the CPU to vector to the CCF interrupt service routine. This bit is not automati- cally cleared by hardware and must be cleared by software. Bit1: CCF1: PCA0 Module 1 Capture/Compare Flag. This bit is set by hardware when a match or capture occurs. When the CCF interrupt is enabled, set- ting this bit causes the CPU to vector to the CCF interrupt service routine. This bit is not automati- cally cleared by hardware and must be cleared by software. Bit0: CCF0: PCA0 Module 0 Capture/Compare Flag. This bit is set by hardware when a match or capture occurs. When the CCF interrupt is enabled, set- ting this bit causes the CPU to vector to the CCF interrupt service routine. This bit is not automati- cally cleared by hardware and must be cleared by software. Rev. 1.4 259

C8051F020/1/2/3 Figure 23.11. PCA0MD: PCA0 Mode Register R/W R/W R/W R/W R/W R/W R/W R/W Reset Value CIDL - CPS2 CPS1 CPS0 ECF 01000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xD9 Bit7: CIDL: PCA0 Counter/Timer Idle Control. Specifies PCA0 behavior when CPU is in Idle Mode. 0: PCA0 continues to function normally while the system controller is in Idle Mode. 1: PCA0 operation is suspended while the system controller is in Idle Mode. Bits6-4: UNUSED. Read = 000b, Write = don't care. Bits3-1: CPS2-CPS0: PCA0 Counter/Timer Pulse Select. These bits select the timebase source for the PCA0 counter CPS2 CPS1 CPS0 Timebase 0 0 0 System clock divided by 12 0 0 1 System clock divided by 4 0 1 0 Timer 0 overflow High-to-low transitions on ECI† 0 1 1 (max rate = system clock divided by 4) 1 0 0 System clock 1 0 1 External clock divided by 8‡ 1 1 0 Reserved 1 1 1 Reserved † The minimum high or low time for the ECI input signal is at least 2 system clock cycles. ‡ External oscillator source divided by 8 is synchronized with the system clock. Bit0: ECF: PCA Counter/Timer Overflow Interrupt Enable. This bit sets the masking of the PCA0 Counter/Timer Overflow (CF) interrupt. 0: Disable the CF interrupt. 1: Enable a PCA0 Counter/Timer Overflow interrupt request when CF (PCA0CN.7) is set. 260 Rev. 1.4

C8051F020/1/2/3 Figure 23.12. PCA0CPMn: PCA0 Capture/Compare Mode Registers R/W R/W R/W R/W R/W R/W R/W R/W Reset Value PWM16n ECOMn CAPPn CAPNn MATn TOGn PWMn ECCFn 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xDA-0xDE PCA0CPMn Address: PCA0CPM0 = 0xDA (n = 0) PCA0CPM1 = 0xDB (n = 1) PCA0CPM2 = 0xDC (n = 2) PCA0CPM3 = 0xDD (n = 3) PCA0CPM4 = 0xDE (n = 4) Bit7: PWM16n: 16-bit Pulse Width Modulation Enable This bit selects 16-bit mode when Pulse Width Modulation mode is enabled (PWMn = 1). 0: 8-bit PWM selected. 1: 16-bit PWM selected. Bit6: ECOMn: Comparator Function Enable. This bit enables/disables the comparator function for PCA0 module n. 0: Disabled. 1: Enabled. Bit5: CAPPn: Capture Positive Function Enable. This bit enables/disables the positive edge capture for PCA0 module n. 0: Disabled. 1: Enabled. Bit4: CAPNn: Capture Negative Function Enable. This bit enables/disables the negative edge capture for PCA0 module n. 0: Disabled. 1: Enabled. Bit3: MATn: Match Function Enable. This bit enables/disables the match function for PCA0 module n. When enabled, matches of the PCA0 counter with a module's capture/compare register cause the CCFn bit in PCA0MD register to be set to logic 1. 0: Disabled. 1: Enabled. Bit2: TOGn: Toggle Function Enable. This bit enables/disables the toggle function for PCA0 module n. When enabled, matches of the PCA0 counter with a module's capture/compare register cause the logic level on the CEXn pin to tog- gle. If the PWMn bit is also set to logic 1, the module operates in Frequency Output Mode. 0: Disabled. 1: Enabled. Bit1: PWMn: Pulse Width Modulation Mode Enable. This bit enables/disables the PWM function for PCA0 module n. When enabled, a pulse width modu- lated signal is output on the CEXn pin. 8-bit PWM is used if PWM16n is logic 0; 16-bit mode is used if PWM16n logic 1. If the TOGn bit is also set, the module operates in Frequency Output Mode. 0: Disabled. 1: Enabled. Bit0: ECCFn: Capture/Compare Flag Interrupt Enable. This bit sets the masking of the Capture/Compare Flag (CCFn) interrupt. 0: Disable CCFn interrupts. 1: Enable a Capture/Compare Flag interrupt request when CCFn is set. Rev. 1.4 261

C8051F020/1/2/3 Figure 23.13. PCA0L: PCA0 Counter/Timer Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xE9 Bits 7-0: PCA0L: PCA0 Counter/Timer Low Byte. The PCA0L register holds the low byte (LSB) of the 16-bit PCA0 Counter/Timer. Figure 23.14. PCA0H: PCA0 Counter/Timer High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xF9 Bits 7-0: PCA0H: PCA0 Counter/Timer High Byte. The PCA0H register holds the high byte (MSB) of the 16-bit PCA0 Counter/Timer. 262 Rev. 1.4

C8051F020/1/2/3 Figure 23.15. PCA0CPLn: PCA0 Capture Module Low Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xEA - 0xEE PCA0CPLn Address: PCA0CPL0 = 0xEA (n = 0) PCA0CPL1 = 0xEB (n = 1) PCA0CPL2 = 0xEC (n = 2) PCA0CPL3 = 0xED (n = 3) PCA0CPL4 = 0xEE (n = 4) Bits7-0: PCA0CPLn: PCA0 Capture Module Low Byte. The PCA0CPLn register holds the low byte (LSB) of the 16-bit capture module n. Figure 23.16. PCA0CPHn: PCA0 Capture Module High Byte R/W R/W R/W R/W R/W R/W R/W R/W Reset Value 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 SFR Address: 0xFA - 0xFE PCA0CPHn Address: PCA0CPH0 = 0xFA (n = 0) PCA0CPH1 = 0xFB (n = 1) PCA0CPH2 = 0xFC (n = 2) PCA0CPH3 = 0xFD (n = 3) PCA0CPH4 = 0xFE (n = 4) Bits7-0: PCA0CPHn: PCA0 Capture Module High Byte. The PCA0CPHn register holds the high byte (MSB) of the 16-bit capture module n. Rev. 1.4 263

C8051F020/1/2/3 Notes 264 Rev. 1.4

C8051F020/1/2/3 24. JTAG (IEEE 1149.1) Each MCU has an on-chip JTAG interface and logic to support boundary scan for production and in-system testing, Flash read/write operations, and non-intrusive in-circuit debug. The JTAG interface is fully compliant with the IEEE 1149.1 specification. Refer to this specification for detailed descriptions of the Test Interface and Boundary-Scan Architecture. Access of the JTAG Instruction Register (IR) and Data Registers (DR) are as described in the Test Access Port and Operation of the IEEE 1149.1 specification. The JTAG interface is accessed via four dedicated pins on the MCU: TCK, TMS, TDI, and TDO. Through the 16-bit JTAG Instruction Register (IR), any of the seven instructions shown in Figure 24.1 can be com- manded. There are three DR’s associated with JTAG Boundary-Scan, and four associated with Flash read/write oper- ations on the MCU. Figure 24.1. IR: JTAG Instruction Register Reset Value 0x0000 Bit15 Bit0 IR Value Instruction Description 0x0000 EXTEST Selects the Boundary Data Register for control and observability of all device pins SAMPLE/ Selects the Boundary Data Register for observability and presetting the scan-path 0x0002 PRELOAD latches 0x0004 IDCODE Selects device ID Register 0xFFFF BYPASS Selects Bypass Data Register Selects FLASHCON Register to control how the interface logic responds to reads 0x0082 Flash Control and writes to the FLASHDAT Register 0x0083 Flash Data Selects FLASHDAT Register for reads and writes to the Flash memory Selects FLASHADR Register which holds the address of all Flash read, write, and 0x0084 Flash Address erase operations Rev. 1.4 265

C8051F020/1/2/3 24.1. Boundary Scan The DR in the Boundary Scan path is an 134-bit shift register. The Boundary DR provides control and observability of all the device pins as well as the SFR bus and Weak Pullup feature via the EXTEST and SAMPLE commands. Table 24.1. Boundary Data Register Bit Definitions EXTEST provides access to both capture and update actions, while Sample only performs a capture. Bit Action Target 0 Capture Reset Enable from MCU (C8051F021/3 devices) Update Reset Enable to /RST pin (C8051F021/3 devices) 1 Capture Reset input from /RST pin (C8051F021/3 devices) Update Reset output to /RST pin (C8051F021/3 devices) 2 Capture Reset Enable from MCU (C8051F020/2 devices) Update Reset Enable to /RST pin (C8051F020/2 devices) 3 Capture Reset input from /RST pin (C8051F020/2 devices) Update Reset output to /RST pin (C8051F020/2 devices) 4 Capture External Clock from XTAL1 pin Update Not used 5 Capture Weak pullup enable from MCU Update Weak pullup enable to Port Pins 6, 8, 10, 12, 14, 16, Capture P0.n output enable from MCU (e.g. Bit6=P0.0, Bit8=P0.1, etc.) 18, 20 Update P0.n output enable to pin (e.g. Bit6=P0.0oe, Bit8=P0.1oe, etc.) 7, 9, 11, 13, 15, 17, Capture P0.n input from pin (e.g. Bit7=P0.0, Bit9=P0.1, etc.) 19, 21 Update P0.n output to pin (e.g. Bit7=P0.0, Bit9=P0.1, etc.) 22, 24, 26, 28, 30, Capture P1.n output enable from MCU 32, 34, 36 Update P1.n output enable to pin 23, 25, 27, 29, 31, Capture P1.n input from pin 33, 35, 37 Update P1.n output to pin 38, 40, 42, 44, 46, Capture P2.n output enable from MCU 48, 50, 52 Update P2.n output enable to pin 39, 41, 43, 45, 47, Capture P2.n input from pin 49, 51, 53 Update P2.n output to pin 54, 56, 58, 60, 62, Capture P3.n output enable from MCU 64, 66, 68 Update P3.n output enable to pin 55, 57, 59, 61, 63, Capture P3.n input from pin 65, 67, 69 Update P3.n output to pin 70, 72, 74, 76, 78, Capture P4.n output enable from MCU 80, 82, 84 Update P4.n output enable to pin 71, 73, 75, 77, 79, Capture P4.n input from pin 81, 83, 85 Update P4.n output to pin 86, 88, 90, 92, 94, Capture P5.n output enable from MCU 96, 98, 100 Update P5.n output enable to pin 87, 89, 91, 93, 95, Capture P5.n input from pin 97, 99, 101 Update P5.n output to pin 102, 104, 106, 108, Capture P6.n output enable from MCU 110, 112, 114, 116 Update P6.n output enable to pin 103, 105, 107, 109, Capture P6.n input from pin 111, 113, 115, 117 Update P6.n output to pin 266 Rev. 1.4

C8051F020/1/2/3 Table 24.1. Boundary Data Register Bit Definitions Bit Action Target 118, 120, 122, 124, Capture P7.n output enable from MCU 126, 128, 130, 132 Update P7.n output enable to pin 119, 121, 123, 125, Capture P7.n input from pin 127, 129, 131, 133 Update P7.n output to pin 24.1.1. EXTEST Instruction The EXTEST instruction is accessed via the IR. The Boundary DR provides control and observability of all the device pins as well as the Weak Pullup feature. All inputs to on-chip logic are set to logic 1. 24.1.2. SAMPLE Instruction The SAMPLE instruction is accessed via the IR. The Boundary DR provides observability and presetting of the scan- path latches. 24.1.3. BYPASS Instruction The BYPASS instruction is accessed via the IR. It provides access to the standard JTAG Bypass data register. 24.1.4. IDCODE Instruction The IDCODE instruction is accessed via the IR. It provides access to the 32-bit Device ID register. Figure 24.2. DEVICEID: JTAG Device ID Register Reset Value Version Part Number Manufacturer ID 1 0xn0003243 Bit31 Bit28 Bit27 Bit12 Bit11 Bit1 Bit0 Version = 0000b Part Number = 0000 0000 0000 0011b (C8051F020/1/2/3) Manufacturer ID = 0010 0100 001b (Silicon Labs) Rev. 1.4 267

C8051F020/1/2/3 24.2. Flash Programming Commands The Flash memory can be programmed directly over the JTAG interface using the Flash Control, Flash Data, Flash Address, and Flash Scale registers. These Indirect Data Registers are accessed via the JTAG Instruction Register. Read and write operations on indirect data registers are performed by first setting the appropriate DR address in the IR register. Each read or write is then initiated by writing the appropriate Indirect Operation Code (IndOpCode) to the selected data register. Incoming commands to this register have the following format: 19:18 17:0 IndOpCode WriteData IndOpCode: These bit set the operation to perform according to the following table: IndOpCode Operation 0x Poll 10 Read 11 Write The Poll operation is used to check the Busy bit as described below. Although a Capture-DR is performed, no Update-DR is allowed for the Poll operation. Since updates are disabled, polling can be accomplished by shifting in/ out a single bit. The Read operation initiates a read from the register addressed by the DRAddress. Reads can be initiated by shifting only 2 bits into the indirect register. After the read operation is initiated, polling of the Busy bit must be performed to determine when the operation is complete. The write operation initiates a write of WriteData to the register addressed by DRAddress. Registers of any width up to 18 bits can be written. If the register to be written contains fewer than 18 bits, the data in WriteData should be left- justified, i.e. its MSB should occupy bit 17 above. This allows shorter registers to be written in fewer JTAG clock cycles. For example, an 8-bit register could be written by shifting only 10 bits. After a Write is initiated, the Busy bit should be polled to determine when the next operation can be initiated. The contents of the Instruction Register should not be altered while either a read or write operation is busy. Outgoing data from the indirect Data Register has the following format: 19 18:1 0 0 ReadData Busy The Busy bit indicates that the current operation is not complete. It goes high when an operation is initiated and returns low when complete. Read and Write commands are ignored while Busy is high. In fact, if polling for Busy to be low will be followed by another read or write operation, JTAG writes of the next operation can be made while checking for Busy to be low. They will be ignored until Busy is read low, at which time the new operation will initi- ate. This bit is placed ate bit 0 to allow polling by single-bit shifts. When waiting for a Read to complete and Busy is 0, the following 18 bits can be shifted out to obtain the resulting data. ReadData is always right-justified. This allows registers shorter than 18 bits to be read using a reduced number of shifts. For example, the results from a byte-read requires 9 bit shifts (Busy + 8 bits). 268 Rev. 1.4

C8051F020/1/2/3 Figure 24.3. FLASHCON: JTAG Flash Control Register Reset Value SFLE WRMD2 WRMD1 WRMD0 RDMD3 RDMD2 RDMD1 RDMD0 00000000 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 This register determines how the Flash interface logic will respond to reads and writes to the FLASHDAT Register. Bit7: SFLE: Scratchpad FLASH Memory Access Enable. When this bit is set, FLASH reads and writes are directed to the 128-byte Scratchpad FLASH sector. When SFLE is set to logic 1, FLASH accesses out of the address range 0x00-0x7F should not be attempted. Reads/Writes out of this range will yield unpredictable results. 0: FLASH access directed to the 64k byte Program/Data FLASH sector. 1: FLASH access directed to the 128 byte Scratchpad sector. Bits6-4: WRMD2-0: Write Mode Select Bits. The Write Mode Select Bits control how the interface logic responds to writes to the FLASHDAT Register per the following values: 000: A FLASHDAT write replaces the data in the FASHDAT register, but is otherwise ignored. 001: A FLASHDAT write initiates a write of FLASHDAT into the memory address by the FLASHADR register. FLASHADR is incremented by one when complete. 010: A FLASHDAT write initiates an erasure (sets all bytes to 0xFF) of the Flash page containing the address in FLASHADR. The data written must be 0xA5 for the erase to occur. FLASHADR is not affected. If FLASHADR = 0x7DFE - 0x7DFF, the entire user space will be erased (i.e. entire Flash memory except for Reserved area 0x7E00 - 0x7FFF). (All other values for WRMD3-0 are reserved.) Bits3-0: RDMD3-0: Read Mode Select Bits. The Read Mode Select Bits control how the interface logic responds to reads to the FLASHDAT Reg- ister per the following values: 0000: A FLASHDAT read provides the data in the FASHDAT register, but is otherwise ignored. 0001: A FLASHDAT read initiates a read of the byte addressed by the FLASHADR register if no operation is currently active. This mode is used for block reads. 0010: A FLASHDAT read initiates a read of the byte addressed by FLASHADR only if no operation is active and any data from a previous read has already been read from FLASHDAT. This mode allows single bytes to be read (or the last byte of a block) without initiating an extra read. (All other values for RDMD3-0 are reserved.) Rev. 1.4 269

C8051F020/1/2/3 Figure 24.4. FLASHADR: JTAG Flash Address Register Reset Value 0x0000 Bit15 Bit0 This register holds the address for all JTAG Flash read, write, and erase operations. This register autoincrements after each read or write, regardless of whether the operation succeeded or failed. Bits15-0: Flash Operation 16-bit Address. Figure 24.5. FLASHDAT: JTAG Flash Data Register Reset Value 0000000000 Bit9 Bit0 This register is used to read or write data to the Flash memory across the JTAG interface. Bits9-2: DATA7-0: Flash Data Byte. Bit1: FAIL: Flash Fail Bit. 0: Previous Flash memory operation was successful. 1: Previous Flash memory operation failed. Usually indicates the associated memory location was locked. Bit0: BUSY: Flash Busy Bit. 0: Flash interface logic is not busy. 1: Flash interface logic is processing a request. Reads or writes while BUSY = 1 will not initiate another operation 270 Rev. 1.4

C8051F020/1/2/3 24.3. Debug Support Each MCU has on-chip JTAG and debug logic that provides non-intrusive, full speed, in-circuit debug support using the production part installed in the end application, via the four pin JTAG I/F. Silicon Labs' debug system supports inspection and modification of memory and registers, breakpoints, and single stepping. No additional target RAM, program memory, or communications channels are required. All the digital and analog peripherals are functional and work correctly (remain synchronized) while debugging. The Watchdog Timer (WDT) is disabled when the MCU is halted during single stepping or at a breakpoint. The C8051F020DK is a development kit with all the hardware and software necessary to develop application code and perform in-circuit debug with each MCU in the C8051F020 family. Each kit includes an Integrated Development Environment (IDE) which has a debugger and integrated 8051 assembler. The kit also includes an RS-232 to JTAG interface module referred to as the Serial Adapter, a target application board with a C8051F020 installed, RS-232 and JTAG cables, and wall-mount power supply. Rev. 1.4 271

Simplicity Studio One-click access to MCU and wireless tools, documentation, software, source code libraries & more. Available for Windows, Mac and Linux! IoT Portfolio SW/HW Quality Support and Community www.silabs.com/IoT www.silabs.com/simplicity www.silabs.com/quality community.silabs.com Disclaimer Silicon Laboratories intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Laboratories products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Laboratories reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Laboratories shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products must not be used within any Life Support System without the specific written consent of Silicon Laboratories. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Laboratories products are generally not intended for military applications. Silicon Laboratories products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons. Trademark Information Silicon Laboratories Inc., Silicon Laboratories, Silicon Labs, SiLabs and the Silicon Labs logo, CMEMS®, EFM, EFM32, EFR, Energy Micro, Energy Micro logo and combinations thereof, "the world’s most energy friendly microcontrollers", Ember®, EZLink®, EZMac®, EZRadio®, EZRadioPRO®, DSPLL®, ISOmodem ®, Precision32®, ProSLIC®, SiPHY®, USBXpress® and others are trademarks or registered trademarks of Silicon Laboratories Inc. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders. Silicon Laboratories Inc. 400 West Cesar Chavez Austin, TX 78701 USA http://www.silabs.com