C 8051 F 04 X
C 8051 F 04 X
C 8051 F 04 X
12-bit (C8051F040/1) or
10-bit (C8051F042/3/4/5/6/7) resolution
1 LSB INL, guaranteed no missing codes
Programmable throughput up to 100 ksps
13 External Inputs; single-ended or differential
SW programmable high voltage difference amplifier
Programmable amplifier gain: 16, 8, 4, 2, 1, 0.5
Data-dependent windowed interrupt generator
Built-in temperature sensor
Digital Peripherals
- 8 byte-wide port I/O (C8051F040/2/4/6); 5 V tolerant
- 4 byte-wide port I/O (C8051F041/3/5/7); 5 V tolerant
- Bosch Controller Area Network (CAN 2.0B), hard-
Clock Sources
- Internal calibrated programmable oscillator: 3 to
- Voltage Reference
- Precision VDD Monitor/Brown-Out Detector
On-Chip JTAG Debug & Boundary Scan
- On-chip debug circuitry facilitates full- speed, non-
24.5 MHz
ANALOG PERIPHERALS
AMUX
TEMP
SENSOR
PGA
12/10-bit
100 ksps
UART0
ADC
SMBus
AMUX
VREF
12-Bit
DAC
PGA
C8051F041/2/3
ONLY
UART1
SPI Bus
8-bit
500 ksps
ADC
12-Bit
DAC
DIGITAL I/O
CAN
2.0B
HV
DIFF
AMP
VOLTAGE COMPARATORS
PCA
Timer 0
Timer 1
Timer 2
CROSSBAR
Port 0
Port 1
External Memory Interface
Memory
- 4352 bytes internal data RAM (4 k + 256)
- 64 kB (C8051F040/1/2/3/4/5)
Timer 3
Port 2
Port 3
Port 4
Port 5
Port 6
Port 7
Timer 4
64 kB/32 kB
ISP FLASH
DEBUG
CIRCUITRY
4352 B
JTAG
SRAM
CLOCK
SANITY
CIRCUIT
CONTROL
C8051F04x
C8051F040/1/2/3/4/5/6/7
NOTES:
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table of Contents
1. System Overview.................................................................................................... 19
1.1. CIP-51 Microcontroller Core.......................................................................... 25
1.1.1. Fully 8051 Compatible.............................................................................. 25
1.1.2. Improved Throughput ............................................................................... 25
1.1.3. Additional Features .................................................................................. 26
1.2. On-Chip Memory............................................................................................... 27
1.3. JTAG Debug and Boundary Scan..................................................................... 28
1.4. Programmable Digital I/O and Crossbar ........................................................... 29
1.5. Programmable Counter Array ........................................................................... 30
1.6. Controller Area Network.................................................................................... 31
1.7. Serial Ports ....................................................................................................... 31
1.8. 12/10-Bit Analog to Digital Converter................................................................ 32
1.9. 8-Bit Analog to Digital Converter (C8051F040/1/2/3 Only) ............................... 33
1.10.Comparators and DACs ................................................................................... 34
2. Absolute Maximum Ratings .................................................................................. 35
3. Global DC Electrical Characteristic ...................................................................... 36
4. Pinout and Package Definitions............................................................................ 37
5. 12-Bit ADC (ADC0, C8051F040/1 Only)................................................................. 47
5.1. Analog Multiplexer and PGA............................................................................. 47
5.1.1. Analog Input Configuration....................................................................... 48
5.2. High Voltage Difference Amplifier ..................................................................... 52
5.3. ADC Modes of Operation.................................................................................. 54
5.3.1. Starting a Conversion............................................................................... 54
5.3.2. Tracking Modes........................................................................................ 54
5.3.3. Settling Time Requirements ..................................................................... 56
5.4. ADC0 Programmable Window Detector ........................................................... 62
6. 10-Bit ADC (ADC0, C8051F042/3/4/5/6/7 Only)..................................................... 69
6.1. Analog Multiplexer and PGA............................................................................. 69
6.1.1. Analog Input Configuration....................................................................... 70
6.2. High Voltage Difference Amplifier ..................................................................... 74
6.3. ADC Modes of Operation.................................................................................. 76
6.3.1. Starting a Conversion............................................................................... 76
6.3.2. Tracking Modes........................................................................................ 76
6.3.3. Settling Time Requirements ..................................................................... 78
6.4. ADC0 Programmable Window Detector ........................................................... 84
7. 8-Bit ADC (ADC2, C8051F040/1/2/3 Only)............................................................. 91
7.1. Analog Multiplexer and PGA............................................................................. 91
7.2. ADC2 Modes of Operation................................................................................ 92
7.2.1. Starting a Conversion............................................................................... 92
7.2.2. Tracking Modes........................................................................................ 92
7.2.3. Settling Time Requirements ..................................................................... 94
7.3. ADC2 Programmable Window Detector ......................................................... 100
7.3.1. Window Detector In Single-Ended Mode ............................................... 100
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
7.3.2. Window Detector In Differential Mode.................................................... 102
8. DACs, 12-Bit Voltage Mode (C8051F040/1/2/3 Only) ......................................... 105
8.1. DAC Output Scheduling.................................................................................. 106
8.1.1. Update Output On-Demand ................................................................... 106
8.1.2. Update Output Based on Timer Overflow .............................................. 106
8.2. DAC Output Scaling/Justification .................................................................... 106
9. Voltage Reference (C8051F040/2/4/6) ................................................................. 113
10. Voltage Reference (C8051F041/3/5/7) ................................................................. 117
11. Comparators ......................................................................................................... 121
11.1.Comparator Inputs.......................................................................................... 123
12. CIP-51 Microcontroller ......................................................................................... 127
12.1.Instruction Set................................................................................................. 129
12.1.1.Instruction and CPU Timing ................................................................... 129
12.1.2.MOVX Instruction and Program Memory ............................................... 129
12.2.Memory Organization ..................................................................................... 133
12.2.1.Program Memory ................................................................................... 133
12.2.2.Data Memory.......................................................................................... 134
12.2.3.General Purpose Registers.................................................................... 134
12.2.4.Bit Addressable Locations...................................................................... 134
12.2.5.Stack ..................................................................................................... 134
12.2.6.Special Function Registers .................................................................... 135
12.2.7.Register Descriptions ............................................................................. 151
12.3.Interrupt Handler............................................................................................. 154
12.3.1.MCU Interrupt Sources and Vectors ...................................................... 154
12.3.2.External Interrupts.................................................................................. 155
12.3.3.Interrupt Priorities................................................................................... 157
12.3.4.Interrupt Latency .................................................................................... 157
12.3.5.Interrupt Register Descriptions............................................................... 157
12.4.Power Management Modes............................................................................ 164
12.4.1.Idle Mode ............................................................................................... 164
12.4.2.Stop Mode.............................................................................................. 165
13. Reset Sources....................................................................................................... 167
13.1.Power-on Reset.............................................................................................. 168
13.2.Power-Fail Reset ............................................................................................ 168
13.3.External Reset ................................................................................................ 168
13.4.Missing Clock Detector Reset ........................................................................ 169
13.5.Comparator0 Reset ........................................................................................ 169
13.6.External CNVSTR0 Pin Reset ........................................................................ 169
13.7.Watchdog Timer Reset................................................................................... 169
13.7.1.Enable/Reset WDT ................................................................................ 170
13.7.2.Disable WDT .......................................................................................... 170
13.7.3.Disable WDT Lockout ............................................................................ 170
13.7.4.Setting WDT Interval .............................................................................. 170
14. Oscillators ............................................................................................................. 175
14.1.Programmable Internal Oscillator ................................................................... 175
4
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
14.2.External Oscillator Drive Circuit...................................................................... 177
14.3.System Clock Selection.................................................................................. 177
14.4.External Crystal Example ............................................................................... 179
14.5.External RC Example ..................................................................................... 180
14.6.External Capacitor Example ........................................................................... 180
15. Flash Memory ....................................................................................................... 181
15.1.Programming The Flash Memory ................................................................... 181
15.2.Non-volatile Data Storage .............................................................................. 182
15.3.Security Options ............................................................................................. 182
15.3.1.Summary of Flash Security Options....................................................... 184
16. External Data Memory Interface and On-Chip XRAM........................................ 189
16.1.Accessing XRAM............................................................................................ 189
16.1.1.16-Bit MOVX Example ........................................................................... 189
16.1.2.8-Bit MOVX Example ............................................................................. 189
16.2.Configuring the External Memory Interface .................................................... 190
16.3.Port Selection and Configuration.................................................................... 190
16.4.Multiplexed and Non-multiplexed Selection.................................................... 193
16.4.1.Multiplexed Configuration....................................................................... 193
16.4.2.Non-multiplexed Configuration............................................................... 194
16.5.Memory Mode Selection................................................................................. 195
16.5.1.Internal XRAM Only ............................................................................... 195
16.5.2.Split Mode without Bank Select.............................................................. 195
16.5.3.Split Mode with Bank Select................................................................... 196
16.5.4.External Only.......................................................................................... 196
16.6.Timing .......................................................................................................... 196
16.6.1.Non-multiplexed Mode ........................................................................... 198
16.6.2.Multiplexed Mode ................................................................................... 201
17. Port Input/Output.................................................................................................. 205
17.1.Ports 0 through 3 and the Priority Crossbar Decoder..................................... 206
17.1.1.Crossbar Pin Assignment and Allocation ............................................... 207
17.1.2.Configuring the Output Modes of the Port Pins...................................... 208
17.1.3.Configuring Port Pins as Digital Inputs................................................... 209
17.1.4.Weak Pullups ......................................................................................... 209
17.1.5.Configuring Port 1, 2, and 3 Pins as Analog Inputs ............................... 209
17.1.6.External Memory Interface Pin Assignments ......................................... 210
17.1.7.Crossbar Pin Assignment Example........................................................ 212
17.2.Ports 4 through 7 ............................................................................................ 222
17.2.1.Configuring Ports which are not Pinned Out .......................................... 223
17.2.2.Configuring the Output Modes of the Port Pins...................................... 223
17.2.3.Configuring Port Pins as Digital Inputs................................................... 223
17.2.4.Weak Pull-ups ........................................................................................ 223
17.2.5.External Memory Interface ..................................................................... 223
18. Controller Area Network (CAN0) ......................................................................... 229
18.1.Bosch CAN Controller Operation.................................................................... 230
18.1.1.CAN Controller Timing ........................................................................... 231
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
18.1.2.Example Timing Calculation for 1 Mbit/Sec Communication ................. 231
18.2.CAN Registers................................................................................................ 233
18.2.1.CAN Controller Protocol Registers......................................................... 233
18.2.2.Message Object Interface Registers ...................................................... 233
18.2.3.Message Handler Registers................................................................... 234
18.2.4.CIP-51 MCU Special Function Registers ............................................... 234
18.2.5.Using CAN0ADR, CAN0DATH, and CANDATL to
Access CAN Registers .......................................................................... 234
18.2.6.CAN0ADR Autoincrement Feature ........................................................ 234
19. System Management BUS / I2C BUS (SMBUS0)................................................ 241
19.1.Supporting Documents ................................................................................... 242
19.2.SMBus Protocol.............................................................................................. 243
19.2.1.Arbitration............................................................................................... 243
19.2.2.Clock Low Extension.............................................................................. 244
19.2.3.SCL Low Timeout................................................................................... 244
19.2.4.SCL High (SMBus Free) Timeout .......................................................... 244
19.3.SMBus Transfer Modes.................................................................................. 244
19.3.1.Master Transmitter Mode ....................................................................... 244
19.3.2.Master Receiver Mode ........................................................................... 245
19.3.3.Slave Transmitter Mode ......................................................................... 245
19.3.4.Slave Receiver Mode ............................................................................. 246
19.4.SMBus Special Function Registers ................................................................ 247
19.4.1.Control Register ..................................................................................... 247
19.4.2.Clock Rate Register ............................................................................... 250
19.4.3.Data Register ......................................................................................... 251
19.4.4.Address Register.................................................................................... 251
19.4.5.Status Register....................................................................................... 252
20. Enhanced Serial Peripheral Interface (SPI0)...................................................... 257
20.1.Signal Descriptions......................................................................................... 258
20.1.1.Master Out, Slave In (MOSI).................................................................. 258
20.1.2.Master In, Slave Out (MISO).................................................................. 258
20.1.3.Serial Clock (SCK) ................................................................................. 258
20.1.4.Slave Select (NSS) ................................................................................ 258
20.2.SPI0 Master Mode Operation ......................................................................... 259
20.3.SPI0 Slave Mode Operation ........................................................................... 261
20.4.SPI0 Interrupt Sources ................................................................................... 261
20.5.Serial Clock Timing......................................................................................... 262
20.6.SPI Special Function Registers ...................................................................... 263
21. UART0.................................................................................................................... 267
21.1.UART0 Operational Modes ............................................................................ 268
21.1.1.Mode 0: Synchronous Mode .................................................................. 268
21.1.2.Mode 1: 8-Bit UART, Variable Baud Rate.............................................. 269
21.1.3.Mode 2: 9-Bit UART, Fixed Baud Rate .................................................. 271
21.1.4.Mode 3: 9-Bit UART, Variable Baud Rate.............................................. 272
21.2.Multiprocessor Communications .................................................................... 272
6
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
21.3.Configuration of a Masked Address ............................................................... 273
21.4.Broadcast Addressing .................................................................................... 273
21.5.Frame and Transmission Error Detection....................................................... 274
22. UART1.................................................................................................................... 279
22.1.Enhanced Baud Rate Generation................................................................... 280
22.2.Operational Modes ......................................................................................... 281
22.2.1.8-Bit UART ............................................................................................. 281
22.2.2.9-Bit UART ............................................................................................. 282
22.3.Multiprocessor Communications .................................................................... 283
23. Timers.................................................................................................................... 289
23.1.Timer 0 and Timer 1 ....................................................................................... 289
23.1.1.Mode 0: 13-bit Counter/Timer ................................................................ 289
23.1.2.Mode 1: 16-bit Counter/Timer ................................................................ 290
23.1.3.Mode 2: 8-bit Counter/Timer with Auto-Reload...................................... 291
23.1.4.Mode 3: Two 8-bit Counter/Timers (Timer 0 Only)................................. 292
23.2.Timer 2, Timer 3, and Timer 4 ........................................................................ 297
23.2.1.Configuring Timer 2, 3, and 4 to Count Down........................................ 297
23.2.2.Capture Mode ........................................................................................ 298
23.2.3.Auto-Reload Mode ................................................................................. 299
23.2.4.Toggle Output Mode .............................................................................. 300
24. Programmable Counter Array ............................................................................. 305
24.1.PCA Counter/Timer ........................................................................................ 306
24.2.Capture/Compare Modules ............................................................................ 307
24.2.1.Edge-triggered Capture Mode................................................................ 308
24.2.2.Software Timer (Compare) Mode........................................................... 309
24.2.3.High Speed Output Mode....................................................................... 310
24.2.4.Frequency Output Mode ........................................................................ 311
24.2.5.8-Bit Pulse Width Modulator Mode......................................................... 312
24.2.6.16-Bit Pulse Width Modulator Mode....................................................... 313
24.3.Register Descriptions for PCA0...................................................................... 314
25. JTAG (IEEE 1149.1) .............................................................................................. 319
25.1.Boundary Scan ............................................................................................... 320
25.1.1.EXTEST Instruction................................................................................ 321
25.1.2.SAMPLE Instruction ............................................................................... 321
25.1.3.BYPASS Instruction ............................................................................... 321
25.1.4.IDCODE Instruction................................................................................ 321
25.2.Flash Programming Commands..................................................................... 323
25.3.Debug Support ............................................................................................... 326
Document Change List............................................................................................. 327
Contact Information.................................................................................................. 328
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
NOTES:
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
List of Figures
1. System Overview
Figure 1.1. C8051F040/2 Block Diagram ................................................................. 21
Figure 1.2. C8051F041/3 Block Diagram ................................................................. 22
Figure 1.3. C8051F044/6 Block Diagram ................................................................. 23
Figure 1.4. C8051F045/7 Block Diagram ................................................................. 24
Figure 1.5. Comparison of Peak MCU Execution Speeds ....................................... 25
Figure 1.6. On-Board Clock and Reset .................................................................... 26
Figure 1.7. On-Chip Memory Map............................................................................ 27
Figure 1.8. Development/In-System Debug Diagram............................................... 28
Figure 1.9. Digital Crossbar Diagram ....................................................................... 29
Figure 1.10. PCA Block Diagram.............................................................................. 30
Figure 1.11. CAN Controller Diagram....................................................................... 31
Figure 1.12. 10/12-Bit ADC Block Diagram .............................................................. 32
Figure 1.13. 8-Bit ADC Diagram............................................................................... 33
Figure 1.14. Comparator and DAC Diagram ............................................................ 34
2. Absolute Maximum Ratings
3. Global DC Electrical Characteristic
4. Pinout and Package Definitions
Figure 4.1. TQFP-100 Pinout Diagram..................................................................... 42
Figure 4.2. TQFP-100 Package Drawing ................................................................. 43
Figure 4.3. TQFP-64 Pinout Diagram....................................................................... 44
Figure 4.4. TQFP-64 Package Drawing ................................................................... 45
5. 12-Bit ADC (ADC0, C8051F040/1 Only)
Figure 5.1. 12-Bit ADC0 Functional Block Diagram ................................................. 47
Figure 5.2. Analog Input Diagram ............................................................................ 48
Figure 5.3. High Voltage Difference Amplifier Functional Diagram .......................... 52
Figure 5.4. 12-Bit ADC Track and Conversion Example Timing .............................. 55
Figure 5.5. ADC0 Equivalent Input Circuits.............................................................. 56
Figure 5.6. Temperature Sensor Transfer Function ................................................. 57
Figure 5.7. ADC0 Data Word Example .................................................................... 61
Figure 5.8. 12-Bit ADC0 Window Interrupt Example:
Right Justified Single-Ended Data ........................................................ 63
Figure 5.9. 12-Bit ADC0 Window Interrupt Example:
Right Justified Differential Data............................................................. 64
Figure 5.10. 12-Bit ADC0 Window Interrupt Example:
Left Justified Single-Ended Data........................................................... 65
Figure 5.11. 12-Bit ADC0 Window Interrupt Example:
Left Justified Differential Data ............................................................... 66
6. 10-Bit ADC (ADC0, C8051F042/3/4/5/6/7 Only)
Figure 6.1. 10-Bit ADC0 Functional Block Diagram ................................................. 69
Figure 6.2. Analog Input Diagram ............................................................................ 70
Figure 6.3. High Voltage Difference Amplifier Functional Diagram .......................... 74
Figure 6.4. 10-Bit ADC Track and Conversion Example Timing .............................. 77
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Figure 6.5.
Figure 6.6.
Figure 6.7.
Figure 6.8.
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16. External Data Memory Interface and On-Chip XRAM
Figure 16.1. Multiplexed Configuration Example.................................................... 193
Figure 16.2. Non-multiplexed Configuration Example ............................................ 194
Figure 16.3. EMIF Operating Modes ...................................................................... 195
Figure 16.4. Non-multiplexed 16-bit MOVX Timing ................................................ 198
Figure 16.5. Non-multiplexed 8-bit MOVX without Bank Select Timing ................. 199
Figure 16.6. Non-multiplexed 8-bit MOVX with Bank Select Timing ...................... 200
Figure 16.7. Multiplexed 16-bit MOVX Timing........................................................ 201
Figure 16.8. Multiplexed 8-bit MOVX without Bank Select Timing ......................... 202
Figure 16.9. Multiplexed 8-bit MOVX with Bank Select Timing .............................. 203
17. Port Input/Output
Figure 17.1. Port I/O Cell Block Diagram ............................................................... 205
Figure 17.2. Port I/O Functional Block Diagram ..................................................... 206
Figure 17.3. Priority Crossbar Decode Table ......................................................... 207
Figure 17.4. Priority Crossbar Decode Table ......................................................... 210
Figure 17.5. Priority Crossbar Decode Table ......................................................... 211
Figure 17.6. Crossbar Example:............................................................................. 213
18. Controller Area Network (CAN0)
Figure 18.1. Typical CAN Bus Configuration.......................................................... 229
Figure 18.2. CAN Controller Diagram..................................................................... 230
Figure 18.3. Four Segments of a CAN Bit Time ..................................................... 231
Figure 18.4. CAN0DATH: CAN Data Access Register High Byte .......................... 236
19. System Management BUS / I2C BUS (SMBUS0)
Figure 19.1. SMBus0 Block Diagram ..................................................................... 241
Figure 19.2. Typical SMBus Configuration ............................................................. 242
Figure 19.3. SMBus Transaction ............................................................................ 243
Figure 19.4. Typical Master Transmitter Sequence................................................ 244
Figure 19.5. Typical Master Receiver Sequence.................................................... 245
Figure 19.6. Typical Slave Transmitter Sequence.................................................. 245
Figure 19.7. Typical Slave Receiver Sequence...................................................... 246
20. Enhanced Serial Peripheral Interface (SPI0)
Figure 20.1. SPI Block Diagram ............................................................................. 257
Figure 20.2. Multiple-Master Mode Connection Diagram ....................................... 260
Figure 20.3. 3-Wire Single Master and Slave Mode Connection Diagram ............. 260
Figure 20.4. 4-Wire Single Master and Slave Mode Connection Diagram ............. 260
Figure 20.5. Data/Clock Timing Diagram ............................................................... 262
21. UART0
Figure 21.1. UART0 Block Diagram ....................................................................... 267
Figure 21.2. UART0 Mode 0 Timing Diagram ........................................................ 268
Figure 21.3. UART0 Mode 0 Interconnect.............................................................. 269
Figure 21.4. UART0 Mode 1 Timing Diagram ........................................................ 269
Figure 21.5. UART0 Modes 2 and 3 Timing Diagram ............................................ 271
Figure 21.6. UART0 Modes 1, 2, and 3 Interconnect Diagram .............................. 272
Figure 21.7. UART Multi-Processor Mode Interconnect Diagram .......................... 274
Rev. 1.4
11
C8051F040/1/2/3/4/5/6/7
22. UART1
Figure 22.1. UART1 Block Diagram ....................................................................... 279
Figure 22.2. UART1 Baud Rate Logic .................................................................... 280
Figure 22.3. UART Interconnect Diagram .............................................................. 281
Figure 22.4. 8-Bit UART Timing Diagram............................................................... 281
Figure 22.5. 9-Bit UART Timing Diagram............................................................... 282
Figure 22.6. UART Multi-Processor Mode Interconnect Diagram .......................... 283
23. Timers
Figure 23.1. T0 Mode 0 Block Diagram.................................................................. 290
Figure 23.2. T0 Mode 2 Block Diagram.................................................................. 291
Figure 23.3. T0 Mode 3 Block Diagram.................................................................. 292
Figure 23.4. Tn Capture Mode Block Diagram ....................................................... 298
Figure 23.5. Tn Auto-reload Mode Block Diagram ................................................. 299
24. Programmable Counter Array
Figure 24.1. PCA Block Diagram............................................................................ 305
Figure 24.2. PCA Counter/Timer Block Diagram.................................................... 306
Figure 24.3. PCA Interrupt Block Diagram ............................................................. 307
Figure 24.4. PCA Capture Mode Diagram.............................................................. 308
Figure 24.5. PCA Software Timer Mode Diagram .................................................. 309
Figure 24.6. PCA High Speed Output Mode Diagram............................................ 310
Figure 24.7. PCA Frequency Output Mode ............................................................ 311
Figure 24.8. PCA 8-Bit PWM Mode Diagram ......................................................... 312
Figure 24.9. PCA 16-Bit PWM Mode...................................................................... 313
25. JTAG (IEEE 1149.1)
12
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
List of Tables
1. System Overview
Table 1.1. Product Selection Guide ......................................................................... 20
2. Absolute Maximum Ratings
Table 2.1. Absolute Maximum Ratings .................................................................... 35
3. Global DC Electrical Characteristic
Table 3.1. Global DC Electrical Characteristics ....................................................... 36
4. Pinout and Package Definitions
Table 4.1. Pin Definitions ......................................................................................... 37
5. 12-Bit ADC (ADC0, C8051F040/1 Only)
Table 5.1. AMUX Selection Chart (AMX0AD30 and AMX0CF30 bits) ................ 50
Table 5.2. 12-Bit ADC0 Electrical Characteristics ................................................... 67
Table 5.3. High Voltage Difference Amplifier Electrical Characteristics .................. 68
6. 10-Bit ADC (ADC0, C8051F042/3/4/5/6/7 Only)
Table 6.1. AMUX Selection Chart (AMX0AD3-0 and AMX0CF3-0 bits) .................. 72
Table 6.2. 10-Bit ADC0 Electrical Characteristics ................................................... 89
Table 6.3. High Voltage Difference Amplifier Electrical Characteristics .................. 90
7. 8-Bit ADC (ADC2, C8051F040/1/2/3 Only)
Table 7.1. AMUX Selection Chart (AMX2AD2-0 and AMX2CF3-0 bits) .................. 96
Table 7.2. ADC2 Electrical Characteristics ............................................................ 103
8. DACs, 12-Bit Voltage Mode (C8051F040/1/2/3 Only)
Table 8.1. DAC Electrical Characteristics .............................................................. 111
9. Voltage Reference (C8051F040/2/4/6)
Table 9.1. Voltage Reference Electrical Characteristics ....................................... 115
10. Voltage Reference (C8051F041/3/5/7)
Table 10.1. Voltage Reference Electrical Characteristics ..................................... 119
11. Comparators
Table 11.1. Comparator Electrical Characteristics ................................................ 126
12. CIP-51 Microcontroller
Table 12.1. CIP-51 Instruction Set Summary ........................................................ 129
Table 12.2. Special Function Register (SFR) Memory Map .................................. 144
Table 12.3. Special Function Registers ................................................................. 147
Table 12.4. Interrupt Summary .............................................................................. 155
13. Reset Sources
Table 13.1. Reset Electrical Characteristics .......................................................... 173
14. Oscillators
Table 14.1. Internal Oscillator Electrical Characteristics ....................................... 177
15. Flash Memory
Table 15.1. Flash Electrical Characteristics .......................................................... 182
16. External Data Memory Interface and On-Chip XRAM
Table 16.1. AC Parameters for External Memory Interface ................................... 204
17. Port Input/Output
Table 17.1. Port I/O DC Electrical Characteristics ................................................. 205
Rev. 1.4
13
C8051F040/1/2/3/4/5/6/7
18. Controller Area Network (CAN0)
Table 18.1. Background System Information ........................................................ 231
Table 18.2. CAN Register Index and Reset Values .............................................. 235
19. System Management BUS / I2C BUS (SMBUS0)
Table 19.1. SMB0STA Status Codes and States .................................................. 254
20. Enhanced Serial Peripheral Interface (SPI0)
21. UART0
Table 21.1. UART0 Modes .................................................................................... 268
Table 21.2. Oscillator Frequencies for Standard Baud Rates ............................... 275
22. UART1
Table 22.1. Timer Settings for Standard Baud Rates Using
the Internal 24.5 MHz Oscillator ......................................................... 286
Table 22.2. Timer Settings for Standard Baud Rates Using
an External 25.0 MHz Oscillator ......................................................... 286
Table 22.3. Timer Settings for Standard Baud Rates Using
an External 22.1184 MHz Oscillator ................................................... 287
Table 22.4. Timer Settings for Standard Baud Rates Using
an External 18.432 MHz Oscillator ..................................................... 287
Table 22.5. Timer Settings for Standard Baud Rates Using
an External 11.0592 MHz Oscillator ................................................... 288
Table 22.6. Timer Settings for Standard Baud Rates Using
an External 3.6864 MHz Oscillator ..................................................... 288
23. Timers
24. Programmable Counter Array
Table 24.1. PCA Timebase Input Options ............................................................. 306
Table 24.2. PCA0CPM Register Settings for PCA Capture/Compare Modules .... 307
25. JTAG (IEEE 1149.1)
Table 25.1. Boundary Data Register Bit Definitions .............................................. 320
14
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
List of Registers
SFR Definition 5.1. AMX0CF: AMUX0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 49
SFR Definition 5.2. AMX0SL: AMUX0 Channel Select . . . . . . . . . . . . . . . . . . . . . . . . . 49
SFR Definition 5.3. AMX0PRT: Port 3 Pin Selection . . . . . . . . . . . . . . . . . . . . . . . . . . 51
SFR Definition 5.4. HVA0CN: High Voltage Difference Amplifier Control . . . . . . . . . . . 53
SFR Definition 5.5. ADC0CF: ADC0 Configuration Register . . . . . . . . . . . . . . . . . . . . 58
SFR Definition 5.6. ADC0CN: ADC0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
SFR Definition 5.7. ADC0H: ADC0 Data Word MSB . . . . . . . . . . . . . . . . . . . . . . . . . . 60
SFR Definition 5.8. ADC0L: ADC0 Data Word LSB . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
SFR Definition 5.9. ADC0GTH: ADC0 Greater-Than Data High Byte . . . . . . . . . . . . . 62
SFR Definition 5.10. ADC0GTL: ADC0 Greater-Than Data Low Byte . . . . . . . . . . . . . 62
SFR Definition 5.11. ADC0LTH: ADC0 Less-Than Data High Byte . . . . . . . . . . . . . . . 62
SFR Definition 5.12. ADC0LTL: ADC0 Less-Than Data Low Byte . . . . . . . . . . . . . . . . 63
SFR Definition 6.1. AMX0CF: AMUX0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 71
SFR Definition 6.2. AMX0SL: AMUX0 Channel Select . . . . . . . . . . . . . . . . . . . . . . . . 71
SFR Definition 6.3. AMX0PRT: Port 3 Pin Selection . . . . . . . . . . . . . . . . . . . . . . . . . . 73
SFR Definition 6.4. HVA0CN: High Voltage Difference Amplifier Control . . . . . . . . . . . 75
SFR Definition 6.5. ADC0CF: ADC0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
SFR Definition 6.6. ADC0CN: ADC0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
SFR Definition 6.7. ADC0H: ADC0 Data Word MSB . . . . . . . . . . . . . . . . . . . . . . . . . . 82
SFR Definition 6.8. ADC0L: ADC0 Data Word LSB . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
SFR Definition 6.9. ADC0GTH: ADC0 Greater-Than Data High Byte . . . . . . . . . . . . . 84
SFR Definition 6.10. ADC0GTL: ADC0 Greater-Than Data Low Byte . . . . . . . . . . . . . 84
SFR Definition 6.11. ADC0LTH: ADC0 Less-Than Data High Byte . . . . . . . . . . . . . . . 84
SFR Definition 6.12. ADC0LTL: ADC0 Less-Than Data Low Byte . . . . . . . . . . . . . . . . 85
SFR Definition 7.1. AMX2CF: AMUX2 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 95
SFR Definition 7.2. AMX2SL: AMUX2 Channel Select . . . . . . . . . . . . . . . . . . . . . . . . . 95
SFR Definition 7.3. ADC2CF: ADC2 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
SFR Definition 7.4. ADC2CN: ADC2 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
SFR Definition 7.5. ADC2: ADC2 Data Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
SFR Definition 7.6. ADC2GT: ADC2 Greater-Than Data . . . . . . . . . . . . . . . . . . . . . . 100
SFR Definition 7.7. ADC2LT: ADC2 Less-Than Data . . . . . . . . . . . . . . . . . . . . . . . . . 100
SFR Definition 8.1. DAC0H: DAC0 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
SFR Definition 8.2. DAC0L: DAC0 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
SFR Definition 8.3. DAC0CN: DAC0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
SFR Definition 8.4. DAC1H: DAC1 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
SFR Definition 8.5. DAC1L: DAC1 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
SFR Definition 8.6. DAC1CN: DAC1 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
SFR Definition 9.1. REF0CN: Reference Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
SFR Definition 10.1. REF0CN: Reference Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
SFR Definition 11.1. CPTnCN: Comparator 0, 1, and 2 Control . . . . . . . . . . . . . . . . . 124
SFR Definition 11.2. CPTnMD: Comparator Mode Selection . . . . . . . . . . . . . . . . . . . 125
SFR Definition 12.1. SFR Page Control Register: SFRPGCN . . . . . . . . . . . . . . . . . . 142
SFR Definition 12.2. SFR Page Register: SFRPAGE . . . . . . . . . . . . . . . . . . . . . . . . . 142
Rev. 1.4
15
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.3. SFR Next Register: SFRNEXT . . . . . . . . . . . . . . . . . . . . . . . . . 143
SFR Definition 12.4. SFR Last Register: SFRLAST . . . . . . . . . . . . . . . . . . . . . . . . . . 146
SFR Definition 12.5. SP: Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
SFR Definition 12.6. DPL: Data Pointer Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
SFR Definition 12.7. DPH: Data Pointer High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
SFR Definition 12.8. PSW: Program Status Word . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
SFR Definition 12.9. ACC: Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
SFR Definition 12.10. B: B Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
SFR Definition 12.11. IE: Interrupt Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
SFR Definition 12.12. IP: Interrupt Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
SFR Definition 12.13. EIE1: Extended Interrupt Enable 1 . . . . . . . . . . . . . . . . . . . . . 160
SFR Definition 12.14. EIE2: Extended Interrupt Enable 2 . . . . . . . . . . . . . . . . . . . . . 161
SFR Definition 12.15. EIP1: Extended Interrupt Priority 1 . . . . . . . . . . . . . . . . . . . . . 162
SFR Definition 12.16. EIP2: Extended Interrupt Priority 2 . . . . . . . . . . . . . . . . . . . . . 163
SFR Definition 12.18. PCON: Power Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
SFR Definition 13.1. WDTCN: Watchdog Timer Control . . . . . . . . . . . . . . . . . . . . . . 171
SFR Definition 13.2. RSTSRC: Reset Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
SFR Definition 14.1. OSCICL: Internal Oscillator Calibration . . . . . . . . . . . . . . . . . . . 176
SFR Definition 14.2. OSCICN: Internal Oscillator Control . . . . . . . . . . . . . . . . . . . . . 176
SFR Definition 14.3. CLKSEL: Oscillator Clock Selection . . . . . . . . . . . . . . . . . . . . . 177
SFR Definition 14.4. OSCXCN: External Oscillator Control . . . . . . . . . . . . . . . . . . . . 178
SFR Definition 15.1. FLACL: Flash Access Limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
SFR Definition 15.2. FLSCL: Flash Memory Control . . . . . . . . . . . . . . . . . . . . . . . . . 186
SFR Definition 15.3. PSCTL: Program Store Read/Write Control . . . . . . . . . . . . . . . 187
SFR Definition 16.1. EMI0CN: External Memory Interface Control . . . . . . . . . . . . . . 191
SFR Definition 16.2. EMI0CF: External Memory Configuration . . . . . . . . . . . . . . . . . 192
SFR Definition 16.3. EMI0TC: External Memory Timing Control . . . . . . . . . . . . . . . . 197
SFR Definition 17.1. XBR0: Port I/O Crossbar Register 0 . . . . . . . . . . . . . . . . . . . . . 214
SFR Definition 17.2. XBR1: Port I/O Crossbar Register 1 . . . . . . . . . . . . . . . . . . . . . 215
SFR Definition 17.3. XBR2: Port I/O Crossbar Register 2 . . . . . . . . . . . . . . . . . . . . . 216
SFR Definition 17.4. XBR3: Port I/O Crossbar Register 3 . . . . . . . . . . . . . . . . . . . . . 217
SFR Definition 17.5. P0: Port0 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
SFR Definition 17.6. P0MDOUT: Port0 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . . 218
SFR Definition 17.7. P1: Port1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
SFR Definition 17.8. P1MDIN: Port1 Input Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
SFR Definition 17.9. P1MDOUT: Port1 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . . 219
SFR Definition 17.10. P2: Port2 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
SFR Definition 17.11. P2MDIN: Port2 Input Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
SFR Definition 17.12. P2MDOUT: Port2 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 221
SFR Definition 17.13. P3: Port3 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
SFR Definition 17.14. P3MDIN: Port3 Input Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
SFR Definition 17.15. P3MDOUT: Port3 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 222
SFR Definition 17.16. P4: Port4 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
SFR Definition 17.17. P4MDOUT: Port4 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 224
SFR Definition 17.18. P5: Port5 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
16
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.19. P5MDOUT: Port5 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 225
SFR Definition 17.20. P6: Port6 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
SFR Definition 17.21. P6MDOUT: Port6 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 226
SFR Definition 17.22. P7: Port7 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
SFR Definition 17.23. P7MDOUT: Port7 Output Mode . . . . . . . . . . . . . . . . . . . . . . . . 227
SFR Definition 18.1. CAN0DATL: CAN Data Access Register Low Byte . . . . . . . . . . 237
SFR Definition 18.2. CAN0ADR: CAN Address Index . . . . . . . . . . . . . . . . . . . . . . . . 237
SFR Definition 18.3. CAN0CN: CAN Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
SFR Definition 18.4. CAN0TST: CAN Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
SFR Definition 18.5. CAN0STA: CAN Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
SFR Definition 19.1. SMB0CN: SMBus0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
SFR Definition 19.2. SMB0CR: SMBus0 Clock Rate . . . . . . . . . . . . . . . . . . . . . . . . . 250
SFR Definition 19.3. SMB0DAT: SMBus0 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
SFR Definition 19.4. SMB0ADR: SMBus0 Address . . . . . . . . . . . . . . . . . . . . . . . . . . 252
SFR Definition 19.5. SMB0STA: SMBus0 Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
SFR Definition 20.1. SPI0CFG: SPI0 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 263
SFR Definition 20.2. SPI0CN: SPI0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
SFR Definition 20.3. SPI0CKR: SPI0 Clock Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
SFR Definition 20.4. SPI0DAT: SPI0 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
SFR Definition 21.1. SCON0: UART0 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
SFR Definition 21.2. SSTA0: UART0 Status and Clock Selection . . . . . . . . . . . . . . . 277
SFR Definition 21.3. SBUF0: UART0 Data Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
SFR Definition 21.4. SADDR0: UART0 Slave Address . . . . . . . . . . . . . . . . . . . . . . . 278
SFR Definition 21.5. SADEN0: UART0 Slave Address Enable . . . . . . . . . . . . . . . . . 278
SFR Definition 22.1. SCON1: Serial Port 1 Control . . . . . . . . . . . . . . . . . . . . . . . . . . 284
SFR Definition 22.2. SBUF1: Serial (UART1) Port Data Buffer . . . . . . . . . . . . . . . . . 285
SFR Definition 23.1. TCON: Timer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
SFR Definition 23.2. TMOD: Timer Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
SFR Definition 23.3. CKCON: Clock Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
SFR Definition 23.4. TL0: Timer 0 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
SFR Definition 23.5. TL1: Timer 1 Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
SFR Definition 23.6. TH0: Timer 0 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
SFR Definition 23.7. TH1: Timer 1 High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
SFR Definition 23.8. TMRnCN: Timer n Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
SFR Definition 23.9. TMRnCF: Timer n Configuration . . . . . . . . . . . . . . . . . . . . . . . . 302
SFR Definition 23.10. RCAPnL: Timer n Capture Register Low Byte . . . . . . . . . . . . . 303
SFR Definition 23.11. RCAPnH: Timer n Capture Register High Byte . . . . . . . . . . . . 303
SFR Definition 23.12. TMRnL: Timer n Low Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
SFR Definition 23.13. TMRnH Timer n High Byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
SFR Definition 24.1. PCA0CN: PCA Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
SFR Definition 24.2. PCA0MD: PCA0 Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
SFR Definition 24.3. PCA0CPMn: PCA0 Capture/Compare Mode . . . . . . . . . . . . . . 316
SFR Definition 24.4. PCA0L: PCA0 Counter/Timer Low Byte . . . . . . . . . . . . . . . . . . 317
SFR Definition 24.5. PCA0H: PCA0 Counter/Timer High Byte . . . . . . . . . . . . . . . . . . 317
SFR Definition 24.6. PCA0CPLn: PCA0 Capture Module Low Byte . . . . . . . . . . . . . . 318
Rev. 1.4
17
C8051F040/1/2/3/4/5/6/7
SFR Definition 24.7. PCA0CPHn: PCA0 Capture Module High Byte . . . . . . . . . . . . . 318
JTAG Register Definition 25.1. IR: JTAG Instruction Register . . . . . . . . . . . . . . . . . . 319
JTAG Register Definition 25.2. DEVICEID: JTAG Device ID Register . . . . . . . . . . . . 322
JTAG Register Definition 25.3. FLASHCON: JTAG Flash Control Register . . . . . . . . 324
JTAG Register Definition 25.4. FLASHDAT: JTAG Flash Data . . . . . . . . . . . . . . . . . 325
JTAG Register Definition 25.5. FLASHADR: JTAG Flash Address . . . . . . . . . . . . . . 325
18
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
1.
System Overview
The C8051F04x family of devices are fully integrated mixed-signal System-on-a-Chip MCUs with 64 digital
I/O pins (C8051F040/2/4/6) or 32 digital I/O pins (C8051F041/3/5/7), and an integrated CAN 2.0B controller. Highlighted features are listed below; refer to Table 1.1 for specific product feature selection.
With on-chip VDD monitor, Watchdog Timer, and clock oscillator, the C8051F04x family of 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 programming and 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 to +85 C).
The Port I/Os, /RST, and JTAG pins are tolerant for input signals up to 5 V. The C8051F040/2/4/6 are available in a 100-pin TQFP and the C8051F041/3/5/7 are available in a 64-pin TQFP.
Rev. 1.4
19
C8051F040/1/2/3/4/5/6/7
DAC Outputs
12
3 100TQFP
C8051F041 25 64 kB 4352 3 3 3
3 32 3
3 3 3
12
C8051F042 25 64 kB 4352 3 3 3
3 64 -
3 3 3
12
3 100TQFP
C8051F043 25 64 kB 4352 3 3 3
3 32 -
3 3 3
12
C8051F044 25 64 kB 4352 3 3 3
3 64 -
3 3 3
3 100TQFP
C8051F045 25 64 kB 4352 3 3 3
3 32 -
3 3 3
C8051F046 25 32 kB 4352 3 3 3
3 64 -
3 3 3
3 100TQFP
C8051F047 25 32 kB 4352 3 3 3
3 32 -
3 3 3
20
Rev. 1.4
Package
Temperature Sensor
3 3 3
Analog Comparators
Voltage Reference
3 64 3
Timers (16-bit)
UARTS
RAM
Flash Memory
C8051F040 25 64 kB 4352 3 3 3
MIPS (Peak)
64TQFP
64TQFP
64TQFP
64TQFP
C8051F040/1/2/3/4/5/6/7
VDD
VDD
VDD
DGND
DGND
DGND
AV+
AV+
AV+
AGND
AGND
AGND
TCK
TMS
TDI
TDO
/RST
Digital Power
8
0
5
1
Analog Power
Boundary Scan
JTAG
Logic
Debug HW
Reset
MONEN
V DD
Monitor
XTAL1
XTAL2
External
Oscillator
Circuit
WDT
System
Clock
VREF
VREF
VREFD
DAC1
(12-Bit)
DAC1
Internal
Oscillator
C
o
r
e
UART0
UART1
SFR Bus
C
R
O
S
S
B
A
R
SMBus
SPI Bus
PCA
Memories
64 kB
Flash
32x136
CANRAM
Timers
0,1,2,3,4
Port
0,1,2,3
&4
Latches
ADC
500 ksps
(8-Bit)
TEMP
SENSOR
HVAIN+
A
M
U
X
P3
Drv
P3.0
P1.7
P2.7
P3.7
A
M
U
X
8:1
VREF2
+
-
CP0
ADC
100 ksps
(12 or 10Bit)
P2.0
Prog
Gain
+
-
CP1
Prog
Gain
P2
Drv
4 kB
RAM
CP2
A
M
U
X
P1.0
CANRX
AIN0.0
AIN0.1
AIN0.3
P1
Drv
P0.7
CANTX
256 byte
RAM
VREF0
AIN0.2
P0.0
CAN
2.0B
DAC0
(12-Bit)
DAC0
P0
Drv
+
-
P2.6
P2.7
P2.2
P2.3
P2.4
P2.5
P4.0
Bus Control
Address [15:0]
Addr [15:8]
Addr [7:0]
P7 Latch
Data [7:0]
HVAMP
P4.4
P4.5/ALE
P4.6/RD
P4.7/WR
P5
DRV
P5.0/A8
P6
DRV
P6.0/A0
P6.7/A7
P7
DRV
P7.7/D7
Ctrl Latch
P5 Latch
P6 Latch
8:2
P4
DRV
Data Latch
P5.7/A51
P7.0/D0
HVAINHVREF
HVCAP
Rev. 1.4
21
C8051F040/1/2/3/4/5/6/7
VDD
VDD
VDD
DGND
DGND
DGND
AV+
AV+
AGND
AGND
TCK
TMS
TDI
TDO
/RST
MONEN
XTAL1
XTAL2
Digital Power
8
0
5
1
Analog Power
Boundary Scan
JTAG
Logic
Debug HW
Reset
VDD
Monitor
WDT
External
Oscillator
Circuit
VREF
VREF
DAC1
DAC1
(12-Bit)
DAC0
DAC0
(12-Bit)
System
Clock
Internal
Oscillator
C
o
r
e
UART0
UART1
SFR Bus
SPI Bus
PCA
Memories
64 kB
Flash
32x136
CANRAM
Timers
0,1,2,3,4
Port
0,1,2,3
&4
Latches
A
M
U
X
256 byte
RAM
ADC
500 ksps
(8-Bit)
TEMP
SENSOR
HVAIN+
A
M
U
X
4 kB
RAM
P2.0
P3
Drv
P3.0
+
+
+
-
Bus Control
Address [15:0]
P2.7
P3.7
A
M
U
X
8:1
Addr [15:8]
Addr [7:0]
P7 Latch
Data [7:0]
HVAMP
HVREF
HVCAP
P2.6
P2.7
P2.2
P2.3
P2.4
P2.5
P4
DRV
Ctrl Latch
P5 Latch
P6 Latch
8:2
Rev. 1.4
P1.7
VREFA
HVAIN-
22
P2
Drv
Prog
Gain
CP0
ADC
100 ksps
(12 or 10Bit)
P1.0
CANTX
CP1
Prog
Gain
P1
Drv
P0.7
CANRX
CP2
AIN0.2
P0.0
CAN
2.0B
VREFA
AIN0.0
AIN0.1
AIN0.3
C
R
O
S
S
B
A
R
SMBus
P0
Drv
Data Latch
P5
DRV
P6
DRV
P7
DRV
C8051F040/1/2/3/4/5/6/7
VDD
VDD
VDD
DGND
DGND
DGND
AV+
AV+
AV+
AGND
AGND
AGND
TCK
TMS
TDI
TDO
/RST
MONEN
XTAL1
XTAL2
Digital Power
8
0
5
1
Analog Power
Boundary Scan
JTAG
Logic
Debug HW
Reset
VDD
Monitor
WDT
External
Oscillator
Circuit
System
Clock
VREF
VREF
Internal
Oscillator
C
o
r
e
UART0
UART1
SFR Bus
C
R
O
S
S
B
A
R
SMBus
SPI Bus
PCA
Memories
64/32 kB
Flash
32x136
CANRAM
Timers
0,1,2,3,4
Port
0,1,2,3
&4
Latches
P0
Drv
P0.0
P1
Drv
P1.0
P2
Drv
P2.0
P3
Drv
P3.0
P0.7
P1.7
P2.7
P3.7
CAN
2.0B
CANTX
CANRX
256 byte
RAM
4 kB
RAM
+
-
CP0
+
-
CP1
CP2
+
-
P2.6
P2.7
P2.2
P2.3
P2.4
P2.5
VREF0
AIN0.0
AIN0.1
AIN0.2
AIN0.3
P4.0
A
M
U
X
Prog
Gain
TEMP
SENSOR
HVAIN+
ADC
100 ksps
(10-Bit)
A
M
U
X
Bus Control
Address [15:0]
Addr [15:8]
Addr [7:0]
P7 Latch
Data [7:0]
HVAMP
P4.4
P4.5/ALE
P4.6/RD
P4.7/WR
P5
DRV
P5.0/A8
P6
DRV
P6.0/A0
P6.7/A7
P7
DRV
P7.7/D7
Ctrl Latch
P5 Latch
P6 Latch
8:2
P4
DRV
Data Latch
P5.7/A51
P7.0/D0
HVAINHVREF
HVCAP
Rev. 1.4
23
C8051F040/1/2/3/4/5/6/7
VDD
VDD
VDD
DGND
DGND
DGND
AV+
AV+
AGND
AGND
TCK
TMS
TDI
TDO
/RST
Digital Power
8
0
5
1
Analog Power
Boundary Scan
JTAG
Logic
Debug HW
Reset
MONEN
VDD
Monitor
XTAL1
XTAL2
External
Oscillator
Circuit
WDT
System
Clock
VREF
VREF
Internal
Oscillator
C
o
r
e
UART0
UART1
SFR Bus
C
R
O
S
S
B
A
R
SMBus
SPI Bus
PCA
Memories
64/32 kB
Flash
32x136
CANRAM
Timers
0,1,2,3,4
Port
0,1,2,3
&4
Latches
P0
Drv
P0.0
P1
Drv
P1.0
P2
Drv
P2.0
P3
Drv
P3.0
P0.7
P1.7
P2.7
P3.7
CAN
2.0B
CANTX
CANRX
256 byte
RAM
4 kB
RAM
+
-
CP0
+
-
CP1
CP2
+
-
P2.6
P2.7
P2.2
P2.3
P2.4
P2.5
VREFA
AIN0.0
AIN0.1
AIN0.2
AIN0.3
A
M
U
X
Prog
Gain
TEMP
SENSOR
HVAIN+
ADC
100 ksps
(10-Bit)
A
M
U
X
Bus Control
Address [15:0]
Addr [15:8]
Addr [7:0]
P7 Latch
Data [7:0]
HVAMP
HVAINHVREF
HVCAP
24
P5 Latch
P6 Latch
8:2
Rev. 1.4
P4
DRV
Ctrl Latch
Data Latch
P5
DRV
P6
DRV
P7
DRV
C8051F040/1/2/3/4/5/6/7
1.1.
Clocks to Execute
2/3
3/4
4/5
Number of Instructions
26
50
14
With the CIP-51's maximum system clock at 25 MHz, it has a peak throughput of 25 MIPS. Figure 1.5
shows a comparison of peak throughputs of various 8-bit microcontroller cores with their maximum system
clocks.
25
MIPS
20
15
10
25
C8051F040/1/2/3/4/5/6/7
1.1.3. Additional Features
The C8051F04x MCU family includes several key enhancements to the CIP-51 core and peripherals to
improve overall performance and ease of use in end applications.
The extended interrupt handler provides 20 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 CNVSTR0 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 permanently 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 resonator, 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 switching to the fast (up to 25 MHz) internal oscillator as needed.
VDD
Crossbar
CNVSTR
Supply
Monitor
(CNVSTR
reset
enable)
+
-
Comparator0
CP0+
+
-
CP0-
XTAL2
OSC
EN
Clock Select
PRE
WDT
Enable
MCD
Enable
System
Clock
Reset
Funnel
WDT
EN
XTAL1
CIP-51
Microcontroller
Core
Software Reset
System Reset
Extended Interrupt
Handler
26
(wired-OR)
(CP0
reset
enable)
Missing
Clock
Detector
(oneshot)
Internal
Clock
Generator
Supply
Reset
Timeout
WDT
Strobe
(Port I/O)
Rev. 1.4
RST
C8051F040/1/2/3/4/5/6/7
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 CIP-51 SFR
address space contains up to 256 SFR Pages. In this way, the CIP-51 MCU can accommodate the many
SFRs required to control and configure the various peripherals featured on the device. The lower
128 bytes of RAM are accessible via direct and indirect 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 C8051F04x MCUs additionally has an on-chip 4 kB RAM block and an external memory
interface (EMIF) for accessing off-chip data memory or memory-mapped peripherals. The on-chip 4 byte
block can be addressed over the entire 64 kB external data memory address range (overlapping 4 kB
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 4 kB directed to on-chip, above 4 kB directed to
EMIF). The EMIF is also configurable for multiplexed or non-multiplexed address/data lines.
The MCU's program memory consists of 64 kB (C8051F040/1/2/3/4/5) or 32 kB (C8051F046/7) 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 the 64 kB devices.
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.
PROGRAM/DATA MEMORY
(FLASH)
C8051F040/1/2/3/4/5
0x1007F
0x10000
0xFE00
0xFF
Scrachpad Memory
(DATA only)
0x80
0x7F
RESERVED
Special Function
Registers
(Direct Addressing Only) 0
0xFDFF
0x30
0x2F
64 kB
Flash
(In-System
Programmable in 512
Byte Sectors)
0x20
0x1F
0x00
0x0000
Bit Addressable
General Purpose
Registers
Up To
256 SFR Pages
0x1007F
0x10000
0x8000
0xFFFF
Scrachpad Memory
(DATA only)
RESERVED
0x7FFF
32 kB
Flash
0x1000
(In-System
Programmable in 512
Byte Sectors)
0x0FFF
0x0000
0x0000
27
C8051F040/1/2/3/4/5/6/7
1.3.
The C8051F04x 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, watchpoints, 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 with instruction execution.
The C8051F040DK development kit provides all the hardware and software necessary to develop application code and perform in-circuit debugging with the C8051F04x MCUs. The development kit includes two
target boards and a cable to facilitate evaluating a simple CAN communication network. The kit also
includes software with a developer's studio and debugger, a target application board with the associated
MCU installed, and the required cables and wall-mount power supply. 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 sufficient 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 applications 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, on-chip analog peripherals.
Integrated Development
Environment
WINDOWS 95 or later
Serial
Adapter
VDD
TARGET PCB
GND
C8051
F040
28
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
1.4.
The standard 8051 Ports (0, 1, 2, and 3) are available on the MCUs. The C8051F040/2/4/6 have 4 additional 8-bit ports (4, 5, 6, and 7) for a total of 64 general-purpose I/O Ports. The Ports behave like the standard 8051 with a few enhancements.
Each port pin can be configured as either a push-pull or open-drain output. Also, the "weak pullups" 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 ports, all combinations of
functions are supported with all package options offered.
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 Control registers. This allows the user to select the exact mix of general purpose Port I/O and
digital resources needed for the particular application.
Highest
Priority
UART0
SPI
SMBus
UART1
P0MDOUT, P1MDOUT,
P2MDOUT, P3MDOUT
Registers
External
Pins
Priority
Decoder
8
PCA
P0.0
P1
I/O
Cells
P1.0
Comptr.
Outputs
Digital
Crossbar
T0, T1,
T2, T2EX,
T3, T3EX,
T4,T4EX,
/INT0,
/INT1
P1
(P1.0-P1.7)
8
P2
P2.0
P3
I/O
Cells
P3.0
P2.7
P3.7
Lowest
Priority
To
ADC2
Input
To External
Memory
Interface
(EMIF)
(P2.0-P2.7)
8
P3
P1.7
P2
I/O
Cells
(P0.0-P0.7)
8
Port
Latches
P0.7
CNVSTR0
CNVSTR2
P0
Highest
Priority
/SYSCLK
Lowest
Priority
P0
I/O
Cells
To
Comparators
To
ADC0
Input
(P3.0-P3.7)
Rev. 1.4
29
C8051F040/1/2/3/4/5/6/7
1.5.
The C8051F04x 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 six programmable 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 Crossbar.
SYSCLK/12
SYSCLK/4
Timer 0 Overflow
ECI
SYSCLK
PCA
CLOCK
MUX
16-Bit Counter/Timer
External Clock/8
Capture/Compare
Module 0
Capture/Compare
Module 1
Capture/Compare
Module 2
Capture/Compare
Module 3
30
Rev. 1.4
Capture/Compare
Module 5
CEX5
Port I/O
CEX4
CEX3
CEX2
CEX1
CEX0
ECI
Crossbar
Capture/Compare
Module 4
C8051F040/1/2/3/4/5/6/7
1.6.
The C8051F04x family of devices feature a Controller Area Network (CAN) controller that implements
serial communication using the CAN protocol. The CAN controller facilitates communication on a CAN network in accordance with the Bosch specification 2.0A (basic CAN) and 2.0B (full CAN). The CAN controller
consists of a CAN Core, Message RAM (separate from the C8051 RAM), a message handler state
machine, and control registers.
The CAN controller can operate at bit rates up to 1 Mbit/second. Silicon Labs CAN has 32 message
objects each having its own identifier mask used for acceptance filtering of received messages. Incoming
data, message objects and identifier masks are stored in the CAN message RAM. All protocol functions for
transmission of data and acceptance filtering is performed by the CAN controller and not by the C8051
MCU. In this way, minimal CPU bandwidth is used for CAN communication. The C8051 configures the
CAN controller, accesses received data, and passes data for transmission via Special Function Registers
(SFR) in the C8051.
CANTX
C8051F04x
CANRX
CAN Controller
TX
RX
BRP
Prescaler
CAN
Core
CAN_CLK
(fsys)
S
Y
S
C
L
K
CIP-51
MCU
Message RAM
REGISTERS
Message Handler
S
F
R
's
Interrupt
Serial Ports
The C8051F04x MCU Family includes two Enhanced Full-Duplex UARTs, an enhanced 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
31
C8051F040/1/2/3/4/5/6/7
1.8.
The C8051F040/1 devices have 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 performance with an INL of 1LSB. C8051F042/3/4/5/6/7 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 C8051F040/2/4/6 devices, ADC0 has its own dedicated VREF0 input pin;
on C8051F041/3/5/7 devices, the ADC0 uses the VREFA input pin and, on the C8051F041/3, shares it
with the 8-bit ADC2. The on-chip 15 ppm/C voltage reference may generate the voltage reference for the
on-chip ADCs or other system components 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 to 0.5, 1, 2, 4, 8, or 16
and is software programmable. 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 interrupt the controller unless the converted data is within the specified window.
Analog Multiplexer
Configuration, Control, and Data
Registers
AIN0.0
AIN0.1
AIN0.2
AIN0.3
HVAIN +
HVAIN -
HVDA
Programmable Gain
Amplifier
9-to-1
AMUX
(SE or
DIFF)
AV+
+
-
12/10-Bit
SAR
12
ADC
Port 3
Pins
Window
Compare
Interrupt
Window Compare
Logic
ADC Data
Registers
Conversion
Complete
Interrupt
TEMP
SENSOR
External VREF
Pin
AGND
VREF
Start
Conversion
DAC0 Output
(C8051F040/1/2/3 Only)
Rev. 1.4
Write to AD0BUSY
Timer 3 Overflow
CNVSTR0
Timer 2 Overflow
C8051F040/1/2/3/4/5/6/7
1.9.
The C8051F040/1/2/3 devices have an on-board 8-bit SAR ADC (ADC2) with an 8-channel input multiplexer and programmable gain amplifier. This ADC features a 500 ksps maximum throughput and true 8bit performance with an INL of 1LSB. Eight input pins are available for measurement and can be programmed as single-ended or differential inputs. The ADC is under full control of the CIP-51 microcontroller
via the Special Function Registers. The ADC2 voltage reference is selected between the analog power
supply (AV+) and an external VREF pin. On C8051F040/2 devices, ADC2 has its own dedicated VREF2
input pin; on C8051F041/3 devices, ADC2 shares the VREFA input pin with the 12/10-bit ADC0. User software may put ADC2 into shutdown mode to save power.
A programmable gain amplifier follows the analog multiplexer. 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). The PGA gain can be set in software to 0.5, 1, 2, or 4.
A flexible conversion scheduling system allows ADC2 conversions to be initiated by software commands,
timer overflows, or an external input signal. ADC2 conversions may also be synchronized with ADC0 software-commanded 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.
Analog Multiplexer
Window
Compare Logic
AIN2.0
Window
Compare
Interrupt
AIN2.1
AIN2.2
AIN2.3
AIN2.4
AIN2.5
AIN2.6
AIN2.7
Programmable Gain
Amplifier
8-to-1
AMUX
8-Bit
SAR
AV+
+
-
ADC
ADC Data
Register
Conversion
Complete
Interrupt
Write to AD2BUSY
Single-ended or
Differential Measurement
External VREF
Pin
VREF
Start Conversion
AV+
Timer 3 Overflow
CNVSTR2 Input
Timer 2 Overflow
Write to AD0BUSY
(synchronized with
ADC0)
Rev. 1.4
33
C8051F040/1/2/3/4/5/6/7
1.10. Comparators and DACs
Each C8051F040/1/2/3 MCU has two 12-bit DACs, and all C8051F04x devices have three comparators on
chip. The MCU data and control interface 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 and response time. 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
mechanism 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 C8051F040/2 devices or via the
internal voltage reference on C8051F041/3 devices. The DACs are especially useful as references for the
comparators or offsets for the differential inputs of the ADC.
CPn O utput
(Port I/O )
C om parator inputs
Port 2.[7:2]
CRO SSBAR
3 Com parators
CPn+
CPn-
CPn
SFR's
(Data
and
Cntrl)
VREF
DAC0
DAC 0
(C 8051F040/1/2/3 only)
VREF
DAC1
DAC 1
(C 8051F040/1/2/3 only)
34
Rev. 1.4
C IP-51
and
Interrupt
H andler
C8051F040/1/2/3/4/5/6/7
2.
Conditions
Min
Typ
Max
Units
55
125
Storage Temperature
65
150
0.3
VDD +
0.3
Voltage on any Port I/O Pin, /RST, and JTAG pins with
respect to DGND
0.3
5.8
0.3
4.2
800
mA
100
mA
50
mA
100
mA
50
mA
*Note: 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.
Due to special I/O design requirements of the High Voltage Difference Amplifier, undue electrical over-voltage
stress (i.e., ESD) experienced by these pads may result in impedance degredation of these inputs (HVAIN+
and HVAIN). For this reason, care should be taken to ensure proper handling and use as typically required to
prevent ESD damage to electrostatically sensitive CMOS devices (e.g., static-free workstations, use of
grounding straps, over-voltage protection in end-applications, etc.)
Rev. 1.4
35
C8051F040/1/2/3/4/5/6/7
3.
Parameter
Conditions
Min
Typ
Max
Units
2.7
3.0
3.6
1.7
mA
Analog Supply Current with Internal REF, ADC, DAC, Comanalog sub-systems inactive parators all disabled, oscillator
disabled
0.2
mA
Analog-to-Digital Supply
Delta (|VDD - AV+|)
0.5
2.7
3.0
3.6
10
0.5
20
mA
mA
A
5
0.2
10
mA
mA
A
0.2
1.5
40
+85
25
MHz
18
ns
18
ns
Notes:
1. Analog Supply AV+ must be greater than 1 V for VDD monitor to operate.
2. SYSCLK must be at least 32 kHz to enable debugging.
36
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
4.
Name
Pin Numbers
F040/2/4/6 F041/3/5/7
Type Description
VDD
DGND
AV+
8, 11, 14
3, 6
AGND
9, 10, 13
4, 5
TMS
58
TCK
59
TDI
60
D In JTAG Test Data Input with internal pullup. TDI is latched on the
rising edge of TCK.
TDO
61
D Out JTAG Test Data Output with internal pullup. Data is shifted out on
TDO on the falling edge of TCK. TDO output is a tri-state driver.
/RST
62
XTAL1
26
17
A In
XTAL2
27
18
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.
In most applications, MONEN should be connected directly
to VDD.
VREF
12
A In
VREFA
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.
A Out Crystal Output. This pin is the excitation driver for a crystal or
ceramic resonator.
VREF0
16
A In
VREF2
17
A In
VREF
15
A In
AIN0.0
18
A In
AIN0.1
19
10
A In
Rev. 1.4
37
C8051F040/1/2/3/4/5/6/7
Table 4.1. Pin Definitions (Continued)
Name
Pin Numbers
F040/2/4/6 F041/3/5/7
Type Description
AIN0.2
20
11
A In
AIN0.3
21
12
A In
HVCAP
22
13
HVREF
23
14
A In
HVAIN+
24
15
A In
HVAIN-
25
16
A In
CANTX
CANRX
DAC0
100
64
A Out Digital to Analog Converter 0 Voltage Output. (See DAC Specification for complete description). (C8051F040/1/2/3 only)
DAC1
99
63
A Out Digital to Analog Converter 1 Voltage Output. (See DAC Specification for complete description). (C8051F040/1/2/3 only)
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.
P0.5/ALE
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.
P0.6/RD
56
49
P0.7/WR
55
48
P1.0/AIN2.0/A8
36
29
P1.1/AIN2.1/A9
35
28
P1.2/AIN2.2/A10
34
27
P1.3/AIN2.3/A11
33
26
38
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 4.1. Pin Definitions (Continued)
Name
Pin Numbers
F040/2/4/6 F041/3/5/7
Type Description
P1.4/AIN2.4/A12
32
23
P1.5/AIN2.5/A13
31
22
P1.6/AIN2.6/A14
30
21
P1.7/AIN2.7/A15
29
20
P2.0/A8m/A0
46
37
P2.1/A9m/A1
45
36
D I/O Port 2.1. See Port Input/Output section for complete description.
P2.2/A10m/A2
44
35
D I/O Port 2.2. See Port Input/Output section for complete description.
P2.3/A11m/A3
43
34
D I/O Port 2.3. See Port Input/Output section for complete description.
P2.4/A12m/A4
42
33
D I/O Port 2.4. See Port Input/Output section for complete description.
P2.5/A13m/A5
41
32
D I/O Port 2.5. See Port Input/Output section for complete description.
P2.6/A14m/A6
40
31
D I/O Port 2.6. See Port Input/Output section for complete description.
P2.7/A15m/A7
39
30
D I/O Port 2.7. See Port Input/Output section for complete description.
P3.0/AD0/D0
54
47
P3.1/AD1/D1
53
46
P3.2/AD2/D2
52
45
P3.3/AD3/D3
51
44
P3.4/AD4/D4
50
43
P3.5/AD5/D5
49
42
P3.6/AD6/D6
48
39
P3.7/AD7/D7
47
38
P4.0
98
D I/O Port 4.0. See Port Input/Output section for complete description.
Rev. 1.4
39
C8051F040/1/2/3/4/5/6/7
Table 4.1. Pin Definitions (Continued)
Name
Pin Numbers
F040/2/4/6 F041/3/5/7
Type 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.
P4.5/ALE
93
D I/O ALE Strobe for External Memory Address bus (multiplexed mode)
Port 4.5
See Port Input/Output section for complete description.
P4.6/RD
92
P4.7/WR
91
P5.0/A8
88
P5.1/A9
87
D I/O Port 5.1. See Port Input/Output section for complete description.
P5.2/A10
86
D I/O Port 5.2. See Port Input/Output section for complete description.
P5.3/A11
85
D I/O Port 5.3. See Port Input/Output section for complete description.
P5.4/A12
84
D I/O Port 5.4. See Port Input/Output section for complete description.
P5.5/A13
83
D I/O Port 5.5. See Port Input/Output section for complete description.
P5.6/A14
82
D I/O Port 5.6. See Port Input/Output section for complete description.
P5.7/A15
81
D I/O Port 5.7. See Port Input/Output section for complete description.
P6.0/A8m/A0
80
P6.1/A9m/A1
79
D I/O Port 6.1. See Port Input/Output section for complete description.
P6.2/A10m/A2
78
D I/O Port 6.2. See Port Input/Output section for complete description.
P6.3/A11m/A3
77
D I/O Port 6.3. See Port Input/Output section for complete description.
P6.4/A12m/A4
76
D I/O Port 6.4. See Port Input/Output section for complete description.
P6.5/A13m/A5
75
D I/O Port 6.5. See Port Input/Output section for complete description.
P6.6/A14m/A6
74
D I/O Port 6.6. See Port Input/Output section for complete description.
P6.7/A15m/A7
73
D I/O Port 6.7. See Port Input/Output section for complete description.
P7.0/AD0/D0
72
40
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 4.1. Pin Definitions (Continued)
Name
Pin Numbers
F040/2/4/6 F041/3/5/7
Type Description
P7.1/AD1/D1
71
D I/O Port 7.1. See Port Input/Output section for complete description.
P7.2/AD2/D2
70
D I/O Port 7.2. See Port Input/Output section for complete description.
P7.3/AD3/D3
69
D I/O Port 7.3. See Port Input/Output section for complete description.
P7.4/AD4/D4
68
D I/O Port 7.4. See Port Input/Output section for complete description.
P7.5/AD5/D5
67
D I/O Port 7.5. See Port Input/Output section for complete description.
P7.6/AD6/D6
66
D I/O Port 7.6. See Port Input/Output section for complete description.
P7.7/AD7/D7
65
D I/O Port 7.7. See Port Input/Output section for complete description.
Rev. 1.4
41
42
41
42
43
44
45
46
47
48
49
50
P2.4/A12m/A4
P2.3/A11m/A3
P2.2/A10m/A2
P2.1/A9m/A1
P2.0/A8m/A0
P3.7/AD7/D7
P3.6/AD6/D6
P3.5/AD5/D5
P3.4/AD4/D4
38
DGND
P2.5/A13m/A5
37
VDD
40
36
P1.0/AIN2.0/A8
P2.6/A14m/A6
35
P1.1/AIN2.1/A9
39
34
P1.2/AIN2.2/A10
P2.7/A15m/A7
33
P1.3/AIN2.3/A11
30
P1.6/AIN2.6/A14
32
29
P1.7/AIN2.7/A15
P1.4/AIN2.4/A12
28
MONEN
31
27
XTAL2
P1.5/AIN2.5/A13
26
XTAL1
DAC0
DAC1
P4.0
P4.1
P4.2
P4.3
P4.4
P4.5/ALE
P4.6/RD
P4.7/WR
VDD
DGND
P5.0/A8
P5.1/A9
P5.2/A10
P5.3/A11
P5.4/A12
P5.5/A13
P5.6/A14
P5.7/A15
P6.0/A8m/A0
P6.1/A9m/A1
P6.2/A10m/A2
P6.3/A11m/A3
P6.4/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
C8051F040/1/2/3/4/5/6/7
TMS
1
75
P6.5/A13m/A5
TCK
2
74
P6.6/A14m/A6
TDI
3
73
P6.7/A15m/A7
TDO
4
72
P7.0/AD0/D0
/RST
5
71
P7.1/AD1/D1
CANRX
6
70
P7.2/AD2/D2
CANTX
7
69
P7.3/AD3/D3
AV+
8
68
P7.4/AD4/D4
AGND
9
67
P7.5/AD5/D5
AGND
10
66
P7.6/AD6/D6
AV+
11
65
P7.7/AD7/D7
VREF
12
64
VDD
AGND
13
63
DGND
AV+
14
62
P0.0
VREFD
15
61
P0.1
VREF0
16
60
P0.2
VREF2
17
59
P0.3
AIN0.0
18
58
P0.4
AIN0.1
19
57
P0.5/ALE
AIN0.2
20
56
P0.6/RD
AIN0.3
21
55
P0.7/WR
HVCAP
22
54
P3.0/AD0/D0
HVREF
23
53
P3.1/AD1/D1
HVAIN+
24
52
P3.2/AD2/D2
HVAIN25
51
P3.3/AD3/D3
C8051F040/2/4/6
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
D
D1
E1
100
PIN 1
DESIGNATOR
A2
1.20
A1 0.05
0.15
A2 0.95
1.00
1.05
0.17
0.22
0.27
16.00
D1
14.00
0.50
16.00
E1
14.00
0.45
0.60
0.75
1
e
A
A1
Rev. 1.4
43
DAC0
DAC1
/RST
TDO
TDI
TCK
TMS
VDD
DGND
P0.0
P0.1
P0.2
P0.3
P0.4
P0.5/ALE
P0.6/RD
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
C8051F040/1/2/3/4/5/6/7
CANRX
48
P0.7/WR
CANTX
47
P3.0/AD0/D0
AV+
46
P3.1/AD1/D1
AGND
45
P3.2/AD2/D2
AGND
44
P3.3/AD3/D3
AV+
43
P3.4/AD4/D4
VREF
42
P3.5/AD5/D5
VREFA
41
VDD
C8051F041/3/5/7
AIN0.0
40
DGND
AIN0.1
10
39
P3.6/AD6/D6
AIN0.2
11
38
P3.7/AD7/D7
AIN0.3
12
37
P2.0/A8m/A0
HVCAP
13
36
P2.1/A9m/A1
21
22
23
24
25
26
27
28
29
30
31
32
P1.6/AIN2.6/A14
P1.5/AIN2.5/A13
P1.4/AIN2.4/A12
VDD
DGND
P1.3/AIN2.3/A11
P1.2/AIN2.2/A10
P1.1/AIN2.1/A9
P1.0/AIN2.0/A8
P2.7/A15m/A7
P2.6/A14m/A6
P2.5/A13m/A5
P2.4/A12m/A4
20
33
P1.7/AIN2.7/A15
16
19
HVAIN-
MONEN
P2.3/A11m/A3
18
P2.2/A10m/A2
34
XTAL2
35
15
17
14
XTAL1
HVREF
HVAIN+
44
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
D
D1
E1
A1 0.05
0.15
A2 0.95
1.05
64
PIN 1
DESIGNATOR
1
A2
e
A
A1
0.17
0.22
0.27
12.00
D1
10.00
0.50
12.00
E1
10.00
0.45
0.6
0.75
Rev. 1.4
45
C8051F040/1/2/3/4/5/6/7
NOTES:
46
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
5.
The ADC0 subsystem for the C8051F040/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 Registers shown in Figure 5.1. The voltage reference used by
ADC0 is selected as described in Section 9. Voltage Reference (C8051F040/2/4/6) on page 113 for
C8051F040 devices, or Section 10. Voltage Reference (C8051F041/3/5/7) on page 117 for
C8051F041 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.
ADC0GTH
ADC0GTL
ADC0LTH
ADC0LTL
AD0EN
12-Bit
SAR
+
-
Analog
Input
Pins
ADC
AGND
00
TEMP
SENSOR
AD0SC4
AD0SC3
AD0SC2
AD0SC1
AD0SC0
AMP0GN2
AMP0GN1
AMP0GN0
AD0EN
AD0TM
AD0INT
AD0BUSY
AD0CM1
AD0CM0
AD0WINT
AD0LJST
AMX0CF
AMX0AD3
AMX0AD2
AMX0AD1
AMX0AD0
Start Conversion 01
PORT3IC
HVDAIC
AIN23IC
AIN01IC
AGND
12
ADC0L
Port 3
I/O Pins
ADC0CF
ADC0CN
AMX0SL
AD0WINT
12
AV+
9-to-1
AMUX
(SE or
DIFF)
Comb.
Logic
ADC0H
AV+
HV
Input
SYSCLK
REF
24
AD0BUSY (W)
Timer 3 Overflow
10
CNVSTR0
11
Timer 2 Overflow
The analog multiplexer can input analog signals to the ADC from four external analog input pins (AIN0.0 AIN0.3), Port 3 port pins (optionally configured as analog input pins), High Voltage Difference Amplifier, or
an internally connected on-chip temperature sensor (temperature transfer function is shown in Figure 5.6).
AMUX input pairs can be programmed to operate in either differential or single-ended mode. This allows
the user to select the best measurement 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 three registers
associated with the AMUX: the Channel Selection register AMX0SL (SFR Definition 5.2), the Configuration
register AMX0CF (SFR Definition 5.1), and the Port Pin Selection register AMX0PRT (SFR Definition 5.3).
Table 5.1 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 (SFR Definition 5.5). 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
47
C8051F040/1/2/3/4/5/6/7
5.1.1. Analog Input Configuration
AIN0.0
AIN0.1
AIN0.2
AIN0.3
HVAIN +
HV
AMP
HVAIN HVCAP
AGND
PAIN0EN
PAIN2EN
PAIN4EN
PAIN6EN
PAIN1EN
PAIN3EN
PAIN5EN
PAIN7EN
9-to-1
AMUX
(SE or
DIFF)
P3.6
P3.4
(WIRED-OR)
P3.2
P3EVEN
P3.0
P3.7
P3.5
P3ODD
P3.3
(WIRED-OR)
AMX0CF
12-Bit
SAR
ADC
P3.1
AMX0AD3
AMX0AD2
AMX0AD1
AMX0AD0
AMX0PRT
HVREF
PORT3IC
HVDAIC
AIN23IC
AIN01IC
The analog multiplexer routes signals from external analog input pins, Port 3 I/O pins (See Section
17.1.5. Configuring Port 1, 2, and 3 Pins as Analog Inputs on page 209), a High Voltage Difference
Amplifier, and an on-chip temperature sensor as shown in Figure 5.2.
TEMP SENSOR
AMX0SL
AGND
48
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.1. AMX0CF: AMUX0 Configuration
R
Bit7
Bit6
Bit5
Bit4
R/W
R/W
PORT3IC HVDA2C
Bit3
Bit2
R/W
AIN23IC
Bit1
R/W
Reset Value
AIN01IC 00000000
Bit0
SFR
Address:
Bits7-4:
Bit3:
Bit2:
Bit1:
Bit0:
NOTE:
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xBB
SFR Page: 0
Bits7-4:
Bits3-0:
Rev. 1.4
49
C8051F040/1/2/3/4/5/6/7
Table 5.1. AMUX Selection Chart (AMX0AD30 and AMX0CF30 bits)
AMX0AD3-0
0000
0001
0010
0011
0100
0101
0110
0111
1xxx
0000
AIN0.0
AIN0.1
AIN0.2
AIN0.3
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0001
+(AIN0.0)
-(AIN0.1)
AIN0.2
AIN0.3
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0010
AIN0.0
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0011
+(AIN0.0)
-(AIN0.1)
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0100
AIN0.0
0101
+(AIN0.0)
-(AIN0.1)
0110
AIN0.0
0111
+(AIN0.0)
-(AIN0.1)
1000
AIN0.0
1001
+(AIN0.0)
-(AIN0.1)
1010
AIN0.0
1011
+(AIN0.0)
-(AIN0.1)
1100
AIN0.0
1101
+(AIN0.0)
-(AIN0.1)
1110
AIN0.0
1111
+(AIN0.0)
-(AIN0.1)
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.2
AIN0.3
P3EVEN
P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
P3EVEN
P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
P3EVEN
P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
P3EVEN
P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
+P3EVEN
-P3ODD)
TEMP
SENSOR
AIN0.2
AIN0.3
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
+P3EVEN
-P3ODD
TEMP
SENSOR
Note: P3EVEN denotes even numbered and P3ODD odd numbered Port 3 pins selected in the AMX0PRT
register.
50
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.3. AMX0PRT: Port 3 Pin Selection
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xBD
SFR Page: 0
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Note:Any number of Port 3 pins may be selected simultaneously inputs to the AMUX. Odd numbered and even
numbered pins that are selected simultaneously are shorted together as wired-OR.
Rev. 1.4
51
C8051F040/1/2/3/4/5/6/7
5.2.
The High Voltage Difference Amplifier (HVDA) can be used to measure high differential voltages up to 60 V
peak-to-peak, reject high common-mode voltages up to 60 V, and condition the signal voltage range to be
suitable for input to ADC0. The input signal to the HVDA may be below AGND to 60 volts, and as high as
+60 volts, making the device suitable for both single and dual supply applications. The HVDA will provides
a common-mode signal for the ADC via the High Voltage Reference Input (HVREF), allowing measurement of signals outside the specified ADC input range using on-chip circuitry. The HVDA has a gain of
0.05 V/V to 14 V/V. The first stage 20:1 difference amplifier has a gain of 0.05 V/V when the output amplifier is used as a unity gain buffer. When the output amplifier is set to a gain of 280 (selected using the
HVGAIN bits in the High Voltage Control Register), the overall gain of 14 can be attained. The HVDA is
factory calibrated for a high common-mode rejection of 72 dB.
The HVDA uses four available external pins: +HVAIN, HVAIN, HVCAP, and the aforementioned HVREF.
HVAIN+ and HVAIN- serve as the differential inputs to the HVDA. HVREF can be used to provide a common mode reference for input to ADC0. HVCAP facilitates the use of a capacitor for noise filtering in conjunction with R7 (see Figure 5.3 for R7 and other approximate resistor values). Alternatively, the HVCAP
could also be used to access amplification of the first stage of the HVDA at an external pin. (See Table 5.3
on page 68 for electrical specifications of the HVDA.)
5k
HVAIN5k
Vout
HVA0CN
HVAIN+
(To AMUX0)
100k
5k
Gain Setting
HVREF
52
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.4. HVA0CN: High Voltage Difference Amplifier Control
R/W
HVDAEN
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xD6
SFR Page: 0
Bit7:
Bits6-3:
Bits2-0:
HVDA Gain
0.05
0.1
0.125
0.2
0.25
0.4
0.5
0.8
1.0
1.6
2.0
3.2
4.0
6.2
7.6
14
Rev. 1.4
53
C8051F040/1/2/3/4/5/6/7
5.3.
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 ADC0SC bits of register ADC0CF.
The AD0BUSY bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete.
The falling edge of AD0BUSY triggers an interrupt (when enabled) and sets the AD0INT interrupt flag
(ADC0CN.5). Converted 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.7) depending on the programmed 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.
Step 2.
Step 3.
Step 4.
Write a 0 to AD0INT;
Write a 1 to AD0BUSY;
Poll AD0INT for 1;
Process ADC0 data.
54
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
A. ADC Timing for External Trigger Source
CNVSTR
(AD0STM[1:0]=10)
1
10 11 12 13 14 15 16
SAR Clocks
ADC0TM=1
ADC0TM=0
Low Power
or Convert
Track
Track Or Convert
Convert
Convert
Track
10 11 12 13 14 15 16 17 18 19
SAR Clocks
ADC0TM=1
Low Power
or Convert
Track
1
Convert
4
10 11 12 13 14 15 16
SAR Clocks
ADC0TM=0
Track or
Convert
Convert
Track
Rev. 1.4
55
C8051F040/1/2/3/4/5/6/7
5.3.3. Settling Time Requirements
A minimum tracking time is required before an accurate conversion can be performed. This tracking 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.5 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.2. When measuring the Temperature Sensor output, RTOTAL reduces to RMUX. Note that in
Low-Power tracking mode, three SAR clocks are used for tracking at the start of every conversion. For
most applications, these three SAR clocks will meet the tracking requirements. See Table 5.2 for absolute
minimum settling/tracking time requirements.
n
2
t = ln ------- R TOTAL C SAMPLE
SA
Equation 5.2. ADC0 Settling Time Requirements
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
RTOTAL is the sum of the ADC0 MUX resistance and any external source resistance.
n is the ADC resolution in bits (12).
Differential Mode
Single-Ended Mode
MUX Select
MUX Select
AIN0.x
AIN0.x
RMUX = 5k
RMUX = 5k
CSAMPLE = 10pF
CSAMPLE = 10pF
AIN0.y
RMUX = 5k
MUX Select
56
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
(Volts)
1.000
0.900
0.800
VTEMP = 0.00286(TEMPC) + 0.776
0.700
0.600
0.500
-50
50
100
(Celsius)
Rev. 1.4
57
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.5. ADC0CF: ADC0 Configuration Register
R/W
R/W
R/W
R/W
R/W
AD0SC4
AD0SC3
AD0SC2
AD0SC1
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xBC
SFR Page: 0
Bits7-3:
SYSCLK
AD0SC ----------------------- 1 *
CLK SAR0
or
SYSCLK
CLK SAR0 = ---------------------------AD0SC + 1
Bits2-0:
58
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.6. ADC0CN: ADC0 Control
R/W
R/W
AD0EN
AD0TM
Bit7
Bit6
R/W
R/W
R/W
R/W
Bit4
Bit3
Bit2
R/W
AD0WINT
Bit1
R/W
Reset Value
AD0LJST 00000000
Bit0
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3-2:
Bit1:
Bit0:
Rev. 1.4
59
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.7. ADC0H: ADC0 Data Word MSB
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:
Bits7-0:
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:
Bits7-0:
60
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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 --------------- 2 n ; n = 12 for Single-Ended; n=11 for Differential.
VREF
Rev. 1.4
61
C8051F040/1/2/3/4/5/6/7
5.4.
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 63. 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.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xC5
SFR Page: 0
Bits7-0:
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xC4
SFR Page: 0
Bits7-0:
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
SFR Page: 0
Bits7-0:
62
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 5.12. ADC0LTL: ADC0 Less-Than Data 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: 0xC6
SFR Page: 0
Bits7-0:
Input Voltage
(AD0 - AGND)
REF x (4095/4096)
Input Voltage
(AD0 - AGND)
ADC Data
Word
REF x (4095/4096)
0x0FFF
ADC Data
Word
0x0FFF
AD0WINT
not affected
AD0WINT=1
0x0201
REF x (512/4096)
0x0200
0x0201
ADC0LTH:ADC0LTL
REF x (512/4096)
0x01FF
0x0200
0x01FF
AD0WINT=1
0x0101
REF x (256/4096)
0x0100
0x0101
ADC0GTH:ADC0GTL
REF x (256/4096)
0x00FF
0x0100
AD0WINT
not affected
ADC0LTH:ADC0LTL
0x00FF
AD0WINT=1
AD0WINT
not affected
0
ADC0GTH:ADC0GTL
0x0000
0x0000
Given:
AMX0SL = 0x00, AMX0CF = 0x00,
AD0LJST = 0,
ADC0LTH:ADC0LTL = 0x0100,
ADC0GTH:ADC0GTL = 0x0200.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
> 0x0200 or < 0x0100.
Given:
AMX0SL = 0x00, AMX0CF = 0x00
AD0LJST = 0,
ADC0LTH:ADC0LTL = 0x0200,
ADC0GTH:ADC0GTL = 0x0100.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0x0200 and > 0x0100.
Figure 5.8. 12-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended
Data
Rev. 1.4
63
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AD1)
ADC Data
Word
Input Voltage
(AD0 - AD1)
ADC Data
Word
REF x (2047/2048)
0x07FF
REF x (2047/2048)
0x07FF
AD0WINT
not affected
AD0WINT=1
0x0101
REF x (256/2048)
0x0100
0x0101
ADC0LTH:ADC0LTL
REF x (256/2048)
0x00FF
0x0100
0x00FF
AD0WINT=1
0x0000
REF x (-1/2048)
0xFFFF
0x0000
ADC0GTH:ADC0GTL
REF x (-1/2048)
0xFFFE
0xFFFF
AD0WINT
not affected
ADC0LTH:ADC0LTL
0xFFFE
AD0WINT=1
AD0WINT
not affected
-REF
ADC0GTH:ADC0GTL
0xF800
-REF
0xF800
Given:
AMX0SL = 0x00, AMX0CF = 0x01,
AD0LJST = 0,
ADC0LTH:ADC0LTL = 0xFFFF,
ADC0GTH:ADC0GTL = 0x0100.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0xFFFF or > 0x0100. (In twos-complement
math, 0xFFFF = -1.)
Given:
AMX0SL = 0x00, AMX0CF = 0x01,
AD0LJST = 0,
ADC0LTH:ADC0LTL = 0x0100,
ADC0GTH:ADC0GTL = 0xFFFF.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0x0100 and > 0xFFFF. (In twos-complement
math, 0xFFFF = -1.)
Figure 5.9. 12-Bit ADC0 Window Interrupt Example: Right Justified Differential
Data
64
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AGND)
REF x (4095/4096)
Input Voltage
(AD0 - AGND)
ADC Data
Word
REF x (4095/4096)
0xFFF0
ADC Data
Word
0xFFF0
AD0WINT
not affected
AD0WINT=1
0x2010
REF x (512/4096)
0x2000
0x2010
REF x (512/4096)
ADC0LTH:ADC0LTL
0x1FF0
0x2000
0x1FF0
AD0WINT=1
0x1010
REF x (256/4096)
0x1000
0x1010
REF x (256/4096)
ADC0GTH:ADC0GTL
0x0FF0
0x1000
AD0WINT
not affected
ADC0LTH:ADC0LTL
0x0FF0
AD0WINT=1
AD0WINT
not affected
0
ADC0GTH:ADC0GTL
0x0000
0x0000
Given:
AMX0SL = 0x00, AMX0CF = 0x00,
AD0LJST = 1
ADC0LTH:ADC0LTL = 0x1000,
ADC0GTH:ADC0GTL = 0x2000.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0x1000 or > 0x2000.
Given:
AMX0SL = 0x00, AMX0CF = 0x00,
AD0LJST = 1,
ADC0LTH:ADC0LTL = 0x2000,
ADC0GTH:ADC0GTL = 0x1000.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0x2000 and > 0x1000.
Figure 5.10. 12-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended
Data
Rev. 1.4
65
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AD1)
ADC Data
Word
Input Voltage
(AD0 - AD1)
ADC Data
Word
REF x (2047/2048)
0x7FF0
REF x (2047/2048)
0x7FF0
AD0WINT
not affected
AD0WINT=1
0x1010
REF x (256/2048)
0x1000
0x1010
ADC0LTH:ADC0LTL
REF x (256/2048)
0x0FF0
0x1000
0x0FF0
AD0WINT=1
0x0000
REF x (-1/2048)
0xFFF0
0x0000
ADC0GTH:ADC0GTL
REF x (-1/2048)
0xFFE0
0xFFF0
AD0WINT
not affected
ADC0LTH:ADC0LTL
0xFFE0
AD0WINT=1
AD0WINT
not affected
-REF
ADC0GTH:ADC0GTL
0x8000
-REF
0x8000
Given:
AMX0SL = 0x00, AMX0CF = 0x01,
AD0LJST = 1,
ADC0LTH:ADC0LTL = 0xFFF0,
ADC0GTH:ADC0GTL = 0x1000.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0xFFF0 or > 0x1000. (Twos-complement
math.)
Given:
AMX0SL = 0x00, AMX0CF = 0x01,
AD0LJST = 1,
ADC0LTH:ADC0LTL = 0x1000,
ADC0GTH:ADC0GTL = 0xFFF0.
An ADC0 End of Conversion will cause an
ADC0 Window Compare Interrupt (AD0WINT
= 1) if the resulting ADC0 Data Word is
< 0x1000 and > 0xFFF0. (Twos-complement
math.)
Figure 5.11. 12-Bit ADC0 Window Interrupt Example: Left Justified Differential Data
66
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 5.2. 12-Bit ADC0 Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, VREF = 2.40 V (REFBE = 0), PGA Gain = 1, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
DC Accuracy
Resolution
12
Integral Nonlinearity
bits
LSB
Differential Nonlinearity
Guaranteed Monotonic
LSB
Offset Error
Note 1
0.53
LSB
0.43
LSB
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
75
dB
80
dB
2.5
MHz
16
clocks
1.5
Throughput Rate
100
ksps
VREF
AGND
AV+
10
pF
th
Up to the 5 harmonic
Analog Inputs
Input Voltage Range
Single-ended operation
Differential operation
Input Capacitance
Temperature Sensor
Nonlinearity
Notes 1, 2
Absolute Accuracy
Notes 1, 2
Gain
Notes 1, 2
2.86
0.034
mV/C
Offset
Notes 1, 2 (Temp = 0 C)
0.776
0.009
450
900
0.3
mV/V
Power Specifications
Notes:
1. Represents one standard deviation from the mean.
2. Includes ADC offset, gain, and linearity variations.
Rev. 1.4
67
C8051F040/1/2/3/4/5/6/7
Table 5.3. High Voltage Difference Amplifier Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, VREF = 3.0 V, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
60
60
+60
0.1
2.9
70
72
dB
mV
Analog Inputs
Differential range
peak-to-peak
(HVAIN+) (HVAIN) = 0 V
Analog Output
Output Voltage Range
DC Performance
Common Mode Rejection Ratio
Offset Voltage
Noise
HVCAP floating
500
nV/rtHz
Nonlinearity
G=1
72
dB
G = 0.05
MHz
G=1
150
kHz
V/S
10
105
98
51
HVCAP
450
1000
Dynamic Performance
Slew Rate
Settling Time
Input/Output Impedance
Power Specification
Quiescent Current
68
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
6.
The ADC0 subsystem for the C8051F042/3/4/5/6/7 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 Registers shown in Figure 6.1. The voltage reference used
by ADC0 is selected as described in Section 9. Voltage Reference (C8051F040/2/4/6) on page 113 for
C8051F042/4/6 devices, or Section 10. Voltage Reference (C8051F041/3/5/7) on page 117 for
C8051F043/5/7 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.
ADC0GTH
ADC0GTL
ADC0LTH
ADC0LTL
10-Bit
SAR
+
-
Analog
Input
Pins
ADC
AGND
00
TEMP
SENSOR
AD0EN
AD0TM
AD0INT
AD0BUSY
AD0CM1
AD0CM0
AD0WINT
AD0LJST
AMX0SL
AD0SC4
AD0SC3
AD0SC2
AD0SC1
AD0SC0
AMP0GN2
AMP0GN1
AMP0GN0
AMX0CF
AMX0AD3
AMX0AD2
AMX0AD1
AMX0AD0
Start Conversion 01
PORT3IC
HVDA2IC
AIN23IC
AIN01IC
AGND
10
ADC0L
9-to-1
AMUX
(SE or
DIFF)
ADC0CF
ADC0CN
AD0WINT
10
AV+
Port 3
I/O Pins
Comb.
Logic
ADC0H
AD0EN
REF
AV+
HV
Input
SYSCLK
20
AD0BUSY (W)
Timer 3 Overflow
10
CNVSTR0
11
Timer 2 Overflow
The analog multiplexer can input analog signals to the ADC from four external analog input pins, Port 3
port pins (optionally configured as analog input pins), High Voltage Difference Amplifier, and an internally
connected on-chip temperature sensor (temperature transfer function is shown in Figure 6.6). AMUX input
pairs can be programmed to operate in either differential or single-ended mode. This allows the user to
select the best measurement 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 three registers associated
with the AMUX: the Channel Selection register AMX0SL (SFR Definition 6.2), the Configuration register
AMX0CF (SFR Definition 6.1), and the Port Pin Selection register AMX0PRT (SFR Definition 6.3).
Table 6.1 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 (SFR Definition 6.5). 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
69
C8051F040/1/2/3/4/5/6/7
6.1.1. Analog Input Configuration
AMX0PRT
PAIN0EN
PAIN2EN
PAIN4EN
PAIN6EN
PAIN1EN
PAIN3EN
PAIN5EN
PAIN7EN
AIN67IC
AIN45IC
AIN23IC
AIN01IC
The analog multiplexer routes signals from external analog input pins, Port 3 I/O pins (programmed to be
analog inputs), a High Voltage Difference Amplifier, and an on-chip temperature sensor as shown in
Figure 6.2.
AIN0.0
AIN0.1
AIN0.2
AIN0.3
P3.0
6 AMUX
P3.7
7 (SE or
AMX0CF
P3.6
P3.4
(WIRED-OR)
P3.2
P3EVEN
P3.5
P3ODD
P3.3
(WIRED-OR)
9-to-1
10-Bit
SAR
ADC
DIFF)
P3.1
AGND
HVAIN +
HV
AMP
HVAIN HVREF
AMX0AD3
AMX0AD2
AMX0AD1
AMX0AD0
HVCAP
TEMP SENSOR
AMX0SL
AGND
70
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.1. AMX0CF: AMUX0 Configuration
R
Bit7
Bit6
Bit5
Bit4
R/W
R/W
PORT3IC HVDA2C
Bit3
Bit2
R/W
R/W
Reset Value
AIN23IC
AIN01IC
00000000
Bit1
Bit0
SFR Address:
Bits7-4:
Bit3:
Bit2:
Bit1:
Bit0:
NOTE:
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xBB
SFR Page: 0
Bits7-4:
Bits3-0:
Rev. 1.4
71
C8051F040/1/2/3/4/5/6/7
Table 6.1. AMUX Selection Chart (AMX0AD3-0 and AMX0CF3-0 bits)
AMX0AD3-0
0000
0001
0010
0011
0100
0101
0110
0111
1xxx
0000
AIN0.0
AIN0.1
AIN0.2
AIN0.3
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0001
+(AIN0.0)
-(AIN0.1)
AIN0.2
AIN0.3
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0010
AIN0.0
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0011
+(AIN0.0)
-(AIN0.1)
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
P3EVEN
P3ODD
TEMP
SENSOR
0100
AIN0.0
0101
+(AIN0.0)
-(AIN0.1)
0110
AIN0.0
0111
+(AIN0.0)
-(AIN0.1)
1000
AIN0.0
1001
+(AIN0.0)
-(AIN0.1)
1010
AIN0.0
1011
+(AIN0.0)
-(AIN0.1)
1100
AIN0.0
1101
+(AIN0.0)
-(AIN0.1)
1110
AIN0.0
1111
+(AIN0.0)
-(AIN0.1)
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.1
AIN0.2
AIN0.3
P3EVEN
P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
P3EVEN
P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
P3EVEN
P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
P3EVEN
P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
HVDA
AGND
+P3EVEN
-P3ODD
TEMP
SENSOR
AIN0.2
AIN0.3
+P3EVEN
-P3ODD)
TEMP
SENSOR
AIN0.2
AIN0.3
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
+P3EVEN
-P3ODD
TEMP
SENSOR
+(AIN0.2)
-(AIN0.3)
+P3EVEN
-P3ODD
TEMP
SENSOR
Note: P3EVEN denotes even numbered and P3ODD odd numbered Port 3 pins selected in the AMX0PRT
register.
72
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.3. AMX0PRT: Port 3 Pin Selection
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xBA
SFR Page: 0
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
NOTE: Any number of Port 3 pins may be selected simultaneously inputs to the AMUX. Odd numbered and even numbered pins that are selected simultaneously are shorted together as
wired-OR.
Rev. 1.4
73
C8051F040/1/2/3/4/5/6/7
6.2.
The High Voltage Difference Amplifier (HVDA) can be used to measure high differential voltages up to 60 V
peak-to-peak, reject high common-mode voltages up to 60 V, and condition the signal voltage range to be
suitable for input to ADC0. The input signal to the HVDA may be below AGND to -60 volts, and as high as
+60 volts, making the device suitable for both single and dual supply applications. The HVDA will provides
a common-mode signal for the ADC via the High Voltage Reference Input (HVREF), allowing measurement of signals outside the specified ADC input range using on-chip circuitry. The HVDA has a gain of
0.05 V/V to 14 V/V. The first stage 20:1 difference amplifier has a gain of 0.05 V/V when the output amplifier is used as a unity gain buffer. When the output amplifier is set to a gain of 280 (selected using the
HVGAIN bits in the High Voltage Control Register), the overall gain of 14 can be attained. The HVDA is
factory calibrated for a high common-mode rejection of 72 dB.
The HVDA uses four available external pins: +HVAIN, -HVAIN, HVCAP, and the aforementioned HVREF.
HVAIN+ and HVAIN- serve as the differential inputs to the HVDA. HVREF can be used to provide a common mode reference for input to ADC0. HVCAP facilitates the use of a capacitor for noise filtering in conjunction with R7 (see Figure 6.3 for R7 and other approximate resistor values). Alternatively, the HVCAP
could also be used to access amplification of the first stage of the HVDA at an external pin. (See Table 6.3
on page 90 for electrical specifications of the HVDA.)
HVCAP
100k
5k
HVAIN5k
Vout
HVA0CN
(To AMUX0)
HVAIN+
100k
5k
Gain Setting
HVREF
74
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.4. HVA0CN: High Voltage Difference Amplifier Control
R/W
HVDAEN
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xD6
SFR Page: 0
Bit7:
Bits6-3:
Bits2-0:
HVDA Gain
0.05
0.1
0.125
0.2
0.25
0.4
0.5
0.8
1.0
1.6
2.0
3.2
4.0
6.2
7.6
14
Rev. 1.4
75
C8051F040/1/2/3/4/5/6/7
6.3.
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 ADC0SC bits of register ADC0CF.
The AD0BUSY bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete.
The falling edge of AD0BUSY triggers an interrupt (when enabled) and sets the AD0INT interrupt flag
(ADC0CN.5). Converted 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.7) depending on the programmed 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.
Step 2.
Step 3.
Step 4.
Write a 0 to AD0INT;
Write a 1 to AD0BUSY;
Poll AD0INT for 1;
Process ADC0 data.
76
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
A. ADC Timing for External Trigger Source
CNVSTR
(AD0STM[1:0]=10)
1
10 11 12 13 14 15 16
SAR Clocks
ADC0TM=1
ADC0TM=0
Low Power
or Convert
Track
Track Or Convert
Convert
Convert
Track
10 11 12 13 14 15 16 17 18 19
SAR Clocks
ADC0TM=1
Low Power
or Convert
Track
1
Convert
4
10 11 12 13 14 15 16
SAR Clocks
ADC0TM=0
Track or
Convert
Convert
Track
Rev. 1.4
77
C8051F040/1/2/3/4/5/6/7
6.3.3. Settling Time Requirements
A minimum tracking time is required before an accurate conversion can be performed. This tracking 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.5 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.2. When measuring the Temperature Sensor output, RTOTAL reduces to RMUX. Note that in lowpower tracking mode, three SAR clocks are used for tracking at the start of every conversion. For most
applications, these three SAR clocks will meet the tracking requirements. See Table 6.2 for absolute minimum settling/tracking time requirements.
2
t = ln ------- R TOTAL C SAMPLE
SA
Differential Mode
Single-Ended Mode
MUX Select
MUX Select
AIN0.x
AIN0.x
RMUX = 5k
RMUX = 5k
CSAMPLE = 10pF
CSAMPLE = 10pF
AIN0.y
RMUX = 5k
MUX Select
78
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
(Volts)
1.000
0.900
0.800
VTEMP = 0.00286(TEMPC) + 0.776
0.700
0.600
0.500
-50
50
100
(Celsius)
Rev. 1.4
79
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.5. ADC0CF: ADC0 Configuration
R/W
R/W
R/W
R/W
AD0SC4
AD0SC3
AD0SC2
AD0SC1
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
SFR Address: 0xBC
SFR Page: 0
Bits7-3:
SYSCLK
AD0SC ----------------------- 1 *
CLK SAR0
or
SYSCLK
CLK SAR0 = ---------------------------AD0SC + 1
Bits2-0:
80
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.6. ADC0CN: ADC0 Control
R/W
R/W
AD0EN
AD0TM
Bit7
Bit6
R/W
R/W
R/W
R/W
Bit4
Bit3
Bit2
R/W
AD0WINT
Bit1
R/W
Reset Value
AD0LJST 00000000
Bit0
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3-2:
Bit1:
Bit0:
Rev. 1.4
81
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.7. ADC0H: ADC0 Data Word MSB
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:
Bits7-0:
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:
Bits7-0:
82
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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 --------------- 2 n ; n = 10 for Single-Ended; n=9 for Differential.
VREF
Figure 6.7. ADC0 Data Word Example
Rev. 1.4
83
C8051F040/1/2/3/4/5/6/7
6.4.
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 85. 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.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xC5
SFR Page: 0
Bits7-0:
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xC4
SFR Page: 0
Bits7-0:
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
SFR Page: 0
Bits7-0:
84
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 6.12. ADC0LTL: ADC0 Less-Than Data Low Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xC6
SFR Page: 0
Bits7-0:
Input Voltage
(AD0 - AGND)
REF x (1023/1024)
Input Voltage
(AD0 - AGND)
ADC Data
Word
0x03FF
REF x (1023/1024)
ADC Data
Word
0x03FF
AD0WINT
not affected
AD0WINT=1
0x0201
REF x (512/1024)
0x0200
0x0201
REF x (512/1024)
ADC0LTH:ADC0LTL
0x01FF
0x0200
0x01FF
AD0WINT=1
0x0101
REF x (256/1024)
0x0100
0x0101
REF x (256/1024)
ADC0GTH:ADC0GTL
0x00FF
0x0100
AD0WINT
not affected
ADC0LTH:ADC0LTL
0x00FF
AD0WINT=1
AD0WINT
not affected
0
ADC0GTH:ADC0GTL
0x0000
Given:
AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 0,
ADC0LTH:ADC0LTL = 0x0200,
ADC0GTH:ADC0GTL = 0x0100.
An ADC End of Conversion will cause an ADC
Window Compare Interrupt (ADWINT=1) if the
resulting ADC Data Word is < 0x0200 and
> 0x0100.
Given:
0x0000
Figure 6.8. 10-Bit ADC0 Window Interrupt Example: Right Justified Single-Ended
Data
Rev. 1.4
85
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AD1)
ADC Data
Word
Input Voltage
(AD0 - AD1)
ADC Data
Word
REF x (511/512)
0x01FF
REF x (511/512)
0x01FF
AD0WINT
not affected
AD0WINT=1
0x0101
REF x (256/512)
0x0100
0x0101
ADC0LTH:ADC0LTL
REF x (256/512)
0x00FF
0x0100
0x00FF
AD0WINT=1
0x0000
REF x (-1/512)
0xFFFF
0x0000
ADC0GTH:ADC0GTL
REF x (-1/512)
0xFFFE
0xFFFF
AD0WINT
not affected
ADC0LTH:ADC0LTL
0xFFFE
AD0WINT=1
AD0WINT
not affected
-REF
ADC0GTH:ADC0GTL
0xFE00
-REF
Given:
AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 0,
ADC0LTH:ADC0LTL = 0x0100,
ADC0GTH:ADC0GTL = 0xFFFF.
An ADC End of Conversion will cause an ADC
Window Compare Interrupt (ADWINT=1) if the
resulting ADC Data Word is < 0x0100 and
> 0xFFFF. (In twos-complement math,
0xFFFF = -1.)
Given:
0xFE00
Figure 6.9. 10-Bit ADC0 Window Interrupt Example: Right Justified Differential
Data
86
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AGND)
REF x (1023/1024)
Input Voltage
(AD0 - AGND)
ADC Data
Word
REF x (1023/1024)
0xFFC0
ADC Data
Word
0xFFC0
AD0WINT
not affected
AD0WINT=1
0x8040
REF x (512/1024)
0x8000
0x8040
ADC0LTH:ADC0LTL
REF x (512/1024)
0x7FC0
0x8000
0x7FC0
AD0WINT=1
0x4040
REF x (256/1024)
0x4000
0x4040
ADC0GTH:ADC0GTL
REF x (256/1024)
0x3FC0
0x4000
AD0WINT
not affected
ADC0LTH:ADC0LTL
0x3FC0
AD0WINT=1
AD0WINT
not affected
0
ADC0GTH:ADC0GTL
0x0000
Given:
AMX0SL = 0x00, AMX0CF = 0x00, ADLJST = 1,
ADC0LTH:ADC0LTL = 0x8000,
ADC0GTH:ADC0GTL = 0x4000.
An ADC End of Conversion will cause an ADC
Window Compare Interrupt (ADWINT=1) if the
resulting ADC Data Word is < 0x8000 and
> 0x4000.
Given:
0x0000
Figure 6.10. 10-Bit ADC0 Window Interrupt Example: Left Justified Single-Ended
Data
Rev. 1.4
87
C8051F040/1/2/3/4/5/6/7
Input Voltage
(AD0 - AD1)
ADC Data
Word
Input Voltage
(AD0 - AD1)
ADC Data
Word
REF x (511/512)
0x7FC0
REF x (511/512)
0x7FC0
AD0WINT
not affected
AD0WINT=1
0x4040
REF x (256/512)
0x4000
0x4040
ADC0LTH:ADC0LTL
REF x (256/512)
0x3FC0
0x4000
0x3FC0
AD0WINT=1
0x0000
REF x (-1/512)
0xFFC0
0x0000
ADC0GTH:ADC0GTL
REF x (-1/512)
0xFF80
0xFFC0
AD0WINT
not affected
ADC0LTH:ADC0LTL
0xFF80
AD0WINT=1
AD0WINT
not affected
-REF
ADC0GTH:ADC0GTL
0x8000
-REF
Given:
AMX0SL = 0x00, AMX0CF = 0x01, ADLJST = 1,
ADC0LTH:ADC0LTL = 0x4000,
ADC0GTH:ADC0GTL = 0xFFC0.
An ADC End of Conversion will cause an ADC
Window Compare Interrupt (ADWINT=1) if the
resulting ADC Data Word is < 0x4000 and
> 0xFFC0. (Twos-complement math.)
Given:
0x8000
Figure 6.11. 10-Bit ADC0 Window Interrupt Example: Left Justified Differential Data
88
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 6.2. 10-Bit ADC0 Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, VREF = 2.40 V (REFBE = 0), PGA Gain = 1, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
DC Accuracy
Resolution
10
Integral Nonlinearity
Differential Nonlinearity
Guaranteed Monotonic
Offset Error
Full Scale Error
Differential mode
bits
LSB
LSB
0.21
LSB
0.11
LSB
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
Total Harmonic Distortion
th
Up to the 5 harmonic
59
dB
70
dB
80
dB
Conversion Rate
SAR Clock Frequency
2.5
MHz
16
clocks
1.5
Throughput Rate
100
ksps
VREF
AGND
AV+
10
pF
Nonlinearity1,2
Absolute Accuracy1,2
2.86
0.034
mV/C
0.776
0.009
450
900
0.3
mV/V
Analog Inputs
Input Voltage Range
Single-ended operation
Differential operation
Input Capacitance
Temperature Sensor
Gain1,2
Offset1,2
Temp = 0 C
Power Specifications
Power Supply Current
(AV+ supplied to ADC)
Rev. 1.4
89
C8051F040/1/2/3/4/5/6/7
Table 6.3. High Voltage Difference Amplifier Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, VREF = 3.0 V, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
60
60
+60
0.1
2.9
70
72
dB
mV
Analog Inputs
Differential range
peak-to-peak
(HVAIN+) (HVAIN) = 0 V
Analog Output
Output Voltage Range
DC Performance
Common Mode Rejection Ratio
Vcm = 10 V to +10 V, Rs = 0
Offset Voltage
Noise
HVCAP floating
500
nV/rtHz
Nonlinearity
G=1
72
dB
G = 0.05
MHz
G=1
150
kHz
V/S
10
105
98
51
HVCAP
450
1000
Dynamic Performance
Slew Rate
Settling Time
Input/Output Impedance
Power Specification
Quiescent Current
90
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
7.
The ADC2 subsystem for the C8051F040/1/2/3 consists of an 8-channel, configurable analog multiplexer,
a programmable gain amplifier, and a 500 ksps, 8-bit successive-approximation-register ADC with integrated track-and-hold (see block diagram in Figure 7.1). The AMUX2, PGA2, and Data Conversion Modes,
are all configurable under software control via the Special Function Registers shown in Figure 7.1. The
ADC2 subsystem (8-bit ADC, track-and-hold and PGA) is enabled only when the AD2EN bit in the ADC2
Control register (ADC2CN) is set to logic 1. The ADC2 subsystem is in low power shutdown when this bit is
logic 0. The voltage reference used by ADC2 is selected as described in Section 9. Voltage Reference
(C8051F040/2/4/6) on page 113 for C8051F040/2 devices, or Section 10. Voltage Reference
(C8051F041/3/5/7) on page 117 for C8051F041/3 devices.
ADC2GTH
ADC2LTH
AV+
+
AIN2.1 (P1.1)
AIN2.2 (P1.2)
AIN2.3 (P1.3)
AIN2.4 (P1.4)
8-to-1
+ AMUX
AIN2.5 (P1.5)
AIN2.6 (P1.6)
AIN2.7 (P1.7)
AD2EN
ADC Window
Interrupt
AV+
8-Bit
SAR
+
-
ADC
AGND
AMX2SL
ADC2CF
AD2EN
AD2TM
AD2INT
AD2BUSY
AD2CM2
AD2CM1
AD2CM0
AMP2GN1
AMP2GN0
AD2SC4
AD2SC3
AD2SC2
AD2SC1
AD2SC0
AMX2AD2
AMX2AD1
AMX2AD0
AIN67IC
AIN45IC
AIN23IC
AIN01IC
Start Conversion
AMX2CF
Dig
Comp
ADC2
AIN2.0 (P1.0)
REF
SYSCLK
16
000
Write to AD2BUSY
001
Timer 3 Overflow
010
CNVSTR
011
Timer 2 Overflow
1xx
Write to AD0BUSY
(synchronized with
ADC0)
ADC2CN
Eight ADC2 channels are available for measurement, as selected by the AMX2SL register (see SFR Definition 7.2). The PGA amplifies the ADC2 output signal by an amount determined by the states of the
AMP2GN2-0 bits in the ADC2 Configuration register, ADC2CF (SFR Definition 7.1). The PGA can be software-programmed for gains of 0.5, 1, 2, or 4. Gain defaults to 0.5 on reset.
Important Note: AIN2 pins also function as Port 1 I/O pins, and must be configured as analog inputs when
used as ADC2 inputs. To configure an AIN2 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.5. Configuring Port 1, 2, and 3 Pins as Analog Inputs on page 209 for more information on configuring the AIN2 pins.
Rev. 1.4
91
C8051F040/1/2/3/4/5/6/7
7.2.
ADC2 has a maximum conversion speed of 500 ksps. The ADC2 conversion clock (SAR2 clock) is a
divided version of the system clock, determined by the AD2SC bits in the ADC2CF register (system clock
divided by (AD2SC + 1) for 0 AD2SC 31). The maximum ADC2 conversion clock is 7.5 MHz.
Write a 0 to AD2INT;
Write a 1 to AD2BUSY;
Poll AD2INT for 1;
Process ADC2 data.
92
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
A. ADC Timing for External Trigger Source
CNVSTR2/CNVSTR0
(AD2CM[2:0]=010)
1
SAR2 Clocks
AD2TM=1
AD2TM=0
Low Power
or Convert
Track
Track or Convert
Convert
Convert
Track
10 11 12
SAR2 Clocks
AD2TM=1
Low Power
or Convert
Track
1
Convert
4
SAR2 Clocks
AD2TM=0
Track or
Convert
Convert
Track
Rev. 1.4
93
C8051F040/1/2/3/4/5/6/7
7.2.3. Settling Time Requirements
A minimum tracking time is required before an accurate conversion can be performed. This tracking time is
determined by the ADC2 MUX resistance, the ADC2 sampling capacitance, any external source resistance, and the accuracy required for the conversion. Figure 7.3 shows the equivalent ADC2 input circuit.
The required ADC2 settling time for a given settling accuracy (SA) may be approximated by Equation 7.1.
Note: An absolute minimum settling time of 0.8 s required after any MUX selection. Note that in lowpower tracking mode, three SAR2 clocks are used for tracking at the start of every conversion. For most
applications, these three SAR2 clocks will meet the tracking requirements.
2
t = ln ------- R TOTAL C SAMPLE
SA
Equation 7.1. ADC2 Settling Time Requirements
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
RTOTAL is the sum of the ADC2 MUX resistance and any external source resistance.
n is the ADC resolution in bits (8).
MUX Select
AIN2.x
RMUX = 5k
CSAMPLE = 10pF
RCInput= RMUX * CSAMPLE
94
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 7.1. AMX2CF: AMUX2 Configuration
R
R/W
R/W
R/W
R/W
Reset Value
00000000
PIN67IC
PIN45IC
PIN23IC
PIN01IC
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xBA
SFR Page: 2
Bits7-4:
Bit3:
Bit2:
Bit1:
Bit0:
NOTE:
Bit7
Bit6
Bit5
Bit4
Bit3
R/W
R/W
R/W
Reset Value
Bit1
Bit0
SFR Address: 0xBB
SFR Page: 2
Bits7-3:
Bits2-0:
Rev. 1.4
95
C8051F040/1/2/3/4/5/6/7
Table 7.1. AMUX Selection Chart (AMX2AD2-0 and AMX2CF3-0 bits)
AMX2AD2-0
96
000
001
010
011
100
101
110
111
0000
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
0001
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
0010
P1.0
P1.1
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
P1.4
P1.5
P1.6
P1.7
0011
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
P1.4
P1.5
P1.6
P1.7
0100
P1.0
P1.1
P1.2
P1.3
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
P1.6
P1.7
0101
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
P1.2
P1.3
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
P1.6
P1.7
0110
P1.0
P1.1
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
P1.6
P1.7
0111
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
P1.6
P1.7
1000
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1001
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
P1.2
P1.3
P1.4
P1.5
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1010
P1.0
P1.1
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
P1.4
P1.5
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1011
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
P1.4
P1.5
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1100
P1.0
P1.1
P1.2
P1.3
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1101
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
P1.2
P1.3
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1110
P1.0
P1.1
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
1111
+(P1.0)
-(P1.1)
-(P1.0)
+(P1.1)
+(P1.2)
-(P1.3)
-(P1.2)
+(P1.3)
+(P1.4)
-(P1.5)
-(P1.4)
+(P1.5)
+(P1.6)
-(P1.7)
-(P1.6)
+(P1.7)
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 7.3. ADC2CF: ADC2 Configuration
R/W
R/W
R/W
R/W
R/W
AD2SC4
AD2SC3
AD2SC2
AD2SC1
AD2SC0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
R/W
R/W
Reset Value
Bit0
SFR Address: 0xBC
SFR Page: 2
Bits7-3:
SYSCLK
AD2SC ----------------------- 1 *
CLK SAR2
or
SYSCLK
CLK SAR2 = ----------------------------
AD2SC + 1
Bit2:
Bits1-0:
Rev. 1.4
97
C8051F040/1/2/3/4/5/6/7
SFR Definition 7.4. ADC2CN: ADC2 Control
R/W
R/W
AD2EN
AD2TM
Bit7
Bit6
R/W
R/W
R/W
R/W
Bit4
Bit3
Bit2
R/W
AD2CM0
Bit1
R/W
Reset Value
AD2WINT 00000000
Bit0
SFR Address: 0xE8
SFR Page: 2
Bit7:
98
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 7.5. ADC2: ADC2 Data Word
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
SFR Page: 2
Bits7-0:
8-bit ADC Data Word appears in the ADC2 Data Word Register as follows:
Example: ADC2 Data Word Conversion Map, AIN1.0 Input
(AMX2SL = 0x00)
AIN1.0-AGND
ADC2
(Volts)
VREF * (255/256)
0xFF
VREF / 2
0x80
VREF * (127/256)
0x7F
0
0x00
Gain
Code = Vin --------------- 256
VREF
Figure 7.4. ADC2 Data Word Example
Rev. 1.4
99
C8051F040/1/2/3/4/5/6/7
7.3.
The ADC2 Programmable Window Detector continuously compares the ADC2 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 (AD2WINT in ADC2CN) can also be used in polled mode. The
reference words are loaded into the ADC2 Greater-Than and ADC2 Less-Than registers (ADC2GT and
ADC2LT). 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 ADC2GT and ADC2LT registers.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xC4
SFR Page: 2
Bits7-0:
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
SFR Page: 2
Bits7-0:
100
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
ADC2
ADC2
Input Voltage
(P1.x - GND)
REF x (255/256)
Input Voltage
(P1.x - GND)
0xFF
REF x (255/256)
0xFF
AD2WINT
not affected
AD2WINT=1
0x21
REF x (32/256)
0x20
0x21
ADC2LT
REF x (32/256)
0x1F
0x20
0x1F
AD2WINT=1
0x11
REF x (16/256)
0x10
0x11
ADC2GT
REF x (16/256)
0x0F
0x10
ADC2GT
AD2WINT
not affected
ADC2LT
0x0F
AD2WINT=1
AD2WINT
not affected
0
0x00
0x00
Rev. 1.4
101
C8051F040/1/2/3/4/5/6/7
7.3.2. Window Detector In Differential Mode
Figure 7.6 shows two example window comparisons for differential mode, with ADC2LT = 0x10 (+16d) and
ADC2GT = 0xFF (1d). Notice that in Differential mode, the codes vary from VREF to VREF x (127/128)
and are represented as 8-bit 2s complement signed integers. In the left example, an AD2WINT interrupt
will be generated if the ADC2 conversion word (ADC2L) is within the range defined by ADC2GT and
ADC2LT (if 0xFF (1d) < ADC2 < 0x0F (16d)). In the right example, an AD2WINT interrupt will be generated if ADC2 is outside of the range defined by ADC2GT and ADC2LT (if ADC2 < 0xFF (1d) or ADC2 >
0x10 (+16d)).
ADC2
ADC2
Input Voltage
(P1.x - P1.y)
Input Voltage
(P1.x - P1.y)
REF x (127/128)
REF x (127/128)
0x7F (127d)
0x7F (127d)
AD2WINT
not affected
AD2WINT=1
0x11 (17d)
REF x (16/128)
0x10 (16d)
0x11 (17d)
ADC2LT
REF x (16/128)
0x0F (15d)
0x10 (16d)
0x0F (15d)
AD2WINT=1
REF x (-1/256)
0x00 (0d)
0xFF (-1d)
ADC2GT
REF x (-1/256)
0xFE (-2d)
0x00 (0d)
0xFF (-1d)
ADC2GT
AD2WINT
not affected
ADC2LT
0xFE (-2d)
AD2WINT=1
AD2WINT
not affected
-REF
0x80 (-128d)
-REF
0x80 (-128d)
102
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 7.2. ADC2 Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, VREF2 = 2.40 V (REFBE = 0), PGA2 = 1, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
DC Accuracy
Resolution
Integral Nonlinearity
Differential Nonlinearity
Guaranteed Monotonic
Offset Error
Full Scale Error
Differential mode
bits
LSB
LSB
0.50.3
LSB
10.2
LSB
Dynamic Performance (10 kHz sine-wave input, 0 to 1 dB below Full Scale, 500 ksps)
Signal-to-Noise Plus Distortion
Total Harmonic Distortion
th
Up to the 5 harmonic
45
47
dB
51
dB
52
dB
MHz
Conversion Rate
SAR Conversion Clock
Frequency
Conversion Time in SAR Clocks
clocks
300
ns
500
ksps
VREF
AV+
Input Capacitance
pF
420
900
0.3
mV/V
Single-ended
Power Specifications
Power Supply Current
(AV+ supplied to ADC2)
Rev. 1.4
103
C8051F040/1/2/3/4/5/6/7
NOTES:
104
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
8.
Timer 2
REF
12
DAC0
DAC0
AGND
Timer 2
Latch
Timer 4
Timer 3
Latch
DAC1H
DAC0L
Dig. MUX
AV+
DAC1EN
DAC1MD1
DAC1MD0
DAC1DF2
DAC1DF1
DAC1DF0
REF
Dig. MUX
Latch
Latch
DAC1H
AV+
DAC1L
DAC1CN
Timer 4
DAC0H
DAC0MD1
DAC0MD0
DAC0DF2
DAC0DF1
DAC0DF0
DAC0H
DAC0CN
DAC0EN
Timer 3
Each C8051F040/1/2/3 devices include two on-chip 12-bit voltage-mode Digital-to-Analog Converters
(DACs). Each DAC has an output swing of 0 V to (VREF 1 LSB) 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 voltage reference for each DAC is supplied at the VREFD pin
(C8051F040/2 devices) or the VREF pin (C8051F041/3 devices). Note that the VREF pin on C8051F041/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 (C8051F040/2/4/6) on page 113 or Section 10. Voltage Reference (C8051F041/3/5/7) on
page 117 for more information on configuring the voltage reference for the DACs.
12
DAC1
DAC1
AGND
Rev. 1.4
105
C8051F040/1/2/3/4/5/6/7
8.1.
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 operation is identical.
8.2.
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 overhead 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.
106
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 8.1. DAC0H: DAC0 High Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xD3
SFR Page: 0
Bits7-0:
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
SFR Page: 0
Bits7-0:
Rev. 1.4
107
C8051F040/1/2/3/4/5/6/7
SFR Definition 8.3. DAC0CN: DAC0 Control
R/W
DAC0EN
Bit7
Bit6
Bit5
R/W
R/W
R/W
R/W
R/W
Reset Value
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xD4
SFR Page: 0
Bit7:
Bits6-5:
Bits4-3:
Bits2-0:
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
001:
LSB
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
010:
LSB
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
011:
LSB
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
1xx:
LSB
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
108
LSB
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 8.4. DAC1H: DAC1 High Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xD3
SFR Page: 1
Bits7-0:
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
SFR Page: 1
Bits7-0:
Rev. 1.4
109
C8051F040/1/2/3/4/5/6/7
SFR Definition 8.6. DAC1CN: DAC1 Control
R/W
R/W
R/W
DAC1EN
Bit7
Bit6
Bit5
R/W
R/W
R/W
R/W
R/W
Reset Value
Bit3
Bit2
Bit1
Bit0
SFR
0xD4
Address:
1
SFR Page:
Bit7:
Bits6-5:
Bits4-3:
Bits2-0:
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
001:
LSB
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
010:
LSB
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
011:
LSB
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
1xx:
LSB
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
110
LSB
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
.
Parameter
Conditions
Min
Typ
Max
Units
Static Performance
Resolution
12
Integral Nonlinearity
Differential Nonlinearity
bits
LSB
LSB
No Output Filter
100 kHz Output Filter
10 kHz Output Filter
250
128
41
Vrms
Output Noise
Offset Error
30
mV
Offset Tempco
ppm/C
Full-Scale Error
20
60
mV
10
ppm/C
60
dB
100
300
15
mA
Load = 40 pF
0.44
V/s
10
VREF
LSB
10
60
ppm
110
400
Rev. 1.4
111
C8051F040/1/2/3/4/5/6/7
NOTES:
112
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
9.
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 (C8051F040/2 only) to reference an external voltage
reference or the on-chip voltage reference output. ADC0 may also reference the DAC0 output internally,
and ADC2 may reference the analog power supply voltage, via the VREF multiplexers shown in Figure 9.1.
The internal voltage reference circuit consists of a 1.2 V, temperature stable 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 specifications.
The Reference Control Register, REF0CN (defined in SFR Definition 9.1) enables/disables the internal reference generator and selects the reference inputs for ADC0 and ADC2. 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 the voltage reference used. 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
AD2VRS select the ADC0 and ADC2 voltage reference sources, respectively. The electrical specifications
for the Voltage Reference are given in Table 9.1.
The temperature sensor connects to the highest order input of the ADC0 input multiplexer (see Section
5.1. Analog Multiplexer and PGA on page 47 for C8051F040 devices, or Section 6.1. Analog Multiplexer and PGA on page 69 for C8051F042/4/6 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 meaningless data.
AD0VRS
AD2VRS
TEMPE
BIASE
REFBE
REF0CN
(C8051F040/2 only)
ADC2
AV+
1
Ref
VREF2
0
VDD
External
Voltage
Reference
Circuit
R1
ADC0
VREF0
0
Ref
(C8051F040/2 only)
DAC0
VREFD
Ref
DAC1
BIASE
EN
VREF
4.7F
x2
0.1F
1.2V
Band-Gap
Bias to
ADCs,
DACs
REFBE
Recommended Bypass
Capacitors
113
C8051F040/1/2/3/4/5/6/7
SFR Definition 9.1. REF0CN: Reference Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
00000000
AD0VRS
AD2VRS
TEMPE
BIASE
REFBE
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xD1
SFR Page: 0
Bits7-5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
114
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 9.1. Voltage Reference Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, 40 to +85C unless otherwise specified
Parameter
Conditions
Min
Typ
Max
Units
2.36
2.43
2.48
30
mA
25 C ambient
15
ppm/C
0.5
ppm/A
Load Regulation
ms
20
no bypass cap
10
40
140
ppm/V
Rev. 1.4
(AV+)
0.3
115
C8051F040/1/2/3/4/5/6/7
NOTES:
116
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
10. Voltage Reference (C8051F041/3/5/7)
The internal voltage reference circuit consists of a 1.2 V, temperature stable 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 recommended 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 ADC2 (C8051F041/3 only). ADC0 may
also reference the DAC0 output internally (C8051F041/3 only), and ADC2 may reference the analog power
supply voltage, via the VREF multiplexers shown in Figure 10.1.
The Reference Control Register, REF0CN (defined in SFR Definition 10.1) enables/disables the internal
reference generator and selects the reference inputs for ADC0 and ADC2. 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 the voltage reference used. 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 AD2VRS select the ADC0 and ADC2 voltage reference sources, respectively. The electrical specifications for the Voltage Reference are given in Table 10.1.
The temperature sensor connects to the highest order input of the ADC0 input multiplexer (see Section
5.1. Analog Multiplexer and PGA on page 47 for C8051F041 devices that feature a 12-bit ADC, or
Section 6.1. Analog Multiplexer and PGA on page 69 for C8051F043/5/7 devices that feature a 10-bit
ADC). 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 meaningless data.
AD0VRS
AD2VRS
TEMPE
BIASE
REFBE
REF0CN
(C8051F041/3 only)
ADC2
AV+
VDD
External
Voltage
Reference
Circuit
Ref
R1
0
VREFA
ADC0
0
(C8051F041/3 only)
Ref
DAC0
Ref
DAC1
BIASE
EN
VREF
4.7F
x2
0.1F
1.2V
Band-Gap
Bias to
ADCs,
DACs
REFBE
Recommended Bypass
Capacitors
117
C8051F040/1/2/3/4/5/6/7
SFR Definition 10.1. REF0CN: Reference Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
00000000
AD0VRS
AD1VRS
TEMPE
BIASE
REFBE
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xD1
SFR Page: 0
Bits7-5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
118
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 10.1. Voltage Reference Electrical Characteristics
VDD = 3.0 V, AV+ = 3.0 V, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
2.36
2.43
2.48
30
mA
15
ppm/C
25 C ambient
Load Regulation
0.5
ppm/A
ms
20
no bypass cap
10
40
140
ppm/V
1.00
(AV+)
0.3
Rev. 1.4
119
C8051F040/1/2/3/4/5/6/7
NOTES:
120
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
11. Comparators
C8051F04x family of devices include three on-chip programmable voltage comparators, shown in
Figure 11.1. Each comparator offers programmable response time and hysteresis. When assigned to a
Port pin, the Comparator output may be configured as open drain or push-pull, and Comparator inputs
should be configured as analog inputs (see Section 17.1.5. Configuring Port 1, 2, and 3 Pins as Analog Inputs on page 209). The Comparator may also be used as a reset source (see Section
13.5. Comparator0 Reset on page 169).
The output of a Comparator can be polled by software, used as an interrupt source, used as a reset
source, and/or routed to a Port pin. Each comparator can be individually enabled and disabled (shutdown).
When disabled, the Comparator output (if assigned to a Port I/O pin via the Crossbar) defaults to the logic
low state, and its supply current falls to less than 1 A. See Section 17.1.1. Crossbar Pin Assignment
and Allocation on page 207 for details on configuring the Comparator output via the digital Crossbar.
The Comparator inputs can be externally driven from -0.25 V to (VDD) + 0.25 V without damage or upset.
The complete electrical specifications for the Comparator are given in Table 11.1.
CPTnCN
The Comparator response time may be configured in software using the CPnMD1-0 bits in register CPTnMD (see SFR Definition 11.2). Selecting a longer response time reduces the amount of power consumed
by the comparator. See Table 11.1 for complete timing and current consumption specifications.
CPnEN
CPnOUT
CPnRIF
CPnFIF
CPnHYP1
CPnHYP0
CPnHYN1
CPnHYN0
VDD
CPn
Interrupt
CPn
Rising-edge
Interrupt Flag
P2.6
P2.7
CP1 +
CP1 -
P2.2
P2.3
CP2 +
CP2 -
P2.4
P2.5
CPn
Falling-edge
Interrupt Flag
Interrupt
Logic
CPn +
CPn -
SET
CLR
Q
Q
SET
CLR
Q
Q
Crossbar
CPn
(SYNCHRONIZER)
GND
CPTnMD
Reset
Decision
Tree
CPnRIEN
CPnFIEN
CPnMD1
CPnMD0
121
C8051F040/1/2/3/4/5/6/7
VIN+
VIN-
CPn+
CPn-
+
CPn
_
OUT
CIRCUIT CONFIGURATION
VIN-
INPUTS
VIN+
VOH
OUTPUT
VOL
Negative Hysteresis
Disabled
Positive Hysteresis
Disabled
Maximum
Negative Hysteresis
Maximum
Positive Hysteresis
122
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
11.1. Comparator Inputs
The Port pins selected as comparator inputs should be configured as analog inputs in the Port 2 Input Configuration Register (for details on Port configuration, see Section 17.1.3. Configuring Port Pins as Digital Inputs on page 209). The inputs for Comparator are on Port 2 as follows:
Comparator Input
Port PIN
CP0+
P2.6
CP0
P2.7
CP1+
P2.2
CP1
P2.3
CP2+
P2.4
CP2
P2.5
Rev. 1.4
123
C8051F040/1/2/3/4/5/6/7
SFR Definition 11.1. CPTnCN: Comparator 0, 1, and 2 Control
R/W
R/W
R/W
CPnEN
CPnOUT
CPnRIF
CPnFIF
Bit7
Bit6
Bit5
Bit4
R/W
R/W
R/W
R/W
Reset Value
Bit2
Bit1
Bit0
Bit7:
Bit6:
Bit5:
Bit4:
Bits3-2:
Bits1-0:
NOTE: Upon enabling a comparator, the output of the comparator is not immediately valid. Before
using a comparator as an interrupt or reset source, software should wait for a minimum of
the specified Power-up time as specified in Table 11.1, Comparator Electrical Characteristics, on page 126.
124
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 11.2. CPTnMD: Comparator Mode Selection
R/W
R/W
R/W
R/W
CPnRIE
CPnFIE
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
R/W
R/W
Reset Value
Bit0
Bits7-6:
Bit 5:
Bit 4:
Bits3-2:
Bits1-0:
CPnMD1 CPnMD0
0
0
0
1
1
0
1
1
Rev. 1.4
125
C8051F040/1/2/3/4/5/6/7
Table 11.1. Comparator Electrical Characteristics
VDD = 3.0 V, 40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
Response Time,
Mode 0
100
ns
CPn+ CPn = 10 mV
250
ns
Response Time,
Mode 1
175
ns
CPn+ CPn = 10 mV
500
ns
Response Time,
Mode 2
320
ns
CPn+ CPn = 10 mV
1100
ns
Response Time,
Mode 3
1050
ns
CPn+ CPn = 10 mV
5200
ns
1.5
mV/V
Common-Mode Rejection
Ratio
Positive Hysteresis 1
CPnHYP1-0 = 00
mV
Positive Hysteresis 2
CPnHYP1-0 = 01
4.5
mV
Positive Hysteresis 3
CPnHYP1-0 = 10
13
mV
Positive Hysteresis 4
CPnHYP1-0 = 11
10
17
25
mV
Negative Hysteresis 1
CPnHYN1-0 = 00
mV
Negative Hysteresis 2
CPnHYN1-0 = 01
4.5
mV
Negative Hysteresis 3
CPnHYN1-0 = 10
13
mV
Negative Hysteresis 4
CPnHYN1-0 = 11
10
17
25
mV
VDD + 0.25
Inverting or Non-Inverting
Input Voltage Range
0.25
Input Capacitance
pF
0.001
+5
nA
+5
mV
Power Supply
Power Supply Rejection
0.1
mV/V
Power-up Time
10
Mode 0
7.6
Mode 1
3.2
Mode 2
1.3
Mode 3
0.4
Supply Current at DC
126
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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 description in Section 23), two full-duplex UARTs (see description in Section 21 and Section 22), 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 25), 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:
-
D8
TMP2
B REGISTER
STACK POINTER
SRAM
ADDRESS
REGISTER
PSW
D8
D8
D8
ALU
SRAM
(256 X 8)
D8
D8
TMP1
ACCUMULATOR
D8
D8
D8
DATA BUS
DATA BUS
DATA BUS
SFR_ADDRESS
BUFFER
D8
DATA POINTER
D8
D8
SFR
BUS
INTERFACE
SFR_CONTROL
SFR_WRITE_DATA
SFR_READ_DATA
PC INCREMENTER
DATA BUS
MEM_CONTROL
A16
PIPELINE
RESET
MEMORY
INTERFACE
MEM_READ_DATA
CONTROL
LOGIC
SYSTEM_IRQs
D8
STOP
POWER CONTROL
REGISTER
MEM_WRITE_DATA
D8
CLOCK
IDLE
MEM_ADDRESS
D8
INTERRUPT
INTERFACE
DEBUG_IRQ
D8
Rev. 1.4
127
C8051F040/1/2/3/4/5/6/7
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 execute, and usually have a maximum system clock of 12 MHz. By contrast, the CIP-51
core executes 70% of its instructions 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
2/3
3/4
4/5
Number of Instructions
26
50
14
128
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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.
Description
ADD A, Rn
ADD A, direct
ADD A, @Ri
ADD A, #data
ADDC A, Rn
ADDC A, direct
ADDC A, @Ri
ADDC A, #data
SUBB A, Rn
SUBB A, direct
SUBB A, @Ri
SUBB A, #data
INC A
INC Rn
INC direct
INC @Ri
DEC A
Arithmetic Operations
Add register to A
Add direct byte to A
Add indirect RAM to A
Add immediate to A
Add register to A with carry
Add direct byte to A with carry
Add indirect RAM to A with carry
Add immediate to A with carry
Subtract register from A with borrow
Subtract direct byte from A with borrow
Subtract indirect RAM from A with borrow
Subtract immediate from A with borrow
Increment A
Increment register
Increment direct byte
Increment indirect RAM
Decrement A
Rev. 1.4
Bytes
Clock
Cycles
1
2
1
2
1
2
1
2
1
2
1
2
1
1
2
1
1
1
2
2
2
1
2
2
2
1
2
2
2
1
1
2
2
1
129
C8051F040/1/2/3/4/5/6/7
Table 12.1. CIP-51 Instruction Set Summary (Continued)
Mnemonic
Description
DEC Rn
DEC direct
DEC @Ri
INC DPTR
MUL AB
DIV AB
DA A
Decrement register
Decrement direct byte
Decrement indirect RAM
Increment Data Pointer
Multiply A and B
Divide A by B
Decimal adjust A
Logical Operations
AND Register to A
AND direct byte to A
AND indirect RAM to A
AND immediate to A
AND A to direct byte
AND immediate to direct byte
OR Register to A
OR direct byte to A
OR indirect RAM to A
OR immediate to A
OR A to direct byte
OR immediate to direct byte
Exclusive-OR Register to A
Exclusive-OR direct byte to A
Exclusive-OR indirect RAM to A
Exclusive-OR immediate to A
Exclusive-OR A to direct byte
Exclusive-OR immediate to direct byte
Clear A
Complement A
Rotate A left
Rotate A left through Carry
Rotate A right
Rotate A right through Carry
Swap nibbles of A
Data Transfer
Move Register to A
Move direct byte to A
Move indirect RAM to A
Move immediate to A
Move A to Register
Move direct byte to Register
Move immediate to Register
Move A to direct byte
Move Register to direct byte
Move direct byte to direct byte
Move indirect RAM to direct byte
ANL A, Rn
ANL A, direct
ANL A, @Ri
ANL A, #data
ANL direct, A
ANL direct, #data
ORL A, Rn
ORL A, direct
ORL A, @Ri
ORL A, #data
ORL direct, A
ORL direct, #data
XRL A, Rn
XRL A, direct
XRL A, @Ri
XRL A, #data
XRL direct, A
XRL direct, #data
CLR A
CPL A
RL A
RLC A
RR A
RRC A
SWAP A
MOV A, Rn
MOV A, direct
MOV A, @Ri
MOV A, #data
MOV Rn, A
MOV Rn, direct
MOV Rn, #data
MOV direct, A
MOV direct, Rn
MOV direct, direct
MOV direct, @Ri
130
1
2
1
1
1
1
1
Clock
Cycles
1
2
2
1
4
8
1
1
2
1
2
2
3
1
2
1
2
2
3
1
2
1
2
2
3
1
1
1
1
1
1
1
1
2
2
2
2
3
1
2
2
2
2
3
1
2
2
2
2
3
1
1
1
1
1
1
1
1
2
1
2
1
2
2
2
2
3
2
1
2
2
2
1
2
2
2
2
3
2
Bytes
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 12.1. CIP-51 Instruction Set Summary (Continued)
Mnemonic
Description
CLR C
CLR bit
SETB C
SETB bit
CPL C
CPL bit
ANL C, bit
ANL C, /bit
ORL C, bit
ORL C, /bit
MOV C, bit
MOV bit, C
JC rel
JNC rel
JB bit, rel
JNB bit, rel
JBC bit, rel
ACALL addr11
LCALL addr16
RET
RETI
AJMP addr11
LJMP addr16
SJMP rel
JMP @A+DPTR
JZ rel
3
1
2
2
3
1
1
1
1
1
1
2
2
1
2
1
1
Clock
Cycles
3
2
2
2
3
3
3
3
3
3
3
2
2
1
2
2
2
1
2
1
2
1
2
2
2
2
2
2
2
2
2
3
3
3
1
2
1
2
1
2
2
2
2
2
2
2
2/3
2/3
3/4
3/4
3/4
2
3
1
1
2
3
2
1
2
3
4
5
5
3
4
3
3
2/3
Bytes
Rev. 1.4
131
C8051F040/1/2/3/4/5/6/7
Table 12.1. CIP-51 Instruction Set Summary (Continued)
Mnemonic
Description
JNZ rel
CJNE A, direct, rel
CJNE A, #data, rel
2
3
3
Clock
Cycles
2/3
3/4
3/4
3/4
4/5
2
3
1
2/3
3/4
1
Bytes
132
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
12.2. Memory Organization
The memory organization of the CIP-51 System Controller is similar to that of a standard 8051. There are
two separate 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.
PROGRAM/DATA MEMORY
(FLASH)
C8051F040/1/2/3/4/5
0x1007F
0x10000
0xFE00
Scrachpad Memory
(DATA only)
RESERVED
0xFF
0x80
0x7F
Special Function
Registers
(Direct Addressing Only) 0
0xFDFF
64 kB
Flash
(In-System
Programmable in 512
Byte Sectors)
0x30
0x2F
0x20
0x1F
0x00
0x0000
Bit Addressable
General Purpose
Registers
Up To
256 SFR Pages
0x1007F
0x10000
0x8000
0x7FFF
Scrachpad Memory
(DATA only)
0xFFFF
RESERVED
Off-chip XRAM space
32 kB
Flash
(In-System
Programmable in 512
Byte Sectors)
0x1000
0x0FFF
0x0000
0x0000
Rev. 1.4
133
C8051F040/1/2/3/4/5/6/7
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.
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; 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 which is accessed by the debug logic. 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 register. (A POP or decrement SP pops one record bit,
134
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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.
Rev. 1.4
135
C8051F040/1/2/3/4/5/6/7
Interrupt
Logic
SFRPAGE
SFRNEXT
SFRLAST
Figure 12.3. SFR Page Stack
Automatic hardware switching of the SFR Page on interrupts may be enabled or disabled as desired using
the SFR Automatic Page Control Enable Bit located in the SFR Page Control Register (SFRPGCN). This
function defaults to enabled upon reset. In this way, the autoswitching function will be enabled unless disabled in software.
A summary of the SFR locations (address and SFR page) is provided in Table 12.2. in the form of an SFR
memory map. Each memory location in the map has an SFR page row, denoting the page in which that
SFR resides. Note that certain SFRs are accessible from ALL SFR pages, and are denoted by the (ALL
PAGES) designation. For example, the Port I/O registers P0, P1, P2, and P3 all have the (ALL PAGES)
designation, indicating these SFRs are accessible from all SFR pages regardless of the SFRPAGE register value.
136
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
12.2.6.3.SFR Page Stack Example
The following is an example of a C8051F040 device that shows the operation of the SFR Page Stack during interrupts.
In this example, the SFR Page Control is left in the default enabled state (i.e., SFRPGEN = 1), and the
CIP-51 is executing in-line code that is writing values to Port 5 (SFR P5, located at address 0xD8 on SFR
Page 0x0F). The device is also using the Programmable Counter Array (PCA) and the 8-bit ADC (ADC2)
window comparator to monitor a voltage. The PCA is timing a critical control function in its interrupt service
routine (ISR), so its interrupt is enabled and is set to high priority. The ADC2 is monitoring a voltage that is
less important, but to minimize the software overhead its window comparator is being used with an associated ISR that is set to low priority. At this point, the SFR page is set to access the Port 5 SFR (SFRPAGE =
0x0F). See Figure 12.4 below.
SFR Page
Stack SFR's
0x0F
SFRPAGE
(Port 5)
SFRNEXT
SFRLAST
Figure 12.4. SFR Page Stack While Using SFR Page 0x0F To Access Port 5
Rev. 1.4
137
C8051F040/1/2/3/4/5/6/7
While CIP-51 executes in-line code (writing values to Port 5 in this example), an ADC2 Window Comparator Interrupt occurs. The CIP-51 vectors to the ADC2 Window Comparator ISR and pushes the current
SFR Page value (SFR Page 0x0F) into SFRNEXT in the SFR Page Stack. The SFR page needed to
access ADC2s SFRs is then automatically placed in the SFRPAGE register (SFR Page 0x02). SFRPAGE
is considered the top of the SFR Page Stack. Software can now access the ADC2 SFRs. Software may
switch to any SFR Page by writing a new value to the SFRPAGE register at any time during the ADC2 ISR
to access SFRs that are not on SFR Page 0x02. See Figure 12.5 below.
0x02
SFRPAGE
SFRPAGE
pushed to
SFRNEXT
(ADC2)
0x0F
SFRNEXT
(Port 5)
SFRLAST
Figure 12.5. SFR Page Stack After ADC2 Window Comparator Interrupt Occurs
138
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
While in the ADC2 ISR, a PCA interrupt occurs. Recall the PCA interrupt is configured as a high priority
interrupt, while the ADC2 interrupt is configured as a low priority interrupt. Thus, the CIP-51 will now vector
to the high priority PCA ISR. Upon doing so, the CIP-51 will automatically place the SFR page needed to
access the PCAs special function registers into the SFRPAGE register, SFR Page 0x00. The value that
was in the SFRPAGE register before the PCA interrupt (SFR Page 2 for ADC2) is pushed down the stack
into SFRNEXT. Likewise, the value that was in the SFRNEXT register before the PCA interrupt (in this
case SFR Page 0x0F for Port 5) is pushed down to the SFRLAST register, the bottom of the stack. Note
that a value stored in SFRLAST (via a previous software write to the SFRLAST register) will be overwritten.
See Figure 12.6 below.
0x00
SFRPAGE
SFRPAGE
pushed to
SFRNEXT
(PCA)
0x02
SFRNEXT
SFRNEXT
pushed to
SFRLAST
(ADC2)
0x0F
SFRLAST
(Port 5)
Figure 12.6. SFR Page Stack Upon PCA Interrupt Occurring During an ADC2 ISR
Rev. 1.4
139
C8051F040/1/2/3/4/5/6/7
On exit from the PCA interrupt service routine, the CIP-51 will return to the ADC2 Window Comparator
ISR. On execution of the RETI instruction, SFR Page 0x00 used to access the PCA registers will be automatically popped off of the SFR Page Stack, and the contents of the SFRNEXT register will be moved to
the SFRPAGE register. Software in the ADC2 ISR can continue to access SFRs as it did prior to the PCA
interrupt. Likewise, the contents of SFRLAST are moved to the SFRNEXT register. Recall this was the
SFR Page value 0x0F being used to access Port 5 before the ADC2 interrupt occurred. See Figure 12.7
below.
0x02
SFRPAGE
SFRNEXT
popped to
SFRPAGE
(ADC2)
0x0F
SFRNEXT
SFRLAST
popped to
SFRNEXT
(Port 5)
SFRLAST
Figure 12.7. SFR Page Stack Upon Return From PCA Interrupt
140
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
On the execution of the RETI instruction in the ADC2 Window Comparator ISR, the value in SFRPAGE
register is overwritten with the contents of SFRNEXT. The CIP-51 may now access the Port 5 SFR bits as
it did prior to the interrupts occurring. See Figure 12.8 below.
SFR Page 0x02
Automatically
popped off of the
stack on return from
interrupt
0x0F
SFRPAGE
SFRNEXT
popped to
SFRPAGE
(Port 5)
SFRNEXT
SFRLAST
Figure 12.8. SFR Page Stack Upon Return From ADC2 Window Interrupt
Note that in the above example, all three bytes in the SFR Page Stack are accessible via the SFRPAGE,
SFRNEXT, and SFRLAST special function registers. If the stack is altered while servicing an interrupt, it is
possible to return to a different SFR Page upon interrupt exit than selected prior to the interrupt call. Direct
access to the SFR Page stack can be useful to enable real-time operating systems to control and manage
context switching between multiple tasks.
Push operations on the SFR Page Stack only occur on interrupt service, and pop operations only occur on
interrupt exit (execution on the RETI instruction). The automatic switching of the SFRPAGE and operation
of the SFR Page Stack as described above can be disabled in software by clearing the SFR Automatic
Page Enable Bit (SFRPGEN) in the SFR Page Control Register (SFRPGCN). See SFR Definition 12.1.
Rev. 1.4
141
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.1. SFR Page Control Register: SFRPGCN
R
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
R/W
Reset Value
SFRPGEN 00000001
Bit0
SFR Address: 0x81
SFR Page: All Pages
Bits7-1:
Bit0:
Reserved.
SFRPGEN: SFR Automatic Page Control Enable.
Upon interrupt the C8051 Core will vector to the specified interrupt service routine and automatically switch the SFR page to the corresponding peripheral or functions SFR page. This
bit is used to control this autopaging function.
0: SFR Automatic Paging disabled. C8051 core will not automatically change to the appropriate SFR page (i.e., the SFR page that contains the SFRs for the peripheral/function that
was the source of the interrupt).
1: SFR Automatic Paging enabled. Upon interrupt, the CIP-51 will switch the SFR page to
the page that contains the SFRs for the peripheral or function that is the source of the interrupt.
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: 0x84
SFR Page: All Pages
Bits7-0:
142
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.3. SFR Next Register: SFRNEXT
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x85
SFR Page: All Pages
Bits7-0:
SFR page context is retained upon interrupts/return from interrupts in a 3 byte SFR Page
Stack: SFRPAGE is the first entry, SFRNEXT is the second, and SFRLAST is third entry.
The SFRPAGE, SFRSTACK, and SFRLAST bytes may be used alter the context in the SFR
Page Stack. Only interrupts and returns from interrupt service routines push and pop the
SFR Page Stack. (See Section 12.2.6.2 and Section 12.2.6.3 for further information.)
Write:
Sets the SFR Page contained in the second byte of the SFR Stack. This will cause the
SFRPAGE SFR to have this SFR page value upon a return from interrupt.
Read:
Returns the value of the SFR page contained in the second byte of the SFR stack. This is
the value that will go to the SFR Page register upon a return from interrupt.
Rev. 1.4
143
C8051F040/1/2/3/4/5/6/7
Table 12.2. Special Function Register (SFR) Memory Map
A
D
D
R
E
S
S
0(8)
1(9)
2(A)
SPI0CN
CAN0CN
PCA0L
PCA0H
3(B)
4(C)
5(D)
6(E)
7(F)
0
WDTCN
(ALL PAGES)
F8
SFR
P
A
G
E
P7
1
2
3
F
0
F0 (ALL PAGES)
ADC0CN
ADC2CN
PCA0CPL2
E8
P6
PCA0CPL5
ACC
E0 (ALL PAGES)
XBR0
PCA0CN
PCA0MD
CAN0DATL CAN0DATH
D8
P5
REF0CN
PSW
D0 (ALL PAGES)
C8
TMR2CN
TMR3CN
TMR4CN
TMR2CF
TMR3CF
TMR4CF
P4
SMB0CN
CAN0STA
SMB0STA
C0
SADEN0
B8
IP
(ALL PAGES)
0(8)
144
1(9)
1
EIP1
EIP2
2
(ALL PAGES) (ALL PAGES)
3
F
0
PCA0CPH2 PCA0CPL3 PCA0CPH3 PCA0CPL4 PCA0CPH4 RSTSRC
1
2
3
F
0
PCA0CPH5
1
EIE1
EIE2
2
(ALL PAGES) (ALL PAGES)
3
F
XBR1
XBR2
XBR3
PCA0CPM0 PCA0CPM1 PCA0CPM2 PCA0CPM3 PCA0CPM4 PCA0CPM5 0
1
CAN0ADR CAN0TST
2
3
F
0
DAC0L
DAC0H
DAC0CN
HVA0CN
1
DAC1L
DAC1H
DAC1CN
2
3
F
0
RCAP2L
RCAP2H
TMR2L
TMR2H
SMB0CR
1
RCAP3L
RCAP3H
TMR3L
TMR3H
2
RCAP4L
RCAP4H
TMR4L
TMR4H
3
F
0
SMB0DAT SMB0ADR ADC0GTL ADC0GTH ADC0LTL
ADC0LTH
1
2
ADC2GT
ADC2LT
3
F
0
AMX0CF
AMX0SL
ADC0CF
AMX0PRT
ADC0L
ADC0H
1
2
AMX2CF
AMX2SL
ADC2CF
ADC2
3
F
2(A)
3(B)
4(C)
Rev. 1.4
5(D)
6(E)
7(F)
C8051F040/1/2/3/4/5/6/7
Table 12.2. Special Function Register (SFR) Memory Map (Continued)
A
D
D
R
E
S
S
B0
0(8)
1(9)
2(A)
3(B)
4(C)
5(D)
6(E)
7(F)
FLSCL
FLACL
1
2
3
F
P3MDIN
1
2
3
F
P3MDOUT
1
2
3
F
P7MDOUT
1
2
3
F
P3
(ALL PAGES)
SADDR0
IE
A8 (ALL PAGES)
P1MDIN
EMI0TC
A0
EMI0CN
P2MDIN
EMI0CF
P2
(ALL PAGES)
P0MDOUT
SCON0
SCON1
SBUF0
SBUF1
SPI0CFG
SPI0DAT
P1MDOUT
SPI0CKR
P2MDOUT
98
P4MDOUT
P5MDOUT
P6MDOUT
SSTA0
90
88
P1
(ALL PAGES)
TCON
CPT0CN
CPT1CN
CPT2CN
TMOD
CPT0MD
CPT1MD
CPT2MD
SFR
P
A
G
E
TL0
TL1
TH0
OSCICN
OSCICL
OSCXCN
TH1
SFRPGCN
CKCON
CLKSEL
PSCTL
1
2
3
F
0
1
2
3
F
0
1
P0
SP
DPL
DPH
SFRPAGE SFRNEXT SFRLAST
PCON
2
80
(ALL PAGES) (ALL PAGES) (ALL PAGES) (ALL PAGES) (ALL PAGES) (ALL PAGES) (ALL PAGES) (ALL PAGES)
3
F
0(8)
1(9)
2(A)
3(B)
4(C)
Rev. 1.4
5(D)
6(E)
7(F)
145
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.4. SFR Last Register: SFRLAST
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x86
SFR Page: All Pages
Bits7-0:
SFR page context is retained upon interrupts/return from interrupts in a 3 byte SFR Page
Stack: SFRPAGE is the first entry, SFRNEXT is the second, and SFRLAST is the third entry.
The SFR stack bytes may be used alter the context in the SFR Page Stack, and will not
cause the stack to push or pop. Only interrupts and returns from the interrupt service routine push and pop the SFR Page Stack.
Write:
Sets the SFR Page in the last entry of the SFR Stack. This will cause the SFRNEXT SFR to
have this SFR page value upon a return from interrupt.
Read:
Returns the value of the SFR page contained in the last entry of the SFR stack.
146
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 12.3. Special Function Registers
SFRs are listed in alphabetical order. All undefined SFR locations are reserved.
Register
Address
SFR Page
Description
Page No.
ACC
ADC0CF
0xE0
0xBC
All Pages
0
Accumulator
ADC0 Configuration
page 153
ADC0CN
0xE8
ADC0 Control
ADC0GTH
0xC5
ADC0GTL
0xC4
ADC0H
0xBF
ADC0L
0xBE
ADC0LTH
0xC7
ADC0LTL
0xC6
ADC23
0xBE
0xBC
page 95
ADC2CN3
0xE8
ADC2 Control
page 98
ADC2GT3
0xC4
ADC2LT3
0xC6
page 100
AMX0CF
AMX0PRT
AMX0SL
0xBA
0xBD
0xBB
0
0
0
AMX2CF3
0xBA
AMX2SL3
B
CAN0ADR
CAN0CN
CAN0DATH
CAN0DATL
CAN0STA
CAN0TST
CKCON
CLKSEL
CPT0MD
CPT1MD
CPT2MD
CPT0CN
CPT1CN
CPT2CN
DAC0CN3
0xBB
0xF0
0xDA
0xF8
0xD9
0xD8
0xC0
0xDB
0x8E
0x97
0x89
0x89
0x89
0x88
0x88
0x88
0xD4
2
All Pages
1
1
1
1
1
1
0
F
1
2
3
1
2
3
0
page 95
page 153
page 213
page 213
page 212
page 212
page 214
page 214
page 295
page 177
page 125
page 125
page 125
page 124
page 124
page 124
page 108
DAC0H3
0xD3
DAC0 High
page 107
ADC2CF
0xD2
DAC0 Low
page 107
DAC1CN3
0xD4
DAC1 Control
page 110
DAC1H3
0xD3
page 109
DAC0L
Rev. 1.4
147
C8051F040/1/2/3/4/5/6/7
Table 12.3. Special Function Registers (Continued)
SFRs are listed in alphabetical order. All undefined SFR locations are reserved.
Register
DAC1L3
DPH
DPL
EIE1
EIE2
EIP1
EIP2
EMI0CF
EMI0CN
EMI0TC
FLACL
FLSCL
HVA0CN
IE
IP
OSCICL
OSCICN
OSCXCN
P0
P0MDOUT
P1
P1MDIN
P1MDOUT
P2
P2MDIN
P2MDOUT
P3
P3MDIN
P3MDOUT
Address
SFR Page
Description
Page No.
1
All Pages
All Pages
All Pages
All Pages
All Pages
All Pages
0
0
0
F
0
0
All Pages
All Pages
F
F
F
All Pages
F
All Pages
F
F
All Pages
F
F
All Pages
F
F
F
page 109
page 151
page 151
page 160
page 161
page 162
page 163
page 192
page 191
page 197
page 186
page 186
P44
0xD2
0x83
0x82
0xE6
0xE7
0xF6
0xF7
0xA3
0xA2
0xA1
0xB7
0xB7
0xD6
0xA8
0xB8
0x8B
0x8A
0x8C
0x80
0xA4
0x90
0xAD
0xA5
0xA0
0xAE
0xA6
0xB0
0xAF
0xA7
0xC8
P4MDOUT4
0x9C
page 224
P54
0xD8
Port 5 Latch
page 225
0x9D
page 225
0xE8
Port 6 Latch
page 226
0x9E
page 226
0xF8
Port 7 Latch
page 227
0x9F
0xD8
0xFC
0xFE
0xEA
0xEC
F
0
0
0
0
0
page 227
page 314
page 318
page 318
page 318
page 318
P5MDOUT
P6
P6MDOUT
P7
4
4
P7MDOUT
PCA0CN
PCA0CPH0
PCA0CPH1
PCA0CPH2
PCA0CPH3
148
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 12.3. Special Function Registers (Continued)
SFRs are listed in alphabetical order. All undefined SFR locations are reserved.
Register
PCA0CPH4
PCA0CPH5
PCA0CPL0
PCA0CPL1
PCA0CPL2
PCA0CPL3
PCA0CPL4
PCA0CPL5
PCA0CPM0
PCA0CPM1
PCA0CPM2
PCA0CPM3
PCA0CPM4
PCA0CPM5
PCA0H
PCA0L
PCA0MD
PCON
PSCTL
PSW
RCAP2H
RCAP2L
RCAP3H
RCAP3L
RCAP4H
RCAP4L
REF0CN
RSTSRC
SADDR0
SADEN0
SBUF0
SBUF1
SCON0
SCON1
SFRPAGE
SFRPGCN
SFRNEXT
SFRLAST
SMB0ADR
SMB0CN
SMB0CR
SMB0DAT
SMB0STA
SP
Address
0xEE
0xE2
0xFB
0xFD
0xE9
0xEB
0xED
0xE1
0xDA
0xDB
0xDC
0xDD
0xDE
0xDF
0xFA
0xF9
0xD9
0x87
0x8F
0xD0
0xCB
0xCA
0xCB
0xCA
0xCB
0xCA
0xD1
0xEF
0xA9
0xB9
0x99
0x99
0x98
0x98
0x84
0x96
0x85
0x86
0xC3
0xC0
0xCF
0xC2
0xC1
0x81
SFR Page
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
All Pages
0
All Pages
0
0
1
1
2
2
0
0
0
0
0
1
0
1
All Pages
F
All Pages
All Pages
0
0
0
0
0
All Pages
Description
PCA Capture 4 High
PCA Capture 5 High
PCA Capture 0 Low
PCA Capture 1 Low
PCA Capture 2 Low
PCA Capture 3 Low
PCA Capture 4 Low
PCA Capture 5 Low
PCA Module 0 Mode Register
PCA Module 1 Mode Register
PCA Module 2 Mode Register
PCA Module 3 Mode Register
PCA Module 4 Mode Register
PCA Module 5 Mode Register
PCA Counter High
PCA Counter Low
PCA Mode
Power Control
Program Store R/W Control
Program Status Word
Timer/Counter 2 Capture/Reload High
Timer/Counter 2 Capture/Reload Low
Timer/Counter 3 Capture/Reload High
Timer/Counter 3 Capture/Reload Low
Timer/Counter 4 Capture/Reload High
Timer/Counter 4 Capture/Reload Low
Programmable Voltage Reference Control
Reset Source Register
UART 0 Slave Address
UART 0 Slave Address Enable
UART 0 Data Buffer
UART 1 Data Buffer
UART 0 Control
UART 1 Control
SFR Page Register
SFR Page Control Register
SFR Next Page Stack Access Register
SFR Last Page Stack Access Register
SMBus Slave Address
SMBus Control
SMBus Clock Rate
SMBus Data
SMBus Status
Stack Pointer
Rev. 1.4
Page No.
page 318
page 318
page 318
page 318
page 318
page 318
page 318
page 318
page 316
page 316
page 316
page 316
page 316
page 316
page 317
page 317
page 315
page 165
page 187
page 152
page 303
page 303
page 303
page 303
page 303
page 303
page 1144, page 1185
page 172
page 278
page 278
page 278
page 285
page 276
page 284
page 142
page 142
page 143
page 146
page 252
page 249
page 250
page 251
page 253
page 151
149
C8051F040/1/2/3/4/5/6/7
Table 12.3. Special Function Registers (Continued)
SFRs are listed in alphabetical order. All undefined SFR locations are reserved.
Register
Address
SPI0CFG
0x9A
SPI0CKR
0x9D
SPI0CN
0xF8
SPI0DAT
0x9B
SSTA0
0x91
TCON
0x88
TH0
0x8C
TH1
0x8D
TL0
0x8A
TL1
0x8B
TMOD
0x89
TMR2CF
0xC9
TMR2CN
0xC8
TMR2H
0xCD
TMR2L
0xCC
TMR3CF
0xC9
TMR3CN
0xC8
TMR3H
0xCD
TMR3L
0xCC
TMR4CF
0xC9
TMR4CN
0xC8
TMR4H
0xCD
TMR4L
0xCC
WDTCN
0xFF
XBR0
0xE1
XBR1
0xE2
XBR2
0xE3
XBR3
0xE4
0x97, 0xA2, 0xB3, 0xB4,
0xCE, 0xDF
SFR Page
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
2
2
2
2
All Pages
F
F
F
F
Description
SPI Configuration
SPI Clock Rate Control
SPI Control
SPI Data
UART0 Status and Clock Selection
Timer/Counter Control
Timer/Counter 0 High
Timer/Counter 1 High
Timer/Counter 0 Low
Timer/Counter 1 Low
Timer/Counter Mode
Timer/Counter 2 Configuration
Timer/Counter 2 Control
Timer/Counter 2 High
Timer/Counter 2 Low
Timer/Counter 3 Configuration
Timer 3 Control
Timer/Counter 3 High
Timer/Counter 3 Low
Timer/Counter 4 Configuration
Timer/Counter 4 Control
Timer/Counter 4 High
Timer/Counter 4 Low
Watchdog Timer Control
Port I/O Crossbar Control 0
Port I/O Crossbar Control 1
Port I/O Crossbar Control 2
Port I/O Crossbar Control 3
Reserved
Notes:
1. Refers to a register in the C8051F040 only.
2. Refers to a register in the C8051F041 only.
3. Refers to a register in C8051F040/1/2/3 only.
4. Refers to a register in the C8051F040/2/4/6 only.
5. Refers to a register in the C8051F041/3/5/7 only.
150
Rev. 1.4
Page No.
page 263
page 265
page 264
page 266
page 277
page 293
page 296
page 296
page 295
page 296
page 294
page 302
page 301
page 304
page 303
page 302
page 301
page 304
page 303
page 302
page 301
page 304
page 303
page 171
page 214
page 215
page 216
page 217
C8051F040/1/2/3/4/5/6/7
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 1. 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 data sheet associated with their corresponding system function.
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
SFR Page: All Pages
Bits7-0:
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
SFR Page: All Pages
Bits7-0:
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
SFR Page: All Pages
Bits7-0:
Rev. 1.4
151
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.8. PSW: Program Status Word
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
CY
AC
F0
RS1
RS0
OV
F1
PARITY
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bits4-3:
Bit2:
Bit1:
Bit0:
152
RS0
0
1
0
1
Register Bank
0
1
2
3
Address
0x000x07
0x080x0F
0x100x17
0x180x1F
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.9. 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
Bit
Addressable
Bits7-0:
ACC: Accumulator.
This register is the accumulator for arithmetic operations.
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
Bit
Addressable
Bits7-0:
B: B Register.
This register serves as a second accumulator for certain arithmetic operations.
Rev. 1.4
153
C8051F040/1/2/3/4/5/6/7
12.3. Interrupt Handler
The CIP-51 includes an extended interrupt system supporting a total of 20 interrupt sources with two priority levels. The allocation of interrupt sources between on-chip peripherals and external inputs pins varies
according to the specific version of the device. Each interrupt source has one or more associated interruptpending 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 program 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.
Note: Any instruction that clears the EA bit should be immediately followed by an instruction that has two
or more opcode bytes. For example:
// in 'C':
EA = 0;
// clear EA bit
EA = 0;
// ... followed by another 2-byte opcode
; in assembly:
CLR EA
; clear EA bit
CLR EA
; ... followed by another 2-byte opcode
If an interrupt is posted during the execution phase of a "CLR EA" opcode (or any instruction which clears
the EA bit), and the instruction is followed by a single-cycle instruction, the interrupt may be taken. However, a read of the EA bit will return a '0' inside the interrupt service routine. When the "CLR EA" opcode is
followed by a multi-cycle instruction, the interrupt will not be taken.
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.
154
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
12.3.2. External Interrupts
The external interrupt sources (/INT0 and /INT1) are configurable as active-low level-sensitive or activelow 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 interruptpending 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.
Bit addressable?
Cleared by HW?
Reset
0x0000
Top
None
N/A
N/A
Always
Enabled
External Interrupt 0
(/INT0)
0x0003
IE0 (TCON.1)
Timer 0 Overflow
0x000B
TF0 (TCON.5)
External Interrupt 1
(/INT1)
0x0013
IE1 (TCON.3)
Timer 1 Overflow
0x001B
TF1 (TCON.7)
Interrupt Source
Interrupt
Vector
Priority
Order
Pending Flag
Enable
Flag
Priority
Control
Always
Highest
UART0
0x0023
RI0 (SCON0.0)
TI0 (SCON0.1)
Timer 2
0x002B
TF2 (T2CON.7)
ESPI0
(EIE1.0)
PSPI0
(EIP1.0)
Serial Peripheral
Interface
0x0033
SPIF (SPI0CN.7)
WCOL (SPI0CN.6)
MODF (SPI0CN.5) Y
RXOVRN
(SPI0CN.4)
SMBus Interface
0x003B
SI (SMB0CN.3)
ESMB0
(EIE1.1)
PSMB0
(EIP1.1)
ADC0 Window
Comparator
0x0043
ADWINT
(ADC0CN.2)
EWADC0
(EIE1.2)
PWADC0
(EIP1.2)
Programmable Counter
Array
0x004B
CF (PCA0CN.7)
Y
CCFn (PCA0CN.n)
EPCA0
(EIE1.3)
PPCA0
(EIP1.3)
Comparator 0
0x0053
10
CP0FIF/CP0RIF
(CPT0CN.4/.5)
CP0IE
(EIE1.4)
PCP0
(EIP1.4)
Comparator 1
0x005B
11
CP1FIF/CP1RIF
(CPT1CN.4/.5)
CP1IE
(EIE1.5)
PCP1
(EIP1.5)
Comparator 2
0x0063
12
CP2FIF/CP2RIF
(CPT2CN.4/.5)
CP2IE
(EIE1.6)
PCP2
(EIP1.6)
Rev. 1.4
155
C8051F040/1/2/3/4/5/6/7
Interrupt
Vector
Priority
Order
Pending Flag
Cleared by HW?
Interrupt Source
Bit addressable?
Enable
Flag
Priority
Control
ET3
(EIE2.0)
PT3
(EIP2.0)
EADC0
(EIE2.1)
PADC0
(EIP2.1)
TF4 (T4CON.7)
ET4
(EIE2.2)
PT4
(EIP2.2)
17
AD2WINT
(ADC2CN.0)
EWADC2
(EIE2.3)
PWADC2
(EIP2.3)
18
ADC2INT
(ADC1CN.5)
EADC1
(EIE2.4)
PADC1
(EIP2.4)
CAN Interrupt
0x009B
19
CAN0CN.7
ECAN0
(EIE2.5)
PCAN0
(EIP2.5)
UART1
0x00A3
20
RI1 (SCON1.0)
TI1 (SCON1.1)
ES1
(EIE2.6)
PS1
(EIP2.6)
Timer 3
0x0073
14
TF3 (TMR3CN.7)
15
ADC0INT
(ADC0CN.5)
Timer 4
0x0083
16
ADC2 Window
Comparator
0x0093
156
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
12.3.3. Interrupt Priorities
Each interrupt source can be individually programmed to one of two priority levels: low or high. A low priority interrupt 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.
Rev. 1.4
157
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.11. 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
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
158
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.12. 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
11000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit
Addressable
Bits7-6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
159
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.13. EIE1: Extended Interrupt Enable 1
R/W
Bit7
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
CP2IE
CP1IE
CP0IE
EPCA0
EWADC0
ESMB0
ESPI0
00000000
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xE6
SFR Page: All Pages
Bit7:
Bit6:
Bit6:
Bit6:
Bit3:
Bit2:
Bit1:
Bit0:
160
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.14. EIE2: Extended Interrupt Enable 2
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
ES1
ECAN0
EADC2
EWADC2
ET4
EADC0
ET3
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xE7
SFR Page: All Pages
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Reserved
ES1: Enable UART1 Interrupt.
This bit sets the masking of the UART1 interrupt.
0: Disable UART1 interrupt.
1: Enable UART1 interrupt.
ECAN0: Enable CAN Controller Interrupt.
This bit sets the masking of the CAN Controller Interrupt.
0: Disable CAN Controller Interrupt.
1: Enable interrupt requests generated by the CAN Controller.
EADC2: Enable ADC2 End Of Conversion Interrupt (C8051F040/1/2/3 only).
This bit sets the masking of the ADC2 End of Conversion interrupt.
0: Disable ADC2 End of Conversion interrupt.
1: Enable interrupt requests generated by the ADC2 End of Conversion Interrupt.
EWADC2: Enable Window Comparison ADC2 Interrupt (C8051F040/1/2/3 only).
This bit sets the masking of ADC2 Window Comparison interrupt.
0: Disable ADC2 Window Comparison Interrupt.
1: Enable Interrupt requests generated by ADC2 Window Comparisons.
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.
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.
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.
Rev. 1.4
161
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.15. EIP1: Extended Interrupt Priority 1
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
PCP2
PCP1
PCP0
PPCA0
PWADC0
PSMB0
PSPI0
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xF6
SFR Page: All Pages
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
162
Reserved.
PCP2: Comparator2 (CP2) Interrupt Priority Control.
This bit sets the priority of the CP2 interrupt.
0: CP2 interrupt set to low priority level.
1: CP2 interrupt set to high priority level.
PCP1: Comparator1 (CP1) Interrupt Priority Control.
This bit sets the priority of the CP1 interrupt.
0: CP1 interrupt set to low priority level.
1: CP1 interrupt set to high priority level.
PCP0: Comparator0 (CP0) Interrupt Priority Control.
This bit sets the priority of the CP0 interrupt.
0: CP0 interrupt set to low priority level.
1: CP0 interrupt set to high priority level.
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.
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.
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.
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
C8051F040/1/2/3/4/5/6/7
SFR Definition 12.16. EIP2: Extended Interrupt Priority 2
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
EP1
PX7
PADC2
PWADC2
PT4
PADC0
PT3
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xF7
SFR Page: All Pages
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Reserved.
EP1: UART1 Interrupt Priority Control.
This bit sets the priority of the UART1 interrupt.
0: UART1 interrupt set to low level.
1: UART1 interrupt set to high level.
PCAN0: CAN Interrupt Priority Control.
This bit sets the priority of the CAN Interrupt.
0: CAN Interrupt set to low priority level.
1: CAN Interrupt set to high priority level.
PADC2: ADC2 End Of Conversion Interrupt Priority Control (C8051F040/1/2/3 only).
This bit sets the priority of the ADC2 End of Conversion interrupt.
0: ADC2 End of Conversion interrupt set to low level.
1: ADC2 End of Conversion interrupt set to low level.
PWADC2: ADC2 Window Comparator Interrupt Priority Control (C8051F040/1/2/3 only).
0: ADC2 Window interrupt set to low level.
1: ADC2 Window interrupt set to high level.
PT4: Timer 4 Interrupt Priority Control.
This bit sets the priority of the Timer 4 interrupt.
0: Timer 4 interrupt set to low level.
1: Timer 4 interrupt set to low level.
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.
PT3: Timer 3 Interrupt Priority Control.
This bit sets the priority of the Timer 3 interrupts.
0: Timer 3 interrupt set to low priority level.
1: Timer 3 interrupt set to high priority level.
Rev. 1.4
163
C8051F040/1/2/3/4/5/6/7
12.17. 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 internal oscillator
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. SFR Definition 12.18 describes the Power Control Register (PCON) used to control the CIP51'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 peripheral 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
oscillator saves even more power, but requires a reset to restart the MCU.
12.17.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 feature 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.7 for more information on the use and
configuration of the WDT.
Note: Any instruction that sets the IDLE bit should be immediately followed by an instruction that has 2 or
more opcode bytes. For example:
// in 'C':
PCON |= 0x01;
PCON = PCON;
; in assembly:
ORL PCON, #01h
MOV PCON, PCON
If the instruction following the write of the IDLE bit is a single-byte instruction and an interrupt occurs during
the execution phase of the instruction that sets the IDLE bit, the CPU may not wake from IDLE mode when
a future interrupt occurs.
164
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
12.17.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 oscillators 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.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
STOP
IDLE
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x87
SFR Page: All Pages
Bits7-3:
Bit1:
Bit0:
Reserved.
STOP: STOP Mode Select.
Writing a 1 to this bit will place the CIP-51 into STOP mode. This bit will always read 0.
0: No effect.
1: CIP-51 forced into power-down mode. (Turns off internal oscillator).
IDLE: IDLE Mode Select.
Writing a 1 to this bit will place the CIP-51 into IDLE mode. This bit will always read 0.
0: No effect.
1: CIP-51 forced into idle mode. (Shuts off clock to CPU, but clock to Timers, Interrupts, and
all peripherals remain active.)
Rev. 1.4
165
C8051F040/1/2/3/4/5/6/7
NOTES:
166
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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:
All SFRs are reset to the predefined values noted in the SFR detailed descriptions. The contents of internal
data memory 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 1s), activating internal weak pullups which take the external I/O pins to a high state. 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 its lowest frequency. Refer to Section 14. Oscillators on page 175 for information on selecting and configuring the system clock source. The Watchdog Timer is enabled using its
longest timeout interval (see Section 13.7. Watchdog Timer Reset on page 169). 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 CNVSTR0 signal, software command, Comparator0, Missing Clock Detector, and Watchdog
Timer. Each reset source is described in the following sections.
VDD
Crossbar
CNVSTR
Supply
Monitor
(CNVSTR
reset
enable)
+
-
Comparator0
CP0+
+
-
CP0-
XTAL2
OSC
Clock Select
Reset
Funnel
WDT
EN
PRE
WDT
Enable
MCD
Enable
System
Clock
RST
(wired-OR)
(CP0
reset
enable)
EN
XTAL1
(wired-OR)
VDD Monitor
reset enable
Missing
Clock
Detector
(oneshot)
Internal
Clock
Generator
Supply
Reset
Timeout
WDT
Strobe
(Port I/O)
CIP-51
Microcontroller
Core
Software Reset
System Reset
Extended Interrupt
Handler
Rev. 1.4
167
C8051F040/1/2/3/4/5/6/7
13.1. Power-on Reset
The C8051F04x family incorporates a power supply monitor that holds the MCU in the reset state until VDD
rises above the VRST level during power-up. See Figure 13.2 for timing diagram, and refer to Table 13.1 for
the Electrical 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. The VDD Monitor reset is
enabled and disabled using the external VDD monitor enable pin (MONEN).
volts
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 execution 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.
2.70
V RST
2.55
VD
D
2.0
1.0
t
Logic HIGH
/RST
Reset Time
Delay
Reset Time
Delay
Logic LOW
Power-On Reset
168
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
lup and/or decoupling 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.
Rev. 1.4
169
C8051F040/1/2/3/4/5/6/7
13.7.1. Enable/Reset WDT
The watchdog timer is both enabled and reset by writing 0xA5 to the WDTCN register. The user's application software 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.
EA
WDTCN,#0DEh
WDTCN,#0ADh
EA
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.
3 + WDTCN [ 2 0 ]
For a 3 MHz system clock, this provides an interval range of 0.021 ms to 349.5 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.
170
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 13.1. WDTCN: Watchdog Timer Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
xxxxx111
SFR Address: 0xFF
SFR Page: All Pages
Bits7-0:
Bit4:
Bits2-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.
Watchdog Status Bit (when Read)
Reading the WDTCN.[4] bit indicates the Watchdog Timer Status.
0: WDT is inactive
1: WDT is active
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
171
C8051F040/1/2/3/4/5/6/7
SFR Definition 13.2. RSTSRC: Reset Source
R
Bit7
R/W
R/W
R/W
R/W
Bit5
Bit4
Bit3
Bit2
R/W
Reset Value
PORSF
PINRSF
00000000
Bit1
Bit0
SFR Address: 0xEF
SFR Page: 0
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
172
Reserved.
CNVRSEF: Convert Start Reset Source Enable and Flag
Write: 0: CNVSTR0 is not a reset source.
1: CNVSTR0 is a reset source (active low).
Read: 0: Source of prior reset was not CNVSTR0.
1: Source of prior reset was CNVSTR0.
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 last reset was not Comparator0.
1: Source of last reset was Comparator0.
SWRSF: Software Reset Force and Flag.
Write: 0: No effect.
1: Forces an internal reset. /RST pin is not effected.
Read: 0: Source of last reset was not a write to the SWRSF bit.
1: Source of last reset was a write to the SWRSF bit.
WDTRSF: Watchdog Timer Reset Flag.
0: Source of last reset was not WDT timeout.
1: Source of last reset was WDT timeout.
MCDRSF: Missing Clock Detector Flag.
Write: 0: Missing Clock Detector disabled.
1: Missing Clock Detector enabled; triggers a reset if a missing clock condition is
detected.
Read: 0: Source of last reset was not a Missing Clock Detector timeout.
1: Source of last reset was a Missing Clock Detector timeout.
PORSF: Power-On Reset Flag.
Write: If the VDD monitor circuitry is enabled (by tying the MONEN pin to a logic high state), this
bit can be written to select or de-select the VDD monitor as a reset source.
0: De-select the VDD monitor as a reset source.
1: Select the VDD monitor as a reset source.
Important: At power-on, the VDD monitor is enabled/disabled using the external VDD monitor enable pin (MONEN). The PORSF bit does not disable or enable the VDD monitor circuit. It simply selects the VDD monitor as a reset source.
Read: This bit is set whenever a power-on reset occurs. This may be due to a true power-on
reset or a VDD monitor reset. In either case, data memory should be considered indeterminate
following the reset.
0: Source of last reset was not a power-on or VDD monitor reset.
1: Source of last reset was a power-on or VDD monitor reset.
Note: When this flag is read as '1', all other reset flags are indeterminate.
PINRSF: HW Pin Reset Flag.
Write: 0: No effect.
1: Forces a Power-On Reset. /RST is driven low.
Read: 0: Source of prior reset was not /RST pin.
1: Source of prior reset was /RST pin.
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 13.1. Reset Electrical Characteristics
40 to +85 C unless otherwise specified.
Parameter
Min
0.7 x
VDD
Typ
Max
0.6
Units
V
0.3 x
VDD
50
1.0
1.0
2.40
2.55
2.70
10
ns
Conditions
IOL = 8.5 mA, VDD = 2.7 V to 3.6 V
RST = 0.0 V
80
100
120
ms
100
220
500
Rev. 1.4
173
C8051F040/1/2/3/4/5/6/7
NOTES:
174
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
14. Oscillators
XTAL1
CLKSL
Option 3
CLKSEL
IFCN1
IFCN0
OSCICN
IOSCEN
IFRDY
OSCICL
XTAL2
Option 4
EN
XTAL1
Option 2
VDD
Programmable
Internal Clock
Generator
0
SYSCLK
Option 1
XTAL1
Input
Circuit
XTAL1
OSC
XFCN2
XFCN1
XFCN0
XTLVLD
XOSCMD2
XOSCMD1
XOSCMD0
XTAL2
OSCXCN
Rev. 1.4
175
C8051F040/1/2/3/4/5/6/7
SFR Definition 14.1. OSCICL: Internal Oscillator Calibration
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
Variable
SFR Address: 0x8B
SFR Page: F
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
IOSCEN
IFRDY
IFCN1
IFCN0
11000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x8A
SFR Page: F
Bit7:
Bit6:
Bits5-2:
Bits1-0:
176
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 14.1. Internal Oscillator Electrical Characteristics
40 to +85 C unless otherwise specified.
Parameter
Conditions
Min
Typ
Max
Units
24
24.5
25
MHz
450
30
MHz
15
ns
15
ns
R/W
Reset Value
00000000
CLKSL
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x97
SFR Page: F
Bits7-1:
Bit0:
Reserved.
CLKSL: System Clock Source Select Bit.
0: SYSCLK derived from the Internal Oscillator, and scaled as per the IFCN bits in OSCICN.
1: SYSCLK derived from the External Oscillator circuit.
Rev. 1.4
177
C8051F040/1/2/3/4/5/6/7
SFR Definition 14.4. OSCXCN: External Oscillator Control
R
R/W
R/W
R/W
Bit6
Bit5
Bit4
R/W
R/W
R/W
Reset Value
XFCN2
XFCN1
XFCN0
00000000
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x8C
SFR Page: F
Bit7:
Bits6-4:
Bit3:
Bits2-0:
RC (XOSCMD = 10x)
f 25 kHz
25 kHz < f 50 kHz
50 kHz < f 100 kHz
100 kHz < f 200 kHz
200 kHz < f 400 kHz
400 kHz < f 800 kHz
800 kHz < f 1.6 MHz
1.6 MHz < f 3.2 MHz
178
Rev. 1.4
C (XOSCMD = 10x)
K Factor = 0.87
K Factor = 2.6
K Factor = 7.7
K Factor = 22
K Factor = 65
K Factor = 180
K Factor = 664
K Factor = 1590
C8051F040/1/2/3/4/5/6/7
14.4. External Crystal Example
If a crystal or ceramic resonator is used as an external oscillator source for the MCU, the circuit should be
configured as shown in Figure 14.1, Option 1. The External Oscillator Frequency Control value (XFCN)
should be chosen from the Crystal column of the table in SFR Definition 14.4 (OSCXCN register). For
example, an 11.0592 MHz crystal requires an XFCN setting of 111b.
When the crystal oscillator is enabled, the oscillator amplitude detection circuit requires a settle time to
achieve proper bias. Introducing a delay of at least 1 ms between enabling the oscillator and checking the
XTLVLD bit will prevent a premature switch to the external oscillator as the system clock. Switching to the
external oscillator before the crystal oscillator has stabilized can result in unpredictable behavior. The recommended procedure is:
Step 1.
Step 2.
Step 3.
Step 4.
Step 5.
Step 6.
Force the XTAL1 and XTAL2 pins low by writing 0s to the port latch.
Configure XTAL1 and XTAL2 as analog inputs.
Enable the external oscillator.
Wait at least 1 ms.
Poll for XTLVLD => '1'.
Switch the system clock to the external oscillator.
Note: Tuning-fork crystals may require additional settling time before XTLVLD returns a valid result.
The capacitors shown in the external crystal configuration provide the load capacitance required by the
crystal for correct oscillation. These capacitors are "in series" as seen by the crystal and "in parallel" with
the stray capacitance of the XTAL1 and XTAL2 pins.
Note: The load capacitance depends upon the crystal and the manufacturer. Please refer to the crystal
data sheet when completing these calculations.
For example, a tuning-fork crystal of 32.768 kHz with a recommended load capacitance of 12.5 pF should
use the configuration shown in Figure 14.1, Option 1. The total value of the capacitors and the stray
capacitance of the XTAL pins should equal 25 pF. With a stray capacitance of 3 pF per pin, the 22 pF
capacitors yield an equivalent capacitance of 12.5 pF across the crystal, as shown in Figure 14.2.
22 pF
XTAL1
10 M
32.768 kHz
XTAL2
22 pF
Rev. 1.4
179
C8051F040/1/2/3/4/5/6/7
short as possible and shielded with ground plane from any other traces which could introduce noise or
interference.
180
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
15. Flash Memory
The C8051F04x family includes 64 kB + 128 (C8051F040/1/2/3/4/5) or 32 kB + 128 (C8051F046/7) of onchip, 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 using the
MOVX write instructions. 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 operations are automatically timed by hardware for proper execution; data polling to determine the end of the
write/erase operation is not required. The CPU is stalled during write/erase operations while the device
peripherals remain active. Interrupts that occur during Flash write/erase operations are held, and are then
serviced in their priority order once the Flash operation has completed. Refer to Table 15.1 for the electrical characteristics of the Flash memory.
Step 8.
Step 9.
Disable interrupts.
Set FLWE (FLSCL.0) to enable Flash writes/erases via user software.
Set PSEE (PSCTL.1) to enable Flash erases.
Set PSWE (PSCTL.0) to redirect MOVX commands to write to Flash.
Use the MOVX command to write a data byte to any location within the 512-byte page to
be erased.
Clear PSEE to disable Flash erases
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).
Clear the PSWE bit to redirect MOVX commands to the XRAM data space.
Re-enable interrupts.
Rev. 1.4
181
C8051F040/1/2/3/4/5/6/7
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. Note that 512 bytes at locations 0xFE00 (C8051F040/1/2/
3/4/5) and all locations above 0x8000 (C8051F046/7) are reserved. Flash writes and erases targeting the
reserved area should be avoided.
Parameter
1
Flash Size
Conditions
Min
Typ
Max
2
C8051F040/1/2/3/4/5
C8051F046/7
65664
32896
Units
Bytes
20 k
100 k
Erase/Write
10
12
14
ms
40
50
60
Endurance
Notes:
1. Includes 128-byte scratchpad.
2. 512 bytes at locations 0xFE00 to 0xFFFF are reserved.
182
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Bit
7
6
5
4
3
2
1
0
Memory Block
C8051F040/1/2/3/4/5
0xE000 - 0xFDFD
0xC000 - 0xDFFF
0xA000 - 0xBFFF
0x8000 - 0x9FFF
0x6000 - 0x7FFF
0x4000 - 0x5FFF
0x2000 - 0x3FFF
0x0000 - 0x1FFF
C8051F046/7
No effect
No effect
No effect
No effect
0x6000 - 0x7FFD
0x4000 - 0x5FFF
0x2000 - 0x3FFF
0x0000 - 0x1FFF
SFLE = 0
C8051F040/1/2/3/4/5
SFLE = 1
Scratchpad Memory
(Data only)
Reserved
0x007F
0x0000
0xFE00
0xFDFF
0xFDFE
0xFDFD
Program/Data
Memory Space
Software Read Limit
0x0000
C8051F046/7
Reserved
0x8000
0x7FFF
0x7FFE
0x7FFD
Program/Data
Memory Space
Software Read Limit
0x0000
Rev. 1.4
183
C8051F040/1/2/3/4/5/6/7
The lock bits can always be read and cleared to logic 0 regardless of the security setting applied to the
block containing 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 memory 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 program memory space (except for the reserved
area). This erasure can only be performed via JTAG. If a non-security byte in the 0xFBFF-0xFDFF
(C8051F040/1/2/3/4/5) or 0x7DFF-0x7FFF (C8051F046/7) 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 C8051F04x. This feature provides support for OEMs that wish to
program the 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 excluding) 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 valueadded firmware via the reset vector. Once the value-added firmware completes its initial execution, it
branches to a predetermined location in the upper partition. If entry points are published, software running
in the upper partition may execute 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 boundaries 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.
184
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Accessing Flash through the JTAG debug interface:
1. The Read and Write/Erase Lock bytes (security bytes) provide security for Flash access
through the JTAG interface.
2. Any unlocked page may be read from, written to, or erased.
3. Locked pages cannot be read from, written to, or erased.
4. Reading the security bytes is always permitted.
5. Locking additional pages by writing to the security bytes is always permitted.
6. If the page containing the security bytes is unlocked, it can be directly erased. Doing so will
reset the security bytes and unlock all pages of Flash.
7. If the page containing the security bytes is locked, it cannot be directly erased. To unlock the
page containing the security bytes, a full JTAG device erase is required. A full JTAG
device erase will erase all Flash pages, including the page containing the security bytes and
the security bytes themselves.
8. The Reserved Area cannot be read from, written to, or erased at any time.
Accessing Flash from firmware residing below the Flash Access Limit:
1. The Read and Write/Erase Lock bytes (security bytes) do not restrict Flash access from user
firmware.
2. Any page of Flash except the page containing the security bytes may be read from, written to,
or erased.
3. The page containing the security bytes cannot be erased. Unlocking pages of Flash can
only be performed via the JTAG interface.
4. The page containing the security bytes may be read from or written to. Pages of Flash can be
locked from JTAG access by writing to the security bytes.
5. The Reserved Area cannot be read from, written to, or erased at any time.
Accessing Flash from firmware residing at or above the Flash Access Limit:
1. The Read and Write/Erase Lock bytes (security bytes) do not restrict Flash access from user
firmware.
2. Any page of Flash at or above the Flash Access Limit except the page containing the security
bytes may be read from, written to, or erased.
3. Any page of Flash below the Flash Access Limit cannot be read from, written to, or erased.
4. Code branches to locations below the Flash Access Limit are permitted.
5. The page containing the security bytes cannot be erased. Unlocking pages of Flash can
only be performed via the JTAG interface.
6. The page containing the security bytes may be read from or written to. Pages of Flash can be
locked from JTAG access by writing to the security bytes.
7. The Reserved Area cannot be read from, written to, or erased at any time.
Rev. 1.4
185
C8051F040/1/2/3/4/5/6/7
SFR Definition 15.1. 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:
R/W
FOSE
FRAE
Bit7
Bit6
R/W
R/W
R/W
R/W
R/W
Bit4
Bit3
Bit2
Bit1
R/W
Reset Value
FLWE
10000000
Bit0
SFR Address:
Bit7:
Bit6:
Bits5-1:
Bit0:
186
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 15.3. 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:
Bits7-3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
187
C8051F040/1/2/3/4/5/6/7
NOTES:
188
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16. External Data Memory Interface and On-Chip XRAM
The C8051F04x 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 SFR Definition 16.1). Note: the MOVX instruction can also be used for writing to
the Flash memory. See Section 15. Flash Memory on page 181 for details. The MOVX instruction
accesses XRAM by default. The EMIF can be configured to appear on the lower GPIO Ports (P0-P3) or the
upper GPIO Ports (P4-P7).
DPTR, #1234h
A, @DPTR
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.
EMI0CN, #12h
R0, #34h
a, @R0
Rev. 1.4
189
C8051F040/1/2/3/4/5/6/7
16.2. Configuring the External Memory Interface
Configuring the External Memory Interface consists of five steps:
1.
2.
3.
4.
Select EMIF on Low Ports (P3, P2, P1, and P0) or High Ports (P7, P6, P5, and P4).
Configure the Output Modes of the port pins as either push-pull or open-drain.
Select Multiplexed mode or Non-multiplexed mode.
Select the memory mode (on-chip only, split mode without bank select, split mode with bank
select, or off-chip only).
5. Set up timing to interface with off-chip memory or peripherals.
Each of these five steps is explained in detail in the following sections. The Port selection, Multiplexed
mode selection, and Mode bits are located in the EMI0CF register shown in SFR Definition 16.2.
190
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 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: 0xA2
SFR Page: 0
Bits7-0:
Rev. 1.4
191
C8051F040/1/2/3/4/5/6/7
SFR Definition 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
SFR Page: 0
Bits7-6:
Bit5:
Bit4:
Bits3-2:
Bits1-0:
192
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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.
A[15:8]
A[15:8]
ADDRESS BUS
74HC373
E
M
I
F
ALE
AD[7:0]
ADDRESS/DATA BUS
A[7:0]
VDD
64K X 8
SRAM
(Optional)
8
I/O[7:0]
CE
WE
OE
/WR
/RD
Rev. 1.4
193
C8051F040/1/2/3/4/5/6/7
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 Nonmultiplexed Configuration is shown in Figure 16.2. See Section 16.6.1. Non-multiplexed Mode on
page 198 for more information about Non-multiplexed operation.
E
M
I
F
A[15:0]
ADDRESS BUS
A[15:0]
VDD
(Optional)
8
D[7:0]
DATA BUS
64K X 8
SRAM
I/O[7:0]
CE
WE
OE
/WR
/RD
194
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16.5. Memory Mode Selection
The external data memory space can be configured in one of four modes, shown in Figure 16.3, based on
the EMIF Mode bits in the EMI0CF register (SFR Definition 16.2). These modes are summarized below.
More information about the different modes can be found in Section 16.6. Timing on page 196.
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.
Effective addresses below the 4k boundary will access on-chip XRAM space.
Effective addresses above the 4k boundary will access off-chip space.
8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is onchip or off-chip. 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 via the port latches. This behavior is in
contrast with Split Mode with Bank Select described below. The lower 8-bits of the Address Bus
A[7:0] are driven, determined by R0 or R1.
16-bit MOVX operations use the contents of DPTR to determine whether the memory access is onchip 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.
EMI0CF[3:2] = 00
EMI0CF[3:2] = 01
0xFFFF
EMI0CF[3:2] = 10
EMI0CF[3:2] = 11
0xFFFF
0xFFFF
0xFFFF
On-Chip XRAM
On-Chip XRAM
Off-Chip
Memory
(No Bank Select)
Off-Chip
Memory
(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
Rev. 1.4
195
C8051F040/1/2/3/4/5/6/7
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 offchip space.
Effective addresses below the 4k boundary will access on-chip XRAM space.
Effective addresses above the 4k boundary will access off-chip space.
8-bit MOVX operations use the contents of EMI0CN to determine whether the memory access is onchip 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 onchip or off-chip, and the full 16-bits of the Address Bus A[15:0] are driven during the off-chip transaction.
8-bit MOVX operations ignore the contents of EMI0CN. The upper Address bits A[15:8] are not driven
(identical 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 SFR Definition 16.3, 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 operations, the Address Latch Enable signal will require a minimum of 2 additional
SYSCLK cycles. Therefore, the minimum 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 settings after a reset.
Table 16.1 lists the AC parameters for the External Memory Interface, and Figure 16.4 through Figure 16.9
show the timing diagrams for the different External Memory Interface modes and MOVX operations.
196
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 16.3. 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
ERW3
EWR2
EWR1
EWR0
EAH1
EAH0
11111111
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xA1
SFR Page: 0
Bits7-6:
Bits5-2:
Bits1-0:
Rev. 1.4
197
C8051F040/1/2/3/4/5/6/7
16.6.1. Non-multiplexed Mode
16.6.1.1.16-bit MOVX: EMI0CF[4:2] = 101, 110, or 111.
P1/P5
P1/P5
ADDR[7:0]
P2/P6
P2/P6
DATA[7:0]
P3/P7
P3/P7
WDS
WDH
ACS
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
P1/P5
P1/P5
ADDR[7:0]
P2/P6
P2/P6
DATA[7:0]
P3/P7
P3/P7
RDS
ACS
ACW
RDH
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
198
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16.6.1.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = 101 or 111.
P1/P5
ADDR[7:0]
P2/P6
P2/P6
DATA[7:0]
P3/P7
P3/P7
WDS
WDH
ACS
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
P1/P5
ADDR[7:0]
P2/P6
DATA[7:0]
P3/P7
RDS
ACS
ACW
P2/P6
P3/P7
RDH
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
Rev. 1.4
199
C8051F040/1/2/3/4/5/6/7
16.6.1.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = 110.
P1/P5
P1/P5
ADDR[7:0]
P2/P6
P2/P6
DATA[7:0]
P3/P7
P3/P7
WDS
WDH
ACS
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
P1/P5
P1/P5
ADDR[7:0]
P2/P6
P2/P6
DATA[7:0]
P3/P7
RDS
ACS
ACW
P3/P7
RDH
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
200
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16.6.2. Multiplexed Mode
16.6.2.1.16-bit MOVX: EMI0CF[4:2] = 001, 010, or 011.
P2/P6
AD[7:0]
P3/P7
ALEH
ALE
P2/P6
P3/P7
ALEL
P0.5/P4.5
P0.5/P4.5
T
WDS
ACS
WDH
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
P2/P6
AD[7:0]
P3/P7
ALEH
ALE
P2/P6
ALEL
RDS
P3/P7
RDH
P0.5/P4.5
P0.5/P4.5
ACS
ACW
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
Rev. 1.4
201
C8051F040/1/2/3/4/5/6/7
16.6.2.2.8-bit MOVX without Bank Select: EMI0CF[4:2] = 001 or 011.
AD[7:0]
P2/P6
P3/P7
ALEH
ALE
P3/P7
ALEL
P0.5/P4.5
P0.5/P4.5
T
WDS
ACS
WDH
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
AD[7:0]
P2/P6
P3/P7
ALEH
ALE
ALEL
RDS
RDH
P0.5/P4.5
P0.5/P4.5
ACS
ACW
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
202
P3/P7
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
16.6.2.3.8-bit MOVX with Bank Select: EMI0CF[4:2] = 010.
Muxed 8-bit WRITE with Bank Select
ADDR[15:8]
P2/P6
AD[7:0]
P3/P7
ALEH
ALE
P2/P6
P3/P7
ALEL
P0.5/P4.5
P0.5/P4.5
T
WDS
ACS
WDH
ACW
ACH
/WR
P0.7/P4.7
P0.7/P4.7
/RD
P0.6/P4.6
P0.6/P4.6
P2/P6
AD[7:0]
P3/P7
ALEH
ALE
P2/P6
ALEL
RDS
P3/P7
RDH
P0.5/P4.5
P0.5/P4.5
ACS
ACW
ACH
/RD
P0.6/P4.6
P0.6/P4.6
/WR
P0.7/P4.7
P0.7/P4.7
Rev. 1.4
203
C8051F040/1/2/3/4/5/6/7
Table 16.1. AC Parameters for External Memory Interface
Parameter
Description
Min
Max
Units
TSYSCLK
40
ns
TACS
3 x TSYSCLK
ns
TACW
1 x TSYSCLK
16 x TSYSCLK
ns
TACH
3 x TSYSCLK
ns
TALEH
1 x TSYSCLK
4 x TSYSCLK
ns
TALEL
1 x TSYSCLK
4 x TSYSCLK
ns
TWDS
1 x TSYSCLK
19 x TSYSCLK
ns
TWDH
3 x TSYSCLK
ns
TRDS
20
ns
TRDH
ns
204
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
17. Port Input/Output
The C8051F04x family of devices are fully integrated mixed-signal System on a Chip MCUs with 64 digital
I/O pins (C8051F040/2/4/6) or 32 digital I/O pins (C8051F041/3/5/7), organized as 8-bit Ports. All ports are
both bit- and byte-addressable through their corresponding Port Data registers. All Port pins are 5 V-tolerant, and all support configurable Open-Drain or Push-Pull output modes and weak pullups. A block diagram of the Port I/O cell is shown in Figure 17.1. Complete Electrical Specifications for the Port I/O pins
are given in Table 17.1.
/WEAK-PULLUP
VDD
VDD
PUSH-PULL
/PORT-OUTENABLE
(WEAK)
PORT
PAD
PORT-OUTPUT
ANALOG INPUT
DGND
Analog Select
(Ports 1, 2, and 3)
PORT-INPUT
Parameter
Conditions
Min
Typ
Max
Units
VDD 0.7
VDD 0.1
VDD 0.8
1.0
0.6
0.1
0.7 x VDD
0.3 x VDD
10
pF
IOL = 8.5 mA
IOL = 10 A
IOL = 25 mA
Input Capacitance
Rev. 1.4
205
C8051F040/1/2/3/4/5/6/7
The C8051F04x family of 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. 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 Ports 1, 2, and 3 can be used as Analog Inputs to ADC2 (C8051F040/1/2/3 only), Analog
Voltage Comparators, and ADC0, respectively.
Highest
Priority
UART0
SPI
SMBus
Lowest
Priority
UART1
P0MDOUT, P1MDOUT,
P2MDOUT, P3MDOUT
Registers
External
Pins
Priority
Decoder
8
PCA
Digital
Crossbar
T0, T1,
T2, T2EX,
T3, T3EX,
T4,T4EX,
/INT0,
/INT1
(P1.0-P1.7)
8
P2
P0.7
P1.7
P2
I/O
Cells
P2.0
P3
I/O
Cells
P3.0
P2.7
P3.7
Lowest
Priority
To
ADC2
Input
To External
Memory
Interface
(EMIF)
(P2.0-P2.7)
8
P3
P1.0
(P0.0-P0.7)
8
P1
P1
I/O
Cells
Highest
Priority
/SYSCLK
CNVSTR0
CNVSTR2
Port
Latches
P0.0
Comptr.
Outputs
P0
P0
I/O
Cells
To
Comparators
To
ADC0
Input
(P3.0-P3.7)
206
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
P0
PIN I/O 0
TX0
CEX3
CEX4
CEX5
ECI
CP0
CP1
CP2
T0
/INT0
T1
/INT1
T2
T2EX
T3
T3EX
T4
T4EX
P2
4
P3
4
SPI0EN: XBR0.1
z
z
NSS is not assigned to a port pin when the SPI is placed in 3-wire mode
z z z z z
z
z z z z z
RX1
CEX2
z
z
SCL
CEX1
NSS
CEX0
UART0EN: XBR0.2
MOSI
TX1
P1
4
MISO
SDA
RX0
SCK
SMB0EN: XBR0.0
z z z z z z z
z z z z z z z
z z z z z z z z z
z z z z z z z z z
z
z
UART1EN: XBR2.2
z z z z z z z z z
z z z z z z z z z
z
z z z z z z z z z
PCA0ME: XBR0.[5:3]
z
z z z z z z z z z
z z z z z z z z z z z z z z z z z
ECI0E: XBR0.6
z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z
CP0E: XBR0.7
z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z
CP2E: XBR3.3
z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
INT0E: XBR1.2
CP1E: XBR1.0
T0E: XBR1.1
T1E: XBR1.3
INT1E: XBR1.4
T2E: XBR1.5
z z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z z z
T2EXE: XBR1.6
z z z z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z z z z z
T3EXE: XBR3.1
z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
T4EXE: XBR2.4
T3E: XBR3.0
T4E: XBR2.3
/SYSCLK
SYSCKE: XBR1.7
CNVSTR0
CNVSTE0: XBR2.0
CNVSTE2: XBR3.2
AD7/D7
AD6/D6
AD5/D5
AD4/D4
AD3/D3
AD2/D2
AD1/D1
AD0/D0
A15m/A7
A14m/A6
A13m/A5
A12m/A4
A11m/A3
A10m/A2
A9m/A1
A8m/A0
AIN1.7/A15
AIN1.6/A14
AIN1.5/A13
AIN1.4/A12
AIN1.3/A11
AIN1.2/A10
AIN1.1/A9
AIN1.0/A8
/WR
/RD
ALE
z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
CNVSTR2 z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
Rev. 1.4
207
C8051F040/1/2/3/4/5/6/7
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 SFR Definition 17.5,
SFR Definition 17.7, SFR Definition 17.10, and SFR Definition 17.13), a set of SFRs which are both byteand bit-addressable. The output states of Port pins that are allocated by the Crossbar are controlled by the
digital peripheral that is mapped to those pins. Writes to the Port Data registers (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 registers are typically left alone.
Once the Crossbar registers have been properly configured, the Crossbar is enabled by setting XBARE
(XBR2.4) 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.
208
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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 in the PnMDOUT register 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, which selects open-drain output mode, and P3.7 to a
logic 1, which disables the low-side output driver.
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.
Rev. 1.4
209
C8051F040/1/2/3/4/5/6/7
17.1.6. External Memory Interface Pin Assignments
If the External Memory Interface (EMIF) is enabled on the Low ports (Ports 0 through 3), EMIFLE (XBR2.5)
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 Memory 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 (logic 1 or logic 0) 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 (push-pull or open-drain) 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.
In most cases, GPIO pins used in EMIF operations (especially the /WR and /RD lines) should be
configured as push-pull and parked at a logic 1 state. See Section 16. External Data Memory
Interface and On-Chip XRAM on page 189 for more information about the External Memory Interface.
P0
PIN I/O 0
z
z
z
z
P3
4
SMB0EN: XBR0.0
z
z z
z z z
z z z z
UART1EN: XBR2.2
z z
z
z
z
z z z z
z z z z
z z z z
z z z
z
z z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z z z
z z z z
PCA0ME: XBR0.[5:3]
ECI0E: XBR0.6
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z z z
z z z z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z z z
z z z z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
/SYSCLK
CP0E: XBR0.7
CP1E: XBR1.0
CP2E: XBR3.3
T0E: XBR1.1
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
INT0E: XBR1.2
T1E: XBR1.3
INT1E: XBR1.4
T2E: XBR1.5
z
z
z
z
z
T2EXE: XBR1.6
AD3/D3
AD2/D2
AD1/D1
AD0/D0
A15m/A7
A14m/A6
A13m/A5
A12m/A4
A11m/A3
A10m/A2
A9m/A1
/WR
/RD
ALE
T3E: XBR3.0
z
z z
z z z
z z z
z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
A8m/A0
z z z z z
z z z z z
CNVSTR2 z z z z z
CNVSTR0
AIN1.7/A15
T4
T4EX
z
z
z
z
AIN1.6/A14
T3
T3EX
T3EXE: XBR3.1
T4E: XBR2.3
T4EXE: XBR2.4
SYSCKE: XBR1.7
CNVSTE0: XBR2.0
CNVSTE2: XBR3.2
AD7/D7
z
z
z
z
AIN1.5/A13
T2
T2EX
AD6/D6
z
z z
AIN1.4/A12
T1
/INT1
NSS is not assigned to a port pin when the SPI is placed in 3-wire mode
AIN1.3/A11
/INT0
SPI0EN: XBR0.1
CEX5
T0
P2
4
AD5/D5
z
z
z z
z
z
z
z z
CEX4
CP2
CEX3
CP1
z
z
z z z
CEX2
CP0
z
z
CEX1
ECI
AIN1.2/A10
CEX0
AIN1.1/A9
RX1
UART0EN: XBR0.2
NSS
TX1
AD4/D4
MOSI
SCL
P1
4
MISO
SDA
RX0
SCK
AIN1.0/A8
TX0
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
P0
PIN I/O 0
TX0
CEX1
P2
4
P3
4
SPI0EN: XBR0.1
z
z
NSS is not assigned to a port pin when the SPI is placed in 3-wire mode
z z z z
z
z z z
z
z z z z
z
z
z
z z
z z z
z z z
z z z z
CEX3
z z z
z z
z
z
CEX4
CEX2
z
z
RX1
CEX0
NSS
TX1
UART0EN: XBR0.2
MOSI
SCL
P1
4
MISO
SDA
RX0
SCK
z
z
SMB0EN: XBR0.0
UART1EN: XBR2.2
z z z z
z z z z z
z z z z z z
z z z z z z z
z z z z z z z z
PCA0ME: XBR0.[5:3]
z z z z z z
z z z z z z
z z z z z z
z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
CNVSTR0
z z z z z z
z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
CNVSTE0: XBR2.0
CNVSTR2
z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z
CNVSTE2: XBR3.2
T2E: XBR1.5
T2EXE: XBR1.6
T3EXE: XBR3.1
T4E: XBR2.3
T4EXE: XBR2.4
SYSCKE: XBR1.7
AD7/D7
AD6/D6
T3E: XBR3.0
AD5/D5
AD4/D4
AD3/D3
T1E: XBR1.3
AD2/D2
AD1/D1
T0E: XBR1.1
AD0/D0
A15m/A7
/SYSCLK
A14m/A6
T4EX
CP1E: XBR1.0
A13m/A5
T4
A12m/A4
T3EX
ECI0E: XBR0.6
A11m/A3
T3
A10m/A2
z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z
A9m/A1
z z z z z z
z z z z z z
z z z z z z
T2
T2EX
A8m/A0
INT1E: XBR1.4
AIN1.7/A15
z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z
AIN1.6/A14
z z z z z z
z z z z z z
T1
/INT1
AIN1.5/A13
INT0E: XBR1.2
/INT0
AIN1.4/A12
CP2E: XBR3.3
T0
AIN1.3/A11
z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z
AIN1.2/A10
z z z z z z
z z z z z z
z z z z z z
CP2
AIN1.1/A9
CP0E: XBR0.7
CP1
AIN1.0/A8
z z z z z z z z z z z z
z z z z z z z z z z z z z
CP0
/WR
z z z z z z
z z z z z z
ECI
/RD
z z z z z z z z z
z z z z z z z z z
z z z z z z z z z z z
ALE
z
z z z z z z
CEX5
Rev. 1.4
211
C8051F040/1/2/3/4/5/6/7
17.1.7. 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 ADC2. 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 = 0x42.
- 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
Interface 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 Crossbar will also skip P0.5 (ALE). RX1 is assigned to the next nonskipped 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) and UART1 TX pin (TX1, P0.4) outputs to Push-Pull by
setting P0MDOUT = 0x11.
6. We configure all EMIF-controlled pins to push-pull output mode by setting P0MDOUT |= 0xE0;
P2MDOUT = 0xFF; 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).
212
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
P0
PIN I/O 0
SCL
TX1
RX1
P2
4
P3
4
z
z
SPI0EN: XBR0.1
z
z z z
z
z z
z
z z z
z
z z
z z
z z
CP0
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z z z
z z z z
z
z
T3
z
T3EX
z
T4
z
T4EX
z
/SYSCLK z
CNVSTR0 z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z z
z z z
z z z z
PCA0ME: XBR0.[5:3]
ECI0E: XBR0.6
CP0E: XBR0.7
CP1E: XBR1.0
CP2E: XBR3.2
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
z
T0E: XBR1.1
INT0E: XBR1.2
T1E: XBR1.3
INT1E: XBR1.4
z
z
z
z
z
z
z
z
T2E: XBR1.5
T2EXE: XBR1.6
AD5/D5
AD4/D4
AD3/D3
AD2/D2
AD1/D1
AD0/D0
A15m/A7
A14m/A6
CNVSTE2: XBR3.2
A13m/A5
z z z z z z z z z z z z z z z z z z z
A12m/A4
CNVSTE0: XBR2.0
A11m/A3
z
z
z
z
z
z
z
A10m/A2
z z
z
z
z
z
z
z
A9m/A1
z z z z z
z
z
z
z
z
z
z
A8m/A0
CNVSTR2
z
z
z
z
z
z
z
z
AIN1.7/A15
T2EX
AIN1.4/A12
T2
AIN1.3/A11
/INT1
AIN1.2/A10
T1
AIN1.1/A9
/INT0
/WR
T0
/RD
CP2
ALE
CP1
z
z
z
z
z
z
z
z
AIN1.6/A14
CEX5
z
z
z
z
z
z
AIN1.5/A13
z
z
z
z
z
AIN1.0/A8
CEX4
z z
z
z z z
z
z z
z
z
z
z
UART1EN: XBR2.2
z
z z
CEX3
SMB0EN: XBR0.0
z
z z
z z z z z
CEX2
z
z
ECI
CEX1
UART0EN: XBR0.2
z
z
z
z
z
z
z
z
CEX0
T3E: XBR3.0
T3EXE: XBR3.1
T4E: XBR2.3
T4EXE: XBR2.4
SYSCKE: XBR1.7
AD7/D7
MOSI
SDA
P1
4
MISO
NSS
RX0
SCK
AD6/D6
TX0
Rev. 1.4
213
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.1. XBR0: Port I/O Crossbar Register 0
R/W
R/W
CP0E
ECI0E
Bit7
Bit6
R/W
R/W
R/W
PCA0ME
Bit5
Bit4
R/W
R/W
UART0EN SPI0EN
Bit3
Bit2
Bit1
R/W
Reset Value
SMB0EN 00000000
Bit0
SFR Address: 0xE1
SFR Page: F
Bit7:
Bit6:
Bits5-3:
Bit2:
Bit1:
Bit0:
214
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.2. 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
SFR Page: F
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
215
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.3. XBR2: Port I/O Crossbar Register 2
R/W
R/W
WEAKPUD XBARE
Bit7
Bit6
R/W
R/W
R/W
R/W
R/W
T4EXE
T4E
UART1E
EMIFLE
Bit5
Bit4
Bit3
Bit2
Bit1
R/W
Reset Value
CNVST0E 00000000
Bit0
SFR Address: 0xE3
SFR Page: F
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
216
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.4. XBR3: Port I/O Crossbar Register 3
R/W
R/W
R/W
R/W
R/W
Reset Value
CTXOUT
CP2E
CNVST2E
T3EXE
T3E
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xE4
SFR Page: F
Bit7:
Bit6-4:
Bit3:
Bit2:
Bit1:
Bit0:
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
Bit
Addressable
Bits7-0:
Rev. 1.4
217
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.6. P0MDOUT: Port0 Output Mode
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xA4
SFR Page: F
Bits7-0:
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.
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
Bit
Addressable
Bits7-0:
Notes:
1.
2.
218
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.8. P1MDIN: Port1 Input Mode
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xAD
SFR Page: F
Bits7-0:
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
SFR Page: F
Bits7-0:
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
219
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.10. P2: Port2 Data
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
Bit
Addessable
Bits7-0:
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 Memory Interface and On-Chip XRAM on page 189 for more information about the
External Memory Interface.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xAE
SFR Page: F
Bits7-0:
220
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.12. P2MDOUT: Port2 Output Mode
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xA6
SFR Page: F
Bits7-0:
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.
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
Bit
Addressable
Bits7-0:
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
Interface and On-Chip XRAM on page 189 for more information about the External Memory Interface.
Rev. 1.4
221
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.14. P3MDIN: Port3 Input Mode
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
11111111
SFR Address: 0xAF
SFR Page: F
Bits7-0:
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
SFR Page: F
Bits7-0:
222
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
17.2.1. Configuring Ports which are not Pinned Out
Although P4, P5, P6, and P7 are not brought out to pins on the C8051F041/3/5/7 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 pullup 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 PnOUT = 0xFF.
3. Force the output states of P4, P5, P6, and P7 to logic 0 by writing zeros to the Port Data registers: P4 = 0x00, P5 = 0x00, P6= 0x00, and P7 = 0x00.
Rev. 1.4
223
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.16. P4: Port4 Data
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
Bit
Addressable
Bits7-0:
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x9C
SFR Page: F
Bits7-0:
224
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.18. P5: Port5 Data
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
Bit
Addressable
Bits7-0:
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 189 for more information about the External Memory Interface.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x9D
SFR Page: F
Bits7-0:
Rev. 1.4
225
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.20. P6: Port6 Data
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
Bit
Addressable
Bits7-0:
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 Memory Interface and On-Chip XRAM on page 189 for more information about the
External Memory Interface.
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: 0x9E
SFR Page: F
Bits7-0:
226
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 17.22. P7: Port7 Data
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
Bit
Addressable
Bits7-0:
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
Interface and On-Chip XRAM on page 189 for more information about the External Memory Interface.
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: 0x9F
SFR Page: F
Bits7-0:
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
227
C8051F040/1/2/3/4/5/6/7
NOTES:
228
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
18. Controller Area Network (CAN0)
IMPORTANT DOCUMENTATION NOTE: The Bosch CAN Controller is integrated in the C8051F04x Family of devices. This section of the data sheet gives a description of the CAN controller as an overview and
offers a description of how the Silicon Labs CIP-51 MCU interfaces with the on-chip Bosch CAN controller.
In order to use the CAN controller, please refer to Boschs C_CAN Users Manual (revision 1.2) as an
accompanying manual to Silicon Labs C8051F04x Data sheet.
The C8051F04x family of devices feature a Control Area Network (CAN) controller that enables serial communication using the CAN protocol. Silicon Labs CAN facilitates communication on a CAN network in
accordance with the Bosch specification 2.0A (basic CAN) and 2.0B (full CAN). The CAN controller consists of a CAN Core, Message RAM (separate from the CIP-51 RAM), a message handler state machine,
and control registers. Silicon Labs CAN is a protocol controller and does not provide physical layer drivers
(i.e., transceivers). Figure 18.1 shows an example typical configuration on a CAN bus.
Silicon Labs CAN operates at bit rates of up to 1 Mbit/second, though this can be limited by the physical
layer chosen to transmit data on the CAN bus. The CAN processor has 32 Message Objects that can be
configured to transmit or receive data. Incoming data, message objects and their identifier masks are
stored in the CAN message RAM. All protocol functions for transmission of data and acceptance filtering is
performed by the CAN controller and not by the CIP-51 MCU. In this way, minimal CPU bandwidth is
needed to use CAN communication. The CIP-51 configures the CAN controller, accesses received data,
and passes data for transmission via Special Function Registers (SFRs) in the CIP-51.
C8051F04x
CANTX
CANRX
CAN
Transceiver
Isolation/Buffer (Optional)
CAN
Transceiver
CAN
Transceiver
Isolation/Buffer (Optional)
Isolation/Buffer (Optional)
CAN_H
R
CAN_L
Rev. 1.4
229
C8051F040/1/2/3/4/5/6/7
18.1. Bosch CAN Controller Operation
The CAN Controller featured in the C8051F04x family of devices is a full implementation of Boschs full
CAN module and fully complies with CAN specification 2.0B. A block diagram of the CAN controller is
shown in Figure 18.2. The CAN Core provides shifting (CANTX and CANRX), serial/parallel conversion of
messages, and other protocol related tasks such as transmission of data and acceptance filtering. The
message RAM stores 32 message objects which can be received or transmitted on a CAN network. The
CAN registers and message handler provide an interface for data transfer and notification between the
CAN controller and the CIP-51.
The function and use of the CAN Controller is detailed in the Bosch CAN Users Guide. The Users Guide
should be used as a reference to configure and use the CAN controller. This Silicon Labs data sheet
describes how to access the CAN controller.
The CAN Controller is typically initialized using the following steps:
Step 1. Set the SFRPAGE register to CAN0_PAGE.
Step 2. Set the INIT the CCE bits to 1 in the CAN0CN Register. See the CAN Users Guide for bit
definitions.
Step 3. Set timing parameters in the Bit Timing Register and the BRP Extension Register.
Step 4. Initialize each message object or set its MsgVal bit to NOT VALID.
Step 5. Reset the INIT bit to 0.
The CAN Control Register (CAN0CN), CAN Test Register (CAN0TST), and CAN Status Register
(CAN0STA) in the CAN controller can be accessed directly or indirectly via CIP-51 SFRs. All other CAN
registers must be accessed via an indirect indexing method described in Section 18.2.5. Using
CAN0ADR, CAN0DATH, and CANDATL to Access CAN Registers on page 234.
CANTX
C8051F04x
CANRX
CAN Controller
TX
RX
BRP
Prescaler
CAN
Core
CAN_CLK
(fsys)
S
Y
S
C
L
K
CIP-51
MCU
Message RAM
REGISTERS
Message Handler
Interrupt
230
Rev. 1.4
S
F
R
's
C8051F040/1/2/3/4/5/6/7
18.1.1. CAN Controller Timing
The CAN controllers system clock (fsys) is derived from the CIP-51 system clock (SYSCLK). Note that an
external oscillator (such as a quartz crystal) is typically required due to the high accuracy requirements for
CAN communication. Refer to Section 4.10.4 Oscillator Tolerance Range in the Bosch CAN Users Guide
for further information regarding this topic.
Value
Description
22.1184 MHz
22.1184 MHz
45.211 ns
45.211 ns
10 m
400 ns
Notes:
1. The CAN time quantum (tq) is the smallest unit of time recognized by the CAN contoller. Bit timing parameters
are often specified in integer multiples of the time quantum.
2. The Baud Rate Prescaler (BRP) is defined as the value of the BRP Extension Register plus 1. The BRP
Extension Register has a reset value of 0x0000; the Baud Rate Prescaler has a reset value of 1.
3. Based on an ISO-11898 compliant transceiver. CAN does not specify a physical layer.
Each bit transmitted on a CAN network has 4 segments (Sync_Seg, Prop_Seg, Phase_Seg1, and
Phase_Seg2), as shown in Figure 18.3. The sum of these segments determines the CAN bit time (1/bit
rate). In this example, the desired bit rate is 1 Mbit/sec; therefore, the desired bit time is 1000 ns.
Sync_Seg
Prop_Seg
1tq
1 to 8 tq
Phase_Seg1
1 to 8 tq
1tq
Phase_Seg2
1 to 8 tq
Sample Point
Rev. 1.4
231
C8051F040/1/2/3/4/5/6/7
We will adjust the length of the 4 bit segments so that their sum is as close as possible to the desired bit
time. Since each segment must be an integer multiple of the time quantum (tq), the closest achievable bit
time is 22 tq (994.642 ns), yielding a bit rate of 1.00539 Mbit/sec. The Sync_Seg is a constant 1 tq. The
Prop_Seg must be greater than or equal to the propagation delay of 400 ns; we choose 9 tq (406.899 ns).
The remaining time quanta (tq) in the bit time are divided between Phase_Seg1 and Phase_Seg2 as
shown in Figure 18.1. We select Phase_Seg1 = 6 tq and Phase_Seg2 = 6 tq.
Phase_Seg1 + Phase_Seg2 = Bit Time ( Sync_Seg + Prop_Seg )
Note 1: If Phase_Seg1 + Phase_Seg2 is even, then Phase_Seg2 = Phase_Seg1.
Otherwise, Phase_Seg2 = Phase_Seg1 + 1.
Note 2: Phase_Seg2 should be at least 2 tq.
232
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
The following steps are performed to initialize the CAN timing registers:
Step 1. Set the SFRPAGE register to CAN0_PAGE.
Step 2. Set the INIT the CCE bits to 1 in the CAN Control Register accessible through the
CAN0CN SFR.
Step 3. Set the CAN0ADR to 0x03 to point to the Bit Timing Register.
Step 4. Write the value 0x5EC0 to the [CAN0DATH:CAN0DATL] CIP-51 SFRs to set the Bit
Timing Register using the indirect indexing method described on Section 18.2.5 on page
234.
Step 5. Perform other CAN initializations.
1. CAN Controller Protocol Registers: CAN control, interrupt, error control, bus status, test
modes.
2. Message Object Interface Registers: Used to configure 32 Message Objects, send and
receive data to and from Message Objects. The CIP-51 MCU accesses the CAN message RAM via the Message Object Interface Registers. Upon writing a message object
number to an IF1 or IF2 Command Request Register, the contents of the associated
Interface Registers (IF1 or IF2) will be transferred to or from the message object in CAN
RAM.
3. Message Handler Registers: These read only registers are used to provide information to
the CIP-51 MCU about the message objects (MSGVLD flags, Transmission Request
Pending, New Data Flags) and Interrupts Pending (which Message Objects have caused
an interrupt or status interrupt condition).
4. CIP-51 MCU Special Function Registers (SFR): Six registers located in the CIP-51 MCU
memory map that allow direct access to certain CAN Controller Protocol Registers, and
Indexed indirect access to all CAN registers.
18.2.1. CAN Controller Protocol Registers
The CAN Control Protocol Registers are used to configure the CAN controller, process interrupts, monitor
bus status, and place the controller in test modes. The CAN controller protocol registers are accessible
using CIP-51 MCU SFRs by an indexed method, and some can be accessed directly by addressing the
SFRs in the CIP-51 SFR map for convenience.
The registers are: CAN Control Register (CAN0CN), CAN Status Register (CAN0STA), CAN Test Register
(CAN0TST), Error Counter Register, Bit Timing Register, and the Baud Rate Prescaler (BRP) Extension
Register. CAN0STA, CAN0CN, and CAN0TST can be accessed via CIP-51 MCU SFRs. All others are
accessed indirectly using the CAN address indexed method via CAN0ADR, CAN0DATH, and CAN0DATL.
Please refer to the Bosch CAN Users Guide for information on the function and use of the CAN
Control Protocol Registers.
Rev. 1.4
233
C8051F040/1/2/3/4/5/6/7
Message Objects are stored in Message RAM, and are accessed and configured using the Message
Object Interface Registers. These registers are accessed via the CIP-51s CAN0ADR and CAN0DAT registers using the indirect indexed address method.
Please refer to the Bosch CAN Users Guide for information on the function and use of the Message Object Interface Registers.
Note: CAN0CN, CAN0STA, and CAN0TST may be accessed either by using the index method, or by direct
access with the CIP-51 MCU SFRs. CAN0CN is located at SFR location 0xF8/SFR page 1 (SFR Definition
18.3), CAN0TST at 0xDB/SFR page 1 (SFR Definition 18.4), and CAN0STA at 0xC0/SFR page 1 (SFR
Definition 18.5).
234
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 18.2. CAN Register Index and Reset Values
CAN Register
Index
Register Name
Reset
Value
0x00
0x0001
0x01
Status Register
0x0000
0x02
Error Register
0x0000
Read Only
0x03
0x2301
0x04
Interrupt Register
0x0000
Read Only
0x05
Test Register
0x0000
0x06
0x0000
0x08
0x0001
0x09
0x0000
0x0A
IF1 Mask 1
0xFFFF
0x0B
IF1 Mask 2
0xFFFF
0x0C
IF1 Arbitration 1
0x0000
0x0D
IF1 Arbitration 2
0x0000
0x0E
0x0000
0x0F
IF1 Data A1
0x0000
0x10
IF1 Data A2
0x0000
0x11
IF1 Data B1
0x0000
0x12
IF1 Data B2
0x0000
0x20
0x0001
0x21
0x0000
0x22
IF2 Mask 1
0xFFFF
0x23
IF2 Mask 2
0xFFFF
0x24
IF2 Arbitration 1
0x0000
0x25
IF2 Arbitration 2
0x0000
Rev. 1.4
Notes
235
C8051F040/1/2/3/4/5/6/7
Table 18.2. CAN Register Index and Reset Values (Continued)
CAN Register
Index
Register Name
Reset
Value
0x26
0x0000
0x27
IF2 Data A1
0x0000
0x28
IF2 Data A2
0x0000
0x29
IF2 Data B1
0x0000
0x2A
IF2 Data B2
0x0000
0x40
Transmission Request 1
0x0000
0x41
Transmission Request 2
0x0000
0x48
New Data 1
0x0000
0x49
New Data 2
0x0000
0x50
Interrupt Pending 1
0x0000
0x51
Interrupt Pending 2
0x0000
0x58
Message Valid 1
0x0000
0x59
Message Valid 2
0x0000
Notes
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: 0xD9
SFR Page: 1
Bit7-0:
236
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 18.1. CAN0DATL: CAN Data Access Register Low Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000001
SFR Address: 0xD8
SFR Page: 1
Bit7-0:
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xDA
SFR Page: 1
Bit7-0:
Rev. 1.4
237
C8051F040/1/2/3/4/5/6/7
SFR Definition 18.3. CAN0CN: CAN Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
CANIF
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
Bit 4:
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
Please see the Bosch CAN Users Guide for a complete definition of this register
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xDB
SFR Page: 1
All CAN registers functions/definitions are listed and described in the Bosch CAN
Users Guide.
This register may be accessed directly in the CIP-51 SFR register space, or through the indirect, index method (See Section 18.2.5. Using CAN0ADR, CAN0DATH, and CANDATL to
Access CAN Registers on page 234).
238
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 18.5. CAN0STA: CAN Status
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
Please see the Bosch CAN Users Guide for a complete definition of this register
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xC0
SFR Page: 1
All CAN registers functions/definitions are listed and described in the Bosch CAN
Users Guide.
This register may be accessed directly in the CIP-51 SFR register space, or through the indirect, index method (See Section 18.2.5. Using CAN0ADR, CAN0DATH, and CANDATL to
Access CAN Registers on page 234).
Rev. 1.4
239
C8051F040/1/2/3/4/5/6/7
NOTES:
240
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
19. System Management BUS / I2C BUS (SMBUS0)
The SMBus0 I/O interface is a two-wire, bi-directional serial bus. SMBus0 is compliant with the System
Management Bus Specification, version 2, 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. A method of extending the clock-low duration is available 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 19.4 on
page 247.
SFR Bus
SMB0CN
B
U
S
Y
SMB0STA
E S S S A F T
N T T I A T O
S A O
E E
M
B
S
T
A
7
S
T
A
6
S
T
A
5
S
T
A
4
S
T
A
3
S
T
A
2
SMB0CR
S
T
A
1
S
T
A
0
C C C C C C C C
R R R R R R R R
7 6 5 4 3 2 1 0
Clock Divide
Logic
SYSCLK
SCL
FILTER
Arbitration
SCL Synchronization
Status Generation
SCL Generation (Master Mode)
IRQ Generation
SCL
Control
Data Path
Control
SDA
Control
C
R
O
S
S
B
A
R
A=B
A=B
Interrupt
Request
Port I/O
0000000b
7 MSBs
SMB0DAT
7 6 5 4 3 2 1 0
S
L
V
6
S
L
V
5
S
L
V
4
S
L
V
3
S
L
V
2
S
L
V
1
S
L
V G
0 C
SDA
FILTER
1
N
0
Read
SMB0DAT
SMB0ADR
Write to
SMB0DAT
SFR Bus
Rev. 1.4
241
C8051F040/1/2/3/4/5/6/7
Figure 19.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 pullup 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.
VDD = 5 V
VDD = 3 V
VDD = 5 V
VDD = 3 V
Master
Device
Slave
Device 1
Slave
Device 2
SDA
SCL
242
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
19.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 initiates 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 19.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 generates the START condition and then transmits the slave address and direction bit. If the transaction is a WRITE operation from the master to the slave, the master transmits the data one byte at a time
and expects an ACK from the slave at the end of each byte. For READ operations, the slave transmits the
data and expects 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 19.3 illustrates a typical SMBus transaction.
SCL
SDA
SLA6
START
SLA5-0
R/W
D7
ACK
D6-0
Data Byte
NACK
STOP
Rev. 1.4
243
C8051F040/1/2/3/4/5/6/7
19.2.2. Clock Low Extension
SMBus provides a clock synchronization mechanism, similar to I2C, which allows devices with different
speed capabilities 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.
SLA
Interrupt
Data Byte
Interrupt
Data Byte
Interrupt
Interrupt
S = START
P = STOP
A = ACK
W = WRITE
SLA = Slave Address
Received by SMBus
Interface
Transmitted by
SMBus Interface
244
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
19.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 depending on the state of the AA bit in register SMB0CN. SMBus0
generates a STOP condition to indicate the end of the serial transfer.
SLA
Interrupt
Data Byte
Interrupt
Data Byte
Interrupt
Interrupt
S = START
P = STOP
A = ACK
N = NACK
R = READ
SLA = Slave Address
Received by SMBus
Interface
Transmitted by
SMBus Interface
Interrupt
SLA
Interrupt
Data Byte
Data Byte
Interrupt
Interrupt
S = START
P = STOP
N = NACK
W = WRITE
SLA = Slave Address
Received by SMBus
Interface
Transmitted by
SMBus Interface
Rev. 1.4
245
C8051F040/1/2/3/4/5/6/7
19.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 direction 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.
Interrupt
SLA
Interrupt
Data Byte
Data Byte
Interrupt
Interrupt
S = START
P = STOP
A = ACK
R = READ
SLA = Slave Address
Received by SMBus
Interface
Transmitted by
SMBus Interface
246
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
19.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 sections.
Rev. 1.4
247
C8051F040/1/2/3/4/5/6/7
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 SFR Definition 19.2, SMBus0 Clock Rate Register).
When the TOE bit in SMB0CN is set to logic 1, Timer 4 is used to detect SCL low timeouts. If Timer 4 is
enabled (see Section 23.2. Timer 2, Timer 3, and Timer 4 on page 297), Timer 4 is forced to reload
when SCL is high, and forced to count when SCL is low. With Timer 4 enabled and configured to overflow
after 25 ms (and TOE set), a Timer 4 overflow indicates a SCL low timeout; the Timer 4 interrupt service
routine can then be used to reset SMBus0 communication in the event of an SCL low timeout.
248
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 19.1. SMB0CN: SMBus0 Control
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
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
249
C8051F040/1/2/3/4/5/6/7
19.4.2. Clock Rate Register
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
SFR Page: 0
Bits7-0:
Using the same value of SMB0CR from above, the Bus Free Timeout period is given in the
following equation:
( 256 SMB0CR ) + 1
T BFT 10 ----------------------------------------------------SYSCLK
250
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
19.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 reads 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 transition from master transmitter to slave receiver is made with the correct data in
SMB0DAT.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xC2
SFR Page: 0
Bits7-0:
Rev. 1.4
251
C8051F040/1/2/3/4/5/6/7
SFR Definition 19.4. SMB0ADR: SMBus0 Address
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
SFR Page: 0
Bits7-1:
Bit0:
252
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 19.5. SMB0STA: SMBus0 Status
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
11111000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xC1
SFR Page: 0
Bits7-3:
Bits2-0:
STA2-STA0: The three least significant bits of SMB0STA are always read as logic 0 when
the SI flag is logic 1.
Rev. 1.4
253
C8051F040/1/2/3/4/5/6/7
Table 19.1. SMB0STA Status Codes and States
Master Receiver
Master Transmitter
MT/
MR
Mode
254
Status
Code
SMBus State
Typical Action
0x08
0x10
0x18
0x20
0x28
0x30
1) Retry transfer OR
2) Set STO.
0x38
Arbitration Lost.
0x40
0x48
0x50
0x58
Set STO.
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 19.1. SMB0STA Status Codes and States (Continued)
All
Slave
Slave Transmitter
Slave Receiver
Mode
Status
Code
SMBus State
Typical Action
0x60
0x68
Arbitration lost in sending SLA + R/W as master. Own address + W received. ACK transmitted.
0x70
0x78
Arbitration lost in sending SLA + R/W as master. General call address received. ACK transmitted.
0x80
0x88
0x90
0x98
0xA0
No action necessary.
0xA8
0xB0
0xB8
0xC0
0xC8
0xD0
0x00
0xF8
Idle
Rev. 1.4
255
C8051F040/1/2/3/4/5/6/7
NOTES:
256
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
20. Enhanced Serial Peripheral Interface (SPI0)
The Enhanced Serial Peripheral Interface (SPI0) provides access to a flexible, full-duplex synchronous
serial bus. SPI0 can operate as a master or slave device in both 3-wire or 4-wire modes, and supports multiple masters and slaves on a single SPI bus. The slave-select (NSS) signal can be configured as an input
to select SPI0 in slave mode, or to disable Master Mode operation in a multi-master environment, avoiding
contention on the SPI bus when more than one master attempts simultaneous data transfers. NSS can
also be configured as a chip-select output in master mode, or disabled for 3-wire operation. Additional general purpose port I/O pins can be used to select multiple slave devices in master mode.
SFR Bus
SYSCLK
SPI0CN
SPIBSY
MSTEN
CKPHA
CKPOL
SLVSEL
NSSIN
SRMT
RXBMT
SPIF
WCOL
MODF
RXOVRN
NSSMD1
NSSMD0
TXBMT
SPIEN
SPI0CFG
SCR7
SCR6
SCR5
SCR4
SCR3
SCR2
SCR1
SCR0
SPI0CKR
Clock Divide
Logic
SPI IRQ
Pin Interface
Control
MOSI
Tx Data
SPI0DAT
SCK
Shift Register
Rx Data
7 6 5 4 3 2 1 0
Pin
Control
Logic
MISO
C
R
O
S
S
B
A
R
Port I/O
NSS
Read
SPI0DAT
Write
SPI0DAT
SFR Bus
Rev. 1.4
257
C8051F040/1/2/3/4/5/6/7
20.1. Signal Descriptions
The four signals used by SPI0 (MOSI, MISO, SCK, NSS) are described below.
258
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
20.2. SPI0 Master Mode Operation
A SPI master device initiates all data transfers on a SPI bus. SPI0 is placed in master mode by setting the
Master Enable flag (MSTEN, SPI0CN.6). Writing a byte of data to the SPI0 data register (SPI0DAT) when
in master mode writes to the transmit buffer. If the SPI shift register is empty, the byte in the transmit buffer
is moved to the shift register, and a data transfer begins. 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. 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. Therefore, the SPIF flag serves as both a transmit-complete and receive-data-ready flag. The
data byte received from the slave is transferred MSB-first into the master's shift register. When a byte is
fully shifted into the register, it is moved to the receive buffer where it can be read by the processor by
reading SPI0DAT.
When configured as a master, SPI0 can operate in one of three different modes: multi-master mode, 3-wire
single-master mode, and 4-wire single-master mode. The default, multi-master mode is active when
NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 1. In this mode, NSS is an input to the device, and
is used to disable the master SPI0 when another master is accessing the bus. When NSS is pulled low in
this mode, MSTEN (SPI0CN.6) and SPIEN (SPI0CN.0) are set to 0 to disable the SPI master device, and
a Mode Fault is generated (MODF, SPI0CN.5 = 1). Mode Fault will generate an interrupt if enabled. SPI0
must be manually re-enabled in software under these circumstances. In multi-master systems, devices will
typically default to being slave devices while they are not acting as the system master device. In multi-master mode, slave devices can be addressed individually (if needed) using general-purpose I/O pins.
Figure 20.2 shows a connection diagram between two master devices in multiple-master mode.
3-wire single-master mode is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 0. In this
mode, NSS is not used, and does not get mapped to an external port pin through the crossbar. Any slave
devices that must be addressed in this mode should be selected using general-purpose I/O pins.
Figure 20.3 shows a connection diagram between a master device in 3-wire master mode and a slave
device.
4-wire single-master mode is active when NSSMD1 (SPI0CN.3) = 1. In this mode, NSS is configured as an
output pin, and can be used as a slave-select signal for a single SPI device. In this mode, the output value
of NSS is controlled (in software) with the bit NSSMD0 (SPI0CN.2). Additional slave devices can be
addressed using general-purpose I/O pins. Figure 20.4 shows a connection diagram for a master device in
4-wire master mode and two slave devices.
Rev. 1.4
259
C8051F040/1/2/3/4/5/6/7
Master
Device 1
NSS
GPIO
MISO
MISO
MOSI
MOSI
SCK
SCK
GPIO
NSS
Master
Device 2
Master
Device
MISO
MISO
MOSI
MOSI
SCK
SCK
Slave
Device
Figure 20.3. 3-Wire Single Master and Slave Mode Connection Diagram
Master
Device
GPIO
MISO
MISO
MOSI
MOSI
SCK
SCK
NSS
NSS
MISO
MOSI
Slave
Device
Slave
Device
SCK
NSS
Figure 20.4. 4-Wire Single Master and Slave Mode Connection Diagram
260
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
20.3. SPI0 Slave Mode Operation
When SPI0 is enabled and not configured as a master, it will operate as a SPI slave. As a slave, bytes are
shifted in through the MOSI pin and out through the MISO pin by a master device controlling the SCK signal. A bit counter in the SPI0 logic counts SCK edges. When 8 bits have been shifted through the shift register, the SPIF flag is set to logic 1, and the byte is copied into the receive buffer. Data is read from the
receive buffer by reading SPI0DAT. A slave device cannot initiate transfers. Data to be transferred to the
master device is pre-loaded into the shift register by writing to SPI0DAT. Writes to SPI0DAT are doublebuffered, and are placed in the transmit buffer first. If the shift register is empty, the contents of the transmit
buffer will immediately be transferred into the shift register. When the shift register already contains data,
the SPI will wait until the byte is transferred before loading it with the transmit buffers contents.
When configured as a slave, SPI0 can be configured for 4-wire or 3-wire operation. The default, 4-wire
slave mode, is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 1. In 4-wire mode, the
NSS signal is routed to a port pin and configured as a digital input. SPI0 is enabled when NSS is logic 0,
and disabled when NSS is logic 1. The bit counter is reset on a falling edge of NSS. 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.
Figure 20.4 shows a connection diagram between two slave devices in 4-wire slave mode and a master
device.
3-wire slave mode is active when NSSMD1 (SPI0CN.3) = 0 and NSSMD0 (SPI0CN.2) = 0. NSS is not
used in this mode, and does not get mapped to an external port pin through the crossbar. Since there is no
way of uniquely addressing the device in 3-wire slave mode, SPI0 must be the only slave device present
on the bus. It is important to note that in 3-wire slave mode there is no external means of resetting the bit
counter that determines when a full byte has been received. The bit counter can only be reset by disabling
and re-enabling SPI0 with the SPIEN bit. Figure 20.3 shows a connection diagram between a slave device
in 3-wire slave mode and a master device.
Rev. 1.4
261
C8051F040/1/2/3/4/5/6/7
20.5. Serial Clock Timing
As shown in Figure 20.5, 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.5) selects one
of two clock phases (edge used to latch the data). The CKPOL bit (SPI0CFG.4) selects between an activehigh 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) when changing the
clock phase or polarity.
Note that in master mode, the SPI samples MISO one system clock before the inactive edge of SCK (the
edge where MOSI changes state) to provide maximum settling time for the slave device.
The SPI0 Clock Rate Register (SPI0CKR) as shown in SFR Definition 20.3 controls the master mode
serial clock frequency. This register is ignored when operating in slave mode. 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 (in 4-wire slave mode), 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 than 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.
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
NSS
262
Rev. 1.4
Bit 1
Bit 0
C8051F040/1/2/3/4/5/6/7
20.6. SPI Special Function Registers
SPI0 is accessed and controlled through four special function registers in the system controller: SPI0CN
Control Register, 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 definitions.
R/W
R/W
R/W
Reset Value
SPIBSY
MSTEN
CKPHA
CKPOL
SLVSEL
NSSIN
SRMT
RXBMT
00000111
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x9A
SFR Page: 0
Bit 7:
Bit 6:
Bit 5:
Bit 4:
Bit 3:
Bit 2:
Bit 1:
Bit 0:
Rev. 1.4
263
C8051F040/1/2/3/4/5/6/7
SFR Definition 20.2. SPI0CN: SPI0 Control
R/W
R/W
R/W
SPIF
WCOL
MODF
Bit7
Bit6
Bit5
R/W
R/W
R/W
Bit3
Bit2
R/W
Reset Value
TXBMT
SPIEN
00000110
Bit1
Bit0
Bit
Addressable
Bit 7:
264
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 20.3. SPI0CKR: SPI0 Clock Rate
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
SFR Page: 0
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 SCK = 200kHz
Rev. 1.4
265
C8051F040/1/2/3/4/5/6/7
SFR Definition 20.4. SPI0DAT: SPI0 Data
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x9B
SFR Page: 0
266
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
21. 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 supported. 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 previously
received byte has been 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. Reading SCON0 accesses
the Receive register and writing SCON0 accesses the Transmit register.
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).
SFR Bus
Write to
SBUF0
TB80
SET
SSTA0
F R T S
E X X M
0 O C O
V O D
0 L 0
0
S
0
T
C
L
K
1
S
0
T
C
L
K
1
SBUF0
TX0
CLR
S
0
R
C
L
K
1
S
0
R
C
L
K
1
Crossbar
Zero Detector
Shift
Stop Bit
Gen.
Data
Tx Control
Start
Tx Clock
Send
Tx IRQ
SCON0
UART0
Baud Rate Generation
Logic
S
M
0
0
Rx Clock
S
M
1
0
S
M
2
0
R
E
N
0
T
B
8
0
TI0
R T R
B I I
8 0 0
0
EN
Serial Port
(UART0) Interrupt
RI0
Rx IRQ
Rx Control
Start
Shift
Frame Error
Detection
Load
SBUF
Address
Match
Port I/O
0x1FF
Load
SBUF0
RB80
SBUF0
Match Detect
SADDR0
SADEN0
Read
SBUF0
SFR Bus
RX0
Crossbar
Rev. 1.4
267
C8051F040/1/2/3/4/5/6/7
21.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 21.1.
Synchronization
Baud Clock
Data Bits
Start/Stop Bits
Synchronous
SYSCLK / 12
None
Asynchronous
Timer 1, 2, 3, or 4 Overflow
1 Start, 1 Stop
Asynchronous
SYSCLK / 32 or SYSCLK / 64
1 Start, 1 Stop
Asynchronous
Timer 1, 2, 3, or 4 Overflow
1 Start, 1 Stop
D0
D1
D2
D3
D4
D5
D6
D7
TX (clk out)
MODE 0 RECEIVE
RX (data in)
D0
D1
D2
D3
D4
D5
D6
TX (clk out)
268
Rev. 1.4
D7
C8051F040/1/2/3/4/5/6/7
TX
CLK
RX
DATA
Shift
Reg.
C8051Fxxx
8 Extra Outputs
START
BIT
D0
D1
D2
D3
D4
D5
D6
D7
STOP
BIT
BIT TIMES
BIT SAMPLING
Rev. 1.4
269
C8051F040/1/2/3/4/5/6/7
When SMOD0 = 0:
Mode1_BaudRate = 1 32 Timer1_OverflowRate
When SMOD0 = 1:
Mode1_BaudRate = 1 16 Timer1_OverflowRate
Equation 21.1. Mode 1 Baud Rate using Timer 1
The Timer 1 overflow rate is determined by the Timer 1 clock source (T1CLK) and reload value (TH1). The
frequency of T1CLK is selected as described in Section 23.1. Timer 0 and Timer 1 on page 289. The
Timer 1 overflow rate is calculated as shown in Equation 21.2.
Mode1_BaudRate = ( 1 16 Timer234_OverflowRate )
Equation 21.3. Mode 1 Baud Rate using Timer 2, 3, or 4
The overflow rate for Timer 2, 3, or 4 is determined by the clock source for the timer (TnCLK) and the 16bit reload value stored in the RCAPn register (n = 2, 3, or 4), as shown in Equation 21.4.
270
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
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). 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:
SM20 is logic 0
SM20 is logic 1, the received 9th bit is logic 1, and the received address matches the UART0 address
as described in Section 21.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 are set.
The baud rate in Mode 2 is either SYSCLK / 32 or SYSCLK / 64, according to the value of the SMOD0 bit
in register SSTA0.
BaudRate = 2
SMOD0
SYSCLK
----------------------
64
START
BIT
D0
D1
D2
D3
D4
D5
D6
D7
D8
STOP
BIT
BIT TIMES
BIT SAMPLING
Rev. 1.4
271
C8051F040/1/2/3/4/5/6/7
RS-232
LEVEL
XLTR
RS-232
TX
RX
C8051Fxxx
OR
TX
TX
RX
RX
MCU
C8051Fxxx
272
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
21.3. Configuration of a Masked Address
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 dont care bits in SADDR0.
Example 1, SLAVE #1
SADDR0
= 00110101
SADEN0
= 00001111
UART0 Address = xxxx0101
Example 2, SLAVE #2
SADDR0
= 00110101
SADEN0
= 11110011
UART0 Address = 0011xx01
Example 3, SLAVE #3
SADDR0
= 00110101
SADEN0
= 11000000
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. Following the received address interrupt, the slave will 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 resets 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.
Rev. 1.4
273
C8051F040/1/2/3/4/5/6/7
Master
Device
RX
TX
Slave
Device
RX
TX
Slave
Device
RX
TX
Slave
Device
RX
+5V
TX
274
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 21.2. Oscillator Frequencies for Standard Baud Rates
Timer 1 Reload Timer 2, 3, or 4
Oscillator frequency
2
Divide Factor
(MHz)
Reload Value Resulting Baud Rate (Hz)
Value1
24.0
208
0xF3
0xFFF3
115200 (115384)
22.1184
192
0xF4
0xFFF4
115200
18.432
160
0xF6
0xFFF6
115200
11.0592
96
0xFA
0xFFFA
115200
3.6864
32
0xFE
0xFFFE
115200
1.8432
16
0xFF
0xFFFF
115200
24.0
832
0xCC
0xFFCC
28800 (28846)
22.1184
768
0xD0
0xFFD0
28800
18.432
640
0xD8
0xFFD8
28800
11.0592
348
0xE8
0xFFE8
28800
3.6864
128
0xF8
0xFFF8
28800
1.8432
64
0xFC
0xFFFC
28800
24.0
2496
0x64
0xFF64
9600 (9615)
22.1184
2304
0x70
0xFF70
9600
18.432
1920
0x88
0xFF88
9600
11.0592
1152
0xB8
0xFFB8
9600
3.6864
384
0xE8
0xFFE8
9600
1.8432
192
0xF4
0xFFF4
9600
Notes:
1. Assumes SMOD0=1 and T1M=1.
2. Numbers in parenthesis show the actual baud rate.
Rev. 1.4
275
C8051F040/1/2/3/4/5/6/7
SFR Definition 21.1. SCON0: UART0 Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
SM00
SM10
SM20
REN0
TB80
RB80
TI0
RI0
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x98
SFR Page: 0
Bits7-6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
276
SM10
0
1
0
1
Mode
Mode 0: Synchronous Mode
Mode 1: 8-Bit UART, Variable Baud Rate
Mode 2: 9-Bit UART, Fixed Baud Rate
Mode 3: 9-Bit UART, Variable Baud Rate
Reading these bits returns the current UART0 mode as defined above.
SM20: Multiprocessor Communication Enable.
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.
Mode 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.
REN0: Receive Enable.
This bit enables/disables the UART0 receiver.
0: UART0 reception disabled.
1: UART0 reception enabled.
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.
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.
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.
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 interrupt service routine. This bit must be cleared manually by software.
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 21.2. SSTA0: UART0 Status and Clock Selection
R/W
R/W
FE0
RXOV0
Bit7
Bit6
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x91
SFR Page: 0
Bit7:
Bit6:
Bit5:
Bit4:
Bits3-2:
Bits1-0:
S0TCLK0
0
1
0
1
Rev. 1.4
277
C8051F040/1/2/3/4/5/6/7
SFR Definition 21.3. SBUF0: UART0 Data Buffer
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x99
SFR Page: 0
Bits7-0:
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
SFR Page: 0
Bits7-0:
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
SFR Page: 0
Bits7-0:
278
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
22. UART1
UART1 is an asynchronous, full duplex serial port offering modes 1 and 3 of the standard 8051 UART.
Enhanced baud rate support allows a wide range of clock sources to generate standard baud rates (details
in Section 22.1. Enhanced Baud Rate Generation on page 280). Received data buffering allows
UART1 to start reception of a second incoming data byte before software has finished reading the previous
data byte.
UART1 has two associated SFRs: Serial Control Register 1 (SCON1) and Serial Data Buffer 1 (SBUF1).
The single SBUF1 location provides access to both transmit and receive registers. Reading SBUF1
accesses the buffered Receive register; writing SBUF1 accesses the Transmit register.
With UART1 interrupts enabled, an interrupt is generated each time a transmit is completed (TI1 is set in
SCON1), or a data byte has been received (RI1 is set in SCON1). The UART1 interrupt flags are not
cleared by hardware when the CPU vectors to the interrupt service routine. They must be cleared manually
by software, allowing software to determine the cause of the UART1 interrupt (transmit complete or receive
complete).
SFR Bus
Write to
SBUF1
TB81
SBUF1
(TX Shift)
SET
D
TX1
CLR
Crossbar
Zero Detector
Stop Bit
Shift
Start
Data
Tx Control
Tx Clock
Tx IRQ
TI1
MCE1
REN1
TB81
RB81
TI1
RI1
S1MODE
SCON1
UART1 Baud
Rate Generator
Send
RI1
Serial
Port
Interrupt
Port I/O
Rx IRQ
Rx Clock
Rx Control
Start
Shift
0x1FF
RB81
Load
SBUF1
SBUF1
(RX Latch)
Read
SBUF1
SFR Bus
RX1
Crossbar
Rev. 1.4
279
C8051F040/1/2/3/4/5/6/7
22.1. Enhanced Baud Rate Generation
The UART1 baud rate is generated by Timer 1 in 8-bit auto-reload mode. The TX clock is generated by
TL1; the RX clock is generated by a copy of TL1 (shown as RX Timer in Figure 22.2), which is not useraccessible. Both TX and RX Timer overflows are divided by two to generate the TX and RX baud rates.
The RX Timer runs when Timer 1 is enabled, and uses the same reload value (TH1). However, an
RX Timer reload is forced when a START condition is detected on the RX pin. This allows a receive to
begin any time a START is detected, independent of the TX Timer state.
Timer 1
TL1
UART1
Overflow
TX Clock
Overflow
RX Clock
TH1
Start
Detected
RX Timer
T1 CLK
1
UartBaudRate = ------------------------------- --( 256 TH1 ) 2
Equation 22.1. UART1 Baud Rate
Timer 1 clock frequency is selected as described in Section 23.1. Timer 0 and Timer 1 on page 289. A
quick reference for typical baud rates and system clock frequencies is given in Table 22.1 through
Table 22.6. Note that the internal oscillator may still generate the system clock when the external oscillator
is driving Timer 1 (see Section 23.1. Timer 0 and Timer 1 on page 289 for more details).
280
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
22.2. Operational Modes
UART1 provides standard asynchronous, full duplex communication. The UART mode (8-bit or 9-bit) is
selected by the S1MODE bit (SCON1.7). Typical UART connection options are shown below.
TX
RS-232
LEVEL
XLTR
RS-232
RX
C8051Fxxx
OR
TX
TX
RX
RX
MCU
C8051Fxxx
START
BIT
D0
D1
D2
D3
D4
D5
D6
D7
STOP
BIT
BIT TIMES
BIT SAMPLING
Rev. 1.4
281
C8051F040/1/2/3/4/5/6/7
22.2.2. 9-Bit UART
9-bit UART mode uses 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. The state of the ninth transmit data bit is determined by the value in TB81
(SCON1.3), which is assigned by user software. It can be assigned the value of the parity flag (bit P in register PSW) for error detection, 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 1. After the stop bit
is received, the data byte will be loaded into the SBUF1 receive register if the following conditions are met:
(1) RI1 must be logic 0, and (2) if MCE1 is logic 1, the 9th bit must be logic 1 (when MCE1 is logic 0, the
state of the ninth data bit is unimportant). If these conditions are met, the eight bits of data are stored in
SBUF1, the ninth bit is stored in RB81, and the RI1 flag is set to 1. If the above conditions are not met,
SBUF1 and RB81 will not be loaded and the RI1 flag will not be set to 1. A UART1 interrupt will occur if
enabled when either TI1 or RI1 is set to 1.
MARK
SPACE
START
BIT
D0
D1
D2
D3
D4
D5
D6
BIT TIMES
BIT SAMPLING
282
Rev. 1.4
D7
D8
STOP
BIT
C8051F040/1/2/3/4/5/6/7
22.3. Multiprocessor Communications
9-Bit UART mode supports multiprocessor communication between a master processor and one or more
slave processors by special use of the ninth data bit. When a master processor wants to transmit to one or
more slaves, it first sends an address byte to select the target(s). 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.
Setting the MCE1 bit (SCON1.5) of a slave processor configures its UART such that when a stop bit is
received, the UART will generate an interrupt only if the ninth bit is logic one (RB81 = 1) signifying an
address byte has been received. In the UART interrupt handler, software should compare the received
address with the slave's own assigned 8-bit address. If the addresses match, the slave should clear its
MCE1 bit to enable interrupts on the reception of the following data byte(s). Slaves that weren't addressed
leave their MCE1 bits set and do not generate interrupts on the reception of the following data bytes,
thereby ignoring the data. Once the entire message is received, the addressed slave should reset its
MCE1 bit to ignore all transmissions until it receives the next address byte.
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 master
processor 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).
Master
Device
RX
TX
Slave
Device
RX
TX
Slave
Device
RX
TX
Slave
Device
RX
+5V
TX
Rev. 1.4
283
C8051F040/1/2/3/4/5/6/7
SFR Definition 22.1. SCON1: Serial Port 1 Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
S1MODE
MCE1
REN1
TB81
RB81
TI1
RI1
01000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
284
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 22.2. SBUF1: Serial (UART1) Port Data Buffer
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x99
SFR Page: 1
Bits7-0:
Rev. 1.4
285
C8051F040/1/2/3/4/5/6/7
Table 22.1. Timer Settings for Standard Baud Rates Using the Internal 24.5 MHz
Oscillator
Frequency: 24.5 MHz
SYSCLK from
Internal Osc.
Target
Baud Rate
(bps)
230400
115200
57600
28800
14400
9600
2400
1200
Baud Rate
% Error
-0.32%
-0.32%
0.15%
-0.32%
0.15%
-0.32%
-0.32%
0.15%
X = Dont care
Oscillator
Divide
Factor
Timer Clock
Source
106
212
426
848
1704
2544
10176
20448
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 4
SYSCLK / 12
SYSCLK / 12
SYSCLK / 48
SYSCLK / 48
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
01
00
00
10
10
T1M*
Timer 1
Reload
Value (hex)
1
1
1
0
0
0
0
0
0xCB
0x96
0x2B
0x96
0xB9
0x96
0x96
0x2B
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
Table 22.2. Timer Settings for Standard Baud Rates Using an External 25.0 MHz
Oscillator
Frequency: 25.0 MHz
Target
Baud Rate
(bps)
Baud Rate
% Error
Oscillator
Divide
Factor
Timer Clock
Source
T1M*
Timer 1
Reload
Value (hex)
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 4
SYSCLK / 4
EXTCLK / 8
SYSCLK / 48
SYSCLK / 48
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
01
01
11
10
10
230400
115200
57600
28800
14400
9600
2400
1200
-0.47%
0.45%
-0.01%
0.45%
-0.01%
0.15%
0.45%
-0.01%
108
218
434
872
1736
2608
10464
20832
1
1
1
0
0
0
0
0
0xCA
0x93
0x27
0x93
0x27
0x5D
0x93
0x27
57600
-0.47%
432
EXTCLK / 8
11
0xE5
28800
-0.47%
864
EXTCLK / 8
11
0xCA
14400
0.45%
1744
EXTCLK / 8
11
0x93
9600
0.15%
2608
EXTCLK / 8
11
0x5D
X = Dont care
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
286
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 22.3. Timer Settings for Standard Baud Rates Using an External 22.1184 MHz
Oscillator
Frequency: 22.1184 MHz
SYSCLK from
Internal Osc.
SYSCLK from
External Osc.
Target
Baud Rate
(bps)
230400
115200
57600
28800
14400
9600
2400
1200
230400
115200
57600
28800
14400
9600
Baud Rate
% Error
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
X = Dont care
Oscillator
Divide
Factor
Timer Clock
Source
96
192
384
768
1536
2304
9216
18432
96
192
384
768
1536
2304
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 12
SYSCLK / 12
SYSCLK / 12
SYSCLK / 48
SYSCLK / 48
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
00
00
00
10
10
11
11
11
11
11
11
T1M*
Timer 1
Reload
Value (hex)
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0xD0
0xA0
0x40
0xE0
0xC0
0xA0
0xA0
0x40
0xFA
0xF4
0xE8
0xD0
0xA0
0x70
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
Table 22.4. Timer Settings for Standard Baud Rates Using an External 18.432 MHz
Oscillator
Frequency: 18.432 MHz
SYSCLK from
Internal Osc.
SYSCLK from
External Osc.
Target
Baud Rate
(bps)
230400
115200
57600
28800
14400
9600
2400
1200
230400
115200
57600
28800
14400
9600
Baud Rate
% Error
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
X = Dont care
Oscillator
Divide
Factor
Timer Clock
Source
80
160
320
640
1280
1920
7680
15360
80
160
320
640
1280
1920
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 4
SYSCLK / 4
SYSCLK / 12
SYSCLK / 48
SYSCLK / 48
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
01
01
00
10
10
11
11
11
11
11
11
T1M*
Timer 1
Reload
Value (hex)
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0xD8
0xB0
0x60
0xB0
0x60
0xB0
0xB0
0x60
0xFB
0xF6
0xEC
0xD8
0xB0
0x88
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
Rev. 1.4
287
C8051F040/1/2/3/4/5/6/7
Table 22.5. Timer Settings for Standard Baud Rates Using an External 11.0592 MHz
Oscillator
Frequency: 11.0592 MHz
SYSCLK from
Internal Osc.
SYSCLK from
External Osc.
Target
Baud Rate
(bps)
230400
115200
57600
28800
14400
9600
2400
1200
230400
115200
57600
28800
14400
9600
Baud Rate
% Error
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
X = Dont care
Oscillator
Divide
Factor
Timer Clock
Source
48
96
192
384
768
1152
4608
9216
48
96
192
384
768
1152
SYSCLK
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 12
SYSCLK / 12
SYSCLK / 12
SYSCLK / 48
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
XX
00
00
00
10
11
11
11
11
11
11
T1M*
Timer 1
Reload
Value (hex)
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0xE8
0xD0
0xA0
0x40
0xE0
0xD0
0x40
0xA0
0xFD
0xFA
0xF4
0xE8
0xD0
0xB8
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
Table 22.6. Timer Settings for Standard Baud Rates Using an External 3.6864 MHz
Oscillator
Frequency: 3.6864 MHz
SYSCLK from
Internal Osc.
SYSCLK from
External Osc.
Target
Baud Rate
(bps)
230400
115200
57600
28800
14400
9600
2400
1200
230400
115200
57600
28800
14400
9600
Baud Rate
% Error
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
X = Dont care
Oscillator
Divide
Factor
Timer Clock
Source
16
32
64
128
256
384
1536
3072
16
32
64
128
256
384
SYSCLK
SYSCLK
SYSCLK
SYSCLK
SYSCLK
SYSCLK
SYSCLK / 12
SYSCLK / 12
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
EXTCLK / 8
SCA1-SCA0
(pre-scale
select)*
XX
XX
XX
XX
XX
XX
00
00
11
11
11
11
11
11
T1M*
Timer 1
Reload
Value (hex)
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0xF8
0xF0
0xE0
0xC0
0x80
0x40
0xC0
0x80
0xFF
0xFE
0xFC
0xF8
0xF0
0xE8
*Note: SCA1-SCA0 and T1M bit definitions can be found in Section 23.1.
288
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
23. Timers
Each MCU includes 5 counter/timers: Timer 0 and Timer 1 are 16-bit counter/timers compatible with those
found in the standard 8051. Timer 2, Timer 3, and Timer 4 are 16-bit auto-reload and capture counter/timers for use with the ADC, DACs, square-wave generation, or for general-purpose use. These timers 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. Timers 2, 3, and 4 are identical, and offer not only 16-bit auto-reload and capture, but have the ability to produce a 50% duty-cycle
square-wave (toggle output) at an external port pin.
Timer 0 and Timer 1 Modes:
13-bit counter/timer
16-bit counter/timer
8-bit counter/timer with auto-reload
Two 8-bit counter/timers (Timer 0 only)
Timers 0 and 1 may be clocked by one of five sources, determined by the Timer Mode Select bits (T1MT0M) and the Clock Scale bits (SCA1-SCA0). The Clock Scale bits define a pre-scaled clock by which
Timer 0 and/or Timer 1 may be clocked (See SFR Definition 23.3 for pre-scaled clock selection). Timer 0/1
may then be configured to use this pre-scaled clock signal or the system clock. Timers 2, 3, and 4 may be
clocked by the system clock, the system clock divided by 12, or the external oscillator clock source divided
by 8.
Timer 0 and Timer 1 may also be operated as counters. 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 logic level for at least two full system clock cycles to ensure the level is properly
sampled.
Rev. 1.4
289
C8051F040/1/2/3/4/5/6/7
The C/T0 bit (TMOD.2) selects the counter/timer's clock source. When C/T0 is set to logic 1, high-to-low
transitions at the selected Timer 0 input pin (T0) increment the timer register (Refer to Section
17.1. Ports 0 through 3 and the Priority Crossbar Decoder on page 206 for information on selecting
and configuring external I/O pins). Clearing C/T0 selects the clock defined by the T0M bit (CKCON.3).
When T0M is set, Timer 0 is clocked by the system clock. When T0M is cleared, Timer 0 is clocked by the
source selected by the Clock Scale bits in CKCON (see SFR Definition 23.3).
Setting the TR0 bit (TCON.4) enables the timer when either GATE0 (TMOD.3) is logic 0 or the input signal
/INT0 is logic-level 1. Setting GATE0 to 1 allows the timer to be controlled by the external input signal /
INT0 (see Section 12.3.5. Interrupt Register Descriptions on page 157), facilitating pulse width measurements.
TR0
0
1
1
1
GATE0
X
0
1
1
/INT0
X
X
0
1
Counter/Timer
Disabled
Enabled
Disabled
Enabled
Setting TR0 does not force the timer to reset. The timer registers should be loaded with the desired initial
value before the timer is enabled.
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. The
input signal /INT1 is used with Timer 1.
CKCON
TT
1 0
MM
Pre-scaled Clock
TMOD
SS
CC
AA
1 0
G
A
T
E
1
C
/
T
1
T TG
1 1 A
MM T
1 0 E
0
C
/
T
0
T T
0 0
MM
1 0
0
0
SYSCLK
1
1
TCLK
TR0
Crossbar
TL0
(5 bits)
TH0
(8 bits)
GATE0
TCON
T0
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Interrupt
/INT0
290
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
23.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. TL0 holds the count and TH0 holds the reload value. When the counter in TL0 overflows from 0xFF
to 0x00, the timer overflow flag TF0 (TCON.5) is set and the counter in TL0 is reloaded from TH0. If Timer
0 interrupts are enabled, an interrupt 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. Setting the
TR0 bit (TCON.4) enables the timer when either GATE0 (TMOD.3) is logic 0 or when the input signal /INT0
is low.
CKCON
TT
1 0
MM
Pre-scaled Clock
TMOD
SS
CC
AA
1 0
G
A
T
E
1
C
/
T
1
T TG
1 1 A
MM T
1 0 E
0
C
/
T
0
T T
0 0
MM
1 0
0
0
SYSCLK
1
1
T0
TL0
(8 bits)
TCON
TCLK
TR0
Crossbar
GATE0
TH0
(8 bits)
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Interrupt
Reload
/INT0
Rev. 1.4
291
C8051F040/1/2/3/4/5/6/7
23.1.4. Mode 3: Two 8-bit Counter/Timers (Timer 0 Only)
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. TL0 can use either the system clock or an external input signal as its timebase. The TH0 register is
restricted to a timer function sourced by the system clock or prescaled 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. When Timer 0 is operating 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 generate baud rates for the SMBus and/or UART, and/or initiate ADC
conversions. While Timer 0 is operating in Mode 3, Timer 1 run control is handled through its mode settings. To run Timer 1 while Timer 0 is in Mode 3, set the Timer 1 Mode as 0, 1, or 2. To disable Timer 1,
configure it for Mode 3.
CKCON
T T
1 0
MM
Pre-scaled Clock
TMOD
SS
CC
AA
1 0
G
A
T
E
1
C
/
T
1
T T
1 1
MM
1 0
G
A
T
E
0
C
/
T
0
T T
0 0
MM
1 0
0
TR1
1
TCON
SYSCLK
TH0
(8 bits)
1
T0
TL0
(8 bits)
TR0
Crossbar
GATE0
/INT0
292
Rev. 1.4
TF1
TR1
TF0
TR0
IE1
IT1
IE0
IT0
Interrupt
Interrupt
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.1. TCON: Timer Control
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
Bit
Addressable
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
293
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.2. TMOD: Timer Mode
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
SFR Page: 0
Bit7:
Bit6:
Bits5-4:
Bit3:
Bit2:
Bits1-0:
Mode
Mode 0: 13-bit counter/timer
Mode 1: 16-bit counter/timer
Mode 2: 8-bit counter/timer with auto-reload
Mode 3: Timer 1 inactive
294
T1M0
0
1
0
1
T0M0
0
1
0
1
Mode
Mode 0: 13-bit counter/timer
Mode 1: 16-bit counter/timer
Mode 2: 8-bit counter/timer with auto-reload
Mode 3: Two 8-bit counter/timers
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.3. CKCON: Clock Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
T1M
T0M
SCA1
SCA0
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0x8E
SFR Page: 0
Bits7-5:
Bit4:
Bit3:
Bit2:
Bits1-0:
SCA0
0
1
0
1
Prescaled Clock
System clock divided by 12
System clock divided by 4
System clock divided by 48
External clock divided by 8
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
SFR Page: 0
Rev. 1.4
295
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.5. 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
SFR Page: 0
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
SFR Page: 0
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0x8D
SFR Page: 0
296
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
23.2. Timer 2, Timer 3, and Timer 4
Timers n are 16-bit counter/timers, each formed by two 8-bit SFRs: TMRnL (low byte) and TMRnH (high
byte) where n = 2, 3, and 4 for timers 2, 3, and 4 respectively. These timers feature auto-reload, capture,
and toggle output modes with the ability to count up or down. Capture Mode and Auto-reload mode are
selected using bits in the Timer n Control registers (TMRnCN). Toggle output mode is selected using the
Timer 2, 3, and 4 Configuration registers (TMRnCF). These timers may also be used to generate a squarewave at an external pin. As with Timers 0 and 1, Timers n can use either the system clock (divided by one,
two, or twelve), external clock (divided by eight) or transitions on an external input pin as its clock source.
The Counter/Timer Select bit C/Tn (TMRnCN.1) configures the peripheral as a counter or timer. Clearing
C/Tn configures the Timer to be in a timer mode (i.e., the system clock or external clock as input for the
timer). When C/Tn is set to 1, the timer is configured as a counter (i.e., high-to-low transitions at the Tn
input pin increment (or decrement) the counter/timer register). Refer to Section 17.1. Ports 0 through 3
and the Priority Crossbar Decoder on page 206 for information on selecting and configuring external I/
O pins for digital peripherals, such as the Tn pin. Timer 2 and 3 can be used to start an ADC Data Conversion and Timers 2, 3, and 4 can schedule DAC outputs. Only Timer 1 can be used to generate baud rates
for UART 1, and Timers 1, 2, 3, or 4 may be used to generate baud rates for UART 0.
Timer n can use either SYSCLK, SYSCLK divided by 2, SYSCLK divided by 12, an external clock divided
by 8, or high-to-low transitions on the Tn input pin as its clock source when operating in Counter/Timer with
Capture mode. Clearing the C/Tn bit (TMRnCN.1) selects the system clock/external clock as the input for
the timer. The Timer Clock Select bits TnM0 and TnM1 in TMRnCF can be used to select the system clock
undivided, system clock divided by two, system clock divided by 12, or an external clock provided at the
XTAL1/XTAL2 pins divided by 8 (see SFR Definition 23.9). When C/Tn is set to logic 1, a high-to-low transition at the Tn input pin increments the counter/timer register (i.e., configured as a counter).
Rev. 1.4
297
C8051F040/1/2/3/4/5/6/7
23.2.2. Capture Mode
In Capture Mode, Timer n will operate as a 16-bit counter/timer with capture facility. When the Timer External Enable bit (found in the TMRnCN register) is set to 1, a high-to-low transition on the TnEX input pin
causes the 16-bit value in the associated timer (TMRnH, TMRnL) to be loaded into the capture registers
(RCAPnH, RCAPnL). If a capture is triggered in the counter/timer, the Timer External Flag (TMRnCN.6)
will be set to 1 and an interrupt will occur if the interrupt is enabled. See Section 12.3. Interrupt Handler on page 154 for further information concerning the configuration of interrupt sources.
As the 16-bit timer register increments and overflows TMRnH:TMRnL, the TFn Timer Overflow/Underflow
Flag (TMRnCN.7) is set to 1 and an interrupt will occur if the interrupt is enabled. The timer can be configured to count down by setting the Decrement Enable Bit (TMRnCF.0) to 1. This will cause the timer to
decrement with every timer clock/count event and underflow when the timer transitions from 0x0000 to
0xFFFF. Just as in overflows, the Overflow/Underflow Flag (TFn) will be set to 1, and an interrupt will
occur if enabled.
Counter/Timer with Capture mode is selected by setting the Capture/Reload Select bit CP/RLn
(TMRnCN.0) and the Timer n Run Control bit TRn (TMRnCN.2) to logic 1. The Timer n respective External
Enable EXENn (TMRnCN.3) must also be set to logic 1 to enable captures. If EXENn is cleared, transitions on TnEX will be ignored.
TMRnCF
T T T T
n nO n
MMGO
1 0 n E
D
C
E
N
Toggle Logic
2
0xFF
0xFF
TMRnL
TMRnH
RCAPnL
RCAPnH
12
SYSCLK
External Clock
(XTAL1)
TMRnCN
TCLK
Crossbar
TRn
EXENn
TnE
X
CP/RLn
C/Tn
TRn
EXENn
EXFn
TFn
Crossbar
298
Tn
(Port Pin)
Tn
Rev. 1.4
Interrupt
C8051F040/1/2/3/4/5/6/7
23.2.3. Auto-Reload Mode
In Auto-Reload Mode, the counter/timer can be configured to count up or down and cause an interrupt/flag
to occur upon an overflow/underflow event. When counting up, the counter/timer will set its overflow/underflow flag (TFn) and cause an interrupt (if enabled) upon overflow/underflow, the values in the Reload/Capture Registers (RCAPnH and RCAPnL) are loaded into the timer, and the timer is restarted. When the
Timer External Enable Bit (EXENn) bit is set to 1 and the Decrement Enable Bit (DCEN) is 0, a 1-to-0
transition on the TnEX pin (configured as an input in the digital crossbar) will cause a timer reload (in addition to timer overflows causing auto-reloads). When DCEN is set to 1, the state of the TnEX pin controls
whether the counter/timer counts up (increments) or down (decrements), and will not cause an auto-reload
or interrupt event. See Section 23.2.1 for information concerning configuration of a timer to count down.
When counting down, the counter/timer will set its overflow/underflow flag (TFn) and cause an interrupt (if
enabled) when the value in the timer (TMRnH and TMRnL registers) matches the 16-bit value in the
Reload/Capture Registers (RCAPnH and RCAPnL). This is considered an underflow event, and will cause
the timer to load the value 0xFFFF. The timer is automatically restarted when an underflow occurs.
Counter/Timer with Auto-Reload mode is selected by clearing the CP/RLn bit. Setting TRn to logic 1
enables and starts the timer.
In Auto-Reload Mode, the External Flag (EXFn) toggles upon every overflow or underflow and does not
cause an interrupt. The EXFn flag can be thought of as the most significant bit (MSB) of a 17-bit counter.
TMRnCF
D
T T T T
E
n nO n
C
MMGO
E
1 0 n E
N
Toggle Logic
2
12
SYSCLK
External Clock
(XTAL1)
0xFF
TMRnL
TMRnH
RCAPnL
RCAPnH
1
TCLK
Crossbar
TRn
EXENn
Reload
TnE
X
Tn
(Port Pin)
Crossbar
OVF
TMRnCN
Tn
0xFF
CP/RLn
C/Tn
TRn
EXENn
EXFn
TFn
Interrupt
Rev. 1.4
299
C8051F040/1/2/3/4/5/6/7
23.2.4. Toggle Output Mode
Timer n have the capability to toggle the state of their respective output port pins (T2, T3, or T4) to produce
a 50% duty cycle waveform output. The port pin state will change upon the overflow or underflow of the
respective timer (depending on whether the timer is counting up or down). The toggle frequency is determined by the clock source of the timer and the values loaded into RCAPnH and RCAPnL. When counting
DOWN, the auto-reload value for the timer is 0xFFFF, and underflow will occur when the value in the timer
matches the value stored in RCAPnH:RCAPnL. When counting UP, the auto-reload value for the timer is
RCAPnH:RCAPnL, and overflow will occur when the value in the timer transitions from 0xFFFF to the
reload value.
To output a square wave, the timer is placed in reload mode (the Capture/Reload Select Bit in TMRnCN
and the Timer/Counter Select Bit in TMRnCN are cleared to 0). The timer output is enabled by setting the
Timer Output Enable Bit in TMRnCF to 1. The timer should be configured via the timer clock source and
reload/underflow values such that the timer overflow/underflows at 1/2 the desired output frequency. The
port pin assigned by the crossbar as the timers output pin should be configured as a digital output (see
Section 17. Port Input/Output on page 205). Setting the timers Run Bit (TRn) to 1 will start the toggle
of the pin. A Read/Write of the Timers Toggle Output State Bit (TMRnCF.2) is used to read the state of the
toggle output, or to force a value of the output. This is useful when it is desired to start the toggle of a pin in
a known state, or to force the pin into a desired state when the toggle mode is halted.
F TCLK
F sq = -----------------------------------------------------2 ( 65536 RCAPn )
Equation 23.1. Square Wave Frequency
Equation 23.1 applies regardless of whether the timer is configured to count up or down.
300
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.8. TMRnCN: Timer n Control
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
TFn
EXFn
EXENn
TRn
C/Tn
CP/RLn
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit
Addressable
Bit7:
Bit6:
Bit5-4:
Bit3:
Bit2:
Bit1:
Bit0:
Rev. 1.4
301
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.9. TMRnCF: Timer n Configuration
R/W
R/W
R/W
R/W
R/W
Reset Value
TnM1
TnM0
TOGn
TnOE
DCEN
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit
Addressable
Bit7-5:
Bit4-3:
Bit2:
Bit1:
Bit0:
302
Reserved.
TnM1 and TnM0: Timer Clock Mode Select Bits.
Bits used to select the Timer clock source. The sources can be the System Clock
(SYSCLK), SYSCLK divided by 2 or 12, or an external clock signal routed to Tn (port pin)
divided by 8. Clock source is selected as follows:
00: SYSCLK/12
01: SYSCLK
10: EXTERNAL CLOCK/8
11: SYSCLK/2
TOGn: Toggle output state bit.
When timer is used to toggle a port pin, this bit can be used to read the state of the output, or
can be written to in order to force the state of the output.
TnOE: Timer output enable bit.
This bit enables the timer to output a 50% duty cycle output to the timers assigned external
port pin.
NOTE: A timer is configured for Square Wave Output as follows:
CP/RLn = 0
C/Tn = 0
TnOE = 1
Load RCAPnH:RCAPnL (See Section Equation 23.1. Square Wave Frequency on
page 300).
Configure Port Pin for output (See Section 17. Port Input/Output on page 205).
0: Output of toggle mode not available at Timers assigned port pin.
1: Output of toggle mode available at Timers assigned port pin.
DCEN: Decrement Enable Bit.
This bit enables the timer to count up or down as determined by the state of TnEX.
0: Timer will count up, regardless of the state of TnEX.
1: Timer will count up or down depending on the state of TnEX as follows:
if TnEX = 0, the timer counts DOWN
if TnEX = 1, the timer counts UP.
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.10. RCAPnL: Timer n Capture Register Low Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: RCAP2L: 0xCA; RCAP3L: 0xCA; RCAP4L: 0xCA
SFR Page: RCAP2L: page 0; RCAP3L: page 1; RCAP4L: page 2
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: RCAP2H: 0xCB; RCAP3H: 0xCB; RCAP4H: 0xCB
SFR Page: RCAP2H: page 0; RCAP3H: page 1; RCAP4H: page 2
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
Rev. 1.4
303
C8051F040/1/2/3/4/5/6/7
SFR Definition 23.13. TMRnH Timer n High Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: TMR2H: 0xCD; TMR3H: 0xCD; TMR4H: 0xCD
SFR Page: TMR2H: page 0; TMR3H: page 1; TMR4H: page 2
304
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
24. Programmable Counter Array
The Programmable Counter Array (PCA0) provides enhanced timer functionality while requiring less CPU
intervention than the standard 8051 counter/timers. PCA0 consists of a dedicated 16-bit counter/timer and
six 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 206). 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 Output, Frequency
Output, 8-Bit PWM, or 16-Bit PWM (each is described in Section 24.2). The PCA is configured and controlled through the system controller's Special Function Registers. The basic PCA block diagram is shown
in Figure 24.1.
SYSCLK/12
SYSCLK/4
Timer 0 Overflow
ECI
SYSCLK
PCA
CLOCK
MUX
16-Bit Counter/Timer
External Clock/8
Capture/Compare
Module 0
Capture/Compare
Module 1
Capture/Compare
Module 2
Capture/Compare
Module 3
Capture/Compare
Module 4
Capture/Compare
Module 5
CEX5
CEX4
CEX3
CEX2
CEX1
CEX0
ECI
Crossbar
Port I/O
Rev. 1.4
305
C8051F040/1/2/3/4/5/6/7
24.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 24.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 globally 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.
CPS1
0
0
1
1
0
0
CPS0
0
1
0
1
0
1
Timebase
System clock divided by 12
System clock divided by 4
Timer 0 overflow
High-to-low transitions on ECI1 (max rate = system clock divided by 4)
System clock
External clock divided by 82
Notes:
1. The minimum high or low time for the ECI input signal is at least 2 system clock cycles.
2. External oscillator source divided by 8 is synchronized with the system clock.
IDLE
PCA0MD
CWW
I D D
D T L
L E C
K
C
P
S
2
C
P
S
1
CE
PC
S F
0
PCA0CN
CCC
FRC
F
5
C
C
F
4
C
C
F
3
C
C
F
2
C
C
F
1
C
C
F
0
To SFR Bus
PCA0L
read
Snapshot
Register
SYSCLK/12
SYSCLK/4
Timer 0 Overflow
ECI
SYSCLK
External Clock/8
000
001
010
011
PCA0H
PCA0L
Overflow
100
101
To PCA Modules
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
24.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 Modulator. Each module has Special Function Registers (SFRs) associated with it in the CIP51 system controller. These registers are used to exchange data with a module and configure the module's
mode of operation.
Table 24.2 summarizes the bit settings in the PCA0CPMn registers used to select the PCA0 capture/compare modules 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 24.3 for details on the PCA interrupt configuration.
TOG
PWM ECCF
1
0
0
0
0
0
0
1
1
0
0
0
0
0
1
1
0
0
0
0
0
1
1
1
X
X
X
X
0
0
X
X
X
X
0
1
X
1
1
0
1
0
1
0
1
0
1
0
X = Dont Care
Operation Mode
Capture triggered by positive edge on
CEXn
Capture triggered by negative edge on
CEXn
Capture triggered by transition on CEXn
Software Timer
High Speed Output
Frequency Output
8-Bit Pulse Width Modulator
16-Bit Pulse Width Modulator
(for n = 0 to 5)
PCA0CPMn
P EC
WCA
MOP
1 MP
6 n n
n
C
A
P
N
n
MT P
AOW
TGM
n n n
PCA0CN
E
C
C
F
n
CCC
FRC
F
5
C
C
F
4
C
C
F
3
C
C
F
2
C
C
F
1
PCA0MD
C
C
F
0
C
I
D
L
C
P
S
2
C
P
S
1
CE
PC
S F
0
PCA Counter/
Timer Overflow
ECCF0
EPCA0
(EIE1.3)
PCA Module 0
CCF0
EA
(IE.7)
0
1
Interrupt
Priority
Decoder
ECCF1
0
PCA Module 1
CCF1
ECCF2
0
PCA Module 2
CCF2
ECCF3
0
PCA Module 3
CCF3
ECCF4
0
PCA Module 4
CCF4
ECCF5
PCA Module 5
CCF5
0
1
Rev. 1.4
307
C8051F040/1/2/3/4/5/6/7
24.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 vectors to the interrupt service routine, and
must be cleared by software.
Note: The signal at the CEXn pin must be logic high or low for at least two system clock cycles in order for
it to be recognized as valid by the hardware.
PCA Interrupt
PCA0CPMn
Port I/O
Crossbar
CEXn
PCA0CN
CCCCCCCC
FRCCCCCC
FFFFFF
5 4 3 2 1 0
(to CCFn)
P ECCMT P E
WC A A AOWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
PCA0CPLn
PCA0CPHn
Capture
0
1
PCA
Timebase
308
Rev. 1.4
PCA0L
PCA0H
C8051F040/1/2/3/4/5/6/7
24.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'.
Write to
PCA0CPLn
0
ENB
Reset
Write to
PCA0CPHn
PCA
Interrupt
ENB
PCA0CPMn
PCA0CN
P ECCMT P E
WC A A AOWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
x
0 0
PCA0CPLn
CCCCCCCC
FRCCCCCC
FFFFFF
5 4 3 2 1 0
PCA0CPHn
0 0 x
Enable
16-bit Comparator
PCA
Timebase
PCA0L
Match
0
1
PCA0H
Rev. 1.4
309
C8051F040/1/2/3/4/5/6/7
24.2.3. High Speed Output Mode
In High Speed Output mode, a modules 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 HighSpeed 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'.
Write to
PCA0CPLn
0
ENB
Reset
Write to
PCA0CPHn
PCA0CPMn
P ECCMT P E
WC A A A OWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
ENB
0 0
PCA
Interrupt
0 x
PCA0CN
PCA0CPLn
Enable
CCCCCCCC
FRCCCCCC
FFFFFF
5 4 3 2 1 0
PCA0CPHn
Match
16-bit Comparator
Toggle
PCA
Timebase
TOGn
0 CEXn
1
PCA0L
Crossbar
PCA0H
310
Rev. 1.4
Port I/O
C8051F040/1/2/3/4/5/6/7
24.2.4. Frequency Output Mode
Frequency Output Mode produces a programmable-frequency square wave on the modules 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 24.1, where FPCA is the frequency of the clock selected by the CPS2-0 bits in the PCA mode register, PCA0MD.
PCA0CPMn
P ECCMT P E
WC A A AOWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
0
0 0 0 1
PCA0CPLn
8-bit Adder
Adder
Enable
Toggle
0
Enable
PCA Timebase
8-bit
Comparator
match
PCA0CPHn
TOGn
0 CEXn
1
Crossbar
Port I/O
PCA0L
Rev. 1.4
311
C8051F040/1/2/3/4/5/6/7
24.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 high. When the count value in PCA0L overflows, the CEXn output will be
low (see Figure 24.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 24.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'.
PCA0CPHn
PCA0CPMn
P ECCMT P E
WC A A AOWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
0
0 0 0 0
PCA0CPLn
0
Enable
8-bit
Comparator
match
R
PCA Timebase
PCA0L
SET
CLR
CEXn
Crossbar
Overflow
312
Rev. 1.4
Port I/O
C8051F040/1/2/3/4/5/6/7
24.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 varying 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 24.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'.
PCA0CPMn
P ECCMT P E
WC A A AOWC
MOPP TGMC
1 MP N n n n F
6 n n n
n
n
1
0 0 0 0
PCA0CPHn
PCA0CPLn
0
Enable
match
16-bit Comparator
S
R
PCA Timebase
PCA0H
PCA0L
SET
CLR
CEXn
Crossbar
Port I/O
Overflow
Rev. 1.4
313
C8051F040/1/2/3/4/5/6/7
24.3. Register Descriptions for PCA0
Following are detailed descriptions of the special function registers related to the operation of PCA0.
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
CF
CR
CCF5
CCF4
CCF3
CCF2
CCF1
CCF0
00000000
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xD8
SFR Page: 0
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
314
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 24.2. PCA0MD: PCA0 Mode
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
00000000
CIDL
CPS2
CPS1
CPS0
ECF
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
SFR Address: 0xD9
SFR Page: 0
Bit7:
Bits6-4:
Bits3-1:
CPS1
0
0
1
CPS0
0
1
0
1
1
1
1
0
0
1
1
0
1
0
1
Timebase
System clock divided by 12
System clock divided by 4
Timer 0 overflow
High-to-low transitions on ECI1 (max rate = system clock
divided by 4)
System clock
External clock divided by 82
Reserved
Reserved
Notes:
1. The minimum high or low time for the ECI input signal is at least 2 system clock cycles.
2. External oscillator source divided by 8 is synchronized with the system clock.
Bit0:
Rev. 1.4
315
C8051F040/1/2/3/4/5/6/7
SFR Definition 24.3. PCA0CPMn: PCA0 Capture/Compare Mode
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:
SFR Page:
Bit7:
Bit6:
Bit5:
Bit4:
Bit3:
Bit2:
Bit1:
Bit0:
316
PCA0CPM0: 0xDA, PCA0CPM1: 0xDB, PCA0CPM2: 0xDC, PCA0CPM3: 0xDD, PCA0CPM4: 0xDE, PCA0CPM5:
0xDF
PCA0CPM0: page 0, PCA0CPM1: page 0, PCA0CPM2: page 0, PCA0CPM3: page 0, PCA0CPM4: page 0,
PCA0CPM5: page 0
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
SFR Definition 24.4. PCA0L: PCA0 Counter/Timer Low Byte
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xF9
SFR Page: 0
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address: 0xFA
SFR Page: 0
Rev. 1.4
317
C8051F040/1/2/3/4/5/6/7
SFR Definition 24.6. 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
PCA0CPL0: 0xFB, PCA0CPL1: 0xFD, PCA0CPL2: 0xE9, PCA0CPL3: 0xEB, PCA0CPL4: 0xED, PCA0CPL5:
SFR Address:
0xE1
SFR Page:
Bits7-0:
PCA0CPL0: page 0, PCA0CPL1: page 0, PCA0CPL2: page 0, PCA0CPL3: page 0, PCA0CPL4: page 0,
PCA0CPL5: page 0
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Reset Value
00000000
SFR Address:
SFR Page:
Bits7-0:
318
PCA0CPH0: 0xFC, PCA0CPH1: 0xFD, PCA0CPH2: 0xEA, PCA0CPH3: 0xEC, PCA0CPH4: 0xEE, PCA0CPH5:
0xE2
PCA0CPH0: page 0, PCA0CPH1: page 0, PCA0CPH2: page 0, PCA0CPH3: page 0, PCA0CPH4: page 0,
PCA0CPH5: page 0
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
25. 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 25.1 can
be commanded. There are three DRs associated with JTAG Boundary-Scan, and four associated with
Flash read/write operations on the MCU.
0x0000
Bit15
Bit0
IR Value
Instruction
0x0000
EXTEST
0x0002
SAMPLE/
PRELOAD
0x0004
IDCODE
0xFFFF
BYPASS
0x0082
0x0083
0x0084
Description
Selects the Boundary Data Register for control and observability of all
device pins
Selects the Boundary Data Register for observability and presetting the
scan-path latches
Flash Control Selects FLASHCON Register to control how the interface logic responds
to reads and writes to the FLASHDAT Register
Flash Data
Selects FLASHDAT Register for reads and writes to the Flash memory
Flash Address Selects FLASHADR Register which holds the address of all Flash read,
write, and erase operations
Rev. 1.4
319
C8051F040/1/2/3/4/5/6/7
25.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.
320
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
Table 25.1. Boundary Data Register Bit Definitions (Continued)
EXTEST provides access to both capture and update actions, while Sample only performs a capture.
Bit
Action Target
75, 77, 79, 81, 83, Capture P4.n input from pin
85, 87, 89
Update P4.n output to pin
90, 92, 94, 96, 98, Capture P5.n output enable from MCU
100, 102, 104
Update P5.n output enable to pin
91, 93, 95, 97, 99, Capture P5.n input from pin
101, 103, 105
Update P5.n output to pin
106, 108, 110, 112, Capture P6.n output enable from MCU
114, 116, 118, 120 Update P6.n output enable to pin
107, 109, 111, 113, Capture P6.n input from pin
115, 117, 119, 121 Update P6.n output to pin
122, 124, 126, 128, Capture P7.n output enable from MCU
130, 132, 134, 136 Update P7.n output enable to pin
123, 125, 127, 129, Capture P7.n input from pin
131, 133, 135, 137 Update P7.n output to pin
Rev. 1.4
321
C8051F040/1/2/3/4/5/6/7
JTAG Register Definition 25.2. DEVICEID: JTAG Device ID Register
Reset Value
Version
Bit31
Part Number
Bit28 Bit27
Manufacturer ID
Bit12 Bit11
Version = 0000b
Part Number = 0000 0000 0000 0101b (C8051F040/1/2/3/4/5/6/7)
Manufacturer ID = 0010 0100 001b (Silicon Labs)
322
Rev. 1.4
1
Bit1
Bit0
0xn0005243
C8051F040/1/2/3/4/5/6/7
25.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
0x
10
11
Operation
Poll
Read
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
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 initiate. 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).
Rev. 1.4
323
C8051F040/1/2/3/4/5/6/7
JTAG Register Definition 25.3. FLASHCON: JTAG Flash Control Register
Reset Value
SFLE
WRMD2
WRMD1
WRMD0
RDMD3
RDMD2
RDMD1
RDMD0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
00000000
This register determines how the Flash interface logic will respond to reads and writes to the
FLASHDAT Register.
Bit 7:
Bits6-4:
Bits3-0:
324
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
JTAG Register Definition 25.4. FLASHDAT: JTAG Flash Data
Reset Value
0000000000
Bit9
Bit0
This register is used to read or write data to the Flash memory across the JTAG interface.
Bits9-2:
Bit1:
Bit0:
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.
Rev. 1.4
325
C8051F040/1/2/3/4/5/6/7
25.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 C8051F040DK 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 C8051F04x family. Each kit includes an Integrated Development Environment (IDE) which has a debugger and integrated 8051 assembler. The kit
also includes a JTAG interface module referred to as the Serial Adapter. There is also a target application
board with a C8051F040 installed. The required cables and wall-mount power supply are also included.
326
Rev. 1.4
C8051F040/1/2/3/4/5/6/7
DOCUMENT CHANGE LIST
Revision 1.3 to Revision 1.4
Rev. 1.4
327
C8051F040/1/2/3/4/5/6/7
CONTACT INFORMATION
Silicon Laboratories Inc.
4635 Boston Lane
Austin, TX 78735
Tel: 1+(512) 416-8500
Fax: 1+(512) 416-9669
Toll Free: 1+(877) 444-3032
Email: mcuinfo@silabs.com
Internet: www.silabs.com
The information in this document is believed to be accurate in all respects at the time of publication but is subject to change without
notice. Silicon Laboratories assumes no responsibility for errors and omissions, and disclaims responsibility for any consequences
resulting from the use of information included herein. Additionally, Silicon Laboratories assumes no responsibility for the functioning of undescribed features or parameters. Silicon Laboratories reserves the right to make changes without further notice. Silicon
Laboratories makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose,
nor does Silicon Laboratories assume any liability arising out of the application or use of any product or circuit, and specifically
disclaims any and all liability, including without limitation consequential or incidental damages. Silicon Laboratories products are
not designed, intended, or authorized for use in applications intended to support or sustain life, or for any other application in which
the failure of the Silicon Laboratories product could create a situation where personal injury or death may occur. Should Buyer
purchase or use Silicon Laboratories products for any such unintended or unauthorized application, Buyer shall indemnify and
hold Silicon Laboratories harmless against all claims and damages.
Silicon Laboratories and Silicon Labs are trademarks of Silicon Laboratories Inc.
Other products or brandnames mentioned herein are trademarks or registered trademarks of their respective holder.
328
Rev. 1.4