|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
mixed signal isp flash mcu family c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 preliminary rev. 1.4 12/05 copyright ? 200 5 by silicon laboratories c8051f12x c8051f13x analog peripherals - 10 or 12-bit sar adc ? 1 lsb inl ? programmable throughput up to 100 ksps ? up to 8 external inputs; programmable as single- ended or differential ? programmable amplifier gain: 16, 8, 4, 2, 1, 0.5 ? data-dependent windowed interrupt generator ? built-in temperature sensor - 8-bit sar adc (?f12x only) ? programmable throughput up to 500 ksps ? 8 external inputs (single-ended or differential) ? programmable amplifier gain: 4, 2, 1, 0.5 - two 12-bit dacs (?f12x only) ? can synchronize outputs to timers for jitter-free wave- form generation - two analog comparators - voltage reference - v dd monitor/brown-out detector on-chip jtag debug & boundary scan - on-chip debug circuitry facilitates full-speed, non- intrusive in-circuit/in-system debugging - provides breakpoints, single-stepping, watchpoints, stack monitor; inspect/modi fy memory and registers - superior performance to emulation systems using ice-chips, target pods, and sockets - ieee1149.1 compli ant boundary scan - complete development kit 100-pin tqfp or 64-pin tqfp packaging - temperature range: ?40 to +85 c - rohs available high speed 8051 c core - pipelined instruction architecture; executes 70% of instruction set in 1 or 2 system clocks - 100 mips or 50 mips throughput with on-chip pll - 2-cycle 16 x 16 mac engine (c8051f120/1/2/3 and c8051f130/1/2/3 only) memory - 8448 bytes internal data ram (8 k + 256) - 128 or 64 kb banked flash; in-system programma- ble in 1024-byte sectors - external 64 kb data memory interface (programma- ble multiplexed or non-multiplexed modes) digital peripherals - 8 byte-wide port i/o (100tqfp); 5 v tolerant - 4 byte-wide port i/o (64tqfp); 5 v tolerant - hardware smbus? (i2c? co mpatible), spi?, and two uart serial ports available concurrently - programmable 16-bit coun ter/timer array with 6 capture/compare modules - 5 general purpose 16-bit counter/timers - dedicated watchdog timer; bi-directional reset pin clock sources - internal precision oscillator: 24.5 mhz - flexible pll technology - external oscillator: crystal, rc, c, or clock voltage supples - range: 2.7?3.6 v (50 mips) 3.0?3.6 v (100 mips) - power saving sleep and shutdown modes jtag 128/64 kb isp flash 8448 b sram 16 x 16 mac ('f120/1/2/3, 'f13x) + - 10/12-bit 100ksps adc clock / pll circuit pga vref 12-bit dac temp sensor voltage comparators analog peripherals port 0 port 1 port 2 port 3 crossbar digital i/o high-speed controller core debug circuitry 20 interrupts 8051 cpu (50 or 100mips) 12-bit dac + - 8-bit 500ksps adc port 4 port 5 port 6 port 7 external memory interface 100 pin 64 pin pga uart0 smbus spi bus pca timer 0 timer 1 timer 2 timer 3 timer 4 uart1 amux amux c8051f12x only
c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 2 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 3 table of contents 1. system overview............ ............................................................................. ........... 19 1.1. cip-51? microcontroller core.. ............................................................. ........... 27 1.1.1. fully 8051 compatible...... ............................................................. ........... 27 1.1.2. improved throughput ............ ........................................................ ........... 27 1.1.3. additional features .......... ............................................................. ........... 28 1.2. on-chip memory......... ........................................................................... ........... 29 1.3. jtag debug and boundary scan.. ........................................................ ........... 30 1.4. 16 x 16 mac (multiply and a ccumulate) engine............... ............ ........... ......... 31 1.5. programmable digital i/o and crossbar ............... ................................. ........... 32 1.6. programmable counter array ... ............................................................. ........... 33 1.7. serial ports ............ ................................................................................ ........... 33 1.8. 12 or 10-bit analog to digital converter ...... .......................................... ........... 34 1.9. 8-bit analog to digital conv erter............... ............................................. ........... 35 1.10.12-bit digital to analog conv erters.............. .......................................... ........... 36 1.11.analog comparators... ........................................................................... ........... 37 2. absolute maximum ratings ........ ............................................................... ........... 38 3. global dc electrical characteristi cs ...................... ................................. ............. 39 4. pinout and package definitions..... ............... ............................................. ........... 41 5. adc0 (12-bit adc, c8051f120/1/4/5 only)...... .......................................... ........... 55 5.1. analog multiplexer and pga..... ............................................................. ........... 55 5.2. adc modes of operation........ ............................................................... ........... 57 5.2.1. starting a conversion....... ............................................................. ........... 57 5.2.2. tracking modes................ ............................................................. ........... 58 5.2.3. settling time r equirements ................ .......................................... ........... 59 5.3. adc0 programmable window de tector ............... ................................. ........... 66 6. adc0 (10-bit adc, c8051f122/3/6/7 and c8051f13x only )................................ 73 6.1. analog multiplexer and pga..... ............................................................. ........... 73 6.2. adc modes of operation........ ............................................................... ........... 75 6.2.1. starting a conversion....... ............................................................. ........... 75 6.2.2. tracking modes................ ............................................................. ........... 76 6.2.3. settling time r equirements ................ .......................................... ........... 77 6.3. adc0 programmable window de tector ............... ................................. ........... 84 7. adc2 (8-bit adc, c8051f12x 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 r equirements ................ .......................................... ........... 94 7.3. adc2 programmable window de tector ............... ................................. ......... 100 7.3.1. window detector in sing le-ended mode .......... ............................ ......... 100 7.3.2. window detector in differential mode..... .............. ............... .................. 101 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 4 rev. 1.4 8. dacs, 12-bit voltage mode (c8051f12x only) ... .............. ............... .................. 105 8.1. dac output scheduling ......................................................................... ......... 105 8.1.1. update output on-demand .. ........................................................ ......... 106 8.1.2. update output based on timer overflow ............. ............... .................. 106 8.2. dac output scaling/justificat ion ................. .......................................... ......... 106 9. voltage reference .......... ............................................................................. ......... 113 9.1. reference configuration on the c8051f120/2/4/6 ............. ................. ........... 113 9.2. reference configuration on the c8051f121/3/5/7 ............. ................. ........... 115 9.3. reference configuration on the c8051f130/1/2/3 ............. ................. ........... 117 10. comparators ................ ................................................................................ ......... 119 11. cip-51 microcontroller .............. .................................................................. ......... 127 11.1.instruction set........... ............................................................................. ......... 129 11.1.1.instruction and cpu timing .. ........................................................ ......... 129 11.1.2.movx instruction and pr ogram memory .......... ............................ ......... 129 11.2.memory organization ............. ............................................................... ......... 133 11.2.1.program memory .... ...................................................................... ......... 133 11.2.2.data memory........ ......................................................................... ......... 135 11.2.3.general purpose registers ........................................................... ......... 135 11.2.4.bit addressable locations.. ........................................................... ......... 135 11.2.5.stack ............ ................................................................................ ......... 135 11.2.6.special function register s ........................................................... ......... 136 11.2.7.register description s ................ .................................................. ........... 151 11.3.interrupt handler....... ............................................................................. ......... 154 11.3.1.mcu interrupt sources and vectors ....... .............. ............... .................. 154 11.3.2.external interrupts.......... ............................................................... ......... 155 11.3.3.interrupt priorities........ .................................................................. ......... 156 11.3.4.interrupt latency .............. ............................................................. ......... 156 11.3.5.interrupt register descriptions............ .......................................... ......... 157 11.4.power management modes........ ........................................................... ......... 163 11.4.1.idle mode ........... ........................................................................... ......... 163 11.4.2.stop mode............ ......................................................................... ......... 164 12. multiply and accumulate (mac0) ............... ............................................... ......... 165 12.1.special function registers..... ............................................................... ......... 165 12.2.integer and fractional math.... ............................................................... ......... 166 12.3.operating in multiply and accumulate mode .. ................................................ 167 12.4.operating in multiply only mode ........................................................... ......... 167 12.5.accumulator shift operations.. ............... ............................................... ......... 167 12.6.rounding and saturation.......... ............................................................. ......... 168 12.7.usage examples .......... ......................................................................... ......... 168 12.7.1.multiply and accumulate example ............... ................................. ......... 168 12.7.2.multiply only example...... ............................................................. ......... 169 12.7.3.mac0 accumulator shift example ............... ................................. ......... 169 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 5 13. reset sources.......... .................................................................................. ........... 177 13.1.power-on reset........ ............................................................................. ......... 178 13.2.power-fail reset ....... ............................................................................. ......... 178 13.3.external reset .......... ............................................................................. ......... 179 13.4.missing clock detector reset ... ............... ............................................. ......... 179 13.5.comparator0 reset ............. .................................................................. ......... 179 13.6.external cnvstr0 pin reset ... ............... ............................................. ......... 179 13.7.watchdog timer reset.... ...................................................................... ......... 179 13.7.1.enable/reset wdt ............ ........................................................... ......... 180 13.7.2.disable wdt ........... ...................................................................... ......... 180 13.7.3.disable wdt lockout ............... .................................................. ........... 180 13.7.4.setting wdt interval ........ ............................................................. ......... 180 14. oscillators ................ .................................................................................. ........... 185 14.1.internal calibrated oscillator .......................................................................... 185 14.2.external oscillator drive circuit................ ............................................. ......... 187 14.3.system clock selectio n......................................................................... ......... 187 14.4.external crystal example .... .................................................................. ......... 190 14.5.external rc example .......... .................................................................. ......... 190 14.6.external capacitor example ... ............................................................... ......... 190 14.7.phase-locked loop (pll).......... ........................................................... ......... 191 14.7.1.pll input clock and pre-divi der ................................................... ......... 191 14.7.2.pll multiplication and ou tput clock ............ ................................. ......... 191 14.7.3.powering on and initializing the pll .............. ............................... ......... 192 15. flash memory ................. ............................................................................. ......... 199 15.1.programming the flash memory ........................................................... ......... 199 15.1.1.non-volatile data storage . ............... ............................................. ......... 200 15.1.2.erasing flash pages from software ........... ................................. ......... 201 15.1.3.writing flash memory from software.......... ................................. ......... 202 15.2.security options ....... ............................................................................. ......... 203 15.2.1.summary of flash security options............. ................................. ......... 207 16. branch target cache .............. .................................................................. ........... 211 16.1.cache and prefetch operation . ............................................................. ......... 211 16.2.cache and prefetch optimizati on................ .......................................... ......... 212 17. external data memory interface and on-chi p xram............ ................. ........... 219 17.1.accessing xram.......... ......................................................................... ......... 219 17.1.1.16-bit movx example ....... ........................................................... ......... 219 17.1.2.8-bit movx example ......... ........................................................... ......... 219 17.2.configuring the exte rnal memory interface . .......................................... ......... 219 17.3.port selection and c onfiguration.......... ................................................. ......... 220 17.4.multiplexed and non-multiplex ed selection.......... ................................. ......... 222 17.4.1.multiplexed configuration. ............................................................. ......... 222 17.4.2.non-multiplexed configurat ion.............. ................................................. 223 17.5.memory mode selection...... .................................................................. ......... 224 17.5.1.internal xram only ......... ............................................................. ......... 224 17.5.2.split mode without bank select............. ................................................. 224 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 6 rev. 1.4 17.5.3.split mode with ba nk select................ .......................................... ......... 225 17.5.4.external only...... ........................................................................... ......... 225 17.6.emif timing ............. ............................................................................. ......... 225 17.6.1.non-multiplexed mode ....... ........................................................... ......... 227 17.6.2.multiplexed mode .... ...................................................................... ......... 230 18. port input/output............ ............................................................................. ......... 235 18.1.ports 0 through 3 and the priority crossbar decoder.... ............... .................. 238 18.1.1.crossbar pin assignment and allocation .......... ............................ ......... 238 18.1.2.configuring the output mo des of the port pins........ ............ .................. 239 18.1.3.configuring port pins as digital inputs....... ................................. ........... 240 18.1.4.weak pullups .......... ...................................................................... ......... 240 18.1.5.configuring port 1 pins as analog inputs ................ ............ .................. 240 18.1.6.external memory interface pin assignm ents ............. ................. ........... 241 18.1.7.crossbar pin assignment example.............. ................................. ......... 243 18.2.ports 4 through 7 (100-pin tq fp devices only) ............... ............ .................. 252 18.2.1.configuring ports which are not pinned out .. ............................... ......... 252 18.2.2.configuring the output mo des of the port pins........ ............ .................. 252 18.2.3.configuring port pins as digital inputs....... ................................. ........... 253 18.2.4.weak pullups .......... ...................................................................... ......... 253 18.2.5.external memory interfac e ............................................................ ......... 253 19. system management bus / i2c bus (smbus0) .................... ............ .................. 259 19.1.supporting documents ............. ............................................................. ......... 260 19.2.smbus protocol........ ............................................................................. ......... 260 19.2.1.arbitration......... ............................................................................. ......... 261 19.2.2.clock low extension........ ............................................................. ......... 261 19.2.3.scl low timeout.... ...................................................................... ......... 261 19.2.4.scl high (smbus free) ti meout .............. ................................. ........... 261 19.3.smbus transfer modes... ...................................................................... ......... 262 19.3.1.master transmitter mode .. ............... ............................................. ......... 262 19.3.2.master receiver mode .............. .................................................. ........... 262 19.3.3.slave transmitter mode .... ............... ............................................. ......... 263 19.3.4.slave receiver mode ....... ............................................................. ......... 263 19.4.smbus special function regist ers ................................................................ 264 19.4.1.control register ... ......................................................................... ......... 264 19.4.2.clock rate register ......... ............................................................. ......... 267 19.4.3.data register ....... ......................................................................... ......... 268 19.4.4.address register..... ...................................................................... ......... 268 19.4.5.status register............ .................................................................. ......... 269 20. enhanced serial peripheral interface (spi0)..... ................................................. 273 20.1.signal descriptions....... ......................................................................... ......... 274 20.1.1.master out, slave in (mos i)...................... ................................. ........... 274 20.1.2.master in, slave out (miso)............... .......................................... ......... 274 20.1.3.serial clock (sck) ........... ............................................................. ......... 274 20.1.4.slave select (nss) .......... ............................................................. ......... 274 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 7 20.2.spi0 master mode operation . ............................................................... ......... 275 20.3.spi0 slave mode operation ..... ............................................................. ......... 277 20.4.spi0 interrupt sources ........ .................................................................. ......... 277 20.5.serial clock timing... ............................................................................. ......... 278 20.6.spi special function registers . ............... ............................................. ......... 280 21. uart0................ ........................................................................................... ......... 287 21.1.uart0 operational modes ...... ............................................................. ......... 288 21.1.1.mode 0: synchronous mode .. ................. .............. ............... .................. 288 21.1.2.mode 1: 8-bit uart, variable baud rate.. ................................. ........... 289 21.1.3.mode 2: 9-bit uart, fix ed baud rate .......... ............................... ......... 291 21.1.4.mode 3: 9-bit uart, variable baud rate.. ................................. ........... 292 21.2.multiprocessor communications ... ........................................................ ......... 293 21.2.1.configuration of a mask ed address ............. ................................. ......... 293 21.2.2.broadcast addressing ............... .................................................. ........... 293 21.3.frame and transmission error detection........ .............. ............... .................. 294 22. uart1................ ........................................................................................... ......... 299 22.1.enhanced baud rate g eneration.................. ................................................. 300 22.2.operational modes ....... ......................................................................... ......... 301 22.2.1.8-bit uart ........... ......................................................................... ......... 301 22.2.2.9-bit uart ........... ......................................................................... ......... 302 22.3.multiprocessor communications ... ........................................................ ......... 303 23. timers................ ............................................................ ............... .............. ........... 30 9 23.1.timer 0 and ti mer 1 ............... ............................................................... ......... 309 23.1.1.mode 0: 13-bit counter/timer ................. .............. ............... .................. 309 23.1.2.mode 1: 16-bit counter/timer ................. .............. ............... .................. 311 23.1.3.mode 2: 8-bit counter/tim er with auto-reload.......... ................. ........... 311 23.1.4.mode 3: two 8-bit counter /timers (timer 0 only)..... ................. ........... 312 23.2.timer 2, timer 3, and timer 4 .... ........................................................... ......... 317 23.2.1.configuring timer 2, 3, and 4 to count down............ ................. ........... 317 23.2.2.capture mode ......... ...................................................................... ......... 318 23.2.3.auto-reload mode .... .................................................................. ........... 319 23.2.4.toggle output mode (timer 2 and time r 4 only) ................ .................. 320 24. programmable counter array ....... ............................................................. ......... 325 24.1.pca counter/timer ............. .................................................................. ......... 326 24.2.capture/compare modules ...... ............................................................. ......... 328 24.2.1.edge-triggered captur e mode ................. .............. ............... .................. 329 24.2.2.software timer (compare) mode................. ................................. ......... 330 24.2.3.high speed output mode.............................................................. ......... 331 24.2.4.frequency output mode ....... ........................................................ ......... 332 24.2.5.8-bit pulse width modulato r mode............... ................................. ......... 333 24.2.6.16-bit pulse width modulat or mode............. ................................. ......... 334 24.3.register descriptions for pca0 ............................................................. ......... 335 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 8 rev. 1.4 25. jtag (ieee 1149.1) ........ ............................................................................. ......... 341 25.1.boundary scan ............. ......................................................................... ......... 342 25.1.1.extest instruction.......... ............................................................. ......... 343 25.1.2.sample instruction ......... ............................................................. ......... 343 25.1.3.bypass instruction ......... ............................................................. ......... 343 25.1.4.idcode instruction.......... ............................................................. ......... 343 25.2.flash programming commands.... ........................................................ ......... 344 25.3.debug support ........... ........................................................................... ......... 347 document change list............... ...................................................................... ........ 349 contact information.......... ................................................................................ ........ 350 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 9 list of figures 1. system overview figure 1.1. c8051f120/124 bl ock diagram ............ .............. ............... ........... ......... 21 figure 1.2. c8051f121/125 bl ock diagram ............ .............. ............... ........... ......... 22 figure 1.3. c8051f122/126 bl ock diagram ............ .............. ............... ........... ......... 23 figure 1.4. c8051f123/127 bl ock diagram ............ .............. ............... ........... ......... 24 figure 1.5. c8051f130/132 bl ock diagram ............ .............. ............... ........... ......... 25 figure 1.6. c8051f131/133 bl ock diagram ............ .............. ............... ........... ......... 26 figure 1.7. on-board clo ck and reset ............... .......................................... ........... 28 figure 1.8. on-chip memory map..... ............... ............................................. ........... 29 figure 1.9. development/in-system debug diagram................. ................. ............. 30 figure 1.10. mac0 block diagram .... ............... ............................................. ........... 31 figure 1.11. digital crossbar diagr am ................ .......................................... ........... 32 figure 1.12. pca block diagram...... ............................................................. ........... 33 figure 1.13. 12-bit adc block diagram ........................................................ ........... 34 figure 1.14. 8-bit adc diagram....... ............................................................. ........... 35 figure 1.15. dac system block diagr am ............... .............. ............... ........... ......... 36 figure 1.16. comparator bl ock diagram ............... .......................................... ......... 37 2. absolute maximum ratings 3. global dc electrical characteristics 4. pinout and package definitions figure 4.1. c8051f120/2/4/ 6 pinout diagram (tqfp-100) ..... ............ ........... ......... 49 figure 4.2. c8051f130/2 pinout diagram (tqfp-100) ............. ................. ............. 50 figure 4.3. tqfp-100 package drawin g ................ .............. ............... ........... ......... 51 figure 4.4. c8051f121/3/5/ 7 pinout diagram (tqfp-64) ....... ............ ........... ......... 52 figure 4.5. c8051f131/3 pinout di agram (tqfp-64) ............... ................. ............. 53 figure 4.6. tqfp-64 package drawing . ................. .............. ............... ........... ......... 54 5. adc0 (12-bit adc, c8051f120/1/4/5 only) figure 5.1. 12-bit adc0 functional block diagram .............. ............... ........... ......... 55 figure 5.2. typical temperature sensor transfer function....... ................. ............. 56 figure 5.3. adc0 track and conversion example timing......... ................. ............. 58 figure 5.4. adc0 equivalent input circuits......... .......................................... ........... 59 figure 5.5. adc0 data word exam ple ............... .......................................... ........... 65 figure 5.6. 12-bit adc0 wind ow interrupt example: right justified single- ended data ............. ................................. ........... 68 figure 5.7. 12-bit adc0 wind ow interrupt example: right justified differential da ta ................... ............................... ........... 69 figure 5.8. 12-bit adc0 wind ow interrupt example: left justified single- ended data ............... ................................. ........... 70 figure 5.9. 12-bit adc0 wind ow interrupt example: left justified different ial data............... .............. ............... ........... ......... 71 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 10 rev. 1.4 6. adc0 (10-bit adc, c8051f122/3/6/7 and c8051f13x only) figure 6.1. 10-bit adc0 functional block diagram .............. ............... ........... ......... 73 figure 6.2. typical temperature sensor transfer function....... ................. ............. 74 figure 6.3. adc0 track and conversion example timing......... ................. ............. 76 figure 6.4. adc0 equivalent input circuits......... .......................................... ........... 77 figure 6.5. adc0 data word exam ple ............... .......................................... ........... 83 figure 6.6. 10-bit adc0 wind ow interrupt example: right justified single- ended data ............. ................................. ........... 86 figure 6.7. 10-bit adc0 wind ow interrupt example: right justified differential da ta ................... ............................... ........... 87 figure 6.8. 10-bit adc0 wind ow interrupt example: left justified single- ended data ............... ................................. ........... 88 figure 6.9. 10-bit adc0 wind ow interrupt example: left justified different ial data............... .............. ............... ........... ......... 89 7. adc2 (8-bit adc, c8051f12x only) figure 7.1. adc2 functional block diagram........... .............. ............... ........... ......... 91 figure 7.2. adc2 track and conversion example timing......... ................. ............. 93 figure 7.3. adc2 equivalent input circuit........... .......................................... ........... 94 figure 7.4. adc2 data word exam ple ............... .......................................... ........... 99 figure 7.5. adc2 window compare examples , single-ended mode.... ................ 100 figure 7.6. adc2 window compar e examples, differential mode ........................ 101 8. dacs, 12-bit voltage mode (c8051f12x only) figure 8.1. dac functional block diagram............. .............. ............... .................. 105 9. voltage reference figure 9.1. voltage referenc e functional block diagram (c8051f120/2/4/6) ...... 114 figure 9.2. voltage referenc e functional block diagram (c8051f121/3/5/7) ...... 115 figure 9.3. voltage referenc e functional block diagram (c8051f130/1/2/3) ...... 117 10. comparators figure 10.1. comparator functiona l block diagram ...... ............................... ......... 119 figure 10.2. comparator hysteresis plot ............ .......................................... ......... 121 11. cip-51 microcontroller figure 11.1. cip-51 block diagram.. ............... ............................................. ......... 128 figure 11.2. memory map .............. ............................................................... ......... 133 figure 11.3. address memory m ap for instruction fetches (128 kb flash only)... 134 figure 11.4. sfr page stack... ................. .................................................. ........... 137 figure 11.5. sfr page stack wh ile using sfr page 0x0f to access port 5...... 138 figure 11.6. sfr page stack af ter adc2 window comparator interrupt occurs . 139 figure 11.7. sfr page stack upon pca inte rrupt occurring during an adc2 isr 140 figure 11.8. sfr page sta ck upon return from pca interr upt ........................... 140 figure 11.9. sfr page stack u pon return from adc2 window interrupt ........... 141 12. multiply and accumulate (mac0) figure 12.1. mac0 block diagram .... ............... ............................................. ......... 165 figure 12.2. integer mode da ta representation ................. ................................... 166 figure 12.3. fractional m ode data representation. .............. ............... .................. 166 figure 12.4. mac0 pipeline.. ......................................................................... ......... 167 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 11 13. reset sources figure 13.1. reset sources............ ............................................................... ......... 177 figure 13.2. reset timing .............. ............................................................... ......... 178 14. oscillators figure 14.1. oscillator diagram...... ............................................................... ......... 185 figure 14.2. pll block diagram....... ............................................................. ......... 191 15. flash memory figure 15.1. flash memory map for movc read and movx write operations ... 201 figure 15.2. 128 kb flash memory map and security bytes ..... ................. ........... 204 figure 15.3. 64 kb flash memory map and security bytes ................. .................. 205 16. branch target cache figure 16.1. branch target cache data flow ......... .............. ............... .................. 211 figure 16.2. branch target cache organiztion....... .............. ............... .................. 212 figure 16.3. cache lock operation........... .................................................. ........... 214 17. external data memory interface and on-chip xram figure 17.1. multiplexed configurat ion example.......... ................................. ......... 222 figure 17.2. non-multiplexed conf iguration example .............. ............ .................. 223 figure 17.3. emif operati ng modes .............. ............................................... ......... 224 figure 17.4. non-multiplexed 16-bi t movx timing ...... ................................. ......... 227 figure 17.5. non-multiplexed 8-bi t movx without bank select timing ................. 228 figure 17.6. non-multiplexed 8-bi t movx with bank select ti ming ...................... 229 figure 17.7. multiplexed 16-bit mo vx timing.............. ................................. ......... 230 figure 17.8. multiplexed 8-bit mo vx without bank select timi ng .............. ........... 231 figure 17.9. multiplexed 8-bit mo vx with bank select timing ............ .................. 232 18. port input/output figure 18.1. port i/o cell block diagram ...................................................... ......... 235 figure 18.2. port i/o func tional block diagram ...... .............. ............... .................. 237 figure 18.3. priority crossbar decode table (emifle = 0; p1mdin = 0xff)....... 238 figure 18.4. priority cr ossbar decode table (emifle = 1; emif in mu ltiplexed mode; p1mdin = 0xff) ................ 241 figure 18.5. priority cr ossbar decode table (emifle = 1; emif in non-multiple xed mode; p1mdin = 0xff) ........ 242 figure 18.6. crossbar example........ ............................................................. ......... 244 19. system management bus / i2c bus (smbus0) figure 19.1. smbus0 block diagram . ........................................................... ......... 259 figure 19.2. typical smbus configur ation ............................................................. 260 figure 19.3. smbus transaction ...... ............................................................. ......... 261 figure 19.4. typical mast er transmitter sequence............... ............... .................. 262 figure 19.5. typical master receiver sequence................... ............... .................. 262 figure 19.6. typical slave transmi tter sequence........ ................................. ......... 263 figure 19.7. typical slave receiver sequence....... .............. ............... .................. 263 20. enhanced serial peripheral interface (spi0) figure 20.1. spi block diagram ................ .................................................. ........... 273 figure 20.2. multiple-master mo de connection diagram .. ............................ ......... 276 figure 20.3. 3-wire single ma ster and slave mode connectio n diagram ............. 276 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 12 rev. 1.4 figure 20.4. 4-wire single ma ster and slave mode connectio n diagram ............. 276 figure 20.5. master mode data/clo ck timing .............. ................................. ......... 278 figure 20.6. slave mode data/clock timing (ckpha = 0) ...... ............ .................. 279 figure 20.7. slave mode data/clock timing (ckpha = 1) ...... ............ .................. 279 figure 20.8. spi mast er timing (ckpha = 0)..... .......................................... ......... 283 figure 20.9. spi mast er timing (ckpha = 1)..... .......................................... ......... 283 figure 20.10. spi slave timing (ckpha = 0)............ ................................. ........... 284 figure 20.11. spi slave timing (ckpha = 1)............ ................................. ........... 284 21. uart0 figure 21.1. uart0 block di agram ............... ............................................... ......... 287 figure 21.2. uart0 mode 0 timing diagram ............ ................................. ........... 288 figure 21.3. uart0 mode 0 in terconnect............... .............. ............... .................. 288 figure 21.4. uart0 mode 1 timing diagram ........ .............. ............... .................. 289 figure 21.5. uart0 modes 2 and 3 timing diagram .............. ............ .................. 291 figure 21.6. uart0 modes 1, 2, and 3 interconnect diagram ............ .................. 292 figure 21.7. uart multi-processor mode inte rconnect diagram ........ .................. 294 22. uart1 figure 22.1. uart1 block di agram ............... ............................................... ......... 299 figure 22.2. uart1 baud ra te logic ............ ............................................... ......... 300 figure 22.3. uart interconnect diagr am ............... .............. ............... .................. 301 figure 22.4. 8-bit uart timing diagram........... .......................................... ......... 301 figure 22.5. 9-bit uart timing diagr am................ .............. ............... .................. 302 figure 22.6. uart multi-processor mode inte rconnect diagram ........ .................. 303 23. timers figure 23.1. t0 mode 0 block diagram ................. ................................................. 310 figure 23.2. t0 mode 2 block diagram ................. ................................................. 311 figure 23.3. t0 mode 3 block diagram ................. ................................................. 312 figure 23.4. t2, 3, and 4 captur e mode block diagram ... ............................ ......... 318 figure 23.5. tn auto-reload (t2,3,4) and toggle mode (t2,4) bl ock diagram ..... 319 24. programmable counter array figure 24.1. pca block diagram...... ............................................................. ......... 325 figure 24.2. pca counter/timer bl ock diagram.......... ................................. ......... 326 figure 24.3. pca interrupt block di agram .............. .............. ............... .................. 328 figure 24.4. pca capture m ode diagram............... .............. ............... .................. 329 figure 24.5. pca software timer mode diagram .......... ............................... ......... 330 figure 24.6. pca high speed output mode diagram.. ................................. ......... 331 figure 24.7. pca frequency ou tput mode ............. .............. ............... .................. 332 figure 24.8. pca 8-bit pwm mode di agram .............................................. ........... 333 figure 24.9. pca 16-bit pwm mode..... ........................................................ ......... 334 25. jtag (ieee 1149.1) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 13 list of tables 1. system overview table 1.1. product selection guide ............... ............................................... ........... 20 2. absolute maximum ratings table 2.1. absolute maximum ratings ............... .......................................... ........... 38 3. global dc electrical characteristics table 3.1. global dc electr ical characteristics (c8051f120/1/2/3 and c8051f130/1/ 2/3) .......... ............... ........... ......... 39 table 3.2. global dc electrical characteristics (c8051f124/5 /6/7) .......... ............. 40 4. pinout and package definitions table 4.1. pin definitions .......... .................................................................. ............. 41 5. adc0 (12-bit adc, c8051f120/1/4/5 only) table 5.1. 12-bit adc0 electrical characteri stics (c8051f120/1/4/5) ........... ......... 72 6. adc0 (10-bit adc, c8051f122/3/6/7 and c8051f13x only) table 6.1. 10-bit adc0 elec trical characteristics (c8051f122/3/6/7 and c8051f13x) ............ ............................... ........... 90 7. adc2 (8-bit adc, c8051f12x only) table 7.1. adc2 electrical characteristics ......... .......................................... ......... 103 8. dacs, 12-bit voltage mode (c8051f12x only) table 8.1. dac electrical characte ristics ........... .......................................... ......... 111 9. voltage reference table 9.1. voltage reference electrical characte ristics ......... ............ .................. 118 10. comparators table 10.1. comparator electrical characteristics .... ................................. ........... 126 11. cip-51 microcontroller table 11.1. cip-51 instruction se t summary .............. ................................. ......... 129 table 11.2. special function regi ster (sfr) memory map ...... ................. ........... 144 table 11.3. special function regist ers .............. .......................................... ......... 146 table 11.4. interrupt summary ...... ............................................................... ......... 155 12. multiply and accumulate (mac0) table 12.1. mac0 rounding (mac0sat = 0) ............... ............................... ......... 168 13. reset sources table 13.1. reset electrical charac teristics .............. ................................. ........... 183 14. oscillators table 14.1. oscillator electrical characteristics ..... .............. ............... .................. 185 table 14.2. pll frequency characteri stics ........... .............. ............... .................. 195 table 14.3. pll lock timing characte ristics .............. ................................. ......... 196 15. flash memory table 15.1. flash electrical characteristics ....... .......................................... ......... 200 16. branch target cache 17. external data memory interface and on-chip xram table 17.1. ac parameters for ex ternal memory interface ..... ............ .................. 233 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 14 rev. 1.4 18. port input/output table 18.1. port i/o dc electrical characteristics ..... ................................. ........... 236 19. system management bus / i2c bus (smbus0) table 19.1. smb0sta status codes and states ... .............. ............... .................. 270 20. enhanced serial peripheral interface (spi0) table 20.1. spi slave timing parame ters ........... ................................................. 285 21. uart0 table 21.1. uart0 modes .............. ............................................................. ......... 288 table 21.2. oscillator frequencie s for standard baud rates ... ................. ........... 295 22. uart1 table 22.1. timer settings for standard baud rates using the internal 24.5 mhz oscillator ..... ................................. ......... 305 table 22.2. timer settings for standard baud rates using an external 25.0 mhz o scillator ........... ............................ ......... 306 table 22.3. timer settings for standard baud rates using an external 22.1184 mhz oscillator ................................. ......... 306 table 22.4. timer settings for standard baud rates using the pll .. .................. 307 table 22.5. timer settings for standard baud rates using the pll .. .................. 307 23. timers 24. programmable counter array table 24.1. pca timebase input opti ons .............. .............. ............... .................. 326 table 24.2. pca0cpm register settings for pca captur e/compare modules .... 329 25. jtag (ieee 1149.1) table 25.1. boundary data register bit definitions .... ................................. ......... 342 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 15 list of registers sfr definition 5.1. amx0cf: amux0 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 60 sfr definition 5.2. amx0sl: amux0 channel select . . . . . . . . . . . . . . . . . . . . . . . . 61 sfr definition 5.3. adc0cf: adc0 c onfiguration . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 sfr definition 5.4. adc0cn: adc0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 sfr definition 5.5. adc0h: adc0 da ta word msb . . . . . . . . . . . . . . . . . . . . . . . . . . 64 sfr definition 5.6. adc0l: adc0 data word lsb . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 sfr definition 5.7. adc0gth: a dc0 greater-than data high byte . . . . . . . . . . . . . 66 sfr definition 5.8. adc0gtl: ad c0 greater-than data low byte . . . . . . . . . . . . . . 66 sfr definition 5.9. adc0lth: ad c0 less-than data high byte . . . . . . . . . . . . . . . . 67 sfr definition 5.10. adc0ltl: ad c0 less-than data low byte . . . . . . . . . . . . . . . 67 sfr definition 6.1. amx0cf: amux0 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 78 sfr definition 6.2. amx0sl: amux0 channel select . . . . . . . . . . . . . . . . . . . . . . . . . 79 sfr definition 6.3. adc0cf: adc0 c onfiguration . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 sfr definition 6.4. adc0cn: adc0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 sfr definition 6.5. adc0h: adc0 da ta word msb . . . . . . . . . . . . . . . . . . . . . . . . . . 82 sfr definition 6.6. adc0l: adc0 data word lsb . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 sfr definition 6.7. adc0gth: a dc0 greater-than data high byte . . . . . . . . . . . . . 84 sfr definition 6.8. adc0gtl: ad c0 greater-than data low byte . . . . . . . . . . . . . . 84 sfr definition 6.9. adc0lth: ad c0 less-than data high byte . . . . . . . . . . . . . . . . 85 sfr definition 6.10. adc0ltl: ad c0 less-than data low byte . . . . . . . . . . . . . . . 85 sfr definition 7.1. amx2cf: amux2 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 95 sfr definition 7.2. amx2sl: amux2 channel select . . . . . . . . . . . . . . . . . . . . . . . . 96 sfr definition 7.3. adc2cf: adc2 c onfiguration . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 byte . . . . . . . . . . . . . . . . . . 102 sfr definition 7.7. adc2lt : adc2 less-than data byte . . . . . . . . . . . . . . . . . . . . 102 sfr definition 8.1. dac0h: dac0 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 sfr definition 8.2. dac0l: dac0 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 sfr definition 8.3. dac0cn: dac0 c ontr ol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 sfr definition 8.4. dac1h: dac1 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 sfr definition 8.5. dac1l: dac1 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 sfr definition 8.6. dac1cn: dac1 c ontrol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 sfr definition 9.1. ref0cn: re ference control (c8051f120/2/4/6) . . . . . . . . . . . . 114 sfr definition 9.2. ref0cn: re ference control (c8051f121/3/5/7) . . . . . . . . . . . . 116 sfr definition 9.3. ref0cn: re ference control (c8051f130/1/2/3) . . . . . . . . . . . . 117 sfr definition 10.1. cpt0cn : comparator0 control . . . . . . . . . . . . . . . . . . . . . . . . . 122 sfr definition 10.2. cpt0md: com parator0 mode selection . . . . . . . . . . . . . . . . . 123 sfr definition 10.3. cpt1cn : comparator1 control . . . . . . . . . . . . . . . . . . . . . . . . . 124 sfr definition 10.4. cpt1md: com parator1 mode selectio n . . . . . . . . . . . . . . . . . 125 sfr definition 11.1. psbank: program space bank se lect . . . . . . . . . . . . . . . . . . 134 sfr definition 11.2. sfrpgcn: sfr page control . . . . . . . . . . . . . . . . . . . . . . . . . 142 sfr definition 11.3. sfrpage: sfr pa ge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 16 rev. 1.4 sfr definition 11.4. sfrnext: sfr ne xt register . . . . . . . . . . . . . . . . . . . . . . . . . 143 sfr definition 11.5. sfrlast: sfr la st register . . . . . . . . . . . . . . . . . . . . . . . . . 143 sfr definition 11.6. sp: stack pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 sfr definition 11.7. dpl: data poin ter low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 sfr definition 11.8. dph: data poin ter high byte . . . . . . . . . . . . . . . . . . . . . . . . . . 151 sfr definition 11.9. psw: program st atus word . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 sfr definition 11.10. acc: a ccumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 sfr definition 11.11. b: b regi ster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 sfr definition 11.12. ie: interrupt enabl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 sfr definition 11.13. ip: interrupt prio rity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 sfr definition 11.14. eie1: extended interrupt enable 1 . . . . . . . . . . . . . . . . . . . . . 159 sfr definition 11.15. eie2: extended interrupt enable 2 . . . . . . . . . . . . . . . . . . . . . 160 sfr definition 11.16. eip1: extended interrupt priority 1 . . . . . . . . . . . . . . . . . . . . . 161 sfr definition 11.17. eip2: extended interrupt priority 2 . . . . . . . . . . . . . . . . . . . . . 162 sfr definition 11.18. pcon: power control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 sfr definition 12.1. mac0cf: mac0 configuration . . . . . . . . . . . . . . . . . . . . . . . . . 170 sfr definition 12.2. mac0sta: mac0 status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 sfr definition 12.3. mac0ah: mac0 a high byte . . . . . . . . . . . . . . . . . . . . . . . . . . 171 sfr definition 12.4. mac0al: mac0 a low byte . . . . . . . . . . . . . . . . . . . . . . . . . . 172 sfr definition 12.5. mac0bh: mac0 b high byte . . . . . . . . . . . . . . . . . . . . . . . . . . 172 sfr definition 12.6. mac0bl: mac0 b low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 sfr definition 12.7. mac0 acc3: mac0 accumulator byte 3 . . . . . . . . . . . . . . . . . . 173 sfr definition 12.8. mac0 acc2: mac0 accumulator byte 2 . . . . . . . . . . . . . . . . . 173 sfr definition 12.9. mac0 acc1: mac0 accumulator byte 1 . . . . . . . . . . . . . . . . . 173 sfr definition 12.10. mac0 acc0: mac0 accumulator byte 0 . . . . . . . . . . . . . . . . . 174 sfr definition 12.11. mac0 ovr: mac0 accumulator overflow . . . . . . . . . . . . . . . . 174 sfr definition 12.12. mac0rndh: mac0 rounding register hig h byte . . . . . . . . . 174 sfr definition 12.13. mac0rndl: mac0 rounding register low byte . . . . . . . . . 175 sfr definition 13.1. wdtcn: watch dog timer control . . . . . . . . . . . . . . . . . . . . . . 181 sfr definition 13.2. rstsrc: reset source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 sfr definition 14.1. oscicl: intern al oscillator calibration. . . . . . . . . . . . . . . . . . . 186 sfr definition 14.2. oscicn: inter nal oscillator control . . . . . . . . . . . . . . . . . . . . . 186 sfr definition 14.3. clksel: system clock selection . . . . . . . . . . . . . . . . . . . . . . . 188 sfr definition 14.4. oscxcn: exter nal oscillator control . . . . . . . . . . . . . . . . . . . . 189 sfr definition 14.5. pll0cn: pll control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 sfr definition 14.6. pll0div: pll pre- divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 sfr definition 14.7. pll0mul: pll cl ock scaler . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 sfr definition 14.8. pll0flt: pll filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 sfr definition 15.1. flacl: flash access limit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 sfr definition 15.2. flscl: flash memory control . . . . . . . . . . . . . . . . . . . . . . . . . 208 sfr definition 15.3. psctl: prog ram store read/write control . . . . . . . . . . . . . . . 209 sfr definition 16.1. cch0cn : cache control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 sfr definition 16.2. cch0tn : cache tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 sfr definition 16.3. cch0lc: cache lock control . . . . . . . . . . . . . . . . . . . . . . . . . 216 sfr definition 16.4. cch0ma: cac he miss accumulator . . . . . . . . . . . . . . . . . . . . . 217 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 17 sfr definition 16.5. flstat: flash stat us . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 sfr definition 17.1. emi0 cn: external memory interface cont rol . . . . . . . . . . . . . . 220 sfr definition 17.2. emi0cf: exter nal memory configuration . . . . . . . . . . . . . . . . . 221 sfr definition 17.3. emi0tc: exte rnal memory timing control . . . . . . . . . . . . . . . . 226 sfr definition 18.1. xbr0: port i/o crossbar regist er 0 . . . . . . . . . . . . . . . . . . . . . 245 sfr definition 18.2. xbr1: port i/o crossbar regist er 1 . . . . . . . . . . . . . . . . . . . . . 246 sfr definition 18.3. xbr2: port i/o crossbar regist er 2 . . . . . . . . . . . . . . . . . . . . . 247 sfr definition 18.4. p0: port0 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 sfr definition 18.5. p0mdout: port 0 output mode . . . . . . . . . . . . . . . . . . . . . . . . . 248 sfr definition 18.6. p1: port1 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 sfr definition 18.7. p1mdin : port1 input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 sfr definition 18.8. p1mdout: port 1 output mode . . . . . . . . . . . . . . . . . . . . . . . . . 250 sfr definition 18.9. p2: port2 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 sfr definition 18.10. p2mdout: port 2 output mode . . . . . . . . . . . . . . . . . . . . . . . 251 sfr definition 18.11. p3: port3 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 sfr definition 18.12. p3mdout: port 3 output mode . . . . . . . . . . . . . . . . . . . . . . . 252 sfr definition 18.13. p4: port4 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 sfr definition 18.14. p4mdout: port 4 output mode . . . . . . . . . . . . . . . . . . . . . . . . 254 sfr definition 18.15. p5: port5 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 sfr definition 18.16. p5 mdout: port5 output mode . . . . . . . . . . . . . . . . . . . . . . . 255 sfr definition 18.17. p6: port6 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 sfr definition 18.18. p6mdout: port 6 output mode . . . . . . . . . . . . . . . . . . . . . . . . 256 sfr definition 18.19. p7: port7 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 sfr definition 18.20. p7mdout: port 7 output mode . . . . . . . . . . . . . . . . . . . . . . . 257 sfr definition 19.1. smb0cn : smbus0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 sfr definition 19.2. smb0cr: smbus0 clock rate . . . . . . . . . . . . . . . . . . . . . . . . . 267 sfr definition 19.3. smb0dat: smbus0 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 sfr definition 19.4. smb0adr: smbu s0 address . . . . . . . . . . . . . . . . . . . . . . . . . . 269 sfr definition 19.5. smb0sta: smbus0 status . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 sfr definition 20.1. spi0cf g: spi0 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 280 sfr definition 20.2. spi0cn: spi0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 sfr definition 20.3. spi0ck r: spi0 clock rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 sfr definition 20.4. spi0dat: spi0 data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 sfr definition 21.1. scon0: uart0 control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 sfr definition 21.2. ssta0: uart 0 status and clock selection . . . . . . . . . . . . . . . 297 sfr definition 21.3. sbuf0: uart0 da ta buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 sfr definition 21.4. saddr0: uart0 slave address . . . . . . . . . . . . . . . . . . . . . . . 298 sfr definition 21.5. sade n0: uart0 slave address enable . . . . . . . . . . . . . . . . . 298 sfr definition 22.1. scon1: serial port 1 control . . . . . . . . . . . . . . . . . . . . . . . . . . 304 sfr definition 22.2. sbuf1: serial (uart1) port data buffer . . . . . . . . . . . . . . . . . 305 sfr definition 23.1. tcon: timer cont rol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 sfr definition 23.2. tmod: ti mer mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 sfr definition 23.3. ckcon: clock c ontrol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 sfr definition 23.4. tl0: timer 0 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 sfr definition 23.5. tl1: timer 1 low byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 18 rev. 1.4 sfr definition 23.6. th0: timer 0 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 sfr definition 23.7. th1: timer 1 hi gh byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 sfr definition 23.8. tmrncn: timer 2, 3, and 4 control . . . . . . . . . . . . . . . . . . . . . 321 sfr definition 23.9. tmrncf: time r 2, 3, and 4 confi guration . . . . . . . . . . . . . . . . 322 sfr definition 23.10. rcapnl: ti mer 2, 3, and 4 capture regist er low byte . . . . . 323 sfr definition 23.11. rcapnh: ti mer 2, 3, and 4 capture regi ster high byte . . . . 323 sfr definition 23.12. tmrnl: timer 2, 3, and 4 low byte . . . . . . . . . . . . . . . . . . . . 323 sfr definition 23.13. tmrnh time r 2, 3, and 4 high byte . . . . . . . . . . . . . . . . . . . 324 sfr definition 24.1. pca0cn: pca control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 sfr definition 24.2. pca0md: pca0 mo de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 sfr definition 24.3. pca0cpmn: pca0 capture/compare mode . . . . . . . . . . . . . . 337 sfr definition 24.4. pca0l: pca0 counter/timer low byte . . . . . . . . . . . . . . . . . . 338 sfr definition 24.5. pca0h: pca0 counter/timer high byte . . . . . . . . . . . . . . . . . . 338 sfr definition 24.6. pca0cpln: pc a0 capture module low byte . . . . . . . . . . . . . . 338 sfr definition 24.7. pca0cphn: pc a0 capture module high byte . . . . . . . . . . . . 339 jtag register definition 25.1. ir: jtag instructio n register . . . . . . . . . . . . . . . . . . 341 jtag register definition 25.2. deviceid: jtag devi ce id . . . . . . . . . . . . . . . . . . . 343 jtag register definiti on 25.3. flashcon: jtag flash control . . . . . . . . . . . . . . . 345 jtag register definition 25.4. flashdat: jtag flash data . . . . . . . . . . . . . . . . . 346 jtag register definiti on 25.5. flashadr: jtag flash addres s . . . . . . . . . . . . . . 346 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 19 1. system overview the c8051f12x and c8051f13x devi ce families are fully integrated mixed-sig nal system-on-a-chip mcus with 64 digital i/o pins (100-pin tqfp) or 32 digital i/o pins (64-pin tqfp). highlighted features are listed below. refer to table 1.1 for specific product feature selection. ? high-speed pipelined 8051-compatible cip-51 microcontroller core (100 mips or 50 mips) ? in-system, full-speed, non-intrusive debug interface (on-chip) ? true 12 or 10-bit 100 ksps adc with pga and 8-channel analog multiplexer ? true 8-bit 500 ksps adc with pga and 8-channel analog multiplexer (c8051f12x family) ? two 12-bit dacs with programmable update scheduling (c8051f12x family) ? 2-cycle 16 by 16 multiply and accumulate engine (c8051f120/1/2/3 and c8051f130/1/2/3) ? 128 or 64 kb of in-system programmable flash memory ? 8448 (8 k + 256) bytes of on-chip ram ? external data memory interface with 64 kb address space ? spi, smbus/i2c, and (2) uart serial interfaces implemented in hardware ? five general purpose 16-bit timers ? programmable counter/timer array with 6 capture/compare modules ? on-chip watchdog timer, v dd monitor, and temperature sensor with on-chip v dd monitor, watchdog timer, and clock osci llator, the c8051f12x and c8051f13x devices are truly stand-alone system-on-a-chip solutions. a ll 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 resource s), full speed, in-circuit debugging using the production mcu installed in the fina l application. this debug system supports inspec- tion and modification of memory and registers, settin g 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 operation over the industr ial temperature range (?45 to +85 c). the port i/o, rst , and jtag pins are tolerant for input signals up to 5 v. the devices are available in 100-pin tqfp or 64-pin tqfp packaging. table 1.1 lists the specific device features and package offerings for each part number. figure 1.1 through figure 1.6 show fu nctional block diagrams for each device. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 20 rev. 1.4 table 1.1. product selection guide ordering part number mips (peak) flash memory ram 2-cycle 16 by 16 mac external memory interface smbus/i2c spi uarts timers (16-bit) programmable counter array digital port i/o?s 12-bit 100ksps adc inputs 10-bit 100ksps adc inputs 8-bit 500ksps adc inputs voltage reference temperature sensor dac resolution (bits) dac outputs analog comparators lead-free (rohs compliant) package c8051f120 100 128 k 8448 ???? 25 ? 64 8 - 8 ?? 12 2 2 - 100tqfp c8051f120-gq 100 128 k 8448 ???? 25 ? 64 8 - 8 ?? 12 2 2 ? 100tqfp c8051f121 100 128 k 8448 ???? 25 ? 32 8 - 8 ?? 12 2 2 - 64tqfp c8051f121-gq 100 128 k 8448 ???? 25 ? 32 8 - 8 ?? 12 2 2 ? 64tqfp c8051f122 100 128 k 8448 ???? 25 ? 64 - 8 8 ?? 12 2 2 - 100tqfp c8051f122-gq 100 128 k 8448 ???? 25 ? 64 - 8 8 ?? 12 2 2 ? 100tqfp c8051f123 100 128 k 8448 ???? 25 ? 32 - 8 8 ?? 12 2 2 - 64tqfp c8051f123-gq 100 128 k 8448 ???? 25 ? 32 - 8 8 ?? 12 2 2 ? 64tqfp c8051f124 50 128 k 8448 - ??? 25 ? 64 8 - 8 ?? 12 2 2 - 100tqfp c8051f124-gq 50 128 k 8448 - ??? 25 ? 64 8 - 8 ?? 12 2 2 ? 100tqfp c8051f125 50 128 k 8448 - ??? 25 ? 32 8 - 8 ?? 12 2 2 - 64tqfp c8051f125-gq 50 128 k 8448 - ??? 25 ? 32 8 - 8 ?? 12 2 2 ? 64tqfp c8051f126 50 128 k 8448 - ??? 25 ? 64 - 8 8 ?? 12 2 2 - 100tqfp c8051f126-gq 50 128 k 8448 - ??? 25 ? 64 - 8 8 ?? 12 2 2 ? 100tqfp c8051f127 50 128 k 8448 - ??? 25 ? 32 - 8 8 ?? 12 2 2 - 64tqfp c8051f127-gq 50 128 k 8448 - ??? 25 ? 32 - 8 8 ?? 12 2 2 ? 64tqfp c8051f130 100 128 k 8448 ???? 25 ? 64 - 8 - ?? - - 2 - 100tqfp c8051f130-gq 100 128 k 8448 ???? 25 ? 64 - 8 - ?? --2 ? 100tqfp c8051f131 100 128 k 8448 ???? 25 ? 32 - 8 - ?? - - 2 - 64tqfp C8051F131-GQ 100 128 k 8448 ???? 25 ? 32 - 8 - ?? --2 ? 64tqfp c8051f132 100 64 k 8448 ???? 25 ? 64 - 8 - ?? - - 2 - 100tqfp c8051f132-gq 100 64 k 8448 ???? 25 ? 64 - 8 - ?? --2 ? 100tqfp c8051f133 100 64 k 8448 ???? 25 ? 32 - 8 - ?? - - 2 - 64tqfp c8051f133-gq 100 64 k 8448 ???? 25 ? 32 - 8 - ?? --2 ? 64tqfp c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 21 figure 1.1. c8051f120/124 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca 128 kb flash 256 byte ram vdd monitor sfr bus 8 0 5 1 c o r e timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ av+ vdd vdd vdd dgnd dgnd dgnd agnd agnd reset rst xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator digital power analog power debug hw boundary scan 8 kb xram p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control dac1 dac1 (12-bit) vref dac0 (12-bit) adc 100 ksps (12-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 dac0 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv 8:1 monen wdt vrefd vref0 prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7.0/d0 p7.7/d7 p7 drv p5.0/a8 p5.7/a15 p5 drv p6.0/a0 p6.7/a7 p6 drv p4 drv p4.5/ale p4.6/rd p4.7/wr p4.0 p4.4 prog gain adc 500 ksps (8-bit) a m u x vref2 pll circuitry external data memory bus 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 22 rev. 1.4 figure 1.2. c8051f121/125 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca vdd monitor timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ vdd vdd vdd dgnd dgnd dgnd agnd reset rst digital power analog power debug hw boundary scan p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control dac1 dac1 (12-bit) vref dac0 (12-bit) adc 100 ksps (12-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 dac0 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv 8:1 monen wdt vrefa prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7 drv p5 drv p6 drv p4 drv prog gain adc 500 ksps (8-bit) a m u x vrefa av+ xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator pll circuitry 128 kb flash 256 byte ram sfr bus 8 0 5 1 c o r e 8 kb xram external data memory bus 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 23 figure 1.3. c8051f122/126 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca vdd monitor timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ av+ vdd vdd vdd dgnd dgnd dgnd agnd agnd reset rst digital power analog power debug hw boundary scan p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control dac1 dac1 (12-bit) vref dac0 (12-bit) adc 100 ksps (10-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 dac0 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv 8:1 monen wdt vrefd vref0 prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7.0/d0 p7.7/d7 p7 drv p5.0/a8 p5.7/a15 p5 drv p6.0/a0 p6.7/a7 p6 drv p4 drv p4.5/ale p4.6/rd p4.7/wr p4.0 p4.4 prog gain adc 500 ksps (8-bit) a m u x vref2 xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator pll circuitry 128 kb flash 256 byte ram sfr bus 8 0 5 1 c o r e 8 kb xram external data memory bus 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 24 rev. 1.4 figure 1.4. c8051f123/127 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca vdd monitor timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ vdd vdd vdd dgnd dgnd dgnd agnd reset rst digital power analog power debug hw boundary scan p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control dac1 dac1 (12-bit) vref dac0 (12-bit) adc 100 ksps (10-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 dac0 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv 8:1 monen wdt vrefa prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7 drv p5 drv p6 drv p4 drv prog gain adc 500 ksps (8-bit) a m u x vrefa av+ xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator pll circuitry 128 kb flash 256 byte ram sfr bus 8 0 5 1 c o r e 8 kb xram external data memory bus 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 25 figure 1.5. c8051f130/132 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca vdd monitor timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ av+ vdd vdd vdd dgnd dgnd dgnd agnd agnd reset rst digital power analog power debug hw boundary scan p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control vref adc 100ksps (10-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv monen wdt vref0 prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7.0/d0 p7.7/d7 p7 drv p5.0/a8 p5.7/a15 p5 drv p6.0/a0 p6.7/a7 p6 drv p4 drv p4.5/ale p4.6/rd p4.7/wr p4.0 p4.4 xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator pll circuitry flash 128kbyte (?f130) 64kbyte (?f132) 256 byte ram sfr bus 8 0 5 1 c o r e 8kbyte xram external data memory bus 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 26 rev. 1.4 figure 1.6. c8051f131/133 block diagram p0, p1, p2, p3 latches jtag logic tck tms tdi tdo uart1 smbus spi bus pca vdd monitor timers 0, 1, 2, 4 timer 3/ rtc p0 drv c r o s s b a r port i/o config. crossbar config. av+ vdd vdd vdd dgnd dgnd dgnd agnd reset rst digital power analog power debug hw boundary scan p2.0 p2.7 p1.0/ain2.0 p1.7/ain2.7 p0.0 p0.7 p1 drv p2 drv data bus address bus bus control vref adc 100ksps (10-bit) a m u x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 cp0+ cp0- cp1+ cp1- vref temp sensor uart0 p3.0 p3.7 p3 drv monen wdt vref0 prog gain cp0 cp1 c t l p4 latch d a t a p7 latch a d d r p5 latch p6 latch p7 drv p5 drv p6 drv p4 drv xtal1 xtal2 external oscillator circuit system clock calibrated internal oscillator pll circuitry 256 byte ram sfr bus 8 0 5 1 c o r e 8kbyte xram external data memory bus flash 128kbyte (?f131) 64kbyte (?f133) 64x4 byte cache c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 27 1.1. cip-51? microcontroller core 1.1.1. fully 8051 compatible the c8051f12x and c8051f13x utilize silicon labs? proprietary cip- 51 microcontroller core. 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 core has all the peripherals included with a standard 8052, including five 16-bit counter/timers, two full-duplex uarts, 256 bytes of internal ram, 128 byt e special function regis- ter (sfr) address space, and 8/4 byte-wide i/o ports. 1.1.2. improved throughput the cip-51 employs a pipelined architecture that grea tly increases its instruction throughput over the stan- dard 8051 architecture. in a standa rd 8051, all instructions except for mul and div take 12 or 24 system clock cycles to execute with a maximum system clock of 12-to-24 mhz. by contrast, the cip-51 core exe- cutes 70% of its instructions in one or two system cloc k cycles, with only four in structions taking more than four system clock cycles. the cip-51 has a total of 109 instructions. the table below shows the total number of instructions that require each execution time. with the cip-51's maximum system clock at 100 mhz , the c8051f120/1/2/3 and c8051f130/1/2/3 have a peak throughput of 100 mips (the c8051f124/ 5/6/7 have a peak throughput of 50 mips). clocks to execute 1 22/333/444/55 8 number of instructions 26 50 5 14 7 3 1 2 1 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 28 rev. 1.4 1.1.3. additional features several key enhancements are implemented in the cip-51 core and peripherals to improve overall perfor- mance 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 stan- dard 8051), allowing the numerous analog and digital peripherals to interrupt the controller. an interrupt driven system requires less interventi on by the mcu, giving it more effective throughput. the extra inter- rupt sources are very useful when building multi-tasking, real-time systems. there are up to seven reset sources for the mcu: an on-board v dd monitor, a watchdog timer, a missing clock detector, a voltage level detection from compar ator0, 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 inter- nally generated por to be output on the rst pin. each reset source except for the v dd monitor and reset input pin may be disabled by the user in software; the v dd monitor is enabled/disabled via the monen pin. the watchdog timer may be permanently enabled in software after a power-on reset during mcu ini- tialization. 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 sour ce 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) exter- nal crystal source, while periodically switching to the 24.5 mhz intern al oscillator as needed. additionally, an on-chip pll is provided to achieve higher system clock speeds for increased throughput. figure 1.7. on-board clock and reset wdt xtal1 xtal2 osc internal clock generator system clock cip-51 microcontroller core missing clock detector (one- shot) wdt strobe software reset extended interrupt handler clock select rst + - v dd supply reset timeout (wired-or) system reset supply monitor pre reset funnel + - cp0+ comparator0 cp0- (port i/o) crossbar cnvstr (cnvstr reset enable) (cp0 reset enable) en wdt enable en mcd enable pll circuitry c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 29 1.2. on-chip memory the cip-51 has a standard 8051 program and data addr ess configuration. it includes 256 bytes of data ram, with the upper 128 bytes dual-mapped. indirect addressing accesses the upper 128 bytes of general purpose ram, and direct addressing accesses the 128 byte sfr address space. the lower 128 bytes of ram are accessible via direct and 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 devices include an on-chip 8k byte ram block and an external memory interf ace (emif) for accessing off-chip data memory. the on-chip 8k byte block can be addressed over the entire 64k external data mem- ory address range (overlapping 8k boundaries). external data memory address space can be mapped to on-chip memory only, off-chip memory only, or a comb ination of the two (addresses up to 8k directed to on- chip, above 8k directed to emif). the emif is al so configurable for multiplexed or non-multiplexed address/data lines. on the c8051f12x and c8051f130/1, the mcu?s prog ram memory consists of 128 k bytes of banked flash memory. the 1024 bytes from addresses 0x1fc00 to 0x1ffff are reserved. on the c8051f132/3, the mcu?s program memory consists of 64 k bytes of flash memory. this memory may be reprogrammed in-system in 1024 byte sectors, and requires no special off-chip programming voltage. on all devices, there are also two 128 byte sectors at addresses 0x20000 to 0x200ff, which may be used by software for data storage. see figure 1.8 for the mcu system memory map. figure 1.8. on-chip memory map program/data memory (flash) flash (in-system programmable in 1024 byte sectors) 0x00000 0x1ffff reserved 0x1fc00 0x1fbff scrachpad memory (data only) 0x200ff 0x20000 (direct and indirect addressing) upper 128 ram (indirect addressing only) special function registers (direct addressing only) data memory (ram) general purpose registers bit addressable lower 128 ram (direct and indirect addressing) internal data address space external data address space xram - 8192 bytes (accessable using movx instruction) 0x0000 0x1fff off-chip xram space 0x2000 0xffff up to 256 sfr pages 1 3 0 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1 flash (in-system programmable in 1024 byte sectors) 0x00000 0x0ffff scrachpad memory (data only) 0x200ff 0x20000 c8051f132/3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 30 rev. 1.4 1.3. jtag debug and boundary scan jtag boundary scan and debug circuitry is included which 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, provid ing full boundary scan for test and manufacturing pur- poses. silicon labs' debugging syst em supports inspection and modificati on of memory and registers, break- points, watchpoints, a stack monitor, and single step ping. no additional target ram, program memory, tim- ers, or communications channels are required. all the digital and analog peripherals are functional and work correctly while debugging. all the peripherals (except for the adc and smbus) are stalled when the mcu is halted, during single stepping, or at a breakpoint in order to keep them synchronized. the c8051f120dk development kit provides all the har dware and software necessary to develop applica- tion code and perform in-circuit debugging with the c8051f12x or c8051f13x mcus. the kit includes a windows (95 or later) development environment, a serial adap ter for connecting to the jtag port, and a target application board with a c80 51f120 mcu installed. all of the necessary commu- nication cables and a wall-mount power supply are al so supplied with the development kit. silicon labs? debug environment is a vastly superior configurat ion for developing and debugging embedded applications compared to standard mcu emulators, which use on-bo ard "ice chips" and target cables and require the mcu in the application board to be socketed. silicon labs' debug environm ent both increases ease of use and preserves the performance of the pr ecision, on-chip analog peripherals. figure 1.9. development/in-system debug diagram target pcb serial adapter jtag (x4), vdd, gnd windows 95 or later silicon labs integrated development environment c8051 f12x/13x c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 31 1.4. 16 x 16 mac (multipl y and accumulate) engine the c8051f120/1/2/3 and c8051f130/1/2/3 devices incl ude a multiply and accumulate engine which can be used to speed up many mathematical operations. mac0 contains a 16-by-16 bit multiplier and a 40-bit adder, which can perform integer or fractional multiply -accumulate and multiply operations on signed input values in two sysclk cycles. a rounding engine provides a rounded 16-bit fractional result after an addi- tional (third) sysclk cycle. mac0 also contains a 1-bit arithmetic shifter that will left or right-shift the con- tents of the 40-bit accumulator in a single sysclk cycle. figure 1.10. mac0 block diagram mac0cf mac0ms mac0fm mac0sat mac0ca mac0sd mac0sc mac0sta mac0n mac0so mac0z mac0ho 16 x 16 multiply mac0rndh mac0rndl mac0 rounding register mac0ovr mac0acc3 mac0acc2 mac0acc1 mac0acc0 mac0 accumulator 40 bit add mac0ms 1 0 0 rounding engine 1 bit shift mac0fm flag logic mac0bh mac0bl mac0 b register mac0ah mac0al mac0 a register c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 32 rev. 1.4 1.5. programmable digital i/o and crossbar the standard 8051 8-bit ports (0, 1, 2, and 3) are available on the mcus. the devices in the larger (100- pin tqfp) packaging have 4 additional ports (4, 5, 6, and 7) for a total of 64 general-purpose port i/o. the port i/o behave like the standard 8051 with a few enhancements. each port i/o 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, provid ing additional power saving capabili- ties for low-power applications. perhaps the most unique enhancement is the digital cro ssbar. this is a large digi tal switching network that allows mapping of internal digi tal system resources to port i/o pins on p0, p1, p2, and p3. (see figure 1.11) unlike microcontrollers with standard multip lexed digital i/o, all combinations of functions are supported. the on-chip counter/timers, serial buses, hw interrupts, adc start of conversion inputs, comparator out- puts, 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. figure 1.11. digital crossbar diagram external pins digital crossbar priority decoder smbus 2 spi 4 uart0 2 pca 2 t0, t1, t2, t2ex, t4,t4ex /int0, /int1 p1.0 p1.7 p2.0 p2.7 p0.0 p0.7 highest priority lowest priority 8 8 comptr. outputs (internal digital signals) highest priority lowest priority uart1 /sysclk divided by 1,2,4, or 8 cnvstr0/2 7 2 p3.0 p3.7 8 8 p0mdout, p1mdout, p2mdout, p3mdout registers xbr0, xbr1, xbr2, p1mdin registers p1 i/o cells p3 i/o cells p0 i/o cells p2 i/o cells 8 port latches p0 p1 p2 8 8 8 p3 8 (p2.0-p2.7) (p1.0-p1.7) (p0.0-p0.7) (p3.0-p3.7) to adc2 input (?f12x only) to external memory interface (emif) 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 33 1.6. programmable counter array an on-board programmable counter/timer array (pca) is included in addition to the five 16-bit general purpose counter/timers. the pca consists of a dedicat ed 16-bit counter/timer time base with 6 program- mable capture/compare modules. the timebase is cl ocked 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 sys- tem clock, or the external o scillator 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. figure 1.12. pca block diagram 1.7. serial ports serial peripherals included on the devices are tw o enhanced full-duplex uarts, spi bus, and smbus/ i2c. each of the serial buses is fully implemented in hardware and makes extensive use of the cip-51's interrupts, thus requiring very little intervention by the cpu. the serial buses do not "share" resources such as timers, interrupts, or port i/o, so any or all of the serial buses may be used together with any other. capture/compare module 1 capture/compare module 0 capture/compare module 2 capture/compare module 3 cex1 eci crossbar cex2 cex3 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8 capture/compare module 4 cex4 capture/compare module 5 cex5 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 34 rev. 1.4 1.8. 12 or 10-bit analog to digital converter all devices include either a 12 or 10-bit sar adc (adc0) with a 9-channel inpu t multiplexer and program- mable gain amplifier. with a maximum throughput of 10 0 ksps, the 12 and 10-bit adcs offer true 12-bit lin- earity with an inl of 1lsb. the adc0 voltage refere nce can be selected from an external vref pin, or (on the c8051f12x devices) the dac0 output. on the 100-pin tqfp devices, adc0 has its own dedicated voltage reference input pin; on the 64-pin tqfp devic es, the adc0 shares a voltage reference input pin with the 8-bit adc2. the on-chip vo ltage reference may generate the voltage reference for other system components or the on-chip adcs via the vref output pin. the adc is under full control of th e cip-51 microcontroller via its associated special function registers. one input channel is tied to an internal temperatur e 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 co ntroller can also put the adc into shutdown mode to save power. a programmable gain amplifier follows the analog multiplexer. the gain can be set in software from 0.5 to 16 in powers of 2. the gain stage can be especially us eful 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 dif- ferential 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 tr iggered 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 co nfigured 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. figure 1.13. 12-bit adc block diagram 12-bit sar adc 12 + - temp sensor + - + - + - 9-to-1 amux (se or diff) + - x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 av+ programmable gain amplifier analog multiplexer window compare logic adc data registers window compare interrupt conversion complete interrupt configuration, control, and data registers start conversion timer 3 overflow timer 2 overflow write to ad0busy cnvstr0 external vref pin dac0 output vref agnd c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 35 1.9. 8-bit analog to digital converter the c8051f12x 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 8-bit linearity with an inl of 1lsb. eight input pins are available for measurement. the adc is under full control of the cip-51 microcontroller via the special function re gisters. the adc2 voltage reference is selected between the analog power supply (av+) and an exte rnal vref pin. on the 100-pin tqfp devices, adc2 has its own dedicated voltage reference input pin; on the 64-pin tqfp devices, adc2 shares a voltage reference input pin with 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 diff erential 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 soft- ware-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. figure 1.14. 8-bit adc diagram + - av+ 8 8-to-1 amux x ain2.0 ain2.1 ain2.2 ain2.3 ain2.4 ain2.5 ain2.6 ain2.7 configuration, control, and data registers programmable gain amplifier analog multiplexer 8-bit sar adc start conversion timer 3 overflow timer 2 overflow write to ad2busy cnvstr2 input write to ad0busy (synchronized with adc0) adc data register conversion complete interrupt external vref pin av+ vref window compare logic window compare interrupt c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 36 rev. 1.4 1.10. 12-bit digital to analog converters the c8051f12x devices have two integrated 12-bit di gital to analog converters (dacs). the mcu data and control interface to each dac is via the special function registers. the mcu can place either or both of the dacs in a low power shutdown mode. the dacs are voltage output mode and include a flex ible output scheduling mechanism. this scheduling mechanism allows dac output updates to be forced by a software write or scheduled on a timer 2, 3, or 4 overflow. the dac voltage reference is supplied from the dedicated vrefd input pin on the 100-pin tqfp devices or via the internal voltage reference on the 64-pin tqfp devices. the dacs are especially useful as references for the comparators or offset s for the differential inputs of the adcs. figure 1.15. dac syst em block diagram dac0 av+ 12 agnd 8 8 ref dac0 dac0cn dac0en dac0md1 dac0md0 dac0df2 dac0df1 dac0df0 dac0h dac0l dig. mux latch latch 8 8 dac1 av+ 12 agnd 8 8 ref dac1 dac1cn dac1en dac1md1 dac1md0 dac1df2 dac1df1 dac1df0 dac1h dac1l dig. mux latch latch 8 8 dac0h timer 3 timer 4 timer 2 dac1h timer 3 timer 4 timer 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 37 1.11. analog comparators two analog comparators with dedicated input pins are included on-chip. the comparators have software programmable hysteresis and response time. each comp arator can generate an interrupt on a rising edge, falling edge, or both. the in terrupts are capable of waking up the mcu from sleep mode, and comparator 0 can be used as a reset source. the output state of the comparators can be polled in software or routed to port i/o pins via the crossbar. the comparators can be programmed to a low power shutdown mode when not in use. figure 1.16. comparator block diagram + - cpn+ cpn- cip-51 and interrupt handler cpn cpn output (port i/o) sfr's (data and control) crossbar 2 comparators c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 38 rev. 1.4 2. absolute maximum ratings table 2.1. absolute maximum ratings * parameter conditions min typ max units ambient temperature under bias ?55 ? 125 c storage temperature ?65 ? 150 c voltage on any pin (except v dd and port i/o) with respect to dgnd ?0.3 ? v dd + 0.3 v voltage on any port i/o pin or rst with respect to dgnd ?0.3 ? 5.8 v voltage on v dd with respect to dgnd ?0.3 ? 4.2 v maximum total current through v dd , av+, dgnd, and agnd ?? 800ma maximum output current sunk by any port pin ?? 100ma maximum output current s unk by any other i/o pin ?? 50 ma maximum output current sourced by any port pin ?? 100ma maximum output current s ourced by any other i/o pin ?? 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. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 39 3. global dc electrical characteristics table 3.1. global dc elec trical characteristics (c8051f120/1/2/3 and c8051f130/1/2/3) ?40 to +85 c, 100 mhz system clock unless otherwise specified. parameter conditions min typ max units analog supply voltage 1 sysclk = 0 to 50 mhz sysclk > 50 mhz 2.7 3.0 3.0 3.3 3.6 3.6 v v analog supply current internal ref, adcs, dacs, com- parators all active ?1.7?ma analog supply current with analog sub-systems inactive internal ref, adcs, dacs, com- parators all disabled, oscillator disabled ?0.2?a analog-to-digital supply delta (|v dd ?av+|) ??0.5v digital supply voltage sysclk = 0 to 50 mhz sysclk > 50 mhz 2.7 3.0 3.0 3.3 3.6 3.6 v v digital supply current with cpu active v dd = 3.0 v, clock = 100 mhz v dd = 3.0 v, clock = 50 mhz v dd = 3.0 v, clock = 1 mhz v dd = 3.0 v, clock = 32 khz ?65 35 1 33 ?ma ma ma a digital supply current with cpu inactive (not accessing flash) v dd = 3.0 v, clock = 100 mhz v dd = 3.0 v, clock = 50 mhz v dd = 3.0 v, clock = 1 mhz v dd = 3.0 v, clock = 32 khz ?40 20 0.4 15 ?ma ma ma a digital supply current (shut- down) oscillator not running ?0.4?a digital supply ram data retention voltage ?1.5? v sysclk (system clock) 2,3 v dd , av+ = 2.7 to 3.6 v v dd , av+ = 3.0 to 3.6 v 0 0 ?50 100 mhz mhz specified operating temper- ature range ?40 ? +85 c notes: 1. analog supply av+ must be greater than 1 v for v dd monitor to operate. 2. sysclk is the internal device clo ck. for operational speeds in excess of 30 mhz, sysclk must be derived from the phase-locked loop (pll). 3. sysclk must be at least 32 khz to enable debugging. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 40 rev. 1.4 table 3.2. global dc electrical characteristics (c8051f124/5/6/7) ?40 to +85 c, 50 mhz system clock unless otherwise specified. parameter conditions min typ max units analog supply voltage 1 2.7 3.0 3.6 v analog supply current internal ref, adc, dac, com- parators all active ?1.7?ma analog supply current with analog sub-systems inactive internal ref, adc, dac, com- parators all disabled, oscillator disabled ?0.2?a analog-to-digital supply delta (|v dd ?av+|) ??0.5v digital supply voltage 2.7 3.0 3.6 v digital supply current with cpu active v dd =3.0v, clock=50mhz v dd = 3.0 v, clock = 1 mhz v dd =3.0v, clock=32khz ?35 1 33 ?ma ma a digital supply current with cpu inactive (not accessing flash) v dd =3.0v, clock=50mhz v dd = 3.0 v, clock = 1 mhz v dd =3.0v, clock=32khz ?27 0.4 15 ?ma ma a digital supply current (shut- down) oscillator not running ?0.4?a digital supply ram data retention voltage ?1.5? v sysclk (system clock) 2,3 0?50mhz specified operating temperature range ?40 ? +85 c notes: 1. analog supply av+ must be greater than 1 v for v dd monitor to operate. 2. sysclk is the internal device clock. for operational sp eeds in excess of 30 mhz, sysclk must be derived from the phase-locked loop (pll). 3. sysclk must be at least 32 khz to enable debugging. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 41 4. pinout and package definitions table 4.1. pin definitions name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 v dd 37, 64, 90 24, 41, 57 37, 64, 90 24, 41, 57 digital supply voltage. must be tied to +2.7 to +3.6 v. dgnd 38, 63, 89 25, 40, 56 38, 63, 89 25, 40, 56 digital ground. must be tied to ground. av+ 11, 14 6 11, 14 6 analog supply voltage. must be tied to +2.7 to +3.6 v. agnd 10, 13 5 10, 13 5 analog ground. must be tied to ground. tms 1 58 1 58 d in jtag test mode select with internal pullup. tck 2 59 2 59 d in jtag test clock with internal pullup. tdi 3 60 3 60 d in jtag test data input with internal pullup. tdi is latched on the rising edge of tck. tdo 4 61 4 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 5 62 5 62 d i/o device reset. open-drain output of internal v dd monitor. is driven low when v dd is < v rst and monen is high. an external source can initiate a system reset by dr iving this pin low. xtal1 26 17 26 17 a in crystal input. this pin is the return for the inter- nal oscillator circuit for a crystal or ceramic reso- nator. for a precision internal clock, connect a crystal or ceramic res onator from xtal1 to xtal2. if overdriven by an external cmos clock, this become s the system clock. xtal2 27 18 27 18 a out crystal output. this pin is the excitation driver for a crystal or ceramic resonator. monen 28192819d inv dd monitor enable. when tied high, this pin enables the internal v dd monitor, which forces a system reset when v dd is < v rst . when tied low, the internal v dd monitor is disabled. this pin must be tied high or low. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 42 rev. 1.4 vref 12 7 12 7 a i/o bandgap voltage reference output (all devices). dac voltage reference input (c8051f121/3/5/7 only). vrefa 8 a in adc0 and adc2 voltage reference input. vref0 16 16 8 a in adc0 voltage reference input. vref2 17 17 a in adc2 voltage reference input. vrefd 15 15 a in dac voltage reference input. ain0.0 18 9 18 9 a in adc0 input channel 0 (see adc0 specification for complete description). ain0.1 19 10 19 10 a in adc0 input channel 1 (see adc0 specification for complete description). ain0.2 20 11 20 11 a in adc0 input channel 2 (see adc0 specification for complete description). ain0.3 21 12 21 12 a in adc0 input channel 3 (see adc0 specification for complete description). ain0.4 22 13 22 13 a in adc0 input channel 4 (see adc0 specification for complete description). ain0.5 23 14 23 14 a in adc0 input channel 5 (see adc0 specification for complete description). ain0.6 24 15 24 15 a in adc0 input channel 6 (see adc0 specification for complete description). ain0.7 25 16 25 16 a in adc0 input channel 7 (see adc0 specification for complete description). cp0+ 9 4 9 4 a in comparator 0 non-inverting input. cp0- 8 3 8 3 a in comparator 0 inverting input. cp1+ 7 2 7 2 a in comparator 1 non-inverting input. cp1? 6 1 6 1 a in comparator 1 inverting input. dac0 100 64 a out digital to analog converter 0 voltage output. (see dac specification for complete descrip- tion). table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 43 dac1 99 63 a out digital to analog converter 1 voltage output. (see dac specification for complete descrip- tion). p0.0 62 55 62 55 d i/o port 0.0. see port input/output section for com- plete description. p0.1 61 54 61 54 d i/o port 0.1. see port input/output section for com- plete description. p0.2 60 53 60 53 d i/o port 0.2. see port input/output section for com- plete description. p0.3 59 52 59 52 d i/o port 0.3. see port input/output section for com- plete description. p0.4 58 51 58 51 d i/o port 0.4. see port input/output section for com- plete description. ale/p0.5 57 50 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. rd /p0.6 56 49 56 49 d i/o /rd strobe for external memory address bus port 0.6 see port input/output section for complete description. wr /p0.7 55485548d i/o/wr strobe for external memory address bus port 0.7 see port input/output section for complete description. ain2.0/a8/p1.0 36 29 36 29 a in d i/o adc2 input channel 0 (see adc2 specification for complete description). bit 8 external memory address bus (non-multi- plexed mode) port 1.0 see port input/output section for complete description. ain2.1/a9/p1.1 35 28 35 28 a in d i/o port 1.1. see port input/output section for com- plete description. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 44 rev. 1.4 ain2.2/a10/p1.234273427a in d i/o port 1.2. see port input/output section for com- plete description. ain2.3/a11/p1.3 33 26 33 26 a in d i/o port 1.3. see port input/output section for com- plete description. ain2.4/a12/p1.432233223a in d i/o port 1.4. see port input/output section for com- plete description. ain2.5/a13/p1.531223122a in d i/o port 1.5. see port input/output section for com- plete description. ain2.6/a14/p1.630213021a in d i/o port 1.6. see port input/output section for com- plete description. ain2.7/a15/p1.729202920a in d i/o port 1.7. see port input/output section for com- plete description. a8m/a0/p2.0 46 37 46 37 d i/o bit 8 external memory address bus (multiplexed mode) bit 0 external memory address bus (non-multi- plexed mode) port 2.0 see port input/output section for complete description. a9m/a1/p2.145364536d i/oport 2.1. se e port input/output section for com- plete description. a10m/a2/p2.2 44 35 44 35 d i/o port 2.2. se e port input/output section for com- plete description. a11m/a3/p2.3 43 34 43 34 d i/o port 2.3. se e port input/output section for com- plete description. a12m/a4/p2.4 42 33 42 33 d i/o port 2.4. se e port input/output section for com- plete description. a13m/a5/p2.5 41 32 41 32 d i/o port 2.5. se e port input/output section for com- plete description. a14m/a6/p2.6 40 31 40 31 d i/o port 2.6. se e port input/output section for com- plete description. a15m/a7/p2.7 39 30 39 30 d i/o port 2.7. se e port input/output section for com- plete description. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 45 ad0/d0/p3.0 54 47 54 47 d i/o bit 0 external memory address/data bus (multi- plexed mode) bit 0 external memory data bus (non-multi- plexed mode) port 3.0 see port input/output section for complete description. ad1/d1/p3.153465346d i/oport 3.1. se e port input/output section for com- plete description. ad2/d2/p3.252455245d i/oport 3.2. se e port input/output section for com- plete description. ad3/d3/p3.351445144d i/oport 3.3. se e port input/output section for com- plete description. ad4/d4/p3.450435043d i/oport 3.4. se e port input/output section for com- plete description. ad5/d5/p3.549424942d i/oport 3.5. se e port input/output section for com- plete description. ad6/d6/p3.648394839d i/oport 3.6. se e port input/output section for com- plete description. ad7/d7/p3.747384738d i/oport 3.7. se e port input/output section for com- plete description. p4.0 98 98 d i/o port 4.0. see port input/output section for com- plete description. p4.1 97 97 d i/o port 4.1. see port input/output section for com- plete description. p4.2 96 96 d i/o port 4.2. see port input/output section for com- plete description. p4.3 95 95 d i/o port 4.3. see port input/output section for com- plete description. p4.4 94 94 d i/o port 4.4. see port input/output section for com- plete description. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 46 rev. 1.4 ale/p4.5 93 93 d i/o ale strobe for external memory address bus (multiplexed mode) port 4.5 see port input/output section for complete description. rd /p4.6 92 92 d i/o /rd strobe for external memory address bus port 4.6 see port input/output section for complete description. wr /p4.7 91 91 d i/o /wr strobe fo r external memory address bus port 4.7 see port input/output section for complete description. a8/p5.0 88 88 d i/o bit 8 external memory address bus (non-multi- plexed mode) port 5.0 see port input/output section for complete description. a9/p5.1 87 87 d i/o port 5.1. see port input/output section for com- plete description. a10/p5.2 86 86 d i/o port 5.2. see po rt input/output section for com- plete description. a11/p5.3 85 85 d i/o port 5.3. see port input/output section for com- plete description. a12/p5.4 84 84 d i/o port 5.4. see po rt input/output section for com- plete description. a13/p5.5 83 83 d i/o port 5.5. see po rt input/output section for com- plete description. a14/p5.6 82 82 d i/o port 5.6. see po rt input/output section for com- plete description. a15/p5.7 81 81 d i/o port 5.7. see po rt input/output section for com- plete description. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 47 a8m/a0/p6.0 80 80 d i/o bit 8 external memory address bus (multiplexed mode) bit 0 external memory address bus (non-multi- plexed mode) port 6.0 see port input/output section for complete description. a9m/a1/p6.1 79 79 d i/o port 6.1. see port input/output section for com- plete description. a10m/a2/p6.2 78 78 d i/o port 6.2. see port input/output section for com- plete description. a11m/a3/p6.3 77 77 d i/o port 6.3. see port input/output section for com- plete description. a12m/a4/p6.4 76 76 d i/o port 6.4. see port input/output section for com- plete description. a13m/a5/p6.5 75 75 d i/o port 6.5. see port input/output section for com- plete description. a14m/a6/p6.6 74 74 d i/o port 6.6. see port input/output section for com- plete description. a15m/a7/p6.7 73 73 d i/o port 6.7. see port input/output section for com- plete description. ad0/d0/p7.0 72 72 d i/o bit 0 external memory address/data bus (multi- plexed mode) bit 0 external memory data bus (non-multi- plexed mode) port 7.0 see port input/output section for complete description. ad1/d1/p7.1 71 71 d i/o port 7.1. see port input/output section for com- plete description. ad2/d2/p7.2 70 70 d i/o port 7.2. see port input/output section for com- plete description. ad3/d3/p7.3 69 69 d i/o port 7.3. see port input/output section for com- plete description. ad4/d4/p7.4 68 68 d i/o port 7.4. see port input/output section for com- plete description. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 48 rev. 1.4 ad5/d5/p7.5 67 67 d i/o port 7.5. see port input/output section for com- plete description. ad6/d6/p7.6 66 66 d i/o port 7.6. see port input/output section for com- plete description. ad7/d7/p7.7 65 65 d i/o port 7.7. see port input/output section for com- plete description. nc 15, 17, 99, 100 63, 64 no connection. table 4.1. pin definitions (continued) name pin numbers type description ?f120 ?f122 ?f124 ?f126 ?f121 ?f123 ?f125 ?f127 ?f130 ?f132 ?f131 ?f133 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 49 figure 4.1. c8051f120/2/4/6 pinout diagram (tqfp-100) c8051f120 c8051f122 c8051f124 c8051f126 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 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 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 75 74 73 72 71 70 69 68 67 ad6/d6/p7.6 ad7/d7/p7.7 vdd dgnd p0.0 p0.1 p0.2 p0.3 p0.4 ale/p0.5 /rd/p0.6 /wr/p0.7 ad0/d0/p3.0 ad1/d1/p3.1 ad2/d2/p3.2 ad3/d3/p3.3 a13m/a5/p6.5 a14m/a6/p6.6 a15m/a7/p6.7 ad0/d0/p7.0 ad1/d1/p7.1 ad2/d2/p7.2 ad3/d3/p7.3 ad4/d4/p7.4 ad5/d5/p7.5 dac0 dac1 p4.0 p4.1 p4.2 p4.3 p4.4 ale/p4.5 /rd/p4.6 /wr/p4.7 vdd dgnd a8/p5.0 a9/p5.1 a10/p5.2 a11/p5.3 a12/p5.4 a13/p5.5 a14/p5.6 a15/p5.7 a8m/a0/p6.0 a9m/a1/p6.1 a10m/a2/p6.2 a11m/a3/p6.3 a12m/a4/p6.4 agnd av+ vref agnd av+ vrefd vref0 vref2 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 tms tck tdi tdo /rst cp1- cp1+ cp0- cp0+ xtal1 xtal2 monen ain2.7/a15/p1.7 ain2.6/a14/p1.6 ain2.5/a13/p1.5 ain2.4/a12/p1.4 vdd dgnd ain2.3/a11/p1.3 ain2.2/a10/p1.2 ain2.1/a9/p1.1 ain2.0/a8/p1.0 a15m/a7/p2.7 a14m/a6/p2.6 a13m/a5/p2.5 a12m/a4/p2.4 a11m/a3/p2.3 a10m/a2/p2.2 a9m/a1/p2.1 a8m/a0/p2.0 ad7/d7/p3.7 ad6/d6/p3.6 ad5/d5/p3.5 ad4/d4/p3.4 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 50 rev. 1.4 figure 4.2. c8051f130/2 pin out diagram (tqfp-100) c8051f130 c8051f132 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 42 43 44 45 46 47 48 49 50 1 2 3 4 5 6 7 8 9 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 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 75 74 73 72 71 70 69 68 67 ad6/d6/p7.6 ad7/d7/p7.7 vdd dgnd p0.0 p0.1 p0.2 p0.3 p0.4 ale/p0.5 /rd/p0.6 /wr/p0.7 ad0/d0/p3.0 ad1/d1/p3.1 ad2/d2/p3.2 ad3/d3/p3.3 a13m/a5/p6.5 a14m/a6/p6.6 a15m/a7/p6.7 ad0/d0/p7.0 ad1/d1/p7.1 ad2/d2/p7.2 ad3/d3/p7.3 ad4/d4/p7.4 ad5/d5/p7.5 nc nc p4.0 p4.1 p4.2 p4.3 p4.4 ale/p4.5 /rd/p4.6 /wr/p4.7 vdd dgnd a8/p5.0 a9/p5.1 a10/p5.2 a11/p5.3 a12/p5.4 a13/p5.5 a14/p5.6 a15/p5.7 a8m/a0/p6.0 a9m/a1/p6.1 a10m/a2/p6.2 a11m/a3/p6.3 a12m/a4/p6.4 agnd av+ vref agnd av+ nc vref0 nc ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 tms tck tdi tdo /rst cp1- cp1+ cp0- cp0+ xtal1 xtal2 monen ain2.7/a15/p1.7 ain2.6/a14/p1.6 ain2.5/a13/p1.5 ain2.4/a12/p1.4 vdd dgnd ain2.3/a11/p1.3 ain2.2/a10/p1.2 ain2.1/a9/p1.1 ain2.0/a8/p1.0 a15m/a7/p2.7 a14m/a6/p2.6 a13m/a5/p2.5 a12m/a4/p2.4 a11m/a3/p2.3 a10m/a2/p2.2 a9m/a1/p2.1 a8m/a0/p2.0 ad7/d7/p3.7 ad6/d6/p3.6 ad5/d5/p3.5 ad4/d4/p3.4 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 51 figure 4.3. tqfp-100 package drawing a a1 a2 b d d1 e e e1 l - 0.05 0.95 0.17 - - - - - 0.45 - - 1.00 0.22 16.00 14.00 0.50 16.00 14.00 0.60 1.20 0.15 1.05 0.27 - - - - - 0.75 min (mm) nom (mm) max (mm) 100 e a1 b a2 a pin 1 designator 1 e1 e d1 d l c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 52 rev. 1.4 figure 4.4. c8051f121/3/5/7 pinout diagram (tqfp-64) c8051f121 c8051f123 c8051f125 c8051f127 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 dac0 dac1 /rst tdo tdi tck tms vdd dgnd p0.0 p0.1 p0.2 p0.3 p0.4 ale/p0.5 /rd/p0.6 /wr/p0.7 ad0/d0/p3.0 ad1/d1/p3.1 ad2/d2/p3.2 ad3/d3/p3.3 ad4/d4/p3.4 ad5/d5/p3.5 vdd dgnd ad6/d6/p3.6 ad7/d7/p3.7 a8m/a0/p2.0 a9m/a1/p2.1 a10m/a2/p2.2 a11m/a3/p2.3 a12m/a4/p2.4 cp1- cp1+ cp0- cp0+ agnd av+ vref vrefa ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 xtal1 xtal2 monen ain2.7/a15/p1.7 ain2.6/a14/p1.6 ain2.5/a13/p1.5 ain2.4/a12/p1.4 vdd dgnd ain2.3/a11/p1.3 ain2.2/a10/p1.2 ain2.1/a9/p1.1 ain2.0/a8/p1.0 a15m/a7/p2.7 a14m/a6/p2.6 a13m/a5/p2.5 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 53 figure 4.5. c8051f131/3 pi nout diagram (tqfp-64) c8051f131 c8051f133 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 nc nc /rst tdo tdi tck tms vdd dgnd p0.0 p0.1 p0.2 p0.3 p0.4 ale/p0.5 /rd/p0.6 /wr/p0.7 ad0/d0/p3.0 ad1/d1/p3.1 ad2/d2/p3.2 ad3/d3/p3.3 ad4/d4/p3.4 ad5/d5/p3.5 vdd dgnd ad6/d6/p3.6 ad7/d7/p3.7 a8m/a0/p2.0 a9m/a1/p2.1 a10m/a2/p2.2 a11m/a3/p2.3 a12m/a4/p2.4 cp1- cp1+ cp0- cp0+ agnd av+ vref vref0 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 xtal1 xtal2 monen ain2.7/a15/p1.7 ain2.6/a14/p1.6 ain2.5/a13/p1.5 ain2.4/a12/p1.4 vdd dgnd ain2.3/a11/p1.3 ain2.2/a10/p1.2 ain2.1/a9/p1.1 ain2.0/a8/p1.0 a15m/a7/p2.7 a14m/a6/p2.6 a13m/a5/p2.5 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 54 rev. 1.4 figure 4.6. tqfp-64 package drawing a a1 a2 b d d1 e e e1 l - 0.05 0.95 0.17 - - - - - 0.45 - - 1.00 0.22 12.00 10.00 0.50 12.00 10.00 0.60 1.20 0.15 1.05 0.27 - - - - - 0.75 min (mm) nom (mm) max (mm) 1 64 e e1 e a1 b d d1 pin 1 designator a2 a l c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 55 5. adc0 (12-bit adc, c8051f120/1/4/5 only) the adc0 subsystem for the c8051f120/1/4/5 consists of a 9-channel, configurable analog multiplexer (amux0), a programmable gain amplifier (pga0), a nd a 100 ksps, 12-bit successive-approximation-regis- ter adc with integrated track-and-hold and programmable window detector (see block diagram in figure 5.1). the amux0, pga0, data conversion mode s, and window detector are all configurable under software control via the special function register s shown in figure 5.1. the voltage reference used by adc0 is selected as described in section ?9. voltage reference? on page 113 . 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 s hutdown when this bit is logic 0. figure 5.1. 12-bit adc0 functional block diagram 5.1. analog multiplexer and pga eight of the amux channels are available for external measurements while the ninth channel is internally connected to an on-chip temperature sensor (temperatu re transfer function is shown in figure 5.2). amux input pairs can be programmed to operate in either diff erential 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 two registers associated with the amux: the channel selection regi ster amx0sl (sfr definition 5.2), and the configu- ration register amx0cf (sfr definition 5.1). the ta ble in sfr definition 5.2 shows amux functionality by channel, for each possible configuration. the pga am plifies the amux output signal by an amount deter- mined by the states of the amp0gn2-0 bits in the adc0 configuration register, adc0cf (sfr definition 5.3). the pga can be software-programmed for gains of 0.5, 2, 4, 8 or 16. gain defaults to unity on reset. 12-bit sar adc ref + - av+ temp sensor 12 + - + - + - 9-to-1 amux (se or diff) av+ 24 12 ad0en sysclk + - x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 start conversion agnd agnd adc0l adc0h adc0ltl adc0lth adc0gtl adc0gth ad0cm timer 3 overflow timer 2 overflow 00 01 10 11 ad0busy (w) cnvstr0 ad0wint comb. logic amx0cf amx0sl amx0ad0 amx0ad1 amx0ad2 amx0ad3 ain01ic ain23ic ain45ic ain67ic adc0cf amp0gn0 amp0gn1 amp0gn2 ad0sc0 ad0sc1 ad0sc2 ad0sc3 ad0sc4 adc0cn ad0ljst ad0wint ad0cm0 ad0cm1 ad0busy ad0int ad0tm ad0en ad0cm c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 56 rev. 1.4 the temperature sensor transfer function is shown in figure 5.2. the output voltage (v temp ) is the pga input when the temperature sensor is selected by bits amx0ad3-0 in register amx0sl; this voltage will be amplified by the pga according to the user-programmed pga settings. typical values for the slope and offset parameters can be found in table 5.1. figure 5.2. typical temperature sensor transfer function 0 -50 50 100 temperature (celsius) voltage v temp = ( slope x temp c ) + offset offset (v at 0 celsius) slope (v / deg c) temp c = (v temp - offset ) / slope c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 57 5.2. adc modes of operation adc0 has a maximum conver sion speed of 100 ksps. the adc0 conversion clock is derived from the sys- tem clock divided by the value held in the adcsc bits of register adc0cf. 5.2.1. starting a conversion a conversion can be initiated in one of four ways, depending on the programmed states of the adc0 start of conversion mode bits (ad0cm1, ad0cm0) in adc0cn. conversions may be initiated by: 1. writing a ?1? to the ad0busy bit of adc0cn; 2. a timer 3 overflow (i.e. timed continuous conversions); 3. a rising edge detected on the external adc convert start signal, cnvstr0; 4. a timer 2 overflow (i.e. timed continuous conversions). the ad0busy bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete. the 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 justifie d in the adc0h:adc0l register pair (see example in figure 5.5) depending on the programmed state of the ad0ljst bit in the adc0cn register. when initiating conversions by writing a ?1? to ad 0busy, the ad0int bit should be polled to determine when a conversion has co mpleted (adc0 interrupts may also be used). the recomm ended polling proce- dure is shown below. step 1. write a ?0? to ad0int; step 2. write a ?1? to ad0busy; step 3. poll ad0int for ?1?; step 4. process adc0 data. when cnvstr0 is used as a conversion start source, it must be enabled in the crossbar, and the corre- sponding pin must be set to open-drain, high-impedance mode (see section ?18. port input/output? on page 235 for more details on port i/o configuration). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 58 rev. 1.4 5.2.2. tracking modes the ad0tm bit in register adc0cn controls the adc0 track-and-hold mode. in its default state, the adc0 input is continuously tracked when a conversion is not in progress. when the ad0tm bit is logic 1, adc0 operates in low-power track-and-hold mode. in this mode, each conversion is preceded by a tracking period of 3 sar clocks (after the star t-of-conversion signal). when the cnvstr0 signal is used to initiate conversions in low-power tracking mode, adc0 tra cks only when cnvstr0 is low; conversion begins on the rising edge of cnvstr0 (see figure 5.3). tracki ng can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. low-power track-and-hold mode is also useful when amux or pga settings are frequently changed, to ensure that settling time requirements are met (see section ?5.2.3. settling time requirements? on page 59 ). figure 5.3. adc0 track and conversion example timing 12345678910111213141516 cnvstr0 (ad0cm[1:0]=10) adc0tm=1 adc0tm=0 timer 2, timer 3 overflow; write '1' to ad0busy (ad0cm[1:0]=00, 01, 11) adc0tm=1 adc0tm=0 a. adc timing for external trigger source b. adc timing for internal trigger sources sar clocks sar clocks 12345678910111213141516 17 18 19 12345678910111213141516 sar clocks track convert low power mode low power or convert track or convert convert track track convert low power mode low power or convert track or convert convert track c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 59 5.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 adc0 mux resistance, the adc0 sampling capacitance, any external source resis- tance, and the accuracy required for the conversion. figure 5.4 shows the equivalent adc0 input circuits for both differential and single-ended modes. notice t hat the equivalent time constant for both input cir- cuits is the same. the required settling time for a given settling accuracy ( sa ) may be approximated by equation 5.1. when measuring the temperature sensor output, r total reduces to r mux . an absolute minimum settling time of 1.5 s is required after any mux or pga selection. note that in low-power track- ing 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. equation 5.1. 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 r total is the sum of the adc0 mux resistanc e and any external source resistance. n is the adc resoluti on in bits (12). figure 5.4. adc0 equivalent input circuits t 2 n sa ------ - ?? ?? r total c sample ? r mux = 5k rc input = r mux * c sample r mux = 5k c sample = 10pf c sample = 10pf mux select mux select differential mode ain0.x ain0.y r mux = 5k c sample = 10pf rc input = r mux * c sample mux select single-ended mode ain0.x c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 60 rev. 1.4 sfr definition 5.1. amx0cf : amux0 configuration bits7?4: unused. read = 0000b; write = don?t care. bit3: ain67ic: ain0.6, ain0.7 input pair configuration bit. 0: ain0.6 and ain0.7 are independent single-ended inputs. 1: ain0.6, ain0.7 are (respectively ) +, ? differential input pair. bit2: ain45ic: ain0.4, ain0.5 input pair configuration bit. 0: ain0.4 and ain0.5 are independent single-ended inputs. 1: ain0.4, ain0.5 are (respectively ) +, ? differential input pair. bit1: ain23ic: ain0.2, ain0.3 input pair configuration bit. 0: ain0.2 and ain0.3 are independent single-ended inputs. 1: ain0.2, ain0.3 are (respectively ) +, ? differential input pair. bit0: ain01ic: ain0.0, ain0.1 input pair configuration bit. 0: ain0.0 and ain0.1 are independent single-ended inputs. 1: ain0.0, ain0.1 are (respectively ) +, ? differential input pair. note: the adc0 data word is in 2?s complement format for channels configured as differential. sfr page: sfr address: 0 0xba r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - ain67ic ain45ic ain23ic ain01ic 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 61 sfr definition 5.2. amx0sl: amux0 channel select bits7?4: unused. read = 0000b; write = don?t care. bits3?0: amx0ad3?0: amx0 address bits. 0000-1111b: adc inputs selected per chart below. sfr page: sfr address: 0 0xbb r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - amx0ad3 amx0ad2 amx0ad1 amx0ad0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 amx0ad3?0 0000 0001 0010 0011 0100 0101 0110 0111 1xxx amx0cf bits 3?0 0000 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0001 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0010 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0011 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0100 ain0.0 ain0.1 ain0.2 ain0.3 +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0101 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0110 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0111 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 1000 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1001 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1010 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1011 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1100 ain0.0 ain0.1 ain0.2 ain0.3 +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1101 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1110 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1111 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 62 rev. 1.4 sfr definition 5.3. adc0cf : adc0 configuration bits7?3: ad0sc4?0: adc0 sar c onversion clock period bits. the sar conversion clock is derived from sy stem clock by the following equation, where ad0sc refers to the 5-bit value held in ad0sc4-0, and clk sar0 refers to the desired adc0 sar clock (note: the adc0 sar conversion clock should be less than or equal to 2.5 mhz). when the ad0sc bits are equa l to 00000b, the sar conversion clock is equal to sysclk to facilitate faster adc conversions at slower sysclk speeds. bits2?0: amp0gn2?0: adc0 internal amplifier gain (pga). 000: gain = 1 001: gain = 2 010: gain = 4 011: gain = 8 10x: gain = 16 11x: gain = 0.5 sfr page: sfr address: 0 0xbc r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0sc4 ad0sc3 ad0sc2 ad0sc1 ad0sc0 amp0gn2 amp0gn1 amp0gn0 11111000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 ad 0 sc sysclk 2 c ? lk sar 0 ------------------------------- - 1? = ad 0 sc 00000b ? ?? c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 63 sfr definition 5.4. adc0cn: adc0 control bit7: ad0en: adc0 enable bit. 0: adc0 disabled. adc0 is in low-power shutdown. 1: adc0 enabled. adc0 is active and ready for data conversions. bit6: ad0tm: adc track mode bit. 0: when the adc is enabled, tracking is co ntinuous unless a conversion is in process. 1: tracking defined by adcm1-0 bits. bit5: ad0int: adc0 conversion complete interrupt flag. this flag must be cleared by software. 0: adc0 has not completed a data conversion since the last time this flag was cleared. 1: adc0 has completed a data conversion. bit4: ad0busy: adc0 busy bit. read: 0: adc0 conversion is complete or a conversion is not currently in progress. ad0int is set to logic 1 on the falling edge of ad0busy. 1: adc0 conversion is in progress. write: 0: no effect. 1: initiates adc0 conversion if ad0cm1-0 = 00b. bits3?2: ad0cm1?0: adc0 start of conversion mode select. if ad0tm = 0: 00: adc0 conversion initiated on every write of ?1? to ad0busy. 01: adc0 conversion initiated on overflow of timer 3. 10: adc0 conversion initiated on rising edge of external cnvstr0. 11: adc0 conversion initiated on overflow of timer 2. if ad0tm = 1: 00: tracking starts with the wr ite of ?1? to ad0busy and last s for 3 sar clocks, followed by conversion. 01: tracking started by the overflow of timer 3 and lasts for 3 sar clocks, followed by con- version. 10: adc0 tracks only when cnvstr0 input is logic low; conversion starts on rising cnvstr0 edge. 11: tracking started by the overflow of timer 2 and lasts for 3 sar clocks, followed by con- version. bit1: ad0wint: adc0 window compare interrupt flag. this bit must be cleared by software. 0: adc0 window comparison data match has no t occurred since this flag was last cleared. 1: adc0 window comparison data match has occurred. bit0: ad0ljst: adc0 left justify select. 0: data in adc0h:adc0l r egisters are right-justified. 1: data in adc0h:adc0l r egisters are left-justified. sfr page: sfr address: 0 0xe8 (bit addressable) r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0en ad0tm ad0int ad0busy ad0cm1 ad0cm0 ad0wint ad0ljst 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 64 rev. 1.4 sfr definition 5.5. adc0h: adc0 data word msb sfr definition 5.6. adc0l: adc0 data word lsb bits7?0: adc0 data word high-order bits. for ad0ljst = 0: bits 7?4 are the sign extension of bit3. bits 3?0 are the upper 4 bits of the 12-bit adc0 data word. for ad0ljst = 1: bits 7?0 are the most-significant bits of the 12-bit adc0 data word. sfr page: sfr address: 0 0xbf 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 bits7?0: adc0 data word low-order bits. for ad0ljst = 0: bits 7?0 are the lower 8 bits of the 12-bit adc0 data word. for ad0ljst = 1: bits 7?4 are the lower 4 bits of the 12-bit adc0 da ta word. bits 3?0 will always read ?0?. sfr page: sfr address: 0 0xbe 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 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 65 figure 5.5. adc0 data word example 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 si gn-extension of adc0 h.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.0 input in single-ended mode (amx0cf = 0x00, amx0sl = 0x00) example: adc0 data word conversion ma p, ain0.0-ain0.1 differential input pair (amx0cf = 0x01, amx0sl = 0x00) for ad0ljst = 0: ; ?n? = 12 for single-ended ; ?n?=11 for differential. ain0.0?agnd (volts) adc0h:adc0l (ad0ljst = 0) adc0h:adc0l (ad0ljst = 1) vref x (4095/4096) 0x0fff 0xfff0 vref / 2 0x0800 0x8000 vref x (2047/4096) 0x07ff 0x7ff0 0 0x0000 0x0000 ain0.0?ain0.1 (volts) adc0h:adc0l (ad0ljst = 0) adc0h:adc0l (ad0ljst = 1) vref x (2047/2048) 0x07ff 0x7ff0 vref / 2 0x0400 0x4000 vref x (1/2048) 0x0001 0x0010 0 0x0000 0x0000 ?vref x (1/2048) 0xffff (?1d) 0xfff0 ?vref / 2 0xfc00 (?1024d) 0xc000 ?vref 0xf800 (?2048d) 0x8000 code vin gain vref --------------- ? 2 n ? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 66 rev. 1.4 5.3. adc0 programmable window detector the adc0 programmable window detector continuously compares the adc0 output to user-programmed limits, and notifies the system when an out-of-bound condi tion 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 adc0 ltl). reference comparisons are shown starting on page 68. notice that the window detector flag can be asserted when the measured data is inside or out- side the user-programmed limits, depending on th e programming of the adc0gtx and adc0ltx regis- ters. sfr definition 5.7. adc0gth: adc 0 greater-than data high byte sfr definition 5.8. adc0gtl: adc 0 greater-than data low byte bits7?0: high byte of adc0 greater-than data word. sfr page: sfr address: 0 0xc5 r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bits7?0: low byte of adc0 greater-than data word. sfr page: sfr address: 0 0xc4 r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 67 sfr definition 5.9. adc0lth: a dc0 less-than da ta high byte sfr definition 5.10. adc0ltl: adc0 less-than data low byte bits7?0: high byte of adc0 less-than data word. sfr page: sfr address: 0 0xc7 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 bits7?0: low byte of adc0 less-than data word. sfr page: sfr address: 0 0xc6 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 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 68 rev. 1.4 figure 5.6. 12-bit adc0 window interrupt example: right just ified single-ended data given: amx0sl = 0x00, amx0cf = 0x00 ad0ljst = ?0?, adc0lth:adc0ltl = 0x0200, adc0gth:adc0gtl = 0x0100. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x0200 and > 0x0100. given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?0?, adc0lth:adc0ltl = 0x0100, adc0gth:adc0gtl = 0x0200. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is > 0x0200 or < 0x0100. 0x0fff 0x0201 0x0200 0x01ff 0x0101 0x0100 0x00ff 0x0000 ad0wint=1 ad0wint not affected ad0wint not affected adc data word 0x0fff 0x0201 0x0200 0x01ff 0x0101 0x0100 0x00ff 0x0000 ad0wint=1 ad0wint not affected ad0wint=1 adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc0gth:adc0gtl adc0lth:adc0ltl 0 input voltage (ad0.0 - agnd) ref x (4095/4096) ref x (256/4096) ref x (512/4096) 0 input voltage (ad0.0 - agnd) ref x (4095/4096) ref x (256/4096) ref x (512/4096) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 69 figure 5.7. 12-bit adc0 window interrupt example: right justified differential data 0x07ff 0x0101 0x0100 0x00ff 0x0000 0xffff 0xfffe 0xf800 ad0wint=1 ad0wint not affected ad0wint not affected 0x07ff 0x0101 0x0100 0x00ff 0x0000 0xffff 0xfffe 0xf800 ad0wint=1 ad0wint not affected -ref input voltage (ad0.0 - ad0.1) ad0wint=1 ref x (2047/2048) adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc data word adc0lth:adc0ltl adc0gth:adc0gtl ref x (256/2048) ref x (-1/2048) -ref input voltage (ad0.0 - ad0.1) ref x (2047/2048) ref x (256/2048) ref x (-1/2048) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?0?, adc0lth:adc0ltl = 0x0100, adc0gth:adc0gtl = 0xffff. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x0100 and > 0xffff. (in 2s-complement math, 0xffff = -1.) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?0?, adc0lth:adc0ltl = 0xffff, adc0gth:adc0gtl = 0x0100. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0xffff or > 0x0100. (in 2s-complement math, 0xffff = -1.) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 70 rev. 1.4 figure 5.8. 12-bit adc0 window interrupt e xample: left justified single-ended data 0xfff0 0x2010 0x2000 0x1ff0 0x1010 0x1000 0x0ff0 0x0000 ad0wint=1 ad0wint not affected ad0wint not affected adc data word 0xfff0 0x2010 0x2000 0x1ff0 0x1010 0x1000 0x0ff0 0x0000 ad0wint=1 ad0wint not affected ad0wint=1 adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc0gth:adc0gtl adc0lth:adc0ltl 0 input voltage (ad0.0 - agnd) ref x (4095/4096) ref x (256/4096) ref x (512/4096) 0 input voltage (ad0.0 - agnd) ref x (4095/4096) ref x (256/4096) ref x (512/4096) given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?1?, adc0lth:adc0ltl = 0x2000, adc0gth:adc0gtl = 0x1000. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x2000 and > 0x1000. given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?1? adc0lth:adc0ltl = 0x1000, adc0gth:adc0gtl = 0x2000. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0x1000 or > 0x2000. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 71 figure 5.9. 12-bit adc0 window interrupt exam ple: left justifie d differential data 0x7ff0 0x1010 0x1000 0x0ff0 0x0000 0xfff0 0xffe0 0x8000 ad0wint=1 ad0wint not affected ad0wint not affected 0x7ff0 0x1010 0x1000 0x0ff0 0x0000 0xfff0 0xffe0 0x8000 ad0wint=1 ad0wint not affected -ref input voltage (ad0.0 - ad0.1) ad0wint=1 ref x (2047/2048) adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc data word adc0lth:adc0ltl adc0gth:adc0gtl ref x (256/2048) ref x (-1/2048) -ref input voltage (ad0.0 - ad0.1) ref x (2047/2048) ref x (256/2048) ref x (-1/2048) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?1?, adc0lth:adc0ltl = 0x1000, adc0gth:adc0gtl = 0xfff0. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x1000 and > 0xfff0. (2s-complement math.) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?1?, adc0lth:adc0ltl = 0xfff0, adc0gth:adc0gtl = 0x1000. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0xfff0 or > 0x1000. (2s-complement math.) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 72 rev. 1.4 table 5.1. 12-bit adc0 electrical characteristics (c8051f120/1/4/5) v dd = 3.0 v, av+ = 3.0 v, vref = 2.40 v (refbe = 0), pga ga in = 1, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units dc accuracy resolution 12 bits integral nonlinearity ? ? 1 lsb differential nonlinearity guaranteed monotonic ? ? 1 lsb offset error ? ?31 ? lsb full scale error differential mode ? ?73 ? lsb offset temperature coefficient ? 0.25 ? ppm/c dynamic performance (10 khz sine-wave input , 0 to 1 db below full scale, 100 ksps signal-to-noise plus distortion 66 ? ? db total harmonic distortion up to the 5 th harmonic ??75? db spurious-free dynamic range ? 80 ? db conversion rate sar clock frequency ? ? 2.5 mhz conversion time in sar clocks 16 ? ? clocks track/hold acquisition time 1.5 ? ? s throughput rate ? ? 100 ksps analog inputs input voltage range single-ended operation 0 ? vref v *common-mode voltage range differential operation agnd ? av+ v input capacitance ? 10 ? pf temperature sensor linearity 1 ?0.2? c offset (temp = 0 c) ? 776 ? mv offset error 1, 2 (temp = 0 c) ? 8.5 ? mv slope ? 2.86 ? mv / c slope error 2 ? 0.034 ? mv / c power specifications power supply current (av+ supplied to adc) operating mode, 100 ksps ?450900 a power supply rejection ? 0.3 ? mv/v notes: 1. includes adc offset, gain, and linearity variations. 2. represents one standard deviation from the mean. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 73 6. adc0 (10-bit adc, c8051f122 /3/6/7 and c8051f13x only) the adc0 subsystem for the c8051f122/3/6/7 and c8051f13x consists of a 9-channel, co nfigurable ana- log multiplexer (amux0), a programmable gain amplifier (pga0), and a 100 ksps, 10-bit successive- approximation-register adc with integrated tra ck-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 fu nction registers shown in figure 6.1. the voltage reference used by adc0 is selected as described in section ?9. voltage reference? on page 113 . 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 powe r shutdown when this bit is logic 0. figure 6.1. 10-bit adc0 functional block diagram 6.1. analog multiplexer and pga eight of the amux channels are available for external measurements while the ninth channel is internally connected to an on-chip temperature sensor (temperatu re transfer function is shown in figure 6.2). amux input pairs can be programmed to operate in either diff erential 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 two registers associated with the amux: the channel selection regi ster amx0sl (sfr definition 6.2), and the configu- ration register amx0cf (sfr definition 6.1). the ta ble in sfr definition 6.2 shows amux functionality by channel, for each possible configuration. the pga am plifies the amux output signal by an amount deter- mined by the states of the amp0gn2-0 bits in the adc0 configuration register, adc0cf (sfr definition 6.3). the pga can be software-programmed for gains of 0.5, 2, 4, 8 or 16. gain defaults to unity on reset. 10-bit sar adc ref + - av+ temp sensor 10 + - + - + - 9-to-1 amux (se or diff) av+ 20 10 ad0en sysclk + - x ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 start conversion agnd agnd adc0l adc0h adc0ltl adc0lth adc0gtl adc0gth ad0cm timer 3 overflow timer 2 overflow 00 01 10 11 ad0busy (w) cnvstr0 ad0wint comb. logic amx0sl amx0ad0 amx0ad1 amx0ad2 amx0ad3 amx0cf ain01ic ain23ic ain45ic ain67ic adc0cf amp0gn0 amp0gn1 amp0gn2 ad0sc0 ad0sc1 ad0sc2 ad0sc3 ad0sc4 adc0cn ad0ljst ad0wint ad0cm0 ad0cm1 ad0busy ad0int ad0tm ad0en ad0cm c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 74 rev. 1.4 the temperature sensor transfer function is shown in figure 6.2. the output voltage (v temp ) is the pga input when the temperature sensor is selected by bits amx0ad3-0 in register amx0sl; this voltage will be amplified by the pga according to the user-programmed pga settings. typical values for the slope and offset parameters can be found in table 6.1. figure 6.2. typical temperature sensor transfer function 0 -50 50 100 temperature (celsius) voltage v temp = ( slope x temp c ) + offset offset (v at 0 celsius) slope (v / deg c) temp c = (v temp - offset ) / slope c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 75 6.2. adc modes of operation adc0 has a maximum conver sion speed of 100 ksps. the adc0 conversion clock is derived from the sys- tem clock divided by the value held in the adcsc bits of register adc0cf. 6.2.1. starting a conversion a conversion can be initiated in one of four ways, depending on the programmed states of the adc0 start of conversion mode bits (ad0cm1, ad0cm0) in adc0cn. conversions may be initiated by: 1. writing a ?1? to the ad0busy bit of adc0cn; 2. a timer 3 overflow (i.e. timed continuous conversions); 3. a rising edge detected on the external adc convert start signal, cnvstr0; 4. a timer 2 overflow (i.e. timed continuous conversions). the ad0busy bit is set to logic 1 during conversion and restored to logic 0 when conversion is complete. the 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 justifie d in the adc0h:adc0l register pair (see example in figure 6.5) depending on the programmed state of the ad0ljst bit in the adc0cn register. when initiating conversions by writing a ?1? to ad 0busy, the ad0int bit should be polled to determine when a conversion has co mpleted (adc0 interrupts may also be used). the recomm ended polling proce- dure is shown below. step 1. write a ?0? to ad0int; step 2. write a ?1? to ad0busy; step 3. poll ad0int for ?1?; step 4. process adc0 data. when cnvstr0 is used as a conversion start source, it must be enabled in the crossbar, and the corre- sponding pin must be set to open-drain, high-impedance mode (see section ?18. port input/output? on page 235 for more details on port i/o configuration). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 76 rev. 1.4 6.2.2. tracking modes the ad0tm bit in register adc0cn controls the adc0 track-and-hold mode. in its default state, the adc0 input is continuously tracked when a conversion is not in progress. when the ad0tm bit is logic 1, adc0 operates in low-power track-and-hold mode. in this mode, each conversion is preceded by a tracking period of 3 sar clocks (after the star t-of-conversion signal). when the cnvstr0 signal is used to initiate conversions in low-power tracking mode, adc0 tra cks only when cnvstr0 is low; conversion begins on the rising edge of cnvstr0 (see figure 6.3). tracki ng can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. low-power track-and-hold mode is also useful when amux or pga settings are frequently changed, to ensure that settling time requirements are met (see section ?6.2.3. settling time requirements? on page 77 ). figure 6.3. adc0 track and conversion example timing 12345678910111213141516 cnvstr0 (ad0cm[1:0]=10) adc0tm=1 adc0tm=0 timer 2, timer 3 overflow; write '1' to ad0busy (ad0cm[1:0]=00, 01, 11) adc0tm=1 adc0tm=0 a. adc timing for external trigger source b. adc timing for internal trigger sources sar clocks sar clocks 12345678910111213141516 17 18 19 12345678910111213141516 sar clocks track convert low power mode low power or convert track or convert convert track track convert low power mode low power or convert track or convert convert track c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 77 6.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 adc0 mux resistance, the adc0 sampling capacitance, any external source resis- tance, and the accuracy required for the conversion. figure 6.4 shows the equivalent adc0 input circuits for both differential and single-ended modes. notice t hat the equivalent time constant for both input cir- cuits is the same. the required settling time for a given settling accuracy ( sa ) may be approximated by equation 6.1. when measuring the temperature sensor output, r total reduces to r mux . an absolute minimum settling time of 1.5 s is required after any mux or pga selection. note that in low-power track- ing 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. equation 6.1. 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 r total is the sum of the adc0 mux resistanc e and any external source resistance. n is the adc resoluti on in bits (10). figure 6.4. adc0 equivalent input circuits t 2 n sa ------ - ?? ?? r total c sample ? r mux = 5k rc input = r mux * c sample r mux = 5k c sample = 10pf c sample = 10pf mux select mux select differential mode ain0.x ain0.y r mux = 5k c sample = 10pf rc input = r mux * c sample mux select single-ended mode ain0.x c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 78 rev. 1.4 sfr definition 6.1. amx0cf : amux0 configuration bits7?4: unused. read = 0000b; write = don?t care. bit3: ain67ic: ain0.6, ain0.7 input pair configuration bit. 0: ain0.6 and ain0.7 are independent single-ended inputs. 1: ain0.6, ain0.7 are (respectively) +, - differential input pair. bit2: ain45ic: ain0.4, ain0.5 input pair configuration bit. 0: ain0.4 and ain0.5 are independent single-ended inputs. 1: ain0.4, ain0.5 are (respectively) +, - differential input pair. bit1: ain23ic: ain0.2, ain0.3 input pair configuration bit. 0: ain0.2 and ain0.3 are independent single-ended inputs. 1: ain0.2, ain0.3 are (respectively) +, - differential input pair. bit0: ain01ic: ain0.0, ain0.1 input pair configuration bit. 0: ain0.0 and ain0.1 are independent single-ended inputs. 1: ain0.0, ain0.1 are (respectively) +, - differential input pair. note: the adc0 data word is in 2?s complement format for channels configured as differential. sfr page: sfr address: 0 0xba r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - ain67ic ain45ic ain23ic ain01ic 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 79 sfr definition 6.2. amx0sl: amux0 channel select bits7?4: unused. read = 0000b; write = don?t care. bits3?0: amx0ad3?0: amx0 address bits. 0000-1111b: adc inputs selected per chart below. sfr page: sfr address: 0 0xbb r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - amx0ad3 amx0ad2 amx0ad1 amx0ad0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 amx0ad3-0 0000 0001 0010 0011 0100 0101 0110 0111 1xxx amx0cf bits 3-0 0000 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0001 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0010 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0011 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) ain0.4 ain0.5 ain0.6 ain0.7 temp sensor 0100 ain0.0 ain0.1 ain0.2 ain0.3 +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0101 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0110 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 0111 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) ain0.6 ain0.7 temp sensor 1000 ain0.0 ain0.1 ain0.2 ain0.3 ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1001 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1010 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1011 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) ain0.4 ain0.5 +(ain0.6) ?(ain0.7) temp sensor 1100 ain0.0 ain0.1 ain0.2 ain0.3 +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1101 +(ain0.0) ?(ain0.1) ain0.2 ain0.3 +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1110 ain0.0 ain0.1 +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor 1111 +(ain0.0) ?(ain0.1) +(ain0.2) ?(ain0.3) +(ain0.4) ?(ain0.5) +(ain0.6) ?(ain0.7) temp sensor c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 80 rev. 1.4 sfr definition 6.3. adc0cf : adc0 configuration bits7?3: ad0sc4?0: adc0 sar c onversion clock period bits. sar conversion clock is derived from syste m clock by the following equation, where ad0sc refers to the 5-bit value held in ad0sc4-0, and clk sar0 refers to the desired adc0 sar clock (note: the adc0 sar conversion clock should be less than or equal to 2.5 mhz). when the ad0sc bits are equa l to 00000b, the sar conversion clock is equal to sysclk to facilitate faster adc conversions at slower sysclk speeds. bits2?0: amp0gn2?0: adc0 internal amplifier gain (pga). 000: gain = 1 001: gain = 2 010: gain = 4 011: gain = 8 10x: gain = 16 11x: gain = 0.5 sfr page: sfr address: 0 0xbc r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0sc4 ad0sc3 ad0sc2 ad0sc1 ad0sc0 amp0gn2 amp0gn1 amp0gn0 11111000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 ad 0 sc sysclk 2 c ? lk sar 0 ------------------------------- - 1? = ad 0 sc 00000b ? ?? c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 81 sfr definition 6.4. adc0cn: adc0 control bit7: ad0en: adc0 enable bit. 0: adc0 disabled. adc0 is in low-power shutdown. 1: adc0 enabled. adc0 is active and ready for data conversions. bit6: ad0tm: adc track mode bit. 0: when the adc is enabled, tracking is continuous unless a conversion is in process. 1: tracking defined by adcm1-0 bits. bit5: ad0int: adc0 conversion complete interrupt flag. this flag must be cleared by software. 0: adc0 has not completed a data conversion since the last time this flag was cleared. 1: adc0 has completed a data conversion. bit4: ad0busy: adc0 busy bit. read: 0: adc0 conversion is complete or a conversi on is not currently in progress. ad0int is set to logic 1 on the falling edge of ad0busy. 1: adc0 conversion is in progress. write: 0: no effect. 1: initiates adc0 conver sion if ad0cm1-0 = 00b. bits3?2: ad0cm1?0: adc0 start of conversion mode select. if ad0tm = 0: 00: adc0 conversion initiated on every write of ?1? to ad0busy. 01: adc0 conversion initiated on overflow of timer 3. 10: adc0 conversion initiated on rising edge of external cnvstr0. 11: adc0 conversion initiated on overflow of timer 2. if ad0tm = 1: 00: tracking starts with the write of ?1? to ad0busy and lasts for 3 sar clocks, followed by conversion. 01: tracking started by the overflow of timer 3 and lasts for 3 sar clocks, followed by con- version. 10: adc0 tracks only when cnvstr0 input is logic low; conversion starts on rising cnvstr0 edge. 11: tracking started by the overflow of timer 2 and lasts for 3 sar clocks, followed by con- version. bit1: ad0wint: adc0 window compare interrupt flag. this bit must be cleared by software. 0: adc0 window comparison data match has not occurred since this flag was last cleared. 1: adc0 window comparison data match has occurred. bit0: ad0ljst: adc0 left justify select. 0: data in adc0h:adc0l re gisters are right-justified. 1: data in adc0h:adc0l re gisters are left-justified. sfr page: sfr address: 0 0xe8 (bit addressable) r/w r/w r/w r/w r/w r/w r/w r/w reset value ad0en ad0tm ad0int ad0busy ad0cm1 ad0cm0 ad0wint ad0ljst 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 82 rev. 1.4 sfr definition 6.5. adc0h: adc0 data word msb sfr definition 6.6. adc0l: adc0 data word lsb bits7?0: adc0 data word high-order bits. for ad0ljst = 0: bits 7?4 are the sign extension of bit3. bits 3?0 are the upper 4 bits of the 10-bit adc0 data word. for ad0ljst = 1: bits 7?0 are the most-significant bits of the 10-bit adc0 data word. sfr page: sfr address: 0 0xbf 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 bits7?0: adc0 data word low-order bits. for ad0ljst = 0: bits 7?0 are the lower 8 bits of the 10-bit adc0 data word. for ad0ljst = 1: bits 7?4 are the lower 4 bits of the 10-bit adc0 da ta word. bits 3?0 will always read ?0?. sfr page: sfr address: 0 0xbe 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 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 83 figure 6.5. adc0 data word example 10-bit adc0 data word appears in the adc0 data word registers as follows: adc0h[1:0]:adc0l[7:0], if ad0ljst = 0 (adc0h[7:2] will be si gn-extension of adc0 h.1 for a differential reading, otherwise = 000000b). adc0h[7:0]:adc0l[7:6], if ad0ljst = 1 (adc0l[5:0] = 00b). example: adc0 data word conversion map, ain0.0 input in single-ended mode (amx0cf = 0x00, amx0sl = 0x00) example: adc0 data word conversion ma p, ain0.0-ain0.1 differential input pair (amx0cf = 0x01, amx0sl = 0x00) for ad0ljst = 0: ; ?n? = 10 for single-ended ; ?n?= 9 for differential. ain0.0?agnd (volts) adc0h:adc0l (ad0ljst = 0) adc0h:adc0l (ad0ljst = 1) vref x (1023/1024) 0x03ff 0xffc0 vref / 2 0x0200 0x8000 vref x (511/1024) 0x01ff 0x7fc0 0 0x0000 0x0000 ain0.0?ain0.1 (volts) adc0h:adc0l (ad0ljst = 0) adc0h:adc0l (ad0ljst = 1) vref x (511/512) 0x01ff 0x7fc0 vref / 2 0x0100 0x4000 vref x (1/512) 0x0001 0x0040 0 0x0000 0x0000 ?vref x (1/512) 0xffff (?1d) 0xffc0 ?vref / 2 0xff00 (?256d) 0xc000 ?vref 0xfe00 (?512d) 0x8000 code vin gain vref --------------- ? 2 n ? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 84 rev. 1.4 6.3. adc0 programmable window detector the adc0 programmable window detector continuously compares the adc0 output to user-programmed limits, and notifies the system when an out-of-bound condi tion 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 adc0 ltl). reference comparisons are shown starting on page 87. notice that the window detector flag can be asserted when the measured data is inside or out- side the user-programmed limits, depending on th e programming of the adc0gtx and adc0ltx regis- ters. sfr definition 6.7. adc0gth: adc 0 greater-than data high byte sfr definition 6.8. adc0gtl: adc 0 greater-than data low byte bits7?0: high byte of adc0 greater-than data word. sfr page: sfr address: 0 0xc5 r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bits7?0: low byte of adc0 greater-than data word. sfr page: sfr address: 0 0xc4 r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 85 sfr definition 6.9. adc0lth: a dc0 less-than da ta high byte sfr definition 6.10. adc0ltl: adc0 less-than data low byte bits7?0: high byte of adc0 less-than data word. sfr page: sfr address: 0 0xc7 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 bits7?0: low byte of adc0 less-than data word. sfr page: sfr address: 0 0xc6 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 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 86 rev. 1.4 figure 6.6. 10-bit adc0 window interrupt example: right just ified single-ended data given: amx0sl = 0x00, amx0cf = 0x00 ad0ljst = ?0?, adc0lth:adc0ltl = 0x0200, adc0gth:adc0gtl = 0x0100. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x0200 and > 0x0100. given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?0?, adc0lth:adc0ltl = 0x0100, adc0gth:adc0gtl = 0x0200. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is > 0x0200 or < 0x0100. 0x03ff 0x0201 0x0200 0x01ff 0x0101 0x0100 0x00ff 0x0000 adwint=1 adwint not affected adwint not affected adc data word 0x03ff 0x0201 0x0200 0x01ff 0x0101 0x0100 0x00ff 0x0000 adwint=1 adwint not affected adwint=1 adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc0gth:adc0gtl adc0lth:adc0ltl 0 input voltage (ad0.0 - agnd) ref x (1023/1024) ref x (256/1024) ref x (512/1024) 0 input voltage (ad0.0 - agnd) ref x (1023/1024) ref x (256/1024) ref x (512/1024) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 87 figure 6.7. 10-bit adc0 window interrupt example: right justified differential data 0x01ff 0x0101 0x0100 0x00ff 0x0000 0xffff 0xfffe 0xfe00 adwint=1 adwint not affected adwint not affected 0x01ff 0x0101 0x0100 0x00ff 0x0000 0xffff 0xfffe 0xfe00 adwint=1 adwint not affected -ref input voltage (ad0.0 - ad0.1) adwint=1 ref x (511/512) adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc data word adc0lth:adc0ltl adc0gth:adc0gtl ref x (256/512) ref x (-1/512) -ref input voltage (ad0.0 - ad0.1) ref x (511/512) ref x (256/512) ref x (-1/512) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?0?, adc0lth:adc0ltl = 0x0100, adc0gth:adc0gtl = 0xffff. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x0100 and > 0xffff. (in 2s-complement math, 0xffff = -1.) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?0?, adc0lth:adc0ltl = 0xffff, adc0gth:adc0gtl = 0x0100. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0xffff or > 0x0100. (in 2s-complement math, 0xffff = -1.) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 88 rev. 1.4 figure 6.8. 10-bit adc0 window interrupt e xample: left justified single-ended data 0xffc0 0x8040 0x8000 0x7fc0 0x4040 0x4000 0x3fc0 0x0000 adwint=1 adwint not affected adwint not affected adc data word 0xffc0 0x8040 0x8000 0x7fc0 0x4040 0x4000 0x3fc0 0x0000 adwint=1 adwint not affected adwint=1 adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc0gth:adc0gtl adc0lth:adc0ltl 0 input voltage (ad0.0 - agnd) ref x (1023/1024) ref x (256/1024) ref x (512/1024) 0 input voltage (ad0.0 - agnd) ref x (1023/1024) ref x (256/1024) ref x (512/1024) given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?1?, adc0lth:adc0ltl = 0x2000, adc0gth:adc0gtl = 0x1000. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x2000 and > 0x1000. given: amx0sl = 0x00, amx0cf = 0x00, ad0ljst = ?1? adc0lth:adc0ltl = 0x1000, adc0gth:adc0gtl = 0x2000. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0x1000 or > 0x2000. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 89 figure 6.9. 10-bit adc0 window interrupt exam ple: left justifie d differential data 0x7fc0 0x2040 0x2000 0x1fc0 0x0000 0xffc0 0xff80 0x8000 adwint=1 adwint not affected adwint not affected 0x7fc0 0x2040 0x2000 0x1fc0 0x0000 0xffc0 0xff80 0x8000 adwint=1 adwint not affected -ref input voltage (ad0.0 - ad0.1) adwint=1 ref x (511/512) adc0lth:adc0ltl adc0gth:adc0gtl adc data word adc data word adc0lth:adc0ltl adc0gth:adc0gtl ref x (128/512) ref x (-1/512) -ref input voltage (ad0.0 - ad0.1) ref x (511/512) ref x (128/512) ref x (-1/512) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?1?, adc0lth:adc0ltl = 0x2000, adc0gth:adc0gtl = 0xffc0. an adc0 end of co nversion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resulti ng adc0 data word is < 0x2000 and > 0xffc0. (2s-complement math.) given: amx0sl = 0x00, amx0cf = 0x01, ad0ljst = ?1?, adc0lth:adc0ltl = 0xffc0, adc0gth:adc0gtl = 0x2000. an adc0 end of conv ersion will cause an adc0 window compare interrupt (ad0wint = ?1?) if the resultin g adc0 data word is < 0xffc0 or > 0x2000. (2s-complement math.) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 90 rev. 1.4 table 6.1. 10-bit adc0 electrical charact eristics (c8051f122/3/ 6/7 and c8051f13x) v dd = 3.0 v, av+ = 3.0 v, vref = 2.40 v (refbe = 0), pga ga in = 1, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units dc accuracy resolution 10 bits integral nonlinearity ? ? 1 lsb differential nonlinearity guaranteed monotonic ? ? 1 lsb offset error ? 0.5 ? lsb full scale error differential mode ? ?1.50.5 ? lsb offset temperature coefficient ? 0.25 ? ppm/c dynamic performance (10 khz sine-wave input, 0 to 1 db below full scale, 100 ksps signal-to-noise plus distortion 59 ? ? db total harmonic distortion up to the 5 th harmonic ? ?70 ? db spurious-free dynamic range ? 80 ? db conversion rate sar clock frequency ? ? 2.5 mhz conversion time in sar clocks 16 ? ? clocks track/hold acquisition time 1.5 ? ? s throughput rate ? ? 100 ksps analog inputs input voltage range single-ended operation 0 ? vref v *common-mode voltage range differential operation agnd ? av+ v input capacitance ? 10 ? pf temperature sensor linearity 1 ?0.2? c offset (temp = 0 c) ? 776 ? mv offset error 1,2 (temp = 0 c) ? 8.5 ? mv slope ? 2.86 ? mv/c slope error 2 ? 0.034 ? mv/c power specifications power supply current (av+ supplied to adc) operating mode, 100 ksps ? 450 900 a power supply rejection ? 0.3 ? mv/v notes: 1. includes adc offset, gain, and linearity variations. 2. represents one standard deviation from the mean. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 91 7. adc2 (8-bit adc, c8051f12x only) the c8051f12x devices include a second adc peripheral (adc2), which consists of an 8-channel, config- urable analog multiplexer, a programmable gain amplif ier, and a 500 ksps, 8-bit successive-approximation- register adc with integrated track-and-hold (see block diagram in figure 7.1). adc2 is fully 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? on page 113 . figure 7.1. adc2 functional block diagram 7.1. analog multiplexer and pga eight adc2 channels are available for measurement, as selected by the amx2sl register (see sfr defi- nition 7.2). the pga amplifies the adc2 output sig nal by an amount determin ed by the states of the amp2gn2-0 bits in the adc2 configuration register, adc2cf (sfr definition 7.3). the pga can be soft- ware-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 anal og 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 ?18.1.5. configuring port 1 pins as analog inputs? on page 240 for more informat ion on configuring the ain2 pins. 8-bit sar adc ref + - av+ 8 av+ ad2en sysclk x agnd adc2 adc2cf amp2gn0 amp2gn1 ad2sc0 ad2sc1 ad2sc2 ad2sc3 ad2sc4 amx2sl adc2cn ad2wint ad2cm0 ad2cm1 ad2cm2 ad2busy ad2int ad2tm ad2en start conversion timer 3 overflow timer 2 overflow 000 001 010 011 write to ad2busy cnvstr2 1xx write to ad0busy (synchronized with adc0) amx2ad0 amx2ad1 amx2ad2 8-to-1 amux ain2.0 (p1.0) ain2.1 (p1.1) ain2.2 (p1.2) ain2.3 (p1.3) ain2.4 (p1.4) ain2.5 (p1.5) ain2.6 (p1.6) ain2.7 (p1.7) + - + - + - + - amx2cf pin01ic pin23ic pin45ic pin67ic adc2lth adc2gth 16 dig comp ad2wint ad2cm ad2cm 8 8 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 92 rev. 1.4 7.2. adc2 modes of operation 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. the maximum adc2 conversion clock is 6 mhz. 7.2.1. starting a conversion a conversion can be initiated in one of five ways, dep ending on the programmed states of the adc2 start of conversion mode bits (ad2cm2-0) in adc2cn. conversions may be initiated by: 1. writing a ?1? to the ad2busy bit of adc2cn; 2. a timer 3 overflow (i.e. timed continuous conversions); 3. a rising edge detected on the external adc convert start signal, cnvstr2; 4. a timer 2 overflow (i.e. timed continuous conversions); 5. writing a ?1? to the ad0busy of register adc0 cn (initiate conversion of adc2 and adc0 with a single software command). during conversion, the ad2busy bit is set to logic 1 and restored to 0 when conversion is complete. the falling edge of ad2busy trigge rs an interrupt (when enabled) and sets the interrupt flag in adc2cn. con- verted data is available in the adc2 data word, adc2. when a conversion is initiated by writing a ?1? to ad2busy, it is recommended to poll ad2int to determine when the conversion is complete. the recommended procedure is: step 1. write a ?0? to ad2int; step 2. write a ?1? to ad2busy; step 3. poll ad2int for ?1?; step 4. process adc2 data. when cnvstr2 is used as a conversion start source, it must be enabled in the crossbar, and the corre- sponding pin must be set to open-drain, high-impedance mode (see section ?18. port input/output? on page 235 for more details on port i/o configuration). 7.2.2. tracking modes the ad2tm bit in register adc2cn controls the adc2 track-and-hold mode. in its default state, the adc2 input is continuously tracked, except when a conversion is in progress. when the ad2tm bit is logic 1, adc2 operates in low-power track-and-hold mode. in this mode, each conversion is preceded by a track- ing period of 3 sar clocks (after the start-of-conversion signal). when the cnvstr2 signal is used to ini- tiate conversions in low-power tracking mode, adc2 tracks only when cnvstr2 is low; conversion begins on the rising edge of cnvstr2 (see figure 7.2). tracking can also be disabled (shutdown) when the entire chip is in low power standby or sleep modes. low-power track-and-hold mode is also useful when amux or pga settings are frequently changed, due to the settling time requirements described in section ?7.2.3. settling time requirements? on page 94 . c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 93 figure 7.2. adc2 track and conversion example timing write '1' to ad2busy, timer 3 overflow, timer 2 overflow, write '1' to ad0busy (ad2cm[2:0]=000, 001, 011, 1xx) ad2tm=1 ad2tm=0 sar clocks 123456789101112 123456789 sar clocks track convert low power mode low power or convert track or convert convert track b. adc timing for internal trigger source 123456789 cnvstr2 (ad2cm[2:0]=010) ad2tm=1 a. adc timing for external trigger source sar clocks track or convert convert track ad2tm=0 track convert low power mode low power or convert c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 94 rev. 1.4 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 resis- tance, 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 ti me of 800 ns required after any mux selection. in low-power 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. 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 r total is the sum of the adc2 mux resistanc e and any external source resistance. n is the adc resoluti on in bits (8). figure 7.3. adc2 equi valent input circuit t 2 n sa ------ - ?? ?? r total c sample ? r mux = 5k rc input = r mux * c sample r mux = 5k c sample = 5pf c sample = 5pf mux select mux select differential mode ain2.x ain2.y r mux = 5k c sample = 5pf rc input = r mux * c sample mux select single-ended mode ain2.x note: when the pga gain is set to 0.5, c sample = 3pf c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 95 sfr definition 7.1. amx2cf : amux2 configuration bits7?4: unused. read = 0000b; write = don?t care. bit3: pin67ic: ain2.6, ain2.7 input pair configuration bit. 0: ain2.6 and ain2.7 are independent single-ended inputs. 1: ain2.6 and ain2.7 are (respectively) +, ? differential input pair. bit2: pin45ic: ain2.4, ain2.5 input pair configuration bit. 0: ain2.4 and ain2.5 are independent single-ended inputs. 1: ain2.4 and ain2.5 are (respectively) +, ? differential input pair. bit1: pin23ic: ain2.2, ain2.3 input pair configuration bit. 0: ain2.2 and ain2.3 are independent single-ended inputs. 1: ain2.2 and ain2.3 are (respectively) +, ? differential input pair. bit0: pin01ic: ain2.0, ain2.1 input pair configuration bit. 0: ain2.0 and ain2.1 are independent single-ended inputs. 1: ain2.0 and ain2.1 are (respectively) +, ? differential input pair. note: the adc2 data word is in 2?s complement format for channels configured as differential. sfr page: sfr address: 2 0xba r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - pin67ic pin45ic pin23ic pin01ic 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 96 rev. 1.4 sfr definition 7.2. amx2sl: amux2 channel select bits7?3: unused. read = 00000b; write = don?t care. bits2?0: amx2ad2?0: amx2 address bits. 000-111b: adc inputs selected per chart below. sfr page: sfr address: 2 0xbb r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - amx2ad2 amx2ad1 amx2ad0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 amx2ad2?0 000 001 010 011 100 101 110 111 amx2cf bits 3?0 0000 ain2.0 ain2.1 ain2.2 ain2.3 ain2.4 ain2.5 ain2.6 ain2.7 0001 +(ain2.0) ?(ain2.1) ain2.2 ain2.3 ain2.4 ain2.5 ain2.6 ain2.7 0010 ain2.0 ain2.1 +(ain2.2) ?(ain2.3) ain2.4 ain2.5 ain2.6 ain2.7 0011 +(ain2.0) ?(ain2.1) +(ain2.2) ?(ain2.3) ain2.4 ain2.5 ain2.6 ain2.7 0100 ain2.0 ain2.1 ain2.2 ain2.3 +(ain2.4) ?(ain2.5) ain2.6 ain2.7 0101 +(ain2.0) ?(ain2.1) ain2.2 ain2.3 +(ain2.4) ?(ain2.5) ain2.6 ain2.7 0110 ain2.0 ain2.1 +(ain2.2) ?(ain2.3) +(ain2.4) ?(ain2.5) ain2.6 ain2.7 0111 +(ain2.0) ?(ain2.1) +(ain2.2) ?(ain2.3) +(ain2.4) ?(ain2.5) ain2.6 ain2.7 1000 ain2.0 ain2.1 ain2.2 ain2.3 ain2.4 ain2.5 +(ain2.6) ?(ain2.7) 1001 +(ain2.0) ?(ain2.1) ain2.2 ain2.3 ain2.4 ain2.5 +(ain2.6) ?(ain2.7) 1010 ain2.0 ain2.1 +(ain2.2) ?(ain2.3) ain2.4 ain2.5 +(ain2.6) ?(ain2.7) 1011 +(ain2.0) ?(ain2.1) +(ain2.2) ?(ain2.3) ain2.4 ain2.5 +(ain2.6) ?(ain2.7) 1100 ain2.0 ain2.1 ain2.2 ain2.3 +(ain2.4) ?(ain2.5) +(ain2.6) ?(ain2.7) 1101 +(ain2.0) ?(ain2.1) ain2.2 ain2.3 +(ain2.4) ?(ain2.5) +(ain2.6) ?(ain2.7) 1110 ain2.0 ain2.1 +(ain2.2) ?(ain2.3) +(ain2.4) ?(ain2.5) +(ain2.6) ?(ain2.7) 1111 +(ain2.0) ?(ain2.1) +(ain2.2) ?(ain2.3) +(ain2.4) ?(ain2.5) +(ain2.6) ?(ain2.7) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 97 sfr definition 7.3. adc2cf : adc2 configuration bits7?3: ad2sc4?0: adc2 sar c onversion clock period bits. sar conversion clock is derived from syste m clock by the following equation, where ad2sc refers to the 5-bit value held in ad2sc4?0, and clk sar2 refers to the desired adc2 sar clock (note: the adc2 sar conversion clock should be less than or equal to 6mhz). bit2: unused. read = 0b ; write = don?t care. bits1?0: amp2gn1?0: adc2 internal amplifier gain (pga). 00: gain = 0.5 01: gain = 1 10: gain = 2 11: gain = 4 sfr page: sfr address: 2 0xbc r/w r/w r/w r/w r/w r/w r/w r/w reset value ad2sc4 ad2sc3 ad2sc2 ad2sc1 ad2sc0 - amp2gn1 amp2gn0 11111000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 ad 2 sc sysclk clk sar 2 ------------ ---------- - 1? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 98 rev. 1.4 sfr definition 7.4. adc2cn: adc2 control bit7: ad2en: adc2 enable bit. 0: adc2 disabled. adc2 is in low-power shutdown. 1: adc2 enabled. adc2 is active and ready for data conversions. bit6: ad2tm: adc2 track mode bit. 0: normal track mode: when adc2 is enabled , tracking is continuous unless a conversion is in process. 1: low-power track mode: tracking defined by ad2cm2-0 bits (see below). bit5: ad2int: adc2 conversion complete interrupt flag. this flag must be cleared by software. 0: adc2 has not completed a data conversion since the last time this flag was cleared. 1: adc2 has completed a data conversion. bit4: ad2busy: adc2 busy bit. read: 0: adc2 conversion is complete or a conversion is not currently in progress. ad2int is set to logic 1 on the falling edge of ad2busy. 1: adc2 conversion is in progress. write: 0: no effect. 1: initiates adc2 conversion if ad2cm2-0 = 000b bits3?1: ad2cm2?0: adc2 start of conversion mode select. ad2tm = 0: 000: adc2 conversion initiated on every write of ?1? to ad2busy. 001: adc2 conversion initiated on overflow of timer 3. 010: adc2 conversion initiated on rising edge of external cnvstr2. 011: adc2 conversion initiated on overflow of timer 2. 1xx: adc2 conversion initiated on write of ?1 ? to ad0busy ( synchronized with adc0 soft- ware-commanded conversions). ad2tm = 1: 000: tracking initiated on write of ?1? to ad2busy for 3 sar2 clocks, followed by conver- sion. 001: tracking initiated on overflow of time r 3 for 3 sar2 clocks, followed by conversion. 010: adc2 tracks only when cnvstr2 input is logic low; conversion starts on rising cnvstr2 edge. 011: tracking initiated on overflow of ti mer 2 for 3 sar2 clocks, followed by conversion. 1xx: tracking initiated on wr ite of ?1? to ad0busy and lasts 3 sar2 clocks, followed by con- version. bit0: ad2wint: adc2 window compare interrupt flag. this bit must be cleared by software. 0: adc2 window comparison data match has no t occurred since this flag was last cleared. 1: adc2 window comparison data match has occurred. sfr page: sfr address: 2 0xe8 (bit addressable) r/w r/w r/w r/w r/w r/w r/w r/w reset value ad2en ad2tm ad2int ad2busy ad2cm 2 ad2cm1 ad2cm0 ad2wint 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 99 sfr definition 7.5. adc2: adc2 data word figure 7.4. adc2 data word example bits7?0: adc2 data word. sfr page: sfr address: 2 0xbe 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 single-ended example: 8-bit adc data word appears in the adc2 data word register as follows: example: adc2 data word conversion map, single-ended ain2.0 input (amx2cf = 0x00; amx2sl = 0x00) differential example: 8-bit adc data word appears in the adc2 data word register as follows: example: adc2 data word conversion map, differential ain2.0-ain2.1 input (amx2cf = 0x01; amx2sl = 0x00) ain2.0?agnd (volts) adc2 vref * (255/256) 0xff vref * (128/256) 0x80 vref * (64/256) 0x40 00x00 ain2.0?ain2.1 (volts) adc2 vref * (127/128) 0x7f vref * (64/128) 0x40 00x00 ?vref * (64/128) 0xc0 (-64d) ?vref * (128/128) 0x80 (-128d) code vin gain vref --------------- ? 256 ? = code vin gain 2 v ? ref ------------------------ - ? 256 ? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 100 rev. 1.4 7.3. adc2 programmable window detector the adc2 programmable window detector continuously compares the adc2 output to user-programmed limits, and notifies the system when a desired condition is detected. this is especia lly effective in an inter- rupt-driven system, saving code sp ace and cpu bandwidth while deliver ing faster system response times. the window detector interrupt flag (ad2wint in register adc2cn) can also be used in polled mode. the adc2 greater-than (adc2gt) and less-than (adc2lt) registers hold the comparison values. example comparisons for differential and single-ended modes are shown in figure 7.6 and figure 7.5, respectively. notice that the window detector flag can be programmed to indicate when measured data is inside or out- side of the user-programmed limits, depending on the contents of the adc2lt and adc2gt registers. 7.3.1. window detector in single-ended mode figure 7.5 shows two example window comparisons for single-ended mode, with adc2lt = 0x20 and adc2gt = 0x10. notice that in single-ended mode, the codes vary from 0 to vref*(255/256) and are represented as 8-bit unsig ned integers. in the left example, an ad2wint interrup t will be genera ted if the adc2 conversion word (adc2) is within the range defined by adc2gt and adc2lt (if 0x10 ? adc2 ? 0x20). in the right example, and ad2wint interrup t will be generated if adc2 is outside of the range defined by adc2gt and adc2lt (if adc2 ? 0x10 or adc2 ? 0x20). figure 7.5. adc2 window compare examples, single-ended mode 0xff 0x21 0x20 0x1f 0x11 0x10 0x0f 0x00 0 input voltage (ain2.x - agnd) ref x (255/256) ref x (32/256) ref x (16/256) ad2wint=1 ad2wint not affected ad2wint not affected adc2lt adc2gt 0xff 0x21 0x20 0x1f 0x11 0x10 0x0f 0x00 0 input voltage (ain2.x - agnd) ref x (255/256) ref x (32/256) ref x (16/256) ad2wint not affected adc2gt adc2lt ad2wint=1 ad2wint=1 adc2 adc2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 101 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 mo de, the codes vary from -vref to vref*(127/128) and are represented as 8-bit 2?s complement signed integers. in the left example, an ad2wint interrupt will be generated if the adc2 conversion word (adc2l) is with in the range defined by adc2gt and adc2lt (if 0xff (-1d) < adc2 < 0x0f (16d)). in the right example, an ad2wint interrupt will be gener- ated if adc2 is outside of the range defined by adc2gt and adc2lt (if adc2 < 0xff (-1d) or adc2 > 0x10 (+16d)). figure 7.6. adc2 window compare examples, differential mode 0x7f (127d) 0x11 (17d) 0x10 (16d) 0x0f (15d) 0x00 (0d) 0xff (-1d) 0xfe (-2d) 0x80 (-128d) -ref input voltage (ain2.x - ain2.y) ref x (127/128) ref x (16/128) ref x (-1/256) 0x7f (127d) 0x11 (17d) 0x10 (16d) 0x0f (15d) 0x00 (0d) 0xff (-1d) 0xfe (-2d) 0x80 (-128d) -ref input voltage (ain2.x - ain2.y) ref x (127/128) ref x (16/128) ref x (-1/256) ad2wint=1 ad2wint not affected ad2wint not affected adc2lt adc2gt ad2wint not affected adc2gt adc2lt ad2wint=1 ad2wint=1 adc2 adc2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 102 rev. 1.4 sfr definition 7.6. adc2gt: a dc2 greater-than data byte sfr definition 7.7. adc2lt: adc2 less-than data byte bits7?0: adc2 greater-than data word. sfr page: sfr address: 2 0xc4 r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bits7?0: adc2 less-than data word. sfr page: sfr address: 2 0xc6 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 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 103 table 7.1. adc2 electric al characteristics v dd = 3.0 v, av+ = 3.0 v, vref2 = 2.40 v (refbe = 0), pga ga in = 1, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units dc accuracy resolution 8 bits integral nonlinearity ? ? 1 lsb differential nonlinearity guaranteed monotonic ? ? 1 lsb offset error ? 0.50.3 ? lsb full scale error differential mode ? ?10.2 ? lsb offset temperature coefficient ? 10 ? ppm/c dynamic performance (10 khz sine-wave input, 1 db below full scale, 500 ksps signal-to-noise plus distortion 45 47 ? db total harmonic distortion up to the 5 th harmonic ?-51? db spurious-free dynamic range ? 52 ? db conversion rate sar clock frequency ? ? 6 mhz conversion time in sar clocks 8 ? ? clocks track/hold acquisition time 300 ? ? ns throughput rate ? ? 500 ksps analog inputs input voltage range 0 ? vref v input capacitance ? 5 ? pf power specifications power supply current (av+ supplied to adc2) operating mode, 500 ksps ? 420 900 a power supply rejection ? 0.3 ? mv/v c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 104 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 105 8. dacs, 12-bit voltage mode (c8051f12x only) the c8051f12x 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-1lsb) for a corresponding input code range of 0x000 to 0xfff. the dacs may be enabled/disabled via th eir corresponding contro l 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 (c8051f120/2/4/6 devices) or the vref pin (c8051 f121/3/5/7 devices). note that the vref pin on c8051f121/3/5/7 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? on page 113 for more information on configuring the voltage reference for the dacs. 8.1. dac output scheduling each dac features a flexible output update mechan ism which allows for seam less full-scale changes and supports jitter-free update s for waveform generation. the following ex amples are written in terms of dac0, but dac1 operation is identical. figure 8.1. dac functional block diagram dac0 av+ 12 agnd 8 8 ref dac0 dac0cn dac0en dac0md1 dac0md0 dac0df2 dac0df1 dac0df0 dac0h dac0l dig. mux latch latch 8 8 dac1 av+ 12 agnd 8 8 ref dac1 dac1cn dac1en dac1md1 dac1md0 dac1df2 dac1df1 dac1df0 dac1h dac1l dig. mux latch latch 8 8 dac0h timer 3 timer 4 timer 2 dac1h timer 3 timer 4 timer 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 106 rev. 1.4 8.1.1. update output on-demand in its default mode (dac0cn.[4:3] = ?00?) the dac0 output is updated ?on-demand? on a write to the high- byte of the dac0 data register (dac0h). it is import ant to note that writes to dac0l are held, and have no effect on the dac0 output until a write to dac0h take s place. if writing a full 12-bit word to the dac data registers, the 12-bit data word is written to the low byte (dac0l) and high by te (dac0h) data registers. data is latched into dac0 after a write to the corresponding dac0h register, so the write sequence should be dac0l followed by dac0h if the full 12-bit resolution is required. the dac can be used in 8- bit mode by initializing dac0l to th e desired value (typically 0x00), a nd writing data to only dac0h (also see section 8.2 for information on formatting the 12-bit dac data word within the 16-bit sfr space). 8.1.2. update output based on timer overflow similar to the adc operation, in which an adc conv ersion can be initiated by a timer overflow indepen- dently of the processor, the dac outputs can use a timer overflow to schedule an output update event. this feature is useful in systems where the dac is used to generate a waveform of a defined sampling rate by eliminating the effects of variable interrupt latenc y and instruction execution on the timing of the dac output. when the dac0md bits (dac0cn.[4:3]) are set to ?01?, ?10?, or ?11?, writes to both dac data regis- ters (dac0l and dac0h) are held until an associated timer overflow event (timer 3, timer 4, or timer 2, respectively) occurs, at which time the dac0h:dac0l contents are copied to the dac input latches allow- ing the dac output to change to the new value. 8.2. dac output scaling/justification in some instances, input data should be shifted prior to a dac0 write operation to properly justify data within the dac input registers. this action would typi cally require one or more load and shift operations, adding software overhead and slowing dac throughput. to alleviate this problem, the data-formatting fea- ture 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 abov e. the electrical specific ations for both dac0 and dac1 are given in table 8.1. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 107 sfr definition 8.1. dac0h: dac0 high byte sfr definition 8.2. dac0l: dac0 low byte bits7?0: dac0 data word most significant 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: sfr page: 0xd3 0 bits7?0: dac0 data word least significant 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: sfr page: 0xd2 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 108 rev. 1.4 sfr definition 8.3. dac0cn: dac0 control bit7: dac0en: dac0 enable bit. 0: dac0 disabled. dac0 output pin is disabled; dac0 is in low-power shutdown mode. 1: dac0 enabled. dac0 output pin is active; dac0 is operational. bits6?5: unused. read = 00b; write = don?t care. bits4?3: dac0md1?0: dac0 mode bits. 00: dac output updates occur on a write to dac0h. 01: dac output updates occur on timer 3 overflow. 10: dac output updates occur on timer 4 overflow. 11: dac output updates occur on timer 2 overflow. bits2?0: dac0df2?0: dac0 data format bits: 000: the most significant nibble of the dac0 data word is in dac0h[3:0], while the least significant byte is in dac0l. 001: the most significant 5-bits of the dac0 data word is in dac0 h[4:0], while the least significant 7-bits are in dac0l[7:1]. 010: the most significant 6-bits of the dac0 data word is in dac0 h[5:0], while the least significant 6-bits are in dac0l[7:2]. 011: the most significant 7-bits of the dac0 data word is in dac0 h[6:0], while the least significant 5-bits are in dac0l[7:3]. 1xx: the most significant 8-bits of the dac0 data word is in dac0 h[7:0], while the least significant 4-bits are in dac0l[7:4]. r/w r/w r/w r/w r/w r/w r/w r/w reset value dac0en - - dac0md1 dac0md0 dac0df2 dac0df1 dac0df0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xd4 0 dac0h dac0l msb lsb dac0h dac0l msb lsb dac0h dac0l msb lsb dac0h dac0l msb lsb dac0h dac0l msb lsb c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 109 sfr definition 8.4. dac1h: dac1 high byte sfr definition 8.5. dac1l: dac1 low byte bits7?0: dac1 data word most significant 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: sfr page: 0xd3 1 bits7?0: dac1 data word least significant 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: sfr page: 0xd2 1 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 110 rev. 1.4 sfr definition 8.6. dac1cn: dac1 control bit7: dac1en: dac1 enable bit. 0: dac1 disabled. dac1 output pin is disabled; dac1 is in low-power shutdown mode. 1: dac1 enabled. dac1 output pin is active; dac1 is operational. bits6?5: unused. read = 00b; write = don?t care. bits4?3: dac1md1?0: dac1 mode bits: 00: dac output updates occur on a write to dac1h. 01: dac output updates occur on timer 3 overflow. 10: dac output updates occur on timer 4 overflow. 11: dac output updates occur on timer 2 overflow. bits2?0: dac1df2: dac1 data format bits: 000: the most significant nibble of the dac1 data word is in dac1h[3:0], while the least significant byte is in dac1l. 001: the most significant 5-bits of the dac1 data word is in dac1 h[4:0], while the least significant 7-bits are in dac1l[7:1]. 010: the most significant 6-bits of the dac1 data word is in dac1 h[5:0], while the least significant 6-bits are in dac1l[7:2]. 011: the most significant 7-bits of the dac1 data word is in dac1 h[6:0], while the least significant 5-bits are in dac1l[7:3]. 1xx: the most significant 8-bits of the dac1 data word is in dac1 h[7:0], while the least significant 4-bits are in dac1l[7:4]. r/w r/w r/w r/w r/w r/w r/w r/w reset value dac1en - - dac1md1 dac1md0 dac1df2 dac1df1 dac1df0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xd4 1 dac1h dac1l msb lsb dac1h dac1l msb lsb dac1h dac1l msb lsb dac1h dac1l msb lsb dac1h dac1l msb lsb c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 111 . table 8.1. dac electri cal characteristics v dd = 3.0 v, av+ = 3.0 v, vref = 2.40 v (refbe = 0) , no output load unless otherwise specified parameter conditions min typ max units static performance resolution 12 bits integral nonlinearity ? 1.5 ? lsb differential nonlinearity ? ? 1 lsb output noise no output filter 100 khz output filter 10 khz output filter ?250 128 41 ?vrms offset error data word = 0x014 ? 3 30 mv offset tempco ? 6 ? ppm/c full-scale error ? 20 60 mv full-scale error tempco ? 10 ? ppm/c v dd power supply rejection ratio ??60? db output impedance in shutdown mode dacnen = 0 ?100? k ? output sink current ? 300 ? a output short-circuit current data word = 0xfff ? 15 ? ma dynamic performance voltage output slew rate load = 40 pf ? 0.44 ? v/s output settling time to 1/2 lsb load = 40 pf, output swing from code 0xfff to 0x014 ?10? s output voltage swing 0 ? vref- 1lsb v startup time ? 10 ? s analog outputs load regulation i l = 0.01 ma to 0.3 ma at code 0xfff ?60? ppm power consumption (each dac) power supply current (av+ supplied to dac) data word = 0x7ff ?110400 a c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 112 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 113 9. voltage reference the voltage reference options available on the c8051f12x and c8051f13x device families vary according to the device capabilities. all devices include an internal voltage reference circ uit, consisting of a 1.2 v, 15 ppm/c (typical) bandgap voltage reference generator and a gain-of-two output buffer amplifier. the internal reference may be routed via the vref pin to external system components or to the voltage reference input pins. the maximum load seen by the vref pin must be less than 200 a to agnd. bypass capacitors of 0.1 f and 4.7 f are rec- ommended from the vref pin to agnd. the reference control register, ref0cn enables/disab les the internal reference generator and the inter- nal temperature sensor on all devices. the biase bit in ref0cn enables the on-board reference genera- tor while the refbe bit enables the gain-of-two bu ffer 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 ref- erence 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. no te that the biase bit must be set to logic 1 if any dacs or adcs are used, regardless of whether the voltage reference is derived from the on-chip reference or supplied by an off-chip source. if no adcs or dacs are being used, both of these bits can be set to logic 0 to conserve power. when enabled, the temperature sensor connects to the highest order input of the adc0 input multiplexer. the tempe bit within ref0cn enables and disables the temperature sensor. while disabled, the temper- ature sensor defaults to a high impedance state. any adc measurements performed on the sensor while disabled will result in undefined data. the electrical specifications for the internal voltage reference are given in table 9.1. 9.1. reference configurat ion on the c8051f120/2/4/6 on the c8051f120/2/4/6 devices, th e ref0cn register also allows selection of the voltage reference source for adc0 and adc2, as show n in sfr definition 9.1. bits ad0vrs and ad2vrs in the ref0cn register select the adc0 and adc2 voltage reference sources, respectively. three voltage reference input pins allow each adc and the two dacs to reference an external voltage reference or the on-chip voltage reference output (with an external connection). adc0 may also reference the dac0 output internally, and adc2 may reference the analog power supply voltage, via the vref multiplexe rs shown in figure 9.1. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 114 rev. 1.4 figure 9.1. voltage reference function al block diagram (c8051f120/2/4/6) sfr definition 9.1. ref0cn: refe rence control (c8051f120/2/4/6) recommended bypass capacitors x2 vref dac0 dac1 ref vrefd av+ adc2 adc0 vref2 ref ref 1 0 0 1 vref0 4.7 ? f0 . 1 ? f external voltage reference circuit r1 vdd dgnd ref0cn refbe biase tempe ad2vrs ad0vrs refbe biase bias to adcs, dacs 1.2v band-gap en + bits7?5: unused. read = 000b; write = don?t care. bit4: ad0vrs: adc0 volt age reference select. 0: adc0 voltage reference from vref0 pin. 1: adc0 voltage reference from dac0 output. bit3: ad2vrs: adc2 volt age reference select. 0: adc2 voltage reference from vref2 pin. 1: adc2 voltage reference from av+. bit2: tempe: temperature sensor enable bit. 0: internal temperature sensor off. 1: internal temperature sensor on. bit1: biase: adc/dac bias gene rator enable bit. (must be ?1? if using adc, dac, or vref). 0: internal bias generator off. 1: internal bias generator on. bit0: refbe: internal refe rence buffer enable bit. 0: internal reference buffer off. 1: internal reference buffer on. internal voltage reference is driven on the vref pin. sfr page: sfr address: 0 0xd1 r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - ad0vrs ad2vrs tem pe biase refbe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 115 9.2. reference configurat ion on the c8051f121/3/5/7 on the c8051f121/3/5/7 devices, th e ref0cn register also allows selection of the voltage reference source for adc0 and adc2, as show n in sfr definition 9.2. bits ad0vrs and ad2vrs in the ref0cn register select the adc0 and adc2 voltage reference sources, respectively. the vrefa pin provides a voltage reference input for adc0 and adc2, which ca n be connected to an exter nal precision reference or the internal voltage reference. adc0 may also reference the dac0 output internally, and adc2 may refer- ence the analog power supply voltage, via the vref multiplexers shown in figure 9.2. figure 9.2. voltage reference function al block diagram (c8051f121/3/5/7) recommended bypass capacitors x2 vref dac0 dac1 ref av+ adc2 adc0 ref ref 1 0 0 1 vrefa 4.7 ? f0 . 1 ? f external voltage reference circuit r1 vdd dgnd ref0cn refbe biase tempe ad2vrs ad0vrs refbe biase bias to adcs, dacs 1.2v band-gap en + c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 116 rev. 1.4 sfr definition 9.2. ref0cn: refe rence control (c8051f121/3/5/7) bits7?5: unused. read = 000b; write = don?t care. bit4: ad0vrs: adc0 volt age reference select. 0: adc0 voltage reference from vrefa pin. 1: adc0 voltage reference from dac0 output. bit3: ad2vrs: adc2 volt age reference select. 0: adc2 voltage reference from vrefa pin. 1: adc2 voltage reference from av+. bit2: tempe: temperature sensor enable bit. 0: internal temperature sensor off. 1: internal temperature sensor on. bit1: biase: adc/dac bias gene rator enable bit. (must be ?1? if using adc, dac, or vref). 0: internal bias generator off. 1: internal bias generator on. bit0: refbe: internal refe rence buffer enable bit. 0: internal reference buffer off. 1: internal reference buffer on. internal voltage reference is driven on the vref pin. sfr page: sfr address: 0 0xd1 r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - ad0vrs ad2vrs tempe biase refbe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 117 9.3. reference configurat ion on the c8051f130/1/2/3 on the c8051f130/1/2/3 devices, the vref0 pin provides a voltage reference input for adc0, which can be connected to an external precision reference or t he internal voltage reference, as shown in figure 9.3. the ref0cn register for the c8051f130/1/2/3 is described in sfr definition 9.3. figure 9.3. voltage reference function al block diagram (c8051f130/1/2/3) sfr definition 9.3. ref0cn: refe rence control (c8051f130/1/2/3) recommended bypass capacitors x2 vref adc0 ref vref0 4.7 ? f0 . 1 ? f external voltage reference circuit r1 vdd dgnd bias to adc 1.2v band-gap en + ref0cn refbe biase tempe bits7?5: unused. read = 000b; write = don?t care. bits4?3: reserved: must be written to 0. bit2: tempe: temperature sensor enable bit. 0: internal temperature sensor off. 1: internal temperature sensor on. bit1: biase: adc/dac bias ge nerator enable bit. (must be ?1? if using adc or vref). 0: internal bias generator off. 1: internal bias generator on. bit0: refbe: internal refe rence buffer enable bit. 0: internal reference buffer off. 1: internal reference buffer on. internal voltage reference is driven on the vref pin. sfr page: sfr address: 0 0xd1 r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - reserved reserved tempe biase refbe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 118 rev. 1.4 table 9.1. voltage referen ce electrical characteristics v dd = 3.0 v, av+ = 3.0 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units analog bias generator power supply current biase = 1 ?100 ? a internal reference (refbe = 1) output voltage 25 c ambient 2.36 2.43 2.48 v vref short-circuit current ? ? 30 ma vref temperature coefficient ? 15 ? ppm/c load regulation load = 0 to 200 a to agnd ? 0.5 ? ppm/a vref turn-on time 1 4.7 f tantalum, 0.1 f ceramic bypass ?2 ? ms vref turn-on time 2 0.1 f ceramic bypass ? 20 ? s vref turn-on time 3 no bypass cap ? 10 ? s reference buffer power sup- ply current ?40 ? a power supply reje ction ? 140 ? ppm/v external reference (refbe = 0) input voltage range 1.00 ? (av+) ? 0.3 v input current ? 0 1 a c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 119 10. comparators two on-chip programmable voltage comparators are included, as shown in figure 10.1. the inputs of each comparator are available at dedicated pins. the output of each comparator is optionally available at the package pins via the i/o crossbar. when assigned to package pins, each comparator output can be pro- grammed to operate in open drain or push-pull modes. see section ?18.1. ports 0 through 3 and the priority crossbar decoder? on page 238 for crossbar and port initialization details. figure 10.1. comparator functional block diagram + - q q set clr d q q set clr d crossbar interrupt handler reset decision tree (synchronizer) cp0+ cp0- agnd cpt0cn cp0hyn0 cp0md cp0hyn1 cp0hyp0 cp0hyp1 cp0fif cp0rif cp0out cp0en av+ cpt0md cp0md0 cp0md1 cp0fie cp0rie cp0md + - q q set clr d q q set clr d crossbar interrupt handler (synchronizer) cp1+ cp1- agnd cpt1cn cp1hyn0 cp1md cp1hyn1 cp1hyp0 cp1hyp1 cp1fif cp1rif cp1out cp1en av+ cpt1md cp1md0 cp1md1 cp1fie cp1rie cp1md c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 120 rev. 1.4 comparator interrupts can be generat ed on rising-edge and/or falling-edge output transitions. (for inter- rupt enable and priority control, see section ?11.3. interrupt handler? on page 154 ). the cp0fif flag is set upon a comparator0 falling-edge in terrupt, and the cp0rif flag is set upon the co mparator0 rising- edge interrupt. once set, these bits remain set until cleared by software. the output state of comparator0 can be obtained at any time by reading the cp0out bit. comparator0 is enabled by setting the cp0en bit to logic 1, and is disabled by clearing this bit to logic 0. comparator0 can also be programmed as a reset source; for details, see section ? 13.5. comparator0 reset ? on page 179 . note that after being enabled, there is a power-up ti me (listed in table 10.1) during which the comparator outputs stabilize. the states of th e rising-edge and falling- edge flags are indetermi nant after comparator power-up and should be explicitly cleared before t he comparator interrupts are enabled or the compara- tors are configured as a reset source. comparator0 response time may be configured in software via the cp0md1-0 bits in register cpt0md (see sfr definition 10.2). selecting a longer respon se time reduces the amount of current consumed by comparator0. see table 10.1 for complete timing and current consumption specifications. the hysteresis of each comparator is software-progr ammable via its respective comparator control regis- ter (cpt0cn and cpt1cn for comparator0 and comparator1, respectively). the user can program both the amount of hysteresis voltage (referred to the in put voltage) and the positive and negative-going sym- metry of this hysteresis around the threshold voltage. the output of the comparator can be polled in soft- ware, or can be used as an interrupt source. each comparator can be individually enabled or disabled (shutdown). when disabled, the comparator output (if assigned to a port i/o pin via the crossbar) defaults to the logic low state, it s interrupt capability is su spended and its supply curr ent falls to less than 100 na. comparator inputs can be externally driven from ?0.25 v to (av+) + 0.25 v without damage or upset. comparator0 hysteresis is programmed using bits 3-0 in the comparator0 control register cpt0cn (shown in sfr definition 10.1). the amount of negative hysteresis voltage is determined by the settings of the cp0hyn bits. as shown in sfr definition 10.1, the negative hysteresis can be programmed to three different settings, or negative hysteresis can be disabled. in a similar way, the amount of positive hystere- sis is determined by the setting the cp0hyp bits. the operation of comparator1 is identical to that of comparator0, though comparator1 may not be config- ured as a reset source. comparator1 is controlled by the cpt1cn register (sfr definition 10.3) and the cpt1md register (sfr definition 10.4). the complete electrical specifications for the comparators are given in table 10.1. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 121 figure 10.2. comparator hysteresis plot positive hysteresis voltage (programmed with cp0hyp bits) negative hysteresis voltage (programmed by cp0hyn bits) vin- vin+ inputs circuit configuration + _ cp0+ cp0- cp0 vin+ vin- out v oh positive hysteresis disabled maximum positive hysteresis negative hysteresis disabled maximum negative hysteresis output v ol c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 122 rev. 1.4 sfr definition 10.1. cpt0cn: comparator0 control bit7: cp0en: comparator0 enable bit. 0: comparator0 disabled. 1: comparator0 enabled. bit6: cp0out: comparator0 output state flag. 0: voltage on cp0+ < cp0?. 1: voltage on cp0+ > cp0?. bit5: cp0rif: comparator0 rising-edge flag. 0: no comparator0 rising edge has occurred since this flag was last cleared. 1: comparator0 rising edge has occurred. bit4: cp0fif: comparat or0 falling-edge flag. 0: no comparator0 falling-e dge has occurred since this flag was last cleared. 1: comparator0 falling-edge has occurred. bits3?2: cp0hyp1?0: comparator0 positive hysteresis control bits. 00: positive hysteresis disabled. 01: positive hysteresis = 5 mv. 10: positive hysteresis = 10 mv. 11: positive hysteresis = 15 mv. bits1?0: cp0hyn1?0: comparator0 nega tive hysteresis control bits. 00: negative hysteresis disabled. 01: negative hysteresis = 5 mv. 10: negative hysteresis = 10 mv. 11: negative hysteresis = 15 mv. sfr page: sfr address: 1 0x88 r/w r/w r/w r/w r/w r/w r/w r/w reset value cp0en cp0out cp0rif cp0fif cp0hyp1 cp0hyp0 cp0hyn1 cp0hyn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 123 sfr definition 10.2. cpt0md: co mparator0 mode selection bits7?6: unused. read = 00b, write = don?t care. bit 5: cp0rie: comparator 0 rising-edge interrupt enable bit. 0: comparator 0 rising-edge interrupt disabled. 1: comparator 0 rising-edge interrupt enabled. bit 4: cp0fie: comparator 0 fallin g-edge interrupt enable bit. 0: comparator 0 falling-ed ge interrup t disabled. 1: comparator 0 falling- edge interr upt enabled. bits3?2: unused. read = 00b, write = don?t care. bits1?0: cp0md1?cp0md0: comparator0 mode select these bits select the response time for comparator0. sfr page: sfr address: 1 0x89 r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cp0rie cp0fie - - cp0md1 cp0md0 00000010 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 mode cp0md1 cp0md0 notes 0 0 0 fastest response time 101 ? 210 ? 3 1 1 lowest power consumption c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 124 rev. 1.4 sfr definition 10.3. cpt1cn: comparator1 control bit7: cp1en: comparator1 enable bit. 0: comparator1 disabled. 1: comparator1 enabled. bit6: cp1out: comparator1 output state flag. 0: voltage on cp1+ < cp1?. 1: voltage on cp1+ > cp1?. bit5: cp1rif: comparator1 rising-edge flag. 0: no comparator1 rising edge has occurred since this flag was last cleared. 1: comparator1 rising edge has occurred. bit4: cp1fif: comparat or1 falling-edge flag. 0: no comparator1 falling-e dge has occurred since this flag was last cleared. 1: comparator1 falling-edge interrupt has occurred. bits3?2: cp1hyp1?0: comparator1 positive hysteresis control bits. 00: positive hysteresis disabled. 01: positive hysteresis = 5 mv. 10: positive hysteresis = 10 mv. 11: positive hysteresis = 15 mv. bits1?0: cp1hyn1?0: comparator1 nega tive hysteresis control bits. 00: negative hysteresis disabled. 01: negative hysteresis = 5 mv. 10: negative hysteresis = 10 mv. 11: negative hysteresis = 15 mv. sfr page: sfr address: 2 0x88 r/w r/w r/w r/w r/w r/w r/w r/w reset value cp1en cp1out cp1rif cp1fif cp1hyp1 cp1hyp0 cp1hyn1 cp1hyn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 125 sfr definition 10.4. cpt1md: co mparator1 mode selection bits7?6: unused. read = 00b, write = don?t care. bit 5: cp1rie: comparator 1 rising-edge interrupt enable bit. 0: comparator 1 rising-edge interrupt disabled. 1: comparator 1 rising-edge interrupt enabled. bit 4: cp1fie: comparator 0 fallin g-edge interrupt enable bit. 0: comparator 1 falling-ed ge interrup t disabled. 1: comparator 1 falling- edge interr upt enabled. bits3?2: unused. read = 00b, write = don?t care. bits1?0: cp1md1?cp1md0: comparator1 mode select these bits select the response time for comparator1. sfr page: sfr address: 2 0x89 r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cp1rie cp1fie - - cp1md1 cp1md0 00000010 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 mode cp0md1 cp0md0 notes 0 0 0 fastest response time 101 ? 210 ? 3 1 1 lowest power consumption c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 126 rev. 1.4 table 10.1. comparator el ectrical characteristics v dd = 3.0 v, av+ = 3.0 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units response time: mode 0, v cm * = 1.5 v cpn+ ? cpn- = 100 mv ? 100 ? ns cpn+ ? cpn? = ?100 mv ? 250 ? ns response time: mode 1, v cm * = 1.5 v cpn+ ? cpn? = 100 mv ? 175 ? ns cpn+ ? cpn? = ?100 mv ? 500 ? ns response time: mode 2, v cm * = 1.5 v cpn+ ? cpn? = 100 mv ? 320 ? ns cpn+ ? cpn? = ?100 mv ? 1100 ? ns response time: mode 3, v cm * = 1.5 v cpn+ ? cpn? = 100 mv ? 1050 ? ns cpn+ ? cpn? = ?100 mv ? 5200 ? ns common-mode rejection ratio ? 1.5 4 mv/v positive hysteresis 1 cpnhyp1-0 = 00 ? 0 1 mv positive hysteresis 2 c pnhyp1-0 = 01 2 4.5 7 mv positive hysteresis 3 cpnhyp1-0 = 10 4 9 13 mv positive hysteresis 4 cpnhyp1-0 = 11 10 17 25 mv negative hysteresis 1 cpnhyn1-0 = 00 ? 0 1 mv negative hysteresis 2 cpnhyn1-0 = 01 2 4.5 7 mv negative hysteresis 3 cpnhyn1-0 = 10 4 9 13 mv negative hysteresis 4 cpnhyn1-0 = 11 10 17 25 mv inverting or non-inverting input voltage range ?0.25 ? (av+) + 0.25 v input capacitance ? 7 ? pf input bias current ?5 0.001 +5 na input offset voltage ?10 ? +10 mv power supply power-up time cpnen from 0 to 1 ? 20 ? s power supply re jection ? 0.1 1 mv/v supply current at dc (each comparator) mode 0 ? 7.6 ? a mode 1 ? 3.2 ? a mode 2 ? 1.3 ? a mode 3 ? 0.4 ? a *note: v cm is the common-mode voltage on cpn+ and cpn-. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 127 11. cip-51 microcontroller the mcu system controller core is the cip-51 microcon troller. the cip-51 is fu lly compatible with the mcs-51? instruction set; standard 803x/805x assemblers and compilers can be used to develop soft- ware. the mcu family has a superset of all the peripherals included with a standard 8051. included are five 16-bit counter/time rs (see description in section 23 ), two full-duplex uarts (see description in sec- tion 21 and section 22 ), 256 bytes of internal ram, 128 byte special function register (sfr) address space (see section 11.2.6 ), and 8/4 byte-wide i/o ports (see description in section 18 ). the cip-51 also includes on-chip debug hardware (see description in section 25 ), and interfaces directly with the mcu?s analog and digital subsystems providing a complete da ta 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 periphera ls and functions to extend its capability (see figure 11 .1 for a block diagram). the cip-51 includes the following features: performance the cip-51 employs a pipelined architecture that grea tly increases its instruction throughput over the stan- dard 8051 architecture. in a standar d 8051, all instructions except for mul and div take 12 or 24 system clock cycles to execute, and usually have a maximu m system clock of 12 mhz. by contrast, the cip-51 core executes 70% of its instructions in one or tw o system clock cycles, with no instructions taking more than eight system clock cycles. with the cip-51's system clock running at 100 mhz , it has a peak throughput of 100 mips. the cip-51 has a total of 109 instructions. the table below shows the total number of instructions that require each execution time. clocks to execute 1 22/333/444/55 8 number of instructions 265051473121 - fully compatible with mcs-51 instruction set - 100 or 50 mips peak using the on-chip pll - 256 bytes of internal ram - 8/4 byte-wide i/o ports - extended interrupt handler - reset input - power management modes - on-chip debug logic - program and data memory security c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 128 rev. 1.4 figure 11.1. cip-51 block diagram programming and debugging support a jtag-based serial interface is provided for in- system programming of the flash program memory and communication with on-chip debug support logic. the re-programmable flash can also be read and changed by the application software using the movc and movx instructions. this feature allows program memory to be used for non-volatile data storage as well as updating program code under software control. the on-chip debug support logic facilitates full speed in-circuit debugging, allowing the setting of hardware breakpoints and watch points, starting, stopping and single stepping through program execution (including interrupt service routines), examination of the program' s call stack, and reading/wr iting the contents of reg- isters and memory. this method of on-chip debug is completely non-intrusive and non-invasive, requiring no ram, stack, timers, or other on-chip resources. the cip-51 is support ed by development tools from silicon labs and third party vendors. silicon labs pro- vides an integrated development environment (ide) in cluding editor, macro assembler, debugger and pro- grammer. the ide's debugger and programmer interface to the cip-51 via its jtag interface to provide fast and efficient in-system devi ce programming and debugging. third party macro assemblers and c compilers are also available. data bus tmp1 tmp2 prgm. address reg. pc incrementer alu psw data bus data bus memory interface mem_address d8 pipeline buffer data pointer interrupt interface system_irqs emulation_irq mem_control control logic a16 program counter (pc) stop clock reset idle power control register data bus sfr bus interface sfr_address sfr_control sfr_write_data sfr_read_data d8 d8 b register d8 d8 accumulator d8 d8 d8 d8 d8 d8 d8 d8 mem_write_data mem_read_data d8 sram address register sram (256 x 8) d8 stack pointer d8 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 129 11.1. instruction set the instruction set of the cip-51 system controller is fully compatible with th e standard mcs-51? instruc- tion set; standard 8051 development tools can be used to develop software for the cip-51. all cip-51 instructions are the binary and functional equivalen t of their mcs-51? counterparts, including opcodes, addressing modes and effect on psw flags. however, in struction timing is different than that of the stan- dard 8051. 11.1.1. instruction and cpu timing in many 8051 implementations, a distinction is ma de between machine cycles and clock cycles, with machine cycles varying from 2 to 12 clock cycles in length. however, the cip-51 implementation is based solely on clock cycle timing. all instructio n timings are specified in terms of clock cycles. due to the pipelined architecture of the cip-51, most instructions execute in the same number of clock cycles as there are program bytes in the instruction. conditional branch instruct ions take one less clock cycle to complete when the branch is not taken as opposed to when the branch is taken. table 11.1 is the cip-51 instruction set summary, which includes the mnemonic, number of bytes, and number of clock cycles for each instruction. 11.1.2. movx instruction and program memory in the cip-51, the movx instruction serves three purposes: accessing on-chip xram, accessing off-chip xram, and accessing on-chip program flash memory. the flash access feature provides a mechanism for user software to update program code and use the program memory space for non-volatile data stor- age (see section ?15. flash memory? on page 199 ). the external memory interface provides a fast access to off-chip xram (or memory-mapped peripherals) via the movx instruction. refer to section ?17. external data memo ry interface and on-chip xram? on page 219 for details. table 11.1. cip-51 instruction set summary mnemonic description bytes clock cycles arithmetic operations add a, rn add register to a 1 1 add a, direct add direct byte to a 2 2 add a, @ri add indirect ram to a 1 2 add a, #data add immediate to a 2 2 addc a, rn add register to a with carry 1 1 addc a, direct add direct byte to a with carry 2 2 addc a, @ri add indirect ram to a with carry 1 2 addc a, #data add immediate to a with carry 2 2 subb a, rn subtract regist er from a with borrow 1 1 subb a, direct subtract direct byte from a with borrow 2 2 subb a, @ri subtract indirect ram from a with borrow 1 2 subb a, #data subtract immedi ate from a with borrow 2 2 inc a increment a 1 1 inc rn increment register 1 1 inc direct increment direct byte 2 2 inc @ri increment indirect ram 1 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 130 rev. 1.4 dec a decrement a 1 1 dec rn decrement register 1 1 dec direct decrement direct byte 2 2 dec @ri decrement indirect ram 1 2 inc dptr increment data pointer 1 1 mul ab multiply a and b 1 4 div ab divide a by b 1 8 da a decimal adjust a 1 1 logical operations anl a, rn and register to a 1 1 anl a, direct and direct byte to a 2 2 anl a, @ri and indirect ram to a 1 2 anl a, #data and immediate to a 2 2 anl direct, a and a to direct byte 2 2 anl direct, #data and immediate to direct byte 3 3 orl a, rn or register to a 1 1 orl a, direct or direct byte to a 2 2 orl a, @ri or indirect ram to a 1 2 orl a, #data or immediate to a 2 2 orl direct, a or a to direct byte 2 2 orl direct, #data or immediate to direct byte 3 3 xrl a, rn exclusive-or register to a 1 1 xrl a, direct exclusive-or direct byte to a 2 2 xrl a, @ri exclusive-or indirect ram to a 1 2 xrl a, #data exclusive-or immediate to a 2 2 xrl direct, a exclusive-or a to direct byte 2 2 xrl direct, #data exclusive-or immediate to direct byte 3 3 clr a clear a 1 1 cpl a complement a 1 1 rl a rotate a left 1 1 rlc a rotate a left through carry 1 1 rr a rotate a right 1 1 rrc a rotate a right through carry 1 1 swap a swap nibbles of a 1 1 data transfer mov a, rn move register to a 1 1 mov a, direct move direct byte to a 2 2 mov a, @ri move indirect ram to a 1 2 mov a, #data move immediate to a 2 2 mov rn, a move a to register 1 1 mov rn, direct move direct byte to register 2 2 mov rn, #data move immediate to register 2 2 mov direct, a move a to direct byte 2 2 mov direct, rn move register to direct byte 2 2 mov direct, direct move direct byte to direct byte 3 3 table 11.1. cip-51 instructi on set summary (continued) mnemonic description bytes clock cycles c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 131 mov direct, @ri move indirect ram to direct byte 2 2 mov direct, #data move immediate to direct byte 3 3 mov @ri, a move a to indirect ram 1 2 mov @ri, direct move direct byte to indirect ram 2 2 mov @ri, #data move immediate to indirect ram 2 2 mov dptr, #data16 load dptr with 16-bit constant 3 3 movc a, @a+dptr move code byte relative dptr to a 1 3 movc a, @a+pc move code byte relative pc to a 1 3 movx a, @ri move external data (8-bit address) to a 1 3 movx @ri, a move a to external data (8-bit address) 1 3 movx a, @dptr move external data (16-bit address) to a 1 3 movx @dptr, a move a to external data (16-bit address) 1 3 push direct push direct byte onto stack 2 2 pop direct pop direct byte from stack 2 2 xch a, rn exchange register with a 1 1 xch a, direct exchange direct byte with a 2 2 xch a, @ri exchange indirect ram with a 1 2 xchd a, @ri exchange low nibble of indirect ram with a 1 2 boolean manipulation clr c clear carry 1 1 clr bit clear direct bit 2 2 setb c set carry 1 1 setb bit set direct bit 2 2 cpl c complement carry 1 1 cpl bit complement direct bit 2 2 anl c, bit and direct bit to carry 2 2 anl c, /bit and complement of direct bit to carry 2 2 orl c, bit or direct bit to carry 2 2 orl c, /bit or complement of direct bit to carry 2 2 mov c, bit move direct bit to carry 2 2 mov bit, c move carry to direct bit 2 2 jc rel jump if carry is set 2 2/3* jnc rel jump if carry is not set 2 2/3* jb bit, rel jump if direct bit is set 3 3/4* jnb bit, rel jump if direct bit is not set 3 3/4* jbc bit, rel jump if direct bit is set and clear bit 3 3/4* program branching acall addr11 absolute subroutine call 2 3* lcall addr16 long subroutine call 3 4* ret return from subroutine 1 5* reti return from interrupt 1 5* ajmp addr11 absolute jump 2 3* ljmp addr16 long jump 3 4* sjmp rel short jump (relative address) 2 3* jmp @a+dptr jump indirect relative to dptr 1 3* table 11.1. cip-51 instructi on set summary (continued) mnemonic description bytes clock cycles c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 132 rev. 1.4 jz rel jump if a equals zero 2 2/3* jnz rel jump if a does not equal zero 2 2/3* cjne a, direct, rel compare direct byte to a and jump if not equal 3 3/4* cjne a, #data, rel compare immediate to a and jump if not equal 3 3/4* cjne rn, #data, rel compare immediate to register and jump if not equal 33/4* cjne @ri, #data, rel compare immediate to indirect and jump if not equal 34/5* djnz rn, rel decrement register and jump if not zero 2 2/3* djnz direct, rel decrement direct byte and jump if not zero 3 3/4* nop no operation 1 1 * branch instructions will incur a cache-miss penalty if the branch target location is not already stored in the branch target cache. see section ?16. branch target cache? on page 211 for more details. table 11.1. cip-51 instructi on set summary (continued) mnemonic description bytes clock cycles notes on registers, operands and addressing modes: rn - register r0-r7 of the currently selected register bank. @ri - data ram location addressed indirectly through r0 or r1. rel - 8-bit, signed (2s complement) offset relative to t he first byte of the followi ng instruction. used by sjmp and all conditional jumps. direct - 8-bit internal data location?s address. this could be a direct-access data ram location (0x00- 0x7f) or an sfr (0x80-0xff). #data - 8-bit constant #data16 - 16-bit constant bit - direct-accessed bit in data ram or sfr addr11 - 11-bit destination address used by acall and ajmp. the destination must be within the same 2k-byte page of program memory as the first byte of the following instruction. addr16 - 16-bit destination address used by lcall and ljmp. the destination may be anywhere within the 64k-byte program memory space. there is one unused opcode (0xa5) that performs the same function as nop. all mnemonics copyrighted ? intel corporation 1980. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 133 11.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 128k bytes (c8051f12x and c8051f130/1) or 64k bytes (c8051f132/3) of internal program memory address space implemented within the cip-51. the cip-51 memory organization is shown in figure 11.2. figure 11.2. memory map 11.2.1. program memory the c8051f12x and c8051f130/1 have a 128 kb program memory space. the mcu implements this pro- gram memory space as in-system re-programmable flash memory in four 32 kb code banks. a common code bank (bank 0) of 32 kb is always accessible from addresses 0x0000 to 0x7fff. the three upper code banks (bank 1, bank 2, and bank 3) are each mapped to addresses 0x8000 to 0xffff, depending on the selection of bits in the psbank register, as described in sfr definition 11.1. the ifbank bits select which of the upper banks are used for code execution, while the cobank bits select the bank to be used for direct writes and reads of the flash me mory. note: 1024 bytes of the memory in bank 3 (0x1fc00 to 0x1ffff) are reserved and are not available for user program or data storage. the c8051f132/3 have a 64k byte program memory space implemented as in-system re-programmable flash memory, and organized in a contiguous block from address 0x00000 to 0x0ffff. program memory is normally assumed to be read-only . however, the cip-51 can write to program memory by setting the program store write enable bit (psctl.0 ) and using the movx instruction. this feature pro- vides a mechanism for the cip-51 to update program code and use the program memory space for non- volatile data storage. refer to section ?15. flash memory? on page 199 for further details. program/data memory (flash) flash (in-system programmable in 1024 byte sectors) 0x00000 0x1ffff reserved 0x1fc00 0x1fbff scrachpad memory (data only) 0x200ff 0x20000 (direct and indirect addressing) upper 128 ram (indirect addressing only) special function registers (direct addressing only) data memory (ram) general purpose registers bit addressable lower 128 ram (direct and indirect addressing) internal data address space external data address space xram - 8192 bytes (accessable using movx instruction) 0x0000 0x1fff off-chip xram space 0x2000 0xffff up to 256 sfr pages 1 3 0 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1 flash (in-system programmable in 1024 byte sectors) 0x00000 0x0ffff scrachpad memory (data only) 0x200ff 0x20000 c8051f132/3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 134 rev. 1.4 sfr definition 11.1. psbank: pr ogram space bank select figure 11.3. address memory map for inst ruction fetches ( 128 kb flash only) bits 7 ? 6: reserved. bits 5 ? 4: cobank: constant operations bank select. these bits select which flash bank is targeted during constant operations (movc and flash movx) involving addresses 0x8000 to 0xffff. these bits are ignored when accessing the scratchpad memory areas (see section ?15. flash memory? on page 199 ). 00: constant operations target bank 0 (note that bank 0 is also mapped between 0x0000 to 0x7fff). 01: constant operations target bank 1. 10: constant operations target bank 2. 11: constant operations target bank 3. bits 3 ? 2: reserved. bits 1 ? 0: ifbank: instruction fetch operations bank select. these bits select which flash bank is used for instruction fetches involving addresses 0x8000 to 0xffff. these bits can only be changed from code in bank 0 (see figure 11.3). 00: instructions fetch from bank 0 (note that bank 0 is also mapped between 0x0000 to 0x7fff). 01: instructions fetch from bank 1. 10: instructions fetch from bank 2. 11: instructions fetch from bank 3. *note: on the c8051f132/3, the cobank and ifbank bits should both remain set to the default setting of ?01? to ensure proper device functionality. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - cobank - - ifbank 00010001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xb1 all pages bank 0 bank 1 bank 2 bank 3 bank 0 bank 0 bank 0 bank 0 ifbank = 0 ifbank = 1 ifbank = 2 ifbank = 3 internal address 0x0000 0x7fff 0x8000 0xffff c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 135 11.2.2. data memory the cip-51 implements 256 bytes of internal ram map ped into the data memory space from 0x00 through 0xff. the lower 128 bytes of data memory are used for general purpose registers and 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 gene ral purpose registers, each bank consisting of eight byte-wide registers. the next 16 bytes, locations 0x 20 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 regist ers (sfr) but is physically separate from the sfr space. the addressing mode used by an instructio n when accessing locations above 0x7f determines whether the cpu accesses the upper 128 bytes of data memory space or the sfr?s. 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 11.2 illustrates the data memory organization of the cip-51. 11.2.3. general purpose registers the lower 32 bytes of data memory, locations 0x00 through 0x1f, may be addressed as four banks of gen- eral-purpose registers. each bank consists of ei ght byte-wide registers designated r0 through r7. only one of these banks may be enabled at a time. two bits in the program status word, rs0 (psw.3) and rs1 (psw.4), select the active register bank (see description of the psw in sfr definition 11.9). this allows fast context switching when entering subroutines and interrupt service routines. indirect addressing modes use registers r0 and r1 as index registers. 11.2.4. bit addressable locations in addition to direct access to data memory organized as bytes, the sixteen data memory locations at 0x20 through 0x2f are also accessible as 128 individually addressable bits. each bit has a bit address from 0x00 to 0x7f. bit 0 of the byte at 0x20 has bit address 0x00 while bit 7 of the byte at 0x20 has bit address 0x07. bit 7 of the byte at 0x2f has bit address 0x7f. a bit access is distinguished from a full byte access by the type of instruction used (bit source or destinat ion operands as opposed to a byte source or destina- tion). the mcs-51? assembly language allows an alternate notation for bit addressing of the form xx.b where xx is the byte address and b is the bit position within the byte. for example, the instruction: mov c, 22.3h moves the boolean value at 0x13 (bit 3 of the byte at location 0x22) into the carry flag. 11.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 init ializes the stack pointer to location 0x07; therefore, the first value pushed on th e 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, c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 136 rev. 1.4 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 d ebug software even with the mcu running at speed. 11.2.6. special function registers the direct-access data memory locations from 0x80 to 0xff constitute the sp ecial function registers (sfr?s). the sfr?s provide control and data exchange with the cip-51's resources and peripherals. the cip-51 duplicates the sfr?s found in a typical 8051 implementation as well as implementing additional sfr?s used to configure and access the sub-systems unique to the mcu. this allows the addition of new functionality while retaining compatibility with the mcs-51? instruction set. table 11.2 lists the sfr?s implemented in the cip-51 system controller. the sfr registers are accessed whenever the direct addressing mode is used to access memory loca- tions from 0x80 to 0xff. sfr?s with addresses ending in 0x0 or 0x8 (e.g. p0, tcon, p1, scon, ie, etc.) are bit-addressable as well as byte-addressable. all other sfr?s are byte-addressable only. unoccupied addresses in the sfr space are reserv ed for future use. ac cessing these areas will have an in determinate effect and should be avoided. refer to the corr esponding pages of the datasheet, as indicated in table 11.3, for a detailed description of each register. 11.2.6.1.sfr paging the cip-51 features sfr paging, allowing the device to map many sfr?s into the 0x80 to 0xff memory address space. the sfr memory space has 256 pages . in this way, each memory location from 0x80 to 0xff can access up to 256 sfr?s. the c8051f12x family of devices utilizes five sfr pages: 0, 1, 2, 3, and f. sfr pages are selected using the special func tion register page selection register, sfrpage (see sfr definition 11.3). the procedure for reading and writing an sfr is as follows: 1. select the appropriate sfr page number using the sfrpage register. 2. use direct accessing mode to read or write t he special function register (mov instruction). 11.2.6.2.interrupts and sfr paging when an interrupt occu rs, the sfr page register will automatically switch to the sfr page containing the flag bit that caused the interrupt. the automatic sfr page switch function conveniently removes the bur- den of switching sfr pages from the interrupt service ro utine. upon execution of the reti instruction, the sfr page is automatically restored to the sfr page in use prior to the interrupt. this is accomplished via a three-byte sfr page stack . the top byte of the stack is sfrp age, the current sfr page. the second byte of the sfr page stack is sfrnext. the third, or bottom byte of the sfr page stack is sfrlast. on interrupt, the current sfrpage value is pushed to the sfrnext byte, and the value of sfrnext is pushed to sfrlast. hardware then loads sfrpage with the sfr page containing the flag bit associated with the interrupt. on a return from interrupt, the sfr page stack is popped resulting in the value of sfrn- ext returning to the sfrpage register, thereby restor ing the sfr page context without software interven- tion. the value in sfrlast (0x00 if there is no sfr page value in the bottom of the stack) of the stack is placed in sfrnext register. if desired, the valu es stored in sfrnext and sfrlast may be modified during an interrupt, enabling the cpu to return to a different sfr page upon execution of the reti instruc- tion (on interrupt exit). modifying registers in the sfr page stack does not cause a push or pop of the stack. only interrupt calls and returns will ca use push/pop operations on the sfr page stack. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 137 figure 11.4. 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 enab le bit located in the sfr page control register (sfrpgcn). this function defaults to ?enabled? upon reset. in this way, the autoswitching function w ill be enabled unless dis- abled in software. a summary of the sfr locations (address and sfr page) is provided in table 11.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 sfr?s 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 sfr?s are accessible from all sfr pages regardless of the sfrpage regis- ter value. sfrnext sfrpage sfrlast cip-51 interrupt logic sfrpgcn bit c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 138 rev. 1.4 11.2.6.3.sfr page stack example the following is an example that shows the operation of the sfr page stack during interrupts. in this example, the sfr page cont rol 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 10-bit adc (adc2) window comparator to monitor a voltage. the pca is timing a critical control function in its inte rrupt 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 associ- ated 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 11.5 below. figure 11.5. sfr page stack while us ing sfr page 0x0f to access port 5 while cip-51 executes in-line code (writing values to port 5 in this example), adc2 window comparator interrupt occurs. the cip-51 vectors to the adc2 window co mparator isr and pushes the current sfr page value (sfr page 0x0f) into sfrnext in the sfr page stack. the sfr page needed to access adc2?s sfr?s is then automatically placed in the sfrpage register (sfr page 0x02). sfrpage is con- sidered the ?top? of the sfr page stack. software can now access the adc2 sfr?s. 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 sfr?s that are not on sfr page 0x02. see figure 11.6 below. 0x0f (port 5) sfrpage sfrlast sfrnext sfr page stack sfr's c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 139 figure 11.6. sfr page stack after adc2 window comparator interrupt occurs while in the adc2 isr, a pca interrupt occurs. recall the pca interrupt is configured as a high priority interrupt, while the adc2 inte rrupt 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 pl ace the sfr page needed to access the pca?s 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 st ored in sfrlast (via a previous software write to the sf rlast register) will be overwritten. see figure 11.7 below. 0x02 (adc2) 0x0f (port 5) sfrpage sfrlast sfrnext sfrpage pushed to sfrnext sfr page 0x02 automatically pushed on stack in sfrpage on adc2 interrupt c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 140 rev. 1.4 figure 11.7. sfr page stack upon pca in terrupt occurring during an adc2 isr on exit from the pca in terrupt service rout ine, the cip-51 will return to the adc2 window comparator isr. on execution of the reti inst ruction, sfr page 0x00 used to a ccess the pca regi sters will be auto- matically popped off of the sfr pa ge stack, and the contents of th e sfrnext register will be moved to the sfrpage register. software in the adc2 isr can continue to access sfr?s 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 11.8 below. figure 11.8. sfr page stack upon return from pca interrupt 0x00 (pca) 0x02 (adc2) 0x0f (port 5) sfrpage sfrlast sfrnext sfr page 0x00 automatically pushed on stack in sfrpage on pca interrupt sfrpage pushed to sfrnext sfrnext pushed to sfrlast 0x02 (adc2) 0x0f (port 5) sfrpage sfrlast sfrnext sfr page 0x00 automatically popped off of the stack on return from interrupt sfrnext popped to sfrpage sfrlast popped to sfrnext c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 141 on the execution of the reti instruction in the adc2 window comparator isr, the value in sfrpage register is overwritten with the contents of sfrn ext. the cip-51 may now access the port 5 sfr bits as it did prior to the interrupts occurring. see figure 11.9 below. figure 11.9. 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 wh ile 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 betw een 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 t he sfr page control register (sfr pgcn). see sfr definition 11.2. 0x0f (port 5) sfrpage sfrlast sfrnext sfr page 0x02 automatically popped off of the stack on return from interrupt sfrnext popped to sfrpage c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 142 rev. 1.4 sfr definition 11.2. sfrpg cn: sfr page control sfr definition 11.3. sfrpage: sfr page bits7?1: reserved. bit0: sfrpgen: sfr automatic page control enable. upon interrupt, the c8051 core will vector to the specified in terrupt service routine and auto- matically switch the sfr page to the corresponding peripheral or function?s sfr page. this bit is used to control this autopaging function. 0: sfr automatic paging disabled. c8051 core will not automatically change to the appro- priate sfr page (i.e., the sfr page that contains the sfr?s for the peripheral/function that was the source of the interrupt). 1: sfr automatic paging enabl ed. upon interr upt, the c8051 will switch the sfr page to the page that contains the sfr?s for the periphera l or function that is the source of the inter- rupt. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - - - - - sfrpgen 00000001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x96 f bits7?0: sfr page bits: byte represents the sfr page the c8051 mcu uses when reading or mod- ifying sfr?s. write: sets the sfr page. read: byte is the sfr page the c8051 mcu is using. when enabled in the sfr page control regist er (sfrpgcn), the c 8051 will automatically switch to the sfr page that contains the sfr? s of the corresponding peripheral/function that caused the interrupt, and return to the previous sfr page upon return from interrupt (unless sfr stack was altered before a returning from the interrupt). sfrpage is the top byte of the sfr page stack, and push/pop events of this stack are caused by interrupts (and not by reading/writing to the sfrpage register) r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x84 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 143 sfr definition 11.4. sfrnext: sfr next register sfr definition 11.5. sfrlast : sfr last register bits7?0: sfr page stack bits: sfr page context is retained upon interrupts/return from interrupts in a 3 byte sfr page stack: sfrpage is the fi rst entry, sfrnext is the second, and sfr- last is the third entry. the sfr stack bytes ma y be used alter the context in the sfr page stack, and will not cause the sta ck to ?push? or ?pop?. only in terrupts and return from inter- rupts cause pushes and pops of the sfr page stack. write: sets the sfr page contained in the seco nd byte of the sfr st ack. 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 contai ned in the second byte of the sfr stack. this is the value that will go to the sfr pa ge register upon a re turn from interrupt. 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: sfr page: 0x85 all pages bits7?0: sfr page stack bits: sfr page context is retained upon interrupts/return from interrupts in a 3 byte sfr page stack: sfrpage is the fi rst entry, sfrnext is the second, and sfr- last is the third entry. the sfr stack bytes ma y be used alter the context in the sfr page stack, and will not cause the sta ck to ?push? or ?pop?. only in terrupts and return from inter- rupts cause pushes and pops of 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. 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: sfr page: 0x86 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 144 rev. 1.4 table 11.2. special function re gister (sfr) memory map address sfr page 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) f8 0 1 2 3 f spi0cn p7 pca0l pca0h pca0cpl0 pca0cph0 pca0cpl1 pca0cph1 wdtcn (all pages) f0 0 1 2 3 f b (all pages) eip1 (all pages) eip2 (all pages) e8 0 1 2 3 f adc0cn adc2cn p6 pca0cpl2 pca0cph2 pca0cpl3 pca0cph3 pca0cpl4 pca0cph4 rstsrc e0 0 1 2 3 f acc (all pages) pca0cpl5 xbr0 pca0cph5 xbr1 xbr2 eie1 (all pages) eie2 (all pages) d8 0 1 2 3 f pca0cn p5 pca0md pca0cpm0 pca0cpm1 pca0cp m2 pca0cpm3 pca0cpm4 pca0cpm5 d0 0 1 2 3 f psw (all pages) ref0cn dac0l dac1l dac0h dac1h dac0cn dac1cn c8 0 1 2 3 f tmr2cn tmr3cn tmr4cn p4 tmr2cf tmr3cf tmr4cf rcap2l rcap3l rcap4l rcap2h rcap3h rcap4h tmr2l tmr3l tmr4l tmr2h tmr3h tmr4h mac0rndl smb0cr mac0rndh c0 0 1 2 3 f smb0cn mac0sta smb0sta mac0al smb0dat mac0ah smb0adr mac0cf adc0gtl adc2gt adc0gth adc0ltl adc2lt adc0lth 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 145 b8 0 1 2 3 f ip (all pages) saden0 amx0cf amx2cf amx0sl amx2sl adc0cf adc2cf adc0l adc2 adc0h b0 0 1 2 3 f p3 (all pages) psbank (all pages) flscl flacl a8 0 1 2 3 f ie (all pages) saddr0 p1mdin a0 0 1 2 3 f p2 (all pages) emi0tc cch0cn emi0cn cch0tn emi0cf cch0lc p0mdout p1mdout p2mdout p3mdout 98 0 1 2 3 f scon0 scon1 sbuf0 sbuf1 spi0cfg cch0ma spi0dat p4mdout spi0ckr p5mdout p6mdout p7mdout 90 0 1 2 3 f p1 (all pages) ssta0 mac0bl mac0bh mac0acc0 mac0acc1 mac0acc2 mac0acc3 sfrpgcn mac0ovr clksel 88 0 1 2 3 f tcon cpt0cn cpt1cn flstat tmod cpt0md cpt1md pll0cn tl0 oscicn tl1 oscicl th0 oscxcn th1 pll0div ckcon pll0mul psctl pll0flt 80 0 1 2 3 f p0 (all pages) sp (all pages) dpl (all pages) dph (all pages) sfrpage (all pages) sfrnext (all pages) sfrlast (all pages) pcon (all pages) table 11.2. special function register (sfr) memory map (continued) 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 146 rev. 1.4 table 11.3. special function registers sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page no. acc 0xe0 all pages accumulator page 153 adc0cf 0xbc 0 adc0 configuration page 62 1 , page 80 2 adc0cn 0xe8 0 adc0 control page 63 1 , page 81 2 adc0gth 0xc5 0 adc0 greater-than high byte page 66 1 , page 84 2 adc0gtl 0xc4 0 adc0 greater-than low byte page 66 1 , page 84 2 adc0h 0xbf 0 adc0 data word high byte page 64 1 , page 82 2 adc0l 0xbe 0 adc0 data word low byte page 64 1 , page 82 2 adc0lth 0xc7 0 adc0 less-than high byte page 67 1 , page 85 2 adc0ltl 0xc6 0 adc0 less-than low byte page 67 1 , page 85 2 adc2 0xbe 2 adc2 data word page 99 3 adc2cf 0xbc 2 adc2 configuration page 97 3 adc2cn 0xe8 2 adc2 control page 98 3 adc2gt 0xc4 2 adc2 greater-than page 102 3 adc2lt 0xc6 2 adc2 less-than page 102 3 amx0cf 0xba 0 adc0 multiplexer configuration page 60 1 , page 78 2 amx0sl 0xbb 0 adc0 multiplexer channel select page 61 1 , page 79 2 amx2cf 0xba 2 adc2 multiplexer configuration page 95 3 amx2sl 0xbb 2 adc2 multiplexer channel select page 96 3 b 0xf0 all pages b register page 153 cch0cn 0xa1 f cache control page 215 cch0lc 0xa3 f cache lock page 216 cch0ma 0x9a f cache miss accumulator page 217 cch0tn 0xa2 f cache tuning page 216 ckcon 0x8e 0 clock control page 315 clksel 0x97 f system clock select page 188 cpt0cn 0x88 1 comparator 0 control page 123 cpt0md 0x89 1 comparator 0 configuration page 123 cpt1cn 0x88 2 comparator 1 control page 124 cpt1md 0x89 2 comparator 1 configuration page 125 dac0cn 0xd4 0 dac0 control page 108 3 dac0h 0xd3 0 dac0 high byte page 107 3 dac0l 0xd2 0 dac0 low byte page 107 3 dac1cn 0xd4 1 dac1 control page 110 3 dac1h 0xd3 1 dac1 high byte page 109 3 dac1l 0xd2 1 dac1 low byte page 109 3 dph 0x83 all pages data pointer high byte page 151 dpl 0x82 all pages data pointer low byte page 151 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 147 eie1 0xe6 all pages extended interrupt enable 1 page 159 eie2 0xe7 all pages extended interrupt enable 2 page 160 eip1 0xf6 all pages extended interrupt priority 1 page 161 eip2 0xf7 all pages extended interrupt priority 2 page 162 emi0cf 0xa3 0 emif configuration page 221 emi0cn 0xa2 0 emif control page 220 emi0tc 0xa1 0 emif timing control page 226 flacl 0xb7 f flash access limit page 206 flscl 0xb7 0 flash scale page 208 flstat 0x88 f flash status page 217 ie 0xa8 all pages interrupt enable page 157 ip 0xb8 all pages interrupt priority page 158 mac0acc0 0x93 3 mac0 accu mulator byte 0 (lsb) page 174 4 mac0acc1 0x94 3 mac0 accumulator byte 1 page 173 4 mac0acc2 0x95 3 mac0 accumulator byte 2 page 173 4 mac0acc3 0x96 3 mac0 accu mulator byte 3 (msb) page 173 4 mac0ah 0xc2 3 mac0 a register high byte page 171 4 mac0al 0xc1 3 mac0 a register low byte page 172 4 mac0bh 0x92 3 mac0 b register high byte page 172 4 mac0bl 0x91 3 mac0 b register low byte page 172 4 mac0cf 0xc3 3 mac0 configuration page 170 4 mac0ovr 0x97 3 mac0 accumulator overflow page 174 4 mac0rndh 0xcf 3 mac0 rounding register high byte page 174 4 mac0rndl 0xce 3 mac0 rounding register low byte page 175 4 mac0sta 0xc0 3 mac0 status register page 171 4 oscicl 0x8b f internal osc illator calibration page 186 oscicn 0x8a f internal o scillator control page 186 oscxcn 0x8c f external os cillator control page 189 p0 0x80 all pages port 0 latch page 248 p0mdout 0xa4 f port 0 output mode configuration page 248 p1 0x90 all pages port 1 latch page 249 p1mdin 0xad f port 1 input mode page 249 p1mdout 0xa5 f port 1 output mode configuration page 250 p2 0xa0 all pages port 2 latch page 250 p2mdout 0xa6 f port 2 output mode configuration page 251 p3 0xb0 all pages port 3 latch page 251 p3mdout 0xa7 f port 3 output mode configuration page 252 p4 0xc8 f port 4 latch page 254 p4mdout 0x9c f port 4 output mode configuration page 254 p5 0xd8 f port 5 latch page 255 p5mdout 0x9d f port 5 output mode configuration page 255 table 11.3. special functi on registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page no. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 148 rev. 1.4 p6 0xe8 f port 6 latch page 256 p6mdout 0x9e f port 6 output mode configuration page 256 p7 0xf8 f port 7 latch page 257 p7mdout 0x9f f port 7 output mode configuration page 257 pca0cn 0xd8 0 pca control page 335 pca0cph0 0xfc 0 pca module 0 capture/compare high byte page 339 pca0cph1 0xfe 0 pca module 1 capture/compare high byte page 339 pca0cph2 0xea 0 pca module 2 capture/compare high byte page 339 pca0cph3 0xec 0 pca module 3 capture/compare high byte page 339 pca0cph4 0xee 0 pca module 4 capture/compare high byte page 339 pca0cph5 0xe2 0 pca module 5 capture/compare high byte page 339 pca0cpl0 0xfb 0 pca module 0 capture/compare low byte page 338 pca0cpl1 0xfd 0 pca module 1 capture/compare low byte page 338 pca0cpl2 0xe9 0 pca module 2 capture/compare low byte page 338 pca0cpl3 0xeb 0 pca module 3 capture/compare low byte page 338 pca0cpl4 0xed 0 pca module 4 capture/compare low byte page 338 pca0cpl5 0xe1 0 pca module 5 capture/compare low byte page 338 pca0cpm0 0xda 0 pca module 0 mode page 337 pca0cpm1 0xdb 0 pca module 1 mode page 337 pca0cpm2 0xdc 0 pca module 2 mode page 337 pca0cpm3 0xdd 0 pca module 3 mode page 337 pca0cpm4 0xde 0 pca module 4 mode page 337 pca0cpm5 0xdf 0 pca module 5 mode page 337 pca0h 0xfa 0 pca counter high byte page 338 pca0l 0xf9 0 pca counter low byte page 338 pca0md 0xd9 0 pca mode page 336 pcon 0x87 all pages power control page 164 pll0cn 0x89 f pll control page 193 pll0div 0x8d f pll divider page 194 pll0flt 0x8f f pll filter page 195 pll0mul 0x8e f pll multiplier page 194 psbank 0xb1 all pages flash bank select page 134 psctl 0x8f 0 flash write/erase control page 209 psw 0xd0 all pages program status word page 152 rcap2h 0xcb 0 timer/counter 2 capture/reload high byte page 323 rcap2l 0xca 0 timer/counter 2 capture/reload low byte page 323 rcap3h 0xcb 1 timer 3 capture/reload high byte page 323 rcap3l 0xca 1 timer 3 capture/reload low byte page 323 rcap4h 0xcb 2 timer/counter 4 capture/reload high byte page 323 rcap4l 0xca 2 timer/counter 4 capture/reload low byte page 323 table 11.3. special functi on registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page no. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 149 ref0cn 0xd1 0 voltage reference control page 114 5 , page 116 6 , page 117 7 rstsrc 0xef 0 reset source page 182 saddr0 0xa9 0 uart 0 slave address page 298 saden0 0xb9 0 uart 0 slave address mask page 298 sbuf0 0x99 0 uart 0 data buffer page 298 sbuf1 0x99 1 uart 1 data buffer page 305 scon0 0x98 0 uart 0 control page 296 scon1 0x98 1 uart 1 control page 304 sfrlast 0x86 all pages sfr stack last page page 143 sfrnext 0x85 all pages sfr stack next page page 143 sfrpage 0x84 all pages sfr page select page 142 sfrpgcn 0x96 f sfr page control page 142 smb0adr 0xc3 0 smbus slave address page 269 smb0cn 0xc0 0 smbus control page 266 smb0cr 0xcf 0 smbus clock rate page 267 smb0dat 0xc2 0 smbus data page 268 smb0sta 0xc1 0 smbus status page 269 sp 0x81 all pages stack pointer page 151 spi0cfg 0x9a 0 spi configuration page 280 spi0ckr 0x9d 0 spi clock rate control page 282 spi0cn 0xf8 0 spi control page 281 spi0dat 0x9b 0 spi data page 282 ssta0 0x91 0 uart 0 status page 297 tcon 0x88 0 timer/counter control page 313 th0 0x8c 0 timer/counter 0 high byte page 316 th1 0x8d 0 timer/counter 1 high byte page 316 tl0 0x8a 0 timer/counter 0 low byte page 315 tl1 0x8b 0 timer/counter 1 low byte page 316 tmod 0x89 0 timer/counter mode page 314 tmr2cf 0xc9 0 timer/counter 2 configuration page 324 tmr2cn 0xc8 0 timer/counter 2 control page 324 tmr2h 0xcd 0 timer/counter 2 high byte page 324 tmr2l 0xcc 0 timer/counter 2 low byte page 323 tmr3cf 0xc9 1 timer 3 configuration page 324 tmr3cn 0xc8 1 timer 3 control page 324 tmr3h 0xcd 1 timer 3 high byte page 324 tmr3l 0xcc 1 timer 3 low byte page 323 tmr4cf 0xc9 2 timer/counter 4 configuration page 324 tmr4cn 0xc8 2 timer/counter 4 control page 324 tmr4h 0xcd 2 timer/counter 4 high byte page 324 table 11.3. special functi on registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page no. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 150 rev. 1.4 tmr4l 0xcc 2 timer/counter 4 low byte page 323 wdtcn 0xff all pages watchdog timer control page 181 xbr0 0xe1 f port i/o crossbar control 0 page 245 xbr1 0xe2 f port i/o crossbar control 1 page 246 xbr2 0xe3 f port i/o crossbar control 2 page 247 notes: 1. refers to a register in the c8051f120/1/4/5 only. 2. refers to a register in the c8051f122/3/6/7 and c8051f130/1/2/3 only. 3. refers to a register in the c8051f120/1/2/3/4/5/6/7 only. 4. refers to a register in the c8051f120/1/2/3 and c8051f130/1/2/3 only. 5. refers to a register in the c8051f120/2/4/6 only. 6. refers to a register in the c8051f121/3/5/7 only. 7. refers to a register in the c8051f130/1/2/3 only. table 11.3. special functi on registers (continued) sfrs are listed in alphabetical order. all undefined sfr locations are reserved. register address sfr page description page no. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 151 11.2.7. register descriptions following are descriptions of sfrs related to the opera tion of the cip-51 system controller. reserved bits should not be set to logic l. future product versions may use these bits to implement new features in which case the reset value of the bit will be logic 0, selecting the featur e's default state. de tailed descriptions of the remaining sfrs are included in the sections of the datasheet associated with their corresponding sys- tem function. sfr definition 11.6. sp: stack pointer sfr definition 11.7. dpl: data pointer low byte sfr definition 11.8. dph: data pointer high byte bits7?0: sp: stack pointer. the stack pointer holds the location of the top of the stack. the stack pointer is incremented before every push operation. the sp r egister defaults to 0x07 after reset. r/w r/w r/w r/w r/w r/w r/w r/w reset value 00000111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x81 all pages bits7?0: dpl: data pointer low. the dpl register is the low byte of the 16-b it dptr. dptr is used to access indirectly addressed xram and flash memory. 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: sfr page: 0x82 all pages bits7?0: dph: data pointer high. the dph register is the high byte of the 16-b it dptr. dptr is used to access indirectly addressed xram and flash memory. 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: sfr page: 0x83 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 152 rev. 1.4 sfr definition 11.9. psw: program status word bit7: cy: carry flag. this bit is set when the last arithmetic operat ion resulted in a carry (addition) or a borrow (subtraction). it is cleared to 0 by all other arithmetic operations. bit6: ac: auxiliary carry flag this bit is set when the last arithmetic operation resulted in a carry into (addition) or a borrow from (subtraction) the high order nibble. it is cleared to 0 by all other arithmetic operations. bit5: f0: user flag 0. this is a bit-addressable, general purpose flag for use under software control. bits4?3: rs1?rs0: register bank select. these bits select which register ban k is used during register accesses. bit2: ov: overflow flag. this bit is set to 1 under the following circumstances: ? an add, addc, or subb instruction causes a sign-change overflow. ? a mul instruction results in an overflow (result is greater than 255). ? a div instruction causes a divide-by-zero condition. the ov bit is cleared to 0 by the add, addc, subb, mul, and div instructions in all other cases. bit1: f1: user flag 1. this is a bit-addressable, general purpose flag for use under software control. bit0: parity: parity flag. this bit is set to 1 if the sum of the eight bits in the accumulator is odd and cleared if the sum is even. r/w r/w r/w r/w r/w r/w r/w r reset value cy ac f0 rs1 rs0 ov f1 parity 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0xd0 all pages rs1 rs0 register bank address 0 0 0 0x00?0x07 0 1 1 0x08?0x0f 1 0 2 0x10?0x17 1 1 3 0x18?0x1f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 153 sfr definition 11.10. acc: accumulator sfr definition 11.11. b: b register 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 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 sfr address: sfr page: 0xe0 all pages bits7?0: b: b register. this register serves as a second accumu lator for certain arithmetic operations. r/w r/w r/w r/w r/w r/w r/w r/w reset value b.7 b.6 b.5 b.4 b.3 b.2 b.1 b.0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0xf0 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 154 rev. 1.4 11.3. interrupt handler the cip-51 includes an extended interrupt system supp orting a total of 20 interrupt sources with two prior- ity levels. the allocation of interrupt sources between on-chip peripherals and external input pins varies according to the specific version of the device. each interrupt source has one or more associated interrupt- pending flag(s) located in an sfr. when a peripheral or external source meets a valid interrupt condition, the associated interrupt-pend ing 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 instructio n is complete, the cpu generates an lcall to a prede- termined address to begin execution of an interrupt se rvice 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 regard- less 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, eie1, or 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; // this is a dummy instruction with two-byte opcode. ; in assembly: clr ea ; clear ea bit. clr ea ; this is a dummy instruction with two-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. how- ever, a read of the ea bit will return a '0' inside the interrup t service rout ine. when the "clr ea" opcode is followed by a multi-cycle instruction, the inte rrupt will not be taken. some interrupt-pending flags are automatically cleare d 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 interrup t request will be gener ated immediately and the cpu will re-enter the isr after the completion of th e next instruction. 11.3.1. mcu interrupt sources and vectors the mcus support 20 interrupt sources. software can simulate an interrupt event by setting any interrupt- pending flag to logic 1. if interrupts are enabled for the flag, an interrupt request will be generated and the cpu will vector to the isr address associated with the interrupt-pending flag. mcu interrupt sources, associated vector addresses, priority order and cont rol bits are summarized in table 11.4. refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 155 11.3.2. external interrupts two of the external interrupt sources (/int0 and /int1 ) are configurable as active-low level-sensitive or active-low edge-sensitive inputs depending on the se tting of bits it0 (tcon.0) and it1 (tcon.2). ie0 (tcon.1) and ie1 (tcon.3) serve as the interrupt-p ending flag for the /int0 and /int1 external interrupts, respectively. if an /int0 or /int1 external interrupt is configured as edge-sensitive, the corresponding interrupt-pending flag is automatically cleared by the hardware when the cpu vectors to the isr. when configured as level sensitive, the interrupt-pending flag follows the state of the external interrupt's input pin. the external interrupt source must hold the input acti ve until the interrupt request is recognized. it must then deactivate the interrupt request before executio n of the isr completes or another interrupt request will be generated. table 11.4. interrupt summary interrupt source interru pt vector priority order pending flags bit addressable? cleared by hw? sfrpage (sfrpgen = 1) enable flag priority control reset 0x0000 top none n/a n/a 0 always enabled always highest external interrupt 0 (/int0) 0x0003 0 ie0 (tcon.1) y y 0 ex0 (ie.0) px0 (ip.0) timer 0 overflow 0x000b 1 tf0 (tcon.5) y y 0 et0 (ie.1) pt0 (ip.1) external interrupt 1 (/int1) 0x0013 2 ie1 (tcon.3) y y 0 ex1 (ie.2) px1 (ip.2) timer 1 overflow 0x001b 3 tf1 (tcon.7) y y 0 et1 (ie.3) pt1 (ip.3) uart0 0x0023 4 ri0 (scon0.0) ti0 (scon0.1) y 0 es0 (ie.4) ps0 (ip.4) timer 2 0x002b 5 tf2 (tmr2cn.7) exf2 (tmr2cn.6) y 0 et2 (ie.5) pt2 (ip.5) serial peripheral interface 0x0033 6 spif (spi0cn.7) wcol (spi0cn.6) modf (spi0cn.5) rxovrn (spi0cn.4) y0 espi0 (eie1.0) pspi0 (eip1.0) smbus interface 0x003b 7 si (smb0cn.3) y 0 esmb0 (eie1.1) psmb0 (eip1.1) adc0 window comparator 0x0043 8 ad0wint (adc0cn.1) y0 ewadc0 (eie1.2) pwadc0 (eip1.2) programmable counter array 0x004b 9 cf (pca0cn.7) ccfn (pca0cn.n) y0 epca0 (eie1.3) ppca0 (eip1.3) comparator 0 falling edge 0x0053 10 cp0fif (cpt0cn.4) y 1 ecp0f (eie1.4) pcp0f (eip1.4) comparator 0 rising edge 0x005b 11 cp0rif (cpt0cn.5) y 1 ecp0r (eie1.5) pcp0r (eip1.5) comparator 1 falling edge 0x0063 12 cp1fif (cpt1cn.4) y 2 ecp1f (eie1.6) pcp1f (eip1.6) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 156 rev. 1.4 11.3.3. interrupt priorities each interrupt source can be individually programmed to one of two priority levels : low or high. a low prior- ity 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 11.4. 11.3.4. interrupt latency interrupt response time depends on the state of the cpu when the interrupt occurs. pending interrupts are sampled and priority decoded each system clock cycle. therefore, the fastest possible response time is 5 system clock cycles: 1 clock cycle to detect the interrupt and 4 clock cycles to co mplete the lcall to the isr. additional clock cycles will be re quired if a cache miss occurs (see section ?16. branch target cache? on page 211 for more details). if an interrupt is pending when a reti is executed, a single instruc- tion is executed before an lcall is made to serv ice the pending interrupt. therefore, the maximum response time for an interrupt (when no other interrupt is currently being serviced or the new interrupt is of greater priority) is when the cpu is performing an reti instruction followed by a div as the next instruc- tion, and a cache miss event also occurs. if the cp u is executing an isr for an interrupt with equal or higher priority, the new inte rrupt will not be serviced until the current isr comp letes, including the reti and following instruction. comparator 1 rising edge 0x006b 13 cp1rif (cpt1cn.5) y 2 ecp1r (eie1.7) pcp1f (eip1.7) timer 3 0x0073 14 tf3 (tmr3cn.7) exf3 (tmr3cn.6) y1 et3 (eie2.0) pt3 (eip2.0) adc0 end of conversion 0x007b 15 ad0int (adc0cn.5) y 0 eadc0 (eie2.1) padc0 (eip2.1) timer 4 0x0083 16 tf4 (tmr4cn.7) exf4 (tmr4cn.7) y2 et4 (eie2.2) pt4 (eip2.2) adc2 window comparator 0x008b 17 ad2wint (adc2cn.0) y2 ewadc2 (eie2.3) pwadc2 (eip2.3) adc2 end of conversion 0x0093 18 ad2int (adc2cn.5) y 2 eadc2 (eie2.4) padc2 (eip2.4) reserved 0x009b 19 n/a n/a n/a n/a n/a n/a uart1 0x00a3 20 ri1 (scon1.0) ti1 (scon1.1) y1 es1 (eie2.6) ps1 (eip2.6) table 11.4. interrupt summary (continued) interrupt source interru pt vector priority order pending flags bit addressable? cleared by hw? sfrpage (sfrpgen = 1) enable flag priority control c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 157 11.3.5. interrupt register descriptions the sfrs used to enable the interrupt sources and set t heir priority level are described below. refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). sfr definition 11.12. ie: interrupt enable bit7: ea: enable all interrupts. this bit globally enables/disabl es all interrupts. it overrides the individual interrupt mask set- tings. 0: disable all interrupt sources. 1: enable each interrupt accord ing to its individual mask setting. bit6: iegf0: general purpose flag 0. this is a general purpose flag for use under software control. bit5: et2: enabler timer 2 interrupt. this bit sets the masking of the timer 2 interrupt. 0: disable timer 2 interrupt. 1: enable timer 2 interrupt. bit4: es0: enable uart0 interrupt. this bit sets the masking of the uart0 interrupt. 0: disable uart0 interrupt. 1: enable uart0 interrupt. bit3: et1: enable timer 1 interrupt. this bit sets the masking of the timer 1 interrupt. 0: disable timer 1 interrupt. 1: enable timer 1 interrupt. bit2: ex1: enable external interrupt 1. this bit sets the masking of external interrupt 1. 0: disable external interrupt 1. 1: enable external interrupt 1. bit1: et0: enable timer 0 interrupt. this bit sets the masking of the timer 0 interrupt. 0: disable timer 0 interrupts. 1: enable timer 0 interrupts. bit0: ex0: enable external interrupt 0. this bit sets the masking of external interrupt 0. 0: disable external interrupt 0. 1: enable external interrupt 0. 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 sfr address: sfr page: 0xa8 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 158 rev. 1.4 sfr definition 11.13. ip: interrupt priority bits7?6: unused. read = 11b, write = don't care. bit5: pt2: timer 2 interrupt priority control. this bit sets the priority of the timer 2 interrupt. 0: timer 2 interrupt set to low priority. 1: timer 2 interrupt set to high priority. bit4: ps0: uart0 interrupt priority control. this bit sets the priority of the uart0 interrupt. 0: uart0 interrupt se t to low priority. 1: uart0 interrupts set to high priority. bit3: pt1: timer 1 interrupt priority control. this bit sets the priority of the timer 1 interrupt. 0: timer 1 interrupt set to low priority. 1: timer 1 interrupts set to high priority. bit2: px1: external interr upt 1 priority control. this bit sets the priority of th e external interr upt 1 interrupt. 0: external interrupt 1 set to low priority. 1: external interrupt 1 set to high priority. bit1: pt0: timer 0 interrupt priority control. this bit sets the priority of the timer 0 interrupt. 0: timer 0 interrupt set to low priority. 1: timer 0 interrupt set to high priority. bit0: px0: external interr upt 0 priority control. this bit sets the priority of th e external interr upt 0 interrupt. 0: external interrupt 0 set to low priority. 1: external interrupt 0 set to high 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 sfr address: sfr page: 0xb8 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 159 sfr definition 11.14. eie1: ex tended interrupt enable 1 bit7: ecp1r: enable comparator1 (cp1) rising edge interrupt. this bit sets the masking of the cp1 rising edge interrupt. 0: disable cp1 rising edge interrupts. 1: enable cp1 rising edge interrupts. bit6: ecp1f: enable comparator1 (cp1) falling edge interrupt. this bit sets the masking of the cp1 falling edge interrupt. 0: disable cp1 falling edge interrupts. 1: enable cp1 fallin g edge interrupts. bit5: ecp0r: enable comparator0 (cp0) rising edge interrupt. this bit sets the masking of the cp0 rising edge interrupt. 0: disable cp0 rising edge interrupts. 1: enable cp0 rising edge interrupts. bit4: ecp0f: enable comparator0 (cp0) falling edge interrupt. this bit sets the masking of the cp0 falling edge interrupt. 0: disable cp0 falling edge interrupts. 1: enable cp0 fallin g edge interrupts. bit3: epca0: enable programmable counter array (pca0) interrupt. this bit sets the masking of the pca0 interrupts. 0: disable pca0 interrupts. 1: enable pca0 interrupts. bit2: ewadc0: enable window comparison adc0 interrupt. this bit sets the masking of adc0 window comparison interrupt. 0: disable adc0 window comparison interrupt. 1: enable adc0 window comparison interrupt. bit1: esmb0: enable system management bus (smbus0) interrupt. this bit sets the masking of the smbus interrupt. 0: disable smbus interrupts. 1: enable smbu s interrupts. bit0: espi0: enable serial peripher al interface (spi 0) interrupt. this bit sets the masking of spi0 interrupt. 0: disable spi0 interrupts. 1: enable spi0 interrupts. r/w r/w r/w r/w r/w r/w r/w r/w reset value ecp1r ecp1f ecp0r ecp0f epca0 ewadc0 esmb0 espi0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xe6 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 160 rev. 1.4 sfr definition 11.15. eie2: ex tended interrupt enable 2 bit7: unused. read = 0b, write = don't care. bit6: es1: enable uart1 interrupt. this bit sets the masking of the uart1 interrupt. 0: disable uart1 interrupts. 1: enable uart1 interrupts. bit5: unused. read = 0b, write = don't care. bit4: eadc2: enable adc2 end of conversion interrupt. this bit sets the masking of the adc2 end of conversion interrupt. 0: disable adc2 end of conversion interrupts. 1: enable adc2 end of conversion interrupts. bit3: ewadc2: enable window comparison adc2 interrupt. this bit sets the masking of adc2 window comparison interrupt. 0: disable adc2 window comparison interrupts. 1: enable adc2 window comparison interrupts. bit2: et4: enable timer 4 interrupt this bit sets the masking of the timer 4 interrupt. 0: disable timer 4 interrupts. 1: enable timer 4 interrupts. bit1: eadc0: enable adc0 end of conversion interrupt. this bit sets the masking of the adc0 end of conversion interrupt. 0: disable adc0 end of conversion interrupts. 1: enable adc0 end of conversion interrupts. bit0: et3: enable timer 3 interrupt. this bit sets the masking of the timer 3 interrupt. 0: disable timer 3 interrupts. 1: enable timer 3 interrupts. r/w r/w r/w r/w r/w r/w r/w r/w reset value - es1 - eadc2 ewadc2 et4 eadc0 et3 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xe7 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 161 sfr definition 11.16. eip1: ex tended interrupt priority 1 bit7: pcp1r: comparator1 (cp1) risi ng interrupt priority control. this bit sets the priority of the cp1 interrupt. 0: cp1 rising interrupt set to low priority. 1: cp1 rising interrupt set to high priority. bit6: pcp1f: comparator1 (cp1) fa lling interrupt pr iority control. this bit sets the priority of the cp1 interrupt. 0: cp1 falling interrupt set to low priority. 1: cp1 falling interrupt set to high priority. bit5: pcp0r: comparator0 (cp0) risi ng interrupt priority control. this bit sets the priority of the cp0 interrupt. 0: cp0 rising interrupt set to low priority. 1: cp0 rising interrupt set to high priority. bit4: pcp0f: comparator0 (cp0) fa lling interrupt pr iority control. this bit sets the priority of the cp0 interrupt. 0: cp0 falling interrupt set to low priority. 1: cp0 falling interrupt set to high priority. bit3: ppca0: programmable counter array (pca0) interrupt priority control. this bit sets the priority of the pca0 interrupt. 0: pca0 interrupt set to low priority. 1: pca0 interrupt set to high priority. bit2: pwadc0: adc0 window comparator interrupt priority control. this bit sets the priority of the adc0 window interrupt. 0: adc0 window interrup t set to low priority. 1: adc0 window interrup t set to high priority. bit1: psmb0: system management bus (smbus0) interrupt priority control. this bit sets the priority of the smbus0 interrupt. 0: smbus interrupt se t to low priority. 1: smbus interrupt se t to high priority. bit0: pspi0: serial peripheral interfac e (spi0) inte rrupt priority control. this bit sets the priority of the spi0 interrupt. 0: spi0 interrupt set to low priority. 1: spi0 interrupt set to high priority. r/w r/w r/w r/w r/w r/w r/w r/w reset value pcp1r pcp1f pcp0r pcp0f ppca0 pwadc0 psmb0 pspi0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xf6 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 162 rev. 1.4 sfr definition 11.17. eip2: ex tended interrupt priority 2 bit7: unused. read = 0b, write = don't care. bit6: es1: uart1 interrupt priority control. this bit sets the priority of the uart1 interrupt. 0: uart1 interrupt se t to low priority. 1: uart1 interrupt set to high priority. bit5: unused. read = 0b, write = don't care. bit4: padc2: adc2 end of conversion interr upt priority control. this bit sets the priority of the adc2 end of conversion interrupt. 0: adc2 end of conversion in terrupt set to low priority. 1: adc2 end of conversion interrupt set to high priority. bit3: pwadc2: adc2 window compare interrupt priority control. this bit sets the priority of the adc2 window compare interrupt. 0: adc2 window compare inte rrupt set to low priority. 1: adc2 window compare interrupt set to high priority. bit2: pt4: timer 4 interrupt priority control. this bit sets the priority of the timer 4 interrupt. 0: timer 4 interrupt set to low priority. 1: timer 4 interrupt set to high priority. bit1: padc0: adc0 end of conversion interr upt priority control. this bit sets the priority of the adc0 end of conversion interrupt. 0: adc0 end of conversion in terrupt set to low priority. 1: adc0 end of conversion interrupt set to high priority. bit0: pt3: timer 3 interr upt priority control. this bit sets the priority of the timer 3 interrupts. 0: timer 3 interrupt set to low priority. 1: timer 3 interrupt set to high priority. r/w r/w r/w r/w r/w r/w r/w r/w reset value - ps1 - padc2 pwadc2 pt4 padc0 pt3 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xf7 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 163 11.4. power management modes the cip-51 core has two software programmable power management modes: idle and stop. idle mode halts the cpu while leaving the external peripherals and internal clocks active. in stop mode, the cpu is halted, all interrupts and timers (except the missing clock detector) are inactive, and the system clock is stopped. since clocks are running in idle mode, powe r 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 11.18 describes the powe r control register (pcon) used to control the cip- 51's power management modes. although the cip-51 has idle and stop modes built in (as with any standard 8051 architecture), power management of the entire mcu is better accomplished by enabling/disabling individual peripherals as needed. each analog peripheral can be disabled when not in use and put into low power mode. digital peripherals, such as timers or serial buses, draw littl e power whenever they are not in use. turning off the flash memory saves power, simila r to entering idle mode. turning off the oscillator saves even more power, but requires a reset to restart the mcu. 11.4.1. idle mode setting the idle mode select bit (pcon.0) causes the cip-51 to halt the cpu and enter idle mode as soon as the instruction that sets the bit completes. all internal register s 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 inter- rupt will cause the idle m ode selection bit (pco n.0) to be cleared and the cp u to resume operation. the pending interrupt will be serviced and the next inst ruction to be executed afte r the return from interrupt (reti) will be the instruction immediately following th e one that set the id le mode select bit. if idle mode is terminated by an internal or external reset, the cip-51 performs a normal reset sequence and begins pro- gram execution at address 0x00000. if enabled, the wdt will eventually c ause an internal watchd og reset and thereby te rminate 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 oppor- tunity for additional power savings, allowing the system to remain in the idle mo de indefinitely, waiting for an external stimulus to wake up the system. refer to section 13 for more information on the use and con- figuration of the wdt. note: any instruction which sets the idle bit should be immediately followed by an instruction which has two or more opcode bytes. for example: // in ?c?: pcon |= 0x01; // set idle bit pcon = pcon; // ... followed by a 3-cycle dummy instruction ; in assembly: orl pcon, #01h ; set idle bit mov pcon, pcon ; ... followed by a 3-cycle dummy instruction if the instruction following the write to the idle bit is a single-byte instruction and an interrupt occurs during the execution of the instruction of the instruction whic h sets the idle bit, the cpu may not wake from idle mode when a future interrupt occurs. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 164 rev. 1.4 11.4.2. stop mode setting the stop mode select bit (pcon.1) causes the cip-51 to enter stop mode as soon as the instruc- tion that sets the bit completes. in stop mode, the cpu and oscillato rs 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 0x00000. if enabled, the missing clock detector will cause an internal reset and t hereby 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. sfr definition 11.18. pcon: power control bits7?3: reserved. bit1: stop: stop mode select. writing a ?1? to this bit will pl ace the cip-51 into stop mode . this bit will always read ?0?. 1: cip-51 forced into power-down mode. (t urns off oscillator). bit0: idle: idle mode select. writing a ?1? to this bit will pl ace the cip-51 into idle mode. this bit will always read ?0?. 1: cip-51 forced into idle mode. (shuts off cl ock to cpu, but clock to timers, interrupts, and all peripherals remain active.) r/w r/w r/w r/w r/w r/w r/w r/w reset value ------stopidle00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x87 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 165 12. multiply and accumulate (mac0) the c8051f120/1/2/3 and c8051f130/1/2/3 devices incl ude a multiply and accumulate engine which can be used to speed up many mathematical operations. mac0 contains a 16-by-16 bit multiplier and a 40-bit adder, which can perform integer or fractional multiply -accumulate and multiply operations on signed input values in two sysclk cycles. a rounding engine provides a rounded 16-bit fractional result after an addi- tional (third) sysclk cycle. mac0 also contains a 1-bit arithmetic shifter that will left or right-shift the con- tents of the 40-bit accumula tor in a single sysclk cycle. figure 12.1 shows a block diagram of the mac0 unit and its associated special function registers. figure 12.1. mac0 block diagram 12.1. special function registers there are thirteen special function register (sfr) lo cations associated with mac0. two of these regis- ters are related to configuration and operation, while the other eleven are used to store multi-byte input and output data for mac0. the configuration register mac0cf (sfr definition 12.1) is used to configure and control mac0. the status register mac0sta (sfr definition 12.2) contains flags to indicate overflow conditions, as well as ze ro and negative results. the 16-bit mac0a (mac0ah:mac0al) and mac0b (mac0bh:mac0bl) registers are used as inputs to the multiplier. the mac0 accumulator register is 40 bits long, and consists of five sfrs: mac0ovr, mac0acc3, mac0acc2, mac0acc1, and mac0acc0. the primary results of a mac0 operation are stored in the accumulator registers. if they are needed, the rounded results are stored in the 16-bit rounding register mac0rnd (mac0rndh:mac0rndl). mac0cf mac0ms mac0fm mac0sat mac0ca mac0sd mac0sc mac0sta mac0n mac0so mac0z mac0ho 16 x 16 multiply mac0rndh mac0rndl mac0 rounding register mac0ovr mac0acc3 mac0acc2 mac0acc1 mac0acc0 mac0 accumulator 40 bit add mac0ms 1 0 0 rounding engine 1 bit shift mac0fm flag logic mac0bh mac0bl mac0 b register mac0ah mac0al mac0 a register c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 166 rev. 1.4 12.2. integer and fractional math mac0 is capable of interpreting the 16-bit inputs stored in mac0a and mac0b as signed integers or as signed fractional numbers. when the mac0fm bit (mac0c f.1) is cleared to ?0?, the inputs are treated as 16-bit, 2?s complement, int eger values. after the oper ation, the accumulator w ill contain a 40-bit, 2?s com- plement, integer value. figure 12.2 shows how integers are stored in the sfrs. figure 12.2. integer mode data representation when the mac0fm bit is set to ?1?, the inputs are treated at 16-bit, 2?s complement, fractional values. the decimal point is located between bits 15 and 14 of the data word. after the operation, the accumulator will contain a 40-bit, 2?s complement, fractional value, with the decimal point located between bits 31 and 30. figure 12.3 shows how fractional numbers are stored in the sfrs. figure 12.3. fractional mode data representation -(2 15 ) 2 14 2 13 2 12 2 11 2 10 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 -(2 39 ) 2 38 2 33 2 32 2 31 2 30 2 1 2 0 2 2 2 29 2 3 2 28 2 4 high byte low byte mac0ovr mac0acc3 : mac0acc2 : mac0acc1 : mac0acc0 mac0a and mac0b bit weighting mac0 accumulator bit weighting -1 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 2 -8 2 -9 2 -10 2 -11 2 -12 2 -13 2 -14 2 -15 -(2 8 ) 2 7 2 2 2 1 2 0 2 -1 2 -30 2 -31 2 -29 2 -2 2 -28 2 -3 2 -27 high byte low byte mac0ovr mac0acc3 : mac0acc2 : mac0acc1 : mac0acc0 mac0a, and mac0b bit weighting mac0 accumulator bit weighting mac0rnd bit weighting * the mac0rnd register contains the 16 lsbs of a two's complement number. the mac0n flag can be used to determine the sign of the mac0rnd register. 1 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 2 -8 2 -9 2 -10 2 -11 2 -12 2 -13 2 -14 2 -15 high byte low byte * -2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 167 12.3. operating in multiply and accumulate mode mac0 operates in multiply and accumulate (mac) mo de when the mac0ms bit (mac0cf.0) is cleared to ?0?. when operating in mac mode, mac0 performs a 16 -by-16 bit multiply on t he contents of the mac0a and mac0b registers, and adds the result to the contents of the 40-bit mac0 accumulator. figure 12.4 shows the mac0 pipeline. there are three stages in the pipeline, each of which takes exactly one sys- clk cycle to complete. the mac operati on is initiated with a write to the mac0bl register. after the mac0bl register is written, mac0a and mac0b ar e multiplied on the first sysclk cycle. during the sec- ond stage of the mac0 pipeline, the results of the multiplication are added to the current accumulator con- tents, and the result of the addition is stored in the mac0 accumulator. the status flags in the mac0sta register are set after the end of the second pipeline st age. during the second stage of the pipeline, the next multiplication can be initiated by wr iting to the mac0bl register, if it is desired. the rounded (and option- ally, saturated) result is available in the mac0rndh and mac0rndl registers at the end of the third pipe- line stage. if the mac0ca bit (mac0cf.3) is set to ?1? when the mac operation is initiated, the accumulator and all mac0sta flags will be clea red during the next cycle of the controller?s clock (sysclk). the mac0ca bit will clear itself to ?0? wh en the clear operation is complete. figure 12.4. mac0 pipeline 12.4. operating in multiply only mode mac0 operates in multiply only mode when the mac0ms bit (mac0cf.0) is set to ?1?. multiply only mode is identical to multiply and accumulate mode, except that the multiplication result is added with a value of zero before being stored in the mac0 accumulator (i.e. it overwrites the current accumulator contents). the result of the multiplication is available in th e mac0 accumulator registers at the end of the second mac0 pipeline stage (two sysclks afte r writing to mac0bl). as in mac mode, the rounded result is available in the mac0 rounding registers after the thir d pipeline stage. note that in multiply only mode, the mac0ho flag is not affected. 12.5. accumulator shift operations mac0 contains a 1-bit arithmetic shift function which ca n be used to shift the contents of the 40-bit accu- mulator left or right by one bit. the accumulator sh ift is initiated by writin g a ?1? to the mac0sc bit (mac0cf.5), and takes one sysclk cycle (the rounded result is available in the mac0 rounding regis- ters after a second sysclk cycle, and mac0sc is clea red to ?0?). the direction of the arithmetic shift is controlled by the mac0sd bit (mac0cf.4). when this bit is cleared to ?0?, the mac0 accumulator will shift left. when the mac0sd bit is set to ?1?, the mac0 accumulator will shift right. right-shift operations are sign-extended with the current value of bit 39. note t hat the status flags in the mac0sta register are not affected by shift operations. multiply add round multiply add round write mac0bl write mac0bl mac0 operation begins next mac0 operation may be initiated here accumulator results available rounded results available c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 168 rev. 1.4 12.6. rounding and saturation a rounding engine is included, which can be used to provide a rounded result when operating on frac- tional numbers. mac0 uses an unbiased rounding algorithm to round the data stored in bits 31 ? 16 of the accumulator, as shown in table 12.1. rounding occurs during the third stage of the mac0 pipeline, after any shift operation, or on a write to the lsb of the accumulator. the rounded results are stored in the rounding registers: mac0rndh (sfr definition 12 .12) and mac0rndl (sfr definition 12.13). the accumulator registers are not affected by the rounding engine. although rounding is primarily used for frac- tional data, the data in the rounding registers is updated in the same way when operating in integer mode. the rounding engine can also be used to saturate the results stored in the rounding registers. if the mac0sat bit is set to ?1? and the ro unding register overflow s, the rounding regist ers will satu rate. when a positive overflow occurs, the roun ding registers will show a value of 0x7fff when saturated. for a nega- tive overflow, the rounding registers will show a va lue of 0x8000 wh en saturated. if the mac0sat bit is cleared to ?0?, the rounding registers will not saturate. 12.7. usage examples this section details some soft ware examples for using mac0. section 12.7.1 shows a series of two mac operations using fractional numbers. section 12.7.2 shows a single operation in multiply only mode with integer numbers. the last example, shown in section 12.7.3 , demonstrates how the left-shift and right- shift operations can be used to modify the accumulator. all of the examples assume that all of the flags in the mac0sta register ar e initially set to ?0?. 12.7.1. multiply and accumulate example the example below implements the equation: mov mac0cf, #0ah ; set to clear accumulator, use fractional numbers mov mac0ah, #40h ; load mac0a register with 4000 hex = 0.5 decimal mov mac0al, #00h mov mac0bh, #20h ; load mac0b register with 2000 hex = 0.25 decimal mov mac0bl, #00h ; this line initiates the first mac operation mov mac0bh, #e0h ; load mac0b register with e000 hex = -0.25 decimal mov mac0bl, #00h ; this line initiates the second mac operation nop nop ; after this instruction, the accumulator should be equal to 0, ; and the mac0sta register should be 0x04, indicating a zero nop ; after this instruction, the rounding register is updated table 12.1. mac0 rounding (mac0sat = 0) accumulator bits 15?0 (mac0acc1:mac0acc0) accumulator bits 31?16 (mac0acc3:mac0acc2) rounding direction rounded results (mac0rndh:mac0rndl) greater than 0x8000 anything up (mac0acc3:mac0acc2) + 1 less than 0x8000 anything down (mac0acc3:mac0acc2) equal to 0x8000 odd (lsb = 1) up (mac0acc3:mac0acc2) + 1 equal to 0x8000 even (lsb = 0) down (mac0acc3:mac0acc2) 0.5 0.25 ? ?? 0.5 0.25 ? ? ?? + 0.125 0.125 ?0.0 == c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 169 12.7.2. multiply only example the example below implements the equation: mov mac0cf, #01h ; use integer numbers, and multiply only mode (add to zero) mov mac0ah, #12h ; load mac0a register with 1234 hex = 4660 decimal mov mac0al, #34h mov mac0bh, #feh ; load mac0b register with fedc hex = -292 decimal mov mac0bl, #dch ; this line initiates the multiply operation nop nop ; after this instruction, the accumulator should be equal to ; ffffeb3cb0 hex = -1360720 decimal. the mac0sta register should ; be 0x01, indicating a negative result. nop ; after this instruction, the rounding register is updated 12.7.3. mac0 accumulator shift example the example below shifts the mac0 accumulator left one bit, and then right two bits: mov mac0ovr, #40h ; the next few instructions load the accumulator with the value mov mac0acc3, #88h ; 4088442211 hex. mov mac0acc2, #44h mov mac0acc1, #22h mov mac0acc0, #11h mov mac0cf, #20h ; initiate a left-shift nop ; after this instruction, the accumulator should be 0x8110884422 nop ; the rounding register is updated after this instruction mov mac0cf, #30h ; initiate a right-shift mov mac0cf, #30h ; initiate a second right-shift nop ; after this instruction, the accumulator should be 0xe044221108 nop ; the rounding register is updated after this instruction 4660 292? ? 1360720?= c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 170 rev. 1.4 sfr definition 12.1. mac0cf: mac0 configuration bits 7 ? 6: unused: read = 00b, write = don?t care. bit 5: mac0sc: accumu lator shift control. when set to 1, the 40-bit mac0 accumulator register will be shifted during the next sysclk cycle. the direction of the shift (left or right) is controlled by the mac0rs bit. this bit is cleared to ?0? by hardware when the shift is complete. bit 4: mac0sd: accumula tor shift direction. this bit controls the direction of the accu mulator shift activate d by the mac0sc bit. 0: mac0 accumulator will be shifted left. 1: mac0 accumulator will be shifted right. bit 3: mac0ca: clear accumulator. this bit is used to reset mac0 before the next operation. when set to ?1?, the mac0 accumulator will be cleared to zero and the mac0 status regis- ter will be reset during the next sysclk cycle. this bit will be cleared to ?0? by hardware when the reset is complete. bit 2: mac0sat: saturate rounding register. this bit controls whether the rounding register will saturate. if this bit is set and a soft overflow occurs, the rounding r egister will saturate. this bit does not affect the operation of the mac0 accumulator. see section 12.6 for more details about rounding and saturation. 0: rounding register will not saturate. 1: rounding register will saturate. bit 1: mac0fm: fractional mode. this bit selects between integer mode and fractional mode for mac0 operations. 0: mac0 operates in integer mode. 1: mac0 operates in fractional mode. bit 0: mac0ms: mode select this bit selects between mac mode and multiply only mode. 0: mac (multiply and accumulate) mode. 1: multiply only mode. note: the contents of this register should not be changed by software during the first two mac0 pipeline stages. r r r/w r/w r/w r/w r/w r/w reset value - - mac0sc mac0sd mac0ca mac0sat mac0fm mac0ms 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc3 sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 171 sfr definition 12.2. mac0sta: mac0 status sfr definition 12.3. mac0ah: mac0 a high byte bits 7 ? 4: unused: read = 0000b, write = don?t care. bit 3: mac0ho: hard overflow flag. this bit is set to ?1? whenever an overflow out of the mac0ovr register occurs during a mac operation (i.e. when mac0ovr changes from 0x7f to 0x80 or from 0x80 to 0x7f). the hard overflow flag must be cleared in software by directly writing it to ?0?, or by resetting the mac logic using the mac0ca bit in register mac0cf. bit 2: mac0z: zero flag. this bit is set to ?1? if a mac0 operation results in an accumulator value of zero. if the result is non-zero, this bit will be cleared to ?0?. bit 1: mac0so: soft overflow flag. this bit is set to ?1? when a mac operation causes an overflow into the sign bit (bit 31) of the mac0 accumulator. if the overflow conditio n is corrected after a subsequent mac opera- tion, this bit is cleared to ?0?. bit 0: mac0n: negative flag. if the mac accumulator result is negative, this bit w ill be set to ?1?. if t he result is positive or zero, this flag w ill be cleared to ?0?. *note: the contents of this register should not be changed by software during the first two mac0 pipeline stages. r r r r r/w r/w r/w r/w reset value - - - - mac0ho mac0z mac0so mac0n 00000100 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: 0xc0 sfr page: 3 bits 7 ? 0: high byte (bits 15 ? 8) of mac0 a register. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc2 sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 172 rev. 1.4 sfr definition 12.4. mac0al: mac0 a low byte sfr definition 12.5. mac0bh: mac0 b high byte sfr definition 12.6. mac0bl: mac0 b low byte bits 7 ? 0: low byte (bits 7 ? 0) of mac0 a register. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xc1 sfr page: 3 bits 7 ? 0: high byte (bits 15 ? 8) of mac0 b register. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x92 sfr page: 3 bits 7 ? 0: low byte (bits 7 ? 0) of mac0 b register. a write to this register initiates a multip ly or multiply and accumulate operation. *note: the contents of this register should not be chan ged by software during the first mac0 pipeline stage. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x91 sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 173 sfr definition 12.7. mac0acc3: mac0 accumulator byte 3 sfr definition 12.8. mac0acc2: mac0 accumulator byte 2 sfr definition 12.9. mac0acc1: mac0 accumulator byte 1 bits 7 ? 0: byte 3 (bits 31 ? 24) of mac0 accumulator. *note: the contents of this register shoul d not be changed by software during the first two mac0 pipeline stages. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x96 sfr page: 3 bits 7 ? 0: byte 2 (bits 23 ? 16) of mac0 accumulator. *note: the contents of this register shoul d not be changed by software during the first two mac0 pipeline stages. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x95 sfr page: 3 bits 7 ? 0: byte 1 (bits 15 ? 8) of mac0 accumulator. *note: the contents of this register shoul d not be changed by software during the first two mac0 pipeline stages. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x94 sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 174 rev. 1.4 sfr definition 12.10. mac0acc0: mac0 accumulator byte 0 sfr definition 12.11. mac0ovr: mac0 accumulator overflow sfr definition 12.12. mac0rndh: mac0 rounding register high byte bits 7 ? 0: byte 0 (bits 7 ? 0) of mac0 accumulator. *note: the contents of this register should not be changed by software during the first two mac0 pipeline stages. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x93 sfr page: 3 bits 7 ? 0: mac0 accumulator overflow bits (bits 39 ? 32). *note: the contents of this register shoul d not be changed by software during the first two mac0 pipeline stages. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0x97 sfr page: 3 bits 7 ? 0: high byte (bits 15 ? 8) of mac0 rounding register. r r r r r r r r reset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xcf sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 175 sfr definition 12.13. m ac0rndl: mac0 rounding register low byte bits 7 ? 0: low byte (bits 7 ? 0) of mac0 rounding register. rrrrrrrrr e s e t v a l u e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: 0xce sfr page: 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 176 rev. 1.4 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 177 13. reset sources reset circuitry allows the controller to be easily plac ed in a predefined default condition. on entry to this reset state, th e following occur: ? cip-51 halts program execution. ? special function registers (sfrs) are initialized to their defined reset values. ? external port pins are forced to a known configuration. ? interrupts and timers are disabled. 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 prev iously stored data is preserved. however, since the stack pointer sfr is reset, the stack is effectively lost even though the data on the stack are not altered. the i/o port latches are reset to 0xff (all logic 1?s), activating internal weak pullups during and after the reset. for v dd monitor resets, the rst pin is driven low until the end of the v dd reset timeout. on exit from the reset state, the program counter (pc) is reset, and the system clock defaults to the inter- nal oscillator runn ing at its lowest frequenc y. refer to section ? 14. oscillators ? on page 185 for informa- tion on selecting and conf iguring the system clock source. the watchdog timer is enabled using its longest timeout interval (see section ? 13.7. watchdog timer reset ? on page 179 ). 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, softwa re command, comparator0, missing clock detector, and watchdog timer. each reset source is described in the following sections. figure 13.1. reset sources wdt xtal1 xtal2 osc internal clock generator system clock cip-51 microcontroller core missing clock detector (one- shot) wdt strobe software reset extended interrupt handler clock select /rst + - vdd supply reset timeout (wired-or) system reset supply monitor pre reset funnel + - cp0+ comparator0 cp0- (port i/o) crossbar cnvstr (cnvstr reset enable) (cp0 reset enable) en wdt enable en mcd enable pll circuitry c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 178 rev. 1.4 13.1. power-on reset the c8051f120/1/2/3/4/5/6/7 family incorporates a po wer supply monitor that holds the mcu in the reset state until v dd rises above the v rst level during power-up. see figure 13.2 for timing diagram, and refer to table 13.1 for the electrical characteristic s of the power supply monitor circuit. the rst pin is asserted low until the end of the 100 ms v dd monitor timeout in order to allow the v dd supply to stabilize. the v dd monitor reset is enabled and disabled using the external v dd monitor enable pin (monen). when the v dd monitor is enabled, it is selected as a reset source using the porsf bit. if the rstsrc register is written by firmware, porsf (rstsrc.1) mu st be written to ?1? for the v dd monitor to be effective. 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 indeterminat e. 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. figure 13.2. reset timing 13.2. power-fail reset when a power-down transition or power irregularity causes v dd to drop below v rst , the power supply monitor will drive the rst pin low and return the cip-51 to the reset state. when v dd returns to a level above vrst, the cip-51 will leave th e reset state in the sa me manner as that for the power-on reset (see figure 13.2). note that even though internal data memory contents are not altered by the power-fail reset, it is impossible to determine if v dd dropped below the level required for data retention. if the porsf flag is set to logic 1, the data may no longer be valid. vdd monitor reset power-on reset /rst t volts 1.0 2.0 logic high logic low 100ms 100ms v d d 2.70 2.55 v rst c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 179 13.3. external reset the external rst pin provides a means for external circuitry to force the mcu into a reset state. asserting the rst pin low will cause the mcu to ente r the reset state. it may be desir able to provide an external pul- lup and/or decoupling of the rst pin to avoid erroneou s noise-induced resets. the mcu will remain in reset until at least 12 clock cy cles after the active-low rst signal is removed. the pinrsf flag (rst- src.0) is set on exit from an external reset. 13.4. missing clock detector reset the missing clock detector is essentially a one-shot circuit that is triggered by the mcu system clock. if the system clock goes away for more than 100 s, the one-sh ot will time out and generate a reset. after a missing clock detector re set, the mcdrsf flag (rsts rc.2) will be set, signifying the msd as the reset source; otherwise, this bit reads ?0?. the state of the rst pin is unaffected by this reset. setting the mcdrsf bit, rstsrc.2 (see section ? 14. oscillators ? on page 185 ) enables the missing clock detector. 13.5. comparator0 reset comparator0 can be configured as a reset input by writing a ?1? to the c0rsef flag (rstsrc.5). comparator0 should be enabled using cpt0cn.7 (see section ? 10. comparators ? on page 119 ) prior to writing to c0rsef to prevent any turn-on chatter on the output from generating an unwanted reset. the comparator0 reset is active-low: if the non-invertin g input voltage (cp0+ pin) is less than the inverting input voltage (cp0- pin), the mcu is put into the reset state. after a comparator0 reset, the c0rsef flag (rstsrc.5) will read ?1? signif ying comparator0 as the reset source; ot herwise, this bit reads ?0?. the state of the rst pin is unaffected by this reset. 13.6. external cnvstr0 pin reset the external cnvstr0 signal can be configured as a reset input by writing a ?1? to the cnvrsef flag (rstsrc.6). the cnvstr0 signal can appear on any of the p0, p1, p2 or p3 i/o pins as described in section ? 18.1. ports 0 through 3 and the priority crossbar decoder ? on page 238 . note that the cross- bar must be configured for the cnvstr0 signal to be routed to the appropriate port i/o. the crossbar should be configured and enabled before the cnvrsef is set. when configured as a reset, cnvstr0 is active-low and level sensitive. cnvstr0 cannot be us ed to start adc0 conversions when it is configured as a reset source. after a cnvstr0 reset, the cnvrsef flag (rstsrc.6) will read ?1? signifying cnvstr0 as the reset source; otherwise, this bit reads ?0?. the state of the rst pin is unaffected by this reset. 13.7. watchdog timer reset the mcu includes a programmable wa tchdog timer (wdt) running off th e system clock. a wdt overflow will force the mcu into the reset state. to pr event the reset, the wd t must be restarted by application soft- ware before overflow. if the system experiences a soft ware or hardware malfuncti on preventing the soft- ware from restarting the wdt, the wdt will overfl ow and cause a reset. this should prevent the system from running out of control. following a reset the wdt is automatically enabled and running with the default maximum time interval. if desired the wdt can be disabled by system software or locked on to prevent accidental disabling. once locked, the wdt cannot be disabled until th e next system reset. the state of the rst pin is unaffected by this reset. the wdt consists of a 21-bit timer running from th e programmed system clock. the timer measures the period between specific writes to its control regist er. if this period exceeds the programmed limit, a wdt c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 180 rev. 1.4 reset is generated. the wdt can be enabled and disabled as needed in software, or can be permanently enabled if desired. watchdog features are controlled via the watchdog timer control register (wdtcn) shown in sfr definition 13.1. 13.7.1. enable/reset wdt the watchdog timer is both enabled and reset by writ ing 0xa5 to the wdtcn register. the user's applica- tion software should include periodic writes of 0x a5 to wdtcn as needed to prevent a watchdog timer overflow. the wdt is enabled and rese t as a result of any system reset. 13.7.2. disable wdt writing 0xde followed by 0xad to the wdtcn register disables the wdt. the following code segment illustrates disabling the wdt: clr ea ; disable all interrupts mov wdtcn,#0deh ; disable software watchdog timer mov wdtcn,#0adh setb ea ; re-enable interrupts the writes of 0xde and 0xad must occur within 4 cl ock cycles of each other, or the disable operation is ignored. this means that the prefetch engine should be enabled and interrupts should be disabled during this procedure to avoid any delay between the two writes. 13.7.3. disable wdt lockout writing 0xff to wdtcn locks out the disable feature. once locked out, the disable operation is ignored until the next system reset. writing 0xff does not enabl e or reset the watchdog timer. applications always intending to use the watchdog should writ e 0xff to wdtcn in the initialization code. 13.7.4. setting wdt interval wdtcn.[2:0] control the watchdog timeout interval. the interval is given by the following equation: ; where t sysclk is the system clock period. 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 inte rval. wdtcn.[2:0] reads 111b after a system reset. 4 3 wdtcn 20 ? ?? t sysclk ? c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 181 sfr definition 13.1. wdtcn: watchdog timer control bits7 ? 0: wdt control writing 0xa5 both enables and reloads the wdt. writing 0xde followed within 4 syste m clocks by 0xad disables the wdt. writing 0xff locks out the disable feature. bit4: watchdog status bit (when read) reading the wdtcn.[4] bit indicates the watchdog timer status. 0: wdt is inactive 1: wdt is active bits2 ? 0: watchdog timeout interval bits the wdtcn.[2:0] bits set the watchdog timeout interval. when writing these bits, wdtcn.7 must be set to 0. r/w r/w r/w r/w r/w r/w r/w r/w reset value xxxxx111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xff all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 182 rev. 1.4 sfr definition 13.2. r stsrc: reset source bit7: reserved. bit6: cnvrsef: convert start 0 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. bit5: c0rsef: comparator0 reset enable and flag. write: 0: comparator0 is not a reset source. 1: comparator0 is a reset source (active low). read: 0: source of last reset was not comparator0. 1: source of last reset was comparator0. bit4: 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 wa s not a write to the swrsf bit. 1: source of last reset was a write to the swrsf bit. bit3: wdtrsf: watchdog timer reset flag. 0: source of last reset was not wdt timeout. 1: source of last reset was wdt timeout. bit2: 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. bit1: porsf: power-on reset flag. write: if the v dd 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 v dd monitor as a reset source. 0: de-select the v dd monitor as a reset source. 1: select the v dd monitor as a reset source. important: at power-on, the v dd monitor is enabled/di sabled using the external v dd monitor enable pin (monen). the porsf bi t does not disable or enable the v dd monitor circuit. it sim- ply selects the v dd 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 v dd monitor reset. in eith er case, data memory should be considered indeterminate following the reset. 0: source of last reset was not a power-on or v dd monitor reset. 1: source of last reset was a power-on or v dd monitor reset. note: when this flag is read as '1', all other reset flags are indeterminate. bit0: 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. r r/w r/w r/w r r/w r/w r/w reset value - cnvrsef c0rsef swrsef wdtrsf mcdrsf porsf pinrsf 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xef 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 183 table 13.1. reset elect rical characteristics ?40 to +85 c unless otherwise specified. parameter conditions min typ max units rst output low voltage i ol = 8.5 ma, v dd = 2.7 to 3.6 v ??0.6v rst input high voltage 0.7 x v dd ?? v rst input low voltage ? ? 0.3 x v dd rst input leakage current rst = 0.0 v ? 50 ? a v dd for rst output valid 1.0 ? ? v av+ for rst output valid 1.0 ? ? v v dd por threshold (v rst )* 2.40 2.55 2.70 v minimum rst low time to gen- erate a system reset 10??ns reset time delay rst rising edge after v dd crosses v rst threshold 80 100 120 ms missing clock detector timeout time from last system clock to reset initiation 100 220 500 s *note: when operating at frequencies above 50 mhz, minimum v dd supply voltage is 3.0 v. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 184 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 185 14. oscillators the devices include a programmable internal oscillato r and an external oscillato r drive circuit. the internal oscillator can be enabled, disabled , and calibrated us ing the oscicn and oscicl registers, as shown in figure 14.1. the system clock can be sour ced by the external osc illator circuit, the intern al oscillator, or the on-chip phase-locked loop (pll). the internal oscillator's electrical specifications ar e given in table 14.1 on page 185. figure 14.1. oscillator diagram 14.1. internal cali brated oscillator all devices include a calibrated internal oscillator that defaults as the system clock after a system reset. the internal oscillato r period can be adjusted via the oscicl r egister as defined by sfr definition 14.1. oscicl is factory calibrated to obtain a 24.5 mhz frequency. table 14.1. oscillator elec trical characteristics ?40c to +85c unless otherwise specified. parameter conditions min typ max units calibrated internal oscillator frequency 24 24.5 25 mhz internal oscillator supply current (from v dd ) oscicn.7 = 1 ? 400 ? a external clock frequency 0 ? 30 mhz t xch (external clock high time) 15 ? ? ns t xcl (external clock low time) 15 ? ? ns osc calibrated internal oscillator input circuit en sysclk n oscicl oscicn ioscen ifrdy ifcn1 ifcn0 xtal1 xtal2 option 2 vdd xtal1 option 1 option 4 xtal1 oscxcn xtlvld xoscmd2 xoscmd1 xoscmd0 xfcn2 xfcn1 xfcn0 clksel clkdiv1 clkdiv0 clksl1 clksl0 00 01 pll 10 option 3 xtal1 xtal2 agnd av+ c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 186 rev. 1.4 electrical specifications for the precision internal oscillator are given in tabl e 14.1. note that the system clock may be derived from the programm ed internal oscillator divided by 1, 2, 4, or 8, as defined by the ifcn bits in register oscicn. sfr definition 14.1. oscicl: inte rnal oscillator calibration. sfr definition 14.2. oscicn: in ternal oscillator control bits 7?0: oscicl: internal o scillator calibration register. this register calibrates the inte rnal oscillator period. the rese t value for oscicl defines the internal oscillator base frequenc y. the reset value is factory calibrated to generate an inter- nal oscillator frequency of 24.5 mhz. r/w r/w r/w r/w r/w r/w r/w r/w reset value variable bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8b f bit 7: ioscen: internal oscillator enable bit. 0: internal oscillator disabled. 1: internal oscillator enabled. bit 6: ifrdy: internal osc illator frequency ready flag. 0: internal oscillator not ru nning at programmed frequency. 1: internal oscillator runn ing at programmed frequency. bits 5?2: reserved. bits 1?0: ifcn1-0: in ternal oscillator fr equency control bits. 00: internal oscillator is divided by 8. 01: internal oscillator is divided by 4. 10: internal oscillator is divided by 2. 11: internal oscillator is divided by 1. r/w r r/w r 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: sfr page: 0x8a f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 187 14.2. external oscill ator drive circuit the external oscillator circuit may driv e an external crystal, ce ramic resonator, capacito r, or rc network. a cmos clock may also provide a clock input. for a crys tal or ceramic resonator configuration, the crystal/ resonator must be wired across the xtal1 and xtal2 pins as shown in option 1 of figure 14.1. in rc, capacitor, or cmos clock configuration, the clock source should be wired to the xtal2 and/or xtal1 pin(s) as shown in opti on 2, 3, or 4 of figure 14.1 . the type of external oscilla tor must be selected in the oscxcn register, and the frequency control bits (xfcn) must be selected appropriately (see sfr defini- tion 14.4). 14.3. system clock selection the clksl1-0 bits in register cl ksel select which oscillator s ource genera tes the system clock. clksl1-0 must be set to ?01? for the system clock to run from the external oscillator; however the external oscillator may still clock certain periphe rals, such as the timers and pca, when the internal oscillator or the pll is selected as the system clock. the system clock may be switched on-the-fly between the internal and external oscillators or the pll, so long as the se lected oscillator source is enabled and settled. the internal oscillator requires little start-up time, and may be enabled and se lected as the syst em clock in the same write to oscicn. external cr ystals and ceramic resonators typica lly require a start-up time before they are settled and ready for use as the system clock. the crystal valid flag (xtlvld in register oscxcn) is set to ?1? by hardware when the extern al oscillator is settled. to avoid reading a false xtlvld, in crystal mode software should delay at least 1 ms between en abling the external oscillator and checking xtlvld. rc and c modes typically require no startup time. the pll also requires time to lock onto the desired frequency, and the pll lock flag (plllck in register pll0cn) is set to ?1? by hardware once the pll is locked on the correct frequency. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 188 rev. 1.4 sfr definition 14.3. clksel: system clock selection bits 7?6: reserved. bits 5?4: clkdiv1?0: output sysclk divide factor. these bits can be used to pre-divide sysclk before it is ou tput to a port pin through the crossbar. 00: output will be sysclk. 01: output will be sysclk/2. 10: output will be sysclk/4. 11: output will be sysclk/8. see section ?18. port input/output? on page 235 for more details about routing this out- put to a port pin. bits 3?2: reserved. bits 1?0: clksl1?0: system clock source select bits. 00: sysclk derived from the internal oscilla tor, and scaled as pe r the ifcn bits in oscicn. 01: sysclk derived from the external osc illator circuit. 10: sysclk derived from the pll. 11: reserved. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - clkdiv1 clkdiv0 - - clksl1 clksl0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x97 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 189 sfr definition 14.4. oscxcn: external oscillator control bit7: xtlvld: crystal oscillator valid flag. ( valid only when xoscmd = 11x. ) 0: crystal oscillator is unused or not yet stable. 1: crystal oscillator is running and stable. bits6?4: xoscmd2?0: extern al oscillator mode bits. 00x: external oscillator circuit off. 010: external cmos clock mode (external cmos clock input on xtal1 pin). 011: external cmos clock mode with divide by 2 stage (external cmos clock input on xtal1 pin). 10x: rc/c oscillator mode with divide by 2 stage. 110: crystal oscillator mode. 111: crystal oscillator mode with divide by 2 stage. bit3: reserved. read = 0, write = don't care. bits2?0: xfcn2?0: external osc illator frequency control bits. 000-111: see table below: crystal mode (circuit from figure 14.1, option 1; xoscmd = 11x) choose xfcn value to match crystal frequency. rc mode (circuit from figure 14.1, option 2; xoscmd = 10x) choose xfcn value to match frequency range: f = 1.23(10 3 ) / (r * c) , where f = frequency of os cillation in mhz c = capacitor value in pf r = pullup resistor value in k ? c mode (circuit from figure 14.1, option 3; xoscmd = 10x) choose k factor (kf) for the oscillation freq uency desired: f = kf / (c * v dd ) , where f = frequency of os cillation in mhz c = capacitor value on xtal1, xtal2 pins in pf v dd = power supply on mcu in volts r r/w r/w r/w r r/w r/w r/w reset value xtlvld xoscmd2 xoscmd1 xoscmd 0 - xfcn2 xfcn1 xfcn0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8c f xfcn crystal (xoscmd = 11x) rc (xoscmd = 10x) c (xoscmd = 10x) 000 f ? 32 khz f ?? 25 khz k factor = 0.87 001 32 khz ?? f ?? 84 khz 25 khz ?? f ?? 50 khz k factor = 2.6 010 84 khz ? f ?? 225 khz 50 khz ?? f ?? 100 khz k factor = 7.7 011 225 khz ? f ?? 590 khz 100 khz ?? f ?? 200 khz k factor = 22 100 590 khz ? f ?? 1.5 mhz 200 khz ?? f ?? 400 khz k factor = 65 101 1.5 mhz ? f ?? 4 mhz 400 khz ?? f ?? 800 khz k factor = 180 110 4 mhz ? f ?? 10 mhz 800 khz ?? f ?? 1.6 mhz k factor = 664 111 10 mhz ? f ?? 30 mhz 1.6 mhz ?? f ?? 3.2 mhz k factor = 1590 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 190 rev. 1.4 14.4. external crystal example if a crystal or ceramic resonator is us ed as an external osc illator source for the mcu, the circuit should be configured as shown in fi gure 14.1, option 1. the external osc illator frequency co ntrol value (xfcn) should be chosen from the crystal column of the ta ble 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 enabl ed, the oscillator amplitude detection circuit requires a settle time to achieve proper bias. waiting at least 1 ms between enabling the oscillator and checking the xtlvld bit will prevent a premature switch to th e external oscillator as the system clock. switching to the external oscillator before the crystal oscillator has stabilized can re sult in unpredictable behavior. the recom- mended procedure is: step 1. enable the external oscillator. step 2. wait at least 1 ms. step 3. poll for xtlvld => ?1?. step 4. switch the system clo ck to the external oscillator. important note on external crystals: crystal oscillator circuits are qui te sensitive to pcb layout. the crystal should be placed as close as possible to th e xtal pins on the device. the traces should be as short as possible and shielded with ground plane from any other traces which could introduce noise or interference. 14.5. external rc example if an rc network is used as an external oscillator so urce for the mcu, the circ uit should be configured as shown in figure 14.1, option 2. the capacitor should be no greater than 100 pf; however for very small capacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layout. to deter- mine the required external oscilla tor frequency control value (xfcn) in the oscxcn register, first select the rc network value to pr oduce the desired frequency of osc illation. if the frequency desired is 100 khz, let r = 246 k ? and c = 50 pf: f = 1.23(10 3 )/rc = 1.23 (10 3 )/[246 x 50] = 0.1 mhz = 100 khz referring to the table in sfr definition 14.4, the required xfcn setting is 010. 14.6. external capacitor example if a capacitor is used as an external oscillator for the mcu, the circui t should be configured as shown in figure 14.1, option 3. the capacitor should be no greater than 100 pf; however for very small capacitors, the total capacitance may be dominated by parasiti c capacitance in the pcb layout. to determine the required external oscillato r frequency control value (xfcn) in th e oscxcn register, select the capaci- tor to be used and find the fr equency of oscillati on from the equations below. assume v dd =3.0v and c=50pf: f = kf/( c x v dd ) = kf/( 50 x 3 ) f=kf/150 if a frequency of roughly 50 khz is desired, select th e k factor from the table in sfr definition 14.4 as kf = 7.7: f = 7.7/150 = 0.051 mhz, or 51 khz therefore, the xfcn value to use in this example is 010. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 191 14.7. phase-locked loop (pll) a phase-locked-loop (pll) is included, wh ich is used to multiply the internal oscillator or an external clock source to achieve higher cpu operating freque ncies. the pll circuitry is designed to produce an output frequency between 25 mhz and 100 mhz, from a divided reference frequency between 5 mhz and 30 mhz. a block diagram of the pll is shown in figure 14.2. figure 14.2. pll block diagram 14.7.1. pll input clock and pre-divider the pll circuitry can derive its refere nce clock from either the internal oscillator or an external clock source. the pllsrc bit (pll0cn.2) controls which clo ck source is used for the reference clock (see sfr definition 14.5). if pllsrc is set to ?0?, the internal oscillato r source is used. note th at the internal oscilla- tor divide factor (as spec ified by bits ifcn1-0 in register oscicn) will also apply to this clock. when pllsrc is set to ?1?, an external oscillator source will be used. the external oscillato r should be active and settled before it is selected as a reference clock for the pll circuit. the reference clock is divided down prior to the pll circuit, according to the contents of the pllm4-0 bits in the pll pre-divider register (pll0div), shown in sfr definition 14.6. 14.7.2. pll multiplication and output clock the pll circuitry will multip ly the divided reference clock by the multiplication factor stored in the pll0mul register shown in sfr definition 14.7. to accomplish this, it uses a feedback loop consisting of a phase/frequency detector, a loop f ilter, and a current-contro lled oscillator (ico). it is important to config- ure the loop filter and the ico for the correct frequency ranges. the plllp3?0 bits (pll0flt.3?0) should be set according to the divided reference clock frequency. likewise, the pllico1?0 bits (pll0flt.5?4) should be set according to the desired output freq uency range. sfr definition 14.8 describes the proper settings to use for the plllp3?0 and pllico1?0 bits. when the pll is locked and stable at the desired frequency, the plllck bit (pll0cn.5) will be set to a ?1?. the resultin g pll frequency will be set accord- ing to the equation: where ?reference frequency? is the selected source clock frequency, plln is the pll multiplier, and pllm is the pll pre-divider. pll0div pllm4 pllm3 pllm2 pllm1 pllm0 pll0mul plln7 plln6 plln5 plln4 plln3 plln2 plln1 plln0 pll0cn plllck pllsrc pllen pllpwr pll0flt pllico1 pllico0 plllp3 plllp2 plllp1 plllp0 0 1 internal oscillator external oscillator ? phase / frequency detection ? loop filter current controlled oscillator pll clock output divided reference clock c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 192 rev. 1.4 14.7.3. powering on and initializing the pll to set up and use the pll as the system clock afte r power-up of the device, the following procedure should be implemented: step 1. ensure that the reference clock to be used (internal or external) is running and stable. step 2. set the pllsrc bit (pll0cn.2) to select the desired clock source for the pll. step 3. program the flash read timing bits, flrt (flscl.5?4) to the appropriate value for the new clock rate (see section ?15. flash memory? on page 199 ). step 4. enable power to the pll by setting pllpwr (pll0cn.0) to ?1?. step 5. program the pll0div register to produc e the divided reference frequency to the pll. step 6. program the plllp3?0 bits (pll0flt.3?0) to the appropriate range for the divided reference frequency. step 7. program the pllico1?0 bits (pll0flt.5?4) to the appropriate range for the pll output frequency. step 8. program the pll0mul register to the desired clock multiplication factor. step 9. wait at least 5 s, to provide a fast frequency lock. step 10. enable the pll by setting pllen (pll0cn.1) to ?1?. step 11. poll plllck (pll0cn.4) until it changes from ?0? to ?1?. step 12. switch the system clock source to the pll using the clksel register. if the pll characteristics need to be changed when the pll is already running, the following procedure should be implemented: step 1. the system clock should fi rst be switched to either the in ternal oscillator or an external clock source that is running and stable, using the clksel register. step 2. ensure that the reference clock to be used for the new pll setting (internal or external) is running and stable. step 3. set the pllsrc bit (pll0cn.2) to select the new clock source for the pll. step 4. if moving to a faster frequency, program the flash read timing bits, flrt (flscl.5?4) to the appropriate value for the new clock rate (see section ?15. flash memory? on page 199 ). step 5. disable the pll by setting pllen (pll0cn.1) to ?0?. step 6. program the pll0div register to produc e the divided reference frequency to the pll. step 7. program the plllp3?0 bits (pll0flt.3?0) to the appropriate range for the divided reference frequency. step 8. program the pllico1-0 bits (pll0flt.5?4) to the appropriate range for the pll output frequency. step 9. program the pll0mul register to the desired clock multiplication factor. step 10. enable the pll by setting pllen (pll0cn.1) to ?1?. step 11. poll plllck (pll0cn.4) until it changes from ?0? to ?1?. step 12. switch the system clock source to the pll using the clksel register. step 13. if moving to a slower frequency, program the flash read timing bits, flrt (flscl.5?4) to the appropriate value for the new clock rate (see section ?15. flash memory? on pll frequency reference frequency plln pllm --------------- ? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 193 page 199 ). important note: cache reads, cache writes, and the prefetch engine should be disabled whenever the flrt bits are changed to a lower setting. to shut down the pll, the s ystem clock should be switched to the internal osc illator or a stable external clock source, using the cl ksel register. next, disable the pll by setting pllen (pll0cn.1) to ?0?. finally, the pll can be powered off, by setting pllp wr (pll0cn.0) to ?0?. note that the pllen and pllpwr bits can be cleared at the same time. sfr definition 14.5. pll0cn: pll control bits 7?5: unused: read = 000b; write = don?t care. bit 4: pllck: pll lock flag. 0: pll frequency is not locked. 1: pll frequency is locked. bit 3: reserved. must write to ?0?. bit 2: pllsrc: pll reference clock source select bit. 0: pll reference clock source is in ternal oscillator. 1: pll reference cl ock source is external oscillator. bit 1: pllen: pll enable bit. 0: pll is held in reset. 1: pll is enabled. pllpwr must be ?1?. bit 0: pllpwr: pll power enable. 0: pll bias generator is de-activated. no static power is consumed. 1: pll bias generator is active. must be set for pll to operate. r/w r/w r/w r r/w r/w r/w r/w reset value - - - plllck 0 pllsrc pllen pllpwr 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x89 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 194 rev. 1.4 sfr definition 14.6. pll0 div: pll pre-divider sfr definition 14.7. pll0mu l: pll clock scaler bits 7?5: unused: read = 000b; write = don?t care. bits 4?0: pllm4?0: pll reference clock pre-divider. these bits select the pre-divide value of the p ll reference clock. when set to any non-zero value, the referenc e clock will be divided by the value in pllm4?0. when set to ?00000b?, the reference cl ock will be divided by 32. r/w r/w r/w r/w r/w r/w r/w r/w reset value - - - pllm4 pllm3 pllm2 pllm1 pllm0 00000001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8d f bits 7?0: plln7?0: pll multiplier. these bits select the multiplication factor of the divided pll reference clock. when set to any non-zero value, the multiplic ation factor will be equal to th e value in plln7-0. when set to ?00000000b?, the multiplicati on factor will be equal to 256. r/w r/w r/w r/w r/w r/w r/w r/w reset value plln7 plln6 plln5 plln4 plln3 plln2 plln1 plln0 00000001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8e f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 195 sfr definition 14.8. pll0flt: pll filter table 14.2. pll frequency characteristics ?40 to +85 c unless otherwise specified parameter conditions min typ max units input frequency (divided reference frequency) 530mhz pll output frequency 25 100* mhz *note: the maximum operating frequency of the c8051f124/5/6/7 is 50 mhz bits 7?6: unused: read = 00b; write = don?t care. bits 5?4: pllico1-0: pl l current-controlled os cillator control bits. selection is based on the desired output frequency, according to the following table: bits 3?0: plllp3-0: pll loop filter control bits. selection is based on the divided pll reference clock, according to the following table: r/w r/w r/w r/w r/w r/w r/w r/w reset value - - pllico1 pllico0 plllp3 plllp2 plllp1 plllp0 00110001 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8f f pll output clock pllico1-0 65?100 mhz 00 45?80 mhz 01 30?60 mhz 10 25?50 mhz 11 divided pll reference clock plllp3-0 19?30 mhz 0001 12.2?19.5 mhz 0011 7.8?12.5 mhz 0111 5?8 mhz 1111 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 196 rev. 1.4 table 14.3. pll lock ti ming characteristics ?40 to +85 c unless otherwise specified input frequency multiplier (pll0mul) pll0flt setting output frequency min typ max units 5mhz 20 0x0f 100 mhz 202 s 13 0x0f 65 mhz 115 s 16 0x1f 80 mhz 241 s 90x1f45mhz116 s 12 0x2f 60 mhz 258 s 60x2f30mhz112 s 10 0x3f 50 mhz 263 s 50x3f25mhz113 s 25 mhz 40x01100mhz42 s 20x0150mhz 33 s 30x1175mhz48 s 20x1150mhz17 s 20x2150mhz 42 s 10x2125mhz 33 s 20x3150mhz 60 s 10x3125mhz 25 s c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 197 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 198 rev. 1.4 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 199 15. flash memory all devices include either 128 kb (c8051f12x and c8051f130/1) or 64 kb (c8051f132/3) of on-chip, reprogrammable flash memory for program code or non-volatile data storage. an additional 256-byte page of flash is also included for non-volatile data storage. the flash memory can be programmed in-sys- tem 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. bytes should be erased (set to 0xff) before being reprogrammed. flash write and erase operations are automatically timed by hardware for proper execu- tion. during a flash erase or write, the flbusy bit in the flstat register is set to ?1? (see sfr definition 16.5). during this time, instructions that are located in the prefetch buffer or the branch target cache can be executed, but the processor will stall until the erase or write is completed if instruction data must be fetched from flash memory. interrupts that have been pre-loaded into the branch target cache can also be ser- viced at this time, if the current code is also exec uting from the prefetch engine or cache memory. any interrupts that are not pre-lo aded into cache, or that o ccur while the core is halted, will be held in a pending state during the flash write/erase operation, and serviced in priority order once the flash operation has completed. refer to table 15.1 for the electrical characteristics of the flash memory. 15.1. programming the flash memory the simplest means of programming the flash memory is through the jtag interface using programming tools provided by silicon labs or a third party vendor. this is the only means for programming a non-initial- ized device. for details on the jtag commands to program flash memory, see section ?25. jtag (ieee 1149.1)? on page 341 . the flash memory can be programmed from software using the movx write instruction with the address and data byte to be programmed provided as norma l operands. before writing to flash memory using movx, flash write operations must be enabled by setting the pswe program store write enable bit (psctl.0) to logic 1. this directs the movx writes to flash memory instead of to xram, which is the default target. the pswe bit remains set until cleared by software. to avoid errant flash writes, it is rec- ommended that interrupts be disabled while the pswe bit is logic 1. flash memory is read using the movc instruction. movx reads are always directed to xram, regardless of the state of pswe. on the devices with 128 kb of flash, the cobank bits in the psbank register (sfr definition 11.1) determine which of the upper three flash banks are mapped to the address range 0x08000 to 0x0ffff for flash writes, reads and erases. for devices with 64 kb of flash. the cobank bits should always remain set to ?01? to ensure that flash write, erase, and read operations are valid. note : to ensure the integrity of flash memory contents, it is strongly recommended that the on- chip v dd monitor be enabled by connecting the v dd monitor enable pin (monen) to v dd and set- ting the porsf bit in the rstsrc register to ?1? in any system that writes and/or erases flash memory from software. see ?reset s ources? on page 177 for more information. a write to flash memory can clear bits but cannot set them; only an erase operation can set bits in flash. a byte location to be programmed must be erased before a new value can be written . write/erase timing is automatically controlled by har dware. note that on the 128 k flash versions, 1024 bytes beginning at location 0x1fc00 are reserved. flash writes and erases targeting the reserved area should be avoided. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 200 rev. 1.4 15.1.1. non-volatile data storage the flash memory can be used for non-volatile data storage as well as program code. this allows data such as calibration coefficients to be calculated and st ored at run time. data is written and erased using the movx write instruction (as described in section 15.1.2 and section 15.1.3 ) and read using the movc instruction. the cobank bits in re gister psbank (sfr definition 11.1 ) control which portion of the flash memory is targeted by writes and erases of addre sses above 0x07fff. for devices with 64 kb of flash. the cobank bits should alwa ys remain set to ?01? to ensure that flash write, erase, and read operations are valid. two additional 128-byte sectors (256 bytes total) of fl ash memory are included for non-volatile data stor- age. the smaller sector size makes them particularly well suited as g eneral purpose, non-volatile scratch- pad memory. even though flash memory can be written a single byte at a time, an entire sector must be erased first. in order to change a single byte of a mult i-byte data set, the data must be moved to temporary storage. the 128-byte sector-size fa cilitates updating data without wa sting program memory or ram space. the 128-byte sectors are double-mapped over the normal flash memory for movc reads and movx writes only; their addresses range from 0x00 to 0x7f and from 0x80 to 0xff (see figure 15.2). to access the 128-byte sectors, the sfle bit in psctl mu st be set to logic 1. code execution from the 128- byte scratchpad areas is not permitted. the 128-byte sectors can be erased individually, or both at the same time. to erase both sectors simultaneously, the address 0x0400 should be targeted during the erase operation with sfle set to ?1?. see figure 15.1 for the memory map under different cobank and sfle settings. table 15.1. flash electri cal characteristics v dd = 2.7 to 3.6 v; ?40 to +85 c parameter conditions min typ max units flash size 1 c8051f12x and c8051f130/1 131328 2 bytes flash size 1 c8051f132/3 65792 bytes endurance 20k 100k erase/write erase cycle time 10 12 14 ms write cycle time 40 50 60 s notes: 1. includes 256-byte scratch pad area 2. 1024 bytes at location 0x1fc00 to 0x1ffff are reserved. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 201 figure 15.1. flash memory map for mo vc read and movx write operations 15.1.2. erasing flash pages from software when erasing flash memory, an entire page is erased (all bytes in the page are set to 0xff). the flash memory is organized in 1024-byte pages. the 256 bytes of scratchpad area (addresses 0x20000 to 0x200ff) consists of two 128 b yte pages. to erase any flash page, the flwe, pswe, and psee bits must be set to ?1?, and a byte must be written using a movx instruction to any address within that page. the following is the recommended procedure for erasing a flash page from software: step 1. disable interrupts. step 2. if erasing a page in bank 1, bank 2, or bank 3, set the cobank bits (psbank.5-4) for the appropriate bank. step 3. if erasing a page in the scratc hpad area, set the sfle bit (psctl.2). step 4. set flwe (flscl.0) to enable flash writes/erases via user software. step 5. set psee (psctl.1) to enable flash erases. step 6. set pswe (psctl.0) to redire ct movx commands to write to flash. step 7. use the movx instruction to write a data byte to any location within the page to be erased. step 8. clear psee to disable flash erases. step 9. clear the pswe bit to redirect movx commands to the xram data space. step 10. clear the flwe bit, to disable flash writes/erases. step 11. if erasing a page in the scratchpad area, clear the sfle bit. step 12. re-enable interrupts. bank 0 bank 1 bank 2 bank 3 bank 0 bank 0 bank 0 bank 0 cobank = 0 cobank = 1 cobank = 2 cobank = 3 sfle = 0 sfle = 1 internal address 0x0000 0x7fff 0x8000 0xffff undefined scratchpad areas (2) 0x00ff 128k flash devices only. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 202 rev. 1.4 15.1.3. writing flash memory from software bytes in flash memory can be written one byte at a time, or in small blocks. the chblkw bit in register cch0cn (sfr definition 16.1) controls whether a single byte or a block of bytes is written to flash during a write operation. when chblkw is cleared to ?0?, the flash will be written one byte at a time. when chblkw is set to ?1?, the flash will be written in blo cks of four bytes for addr esses in code space, or blocks of two bytes for addresses in the scratchpad area. block writes are performed in the same amount of time as single byte writes, which can save time when storing large amounts of data to flash memory. for single-byte writes to flash, bytes are written individually, and the flash write is performed after each movx write instruction. the recommended procedure for writing flash in single bytes is as follows: step 1. disable interrupts. step 2. clear chblkw (cch0cn.0) to select single-byte write mode. step 3. if writing to bytes in bank 1, bank 2, or bank 3, set the cobank bits (psbank.5-4) for the appropriate bank. step 4. if writing to bytes in the scratchpad area, set the sfle bit (psctl.2). step 5. set flwe (flscl.0) to enable flash writes/erases via user software. step 6. set pswe (psctl.0) to redire ct movx commands to write to flash. step 7. use the movx instruction to write a data byte to the desired location (repeat as necessary). step 8. clear the pswe bit to redirect movx commands to the xram data space. step 9. clear the flwe bit, to disable flash writes/erases. step 10. if writing to bytes in the scratchpad area, clear the sfle bit. step 11. re-enable interrupts. for block flash writes, the flash write procedure is only performed after the last byte of each block is writ- ten with the movx write instruction. when writing to addresses located in any of the four code banks, a flash write block is four bytes long, from addresses ending in 00b to addresses ending in 11b. writes must be performed sequentially (i.e. addresses ending in 0 0b, 01b, 10b, and 11b must be written in order). the flash write will be performed following the movx write that targets the address ending in 11b. when writ- ing to addresses located in the flash scratchpad area, a flash block is two bytes long, from addresses ending in 0b to addresses ending in 1b. the flash write will be perf ormed following th e movx write that targets the address ending in 1b. if any bytes in the block do not need to be updated in flash, they should be written to 0xff. the recommended procedur e for writing flash in blocks is as follows: step 1. disable interrupts. step 2. set chblkw (cch0cn.0) to select block write mode. step 3. if writing to bytes in bank 1, bank 2, or bank 3, set the cobank bits (psbank.5-4) for the appropriate bank. step 4. if writing to bytes in the scratchpad area, set the sfle bit (psctl.2). step 5. set flwe (flscl.0) to enable flash writes/erases via user software. step 6. set pswe (psctl.0) to redire ct movx commands to write to flash. step 7. use the movx instruction to write data bytes to the desired block. the data bytes must be written sequentially, and the la st byte written must be the high byte of the block (see text for details, repeat as necessary). step 8. clear the pswe bit to redirect movx commands to the xram data space. step 9. clear the flwe bit, to disable flash writes/erases. step 10. if writing to bytes in the scratchpad area, clear the sfle bit. step 11. re-enable interrupts. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 203 15.2. security options the cip-51 provides security options to protect the flash memory from inadvertent modification by soft- ware as well as prevent the viewing of proprietary program code and constants. the program store write enable (psctl.0), program store er ase enable (psctl.1), and flash write/erase enable (flacl.0) bits protect the flash memory from accidental modification by software. these bits must be explicitly set to logic 1 before software can write or erase the flash memory. additional security features prevent proprie- tary program code and data constants from being read or altered across the jtag interface or by software running on the system controller. a set of security lock bytes protect the flash program memory from being read or altered across the jtag interface. each bit in a security lock-byte protects one 16k-byte block of memory. clearing a bit to logic 0 in the read lock byte prevents the corresponding block of flash memory from being read across the jtag interface. clearing a bit in the writ e/erase lock byte protects the blo ck from jtag erasures and/or writes. the scratchpad area is read or write/erase locked when all bits in the corresponding security byte are cleared to logic 0. on the c8051f12x and c8051f130/1, the security lock bytes are located at 0x1fbfe (write/erase lock) and 0x1fbff (read lock), as shown in figure 15.2. on the c8051f132/3, the security lock bytes are located at 0x0fffe (write/erase lock) and 0x0fff f (read lock), as shown in figure 15.3. the 1024- byte sector containing the lock bytes can be written to, but not erased, by software. an attempted read of a read-locked byte returns undefined data. debugging code in a read-locked sector is not possible through the jtag interface. the lock bits can always be read from and written 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: to ensure protection from external access, the block containing the lock bytes must be write/erase locked. on the 128 kb de vices (c8051f12x and c8051f130/1), the block con- taining the security bytes is 0x18000-0x1bfff, and is locked by clearing bit 7 of the write/erase lock byte. on the 64 kb devices (c8051f132/3), the block containing the security bytes is 0x0c000-0x0ffff, and is locked by clearing bit 3 of the write/erase lock byte. if the page contain- ing the security bytes is not write/erase locked, it is still possible to erase this page of flash mem- ory through the jtag port and reset the security bytes. when the page containing the security bytes has been write/erase locked, a jtag full device erase must be performed to unlock any areas of flash protected by the security bytes. a jtag full device erase is initiated by performing a normal jtag erase operation on either of the security byte locations. this operation must be initiated through the jtag port, and cannot be performed from firmware running on the device. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 204 rev. 1.4 figure 15.2. 128 kb flash memory map and security bytes 0x1fc00 0x1fbfe program/data memory space 0x00000 0x1fbff read lock byte write/erase lock byte reserved 0x1ffff 0x1fbfd sfle = 0 0x00ff 0x0000 scratchpad memory (data only) sfle = 1 bit 7 6 5 4 3 2 1 0 read and write/erase security bits. (bit 7 is msb.) memory block 0x18000 - 0x1bfff 0x1c000 - 0x1fbfd 0x14000 - 0x17fff 0x10000 - 0x13fff 0x08000 - 0x0bfff 0x0c000 - 0x0ffff 0x04000 - 0x07fff 0x00000 - 0x03fff flash access limit flash read lock byte bits7?0: each bit locks a corresponding block of memory. (bit7 is msb). 0: read operations are locked (disabled) for corresponding block across the jtag interface. 1: read operations are unlocked (enabled) fo r corresponding block across the jtag inter- face. flash write/erase lock byte bits7?0: each bit locks a corresponding block of memory. 0: write/erase operations are locked (disabled) for corresponding block across the jtag interface. 1: write/erase operations are unlocked (enabled) for corresponding block across the jtag interface. note: when the highest block is locked, the security bytes may be written but not erased. flash access limit register (flacl) the flash access limit is defined by the settin g of the flacl register, as described in sfr definition 15.1. firmware running at or above this address is prohibited from using the movx and movc instructions to read, write, or erase flash locations below this address. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 205 figure 15.3. 64 kb flash memory map and security bytes 0x0fffe program/data memory space 0x00000 0x0ffff read lock byte write/erase lock byte flash access limit 0x0fffd sfle = 0 0x00ff 0x0000 scratchpad memory (data only) sfle = 1 bit 7 6 5 4 3 2 1 0 read and write/erase security bits. (bit 7 is msb.) memory block n/a n/a n/a n/a 0x08000 - 0x0bfff 0x0c000 - 0x0ffff 0x04000 - 0x07fff 0x00000 - 0x03fff flash read lock byte bits7?0: each bit locks a corresponding block of memory. (bit7 is msb). 0: read operations are locked (disabled) for corresponding block across the jtag interface. 1: read operations are unlocked (enabled) fo r corresponding block across the jtag inter- face. flash write/erase lock byte bits7?0: each bit locks a corresponding block of memory. 0: write/erase operations are locked (disabled) for corresponding block across the jtag interface. 1: write/erase operations are unlocked (enabled) for corresponding block across the jtag interface. note: when the highest block is locked, the security bytes may be written but not erased. flash access limit register (flacl) the flash access limit is defined by the settin g of the flacl register, as described in sfr definition 15.1. firmware running at or above this address is prohibited from using the movx and movc instructions to read, write, or erase flash locations below this address. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 206 rev. 1.4 the flash access limit security feature (see sfr de finition 15.1) protects proprietary program code and data from being read by software running on the device. 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 flash access limit (fal) is a 17-bit address that establishes two logical partitions in the program memory space. the first is an upper partition consis ting of all the program memory locations at or above the fal address, and the second is a lower partition consisting of all the program memory locations start- ing at 0x00000 up to (but excluding) the fal address. software in the upper partition can execute code in the lower partition, but is prohibited from reading locations in th e lower partition using the movc instruc- tion. (executing a movc instruction from the upper pa rtition with a source addre ss in the lower partition will return indeterminate data.) software running in the lower pa rtition can access lo cations in both the upper and lower partition without restriction. the value-added firmware should be placed in the lowe r partition. on reset, cont rol is passed to the value- added 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 th e lower partition, but it cannot read or change the contents of the lower partition. parameters may be passed to the program code running in the lower parti- tion either through the typical method of placing them on the stack or in registers before the call or by plac- ing them in prescribed memory locations in the upper partition. the fal address is specified using the contents of the flash access limit register. the 8 msbs of the 17- bit fal address are determined by the setting of the flacl register. thus, the fal can be located on 512- byte boundaries anywhere in program memory space. however, the 1024-byte erase sector size essen- tially requires that a 1024 boundary be used. the co ntents of a non-initialized flacl security byte are 0x00, thereby setting the fal address to 0x00000 and allowing read access to all locations in program memory space by default. sfr definition 15.1. fl acl: flash access limit bits 7?0: flacl: flash access limit. this register holds the most significant 8 bits of the 17-bit program memory read/write/erase limit address. the lower 9 bits of the read/write/erase limit are always set to 0. a write to this register sets the flash access limit. this register can only be written once after any reset. any subsequent writes are ignored until the next reset. to fully protect all addresses below this limit, bit 0 of flacl should be set to ?0? to align the fal on a 1024-byte flash page boundary. 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: sfr address: sfr page: 0xb7 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 207 15.2.1. summary of flash security options there are three flash access methods supported on the c8051f12x and c8051f13x devices; 1) access- ing flash through the jtag debug interface, 2) acce ssing flash from firmware residing below the flash access limit, and 3) accessing flash from firmwa re residing at or above the flash access limit. 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 flas h pages, including the page cont aining the security bytes and the security by tes themselves. 8. the reserved area cannot be read from, written to, or erased at any time. accessing flash from firmware resi ding 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. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 208 rev. 1.4 sfr definition 15.2. flscl: flash memory control bits 7?6: unused. bits 5?4: flrt: flash read time. these bits should be programmed to the smallest allowed value, according to the system clock speed. 00: sysclk < 25 mhz. 01: sysclk < 50 mhz. 10: sysclk < 75 mhz. 11: sysclk < 100 mhz. bits 3?1: reserved. read = 000b. must write 000b. bit 0: flwe: flash write/erase enable. this bit must be set to allow flash writes/erasures from user software. 0: flash writes/erases disabled. 1: flash writes/erases enabled. important note: when changing the flrt bits to a lower setting (e.g. when changing from a value of 11b to 00b), cache reads, cache writes, and the prefetch engine should be disabled using the cch0cn regi ster (see sfr definition 16.1). r/wr/wr/wr/wr/wr/wr/wr/wreset value - - flrt reserved reserved reserved flwe 10000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr address: sfr page: 0xb7 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 209 sfr definition 15.3. psctl: prog ram store read/w rite control bits 7?3: unused. read = 00000b, write = don't care. bit 2: sfle: scratchpad flash memory access enable when this bit is set, flash movc reads and wr ites from user software are directed to the two 128-byte scratchpad flash sectors. when sfle is set to logic 1, flash accesses out of the address range 0x00-0xff should not be attempted (with the exception of address 0x400, which can be used to simultaneously erase both scratchpad areas). reads/writes out of this range will yield undefined results. 0: flash access from user software directed to the program/data flash sector. 1: flash access from user software directed to the two 128 byte scratchpad sectors. bit 1: psee: program store erase enable. setting this bit allows an entire page of th e flash program memory to be erased provided the pswe bit is also set. after setting this bit, a write to flash memory using the movx instruction will erase th e entire page that contains the location addre ssed by the movx instruction. the value of the data byte written does not matter. note: the flash page con- taining the read lock byte and write/erase lock byte cannot be erased by software. 0: flash program memory erasure disabled. 1: flash program memory erasure enabled. bit 0: pswe: program store write enable. setting this bit allows writing a byte of dat a to the flash program memory using the movx write instruction. the location must be erased prior to writing data. 0: write to flash program memory disabled. movx write operations target external ram. 1: write to flash program memory enabled. movx write operations target flash memory. r/wr/wr/wr/wr/wr/wr/wr/wreset value - - - - - sfle psee pswe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr address: sfr page: 0x8f 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 210 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 211 16. branch target cache the c8051f12x and c8051f13 x device families incorporate a 63x4 byte branch target ca che with a 4-byte prefetch engine. because the access time of the flas h memory is 40 flashns, an d the minimum instruction time is 10ns (c8051f120/1/2/3 and c8051f130/1/2/3) or 20 ns (c8051f124/5/6/7), the branch target cache and prefetch engine are necessary for full-speed code execution. instructions are read from flash memory four bytes at a time by the prefetch engine, and given to the cip-51 processor core to execute. when running linear code (code without any jumps or branches), the prefetch engine alone allows instruc- tions to be executed at full speed. when a code br anch occurs, a search is performed for the branch tar- get (destination address) in the cache. if the branch target information is fo und in the cache (called a ?cache hit?), the instruction data is read from the cache and immediately returned to the cip-51 with no delay in code execution. if the branch target is not found in the cache (called a ?cache miss?), the proces- sor may be stalled for up to four cl ock cycles while the next set of four instructions is retrieved from flash memory. each time a cache miss occurs, the requested instruction data is writt en to the cache if allowed by the current cache settings. a data flow diagram of the interaction between the cip-51 and the branch target cache and prefetch engine is shown in figure 16.1. figure 16.1. branch target cache data flow 16.1. cache and prefetch operation the branch target cache maintains two sets of memory locations: ?slots? and ?tags?. a slot is where the cached instruction data from flash is stored. each slot holds four c onsecutive code bytes. a tag contains the 15 most significant bits of the corresponding flas h address for each four-byt e slot. thus, instruction data is always cached along four-byte boundaries in co de space. a tag also contains a ?valid bit?, which indicates whether a cache location contains valid instru ction data. a special cache location (called the lin- ear tag and slot), is reserved fo r use by the prefetch engine. the cache organization is shown in figure 16.2. each time a flash read is requested, the address is compared with all valid cache tag loca- tions (including the linear tag). if any of the tag locations match the requested address, the data from that slot is immediately provided to the cip-51. if th e requested address matches a location that is currently being read by the prefetch e ngine, the cip-51 will be stalled until the read is complete. if a match is not found, the current prefetch operation is abandoned, and a new prefetch operation is initiated for the requested instruction data. when the prefetch oper ation is finished, the cip-51 begins executing the instructions that were retrieved, and the prefetch engine begins reading the next four-byte word from flash memory. if the newly-fetched data al so meets the criteria necessary to be cached, it will be written to the cache in the slot indicated by the current replacement algorithm. flash memory branch target cache prefetch engine instruction data cip-51 instruction address c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 212 rev. 1.4 the replacement algorithm is selected with the cache algorithm bit, chalgm (cch0tn.3). when chalgm is cleared to ?0?, the cach e will use the rebound algorithm to replace cache locations. the rebound algorithm replaces locations in order from the beginning of cache memory to the end, and then from the end of cache memory to the beginning. when chalgm is set to ?1?, the cache will use the pseudo-random algorithm to replace cache locations. the pseudo-random algorithm uses a pseudo-ran- dom number to determine which cache location to repl ace. the cache can be manually emptied by writing a ?1? to the chflush bit (cch0cn.4). figure 16.2. branch target cache organiztion 16.2. cache and prefetch optimization by default, the branch target cache is configured to provide code speed improvements for a broad range of circumstances. in most applications, the cache control registers should be left in their reset states. sometimes it is desirable to optimize the execution time of a specific routine or critical timing loop. the branch target cache includes options to exclude caching of certain type s of data, as well as the ability to pre-load and lock time-critical branch lo cations to optimize execution speed. the most basic level of cache cont rol is implemented with the cache miss penalty threshold bits, chm- sth (cch0tn.1-0). if the processor is stalled during a prefetch operati on for more clock cycles than the number stored in chm sth, the requested data w ill be cached when it become s available. the chmsth bits are set to zero by default, mean ing that any time the processor is st alled, the new data will be cached. if, for example, chmsth is equal to 2, any cache miss causing a delay of 3 or 4 clock cycles will be cached, while a cache miss causing a delay of 1-2 clock cycles will not be cached. slot = 4 instruction data bytes 0 0 tag 58 slot 58 v58 tag 62 slot 62 v62 tag 61 slot 61 v61 tag 2 slot 2 v2 tag 1 slot 1 v1 tag 0 slot 0 v0 tag 60 slot 60 v60 tag 59 slot 59 v59 linear tag linear slot vl prefetch data valid bit address data cache data tag = 15 msbs of absolute flash address a16 a2 a1 a0 1 0 0 1 1 1 byte 0 byte 1 byte 2 byte 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 213 certain types of instruction data or certain blocks of code can also be excluded from caching. the destina- tions of reti instructions are, by default, excluded from caching. to e nable caching of reti destinations, the chreti bit (cch0cn.3) can be set to ?1?. it is generally not beneficial to cache reti destinations unless the same instruction is likely to be interrupted repeatedly (such as a code loop that is waiting for an interrupt to happen). instructions th at are part of an interrupt service routine (isr) can also be excluded from caching. by default, isr instructions are cached, but this can be disabled by clearing the chisr bit (cch0cn.2) to ?0?. the other information that can be explicitly excluded from caching are the data returned by movc instruct ions. clearing the chmov bit (cch0cn. 1) to ?0? will disable caching of movc data. if movc caching is allowed, it can be restricted to only use slot 0 for the movc information (exclud- ing cache push operations). the chfixm bit (cch0tn.2) controls this behavior. further cache control can be implemented by disabling all cache writes. cache writes can be disabled by clearing the chwren bit (cch0cn.7) to ?0?. although normal cache writes (such as those after a cache miss) are disabled, data can still be written to the cache with a cac he push operation. disabling cache writes can be used to prevent a non-critical section of code from changing the cache contents. note that regardless of the value of chwren, a flash write or erase operation automatically removes the affected bytes from the cache. cache reads and the prefetch engine can also be individually disabled. disabling cache reads forces all instructions data to execute from flash memory or from the prefetch engine. to dis- able cache reads, the chrden bit (cch0cn.6) can be cleared to ?0?. note that when cache reads are disabled, cache writes will still o ccur (if chwren is set to ?1?). disabling the prefetch engine is accom- plished using the chpfen bi t (cch0cn.5). when this bit is cleared to ?0?, the prefetch engine will be dis- abled. if both chpfen and chrden are ?0?, code will execute at a fixed rate, as instructions become available from the flash memory. cache locations can also be pre-loaded and locked with time-critical branch destinations. for example, in a system with an isr that must respond as fast as possible, the entry point fo r the isr can be locked into a cache location to minimize the re sponse latency of the isr. up to 61 locations can be locked into the cache at one time. instructions are locked into cache by enabling cache push operations with the chpush bit (cch0lc.7). when chpush is set to ?1?, a movc instru ction will cause t he four-byte seg- ment containing the data byte to be written to the ca che slot location indicated by chslot (cch0lc.5-0). chslot is them decremented to point to the next lock able cache location. this process is called a cache push operation. cache locations that are above chslo t are ?locked?, and cannot be changed by the pro- cessor core, as shown in figure 16.3. cache locations can be un locked by using a cache pop operation. a cache pop is performed by writing a ?1? to the chpop bit (cch0lc.6). when a cache pop is initiated, the value of chslot is incremented. this unlocks the most recently locked cache location, but does not remove the information from the cache. note that a cache pop should not be init iated if chslot is equal to 111110b. doing so may have an adverse effect on cache performance. important: although locking cache location 1 is not explicitly disabled by hardware, the entire cache will be unlocked when chslot is equal to 000000b. therefore, cache locations 1 and 0 must remain unlocked at all times. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 214 rev. 1.4 figure 16.3. cache lock operation tag 62 slot 62 tag 61 slot 61 tag 2 slot 2 tag 1 slot 1 tag 0 slot 0 tag 60 slot 60 tag 59 slot 59 chslot = 58 locked locked locked unlocked unlocked unlocked lock status cache push operations decrement chslot cache pop operations increment chslot locked tag 58 slot 58 unlocked unlocked tag 57 slot 57 unlocked c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 215 sfr definition 16.1. cc h0cn: cache control bit 7: chwren: cache write enable. this bit enables the processor to write to the cache memory. 0: cache contents are not allowed to change, except during flash writes/erasures or cache locks. 1: writes to cache memory are allowed. bit 6: chrden: cache read enable. this bit enables the processor to read instructions from the cache memory. 0: all instruction data comes from flash memory or the prefetch engine. 1: instruction data is obtained from cache (when available). bit 5: chpfen: cache prefetch enable. this bit enables the prefetch engine. 0: prefetch engine is disabled. 1: prefetch engine is enabled. bit 4: chflsh: cache flush. when written to a ?1?, this bit clears the cache contents. this bit always reads ?0?. bit 3: chreti: cache reti destination enable. this bit enables the destination of a reti address to be cached. 0: destinations of reti instructions will not be cached. 1: reti destinatio ns will be cached. bit 2: chisr: cache isr enable. this bit allows instructions which are part of an interrupt service rountine (isr) to be cached. 0: instructions in isrs will no t be loaded into cache memory. 1: instructions in isrs can be cached. bit 1: chmovc: cache movc enable. this bit allows data requested by a movc instruction to be loaded into the cache memory. 0: data requested by movc in structions will not be cached. 1: data requested by mo vc instructions will be lo aded into cache memory. bit 0: chblkw: block write enable. this bit allows block writes to flash memory from software. 0: each byte of a software flash write is written individually. 1: flash bytes are written in groups of four (for code space writes) or two (for scratchpad writes). r/wr/wr/wr/wr/wr/wr/wr/wreset value chwren chrden chpfen chflsh chreti chisr chmovc chblkw 11100110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa1 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 216 rev. 1.4 sfr definition 16.2. cch0tn: cache tuning sfr definition 16.3. cch0 lc: cache lock control bits 7?4: chmsctl: cache miss penalty accumulator (bits 4?1). these are bits 4-1 of the cache miss penalty accu mulator. to read these bits, they must first be latched by reading the chmscth bits in the cch0ma register (see sfr definition 16.4). bit 3: chalgm: cache algorithm select. this bit selects the cache replacement algorithm. 0: cache uses rebound algorithm. 1: cache uses pseudo-random algorithm. bit 2: chfixm: cache fix movc enable. this bit forces movc writes to the cache memory to use slot 0. 0: movc data is written according to the current algorithm selected by the chalgm bit. 1: movc data is always written to cache slot 0. bits 1?0: chmsth: cache miss penalty threshold. these bits determine w hen missed instruction data will be cached. if data takes longer than chmsth cl ocks to obtain, it will be cached. r/wr/wr/wr/wr/wr/wr/wr/wreset value chmsctl chalgm chfixm chmsth 00000100 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa2 f bit 7: chpush: cache push enable. this bit enables cache push o perations, which will lock info rmation in cache slots using movc instructions. 0: cache push operations are disabled. 1: cache push operations are enabled. when a movc read is executed, the requested 4- byte segment containing the data is locked into the cache at the location indicated by chslot, and chslot is decremented. note that no more than 61 cache slots should be locked at one time, since the entire cache will be unlocked when chslot is equal to 0. bit 6: chpop: cache pop. writing a ?1? to this bit will in crement chslot and then unlock t hat location. this bit always reads ?0?. note that cache pop operations should not be performed while chslot = 111110b. ?pop?ing more cache slots than have been ?push?ed will have inde terminate results on the cache performance. bits 5?0: chslot: cache slot pointer. these read-only bits are the pointer into the cache lock stack. locations above chslot are locked, and will not be changed by the pr ocessor, except when chslot equals 0. r / wr / wrrrrrrr e s e t v a l u e chpush chpop chslot 00111110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa3 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 217 sfr definition 16.4. cch0ma: cache miss accumulator sfr definition 16.5. flstat: flash status bit 7: chmsov: cache miss penalty overflow. this bit indicates when the cache miss pena lty accumulator has overflowed since it was last written. 0: the cache miss penalty accumulator has not overflowed since it was last written. 1: an overflow of the cache miss penalty accumulator has occurred since it was last written. bits 6?0: chmscth: cache miss penalty accumulator (bits 11?5) these are bits 11-5 of the cache miss penalty accumulator. the next four bits (bits 4-1) are stored in chmsctl in the cch0tn register. the cache miss penalty accumulator is incremented every clock cycle that the processor is delayed due to a cache miss. th is is primarily used as a dia gnostic feature, when optimizing code for execution speed. writing to chmscth clears the lower 5 bits of the cache miss penalty accumulator. reading from chmscth returns the current value of chmstch, and latches bits 4-1 into chmstcl so that they can be read. becaus e bit 0 of the cache miss penalty accumulator is not available, the cumulative miss pe nalty is equal to 2 * (cchmstch:cchmstcl). r r/wr/wr/wr/wr/wr/wr/wreset value chmsov chmscth 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x9a f bit 7?1: reserved. bit 0: flbusy: flash busy this bit indicates when a flash write or erase operation is in progress. 0: flash is idle or reading. 1: flash write/erase operation is currently in progress. r r/wr/wr/wr/wr/wr/wr/wreset value -------flbusy00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0x88 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 218 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 219 17. external data memory interface and on-chip xram there are 8 kb of on-chip ram mapped into the external data memory space (xram), as well as an exter- nal 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 17.1). note: the movx instruction can also be used for writing to the flash memory. see sec- tion ?15. flash memory? on page 199 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). 17.1. accessing xram the xram memory space is accessed using the mo vx instruction. the movx in struction has two forms, both of which use an indirect addressing method. th e first method uses the data pointer, dptr, a 16-bit register which contains the effective address of the xr am location to be read from or written to. the sec- ond method uses r0 or r1 in combination with th e emi0cn register to generate the effective xram address. examples of both of these methods are given below. 17.1.1. 16-bit movx example the 16-bit form of the movx instruct ion accesses the memory location po inted to by the contents of the dptr register. the following series of instructions re ads the value of the byte at address 0x1234 into the accumulator a: mov dptr, #1234h ; load dptr with 16-bit address to read (0x1234) movx a, @dptr ; load contents of 0x1234 into accumulator a the above example uses the 16-bit immediate mov instruction to set the contents of dptr. alternately, the dptr can be accessed through the sfr registers dph, which contains the upper 8-bits of dptr, and dpl, which contains the lower 8-bits of dptr. 17.1.2. 8-bit movx example the 8-bit form of the movx instruction uses the cont ents of the emi0cn sfr to determine the upper 8-bits of the effective address to be accessed and the contents of r0 or r1 to determine the lower 8-bits of the effective address to be accessed. the following series of instructions read the contents of the byte at address 0x1234 into the accumulator a. mov emi0cn, #12h ; load high byte of address into emi0cn mov r0, #34h ; load low byte of address into r0 (or r1) movx a, @r0 ; load contents of 0x1234 into accumulator a 17.2. configuring the external memory interface configuring the external memory interface consists of five steps: 1. select emif on low ports (p3, p2, p1, and p0) or high ports (p7, p6, p5, and p4). 2. configure the output modes of the port pins as either push-pull or open-drain (push-pull is most common). 3. configure port latches to ?park? the emif pins in a dormant state (usually by setting them to logic ?1?). 4. select multiplexed mode or non-multiplexed mode. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 220 rev. 1.4 5. select the memory mode (on-chip only, split mode without bank select, split mode with bank select, or off-chip only). 6. set up timing to interface with off-chip memory or peripherals. each of these five steps is explained in detail in th e following sections. the po rt selection, multiplexed mode selection, and mode bits are located in the emi0cf register shown in sfr definition 17.2. 17.3. port selection and configuration the external memory interface can appear on ports 3, 2, 1, and 0 (all devices) or on ports 7, 6, 5, and 4 (100-pin tqfp devices only), depending on the state of the prtsel bit (emi0cf.5). if the lower ports are selected, the emifle bit (xbr 2.1) must be set to a ?1? so that the crossbar will skip over p0.7 (/wr), p0.6 (/rd), and if multiplexed mode is selected p0.5 (ale). for more information about the configuring the crossbar, see section ?18.1. ports 0 through 3 and the priority crossbar decoder? on page 238 . the external memory interface claims the associated port pins for memory operations only during the execution of an off-chip movx instruction. once the movx instruction has completed, control of the port pins reverts to the port latches or to the crossbar (on ports 3, 2, 1, and 0). see section ?18. port input/ output? on page 235 for more information about the crossbar and port operation and configuration. the port latches should be explicitly configured to ?park? the external memory interface pins in a dor- mant state, most commonly by setting them to a logic 1 . during the execution of the movx inst ruction, the external memory interf ace will explicitly disable the driv- ers on all port pins that are acting as inputs (data[7:0] during a read operation, for example). the output mode of the port pins (whether the pin is configured as open-drain or push-pull) is unaffected by the external memory interface operation, and remains c ontrolled by the pnmdout registers. in most cases, the output modes of all emif pins should be config ured for push-pull mode. see?configuring the output modes of the port pins? on page 239. sfr definition 17.1. emi0cn: extern al memory interface control bits7?0: pgsel[7:0]: xr am page select bits. the xram page select bits provide the high byte of the 16-bit external data memory address when using an 8-bit movx command, effectively selecting a 256-byte page of ram. 0x00: 0x0000 to 0x00ff 0x01: 0x0100 to 0x01ff ... 0xfe: 0xfe00 to 0xfeff 0xff: 0xff00 to 0xffff r/wr/wr/wr/wr/wr/wr/wr/wreset value pgsel7 pgsel6 pgsel5 pgsel4 pgsel 3 pgsel2 pgsel1 pgsel0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa2 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 221 sfr definition 17.2. emi0cf: ex ternal memory configuration bits7?6: unused. read = 00b. write = don?t care. bit5: prtsel: emif port select. 0: emif active on p0?p3. 1: emif active on p4?p7. bit4: emd2: emif multiplex mode select. 0: emif operates in multiplexed address/data mode. 1: emif operates in non-multiplexed mode (separate address and data pins). bits3?2: emd1-0: emif op erating mode select. these bits control the operating mode of the external memory interface. 00: internal only: movx accesses on-chip xram only. all effective addresses alias to on- chip memory space. 01: split mode without bank select: accesses below the 8 k boundary are directed on-chip. accesses above the 8 k boundary are directed off-chip. 8-bit off-chip movx operations use the current contents of the address high port latches to resolve upper address byte. note that in order to access off-chip space, emi0cn mu st be set to a page that is not contained in the on-chip address space. 10: split mode with bank select: accesses below the 8 k boundary are directed on-chip. accesses above the 8k boundary are directed off-chip. 8-bit off-chip movx operations use the contents of emi0cn to determine the high-byte of the address. 11: external only: movx accesses off-chip xram only. on-chip xram is not visible to the cpu. bits1?0: eale1?0: ale pulse-width select bits (only has effect when emd2 = 0). 00: ale high and ale low pulse width = 1 sysclk cycle. 01: ale high and ale low pulse width = 2 sysclk cycles. 10: ale high and ale low pulse width = 3 sysclk cycles. 11: ale high and ale low pulse width = 4 sysclk cycles. r/wr/wr/wr/wr/wr/wr/w r/wreset value - - prtsel emd2 emd1 emd0 eale1 eale0 00000011 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa3 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 222 rev. 1.4 17.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. 17.4.1. multiplexed configuration in multiplexed mode, the data bus and the lower 8-bits of the address bus share the same port pins: ad[7:0]. in this mode, an external latch (74hc373 or equivalent logic gate) is used to hold the lower 8-bits of the ram address. the external latch is controlle d by the ale (address latch enable) signal, which is driven by the external memory interface logic. an example of a multiplexed configuration is shown in figure 17.1. in multiplexed mode, the external movx operation can be broken into two phases delineated by the state of the ale signal. during the first phase, ale is high and the lower 8-bits of the address bus are pre- sented to ad[7:0]. during this phase, the address latch is configured such that the ?q? outputs reflect the states of the ?d? inputs. when ale falls, signaling the beginning of the second phase, the address latch outputs remain fixed and are no longer dependent on the latch inputs. later in the second phase, the data bus controls the state of the ad[7:0] port at the time /rd or /wr is asserted. see section ?17.6.2. multiplexed mode? on page 230 for more information. figure 17.1. multiplexed configuration example address/data bus address bus e m i f a[15:8] ad[7:0] /wr /rd ale 64k x 8 sram oe we i/o[7:0] 74hc373 g dq a[15:8] a[7:0] ce v dd 8 (optional) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 223 17.4.2. non-multiplexed configuration in non-multiplexed mode, the data bus and the addr ess bus pins are not shared. an example of a non- multiplexed configuration is shown in figure 17.2. see section ?17.6.1. non-multiplexed mode? on page 227 for more information about non-multiplexed operation. figure 17.2. non-multiplexed configuration example address bus e m i f a[15:0] 64k x 8 sram a[15:0] data bus d[7:0] i/o[7:0] v dd 8 /wr /rd oe we ce (optional) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 224 rev. 1.4 17.5. memory mode selection the external data memory space can be configured in one of four modes, shown in figure 17.3, based on the emif mode bits in the emi0cf register (sfr definition 17.2). these modes are summarized below. more information about the different modes can be found in section ?sfr defi nition 17.3. emi0tc: external memory timing control? on page 226 . 17.5.1. internal xram only when emi0cf.[3:2] are set to ?00?, all movx instructions will ta rget the internal xram space on the device. memory accesses to addre sses beyond the p opulated space will wrap on 8 k boundaries. as an example, the addresses 0x2000 and 0x4000 both evaluate to address 0x0000 in on-chip xram space. ? 8-bit movx operations use the contents of emi0cn to determine the high-byte of the effective address and r0 or r1 to determine the lo w-byte of the effective address. ? 16-bit movx operations use the contents of the 16-bit dptr to determine the effective address. 17.5.2. split mode without bank select when emi0cf.[3:2] are set to ?01?, the xram memory map is split into two areas, on-chip space and off- chip space. ? effective addresses below the 8 k bo undary will access on-chip xram space. ? effective addresses above the 8 k boundary will access off-chip space. ? 8-bit movx operations use the contents of emi0cn to determine whether the memory access is on- chip or off-chip. however, in th e ?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 se tting 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 on- chip or off-chip, and unlike 8-bit movx operations, the full 16-bits of the address bus a[15:0] are driven during the off-chip transaction. figure 17.3. emif operating modes emi0cf[3:2] = 00 0xffff 0x0000 emi0cf[3:2] = 11 0xffff 0x0000 emi0cf[3:2] = 01 0xffff 0x0000 emi0cf[3:2] = 10 on-chip xram on-chip xram on-chip xram on-chip xram on-chip xram on-chip xram off-chip memory (no bank select) on-chip xram 0xffff 0x0000 off-chip memory (bank select) on-chip xram off-chip memory c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 225 17.5.3. split mode with bank select when emi0cf.[3:2] are set to ?10?, the xram memory map is split into two areas, on-chip space and off- chip space. ? effective addresses below the 8k bo undary will access on -chip xram space. ? effective addresses above the 8k boundary will access off-chip space. ? 8-bit movx operations use the contents of emi0cn to determine whether the memory access is on- chip or off-chip. the upper 8-bits of the address bus a[15:8] are determined by emi0cn, and the lower 8-bits of the address bus a[7:0] are determined by r0 or r1. all 16-bits of the address bus a[15:0] are driven in ?ban k select? mode. ? 16-bit movx operations use the contents of dptr to determine whether the memory access is on- chip or off-chip, and the full 16-bits of the address bus a[15:0] are driven during the off-chip transac- tion. 17.5.4. external only when emi0cf[3:2] are set to ?11?, all movx operations are directed to off-chip space. on-chip xram is not visible to the cpu. this mode is useful for ac cessing off-chip memory located between 0x0000 and the 8k boundary. ? 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 upp er 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. 17.6. emif timing the timing parameters of the external memory in terface 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 throug h emi0tc, shown in sfr defini tion 17.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 operat ion is 5 sysclk cycles (1 sysclk for /rd or /wr pulse + 4 sysclks). for multiplexed operations, the addr ess latch enable signal will requir e a minimum of 2 additional sys- clk cycles. therefore, the minimum execution time fo r an off-chip xram oper ation in multiplexed mode is 7 sysclk cycles (2 for /ale + 1 for /rd or /wr + 4). the programma ble setup and hold times default to the maximum delay settings after a reset. table 1 7.1 lists the ac parameters for the external memory interface, and figure 17.4 through figure 17.9 show th e timing diagrams for the different external memory interface modes and movx operations. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 226 rev. 1.4 sfr definition 17.3. emi0tc: exte rnal memory timing control bits7?6: eas1?0: emif addr ess setup time bits. 00: address setup time = 0 sysclk cycles. 01: address setup time = 1 sysclk cycle. 10: address setup time = 2 sysclk cycles. 11: address setup time = 3 sysclk cycles. bits5?2: ewr3?0: emif /wr and /rd pulse-width control bits. 0000: /wr and /rd pulse width = 1 sysclk cycle. 0001: /wr and /rd pulse width = 2 sysclk cycles. 0010: /wr and /rd pulse width = 3 sysclk cycles. 0011: /wr and /rd pulse width = 4 sysclk cycles. 0100: /wr and /rd pulse width = 5 sysclk cycles. 0101: /wr and /rd pulse width = 6 sysclk cycles. 0110: /wr and /rd pulse width = 7 sysclk cycles. 0111: /wr and /rd pulse width = 8 sysclk cycles. 1000: /wr and /rd pulse width = 9 sysclk cycles. 1001: /wr and / rd pulse width = 10 sysclk cycles. 1010: /wr and /rd pulse width = 11 sysclk cycles. 1011: /wr and /rd pulse width = 12 sysclk cycles. 1100: /wr and /rd pulse width = 13 sysclk cycles. 1101: /wr and /rd pulse width = 14 sysclk cycles. 1110: /wr and /rd pulse width = 15 sysclk cycles. 1111: /wr and /rd pulse width = 16 sysclk cycles. bits1?0: eah1?0: emif address hold time bits. 00: address hold time = 0 sysclk cycles. 01: address hold time = 1 sysclk cycle. 10: address hold time = 2 sysclk cycles. 11: address hold time = 3 sysclk cycles. r/wr/wr/wr/wr/wr/wr/wr/wreset value eas1 eas0 erw3 ewr2 ewr1 ewr0 eah1 eah0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xa1 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 227 17.6.1. non-multiplexed mode 17.6.1.1.16-bit movx: emi0cf[4:2] = ?101?, ?110?, or ?111? figure 17.4. non-multiplexed 16-bit movx timing emif address (8 msbs) from dph emif address (8 lsbs) from dpl p2/p6 p1/p5 p0.7/p4.7 p0.6/p4.6 p3/p7 emif write data p2/p6 p1/p5 p0.7/p4.7 p0.6/p4.6 p3/p7 t ach t wdh t acw t acs t wds addr[15:8] addr[7:0] data[7:0] /wr /rd emif address (8 msbs) from dph emif address (8 lsbs) from dpl p2/p6 p1/p5 p0.6/p4.6 p0.7/p4.7 p3/p7 p2/p6 p1/p5 p0.6/p4.6 p0.7/p4.7 p3/p7 t ach t rdh t acw t acs t rds addr[15:8] addr[7:0] data[7:0] /rd /wr emif read data nonmuxed 16-bit write nonmuxed 16-bit read c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 228 rev. 1.4 17.6.1.2.8-bit movx without bank select: emi0cf[4:2] = ?101? or ?111?. figure 17.5. non-multiplexed 8-bit mo vx without bank select timing emif address (8 lsbs) from r0 or r1 p2/p6 p1/p5 p0.7/p4.7 p0.6/p4.6 p3/p7 emif write data p2/p6 p0.7/p4.7 p0.6/p4.6 p3/p7 t ach t wdh t acw t acs t wds addr[15:8] addr[7:0] data[7:0] /wr /rd emif address (8 lsbs) from r0 or r1 p2/p6 p1/p5 p0.6/p4.6 p0.7/p4.7 p3/p7 p2/p6 p0.6/p4.6 p0.7/p4.7 p3/p7 t ach t rdh t acw t acs t rds addr[15:8] addr[7:0] data[7:0] /rd /wr emif read data nonmuxed 8-bit write without bank select nonmuxed 8-bit read without bank select c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 229 17.6.1.3.8-bit movx with bank select : emi0cf[4:2] = ?110?. figure 17.6. non-multipl exed 8-bit movx with bank select timing emif address (8 msbs) from emi0cn emif address (8 lsbs) from r0 or r1 p2/p6 p1/p5 p0.7/p4.7 p0.6/p4.6 p3/p7 emif write data p2/p6 p1/p5 p0.7/p4.7 p0.6/p4.6 p3/p7 t ach t wdh t acw t acs t wds addr[15:8] addr[7:0] data[7:0] /wr /rd emif address (8 msbs) from emi0cn emif address (8 lsbs) from r0 or r1 p2/p6 p1/p5 p0.6/p4.6 p0.7/p4.7 p3/p7 p2/p6 p1/p5 p0.6/p4.6 p0.7/p4.7 p3/p7 t ach t rdh t acw t acs t rds addr[15:8] addr[7:0] data[7:0] /rd /wr emif read data nonmuxed 8-bit write with bank select nonmuxed 8-bit read with bank select c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 230 rev. 1.4 17.6.2. multiplexed mode 17.6.2.1.16-bit movx: emi0cf[4:2] = ?001 ?, ?010?, or ?011? figure 17.7. multiplexed 16-bit movx timing p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p2/p6 p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 t ach t wdh t acw t acs t wds ale /wr /rd emif address (8 msbs) from dph emif write data emif address (8 lsbs) from dpl t aleh t alel p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p2/p6 p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 t ach t acw t acs ale /rd /wr emif address (8 msbs) from dph emif address (8 lsbs) from dpl t aleh t alel t rdh t rds emif read data muxed 16-bit write muxed 16-bit read c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 231 17.6.2.2.8-bit movx without bank select: emi0cf[4:2] = ?001? or ?011?. figure 17.8. multiplexed 8-bit mo vx without bank select timing p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 t ach t wdh t acw t acs t wds ale /wr /rd emif write data emif address (8 lsbs) from r0 or r1 t aleh t alel p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 t ach t acw t acs ale /rd /wr emif address (8 lsbs) from r0 or r1 t aleh t alel t rdh t rds emif read data muxed 8-bit write without bank select muxed 8-bit read without bank select c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 232 rev. 1.4 17.6.2.3.8-bit movx with bank select : emi0cf[4:2] = ?010?. figure 17.9. multiplexed 8-bit mo vx with bank select timing p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p2/p6 p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 p0.7/p4.7 p0.6/p4.6 p0.5/p4.5 t ach t wdh t acw t acs t wds ale /wr /rd emif address (8 msbs) from emi0cn emif write data emif address (8 lsbs) from r0 or r1 t aleh t alel p3/p7 p2/p6 p3/p7 addr[15:8] ad[7:0] p2/p6 p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 p0.6/p4.6 p0.7/p4.7 p0.5/p4.5 t ach t acw t acs ale /rd /wr emif address (8 msbs) from emi0cn emif address (8 lsbs) from r0 or r1 t aleh t alel t rdh t rds emif read data muxed 8-bit write with bank select muxed 8-bit read with bank select c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 233 table 17.1. ac parameters fo r external memory interface parameter description min max units t acs address/control setup time 0 3 x t sysclk ns t acw address/control pulse width 1 x t sysclk 16 x t sysclk ns t ach address/control hold time 0 3 x t sysclk ns t aleh address latch enable high time 1 x t sysclk 4xt sysclk ns t alel address latch enable low time 1 x t sysclk 4xt sysclk ns t wds write data setup time 1 x t sysclk 19 x t sysclk ns t wdh write data hold time 0 3 x t sysclk ns t rds read data setup time 20 ? ns t rdh read data hold time 0 ? ns note: t sysclk is equal to one per iod of the device syst em clock (sysclk). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 234 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 235 18. port input/output the devices are fully integrated mixed-signal system on a chip mcus with 64 digital i/o pins (100-pin tqfp packaging) or 32 digital i/o pins (64-pin tqfp packaging), 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-toler- ant, and all support configurable open-drain or push-pull output modes and weak pullups. a block dia- gram of the port i/o cell is shown in figure 18.1. comp lete electrical specifications for the port i/o pins are given in table 18.1. figure 18.1. port i/o cell block diagram dgnd /port-outenable port-output push-pull vdd vdd /weak-pullup (weak) port pad analog input analog select (ports 1, 2, and 3) port-input c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 236 rev. 1.4 table 18.1. port i/o dc electrical characteristics v dd = 2.7 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units output high voltage (v oh ) i oh = -3 ma, port i/o push-pull i oh = -10 a, port i/o push-pull i oh = -10 ma, port i/o push-pull v dd ?0.7 v dd ?0.1 v dd ?0.8 v output low voltage (v ol ) i ol = 8.5 ma i ol = 10 a i ol = 25 ma 1.0 0.6 0.1 v input high voltage (vih) 0.7 x v dd input low voltage (vil) 0.3 x v dd input leakage current dgnd < port pin < v dd , pin tri-state weak pullup off weak pullup on 10 1 a input capacitance 5 pf c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 237 a wide array of digital resources is 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 18.2. the system designer controls which digital functions are assigned pins, limited only by the number of pins available. this resource assignme nt flexibility is achieved th rough the use of a priority crossbar decode r. note that the state of a port i/o pin can always be read from its associated data register regardless of whether that pin has been assigned to a digital peripheral or behaves as gpio. the port pins on port 1 can be used as analog inputs to adc2. an external memory interface which is active during the execution of an off-chip movx instruction can be active on either the lower ports or the upper ports. see section ?17. external da ta memory interface and on-chip xram? on page 219 for more information about th e external memory interface. figure 18.2. port i/o fun ctional block diagram external pins digital crossbar priority decoder smbus 2 spi 4 uart0 2 pca 2 t0, t1, t2, t2ex, t4,t4ex /int0, /int1 p1.0 p1.7 p2.0 p2.7 p0.0 p0.7 highest priority lowest priority 8 8 comptr. outputs (internal digital signals) highest priority lowest priority uart1 /sysclk divided by 1,2,4, or 8 cnvstr0/2 7 2 p3.0 p3.7 8 8 p0mdout, p1mdout, p2mdout, p3mdout registers xbr0, xbr1, xbr2, p1mdin registers p1 i/o cells p3 i/o cells p0 i/o cells p2 i/o cells 8 port latches p0 p1 p2 8 8 8 p3 8 (p2.0-p2.7) (p1.0-p1.7) (p0.0-p0.7) (p3.0-p3.7) to adc2 input (?f12x only) to external memory interface (emif) 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 238 rev. 1.4 18.1. ports 0 through 3 and the priority crossbar decoder the priority crossbar decoder, or ?crossbar?, allo cates and assigns port pins on port 0 through port 3 to the digital peripherals (uarts, smbus, pca, timers, etc.) on the device using a priority order. the port pins are allocated in order starting with p0.0 and continue through p3.7 if necessary. the digital peripher- als are assigned port pins in a priority order which is listed in figure 18.3, with uart0 having the highest priority and cnvstr2 having the lowest priority. 18.1.1. crossbar pin assignment and allocation the crossbar assigns port pins to a peripheral if the corresponding enable bits of the peripheral are set to a logic 1 in the crossbar configuration registers xbr0, xbr1, and xbr2, shown in sfr definition 18.1, sfr definition 18.2, and sfr definition 18.3. for ex ample, if the uart0en bit (xbr0.2) is set to a logic 1, the tx0 and rx0 pins will be ma pped to p0.0 and p0.1 respectively. figure 18.3. priority crossbar decode table (emifle = 0; p1mdin = 0xff) because uart0 has the highest priori ty, its pins will always be mappe d to p0.0 and p0.1 when uart0en is set to a logic 1. if a digital peripheral?s enable bits are not set to a logic 1, then its ports are not accessi- ble at the port pins of the device. also note that th e crossbar assigns pins to all associated functions when a serial communication peripheral is selected (i.e. smbus, spi, uart). it would be impossible, for exam- pin i/o 01234567012345670123456701234567 tx0 rx0 sck miso mosi nss nss is not assigned to a port pin when the spi is placed in 3-wire mode sda scl tx1 rx1 cex0 cex1 cex2 cex3 cex4 cex5 eci eci0e: xbr0.6 cp0 cp0e: xbr0.7 cp1 cp1e: xbr1.0 t0 t0e: xbr1.1 /int0 int0e: xbr1.2 t1 t1e: xbr1.3 /int1 int1e: xbr1.4 t2 t2e: xbr1.5 t2ex t2exe: xbr1.6 t4 t4e: xbr2.3 t4ex t4exe: xbr2.4 /sysclk syscke: xbr1.7 cnvstr0 cnvste0: xbr2.0 cnvstr2 cnvste2: xbr2.5 ale /rd /wr ain2.0/a8 ain2.1/a9 ain2.2/a10 ain2.3/a11 ain2.4/a12 ain2.5/a13 ain2.6/a14 ain2.7/a15 a8m/a0 a9m/a1 a10m/a2 a11m/a3 a12m/a4 a13m/a5 a14m/a6 a15m/a7 ad0/d0 ad1/d1 ad2/d2 ad3/d3 ad4/d4 ad5/d5 ad6/d6 ad7/d7 p0 p1 p2 p3 ain2 inputs/non-muxed addr h muxed addr h/non-muxed addr l muxed data/non-muxed data uart1en: pca0me: crossbar register bits xbr0.2 xbr0.1 xbr0.0 smb0en: xbr2.2 xbr0.[5:3] uart0en: spi0en: c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 239 ple, to assign tx0 to a port pin without assigning rx0 as well. each combination of enabled peripherals results in a unique device pinout. all port pins on ports 0 through 3 that are not allocated by the crossbar can be accessed as general-pur- pose i/o (gpio) pins by reading and writing the associated port data registers (see sfr definition 18.4, sfr definition 18.6, sfr definition 18.9, and sfr defi nition 18.11), a set of sfr?s which are both byte- and bit-addressable. the output states of port pins th at 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 th e pin itself, regard- less 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, setb, and the bitwise mov write operation). during the read cycle of the read-modify-write instruc- tion, it is the contents of the port data register, not the state of the port pins themselves, which is read. note that at clock rates above 50 mhz, when a pin is written and then immediately read (i.e. a write instruc- tion followed immediately by a read instruction), the propagation delay of the port drivers may cause the read instruction to return the previous logic level of the pin. because the crossbar registers affect the pinout of the peripherals of the device, they are typically config- ured in the initialization co de of the system before the peripherals themselves are configured. once config- ured, the crossbar registers are typically left alone. once the crossbar registers have been properly co nfigured, 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 reg- isters 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 pnmd out registers have no effect on the states of these pins. 18.1.2. configuring the output modes of the port pins the output drivers on ports 0 through 3 remain disabl ed until the crossbar is enabled by setting xbare (xbr2.4) to a logic 1. the output mode of each port pin can be configured to be either open-drain or push-pull. in the push-pull configuration, writ ing a logic 0 to the associated bit in the port data register will cause the port pin to be driven to gnd, and writing a logic 1 w ill cause the port pin to be driven to v dd . in the open-drain configu- ration, writing a logic 0 to th e associated bit in the port data register w ill cause the port pi n to be driven to gnd, and a logic 1 will cause the port pin to assume a high-impedance state. the open-drain configura- tion is useful to prevent contention between devices in systems where the port pin participates in a shared interconnection in which mu ltiple outputs are connected to the same physical wire (like the sda signal on an smbus connection). the output modes of the port pins on ports 0 through 3 are determined by the bits in the associated pnmdout registers (see sfr definition 18.5, sfr definition 18.8, sfr definition 18.10, and sfr defini- tion 18.12). for example, a logic 1 in p3mdout.7 will configure the output mode of p3.7 to push-pull; a logic 0 in p3mdout.7 will configure th e output mode of p3.7 to open-drai n. all port pins default to open- drain output. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 240 rev. 1.4 the pnmdout registers control the out put modes of the port pins regardless of whether the crossbar has allocated the port pin for a digital peripheral or not. th e exceptions to this rule are: the port pins connected to sda, scl, rx0 (if uart0 is in mode 0), and rx 1 (if uart1 is in mode 0) are always configured as open-drain outputs, regardless of the settings of the associated bits in the pnmdout registers. 18.1.3. configuring port pins as digital inputs a port pin is configured as a digital input by setting its output mode to ?open-drain? and writing a logic 1 to the associated bit in the port data register. for exampl e, p3.7 is configured as a digital input by setting p3mdout.7 to a logic 0 and p3.7 to a logic 1. if the port pin has been assigned to a digital peripheral by the crossbar and that pin functions as an input (for example rx0, the uart0 receive pin), then the ou tput drivers on that pin are automatically disabled. 18.1.4. weak pullups by default, each port pin has an internal weak pullup device enabled which provides a resistive connection (about 100 k ? ) between the pin and v dd . the weak pullup devices can be globally disabled by writing a logic 1 to the weak pullup disable bit, (weakpud, xbr2.7). the weak pullup is automatically deactivated on any pin that is drivin g a logic 0; that is, an out put pin will not contend with its own pullup device. the weak pullup device can also be explicitly disabled on any port 1 pin by configuring the pin as an analog input, as described below. 18.1.5. configuring port 1 pins as analog inputs the pins on port 1 can serve as analog inputs to th e adc2 analog mux on the c8051f12x devices. a port pin is configured as an analog inpu t by writing a logic 0 to the associated bit in the pnmdin registers. all port pins default to a digital input mode. configuring a port pin as an analog input: 1. disables the digital input path from the pin. this prevents additional power supply current from being drawn when the voltage at the pin is near v dd / 2. a read of the port data bit will return a logic 0 regardless of the voltage at the port pin. 2. disables the weak pullup device on the pin. 3. causes the crossbar to ?skip over? the pin when allocating port pins for digital peripherals. note that the output drivers on a pin configured as an analog input are not explicitly disabled. therefore, the associated p1mdout bits of pins configured as analog inputs should explicitly be set to logic 0 (open-drain output mode), and the associated port1 data bits should be set to logic 1 (high-impedance). also note that it is not required to configure a port pi n as an analog input in order to use it as an input to adc2, however, it is strongly recommended. see the ad c2 section in this datasheet for further informa- tion. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 241 18.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 assi gn peripherals to p0.7 (/wr), p0.6 (/rd), and if the external memory interface is in multiplexed mode, p0.5 (ale). figure 18.4 shows an example cross- bar decode table with emifle=1 and the emif in multiplexed mode. figure 18.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 out put states of the affected po rt pins during the execution phase of the movx instruction, regardless of the setti ngs of the crossbar registers or the port data regis- ters. the output configuration of the port pins is not affected by the emif operation, except that read operations will explicitly disable the output drivers on the data bus. see section ?17. external data mem- ory interface and on-chip xram? on page 219 for more information about the external memory inter- face. figure 18.4. priority crossbar decode ta ble (emifle = 1; emif in multiplexed mode; p1mdin = 0xff) pin i/o 01234567012345670123456701234567 tx0 rx0 sck miso mosi nss nss is not assigned to a port pin when the spi is placed in 3-wire mode sda scl tx1 rx1 cex0 cex1 cex2 cex3 cex4 cex5 eci eci0e: xbr0.6 cp0 cp0e: xbr0.7 cp1 cp1e: xbr1.0 t0 t0e: xbr1.1 /int0 int0e: xbr1.2 t1 t1e: xbr1.3 /int1 int1e: xbr1.4 t2 t2e: xbr1.5 t2ex t2exe: xbr1.6 t4 t4e: xbr2.3 t4ex t4exe: xbr2.4 /sysclk syscke: xbr1.7 cnvstr0 cnvste0: xbr2.0 cnvstr2 cnvste2: xbr2.5 ale /rd /wr ain2.0/a8 ain2.1/a9 ain2.2/a10 ain2.3/a11 ain2.4/a12 ain2.5/a13 ain2.6/a14 ain2.7/a15 a8m/a0 a9m/a1 a10m/a2 a11m/a3 a12m/a4 a13m/a5 a14m/a6 a15m/a7 ad0/d0 ad1/d1 ad2/d2 ad3/d3 ad4/d4 ad5/d5 ad6/d6 ad7/d7 xbr2.2 xbr0.[5:3] uart0en: spi0en: crossbar register bits xbr0.2 xbr0.1 xbr0.0 smb0en: ain2 inputs/non-muxed addr h muxed addr h/non-muxed addr l muxed data/non-muxed data uart1en: pca0me: p0 p1 p2 p3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 242 rev. 1.4 figure 18.5. priority crossbar decode table (emifle = 1; emif in non-multiplexed mode; p1mdin = 0xff) pin i/o 01234567012345670123456701234567 tx0 rx0 sck miso mosi nss nss is not assigned to a port pin when the spi is placed in 3-wire mode sda scl tx1 rx1 cex0 cex1 cex2 cex3 cex4 cex5 eci eci0e: xbr0.6 cp0 cp0e: xbr0.7 cp1 cp1e: xbr1.0 t0 t0e: xbr1.1 /int0 int0e: xbr1.2 t1 t1e: xbr1.3 /int1 int1e: xbr1.4 t2 t2e: xbr1.5 t2ex t2exe: xbr1.6 t4 t4e: xbr2.3 t4ex t4exe: xbr2.4 /sysclk syscke: xbr1.7 cnvstr0 cnvste0: xbr2.0 cnvstr2 cnvste2: xbr2.5 ale /rd /wr ain2.0/a8 ain2.1/a9 ain2.2/a10 ain2.3/a11 ain2.4/a12 ain2.5/a13 ain2.6/a14 ain2.7/a15 a8m/a0 a9m/a1 a10m/a2 a11m/a3 a12m/a4 a13m/a5 a14m/a6 a15m/a7 ad0/d0 ad1/d1 ad2/d2 ad3/d3 ad4/d4 ad5/d5 ad6/d6 ad7/d7 xbr2.2 xbr0.[5:3] uart0en: spi0en: crossbar register bits xbr0.2 xbr0.1 xbr0.0 smb0en: ain2 inputs/non-muxed addr h muxed addr h/non-muxed addr l muxed data/non-muxed data uart1en: pca0me: p0 p1 p2 p3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 243 18.1.7. crossbar pin assignment example in this example (figure 18.6), we configure the cros sbar to allocate port pins for uart0, the smbus, uart1, /int0, and /int1 (8 pins total). additionally, we configure the external memory interface to oper- ate 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: xbr 0 = 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 anal og input mode by setting p1mdin to 0xe3 (p1.4, p1.3, and p1.2 are analog inputs, so thei r 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, em ifle = 1, which causes the crossbar to skip p0.6 (/rd) and p0.7 (/wr). be cause the external memory interface is configured in multi- plexed mode, the crossbar will also skip p0.5 (ale). rx1 is assigned to the next non- skipped pin, which in this case is p1.0. - /int0 is next in priority order, so it is assigned to p1.1. - p1mdin is set to 0xe3, which configures p1.2, p1.3, and p1.4 as analog inputs, causing the crossbar to skip these pins. - /int1 is next in priority order, so it is assi gned to the next non-skipped pin, which is p1.5. - the external memory inte rface will drive ports 2 and 3 (denoted by red dots in figure 18.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). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 244 rev. 1.4 figure 18.6. crossbar example pin i/o 01234567012345670123456701234567 tx0 rx0 sck miso mosi nss sda scl tx1 rx1 cex0 cex1 cex2 cex3 cex4 cex5 eci eci0e: xbr0.6 cp0 cp0e: xbr0.7 cp1 cp1e: xbr1.0 t0 t0e: xbr1.1 /int0 int0e: xbr1.2 t1 t1e: xbr1.3 /int1 int1e: xbr1.4 t2 t2e: xbr1.5 t2ex t2exe: xbr1.6 t4 t4e: xbr2.3 t4ex t4exe: xbr2.4 /sysclk syscke: xbr1.7 cnvstr0 cnvste0: xbr2.0 cnvstr2 cnvste2: xbr2.5 ale /rd /wr ain2.0/a8 ain2.1/a9 ain2.2/a10 ain2.3/a11 ain2.4/a12 ain2.5/a13 ain2.6/a14 ain2.7/a15 a8m/a0 a9m/a1 a10m/a2 a11m/a3 a12m/a4 a13m/a5 a14m/a6 a15m/a7 ad0/d0 ad1/d1 ad2/d2 ad3/d3 ad4/d4 ad5/d5 ad6/d6 ad7/d7 xbr2.2 xbr0.[5:3] uart0en: spi0en: crossbar register bits xbr0.2 xbr0.1 xbr0.0 smb0en: ain2 inputs/non-muxed addr h muxed addr h/non-muxed addr l muxed data/non-muxed data uart1en: pca0me: p0 p1 p2 p3 (emifle = 1; emif in multiplexed mode; p1mdin = 0xe3; xbr0 = 0x05; xbr1 = 0x14; xbr2 = 0x42) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 245 sfr definition 18.1. xbr0: port i/o crossbar register 0 bit7: cp0e: comparator 0 output enable bit. 0: cp0 unavailable at port pin. 1: cp0 routed to port pin. bit6: eci0e: pca0 external counter input enable bit. 0: pca0 external counter in put unavailable at port pin. 1: pca0 external co unter input (eci0) routed to port pin. bits5?3: pca0me: pca0 mo dule i/o enable bits. 000: all pca0 i/o unavailable at port pins. 001: cex0 routed to port pin. 010: cex0, cex1 routed to 2 port pins. 011: cex0, cex1, and cex2 routed to 3 port pins. 100: cex0, cex1, cex2, and c ex3 routed to 4 port pins. 101: cex0, cex1, cex2, cex3, and cex4 routed to 5 port pins. 110: cex0, cex1, cex2, cex3, cex4, and cex5 routed to 6 port pins. bit2: uart0en: uart0 i/o enable bit. 0: uart0 i/o unavailable at port pins. 1: uart0 tx routed to p0.0 , and rx routed to p0.1. bit1: spi0en: spi0 bus i/o enable bit. 0: spi0 i/o unavailable at port pins. 1: spi0 sck, miso, mosi, and nss routed to 4 port pins. note that the nss signal is not assigned to a port pin if the spi is in 3-wire mode. see section ? 17. external data memory interface and on-chip xram ? on page 219 for more information. bit0: smb0en: smbus0 bus i/o enable bit. 0: smbus0 i/o unavailable at port pins. 1: smbus0 sda and scl routed to 2 port pins. r/wr/wr/wr/wr/wr/wr/wr/wreset value cp0e eci0e pca0me uart0en spi0en smb0en 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xe1 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 246 rev. 1.4 sfr definition 18.2. xbr1: port i/o crossbar register 1 bit7: syscke: /sysclk output enable bit. 0: /sysclk unavailable at port pin. 1: /sysclk (divided by 1, 2, 4, or 8) routed to port pin. divide factor is determined by the clkdiv1?0 bits in register clksel (see section ?14. oscillat ors? on page 185 ). bit6: t2exe: t2ex input enable bit. 0: t2ex unavailable at port pin. 1: t2ex routed to port pin. bit5: t2e: t2 input enable bit. 0: t2 unavailable at port pin. 1: t2 routed to port pin. bit4: int1e: /int1 input enable bit. 0: /int1 unavailable at port pin. 1: /int1 routed to port pin. bit3: t1e: t1 input enable bit. 0: t1 unavailable at port pin. 1: t1 routed to port pin. bit2: int0e: /int0 input enable bit. 0: /int0 unavailable at port pin. 1: /int0 routed to port pin. bit1: t0e: t0 input enable bit. 0: t0 unavailable at port pin. 1: t0 routed to port pin. bit0: cp1e: cp1 output enable bit. 0: cp1 unavailable at port pin. 1: cp1 routed to port pin. r/wr/wr/wr/wr/wr/wr/wr/wreset value syscke t2exe t2e int1e t1e int0e t0e cp1e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xe2 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 247 sfr definition 18.3. xbr2: port i/o crossbar register 2 bit7: weakpud: weak pullup disable bit. 0: weak pullups globally enabled. 1: weak pullups globally disabled. bit6: xbare: crossb ar enable bit. 0: crossbar disabled. all pins on ports 0, 1, 2, and 3, are forced to input mode. 1: crossbar enabled. bit5: cnvst2e: external conver t start 2 input enable bit. 0: cnvstr2 unavailable at port pin. 1: cnvstr2 routed to port pin. bit4: t4exe: t4ex input enable bit. 0: t4ex unavailable at port pin. 1: t4ex routed to port pin. bit3: t4e: t4 input enable bit. 0: t4 unavailable at port pin. 1: t4 routed to port pin. bit2: uart1e: uart1 i/o enable bit. 0: uart1 i/o unavailable at port pins. 1: uart1 tx and rx routed to 2 port pins. bit1: emifle: external memory interface low-port enable bit. 0: p0.7, p0.6, and p0.5 functions are determ ined by the crossbar or the port latches. 1: if emi0cf.4 = ?0? (external memory interface is in multiplexed mode) p0.7 (/wr), p0.6 (/rd), and p0.5 (ale) are ?skipped? by the crossbar and their output states are determined by the port latches and the external memory interface. 1: if emi0cf.4 = ?1? (external memory interface is in non-multiplexed mode) p0.7 (/wr) and p0.6 (/rd) are ?skipped? by the crossbar and their output states are determined by the port latches and the external memory interface. bit0: cnvst0e: adc0 external convert start input enable bit. 0: cnvst0 for adc0 unavailable at port pin. 1: cnvst0 for adc0 r outed to port pin. r/w r/w r/w r/w r/w r/w r/w r/w reset value weakpud xbare cnvst2e t4exe t4e uar t1e emifle cnvst0e 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xe3 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 248 rev. 1.4 sfr definition 18.4. p0: port0 data sfr definition 18.5. p0mdout: port0 output mode bits7?0: p0.[7:0]: port0 output latch bits. (write - output appears on i/o pins per xbr0, xbr1, and xbr2 registers) 0: logic low output. 1: logic high output (open if corresponding p0mdout.n bit = 0). (read - regardless of xbr0, xbr1, and xbr2 register settings). 0: p0.n pin is logic low. 1: p0.n pin is logic high. note: p0.7 (/wr), p0.6 (/rd), and p0.5 (ale) can be driven by the external data memory interface. see section ?17. external data memory interface and on-chip xram? on page 219 for more information. see also sfr definition 18.3 for information about configuring the crossbar for external memory accesses. r/w r/w r/w r/w r/w r/w r/w r/w reset value p0.7 p0.6 p0.5 p0.4 p0.3 p0.2 p0.1 p0.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0x80 all pages bits7?0: p0mdout.[7:0]: port0 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. note: sda, scl, and rx0 (when uart0 is in mode 0) and rx1 (when uart1 is in mode 0) are always configured as open-drain when they appear on port pins. 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: sfr page: 0xa4 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 249 sfr definition 18.6. p1: port1 data sfr definition 18.7. p1m din: port1 input mode bits7?0: p1.[7:0]: port1 output latch bits. (write - output appears on i/o pins per xbr0, xbr1, and xbr2 registers) 0: logic low output. 1: logic high output (open if corresponding p1mdout.n bit = 0). (read - regardless of xbr0, xbr1, and xbr2 register settings). 0: p1.n pin is logic low. 1: p1.n pin is logic high. notes: 1. on c8051f12x devices, p1.[7:0] can be configured as inputs to adc2 as ain2.[7:0], in which case they are ?skipped? by the crossbar assign ment process and their digital input paths are disabled, depending on p1mdin (see sfr definition 18.7 ) . note that in analog mode, the output mode of the pin is determined by the port 1 latch and p1mdout (sfr definition 18.8). see section ?7. adc2 (8-bit adc, c8051f12x only)? on page 91 for more information about adc2. 2. p1.[7:0] can be driven by the external data memory interface (as address[15:8] in non- multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more information about the external memory interface. r/w r/w r/w r/w r/w r/w r/w r/w reset value p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0x90 all pages bits7?0: p1mdin.[7:0]: port 1 input mode bits. 0: port pin is configured in analog input mode. th e digital input path is disabled (a read from the port bit will always return ?0?). t he weak pullup on th e pin is disabled. 1: port pin is configured in digital input mode. a read from the port bit will return the logic level at the pin. when configured as a digital input, the state of the weak pullup for the port pin is determined by the weakpud bit (xbr2.7, see sfr definition 18.3). r/w r/w r/w r/w r/w r/w r/w r/w reset value 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xad f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 250 rev. 1.4 sfr definition 18.8. p1mdout: port1 output mode sfr definition 18.9. p2: port2 data bits7?0: p1mdout.[7:0]: po rt1 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. note: sda, scl, and rx0 (when uart0 is in mode 0) and rx1 (when uart1 is in mode 0) are always configured as open-drain when they appear on port pins. 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: sfr page: 0xa5 f bits7?0: p2.[7:0]: port2 output latch bits. (write - output appears on i/o pins per xbr0, xbr1, and xbr2 registers) 0: logic low output. 1: logic high output (open if corresponding p2mdout.n bit = 0). (read - regardless of xbr0, xbr1, and xbr2 register settings). 0: p2.n pin is logic low. 1: p2.n pin is logic high. note: p2.[7:0] can be driven by the external data memory interface (as address[15:8] in multiplexed mode, or as address[7:0] in non-multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more information about the external memory interface. 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 addressable sfr address: sfr page: 0xa0 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 251 sfr definition 18.10. p2mdout: port2 output mode sfr definition 18.11. p3: port3 data bits7?0: p2mdout.[7:0]: port2 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. note: sda, scl, and rx0 (when uart0 is in mode 0) and rx1 (when uart1 is in mode 0) are always configured as open-drain when they appear on port pins. 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: sfr page: 0xa6 f bits7?0: p3.[7:0]: port3 output latch bits. (write - output appears on i/o pins per xbr0, xbr1, and xbr2 registers) 0: logic low output. 1: logic high output (open if corresponding p3mdout.n bit = 0). (read - regardless of xbr0, xbr1, and xbr2 register settings). 0: p3.n pin is logic low. 1: p3.n pin is logic high. note: p3.[7:0] can be driven by the external data memory interfac e (as ad[7:0] in multiplexed mode, or as d[7:0] in non-multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more information about the external memory interface. r/w r/w r/w r/w r/w r/w r/w r/w reset value p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 11111111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0xb0 all pages c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 252 rev. 1.4 sfr definition 18.12. p3mdout: port3 output mode 18.2. ports 4 through 7 (100-p in tqfp devices only) all port pins on ports 4 through 7 can be accessed as general-purpose i/o (gpio) pins by reading and writing the associated port data registers (see sfr definition 18.13, sfr definition 18.15, sfr definition 18.17, and sfr definition 18.19), a set of sfr?s wh ich are both bit and byte-addressable. note also that the port 4, 5, 6, and 7 registers are located on sfr pa ge f. the sfrpage register must be set to 0x0f to access these port registers. a read of a port data register (or port bit) will always return the logic state present at th e pin itself, regard- less 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, setb, and the bitwise mov write operation). during the read cycle of the read-modify-write instruc- tion, it is the contents of the port data register, not the state of the port pins themselves, which is read. note that at clock rates above 50 mhz, when a pin is written and then immediately read (i.e. a write instruc- tion followed immediately by a read instruction), the propagation delay of the port drivers may cause the read instruction to return the previous logic level of the pin. 18.2.1. configuring ports which are not pinned out although p4, p5, p6, and p7 are not brought out to pins on the 64-pin tqfp devices, the port data regis- ters are still present and can be used by software. be cause the digital i nput paths also remain active, it is recommended that these pins not be left in a ?floating? state in order to avoid unnecessary power dissipa- tion arising from the inputs floating to non-valid logi c 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 pnmdout = 0xff. 3. force the output states of p4, p5, p6, and p7 to logic 0 by writing zeros to the port data regis- ters: p4 = 0x00, p5 = 0x00, p6= 0x00, and p7 = 0x00. 18.2.2. configuring the output modes of the port pins the output mode of each port pin can be configured to be either open-drain or push-pull. in the push-pull configuration, a logic 0 in the associated bit in the port data register will cause the port pin to be driven to gnd, and a logic 1 will cause the port pin to be driven to v dd . in the open-drain configuration, a logic 0 in the associated bit in the port data register will cause the port pin to be driven to gnd, and a logic 1 will cause the port pin to assume a high-impedance state. the open-drain configuration is useful to prevent contention between devices in systems where the port pin participates in a shared interconnection in which multiple outputs are connected to the same physical wire. bits7?0: p3mdout.[7:0]: port3 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. 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: sfr page: 0xa7 f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 253 the output modes of the port pins on ports 4 throu gh 7 are determined by the bits in their respective pnmdout output mode registers. each bit in pnmd out controls the output mode of its corresponding port pin (see sfr definition 18.14, sfr definition 18.16, sfr definition 18.18, and sfr definition 18.20). for example, to place port pin 4.3 in push-pull mode (digital output), set p4mdout.3 to logic 1. all port pins default to open-drain mode upon device reset. 18.2.3. configuring port pins as digital inputs a port pin is configured as a digital input by setting its output mode to ?open-drain? and writing a logic 1 to the associated bit in the port data register. for exampl e, p7.7 is configured as a digital input by setting p7mdout.7 to a logic 0 and p7.7 to a logic 1. 18.2.4. weak pullups by default, each port pin has an internal weak pullup device enabled which provides a resistive connection (about 100 k ? ) between the pin and v dd . the weak pullup devices can be globally disabled by writing a logic 1 to the weak pullup disable bit, (weakpud, xbr2.7). the weak pullup is automatically deactivated on any pin that is driving a logic 0; that is, an output pin will not contend with its own pullup device. 18.2.5. external memory interface if the external memory interface (emif) is enabled on the high ports (ports 4 through 7), emifle (xbr2.5) should be set to a logic 0. if the external memory interface is enabled on the high ports and an off-chip movx operation occurs, the external memory interface will control the out put states of the affected po rt pins during the execution phase of the movx instruction, regardless of the settin gs of the port data registers. the output configura- tion of the port pins is not affected by the emif operation, except that read operations will explicitly dis- able the output drivers on the data bus during the movx execution. see section ?17. external data memory interface and on-chip xram? on page 219 for more information ab out the external memory interface. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 254 rev. 1.4 sfr definition 18.13. p4: port4 data sfr definition 18.14. p4mdout: port4 output mode bits7?0: p4.[7:0]: port4 output latch bits. write - output appears on i/o pins. 0: logic low output. 1: logic high output (open-drain if corresponding p4mdout.n bit = 0). see sfr definition 18.14. read - returns states of i/o pins. 0: p4.n pin is logic low. 1: p4.n pin is logic high. note: p4.7 (/wr), p4.6 (/rd), and p4.5 (ale) can be driven by the external data memory interface. see section ?17. external data memory interface and on-chip xram? on page 219 for more information. 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 sfr address: sfr page: 0xc8 f bits7?0: p4mdout.[7:0]: port4 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. 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: sfr page: 0x9c f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 255 sfr definition 18.15. p5: port5 data sfr definition 18.16. p5mdout: port5 output mode bits7?0: p5.[7:0]: port5 output latch bits. write - output appears on i/o pins. 0: logic low output. 1: logic high output (open-drain if corresponding p5mdout bit = 0). see sfr definition 18.16. read - returns states of i/o pins. 0: p5.n pin is logic low. 1: p5.n pin is logic high. note: p5.[7:0] can be driven by the external data memory interf ace (as address[15:8] in non- multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more information about the external memory interface. 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 sfr address: sfr page: 0xd8 f bits7?0: p5mdout.[7:0]: port5 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. 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: sfr page: 0x9d f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 256 rev. 1.4 sfr definition 18.17. p6: port6 data sfr definition 18.18. p6mdout: port6 output mode bits7?0: p6.[7:0]: port6 output latch bits. write - output appears on i/o pins. 0: logic low output. 1: logic high output (open-drain if corresponding p6mdout bit = 0). see sfr definition 18.18. read - returns states of i/o pins. 0: p6.n pin is logic low. 1: p6.n pin is logic high. note: p6.[7:0] can be driven by the external data me mory interface (as address[15:8] in multiplexed mode, or as address[7:0] in non-multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more inform ation about the external memory interface. 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 sfr address: sfr page: 0xe8 f bits7?0: p6mdout.[7:0]: port6 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. 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: sfr page: 0x9e f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 257 sfr definition 18.19. p7: port7 data sfr definition 18.20. p7mdou t: port7 output mode bits7?0: p7.[7:0]: port7 output latch bits. write - output appears on i/o pins. 0: logic low output. 1: logic high output (open-drain if corresponding p7mdout bit = 0). see sfr definition 18.20. read - returns states of i/o pins. 0: p7.n pin is logic low. 1: p7.n pin is logic high. note: p7.[7:0] can be driven by the external data memory interfac e (as ad[7:0] in multiplexed mode, or as d[7:0] in non-multiplexed mode). see section ?17. external data memory interface and on-chip xram? on page 219 for more information about the external memory interface. 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 sfr address: sfr page: 0xf8 f bits7?0: p7mdout.[7:0]: port7 output mode bits. 0: port pin output mode is configured as open-drain. 1: port pin output mode is configured as push-pull. 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: sfr page: 0x9f f c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 258 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 259 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 1.1, and compat ible with the i2c serial bus. reads and writes to the interface by the system controller are byte ori ented with the smbus0 interface autonomously control- ling the serial transfer of the data. a method of ext ending the clock-low duration is available to accommo- date devices with different spe ed 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 cl ock) generation and synchronization, arbitration logic, and start/stop control and generation. figure 19.1. smbus0 block diagram sfr bus data path control sfr bus write to smb0dat smbus control logic read smb0dat smb0adr s l v 6 g c s l v 5 s l v 4 s l v 3 s l v 2 s l v 1 s l v 0 c r o s s b a r clock divide logic sysclk smb0cr c r 7 c r 6 c r 5 c r 4 c r 3 c r 2 c r 1 c r 0 scl filter n sda control 0000000b 7 msbs 8 ab a=b 8 0 1 2 3 4 5 6 7 smb0dat 8 smb0cn s t a s i a a f t e t o e e n s m b b u s y s t o smb0sta s t a 4 s t a 3 s t a 2 s t a 1 s t a 0 scl control status generation arbitration scl synchronization scl generation (master mode) irq generation s t a 5 s t a 6 s t a 7 ab a=b smbus irq interrupt request port i/o 1 0 sda filter n 7 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 260 rev. 1.4 figure 19.2 shows a typical smbus co nfiguration. the smbus0 interface will work at any voltage between 3.0 and 5.0 v and different devices on the bus may ope rate 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 devi ce connected to the bus must have an open-drain or open-collector output for both the scl and sda lines, so that both are pulled high when the bus is free. the maximum number of devices on the bus is limited only by the requirement that the rise and fall times on the bus will not exceed 300 ns and 1000 ns, respectively. figure 19.2. typical smbus configuration 19.1. supporting documents it is assumed the reader is familiar with or has access to th e following suppo rting documents: 1. the i2c-bus and how to use it (includi ng specifications), philips semiconductor. 2. the i2c-bus specification -- version 2.0, philips semiconductor. 3. system management bus specification -- version 1.1, sbs implementers forum. 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 addres sed slave transmitter to a master receiver (read). the master device initiates both types of data transfer s 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 employ ed with a single master always winning the arbitra- tion. note that it is not necessary to specify one device as the master in a system; any device who trans- mits a start and a slave address beco mes 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 acknow ledged (ack) with a low sda during a high scl (see figure 19.3). if the receiving devic e does not ack, the tr ansmitting device will re ad a ?not acknowledge? (nack), which is a high sda during a high scl. the direction bit (r/w) occupies the least-significant bi t position of the address. the direction bit is set to logic 1 to indicate a "read" operation and clear ed to logic 0 to indicate a "write" operation. vdd = 5v master device slave device 1 slave device 2 vdd = 3v vdd = 5v vdd = 3v sda scl c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 261 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 transmit s the slave address and direction bit. if the trans- action is a write operation from th e master to the slave, the master transmits the data a byte at a time waiting for an ack from the slave at the end of each byte. for read operations , the slave transmits the data waiting for an ack from the master at the end of each byte. at the end of the data transfer, the master generates a stop condition to term inate the transaction an d free the bus. figure 19. 3 illustrates a typical smbus transaction. figure 19.3. smbus transaction 19.2.1. arbitration a master may start a transfer only if the bus is free. th e bus is free after a stop condition or after the scl and sda lines remain high for a specified time (see section 19.2.4 ). in the event that two or more devices attempt to begin a transfer at the same time, an arbi tration scheme is employed to force one master to give up the bus. the master devices continue transmitting until one attempts a high while the other transmits a low. since the bus is open- drain, the bus will be pulle d low. the master attempting the high will detect a low sda and give up the bus. the winning master co ntinues its transmission without interruption; the losing master becomes a slave and receives the rest of the transfer. this arbitration scheme is non- destructive: one device always wins, and no data is lost. 19.2.2. clock low extension smbus provides a clock synchronizati on mechanism, similar to i2c, wh ich allows devices with different speed capabilities to coexist on the bus. a clock-low extensio n is used during a transf er 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. 19.2.3. scl low timeout if the scl line is held low by a slave device on the bus, no further communication is possible. furthermore, the master cannot force the scl line high to correct th e error condition. to solve this problem, the smbus protocol specifies that devices participating in a tran sfer must detect any clock cycle held low longer than 25 ms as a ?timeout? condition. devices that have det ected the timeout condition must reset the communi- cation no later than 10 ms after detecting the timeout condition. 19.2.4. scl high (smbus free) timeout the smbus specification stipulates th at if the scl and sda lines remain high for more that 50 s, the bus is designated as free. if an smbus device is waitin g to generate a master st art, the start will be gen- erated following the bus free timeout. sla6 sda sla5-0 r/w d7 d6-0 scl slave address + r/w data byte start ack nack stop c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 262 rev. 1.4 19.3. smbus transfer modes the smbus0 interface may be configured to operate as a master and/or a slave. at any particular time, the interface will be operating in one of the following modes: master transmitter, master receiver, slave transmitter, or slave receiver. see table 19.1 for transfer mode status decoding using the smb0sta sta- tus register. the following mode de scriptions illustrate an interrupt-driven smbus0 application; smbus0 may alternatively be operated in polled mode. 19.3.1. master transmitter mode serial data is transmitted on sda while the serial clock is output on scl. smbus0 generates a start condition and then transmits the first byte containing the address of the target slave device and the data direction bit. in this case the data direction bit (r/w) will be logic 0 to indicate a "write" operation. the smbus0 interface transmits one or more bytes of serial data, waiting for an acknowledge (ack) from the slave after each byte. to indicate the end of the serial transfer, smbus0 generates a stop condition. figure 19.4. typical master transmitter sequence 19.3.2. master receiver mode serial data is received on sda while the serial cloc k is output on scl. the smbus0 interface generates a start followed by the first data byte containing the ad dress of the target slave and the data direction bit. in this case the data direction bi t (r/w) will be logic 1 to indicate a "read" operation. the smbus0 inter- face 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 t he state of the aa bit in register smb0cn. smbus0 generates a stop condition to indicate the end of the serial transfer. figure 19.5. typical mast er receiver sequence a a a s w p data byte data byte sla s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt data byte data byte a n a s r p sla s = start p = stop a = ack n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 263 19.3.3. slave transmitter mode serial data is transmitted on sda while the serial clo ck is received on scl. th e 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, th e smbus0 interface generate s an ack. smbus0 will also ack if the general call address (0x00) is received and the general call address enable bit (smb0adr.0) is set to logic 1. in this case the data direction bit (r/w) will be logic 1 to indicate a "read" operation. the smbus0 interface receives the clock on scl and transmits one or more bytes of serial data, waiting for an ack from the master after each byte. smbus0 exits slave mode after receiving a stop condition from the master. figure 19.6. typical slave transmitter sequence 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 addr ess and direction bit. if the received slave address matches the address held in regist er smb0adr, the interf ace generates an ack. smbus0 will also ack if the general call address (0x00) is received and the g eneral call address enable bit (smb0adr.0) is set to logic 1. in this case the data di rection bit (r/w) will be logic 0 to indicate a "write" operation. the smbus0 interface receives one or more bytes of seri al data; after each byte is received, the interface transmits an ack or nack depending on the state of the aa bit in smb0cn. smbus0 exits slave receiver mode after receiving a stop condition from the master. figure 19.7. typical sl ave receiver sequence p r sla s data byte data byte a n a s = start p = stop n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt p w sla s data byte data byte a a a s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupt interrupt interrupt interrupt c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 264 rev. 1.4 19.4. smbus special function registers the smbus0 serial interface is ac cessed and controlled through five sfr?s: smb0cn control register, smb0cr clock rate register, smb0adr address r egister, smb0dat data register and smb0sta sta- tus register. the five special function registers related to the operation of the smbus0 interface are described in the following sections. 19.4.1. control register the smbus0 control register smb0cn is used to conf igure and control the smbus0 interface. all of the bits in the register can be read or written by software. two of the control bits are also affected by the smbus0 hardware. the serial interrupt flag (si, smb0cn.3) is set to logic 1 by the hardware when a valid serial interrupt condition occurs. it can only be cleared by software. the stop flag (sto, smb0cn.4) is set to logic 1 by software. it is cleared to logic 0 by hardware when a stop condition is detected on the bus. setting the ensmb flag to logic 1 enables the smbus0 interface. clearing the ensmb flag to logic 0 dis- ables the smbus0 interface and removes it from the bus. momentarily clearing the ensmb flag and then resetting it to logic 1 will reset smbus0 communication . however, ensmb should not be used to tempo- rarily remove a device fr om the bus since the bus state informat ion will be lost. instead, the assert acknowledge (aa) flag should be used to temporarily remove the device from the bus (see description of aa flag below). setting the start flag (sta, smb0cn.5) to logic 1 will put smbus0 in a master mode. if the bus is free, smbus0 will generate a star t condition. if the bus is not free, smbu s0 waits for a stop condition to free the bus and then generates a start condition after a 5 s delay per the smb0cr value (in accordance with the smbus protocol, the smbus0 interface also considers the bus free if the bus is idle for 50 s and no stop condition was recognized). if sta is set to logic 1 while smbus0 is in master mode and one or more bytes ha ve been transferr ed, a repeated start cond ition will be generated. when the stop flag (sto, smb0cn.4) is set to logic 1 while the smbus0 interfac e is in master mode, the interface generates a stop condition. in a slave mode, the sto flag may be used to recover from an error condition. in this case, a stop condition is not generated on the bus, but the smbus hardware behaves as if a stop condition has been received and enters the "not addressed" slave receiver mode. note that this simulated stop will not cause th e bus to appear free to smbus0. th e bus will remain occupied until a stop appears on the bus or a bus free timeout occurs. hardware automatically clears the sto flag to logic 0 when a stop condition is detected on the bus. the serial interrupt flag (si, smb0cn.3) is set to logic 1 by hardware when the smbus0 interface enters one of 27 possible states. if interrupts are enabled fo r the smbus0 interface, an interrupt request is gener- ated when the si flag is set. the si flag must be cleared by software. important note: if si is set to logic 1 while the scl line is lo w, the clock-low period of the serial clock will be stretched and the serial transfer is suspended until si is cleared to logic 0. a high level on scl is not affected by the setting of the si flag. the assert acknowledge flag (aa, smb0cn.2) is used to set the level of the sda line during the acknowl- edge clock cycle on the scl line. sett ing the aa flag to logic 1 will caus e an ack (low level on sda) to be sent during the acknowledge cycle if the device ha s been addressed. setting the aa flag to logic 0 will cause a nack (high level on sda) to be sent during acknowledge cycle. after the transmission of a byte in slave mode, the slave can be temporarily removed from the bus by clearing the aa flag. the slave's own address and general ca ll address will be igno red. to resume oper ation on the bus, the aa flag must be reset to logic 1 to allow the slave's address to be recognized. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 265 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, time r 3 is used to detect scl low timeouts. if timer 3 is enabled (see section ?23.2. timer 2, timer 3, and timer 4? on page 317 ), timer 3 is forced to reload when scl is high, and forced to count when scl is low. with timer 3 enabled and configured to overflow after 25 ms (and toe set), a timer 3 overflow indicate s a scl low timeout; the timer 3 interrupt service routine can then be used to reset smbus0 commu nication in the event of an scl low timeout. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 266 rev. 1.4 sfr definition 19.1. smb0 cn: smbus0 control bit7: busy: busy status flag. 0: smbus0 is free 1: smbus0 is busy bit6: ensmb: smbus enable. this bit enables/disables the smbus serial interface. 0: smbus0 disabled. 1: smbus0 enabled. bit5: sta: smbus start flag. 0: no start condit ion is transmitted. 1: when operating as a master, a start conditi on is transmitted if the bus is free. (if the bus is not free, the start is transmitted after a stop is received.) if sta is set after one or more bytes have been transmitted or received and before a stop is received, a repeated start condition is transmitted. bit4: sto: smbus stop flag. 0: no stop condition is transmitted. 1: setting sto to logic 1 causes a stop condition to be transmitted. when a stop condi- tion is received, hardware clears sto to logic 0. if both sta and sto are set, a stop con- dition is transmitted followed by a start condition. in slave mode, setting the sto flag causes smbus to behave as if a stop condition was received. bit3: si: smbus seri al interrupt flag. this bit is set by hardware when one of 27 po ssible smbus0 states is entered. (status code 0xf8 does not cause si to be set.) when the si interrupt is enabled, se tting this bit causes the cpu to vector to the smbu s interrupt service routine. th is bit is not automatically cleared by hardware and must be cleared by software. bit2: aa: smbus assert acknowledge flag. this bit defines the type of acknowledge retu rned during the acknowledge cycle on the scl line. 0: a "not acknowledge" (high level on sda) is returned during the acknowledge cycle. 1: an "acknowledge" (low level on sda) is returned during the acknowledge cycle. bit1: fte: smbus free timer enable bit 0: no timeout when scl is high 1: timeout when scl high time exceeds limit specified by the smb0cr value. bit0: toe: smbus timeout enable bit 0: no timeout when scl is low. 1: timeout when scl low time exceeds limit specified by timer 3, if enabled. r r/wr/wr/wr/wr/wr/wr/wreset value busy ensmb sta sto si aa fte toe 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0xc0 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 267 19.4.2. clock rate register sfr definition 19.2. smb0 cr: smbus0 clock rate bits7?0: smb0cr.[7:0]: sm bus0 clock rate preset the smb0cr clock rate register controls the frequency of the serial clock scl in master mode. the 8-bit word stored in the smb0cr register preloads a dedicated 8-bit timer. the timer counts up, and when it rolls over to 0x00, the scl logic state toggles. the smb0cr setting should be bounded by the following equation , where smb0cr is the unsigned 8-bit value in register smb0cr, and sysclk is the system clock frequency in mhz: the resulting scl signal high and low times are given by the following equations, where sysclk is the system clock frequency in hz: using the same value of smb0cr from above, the bus free timeout period is given in the following equation: 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: sfr page: 0xcf 0 smb0 cr 288 0.85? sysclk 4 ------------- -------- - ? ?? ?? ? ? t low 4 256 smb 0 cr ? ?? ? sysclk ? t high 4258 smb0 cr ? ?? ? sysclk ? ns + ? t bft 10 4 256 smb0 cr ? ?? ? sysclk -------------------------------------------------------------- ?? c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 268 rev. 1.4 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 regist er 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 t he 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. sfr definition 19.3. smb0dat: smbus0 data 19.4.4. address register the smb0adr address register holds the slave addre ss for the smbus0 interface. in slave mode, the seven most-significant bits hold the 7-bit slave address. the least significant bit (bit0) is used to enable the recognition of the gene ral call address (0x0 0). if bit0 is set to logic 1, th e general call addre ss will be recog- nized. otherwise, the general call address is ignor ed. the contents of this register are ignored when smbus0 is operating in master mode. bits7?0: smb0dat: smbus0 data. the smb0dat register contains a byte of data to be transmitted on the smbus0 serial inter- face or a byte that has just been received on the smbus0 serial interface. the cpu can read from or write to this register whenever t he si serial interrupt flag (smb0cn.3) is set to logic 1. when the si flag is not set, the syste m may be in the process of shifting data and the cpu should not at tempt to access this register. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xc2 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 269 sfr definition 19.4. smb0adr: smbus0 address 19.4.5. status register the smb0sta status register holds an 8-bit status c ode indicating the current state of the smbus0 inter- face. there are 28 possible smbus0 states, each with a corresponding unique status code. the five most significant bits of the status code vary while the three least-significant bits of a valid status code are fixed at zero when si = ?1?. therefore, all po ssible status codes are multiples of eight. this facilitat es the use of sta- tus codes in software as an index used to branch to appropriate service routines (allowing 8 bytes of code to service the state or jump to a more extensive service routine). for the purposes of user software, the contents of the smb0sta register is only defined when the si flag is logic 1. software should ne ver write to the smb0sta register; doing so will yield indeterm inate results. the 28 smbus0 states, along with their correspo nding status codes, are given in table 1.1. sfr definition 19.5. smb0sta: smbus0 status bits7?1: slv6?slv0: smbus0 slave address. these bits are loaded with the 7-bit slave addr ess to which smbus0 w ill respond when oper- ating as a slave transmitter or slave receiver. slv6 is the most significant bit of the address and corresponds to the first bit of the address byte received. bit0: gc: general call address enable. this bit is used to enable general call address (0x00) recognition. 0: general call address is ignored. 1: general call address is recognized. r/wr/wr/wr/wr/wr/wr/wr/wreset value slv6 slv5 slv4 slv3 slv2 slv1 slv0 gc 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xc3 0 bits7?3: sta7?sta3: smbus0 status code. these bits contain the smbus0 status code. there are 28 possible status codes; each sta- tus code corresponds to a single smbus state. a valid status code is present in smb0sta when the si flag (smb0cn.3) is set to logic 1. the content of smb0sta is not defined when the si flag is logic 0. writing to the smb0st a register at any time will yield indeterminate results. bits2?0: sta2?sta0: the three least significant bi ts of smb0sta are always read as logic 0 when the si flag is logic 1. r/wr/wr/wr/wr/wr/wr/wr/wreset value sta7 sta6 sta5 sta4 sta3 sta2 sta1 sta0 11111000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xc1 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 270 rev. 1.4 table 19.1. smb0sta status codes and states mode status code smbus state typical action mt/ mr 0x08 start condition transmitted. load smb0dat with slave address + r/w. clear sta. 0x10 repeated start condition transmitted. load smb0dat with slave address + r/w. clear sta. master transmitter 0x18 slave address + w transmitted. ack received. load smb0dat with data to be transmit- ted. 0x20 slave address + w transmitted. nack received. acknowledge poll to retry. set sto + sta. 0x28 data byte transmitted. ack received. 1) load smb0dat with next byte, or 2) set sto, or 3) clear sto then set sta for repeated start. 0x30 data byte transmitted. nack received. 1) retry transfer or 2) set sto. 0x38 arbitration lost. save current data. master receiver 0x40 slave address + r transmitted. ack received. if only receiving one byte, clear aa (send nack after received byte). wait for received data. 0x48 slave address + r transmitted. nack received. acknowledge poll to retry. set sto + sta. 0x50 data byte received. ack transmitted. read smb0dat. wait for next byte. if next byte is last byte, clear aa. 0x58 data byte received. nack transmitted. set sto. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 271 slave receiver 0x60 own slave address + w received. ack trans- mitted. wait for data. 0x68 arbitration lost in sending sla + r/w as mas- ter. own address + w received. ack transmit- ted. save current data for retry when bus is free. wait for data. 0x70 general call address received. ack transmit- ted. wait for data. 0x78 arbitration lost in sending sla + r/w as mas- ter. general call address received. ack trans- mitted. save current data for retry when bus is free. 0x80 data byte received. ack transmitted. read smb0dat. wait for next byte or stop. 0x88 data byte received. nack transmitted. set sto to reset smbus. 0x90 data byte received after general call address. ack transmitted. read smb0dat. wait for next byte or stop. 0x98 data byte received after general call address. nack transmitted. set sto to reset smbus. 0xa0 stop or repeated start received. no action necessary. slave transmitter 0xa8 own address + r received. ack transmitted. load smb0dat with data to transmit. 0xb0 arbitration lost in transmitting sla + r/w as master. own address + r received. ack transmitted. save current data for retry when bus is free. load smb0dat with data to trans- mit. 0xb8 data byte transmitted. ack received. load smb0dat with data to transmit. 0xc0 data byte transmitted. na ck received. wait for stop. 0xc8 last data byte transmitted (aa=0). ack received. set sto to reset smbus. slave 0xd0 scl clock high timer per smb0cr timed out set sto to reset smbus. all 0x00 bus error (illegal start or stop) set sto to reset smbus. 0xf8 idle state does not set si. table 19.1. smb0sta status codes and states (continued) mode status code smbus state typical action c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 272 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 273 20. enhanced serial peri pheral interface (spi0) the enhanced serial peripheral interface (spi0) pr ovides access to a flexible, full-duplex synchronous serial bus. spi0 can operate as a master or slave devi ce in both 3-wire or 4-wire modes, and supports mul- tiple masters and slaves on a single spi bus. the slav e-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 gen- eral purpose port i/o pins can be used to se lect multiple slave dev ices in master mode. figure 20.1. spi block diagram sfr bus data path control sfr bus write spi0dat receive data buffer spi0dat 0 1 2 3 4 5 6 7 shift register spi control logic spi0ckr scr7 scr6 scr5 scr4 scr3 scr2 scr1 scr0 spi0cfg spi0cn pin interface control pin control logic c r o s s b a r port i/o read spi0dat spi irq tx data rx data sck mosi miso nss transmit data buffer clock divide logic sysclk ckpha ckpol slvsel nssmd1 nssmd0 spibsy msten nssin srmt rxbmt spif wcol modf rxovrn txbmt spien c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 274 rev. 1.4 20.1. signal descriptions the four signals used by spi0 (mosi, miso, sck, nss) are described below. 20.1.1. master out, slave in (mosi) the master-out, slave-in (mosi) signal is an output fr om a master device and an input to slave devices. it is used to serially transfer data from the master to th e slave. this signal is an output when spi0 is operat- ing as a master and an input when spi0 is operating as a slave. data is transferred most-significant bit first. when configured as a master, mosi is driven by the msb of the shift register in both 3- and 4-wire mode. 20.1.2. master in, slave out (miso) the master-in, slave-out (miso) signal is an output fr om a slave device and an input to the master device. it is used to serially transfer data from the slave to the master. this signal is an input when spi0 is operat- ing as a master and an output when spi0 is operating as a slave. data is transferred most-significant bit first. the miso pin is placed in a high-impedance st ate when the spi module is disabled and when the spi operates in 4-wire mode as a slave that is not selected. when acting as a slave in 3-wire mode, miso is always driven by the msb of the shift register. 20.1.3. serial clock (sck) the serial clock (sck) signal is an output from the ma ster device and an input to slave devices. it is used to synchronize the transfer of data between the mast er and slave on the mosi and miso lines. spi0 gen- erates this signal when operating as a master. the sck signal is ignored by a spi slave when the slave is not selected (nss = 1) in 4-wire slave mode. 20.1.4. slave select (nss) the function of the slave-select (nss) signal is dependent on the setting of the nssmd1 and nssmd0 bits in the spi0cn register. there are three possible modes that can be selected with these bits: 1. nssmd[1:0] = 00: 3-wire master or 3-wire slave mode: spi0 operates in 3-wire mode, and nss is disabled. when operating as a slave dev ice, spi0 is always selected in 3-wire mode. since no select signal is present, spi0 must be the only slave on the bus in 3-wire mode. this is intended for point-to-point communication between a master and one slave. 2. nssmd[1:0] = 01: 4-wire slave or multi-master mode: spi0 operates in 4-wire mode, and nss is enabled as an input. when operating as a slave, nss selects the spi0 device. when operating as a master, a 1-to-0 transition of the nss signal disables the master function of spi0 so that multiple master devices can be used on the same spi bus. 3. nssmd[1:0] = 1x: 4-wire master mode: spi0 o perates in 4-wire mode, and nss is enabled as an output. the setting of nssmd0 determines what logic level the nss pin will output. this configuration should only be used wh en operating spi0 as a master device. see figure 20.2, figure 20.3, and figure 20.4 for typica l connection diagrams of the various operational modes. note that the setting of nssmd bits affects the pinout of the device. when in 3-wire master or 3-wire slave mode, the nss pin will not be mapped by the crossbar. in all other modes, the nss signal will be mapped to a pin on the device. see section ? 18. port input/output ? on page 235 for general purpose port i/o and crossbar information. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 275 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 wh ile providing the serial clock on sck. th e 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 transf ers data to a slave on the mosi line, the addressed spi slave device simultaneously transfers the contents of its shift regist er 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 ma ster 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 gene rated (modf, spi0cn.5 = 1). mode fault w ill 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-mas- ter mode, slave devices can be addressed individua lly (if needed) using general-purpose i/o pins. figure 20.2 shows a connection diagram between two master devices in multiple-mas ter 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 is not mapped to an exte rnal 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 devic e in 3-wire master mode and a slave device. 4-wire single-master mode is active when nssmd1 (spi 0cn.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 n ssmd0 (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. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 276 rev. 1.4 figure 20.2. multiple-master mode connection diagram figure 20.3. 3-wire single master and slave mode connection diagram figure 20.4. 4-wire single master and slave mode connection diagram master device 2 master device 1 mosi miso sck miso mosi sck nss gpio nss gpio slave device master device mosi miso sck miso mosi sck slave device master device mosi miso sck miso mosi sck nss nss gpio slave device mosi miso sck nss c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 277 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 a nd out through the miso pin by a ma ster device controlling the sck sig- nal. a bit counter in the spi0 logic counts sck edges. when 8 bits have been shifted through the shift reg- ister, 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 double- buffered, 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 sh ift register already contains data, the spi will load the shift register wi th the transmit buffer?s contents af ter the last sck edge of the next (or current) spi transfer. 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 n ss. note that the nss sig- nal 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 (spi0c n.3) = 0 and nssmd0 (spi0cn.2) = 0. nss is not used in this mode, and is not 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. th e 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. 20.4. spi0 interrupt sources when spi0 interrupts are e nabled, the following four flags will ge nerate an interrupt when they are set to logic 1: note that all of the following bits must be cleared by software. 1. the spi interrupt flag, spif (spi0cn.7) is set to logic 1 at the end of each byte transfer. this flag can occur in all spi0 modes. 2. the write collision flag, wcol ( spi0cn.6) is set to logic 1 if a write to spi0dat is attempted when the transmit buffer has not been emptied to the spi shift register. when this occurs, the write to spi0dat will be ignored, and the transmi t buffer will not be writ ten.this flag can occur in all spi0 modes. 3. the mode fault flag modf (spi0cn.5) is set to logic 1 when spi0 is configured as a master, and for multi-master mode and the nss pin is pulled low. when a mode fault occurs, the msten and spien bits in spi0cn are set to logic 0 to disable spi0 and allow another master device to access the bus. 4. the receive overrun flag rxovrn (spi0cn.4) is set to logic 1 when configured as a slave, and a transfer is completed and the receive buffer still holds an unread byte from a previous transfer. the new byte is not transferred to the receive buffer, allowing the previously received data byte to be read. the data byte which caused the overrun is lost. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 278 rev. 1.4 20.5. serial clock timing 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 active-high or active-low clock. both master and slave devices must be config ured to use the same clock phase and polarity. spi0 should be disabled (by clearing the spien bit, spi0cn.0) when changing the clock phase or polarity. the clock and data line relationships for master mode are shown in figure 20.5. for slave mode, the clock and data relationships are shown in figure 20.6 and figure 2 0.7. note that ckpha must be set to ?0? on both the master and slave spi when communicating between two of the following devices: c8051f04x, c8051f06x, c8051f12x/13x, c8051f31x, c8051f32x, and c8051f33x the spi0 clock rate register (spi 0ckr) 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 or 12.5 mhz, whichever is slower. when the spi is configured as a sl ave, 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 synchrono usly with the slave?s 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 i ssues sck, nss, and the serial input data synchronously with the slave?s system clock. figure 20.5. master mode data/clock timing sck (ckpol=0, ckpha=0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=0) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso/mosi nss (must remain high in multi-master mode) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 279 figure 20.6. slave mode data/clock timing (ckpha = 0) figure 20.7. slave mode data/clock timing (ckpha = 1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi sck (ckpol=0, ckpha=0) sck (ckpol=1, ckpha=0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 280 rev. 1.4 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, spi0cf g 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 figures. sfr definition 20.1. spi0cf g: spi0 configuration bit 7: spibsy: spi busy (read only). this bit is set to logic 1 when a spi transf er is in progress (master or slave mode). bit 6: msten: master mode enable. 0: disable master mode. operate in slave mode. 1: enable master mode. operate as a master. bit 5: ckpha: spi0 clock phase. this bit controls the spi0 clock phase. 0: data centered on first edge of sck period.* 1: data centered on second edge of sck period.* bit 4: ckpol: spi0 clock polarity. this bit controls the spi0 clock polarity. 0: sck line low in idle state. 1: sck line high in idle state. bit 3: slvsel: slave selected flag (read only). this bit is set to logic 1 whenever the nss pin is low indicating spi0 is the selected slave. it is cleared to logic 0 when nss is high (slave not selected). this bit does not indicate the instantaneous value at the nss pin, but rather a de-glitched version of the pin input. bit 2: nssin: nss instantaneous pin input (read only). this bit mimics the instantaneous value that is present on the nss port pin at the time that the register is read. this input is not de-glitched. bit 1: srmt: shift register empty (valid in slave mode, read only). this bit will be set to logic 1 when all data has been transferred in/out of the shift register, and there is no new information available to read from the transmit buffer or write to the receive buffer. it returns to logic 0 when a data byte is transferred to the shift register from the transmit buffer or by a transition on sck. note: srmt = 1 when in master mode. bit 0: rxbmt: receive buffer empty (valid in slave mode, read only). this bit will be set to logic 1 when the receiv e buffer has be en read and contains no new information. if there is new information availabl e in the receive buffer that has not been read, this bit will return to logic 0. note: rxbmt = 1 when in master mode. *note: in slave mode, data on mosi is sampled in the center of each data bit. in master mode, data on miso is sampled one sysclk before the end of each data bit, to provide maximum settling time for the slav e device. see table 20.1 for timing parameters. r r/w r/w r/w r r r r reset value spibsy msten ckpha ckpol slvsel nssin srmt rxbmt 00000111 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x9a 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 281 sfr definition 20.2. spi0cn: spi0 control bit 7: spif: spi0 interrupt flag. this bit is set to logic 1 by hardware at the en d of a data transfer. if interrupts are enabled, setting this bit causes the cpu to vector to the spi0 interrupt service routine. this bit is not automatically cleared by hardware. it must be cleared by software. bit 6: wcol: write collision flag. this bit is set to logic 1 by hardware (and gene rates a spi0 interrupt) to indicate a write to the spi0 data register was attempted while a data transfer was in progress. it must be cleared by software. bit 5: modf: mode fault flag. this bit is set to logic 1 by hardware (and generates a spi0 interrupt) when a master mode collision is detected (nss is low, msten = 1, and nssmd[1:0] = 01). this bit is not auto- matically cleared by hardware. it must be cleared by software. bit 4: rxovrn: receive overrun flag (slave mode only). this bit is set to logic 1 by hardware (and generates a spi0 interrupt) when the receive buffer still holds unread da ta from a previous transfer and the la st bit of the current transfer is shifted into the spi0 shift register. this bit is not automatically cleare d by hardware. it must be cleared by software. bits 3?2: nssmd1?nssmd0: slave select mode. selects between the following nss operation modes: (see section ?20.2. spi0 master mode operation? on page 275 and section ?20.3. spi0 slave mode operation? on page 277 ). 00: 3-wire slave or 3-wire master mode. nss signal is not routed to a port pin. 01: 4-wire slave or multi-master mode (defau lt). nss is always an input to the device. 1x: 4-wire single-maste r mode. nss signal is mapped as an output from t he device and will assume the value of nssmd0. bit 1: txbmt: transmit buffer empty. this bit will be set to logic 0 when new data has been written to th e transmit buffer. when data in the transmit buffer is tr ansferred to the spi shift register, this bit will be set to logic 1, indicating that it is safe to writ e a new byte to the transmit buffer. bit 0: spien: spi0 enable. this bit enables/disables the spi. 0: spi disabled. 1: spi enabled. r/wr/wr/wr/wr/wr/w r r/wreset value spif wcol modf rxovrn nssmd1 nssmd0 txbmt spien 00000110 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 bit addressable sfr address: sfr page: 0xf8 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 282 rev. 1.4 sfr definition 20.3. spi0 ckr: spi0 clock rate sfr definition 20.4. spi0dat: spi0 data bits 7?0: scr7?scr0: spi0 clock rate. these bits determine the frequency of the sck output when the spi0 module is configured for master mode operation. the sck clock frequency is a divided version of the system clock, and is given in the following equation, where sysclk is the system clock frequency and spi0ckr is the 8-bit value held in the spi0ckr register. for 0 <= spi0ckr <= 255 example: if sysclk = 2 m hz and spi0ckr = 0x04, 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: sfr page: 0x9d 0 f sck sysclk 2 spi0ckr 1 + ?? ? f sck 2000000 241 + ?? ? f sck 200 khz = bits 7?0: spi0dat: spi0 transmit and receive data. the spi0dat register is used to transmit an d receive spi0 data. writing data to spi0dat places the data into the transmit buffer and initiates a transfer when in master mode. a read of spi0dat returns the contents of the receive buffer. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x9b 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 283 figure 20.8. spi master timing (ckpha = 0) figure 20.9. spi master timing (ckpha = 1) sck* t mckh t mckl mosi t mis miso * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mih sck* t mckh t mckl miso t mih mosi * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mis c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 284 rev. 1.4 figure 20.10. spi slave timing (ckpha = 0) figure 20.11. spi slave timing (ckpha = 1) sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t sez t sdz sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t slh t sez t sdz c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 285 table 20.1. spi slave timing parameters parameter description min max units master mode timing* (see figure 20.8 and figure 20.9) t mckh sck high time 1xt sysclk ns t mckl sck low time 1xt sysclk ns t mis miso valid to sck shift edge 1xt sysclk + 20 ns t mih sck shift edge to miso change 0 ns slave mode timing* (see figure 20.10 and figure 20.11) t se nss falling to first sck edge 2xt sysclk ns t sd last sck edge to nss rising 2xt sysclk ns t sez nss falling to miso valid 4xt sysclk ns t sdz nss rising to miso high-z 4xt sysclk ns t ckh sck high time 5xt sysclk ns t ckl sck low time 5xt sysclk ns t sis mosi valid to sck sample edge 2xt sysclk ns t sih sck sample edge to mosi change 2xt sysclk ns t soh sck shift edge to miso change 4xt sysclk ns t slh last sck edge to miso change (ckpha = 1 only) 6xt sysclk 8xt sysclk ns *note: t sysclk is equal to one period of the device system clock (sysclk). c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 286 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 287 21. uart0 uart0 is an enhanced serial port with frame erro r detection and address recognition hardware. uart0 may operate in full-duplex asynchronous or half-duplex synchronous modes, and mutiproccessor commu- nication 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 latc hed into the receive buffer before the previously received byte has been read. uart0 is accessed via its associated sfr?s, serial control (scon0) and serial data buffer (sbuf0). the single sbuf0 location provides access to both tr ansmit 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 soft- ware. this allows software to determine the cause of the uart0 interrupt (transmit complete or receive complete). figure 21.1. uart0 block diagram tx control tx clock tx irq zero detector send shift set qd clr stop bit gen. tb80 start data write to sbuf0 crossbar tx0 port i/o serial port (uart0) interrupt rx control start rx clock load sbuf 0x1ff shift en rx irq uart0 baud rate generation logic sfr bus input shift register (9 bits) frame error detection sbuf0 read sbuf0 sfr bus saddr0 saden0 match detect rb80 load sbuf0 crossbar rx0 sbuf0 address match scon0 s m 2 0 t b 8 0 r b 8 0 t i 0 r i 0 s m 1 0 s m 0 0 r e n 0 ssta0 t x c o l 0 s 0 t c l k 1 s 0 t c l k 1 s 0 r c l k 1 s 0 r c l k 1 r x o v 0 f e 0 s m o d 0 ti0 ri0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 288 rev. 1.4 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. 21.1.1. mode 0: synchronous mode mode 0 provides synchronous, half-duplex communication. serial data is transmitted and received on the rx0 pin. the tx0 pin provides the shift clock for both transmit and receive. the mcu must be the master since it generates the shift clock for transmission in both directions (see the interconnect diagram in figure 21.3). data transmission begins when an instruction writes a data byte to the sbuf0 register. eight data bits are transferred lsb first (see the timing diagram in figure 21.2), and the ti0 transmit interrupt flag (scon0.1) is set at the end of the eighth bit time. data reception begins when the ren0 receive enable bit (scon0.4) is set to logic 1 and the ri0 receive in terrupt flag (scon0.0) is cleared. one cycle after the eighth bit is shifted in, the ri0 flag is set and rece ption stops until software clears the ri0 bit. an inter- rupt will occur if enabled when either ti0 or ri0 are set. the mode 0 baud rate is sysclk / 12. rx0 is forced to open-drain in mo de 0, and an external pullup will typically be required. figure 21.2. uart0 mode 0 timing diagram figure 21.3. uart0 mode 0 interconnect table 21.1. uart0 modes mode synchronization baud clock data bits start/stop bits 0 synchronous sysclk / 12 8 none 1 asynchronous timer 1, 2, 3, or 4 overflow 8 1 start, 1 stop 2 asynchronous sysclk / 32 or sysclk / 64 9 1 start, 1 stop 3 asynchronous timer 1, 2, 3, or 4 overflow 9 1 start, 1 stop d1 d0 d2 d3 d4 d5 d6 d7 rx (data out) mode 0 transmit d0 mode 0 receive rx (data in) d1 d2 d3 d4 d5 d6 d7 tx (clk out) tx (clk out) shift reg. clk c8051fxxx rx tx data 8 extra outputs c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 289 21.1.2. mode 1: 8-bit uart, variable baud rate mode 1 provides standard asynchronous, full duplex communication using a total of 10 bits per data byte: one start bit, eight data bits (lsb first), and one stop bit. data are transmitted from the tx0 pin and received at the rx0 pin. on receive, the eight data bits are stored in sbuf0 and the stop bit goes into rb80 (scon0.2). data transmission begins when an instruction writes a data byte to the sbuf0 register. the ti0 transmit interrupt flag (scon0.1) is set at the end of the tran smission (the beginning of the stop-bit time). data reception can begin any time after the ren0 receive en able bit (scon0.4) is set to logic 1. after the stop bit is received, the data byte will be loaded into the sbuf0 receive register if the following conditions are met: ri0 must be logic 0, and if sm20 is logic 1, the stop bit must be logic 1. if these conditions are met, the eight bits of data is stored in sbuf0, the stop bit is stored in rb80 and the ri0 flag is set. if these conditions are not met, sbuf0 and rb80 will not be loaded and the ri0 flag will not be set. an interrupt will occur if enabled when ei ther ti0 or ri0 are set. figure 21.4. uart0 mode 1 timing diagram the baud rate generated in mode 1 is a function of timer overflow. uart0 can use timer 1 operating in 8- bit auto-reload mode , or timer 2, 3, or 4 operating in auto-reload mode to generate the baud rate (note that the tx and rx clocks are selected separately). on each timer overflow event (a rollover from all ones - (0xff for timer 1, 0xffff for timer 2, 3, or 4) - to zero) a clock is sent to the baud rate logic. timers 1, 2, 3, or 4 are selected as the baud rate source with bits in the ssta0 register (see sfr defini- tion 21.2). the transmit baud rate clock is selected using the s0tclk1 and s0tclk0 bits, and the receive baud rate clock is selected using the s0rclk1 and s0rclk0 bits. when timer 1 is selected as a baud rate source, the smod0 bit (ssta0.4) selects whether or not to divide the timer 1 overflow rate by two. on reset, the smod0 bit is logic 0, thus selecting the lower speed baud rate by default. the smod0 bit affects the baud rate generated by timer 1 as shown in equation 21.1. the mode 1 baud rate equations are shown below, wher e t1m is bit4 of register ckcon, th1 is the 8-bit reload register for timer 1, and [rcapnh , rcapnl] is the 16-bit reload register for timer 2, 3, or 4. d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space equation 21.1. mode 1 baud rate using timer 1 mode1_baudrate 1 32 ? timer1_overflowrate ? = when smod0 = 0: mode1_baudrate 1 16 ? timer1_overflowrate ? = when smod0 = 1: c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 290 rev. 1.4 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 309 . the timer 1 overflow rate is calculated as shown in equation 21.2. when timers 2, 3, or 4 are selected as a baud rate source, the baud rate is generated as shown in equation 21.3. the overflow rate for timer 2, 3, or 4 is determin ed by the clock source for the timer (tnclk) and the 16- bit reload value stored in the rcapn register (n = 2, 3, or 4), as shown in equation 21.4. equation 21.2. timer 1 overflow rate timer1_overflowrate t1clk 256 th1 ? ?? ? = equation 21.3. mode 1 baud rate using timer 2, 3, or 4 mode1_baudrate 1 16 ? timer234_overflowrate ? = equation 21.4. timer 2, 3, or 4 overflow rate timer234_overflowrate tnclk 65536 rcapn? ?? ? = c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 291 21.1.3. mode 2: 9-bit uart, fixed baud rate mode 2 provides asynchronous, full-duplex communicatio n using a total of eleven bits per data byte: a start bit, 8 data bits (lsb first), a programmable ninth da ta 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 tran smission (the beginning of the stop-bit time). data reception can begin any time after the ren0 receive en able bit (scon0.4) is set to logic 1. after the stop bit is received, the data byte will be loaded into the sbuf0 receive regist er if ri0 is logi c 0 and one of the following requirements are met: 1. sm20 is logic 0 2. sm20 is logic 1, the received 9th bit is l ogic 1, and the received ad dress 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. figure 21.5. uart0 modes 2 and 3 timing diagram equation 21.5. mode 2 baud rate baudrate 2 smod0 sysclk 64 --------------------- - ?? ?? ? = d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space d8 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 292 rev. 1.4 figure 21.6. uart0 modes 1, 2, and 3 interconnect diagram 21.1.4. mode 3: 9-bit uart, variable baud rate mode 3 uses the mode 2 transmission protocol with the mode 1 baud rate generation. mode 3 operation transmits 11 bits: a start bit, 8 data bits (lsb first), a programmable ninth data bit, and a stop bit. the baud rate is derived from timer 1 or timer 2, 3, or 4 overflows, as defined by equation 21.1 and equation 21.3. multiprocessor communications and hardware address recognition are supported, as described in section 21.2 . or rs-232 c8051fxxx rs-232 level xltr tx rx c8051fxxx rx tx mcu rx tx c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 293 21.2. multiprocessor communications modes 2 and 3 support multiprocessor communication between a master processor and one or more slave processors by special use of the ninth data bit and the built-in uart0 address recognition hardware. when a master processor wants to transmit to one or more sl aves, it first sends an address byte to select the tar- get(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. uart0 w ill recognize as ?valid? (i.e., capable of causing an interrupt) two types of addresses: (1) a masked address and (2) a broadcast address at any given time . both are described below. 21.2.1. configuration of a masked address the uart0 address is configured via two sfr?s: sad dr0 (serial address) and saden0 (serial address enable). saden0 sets the bit mask for the address he ld in saddr0: bits set to logic 1 in saden0 corre- spond to bits in saddr0 that are checked against the received address byte; bits set to logic 0 in saden0 correspond to ?don?t care? bits in saddr0. setting the sm20 bit (scon0.5) configures uart0 such that when a stop bit is received, uart0 will gen- erate an interrupt only if the ninth bit is logic 1 (r b80 = ?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. 21.2.2. broadcast addressing multiple addresses can be assigned to a single sl ave and/or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. the broadcast address is the logical or of registers saddr0 and saden0, and ?0?s of the result are treated as ?don?t cares?. typically a broadcast address of 0xff (hex adecimal) is acknowledged by all slaves, assuming ?don?t care? bits as ?1?s. 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 trans- mission between the original master and slave(s).. note in the above examples 4, 5, and 6, each slave would recognize as ?valid? an address of 0xff as a broadcast address. also note that examples 4, 5, and 6 uses the same saddr0 and saden0 register values as shown in the examples 1, 2, and 3 respec tively (slaves #1, 2, and 3). thus, a master could address each slave device individually using a masked address, and also broadcast to all three slave devices. for example, if a master were to send an address ?11110101?, only slave #1 would recognize the address as valid. if a master were to then send an address of ?11111111?, all three slave devices would rec- ognize the address as a valid broadcast address. example 1, slave #1 example 2, slave #2 example 3, slave #3 saddr0 = 00110101 saddr0 = 00110101 saddr0 = 00110101 saden0 = 00001111 saden0 = 11110011 saden0 = 11000000 uart0 address = xxxx0101 uart0 addres s = 0011xx01 uart0 address = 00xxxxxx example 4, slave #1 example 5, slave #2 example 6, slave #3 saddr0 = 00110101 saddr0 = 00110101 saddr0 = 00110101 saden0 = 00001111 saden0 = 11110011 saden0 = 11000000 broadcast address = 00111111 broadcast address = 11110111 broadcast address = 11110101 where all zeroes in the broadcast address are don?t cares. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 294 rev. 1.4 figure 21.7. uart multi-processor mode interconnect diagram 21.3. frame and transmi ssion error detection all modes: the transmit collision bit (txcol0 bit in register ssta 0) reads ?1? if user soft ware writes data to the sbuf0 register while a transmit is in progress. modes 1, 2, and 3: the receive overrun bit (rxov0 in register ssta0) reads ?1? if a new data byte is latched into the receive buffer before software has read the previous byte. the frame error bit (fe0 in register ssta0) reads ?1? if an invalid (low) stop bit is detected. master device slave device tx rx rx tx slave device rx tx slave device rx tx +5v c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 295 table 21.2. oscillator frequenc ies for standard baud rates system clock frequency (mhz) divide factor timer 1 reload value 1 timer2,3,or 4 reload value resulting baud rate (hz) 2 100.0 864 0xca 0xffca 115200 (115741) 99.5328 864 0xca 0xffca 115200 50.0 432 0xe5 0xffe5 115200 (115741) 49.7664 432 0xe5 0xffe5 115200 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 100.0 3472 0x27 0xff27 28800 (28802) 99.5328 3456 0x28 0xff28 28800 50.0 1744 0x93 0xff93 28800 (28670) 49.7664 1728 0x94 0xff94 28800 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 100.0 10416 - 0xfd75 9600 (9601) 99.5328 10368 - 0xfd78 9600 50.0 5216 - 0xfeba 9600 (9586) 49.7664 5184 - 0xfebc 9600 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. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 296 rev. 1.4 sfr definition 21.1. scon0: uart0 control bits7?6: sm00?sm10: serial port operation mode: write: when written, these bits select the se rial port operation mode as follows: reading these bits returns the current uart0 mode as defined above. bit5: sm20: multiprocesso r 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. bit4: ren0: receive enable. this bit enables/disables the uart0 receiver. 0: uart0 reception disabled. 1: uart0 reception enabled. bit3: tb80: ninth transmission bit. the logic level of this bit will be assigned to th e ninth transmissi on bit in modes 2 and 3. it is not used in modes 0 and 1. set or cleared by software as required. bit2: rb80: ninth receive bit. the bit is assigned the logic level of the ninth bit received in modes 2 and 3. in mode 1, if sm20 is logic 0, rb80 is assigned the logic level of the received stop bit. rb8 is not used in mode 0. bit1: ti0: transmit interrupt flag. set by hardware when a byte of data has been transmitted by uart0 (after the 8th bit in mode 0, or at the beginning of the stop bit in other modes). when the uart0 interrupt is enabled, setting this bit causes the cpu to ve ctor to the uart0 interrupt service routine. this bit must be cleared manually by software bit0: ri0: receive interrupt flag. set by hardware when a byte of data has been received by uart0 (as selected by the sm20 bit). when the uart0 interrupt is enabled, setting this bit causes the cpu to vector to the uart0 interrupt service routine. this bit must be cleared manually by software. 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 bit addressable sfr address: sfr page: 0x98 0 sm00 sm10 mode 0 0 mode 0: synchronous mode 0 1 mode 1: 8-bit uart, variable baud rate 1 0 mode 2: 9-bit uart, fixed baud rate 1 1 mode 3: 9-bit uart, variable baud rate c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 297 sfr definition 21.2. ssta0: uart0 status and clock selection bit7: fe0: frame error flag.* this flag indicates if an invalid (low) stop bit is detected. 0: frame error has not been detected 1: frame error has been detected. bit6: rxov0: receive overrun flag.* this flag indicates new data has been latched into the receive buffer before software has read the previous byte. 0: receive overrun has not been detected. 1: receive overrun has been detected. bit5: txcol0: transm it collision flag.* this flag indicates user software has written to the sbuf0 register while a transmission is in progress. 0: transmission collision has not been detected. 1: transmission collisio n has been detected. bit4: smod0: uart0 baud rate doubler enable. this bit enables/disables the divide-by-two func tion of the uart0 baud rate logic for config- urations described in the uart0 section. 0: uart0 baud rate divide-by-two enabled. 1: uart0 baud rate divide-by-two disabled. bits3?2: uart0 transmit baud rate clock selection bits . bits1?0: uart0 receive baud rate clock selection bits *note: fe0, rxov0, and txcol0 are flags only, and no interrupt is generated by these conditions. r/w r/w r/w r/w r/w r/w r/w r/w reset value fe0 rxov0 txcol0 smod0 s0tclk1 s0 tclk0 s0rclk1 s0rclk0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x91 0 s0tclk1 s0tclk0 serial transmit baud rate clock source 0 0 timer 1 generates uart0 tx baud rate 0 1 timer 2 overflow generates uart0 tx baud rate 1 0 timer 3 overflow generates uart0 tx baud rate 1 1 timer 4 overflow generates uart0 tx baud rate s0rclk1 s0rclk0 serial receive baud rate clock source 0 0 timer 1 generates uart0 rx baud rate 0 1 timer 2 overflow generates uart0 rx baud rate 1 0 timer 3 overflow generates uart0 rx baud rate 1 1 timer 4 overflow generates uart0 rx baud rate c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 298 rev. 1.4 sfr definition 21.3. sbuf 0: uart0 data buffer sfr definition 21.4. sad dr0: uart0 slave address sfr definition 21.5. saden0: uart0 slave address enable bits7?0: sbuf0.[7:0]: uart0 buffer bits 7?0 (msb?lsb) this is actually two registers; a transmit an d a receive buffer register. when data is moved to sbuf0, it goes to the transmit buffer and is held for serial transmission. moving a byte to sbuf0 is what initiates the transmission. when data is moved from sbuf0, it comes from the receive buffer. 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: sfr page: 0x99 0 bits7?0: saddr0.[7:0]: uart0 slave address the contents of this register are used to define the uart0 slave address. register saden0 is a bit mask to determine which bits of sa ddr0 are checked against a received address: corresponding bits set to logic 1 in saden0 are checked; corresponding bits set to logic 0 are ?don?t cares?. 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: sfr page: 0xa9 0 bits7?0: saden0.[7:0]: ua rt0 slave address enable bits in this register enable corresponding bits in register saddr0 to determine the uart0 slave address. 0: corresponding bit in saddr0 is a ?don?t care?. 1: corresponding bit in saddr0 is checked against a received address. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xb9 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 299 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 300 ). 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 regist er 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 re gister; 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 inte rrupt service routine. they must be cleared manually by software, allowing software to determine the cause of the uart1 interrupt (transmit complete or receive complete). figure 22.1. uart1 block diagram uart1 baud rate generator ri1 scon1 ri1 ti1 rb81 tb81 ren1 mce1 s1mode tx control tx clock send sbuf1 (tx shift) start data write to sbuf1 crossbar tx1 shift zero detector tx irq set qd clr stop bit tb81 sfr bus serial port interrupt ti1 port i/o rx control start rx clock load sbuf1 shift 0x1ff rb81 rx irq input shift register (9 bits) load sbuf1 read sbuf1 sfr bus crossbar rx1 sbuf1 (rx latch) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 300 rev. 1.4 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 user- accessible. 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. figure 22.2. uart1 baud rate logic timer 1 should be configured for mode 2, 8-bit auto-reload (see section ?23.1.3. mode 2: 8-bit counter/ timer with auto-reload? on page 311 ). the timer 1 reload value should be set so that overflows will occur at two times the desired baud rate. note that timer 1 may be clocked by one of five sources: sys- clk, sysclk / 4, sysclk / 12, sysclk / 48, or the external oscillator clock / 8. for any given timer 1 clock source, the uart1 baud rate is determined by equation 22.1. where t1 clk is the frequency of the clock supplied to timer 1, and t1h is the high byte of timer 1 (reload value). timer 1 clock frequency is selected as described in section ?23.1. timer 0 and timer 1? on page 309 . a quick reference for typical baud rates and s ystem clock frequencies is given in table 22.1 through table 22.5. note th at the internal oscillator or pll may still generate th e system clock when the external oscillator is driving timer 1 (see section ?23.1. timer 0 and timer 1? on page 309 for more details). rx timer start detected overflow overflow th1 tl1 tx clock 2 rx clock 2 timer 1 uart1 equation 22.1. uart1 baud rate uartbaudrate t 1 clk 256 t 1 h ? ?? ? c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 301 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. figure 22.3. uart inte rconnect diagram 22.2.1. 8-bit uart 8-bit uart mode uses a total of 10 bits per data byte: one start bit, eight data bits (lsb first), and one stop bit. data are transmitted lsb first from the tx1 pin and received at the rx1 pin. on receive, the eight data bits are stored in sbuf1 and the stop bit goes into rb81 (scon1.2). data transmission begins when softwa re writes a data byte to the sbuf 1 register. the ti1 transmit inter- rupt flag (scon1.1) is set at the end of the transmi ssion (the beginning of the stop-bit time). data recep- tion can begin any time after the ren1 receive enable bit (scon1.4) is set to logic 1. after the stop bit is received, the data byte w ill be loaded into the sbuf1 re ceive register if the following conditions are met: ri1 must be logic 0, and if mce1 is logic 1, the stop bi t must be logic 1. in the event of a receive data over- run, the first received 8 bits are latched into the sbuf1 receive register and the following overrun data bits are lost. if these conditions are met, the eight bits of data is stored in sbuf1, the stop bit is stored in rb81 and the ri1 flag is set. if these conditions are not met, sbuf1 and rb81 will not be loaded and the ri1 flag will not be set. an interrupt will occur if enabled when ei ther ti1 or ri1 is set. figure 22.4. 8-bit uart timing diagram or rs-232 c8051fxxx rs-232 level xltr tx rx c8051fxxx rx tx mcu rx tx d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 302 rev. 1.4 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 programma- ble ninth data bit, and a stop bit. the state of the nint h transmit data bit is determ ined 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 reg- ister 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 tran smission (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 da ta byte will be loaded into th e sbuf1 receive register if th e following cond itions 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 co nditions 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 w ill not be set to ?1?. a ua rt1 interrupt will occur if enabled when either ti1 or ri1 is set to ?1?. figure 22.5. 9-bit uart timing diagram d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space d8 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 303 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 (scon.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 sl ave 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 transmissi ons or a protocol can be implemented such that the master/slave role is temporarily re versed to enable half-duplex transmission between the original master and slave(s). figure 22.6. uart multi-processor mode interconnect diagram master device slave device tx rx rx tx slave device rx tx slave device rx tx +5v c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 304 rev. 1.4 sfr definition 22.1. scon1: serial port 1 control bit7: s1mode: serial port 1 operation mode. this bit selects the uart1 operation mode. 0: mode 0: 8-bit uart with variable baud rate 1: mode 1: 9-bit uart with variable baud rate bit6: unused. read = 1b . write = don?t care. bit5: mce1: multiprocessor communication enable. the function of this bit is dependent on the serial port 0 operation mode. mode 0: checks for valid stop bit. 0: logic level of stop bit is ignored. 1: ri1 will only be activated if stop bit is logic level 1. mode 1: multiprocessor communications enable. 0: logic level of ninth bit is ignored. 1: ri1 is set and an interrupt is generated only when the ninth bit is logic 1. bit4: ren1: receive enable. this bit enables/disables the uart receiver. 0: uart1 reception disabled. 1: uart1 reception enabled. bit3: tb81: ninth transmission bit. the logic level of this bit will be assigned to t he ninth transmission bit in 9-bit uart mode. it is not used in 8-bit uart mode. set or cleared by software as required. bit2: rb81: ninth receive bit. rb81 is assigned the value of the stop bit in mode 0; it is assigned the value of the 9th data bit in mode 1. bit1: ti1: transmit interrupt flag. set by hardware when a byte of data has been transmitted by uart1 (after the 8th bit in 8- bit uart mode, or at the beginning of the stop bit in 9-bit uart mode). when the uart1 interrupt is enabled, setting this bit causes the cpu to vector to the uart1 interrupt service routine. this bit must be cleared manually by software bit0: ri1: receive interrupt flag. set to ?1? by hardware when a byte of data has been received by uart1 (set at the stop bit sampling time). when the uart1 interrupt is enab led, setting this bit to ?1? causes the cpu to vector to the uart1 interrup t service routine. this bit must be cleared manually by soft- ware. 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 sfr address: sfr page: 0x98 1 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 305 sfr definition 22.2. sbuf1: seri al (uart1) port data buffer table 22.1. timer settings for standard baud rates using the internal 24.5 mhz oscillator frequency: 24.5 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1-sca0 (pre-scale select)* t1m* timer 1 reload value (hex) sysclk from internal osc. 230400 -0.32% 106 sysclk xx 1 0xcb 115200 -0.32% 212 sysclk xx 1 0x96 57600 0.15% 426 sysclk xx 1 0x2b 28800 -0.32% 848 sysclk / 4 01 0 0x96 14400 0.15% 1704 sysclk / 12 00 0 0xb9 9600 -0.32% 2544 sysclk / 12 00 0 0x96 2400 -0.32% 10176 sysc lk / 48 10 0 0x96 1200 0.15% 20448 sysclk / 48 10 0 0x2b x=don?t care *note: sca1-sca0 and t1m bit definitions can be found in section 23.1 . bits7?0: sbuf1[7:0]: serial data buffer bits 7-0 (msb-lsb) this sfr accesses two registers; a transmit shif t register and a receive latch register. when data is written to sbuf1, it goes to the transmit shift register and is he ld for serial transmis- sion. writing a byte to sbuf1 is what initiates the transmission. a read of sbuf1 returns the contents of the receive latch. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x99 1 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 306 rev. 1.4 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 oscilla- tor divide factor timer clock source sca1-sca0 (pre-scale select)* t1m* timer 1 reload value (hex) sysclk from external osc. 230400 -0.47% 108 sysclk xx 1 0xca 115200 0.45% 218 sysclk xx 1 0x93 57600 -0.01% 434 sysclk xx 1 0x27 28800 0.45% 872 sysclk / 4 01 0 0x93 14400 -0.01% 1736 sysclk / 4 01 0 0x27 9600 0.15% 2608 extclk / 8 11 0 0x5d 2400 0.45% 10464 sysclk / 48 10 0 0x93 1200 -0.01% 20832 sysclk / 48 10 0 0x27 sysclk from internal osc. 57600 -0.47% 432 extclk / 8 11 0 0xe5 28800 -0.47% 864 extclk / 8 11 0 0xca 14400 0.45% 1744 extclk / 8 11 0 0x93 9600 0.15% 2608 extclk / 8 11 0 0x5d x = don?t care *note: sca1-sca0 and t1m bit definitions can be found in section 23.1 . table 22.3. timer settings for standard ba ud rates using an external 22.1184 mhz oscillator frequency: 22.1184 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1-sca0 (pre-scale select)* t1m* timer 1 reload value (hex) sysclk from external osc. 230400 0.00% 96 sysclk xx 1 0xd0 115200 0.00% 192 sysclk xx 1 0xa0 57600 0.00% 384 sysclk xx 1 0x40 28800 0.00% 768 sysclk / 12 00 0 0xe0 14400 0.00% 1536 sysclk / 12 00 0 0xc0 9600 0.00% 2304 sysclk / 12 00 0 0xa0 2400 0.00% 9216 sysclk / 48 10 0 0xa0 1200 0.00% 18432 sysc lk / 48 10 0 0x40 sysclk from internal osc. 230400 0.00% 96 extclk / 8 11 0 0xfa 115200 0.00% 192 extclk / 8 11 0 0xf4 57600 0.00% 384 extclk / 8 11 0 0xe8 28800 0.00% 768 extclk / 8 11 0 0xd0 14400 0.00% 1536 extclk / 8 11 0 0xa0 9600 0.00% 2304 extclk / 8 11 0 0x70 x = don?t care *note: sca1-sca0 and t1m bit definitions can be found in section 23.1 . c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 307 table 22.4. timer settings for standard baud rates using the pll frequency: 50.0 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1-sca0 (pre-scale select)* t1m* timer 1 reload value (hex) 230400 0.45% 218 sysclk xx 1 0x93 115200 -0.01% 434 sysclk xx 1 0x27 57600 0.45% 872 sysclk / 4 01 0 0x93 28800 -0.01% 1736 sysclk / 4 01 0 0x27 14400 0.22% 3480 sysclk / 12 00 0 0x6f 9600 -0.01% 5208 sysclk / 12 00 0 0x27 2400 -0.01% 20832 sysc lk / 48 10 0 0x27 x=don?t care *note: sca1-sca0 and t1m bit definitions can be found in section 23.1 . table 22.5. timer settings for standard baud rates using the pll frequency: 100.0 mhz target baud rate (bps) baud rate % error oscilla- tor divide factor timer clock source sca1-sca0 (pre-scale select)* t1m* timer 1 reload value (hex) 230400 -0.01% 434 sysclk xx 1 0x27 115200 0.45% 872 sysclk / 4 01 0 0x93 57600 -0.01% 1736 sysclk / 4 01 0 0x27 28800 0.22% 3480 sysclk / 12 00 0 0x6f 14400 -0.47% 6912 sysclk / 48 10 0 0xb8 9600 0.45% 10464 sysclk / 48 10 0 0x93 x = don?t care *note: sca1-sca0 and t1m bit definitions can be found in section 23.1 . c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 308 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 309 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/tim- ers for use with the adcs, 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 primar y modes of operation. timer 3 offers 16-bit auto- reload and capture. timers 2 and 4 are identical, and of fer 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. timers 0 and 1 may be clocked by one of five sources, determined by the timer mode select bits (t1m- t0m) and the clock scale bits (sca1-sca0). the cl ock 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). timers 0 and 1 can be configured to use either the pre-scaled clock signal or the system clock directly. timers 2, 3, and 4 may be clocked by the system cl ock, 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 counte rs. 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 fu ll system clock cycles to en sure the leve l is properly sampled. 23.1. timer 0 and timer 1 each timer is implemented as a 16-bit register ac cessed as two separate 8-bit sfrs: a low byte (tl0 or tl1) and a high byte (th0 or th1). the counter/time r control register (tcon) is used to enable timer 0 and timer 1 as well as indicate their status. timer 0 interrupts can be enabled by setting the et0 bit in the ie register ( section ?11.3.5. interrupt register descriptions? on page 157 ); timer 1 interrupts can be enabled by setting the et1 bit in the ie register ( section 11.3.5 ). both counter/timers operate in one of four primary modes selected by setting the mode sele ct bits t1m1?t0m0 in the counter/timer mode reg- ister (tmod). both timers can be configured independently. 23.1.1. mode 0: 13-bit counter/timer timer 0 and timer 1 operate as 13-bit counter/timers in mode 0. the following describes the configuration and operation of timer 0. however, both timers oper ate identically, and timer 1 is configured in the same manner as described for timer 0. the th0 register holds the eight msbs of the 13-bit c ounter/timer. tl0 holds the five lsbs in bit positions tl0.4?tl0.0. the three upper bits of tl0 (tl0.7?tl0.5) are indeterminate and should be masked out or ignored when reading the tl0 register. as the 13-bit timer register increments and overflows from 0x1fff (all ones) to 0x0000, the ti mer overflow flag tf0 (tcon.5) is set and an interrupt will occur if timer 0 inter- rupts are enabled. timer 0 and timer 1 modes: timer 2, 3 and 4 modes: 13-bit counter/timer 16-bit co unter/timer with auto-reload 16-bit counter/timer 16-bit counter/timer with capture 8-bit counter/timer with auto-reload toggle output (timer 2 and 4 only) two 8-bit counter/timers (timer 0 only) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 310 rev. 1.4 the c/t0 bit (tmod.2) selects the counter/timer's cloc k 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 ?18.1. ports 0 through 3 and the priority crossbar decoder? on page 238 for information on selecting and configuring external i/o pins). clearing c/t sele cts the clock defined by the t0m bit (ckcon.3). when t0m is set, timer 0 is clocked by th e system clock. when t0m is clear ed, 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 ?11.3.5. interrupt register descriptions? on page 157 ), facilitating pulse width mea- surements. 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. figure 23.1. t0 mode 0 block diagram tr0 gate0 /int0 counter/timer 0 x x disabled 1 0 x enabled 110disabled 111enabled x = don't care tclk tl0 (5 bits) th0 (8 bits) tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tr0 0 1 0 1 sysclk pre-scaled clock ckcon s c a 0 s c a 1 t 1 m t 0 m tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 gate0 /int0 t0 crossbar c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 311 23.1.2. mode 1: 16-bit counter/timer mode 1 operation is the same as mode 0, except that the counter/timer registers use all 16 bits. the coun- ter/timers are enabled and configured in mode 1 in the same manner as for mode 0. 23.1.3. mode 2: 8-bit counter/timer with auto-reload mode 2 configures timer 0 or 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 relo ad value in th0 is not changed. tl0 must be initialized to the desired value before enabling the timer for the first count to be cor- rect. 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 . figure 23.2. t0 mode 2 block diagram tclk tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tl0 (8 bits) reload th0 (8 bits) 0 1 0 1 sysclk pre-scaled clock ckcon s c a 0 s c a 1 t 1 m t 0 m tr0 gate0 /int0 t0 crossbar c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 312 rev. 1.4 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 cl ock 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 over flow flag tf1 on overflow and thus controls the timer 1 interrupt. timer 1 is inactive in mode 3. when timer 0 is operat ing 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 set- tings. 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. figure 23.3. t0 mode 3 block diagram tl0 (8 bits) tmod 0 1 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt interrupt 0 1 sysclk pre-scaled clock tr1 th0 (8 bits) ckcon s c a 0 s c a 1 t 1 m t 0 m t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tr0 gate0 /int0 t0 crossbar c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 313 sfr definition 23.1. tcon: timer control bit7: tf1: timer 1 overflow flag. set by hardware when timer 1 overflows. this flag can be cleared by software but is auto- matically cleared when the cpu vectors to the timer 1 interrupt service routine. 0: no timer 1 overflow detected. 1: timer 1 has overflowed. bit6: tr1: timer 1 run control. 0: timer 1 disabled. 1: timer 1 enabled. bit5: tf0: timer 0 overflow flag. set by hardware when timer 0 overflows. this flag can be cleared by software but is auto- matically cleared when the cpu vectors to the timer 0 interrupt service routine. 0: no timer 0 overflow detected. 1: timer 0 has overflowed. bit4: tr0: timer 0 run control. 0: timer 0 disabled. 1: timer 0 enabled. bit3: ie1: external interrupt 1. this flag is set by hardware when an edge/level of type defined by it1 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external inter- rupt 1 service routine if it1 = 1. this flag is the inverse of the /int1 signal. bit2: it1: interrupt 1 type select. this bit selects whether the configured /int1 interrupt w ill be falling-edge sensitive or active-low. 0: /int1 is level triggered, active-low. 1: /int1 is edge tr iggered, falling-edge. bit1: ie0: external interrupt 0. this flag is set by hardware when an edge/level of type defined by it0 is detected. it can be cleared by software but is automatically cleared when the cpu vectors to the external inter- rupt 0 service routine if it0 = 1. this flag is the inverse of the /int0 signal. bit0: it0: interrupt 0 type select. this bit selects whether the configured /int0 interrupt w ill be falling-edge sensitive or active-low. 0: /int0 is level trigge red, active logic-low. 1: /int0 is edge tr iggered, falling-edge. 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 sfr address: sfr page: 0x88 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 314 rev. 1.4 sfr definition 23.2. tmod: timer mode bit7: gate1: timer 1 gate control. 0: timer 1 enabled when tr1 = 1 irrespective of /int1 logic level. 1: timer 1 enabled only when tr1 = 1 and /int1 = logic 1. bit6: c/t1: counter/timer 1 select. 0: timer function: timer 1 incremented by clock defined by t1m bit (ckcon.4). 1: counter function: timer 1 incremented by high-to-low transitions on external input pin (t1). bits5?4: t1m1?t1m0: timer 1 mode select. these bits select the timer 1 operation mode. bit3: gate0: timer 0 gate control. 0: timer 0 enabled when tr0 = 1 irrespective of /int0 logic level. 1: timer 0 enabled only when tr0 = 1 and /int0 = logic 1. bit2: c/t0: counter/timer select. 0: timer function: timer 0 incremented by clock defined by t0m bit (ckcon.3). 1: counter function: timer 0 incremented by high-to-low transitions on external input pin (t0). bits1?0: t0m1?t0m0: timer 0 mode select. these bits select the timer 0 operation mode. r/wr/wr/wr/wr/wr/wr/wr/wreset value gate1 c/t1 t1m1 t1m0 gate0 c/t0 t0m1 t0m0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x89 0 t1m1 t1m0 mode 0 0 mode 0: 13-bit counter/timer 0 1 mode 1: 16-bit counter/timer 1 0 mode 2: 8-bit counter/timer with auto-reload 1 1 mode 3: timer 1 inactive t0m1 t0m0 mode 0 0 mode 0: 13-bit counter/timer 0 1 mode 1: 16-bit counter/timer 1 0 mode 2: 8-bit counter/timer with auto-reload 1 1 mode 3: two 8-bit counter/timers c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 315 sfr definition 23.3. ckcon: clock control sfr definition 23.4. tl0: timer 0 low byte bits7?5: unused. read = 000b, write = don?t care. bit4: t1m: timer 1 clock select. this select the clock source supplied to timer 1. t1m is ignored when c/t1 is set to logic 1. 0: timer 1 uses the clock defined by the prescale bits, sca1?sca0. 1: timer 1 uses the system clock. bit3: t0m: timer 0 clock select. this bit selects the clock source supplied to timer 0. t0m is ignored when c/t0 is set to logic 1. 0: counter/timer 0 uses the clock defined by the prescale bits, sca1-sca0. 1: counter/timer 0 uses the system clock. bit2: unused. read = 0b, write = don?t care. bits1?0: sca1?sca0: timer 0/1 prescale bits these bits control the division of the clock su pplied to timer 0 and/or timer 1 if configured to use prescaled clock inputs. 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: sfr page: 0x8e 0 sca1 sca0 prescaled clock 0 0 system clock divided by 12 0 1 system clock divided by 4 1 0 system clock divided by 48 1 1 external clock divided by 8* *note: external clock divided by 8 is synchronized with the system clock, and external clock must be less than or equal to the system clock frequency to operate the timer in this mode. bits 7?0: tl0: timer 0 low byte. the tl0 register is the low byte of the 16-bit timer 0. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8a 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 316 rev. 1.4 sfr definition 23.5. tl1: timer 1 low byte sfr definition 23.6. th0: timer 0 high byte sfr definition 23.7. th1: timer 1 high byte bits 7?0: tl1: timer 1 low byte. the tl1 register is the low byte of the 16-bit timer 1. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8b 0 bits 7?0: th0: timer 0 high byte. the th0 register is the high byte of the 16-bit timer 0. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8c 0 bits 7?0: th1: timer 1 high byte. the th1 register is the high byte of the 16-bit timer 1. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0x8d 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 317 23.2. timer 2, timer 3, and timer 4 timers 2, 3, and 4 are 16-bit counter/timers, each formed by two 8-bit sfr?s: tmrnl (low byte) and tmrnh (high byte) where n = 2, 3, and 4 for timers 2, 3, and 4 respectively. timers 2 and 4 feature auto- reload, capture, and toggle output mo des with the ability to count up or down. timer 3 features auto-reload and capture modes, with the ability to count up or down. capture mode and au to-reload mode are selected using bits in the timer 2, 3, and 4 control registers (tmrncn). toggle output mode is selected using the timer 2 or 4 configuration registers (tmrncf). thes e timers may also be used to generate a square- wave at an external pin. as with timers 0 and 1, timers 2, 3, and 4 can use either the system clock (divided by one, two, or twelve), external clock (divi ded by eight) or transitions on an external input pin as its clock source. timer 2 and 3 can be used to start an adc data conversion and timers 2, 3, and 4 can schedule dac outputs. timers 1, 2, 3, or 4 may be used to generate baud rates for uart 0. only timer 1 can be used to generate baud rates for uart 1. the counter/timer select bit c/tn bit (tmrncn.1) conf igures the peripheral as a counter or timer. clear- ing c/tn configures the timer to be in a timer mode (i.e., the system clock or transitions on an external pin as the input for the timer). when c/tn is set to 1, the timer is configur ed as a counter (i.e., high-to-low tran- sitions at the tn input pin increment (or decrement) the counter/timer register. timer 3 and timer 2 share the t2 input pin. refer to section ?18.1. ports 0 through 3 and the priority crossbar decoder? on page 238 for information on selecting and configuring exter nal i/o pins for digital peripherals, such as the tn pin. timer 2, 3, and 4 can use either sysclk, sysclk divide d 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 (tmr ncn.1) selects the system clock/external clock as the input for the timer. the timer clock select bits tn m0 and tnm1 in tmrncf can be used to select the system clock undivided, system clock divided by two, syst em clock divided by 12, or an external clock pro- vided at the xtal1/xtal2 pins divided by 8 (see sfr definition 23.13). 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 coun- ter). 23.2.1. configuring timer 2, 3, and 4 to count down timers 2, 3, and 4 have the abilit y to count down. when the timer?s decrement enable bit (dcenn) in the timer configuration register (see sfr definition 23 .13) is set to ?1?, t he timer can then count up or down . when dcenn = 1, the direction of the timer?s count is controlled by the tnex pin?s logic level (timer 3 shares the t2ex pin with timer 2) . when tnex = 1, the co unter/timer will count up; when tnex = 0, the counter/timer will count down. to use this feature, tnex must be enabled in the di gital crossbar and config- ured as a digital input. note: when dcenn = 1, other functions of the tnex input (i.e., capture and auto-reload) are not available. tnex will only control the direction of the timer when dcenn = 1. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 318 rev. 1.4 23.2.2. capture mode in capture mode, timer 2, 3, and 4 w ill operate as a 16-bit counter/timer with capt ure 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 (timer 3 shares the t2ex pin with timer 2) ca uses the 16-bit value in the associated timer (thn, tln) to be loaded into the capture registers (rcapnh, rcapnl). if a capture is triggered in the counter/ timer, the timer external flag (tmr ncn.6) will be set to ?1? and an interrupt will occur if the interrupt is enabled. see section ?11.3. interrupt handler? on page 154 for further information concerning the con- figuration of interrupt sources. as the 16-bit timer register increments and overfl ows 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 config- ured to count down by se tting the decr ement 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 overflow s, 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 2, 3, and 4 run control bi t trn (tmrncn.2) to logic 1. the timer 2, 3, and 4 respective external enable exenn (t mrncn.3) must also be set to logic 1 to enable captures. if exenn is cleared, transitions on tnex will be ignored. figure 23.4. t2, 3, and 4 ca pture mode block diagram tmrnl tmrnh trn tclk interrupt tmrncn exfn exenn trn c/tn cp/rln tfn sysclk 12 2 tmrncf d c e n t n o e t o g n t n m 1 t n m 0 toggle logic tn (port pin) 0 1 1 0 exenn crossbar tne x rcapnl rcapnh 0xff 0xff 8 external clock (xtal1) tn crossbar c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 319 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 w ill set its ov erflow/under- flow flag (tfn) and cause an interrupt (if enabled) upon overflow/underflow, and 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) bi t is set to ?1? and the decrement e nable bit (dcenn) is ?0?, a falling edge (?1?-to-?0? transition) on t he tnex pin will cause a timer reload. note that timer overflows will also cause auto-reloads. when dcenn is set to ?1?, the stat e 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 (timer 3 shares the t2ex pin with timer 2). see section 23.2.1 for information concerning configuration of a timer to count down. when counting down, the c ounter/timer will set its over flow/underflow flag (tfn) and cause an interrupt (if enabled) when the value in the tmrnh and tmrnl registers matches the 16-bit value in the reload/cap- ture 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) togg les upon every overflow or underflow and does not cause an interrupt. the exfn flag can be used as the most significant bit (msb) of a 17-bit counter. . figure 23.5. tn auto-reload (t2,3,4) a nd toggle mode (t2, 4) block diagram tmrnl tmrnh trn tclk reload interrupt exenn crossbar tne x tmrncn exfn exenn trn c/tn cp/rln tfn sysclk 12 2 tmrncf d e c e n t n o e t o g n t n m 1 t n m 0 toggle logic tn (port pin) 0 1 1 0 rcapnl rcapnh 0xff 0xff ovf 8 external clock (xtal1) tn crossbar c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 320 rev. 1.4 23.2.4. toggle output mode (timer 2 and timer 4 only) timers 2 and 4 have the capability to to ggle the state of their respective ou tput port pins (t2 or t4) to pro- duce a 50% duty cycle wave form output. the po rt pin state will change upon t he 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-rel oad value for the timer is 0xffff, and under flow 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 th e 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/u nderflows at 1/2 the desire d output frequency. the port pin assigned by the crossbar as the timer?s output pin should be configured as a digital output (see section ?18. port input/output? on page 235 ). setting the timer?s run bit (t rn) to ?1? will start the toggle of the pin. a read/write of the timer?s 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 sq f tclk 265536 rcapn ? ?? ? equation 23.1. square wave frequenc y (timer 2 and timer 4 only) c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 321 sfr definition 23.8. tmrncn: ti mer 2, 3, and 4 control bit7: tfn: timer 2, 3, and 4 overflow/underflow flag. set by hardware when either the timer overfl ows from 0xffff to 0x0000, underflows from the value placed in rcapnh:rcapnl to 0xffff (in auto-reload mode), or underflows from 0x0000 to 0xffff (in capture mode). when the timer interrupt is enabled, setting this bit causes the cpu to vector to the timer interrupt service routine. this bi t is not automatically cleared by hardware and must be cleared by software. bit6: exfn: timer 2, 3, or 4 external flag. set by hardware when either a capture or rel oad is caused by a high-to-low transition on the tnex input pin and exenn is logic 1 . when the timer interrupt is enabled, sett ing this bit causes the cpu to vector to the timer interrupt service routine. this bi t is not automatically cleared by hardware and must be cleared by software. bit5?4: reserved. bit3: exenn: timer 2, 3, and 4 external enable. enables high-to-low transitions on tnex to trigger captures, reloads, and control the direc- tion of the timer/counte r (up or down count). if dcenn = 1, tnex will determine if the timer counts up or down when in auto-reload mode. if exenn = 1, tn ex should be configured as a digital input. 0: transitions on the tnex pin are ignored. 1: transitions on the tnex pin cause capture, re load, or control the direction of timer count (up or down) as follows: capture mode : ?1?-to-?0? transition on tnex pin causes rcapnh:rcapnl to capture timer value. auto-reload mode : dcenn = 0: ?1?-to-?0? transition causes reload of timer and sets the exfn flag. dcenn = 1: tnex logic level controls direction of timer (up or down). bit2: trn: timer 2, 3, and 4 run control. this bit enables/disables the respective timer. 0: timer disabled. 1: timer enabled and running/counting. bit1: c/tn: counter/timer select. 0: timer function: timer incremented by clock defined by tnm1:tnm0 (tmrncf.4:tmrncf.3). 1: counter function: timer incremented by hi gh-to-low transitions on external input pin. bit0: cp/rln: capture/reload select. this bit selects whether the timer functions in capture or auto-reload mode. 0: timer is in auto-reload mode. 1: timer is in capture mode. note: timer 3 and timer 2 share the t2 and t2ex pins. 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 sfr address: tmr2cn:0xc8;tmr3cn:0xc8;tmr4cn:0xc8 sfr page: tmr2cn: page 0;tmr3cn: page 1;tmr4cn: page 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 322 rev. 1.4 sfr definition 23.9. tmrncf: time r 2, 3, and 4 configuration bit7?5: reserved. bit4?3: tnm1 and tnm0: timer clock mode select bits. bits used to select the timer clock sour ce. the sources can be the system clock (sysclk), sysclk divided by 2 or 12, or the ex ternal clock divided by 8. clock source is selected as follows: 00: sysclk/12 01: sysclk 10: external clock/8 (synchronized to the system clock) 11: sysclk/2 bit2: 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 (timer 2 and timer 4 only). bit1: tnoe: timer output enable bit. this bit enables the timer to output a 50% duty cycle output to the timer?s 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 ?square wave frequency (timer 2 and timer 4 only)? on page 320.) configure port pin to output squarewave (see section ?18. port input/output? on page 235 ) 0: output of toggle mode not available at timers?s assigned port pin. 1: output of toggle mode available at timers?s assigned port pin. bit0: dcenn: 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 st ate of tnex as follows: if tnex = 0, the timer counts down. if tnex = 1, the timer counts up. note: timer 3 and timer 2 share the t2 and t2ex pins. r/w r/w r/w r/w r/w reset value - - - tnm1 tnm0 togn tnoe dcenn 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: tmr2cf:0xc9;tmr3cf:0xc9;tmr4cf:0xc9 sfr page tmr2cf: page 0;tmr3cf: page 1;tmr4cf: page 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 323 sfr definition 23.10. rcapnl : timer 2, 3, and 4 ca pture register low byte sfr definition 23.11. rcapnh: timer 2, 3, and 4 capture register high byte sfr definition 23.12. tmrnl: timer 2, 3, and 4 low byte bits 7?0: rcap2, 3, and 4l: timer 2, 3, and 4 capture register low byte. the rcap2, 3, and 4l register captures the low byte of timer 2, 3, and 4 when timer 2, 3, and 4 is configured in capture mode. when timer 2, 3, and 4 is configured in auto-reload mode, it holds the low byte of the reload value. 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: rcap2l: 0xca; rcap3l: 0xca; rcap4l: 0xca sfr page: rcap2l: page 0; rcap3l: page 1; rcap4l: page 2 bits 7?0: rcap2, 3, and 4h: timer 2, 3, and 4 capture register high byte. the rcap2, 3, and 4h register captures the high byte of timer 2, 3, and 4 when timer 2, 3, and 4 is configured in capture mode. when timer 2, 3, and 4 is configured in auto-reload mode, it holds the high byte of the reload value. 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: rcap2h: 0xcb; rcap3h: 0xcb; rcap4h: 0xcb sfr page: rcap2h: page 0; rcap3h: page 1; rcap4h: page 2 bits 7?0: tl2, 3, and 4: timer 2, 3, and 4 low byte. the tl2, 3, and 4 register contains the low byte of the 16-bit timer 2, 3, and 4 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: tmr2l: 0xcc; tmr3l: 0xcc; tmr4l: 0xcc sfr page: tmr2l: page 0; tmr3l: page 1; tmr4l: page 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 324 rev. 1.4 sfr definition 23.13. tmrnh ti mer 2, 3, and 4 high byte bits 7?0: th2, 3, and 4: timer 2, 3, and 4 high byte. the th2, 3, and 4 register contains the hi gh byte of the 16-bit timer 2, 3, and 4 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: tmr2h: 0xcd; tmr3h: 0xcd; tmr4h: 0xcd sfr page: tmr2h: page 0; tmr3h: page 1; tmr4h: page 2 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 325 24. programmable counter array the programmable counter array (pca0) provides enhanced timer functionality while requiring less cpu intervention than the standard 8051 counter/timers. pc a0 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 ?18.1. ports 0 through 3 and the priority crossbar decoder? on page 238 ). the counter/timer is driven by a program- mable timebase that can select between six inputs as its source: system clock, system clock divided by four, system clock divided by twelve, the external oscilla tor 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 inde- pendently in one of six modes: edge-triggered capt ure, 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 con- trolled through the system controller's special function registers. the basic pca block diagram is shown in figure 24.1. figure 24.1. pca block diagram capture/compare module 1 capture/compare module 0 capture/compare module 2 capture/compare module 3 cex1 eci crossbar cex2 cex3 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8 capture/compare module 4 cex4 capture/compare module 5 cex5 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 326 rev. 1.4 24.1. pca counter/timer the 16-bit pca counter/timer consists of two 8-bi t 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 accu rate reading of the entire 16-bit pca0 counter. read- ing pca0h or pca0l does not disturb the counter op eration. the cps2?cps0 bits in the pca0md regis- ter select the timebase for the counter/timer as shown in table 24.1. when the counter/timer overflows from 0xffff to 0x0 000, 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 inte rrupt service routine, and must be cleared by soft- ware (note: pca0 interrupts must be globally enabled before cf interrupts are recognized. pca0 inter- rupts 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 a llows the pca to continue normal operation while the cpu is in idle mode. figure 24.2. pca counter/timer block diagram table 24.1. pca timebase input options cps2 cps1 cps0 timebase 0 0 0 system clock divided by 12 0 0 1 system clock divided by 4 0 1 0 timer 0 overflow 0 1 1 high-to-low transitions on eci (max rate = system clock divided by 4) 1 0 0 system clock 1 0 1 external oscillator source divided by 8* *note: external clock divided by 8 is synchronized with the system clock. pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 idle 0 1 pca0h pca0l snapshot register to sfr bus overflow to pca interrupt system cf pca0l read to pca modules sysclk/12 sysclk/4 timer 0 overflow eci 000 001 010 011 100 101 sysclk external clock/8 pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 5 c c f 4 c c f 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 327 important note about the pca0cn register: if the main pca counter (pca0h : pca0l) overflows dur- ing the execution phase of a read-modify-write instruction (bit-wise setb or clr, anl, orl, xrl) that targets the pca0cn register, the cf (counter overflow) bit will not be set. if the cf flag is used by soft- ware to keep track of counter overflows, the following steps should be taken when performing a bit-wise operation on the pca0cn register: step 1. disable global interrupts. step 2. read pca0l. this w ill latch the value of pca0h. step 3. read pca0h, saving the value. step 4. execute the bit-wise operation on ccfn (for example, clr ccf0, or ccf0 = 0;). step 5. read pca0l. step 6. read pca0h, saving the value. step 7. if the value of pca0h read in step 3 is 0xff and the value for pca0h read in step 6 is 0x00, then manually set the cf bit in software (for example, setb cf, or cf = 1;). step 8. re-enable interrupts. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 328 rev. 1.4 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 functi on registers (sfrs) associ ated with it in the cip- 51 system controller. these registers are used to exchange data with a module and configure the module's mode of operation. table 24.2 summarizes the bit settings in the pca0cp mn registers used to select the pca0 capture/com- pare module?s operating modes. setting the eccfn bit in a pca0cpmn register enables the module's ccfn interrupt. note: pca0 interrupts must be globally enabled before individual ccfn interrupts are rec- ognized. 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. figure 24.3. pca interrupt block diagram pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 5 c c f 4 c c f 3 pca0md c i d l e c f c p s 1 c p s 0 c p s 2 0 1 pca module 0 (ccf0) pca module 1 (ccf1) eccf1 0 1 eccf0 0 1 pca module 2 (ccf2) eccf2 0 1 pca module 3 (ccf3) eccf3 eccf4 pca counter/ timer overflow 0 1 interrupt priority decoder epca0 (eie.3) pca0cpmn (for n = 0 to 5) p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 1 pca module 4 (ccf4) 0 1 pca module 5 (ccf5) 0 1 ea (ie.7) 0 1 eccf5 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 329 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 transi- tion that triggers the capture: low-to-high transition (p ositive 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 th e cpu vectors to the interr upt service routine, and must be cleared by software. figure 24.4. pca capture mode diagram note: the signal at cexn must be high or low for at least 2 system clock cycles in order to be valid. table 24.2. pca0cpm register settings for pca capture/compare modules pwm16 ecom capp capn mat tog pwm eccf operation mode x x 10000x capture triggered by positive edge on cexn x x 01000x capture triggered by negative edge on cexn x x 11000x capture triggered by transition on cexn x 1 00100x software timer x 1 00110x high speed output x 1 00011x frequency output 0 1 000010 8-bit pulse width modulator 1 1 00001016-bit pulse width modulator x = don?t care pca0l pca0cpln pca timebase cexn crossbar port i/o pca0h capture pca0cphn 0 1 0 1 (to ccfn) pca interrupt pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 5 c c f 4 c c f 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 330 rev. 1.4 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 reg- ister (pca0cphn and pca0cpln). when a match oc curs, 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 vect ors 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 wri tten first. writing to pca0cpln clears the ecomn bit to ?0?; writing to pca0 cphn sets ecomn to ?1?. figure 24.5. pca software timer mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 00 00 pca interrupt 0 1 x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 5 c c f 4 c c f 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 331 24.2.3. high speed output mode in high speed output mode, a module?s associated cexn pin is toggled each time a match occurs between the pca counter and the module's 16- bit capture/compare register (pca0cphn and pca0cpln) setting the togn, matn, and ecomn bits in the pca0cpmn register enables the high- speed output mode. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/ compare registers, the low byte should always be wri tten first. writing to pca0cpln clears the ecomn bit to ?0?; writing to pca0 cphn sets ecomn to ?1?. figure 24.6. pca high speed output mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln pca interrupt 0 1 00 0x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x cexn crossbar port i/o toggle 0 1 togn pca0cn c f c r c c f 0 c c f 2 c c f 1 c c f 5 c c f 4 c c f 3 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 332 rev. 1.4 24.2.4. frequency output mode frequency output mode produces a programmable-freq uency square wave on the module?s associated cexn pin. the capture/compare module high byte holds the number of pca clocks to count before the out- put is toggled. the frequency of the square wave is then defined by equation 24.1. where f pca is the frequency of the clock selected by the cps2?0 bits in the pca mode register, pca0md. the lower byte of the capture/compare module is compared to the pca0 counter low byte; on a match, cexn is toggled and the offset held in the hi gh byte is added to the matched value in pca0cpln. frequency output mode is enabled by setting the ecomn, togn, and pwmn bits in the pca0cpmn reg- ister. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/ compare registers, the low byte should always be wri tten first. writing to pca0cpln clears the ecomn bit to ?0?; writing to pca0 cphn sets ecomn to ?1?. figure 24.7. pca frequency output mode equation 24.1. square wa ve frequency output f sqr f pca 2 pca0 cphn ? note: a value of 0x00 in the pca0cphn register is equal to 256 for this equation. 8-bit comparator pca0l enable pca timebase 000 0 match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 pca0cphn 8-bit adder pca0cpln adder enable cexn crossbar port i/o toggle 0 1 togn 1 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 333 24.2.5. 8-bit pulse width modulator mode each module can be used independently to generate pulse width modulated (pwm) outputs on its associ- ated cexn pin. the frequency of the output is depe ndent 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 hi gh. 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 stor ed in the counter/timer's high byte (pca0h) with- out 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 wri tten first. writing to pca0cpln clears the ecomn bit to ?0?; writing to pca0 cphn sets ecomn to ?1?. figure 24.8. pca 8-bit pwm mode diagram dutycycle 256 pca0 cphn ? ?? 256 ----------------------------------- ---------------- = equation 24.2. 8-bit pwm duty cycle 8-bit comparator pca0l pca0cpln pca0cphn cexn crossbar port i/o enable overflow pca timebase 0000 0 q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 334 rev. 1.4 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 inter- rupts. 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 wri tten first. writing to pca0cpln clears the ecomn bit to ?0?; writing to pca0 cphn sets ecomn to ?1?. figure 24.9. pca 16-bit pwm mode equation 24.3. 16-bit pwm duty cycle dutycycle 65536 pca0 cpn ? ?? 65536 ---------------------------------------------------- - = pca0cpln pca0cphn enable pca timebase 0000 0 pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 1 16-bit comparator cexn crossbar port i/o overflow q q set clr s r match pca0h pca0l c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 335 24.3. register descriptions for pca0 following are detailed descriptions of the special fu nction registers related to the operation of pca0. sfr definition 24.1. pca0cn: pca control bit7: cf: pca counter/timer overflow flag. set by hardware when the pca0 counter/ti mer overflows from 0xffff to 0x0000. when the counter/timer overflow (cf) interrupt is enabled, setting this bit causes the cpu to vec- tor to the cf interrupt service routine. this bi t is not automatically cleared by hardware and must be cleared by software. bit6: cr: pca0 counter/timer run control. this bit enables/disables the pca0 counter/timer. 0: pca0 counter/timer disabled. 1: pca0 counter/timer enabled. bit5: ccf5: pca0 module 5 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. bit4: ccf4: pca0 module 4 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. bit3: ccf3: pca0 module 3 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. bit2: ccf2: pca0 module 2 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. bit1: ccf1: pca0 module 1 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. bit0: ccf0: pca0 module 0 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf interrupt is enabled, setting this bit causes the cpu to vect or to the ccf interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by software. r/wr/wr/wr/wr/wr/wr/w r/wreset value cf cr ccf5 ccf4 ccf3 ccf2 ccf1 ccf0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xd8 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 336 rev. 1.4 sfr definition 24.2. pca0md: pca0 mode bit7: cidl: pca0 counter/timer idle control. specifies pca0 behavior wh en cpu is in idle mode. 0: pca0 continues to function normally wh ile the system controlle r is in idle mode. 1: pca0 operation is suspended while the system controller is in idle mode. bits6?4: unused. read = 000b, write = don't care. bits3?1: cps2-cps0: pca0 co unter/timer pulse select. these bits select the timebase source for th e pca0 counter bit0: ecf: pca counter/timer overflow interrupt enable. this bit sets the masking of the pca0 co unter/timer overflow (cf) interrupt. 0: disable the cf interrupt. 1: enable a pca0 counter/ti mer overflow interrupt reques t when cf (pca0cn.7) is set. r/w r/w r/w r/w r/w r/w r/w r/w reset value cidl - - - cps2 cps1 cps0 ecf 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xd9 0 cps2 cps1 cps0 timebase 0 0 0 system clock divided by 12 0 0 1 system clock divided by 4 0 1 0 timer 0 overflow 011 high-to-low transitions on eci (max rate = system clock divided by 4) 100system clock 1 0 1 external clock divided by 8 (synchronized with system clock) 1 1 0 reserved 1 1 1 reserved c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 337 sfr definition 24.3. pca0cpmn: pca0 capture/compare mode bit7: pwm16n: 16-bit pulse width modulation enable this bit selects 16-bit mode when pulse width modulation mode is enabled (pwmn = 1). 0: 8-bit pwm selected. 1: 16-bit pwm selected. bit6: ecomn: comparator function enable. this bit enables/disables the comparator function for pca0 module n. 0: disabled. 1: enabled. bit5: cappn: capture positi ve function enable. this bit enables/disables the positive edge capture for pca0 module n. 0: disabled. 1: enabled. bit4: capnn: capture negative function enable. this bit enables/disables the negative edge capture for pca0 module n. 0: disabled. 1: enabled. bit3: matn: match function enable. this bit enables/disables the match function for pca0 module n. when enabled, matches of the pca0 counter with a module's capture/comp are register cause the ccfn bit in pca0md register to be set to logic 1. 0: disabled. 1: enabled. bit2: togn: toggle function enable. this bit enables/disables the toggle function for pca0 module n. when enabled, matches of the pca0 counter with a module's capture/co mpare register cause the logic level on the cexn pin to toggle. if the pwmn bit is also set to logic 1, the module operates in frequency output mode. 0: disabled. 1: enabled. bit1: pwmn: pulse width modulation mode enable. this bit enables/disables the pwm function for pca0 module n. when enabled, a pulse width modulated signal is output on the cexn pin. 8-bit pwm is used if pwm16n is logic 0; 16-bit mode is used if pwm16n logic 1. if the togn bit is also set, the module operates in frequency output mode. 0: disabled. 1: enabled. bit0: eccfn: capture/compare flag interrupt enable. this bit sets the masking of the capture/compare flag (ccfn) interrupt. 0: disable ccfn interrupts. 1: enable a capture/compare flag interrupt request when ccfn is set. r/w r/w r/w r/w r/w r/w r/w r/w reset value pwm16n ecomn cappn capnn mat n togn pwmn eccfn 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: pca0cpm0: 0xda, pca0cpm1: 0xdb, pca0cpm2 : 0xdc, pca0cpm3: 0xdd, pca0cpm4: 0xde, pca0cpm5: 0xdf sfr page: pca0cpm0: page 0, pca0cpm1: page 0, pca0cpm2: page 0, pca0cpm3: 0, pca0cpm4: page 0, pca0cpm5: page 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 338 rev. 1.4 sfr definition 24.4. pca0l: p ca0 counter/timer low byte sfr definition 24.5. pca0h: p ca0 counter/timer high byte sfr definition 24.6. pca0cpln: p ca0 capture module low byte bits 7?0: pca0l: pca0 counter/timer low byte. the pca0l register holds the low byte (l sb) of the 16-bit pca0 counter/timer. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xf9 0 bits 7?0: pca0h: pca0 counter/timer high byte. the pca0h register holds the high byte (msb) of the 16-bit pca0 counter/timer. r/wr/wr/wr/wr/wr/wr/wr/wreset value 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sfr address: sfr page: 0xfa 0 bits7?0: pca0cpln: pca0 capture module low byte. the pca0cpln register holds the low byte (lsb) of the 16-bit capture module n. 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: pca0cpl0: 0xfb, pca0cpl1: 0xfd, pca0cpl2: 0xe9, pca0cpl3: 0xeb, pca0cpl4: 0xed, pca0cpl5: 0xe1 sfr page: pca0cpl0: page 0, pca0cpl1: page 0, pca0cpl2: page 0, pca0cpl3: page 0, pca0cpl4: page 0, pca0cpl5: page 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 339 sfr definition 24.7. pca0cphn: p ca0 capture module high byte bits7?0: pca0cphn: pca0 capture module high byte. the pca0cphn register holds the high byte (msb) of the 16-bit capture module n. 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: pca0cph0: 0xfc, pca0cph1: 0xfd, pca0cph2: 0xea, pca0cph3: 0xec, pca0cph4: 0xee, pca0cph5: 0xe2 sfr page: pca0cph0: page 0, pca0cph1: page 0, pca0cph2: page 0, pca0cph3: page 0, pca0cph4: page 0, pca0cph5: page 0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 340 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 341 25. jtag (ieee 1149.1) each mcu has an on-chip jtag interface and logic to support boundary scan for production and in-sys- tem 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 architec ture. access of the jtag instruction register (ir) and data regis- ters (dr) are as described in the test access port and operation of the ieee 1149.1 specification. the jtag interface is accessed via four dedica ted pins on the mcu: tck, tms, tdi, and tdo. through the 16-bit jtag instruction register (ir), any of the eight instructions shown in figure 25.1 can be commanded. there are three dr?s associated with jtag boundary-scan, and four associated with flash read/write operations on the mcu. jtag register definition 25.1. ir : jtag instruction register reset value 0x0000 bit15 bit0 ir value instruction description 0x0000 extest selects the boundary data register for control and observability of all device pins 0x0002 sample/ preload selects the boundary data register for observability and presetting the scan-path latches 0x0004 idcode selects device id register 0xffff bypass selects bypass data register 0x0082 flash control selects flashcon register to contro l how the interface logic responds to reads and writes to the flashdat register 0x0083 flash data selects flashdat register for reads and writes to the flash memory 0x0084 flash address selects flashadr register which holds the address of all flash read, write, and erase operations 0x0085 flash scale selects flashscl register which cont rols the flash one-shot timer and read-always enable c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 342 rev. 1.4 25.1. boundary scan the dr in the boundary scan path is an 134-bit sh ift register. the boundary dr provides control and observability of all the de vice pins as well as the sfr bus and weak pullup feature via the extest and sample commands. table 25.1. boundary data register bit definitions extest provides access to both capture and updat e actions, while sample only performs a capture. bit action target 0 capture reset enable from mcu (64-pin tqfp devices) update reset enable to rst pin (64-pin tqfp devices) 1capture reset input from rst pin (64-pin tqfp devices) update reset output to rst pin (64-pin tqfp devices) 2capture reset enable from mcu (100-pin tqfp devices) update reset enable to rst pin (100-pin tqfp devices) 3capture reset input from rst pin (100-pin tqfp devices) update reset output to rst pin (100-pin tqfp devices) 4 capture external clock from xtal1 pin update not used 5 capture weak pullup enable from mcu update weak pullup enable to port pins 6, 8, 10, 12, 14, 16, 18, 20 capture p0.n output enable from mcu (e.g. bit6=p0.0, bit8=p0.1, etc.) update p0.n output enable to pin (e.g. bit6=p0.0oe, bit8=p0.1oe, etc.) 7, 9, 11, 13, 15, 17, 19, 21 capture p0.n input from pin (e.g . bit7=p0.0, bit9=p0.1, etc.) update p0.n output to pin (e.g . bit7=p0.0, bit9=p0.1, etc.) 22, 24, 26, 28, 30, 32, 34, 36 capture p1.n output enable from mcu update p1.n output enable to pin 23, 25, 27, 29, 31, 33, 35, 37 capture p1.n input from pin update p1.n output to pin 38, 40, 42, 44, 46, 48, 50, 52 capture p2.n output enable from mcu update p2.n output enable to pin 39, 41, 43, 45, 47, 49, 51, 53 capture p2.n input from pin update p2.n output to pin 54, 56, 58, 60, 62, 64, 66, 68 capture p3.n output enable from mcu update p3.n output enable to pin 55, 57, 59, 61, 63, 65, 67, 69 capture p3.n input from pin update p3.n output to pin 70, 72, 74, 76, 78, 80, 82, 84 capture p4.n output enable from mcu update p4.n output enable to pin 71, 73, 75, 77, 79, 81, 83, 85 capture p4.n input from pin update p4.n output to pin 86, 88, 90, 92, 94, 96, 98, 100 capture p5.n output enable from mcu update p5.n output enable to pin 87, 89, 91, 93, 95, 97, 99, 101 capture p5.n input from pin update p5.n output to pin 102, 104, 106, 108, 110, 112, 114, 116 capture p6.n output enable from mcu update p6.n output enable to pin c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 343 25.1.1. extest instruction the extest instruction is accessed via the ir. the boundary dr provides control an d observability of all the device pins as well as the weak pullup feature. all inputs to on-chip logic are set to logic 1. 25.1.2. sample instruction the sample instruction is accessed via the ir. the boundary dr prov ides observability and presetting of the scan-path latches. 25.1.3. bypass instruction the bypass instruction is acce ssed via the ir. it provides access to the standard jtag bypass data reg- ister. 25.1.4. idcode instruction the idcode instruction is accessed via the ir. it provides access to the 32-bit device id register. jtag register definition 25. 2. deviceid: jtag device id bit action target 103, 105, 107, 109, 111, 113, 115, 117 capture p6.n input from pin update p6.n output to pin 118, 120, 122, 124, 126, 128, 130, 132 capture p7.n output enable from mcu update p7.n output enable to pin 119, 121, 123, 125, 127, 129, 131, 133 capture p7.n input from pin update p7.n output to pin table 25.1. boundary data regist er bit definitions (continued) version = 0000b part number = 0000 0000 0000 0111b (c8051f120/1/2/3/4/5/6/7 or c8051f130/1/2/3) manufacturer id = 0010 0 100 001b (silicon labs) reset value version part number manufacturer id 1 0xn0003243 bit31 bit28 bit27 bit12 bit11 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 344 rev. 1.4 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: indopcode: these bit set the operation to perform according to the following table: 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. si nce 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 initia ted, 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 addres sed 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 write- data 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-bi t 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 initi- ated. 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: 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 poll- ing for busy to be low will be followed by another read or wr ite operation, jtag writes of the next operation can be made while checking for busy to be low. they will be ignored unt il busy is read low, at which time the new operation will initiate. this bi t 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 regi sters 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). 19:18 17:0 indopcode writedata indopcode operation 0x poll 10 read 11 write 19 18:1 0 0 readdata busy c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 345 jtag register defi nition 25.3. flashcon: jtag flash control this register determines how the fl ash interface logic will respond to reads and writes to the flash- dat register. bit7: sfle: scratchpad flash memory access enable when this bit is set, flash reads and writes are directed to the two 128-byte scratchpad flash sectors. when sfle is set to logic 1, flash accesses out of the address range 0x00- 0xff should not be attempted (with the exception of address 0x400, which can be used to simultaneously erase bot h scratchpad areas). reads/writes out of this range will yield undefined results. 0: flash access directed to the program/data flash sector. 1: flash access directed to the two 128 byte scratchpad sectors. bits6?4: wrmd2?0: write mode select bits. the write mode select bits control how the interface logic responds to writes to the flash- dat register per the following values: 000: a flashdat write replaces the data in the flashdat register, but is otherwise ignored. 001: a flashdat write initiates a write of flashdat into the memory address by the flashadr register. flashadr is incr emented by one when complete. 010: a flashdat write initiates an erasure (sets all bytes to 0xff) of the flash page containing the address in flashadr. the data written must be 0xa5 for the erase to occur. flashadr is not affected. if flashadr = 0x1fbfe ? 0x1fbff, the entire user spac e will be erased (i.e. entire flas h memory except for reserved area 0x1fc00 ? 0x1ffff). (all other values for wrmd2-0 are reserved.) bits3?0: rdmd3?0: read mode select bits. the read mode select bits control how the interface logic responds to reads from the flashdat register per the following values: 0000: a flashdat read provides the data in the flashdat register, but is otherwise ignored. 0001: a flashdat read initiates a read of the byte addressed by the flashadr register if no operation is currently active . this mode is used for block reads. 0010: a flashdat read initiates a read of the byte addressed by flashadr only if no operation is active and any data from a previous read has already been read from flashdat. this mode allows single bytes to be read (or the last byte of a block) without initiating an extra read. (all other values for rdmd3?0 are reserved.) reset value sfle wrmd2 wrmd1 wrmd0 rdmd3 rdmd2 rdmd1 rdmd0 00000000 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 346 rev. 1.4 jtag register definition 25.4 . flashdat: jtag flash data jtag register definition 25.5. flashadr: jtag flash address this register is used to read or write data to the flash memory across the jtag interface. bits9?2: data7?0: flash data byte. bit1: fail: flash fail bit. 0: previous flash memory operation was successful. 1: previous flash memory operation failed. us ually indicates the associated memory loca- tion was locked. bit0: busy: flash busy bit. 0: flash interface logic is not busy. 1: flash interface logic is pr ocessing a request. reads or writes while busy = 1 will not ini- tiate another operation. reset value 0000000000 bit9 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 17-bit address. reset value 0x00000 bit16 bit0 c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 347 25.3. debug support each mcu has on-chip jtag and debug logic that prov ides non-intrusive, full speed, in-circuit debug sup- port using the prod uction 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 correc tly (remain synchronized) while debugging. the watch- dog timer (wdt) is disabled when the mcu is halted during single stepping or at a breakpoint. the c8051f120dk is a development kit with all the hardware and software necessary to develop applica- tion code and per form in-circuit debug with each mcu in the c8051f12x a nd c8051f13x device families. each kit includes development software for the pc, a serial adapter (for connection to jtag) and a target application board with a c8051f120 installed. se rial cables and wall-mount power supply are also included. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 348 rev. 1.4 n otes : c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 rev. 1.4 349 d ocument c hange l ist revision 1.3 to revision 1.4 ? added new paragraph tags: sfr definition and jtag register definition. ? product selection guide table 1.1: added rohs-compliant ordering information. ? overview chapter, figure 1.8, ?on-chip memory map?: corrected on-chip xram size to ?8192 bytes?. ? sar8 chapter: table 7.1, ?adc2 electrical characte ristics?: track/hold minimum spec corrected to ?300 ns?. ? sar8 chapter: table 7.1, ?adc2 electrical characte ristics?: total harmonic distortion typical spec corrected to ?-51 db?. ? oscillators chapter, figure 14.1, ?oscillator diag ram?: corrected locati on of ioscen arrow. ? cip51 chapter, section 11.3 : added note describing ea change behavior when followed by single- cycle instruction. ? cip51 chapter, interrupt summary table: adde d ?sfrpage? column and sfrpage value for each interrupt source. ? cip-51 chapter, figure 11.2, ?memory map?: corrected on-chip xram size to ?8192 bytes?. ? port i/o chapter, crossbar priority figures: character formatting problem corrected. ? port i/o chapter, p7mdout register description: removed references to uart and smbus periph- erals. ? port i/o chapter, p3mdout register descriptio n: corrected text to read ?p3mdout.[7:0]?. ? timers chapter: references to ?t ncon? corrected to read ?tmrncn?. ? pca0 chapter, section 24.1: added note about pca0cn register and effects of read-modify-write instructions on the cf bit. c8051f120/1/2/3/4/5/6/7 c8051f130/1/2/3 350 rev. 1.4 c ontact i nformation 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 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 holders the information in this document is believed to be accurate in all respects at the time of publ ication but is subject to change without notice. silicon laboratories assumes no re sponsibility for errors and omissions, and disclaims responsibi lity for any consequen ces resulting from the use of information included herein. additionally, silicon laborator ies assumes no responsibility for the fun ction- ing of undescribed features or parameters. silicon laboratories reserves the right to make changes without further notice. sili con laboratories makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpos e, nor does silicon laboratories assume any liabi lity arising out of the application or use of any product or circuit, and specifi cally disclaims any and all liability, including without limitation consequential or inciden tal damages. silicon laboratories product s are not designed, intended, or authorized for use in applications in tended to support or sustain life, or for any other application in which the failure of the silicon laboratories product could create a si tuation where personal injury or death may occur. should buyer purchase or use silicon laboratories produ cts for any such unintended or unauthorized ap plication, buyer shall indemnify and hold silicon laboratories harmless against all claims and damages. |
Price & Availability of C8051F131-GQ |
|
|
All Rights Reserved © IC-ON-LINE 2003 - 2022 |
[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy] |
Mirror Sites : [www.datasheet.hk]
[www.maxim4u.com] [www.ic-on-line.cn]
[www.ic-on-line.com] [www.ic-on-line.net]
[www.alldatasheet.com.cn]
[www.gdcy.com]
[www.gdcy.net] |