![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
toshiba original cmos 16-bit microcontroller tlcs-900/l1 series TMP91CW40FG semiconductor company
preface thank you very much for making us e of toshiba microcomputer lsis. before use this lsi, refer the section, ?points of note and restrictions?. especially, take care below cautions. tmp91cw40 2008-09-19 91cw40-1 low voltage/low power consumption cmos 16-bit microcontroller TMP91CW40FG 1. outline and features the tmp91cw40 is a high-speed, high-performance 16-bit microcontroller capable of low-voltage, low-power-consumption operation. this microcontroller comes in a 100-pin flat package and has the following features: (1) toshiba proprietary 16-bit cpu (900/l1 cpu) ? instruction mnemonics are upwardly compatible with the tlcs-90 and tlcs-900. ? 16-mbyte linear address space ? architecture based on general-purp ose registers and register banks ? 16-bit multiply/divide instructions and bit transfer/arithmetic instructions ? micro dma: 4 channels (593 ns/2 bytes at 27 mhz) (2) minimum instruction execution time: 148 ns (at 27 mhz) (3) internal ram: 4 kbytes (4) internal rom: 128 kbytes restrictions on product use 20070701-en general ? the information contained herein is subject to change without notice. ? toshiba is continually working to improve the quality and reliability of its products. nevertheless, semiconductor devices in general can malfunction or fail due to their inherent electrical sensitivity an d vulnerability to physical stress. it is the responsibility of t he buyer, when utilizing toshiba products, to comply with the standards of safety in making a safe design for the entire system, and to avoid situations in which a malfunction or failure of such toshiba products could cause loss of human life, bodily injury or damage to property. in developing your designs, please ensure that toshiba products are used within specified operating ranges as set forth in the most recent toshib a products specifications. also, please keep in mind the precautions and conditions set forth in the ?handling guide for semiconduct or devices,? or ?toshiba semiconductor reliability handbook? etc. ? the toshiba products listed in this document are intend ed for usage in general electronics applications (computer, personal equipment, office equipment, measuring equipmen t, industrial robotics, domestic appliances, etc.).these toshiba products are neither intended nor warranted for us age in equipment that requires extraordinarily high quality and/or reliability or a malfunction or failure of which may cause loss of human life or bodily injury (?unintended usage?). unintended usage include atomic energy control instruments, airplane or spaceship instruments, transportation instrument s, traffic signal instruments, combus tion control instruments, medical instruments, all types of safety devices, etc.. uninte nded usage of toshiba products listed in his document shall be made at the customer?s own risk. ? the products described in this document shall not be used or embedded to any downstream products of which manufacture, use and/or sale are prohibited under any applicable laws and regulations. ? the information contained herein is presented only as a gui de for the applications of our products. no responsibility is assumed by toshiba for any infringements of patents or other rights of the third partie s which may result from its use. no license is granted by implicat ion or otherwise under any patents or other rights of toshiba or the third parties. ? please contact your sales representative for product- by-product details in this document regarding rohs compatibility. please use these products in this document in compliance with all applicable laws and regulations that regulate the inclusion or use of cont rolled substances. toshiba assumes no liability for damage or losses occurring as a result of noncompliance with applicable laws and regulations. tmp91cw40 2008-09-19 91cw40-2 (5) 8-bit timer: 4 channels (6) 16-bit timer: 3 channels (7) divider output (8) general-purpose serial interface: 4 channels ? both uart and synchronous transfer modes are supported. (9) 10-bit ad converter (with sample-and-hold): 4 channels (10) watchdog timer (11) key-on wakeup: 4 channels (12) real-time clock (rtc) ? based on the tc8521a specifications (13) melody/alarm generator (mld) (14) program patch logic: 6 banks (15) lcd driver/controller (voltage reducer type, reference voltage = vcc) ? lcd direct drive possible (8 to 40 segments x 4 commons) ? 1/4 duty, 1/3 duty, 1/2 duty or static drive selectable (16) interrupts: 43 sources ? 9 cpu interrupts: triggered by a software interrupt instruction or undefined instruction ? 27 internal interrupts: 7 priority levels ? 7 external interrupts: 7 priority levels (two interrupts support selection of triggering edge.) (17) input/output ports: 61 pins (18) standby function three halt modes (programmable idle2, idle1, stop) (19) clock control function ? low-frequency clock (fs = 32.768 khz) (20) operating voltage range ? vcc = 2.7 to 3.6 v (fc max = 27 mhz) ? vcc = 2.2 to 3.6 v (fc max = 16 mhz) (vcc 2.7v: lcdd disabled.) (21) package: lqfp100-p-1414-0.50f tmp91cw40 2008-09-19 91cw40-3 figure 1.1 tmp91cw40 block diagram x1 x2 power supply pins high-frequency oscillator connecting pins input/output ports (segment outputs) dvdd dvss address/data bus system controller standby controller high- frequency low- frequency clock generator tlcs-900/l1 cpu ram 4 kb rom 128 kb interrupt controller ad converter power supply analog reference power supply input/output ports avcc,avss vrefh,vrefl p50 (an0/kwi0) p51 (an1/kwi1) p52 (an2/kwi2) p53 (an3/ adtrg /kwi3) seg7 to seg0 p6 10-bit ad converter p5 p8 asynchronous/ synchronous serial interface sio0 address/data bus common outputs com3 to com0 lcd driver (automatic display) p0 p07 (seg31) to p00 (seg24) pb pb7 (seg39) to pb0 ( seg32 ) lcd power supply circuit lcd driver power supply c0 c1 v1 v2 v3 reset pin reset test pins am1, am0 emu1, emu0 tc5 8-bit timer/counter tc6 tc7 tc8 tc1 16-bit timer/counter watchdog timer p80(tc5out) p81(tc6out) p82(tc7out) p83(tc8out) p60(int0) p61(int1) p62( alarm ) xt1 xt2 low-frequency oscillator connecting pins p2 p27 (seg15) to p20 ( seg8 ) p1 p17 (seg23) to p10 (seg16) tc2 tc3 p7 p70(ecnt1) p71(ecnt2) p72(ecnt3/ dvo / mldalm ) p73(ecin1) p74(ecin2) p75(ecin3) sio1 sio2 sio3 p9 p90(txd0) p91(rxd0) p92(sclk0/ 0cts ) p93(txd1) p94(rxd1) p95(sclk1/ 1cts ) rtc pa pa0(txd2) pa1(rxd2) pa2(sclk2/ 2cts ) pa3(txd3) pa4(rxd3) pa5(sclk3/ 3cts ) input ports nmi mld tmp91cw40 2008-09-19 91cw40-4 2. pin assignments and pin functions the assignment of input/output pins for the tmp91cw40, their names and functions are follows: 2.1 pin assignments figure 2.1.1 shows the pin assignments of the TMP91CW40FG. p82/tc7ou t TMP91CW40FG lqfp100 top view 1 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 p82 /tc8out dvcc p62/ alarm p90/txd0 p91/r xd0 p92/ sclk0/ cts0 p93/txd1 p94/rxd1 p95/sclk1/ cts1 dvss pa0 /txd2 pa 1 / r xd 2 pa2/sclk2/ cts2 pa3 /txd3 pa 4 / r xd 3 pa5/ sclk3/ cts3 nmi p60/int0 p61/int1 p70/ecnt1 p72/ecnt3/ dvo / mldalm dvcc seg6 seg7 dvcc dvss p20/seg8 p21/seg9 p22/seg10 p23/seg11 p24/seg12 p25/seg13 p26/seg14 p27/seg15 p11/seg17 p12/seg18 p13/seg19 p14/seg20 p15/seg21 p16/seg22 p17/seg23 p00/seg24 p01/seg25 p02/seg26 p03/seg27 p04/seg28 p0 5/seg29 p06/seg30 p07/seg31 dvcc dvss pb0/seg32 pb1/seg33 pb2/seg34 pb3/seg35 pb4/seg36 pb5/seg37 pb6/seg38 pb7/seg39 p7 5/ec in3 p74/ecni2 p73/ecin1 em u1 emu0 xt2 xt1 am1 x1 dvss x2 vrefl v3 a vss p53/an3/ /kwi 3 p52/an2/kwi2 p51 /an1 /kwi1 p50 /an0 /kwi0 p80/tc5out v2 v1 c0 com0 com1 com2 com3 seg0 seg1 seg2 seg3 seg4 p81 /tc6out am 0 seg5 a vcc p71/ecnt2 reset p10/seg16 c1 adtrg vrefh figure 2.1.1 TMP91CW40FG pin assignments (100-pin lqfp, top view) tmp91cw40 2008-09-19 91cw40-5 2.2 pin names and functions table 2.2.1 to table 2.2.2 list the names and functions of the input and output pins of the tmp91cw40. t able 2.2.1 pin names and functions (1/2) pin name number of pins i/o function p50 to p53 an0 to an3 adtrg kwi0 to kwi3 4 input input input input port 5: input port analog input: input to the ad converter ad trigger: external start request pin for the ad converter (multiplexed with p53) key-on wakeup input (multiplexed with p50 to p53) p60 int0 1 input input port 60: input port interrupt request pin 0: programmable as high-level, low-level, rising-edge or falling-edge sensitive p61 int1 1 i/o input port 61: input/output port interrupt request pin 1: programmable as high-level, low-level, rising-edge or falling-edge sensitive p62 alarm boot 1 output output input port 62: input/output port rtc alarm output pin boot mode control pin for flash memory (spec ifically designed for 91fw40; to be pulled up during the reset period) note: in normal mode, do not input low level on this pin during the reset period. if low level is input, boot mode will be entered. p70 ecnt1 1 i/o input port 70: input/output port 16-bit timer 1 input: count cont rol input for 16-bit timer tc1 p71 ecnt2 1 i/o input port 71: input/output port 16-bit timer 2 input: count cont rol input for 16-bit timer tc2 p72 ecnt3 dvo mldalm 1 i/o input output output port 72: input/output port 16-bit timer 3 input: count cont rol input for 16-bit timer tc3 divider output pin melody/alarm output pin p73 ecin1 1 i/o input port 73: input/output port 16-bit timer 1 input: count input for 16-bit timer tc1 p74 ecin2 1 i/o input port 74: input/output port 16-bit timer 2 input: count input for 16-bit timer tc2 p75 ecin3 1 i/o input port 75: input/output port 16-bit timer 3 input: count input for 16-bit timer tc3 p80 tc5out 1 i/o output port 80: input/output port (large-current port 8-bit timer 5 output: output pin for 8-bit timer tc5 open-drain output mode by programmable p81 tc6out 1 i/o output port 81: input/output port (large-current port) 8-bit timer 6 output: output pin for 8-bit timer tc6 open-drain output mode by programmable p82 tc7out 1 i/o output port 82: input/output port (large-current port) 8-bit timer 7 output: output pin for 8-bit timer tc7 open-drain output mode by programmable p83 tc8out 1 i/o output port 83: input/output port (large-current port) 8-bit timer 8 output: output pin for 8-bit timer tc8 open-drain output mode by programmable p90 txd0 1 i/o output port 90: input/output port serial 0 transmit data open-drain output mode by programmable p91 rxd0 1 i/o input port 91: input/output port serial 0 receive data p92 sclk0 0cts 1 i/o i/o input port 92: input/output port serial 0 clock input/output serial 0 data transmit enable (clear to send) tmp91cw40 2008-09-19 91cw40-6 table 2.2.2 pin names and functions (2/2) pin name number of pins i/o function p93 txd1 1 i/o output port 93: input/output port serial 1 transmit data open-drain output mode by programmable p94 rxd1 1 i/o input port 94: input/output port serial 1 receive data p95 sclk1 cts1 1 i/o i/o input port 95: input/output port serial 1 clock input/output serial 1 data transmit enable (clear to send) pa0 txd2 1 i/o output port a0: input/output port serial 2 transmit data open-drain output mode by programmable pa1 rxd2 1 i/o input port a1: input/output port serial 2 receive data pa2 sclk2 cts2 1 i/o i/o input port a2: input/output port serial 2 clock input/output serial 2 data transmit enable (clear to send) pa3 txd3 1 i/o output port 3: input/output port serial 3 transmit data open-drain output mode by programmable pa4 rxd3 1 i/o input port a4: input/output port serial 3 receive data pa5 sclk3 cts3 1 i/o i/o input port a5: input/output port serial 3 clock input/output serial 3 data transmit enable (clear to send) seg0 to seg7 8 output segment output p20 to p27 seg8 to seg15 8 i/o output port 2: input/output port segment output p10 to p17 seg16 to seg23 8 i/o output port 1: input/output port segment output p00 to p07 seg24 to seg31 8 i/o output port 0: input/output port segment output pb0 to pb7 seg32 to seg39 8 i/o output port b: input/output port segment output c0,c1 2 lcd drive power supply v1 to v3 3 lcd drive power supply com0 to com3 4 common output nmi 1 input nonmaskable interrupt request pin: causes an nmi interrupt on the falling edge; programmable to be rising-edge s ensitive (schmitt input). am0, am1 2 input operation mode both am0 and am1 should be held at logic 1. emu0 1 output this pin should be left open. emu1 1 output this pin should be left open. reset 1 input reset: initializes the tmp91cw40. (schmitt input, with pull-up resistor) vrefh 1 input input pin for high reference voltage for the ad converter vrefl 1 input input pin for low reference voltage for the ad converter avcc 1 power supply pin for the ad converter avss 1 ground pin for the ad converter (0 v) x1/x2 2 i/o connection pins fo r a high-frequency oscillator xt1/xt2 2 i/o connection pins for a low-frequency oscillator dvcc dvss 4 4 power supply pins (the dvcc pins should be connected to power supply.) ground pins (the dvss pins shoul d be connected to ground (0 v).) tmp91cw40 2008-09-19 91cw40-7 3. operation this section describes the functions and basic operation of the tmp91cw40. 3.1 cpu the tmp91cw40 contains a high-performance 16-bit cpu (900/l1 cpu). for a detailed description of the cpu, refer to ?tlcs- 900/l1 cpu? in the preceding chapter. functions unique to the tmp91cw40 not cove red in ?tlcs-900/l1 cpu? are described below. 3.1.1 reset operation to reset the tmp91cw40, ensure that the power supply voltage is within the operating voltage range, and that the internal high-frequency oscillator has stabilized. then, set the reset input to low level for at least 10 system clocks (1s at 27 mhz). after turning on the power to the tmp91cw40, hold the reset input at low level for at least 10 system clocks with the power supply voltage within the operating voltage range and the internal high-frequency oscillator oscillating stably. reset operation initializes the system clock f sys to fc/2. the cpu performs the following operations as a result of a reset: ? sets the program counter (pc) according to the reset vector stored at addresses ffff00h to ffff02h. pc < 7:0 > value at address ffff00h pc < 15:8 > value at address ffff01h pc < 23:16 > value at address ffff02h ? sets the stack pointer (xsp) to 100h. ? sets the tmp91cw40 2008-09-19 91cw40-8 f fph sampling indicates high-impedance state. sampling (input mode) rese t p62 p70 to p75 p80 to p83 p90 to p95, pa0 to pa5 pb0 to pb7(seg32 to seg39) p00 to p07(seg24 to seg31) p10 to p17(seg16 to seg23) p20 to p27(seg8 to seg15) seg0 to seg7 (input mode) com0 to com3 (output mode) (input mode) p62 tmp91fw40 only, (pull-up) figure 3.1.1 tmp91cw40 reset timings tmp91cw40 2008-09-19 91cw40-9 3.2 memory map figure 3.2.1 shows a memory map of the tmp91cw40. figure 3.2.1 memory map 000000h 001000h 16-mbyte area (r) ( ? r) (r + ) (r + r8/16) (r + d8/16) (nnn) direct area ( n ) 64-kbyte area (nn) internal rom ( 128 kb y tes ) internal i/o (4 kbytes) internal ram (4 kbytes) 002000h 010000h fe0000h ( = internal area) ffff00h ffffffh vector table (256 bytes) external memory (access prohibited) 000100h tmp91cw40 2008-09-19 91cw40-10 3.3 system clock/standby control and noise reduction the tmp91cw40 incorporates clock gear, stan dby control and noise reduction circuits to minimize power consumption and no ise. single-clock mode (x1 and x2 pins only) and dual-clock mode (x1, x2, xt1, and xt2 pins) are supported. figure 3.3.1 shows state transitions in each clock mode. figure 3.3.1 state transitions in each operation mode the clock frequency terms used in this document are defined as follows: fc: clock frequency supplied via the x1 and x2 pins fs: clock frequency supplied via the xt1 and xt2 pins f fph : clock frequency select ed by syscr1 tmp91cw40 2008-09-19 91cw40-11 3.3.1 system clock block diagram figure 3.3.2 system clock block diagram warm-up (for high- and low-frequency oscillators) syscr0 tmp91cw40 2008-09-19 91cw40-12 3.3.2 sfrs 7 6 5 4 3 2 1 0 bit symbol xen xten rxen rxten rsysck wuef ? ? read/write r/w after reset 1 0 1 0 0 0 0 0 function high- frequency oscillator 0: stop 1: active low- frequency oscillator 0: stop 1: active high- frequency oscillator after release of stop mode 0: stop 1: active low- frequency oscillator after release of stop mode 0: stop 1: active clock selection after release of stop mode 0: high- frequency 1: low- frequency warm-up timer (wup) control 0 write: don?t care 1 write: start wup 0 read: wup finished 1 read: wup counting always write 00. bit symbol sysck ? ? ? read/write r/w after reset 0 0 0 0 function system clock selection 0: high- frequency (fc) 1: low- frequency (fs) always write 000. bit symbol ? wuptm1 wuptm0 haltm1 haltm0 drve read/write r/w r/w r/w r/w r/w r/w after reset 0 1 0 1 1 0 function always write 0. oscillator warm-up time 00: reserved 01: 2 8 /input frequency 10: 2 14 /input frequency 11: 2 16 /input frequency halt mode selection 00: reserved 01: stop mode 10: idle1 mode 11: idle2 mode 1: pins are driven in stop mode. bit symbol lcdckmod read/write r/w after reset 0 function lcd clock 0: fc 1: fs note: bits 7 to 4 of the syscr1 and bits 7 and 1 of the syscr2 are read as undefined. figure 3.3.3 sfrs for the system clock syscr0 (00e0h) syscr1 (00e1h) syscr3 (00e5h) syscr2 (00e2h) tmp91cw40 2008-09-19 91cw40-13 7 6 5 4 3 2 1 0 bit symbol protect ? ? ? ? extin drvosch drvoscl read/write r r/w r/w r/w r/w r/w r/w r/w after reset 0 0 1 0 0 0 1 1 function protection flag 0: off 1: on always write 0. always write 1. always write 0. always write 0. 1: external clock used as fc fc oscillator drive capability 1: normal 0: weak fs oscillator drive capability 1: normal 0: weak bit symbol read/write after reset function writing 1fh disables protection. writing a value other than 1fh enables protection. note: in case restarting the oscillator in the stop oscillation state (e.g. restart the oscillator in stop mode), set emccr0 tmp91cw40 2008-09-19 91cw40-14 3.3.3 system clock control unit the system clock control unit generates system clock pulses (f sys ) that are supplied to the cpu core and internal i/o. it accepts either fc or fs clock pulses generated by the high-frequency or low-frequency oscillator, respectively. syscr1 tmp91cw40 2008-09-19 91cw40-15 example 1 changing the system clock from high-frequency (fc) to low-frequency (fs) syscr0 equ 00e0h syscr1 equ 00e1h syscr2 equ 00e2h ld (syscr2), x ? 11 ? ?x ? b ; set warm-up time to 2 16 /fs. set 6, (syscr0) ; enable low-frequency oscillator. set 2, (syscr0) ; clear and start warm-up timer. wup: bit 2, (syscr0) ; jr nz, wup ; detect completion of warming up. set 3, (syscr1) ; change f sys from fc to fs. res 7, (syscr0) ; disable high-frequency oscillator. x: don?t care, ? : no change count up fs pulses fc syscr0 tmp91cw40 2008-09-19 91cw40-16 example 2 changing the system clock from low-frequency (fs) to high-frequency (fc) syscr0 equ 00e0h syscr1 equ 00e1h syscr2 equ 00e2h ld (syscr2), x ? 10 ? ?x ? b ; set warm-up time to 2 14 /fc. set 7, (syscr0) ; enable high-frequency oscillator. set 2, (syscr0) ; clear and start warm-up timer. wup: bit 2, (syscr0) ; jr nz, wup ; detect completion of warming up. res 3, (syscr1) ; change f sys from fs to fc. res 6, (syscr0) ; disable low-frequency oscillator. x: don?t care, ? : no change count up fc pulses fs syscr0 tmp91cw40 2008-09-19 91cw40-17 3.3.4 prescaler clock control unit the internal i/o functions (sio0 to sio3) are provided with a clock prescaler. the prescaler clock sources t and t0 are f fph / 2 and f fph / 4, respectively. 3.3.5 noise reduction circuits the tmp91cw40 incorporates circuits providing the following features to reduce electromagnetic interference (emi) and electromagnetic susceptibility (ems): (1) reducing drive capability of the high-frequency oscillator (2) reducing drive capability of the low-frequency oscillator (3) canceling double-drive operation of the high-frequency oscillator (4) preventing software or system lockups using a protection register these features are specified using the emccr0 and emccr1 registers, as described below. (1) reducing drive capability of the high-frequency oscillator purpose: to suppress noise generated by the high-fr equency oscillator and to reduce power consumption of the high-frequency oscillator when an external resonator is connected. block diagram: description: setting the tmp91cw40 2008-09-19 91cw40-18 (2) reducing drive capability of the low-frequency oscillator purpose: to suppress noise generated by the low-frequency oscillator and to reduce power consumption of the low-frequency oscillator when an external resonator is connected. block diagram: description: setting the tmp91cw40 2008-09-19 91cw40-19 (4) preventing software or system lockups using a protection register purpose: to prevent software or system lockups that may occur due to incoming noise. applying protection causes specified sfrs to be write-protected, thus preventing the system recovery routine from becoming unfetchable, for example, if the system clock stops or a memory control register (cs/wait controller) is modified. applicable sfrs 1. clock gear (only emccr1 can be written.) syscr0, syscr1, syscr2, syscr3, emccr0 block diagram: description: writing any code other than 1fh to the emccr1 register enables protection, preventing specified sfrs from being written. writing 1fh to the emccr1 register cancels protection. the state of protection can be determined by reading the tmp91cw40 2008-09-19 91cw40-20 3.3.6 standby control (1) halt mode executing the halt instruction causes the tmp91cw40 to enter one of the halt modes?idle2, idle1 or stop?as specified by the syscr2 tmp91cw40 2008-09-19 91cw40-21 (2) wakeup signaling there are two ways to exit a halt mode: an interrupt request or reset signal. availability of wakeup signaling depends on the settings of the interrupt mask level bits, tmp91cw40 2008-09-19 91cw40-22 table 3.3.4 wakeup signaling sources and wakeup operations interrupt masking unmasked interrupt (request level) (mask level) masked interrupt (request level) < (mask level) halt mode programmable idle2 idle1 stop programmable idle2 idle1 stop interrupts nmi intwd int0,int1, kwi0 to kwi3 note 1) intalm0 to intalm4 intrtc inttmr1 to inttmr3, inttmr5 to inttmr8 intrx0 to intrx3, inttx0 to inttx3 intad ? ? ? ? ? ? ? ? ? ? ? ? ? ? * 1 ? * 1 ? ? ? ? ? ? ? ? ? ? ? ? ? * 1 wakeup signaling sources reset initializes the whole tmp91cw40. ? : execution resumes with the interrupt service routine. ? : execution resumes with the instruction immediately followi ng the halt instruction. (the interrupt is not serviced.) : cannot be used to exit a halt mode. ? : these combinations are not possibl e because nonmaskable interrupts are assi gned the highest priority level (7). * 1: the tmp91cw40 exits the halt mode after the warm-up period timer expires. note 1: if the interrupt request level is greater than the mask le vel, an int0 or int1 interrupt signal which is programmed as level-sensitive must be held high until interrupt processing begi ns. otherwise, the interrupt will not be serviced successfully . example of exiting a halt mode when using an edge-sensitive int0 interrupt to exit idle1 mode address fe8200h ld (p6fc), 01h ; set p60 to int0. fe8203h ld (iimc), 00h ; set int0 interrupt to rising-edge sensitive. fe8206h ld (inte0ad), 06h ; set int0 interrupt priority level to 6. fe8209h ei 5 ; set cpu interrupt priority level to 5. fe820bh ld (syscr2), 28h ; select idle1 mode. fe820eh halt ; stop cpu. int0 int0 interrupt service routine reti fe820fh ld xx, xx tmp91cw40 2008-09-19 91cw40-23 (3) operation in halt modes a. idle2 mode in idle2 mode, the cpu stops executing instructions and only the internal i/o functions enabled with the idle2 setting bits in respective sfrs are operational. figure 3.3.5 shows example timings for ex it ing id le2 m ode with an interrupt. figure 3.3.5 example timings for exiting a halt mode (idle2 mode) with an interrupt b. idle1 mode in idle1 mode, the system clock stops while only the internal oscillator and time-of-day clock timer are active. interru pt requests are sampled asynchronously with the system clock in a halt state, but the halt mode is exited in synchronization with the system clock. figure 3.3.6 shows example timings for ex it ing i d le1 m ode with an interrupt. figure 3.3.6 example timings for exiting a halt mode (idle1 mode) with an interrupt address address + 2 x1 a0 to a23 wakeup interrupt idle2 mode wakeup interrupt address address + 2 a0 to a23 idle1 mode x1 rd rd tmp91cw40 2008-09-19 91cw40-24 c. stop mode in stop mode, the whole tmp91cw40 stops, including the internal oscillator. pin states in stop mode depend on the setting of the syscr2 tmp91cw40 2008-09-19 91cw40-25 example: entering stop mode while using the low-frequency clock, exiting stop mode with an nmi interrupt, and then resuming operation with the high-frequency clock ?: no change note: when different system clock frequencies are to be us ed before entering and after exiting stop mode as shown above, if a wakeup interrupt is accepted while the halt in struction is being executed (a period of 6 states), stop mode may be exited without the system clock frequency being changed. in a system where interrupts are input during execution of the halt instruction, use the same system clock frequency before entering and after exiting stop mode. address syscr0 equ 00e0h syscr1 equ 00e1h syscr2 equ 00e2h fe8ffdh ld (syscr1), 08h ; f sys =fs/2 fe9000h ld (syscr2), x ? 1001x1b ; warm-up time = 2 14 /fc fe9002h ld (syscr0), 01100000b ; enable high-frequency clock after exiting stop mode fe9005h halt nmi pin input fe9006h ld xx, xx reti warm-up timer clear & start (high-frequency clock) warm-up complete nmi interrupt service routine tmp91cw40 2008-09-19 91cw40-26 table 3.3.6 tmp91cw40 input buffer state table input buffer state in halt mode (stop) when the cpu is operating in halt mode (idle2/idle1) tmp91cw40 2008-09-19 91cw40-27 3.4 interrupts interrupt processing is controlled by the cp u interrupt mask register sr tmp91cw40 2008-09-19 91cw40-28 figure 3.4.1 overall interrupt servicing flow general interrupt servicing interrupt specified by micro dma start vector? yes interrupt servicing push pc push sr sr tmp91cw40 2008-09-19 91cw40-29 3.4.1 general interrupt servicing the cpu performs the following operations once it accepts an interrupt. these operations are the same as those performed by the tlcs-900/l and tlcs-900/h. (1) reads an interrupt vector from the interrupt controller. if two or more interrupts having the same priority level occur simultaneously, the interrupt controller generates an interrupt vect or according to default priorities (fixed, higher priorities assigned to smaller vector values) and clears the interrupt request. (2) pushes the contents of the program counter (pc) and status register (sr) to the stack area indicated by the xsp. (3) sets the interrupt mask register bits to one level higher than the accepted interrupt level. if the level is 7, however, the cpu sets tmp91cw40 2008-09-19 91cw40-30 table 3.4.1 interrupt vector table default priority type interrupt source vector value vector reference address micro dma start vector 1 reset or swi0 instruction 0000h ffff00h ? 2 swi1 instruction 0004h ffff04h ? 3 intundef: undefined instruction or swi2 instruction 0008h ffff08h ? 4 swi3 instruction 000ch ffff0ch ? 5 swi4 instruction 0010h ffff10h ? 6 swi5 instruction 0014h ffff14h ? 7 swi6 instruction 0018h ffff18h ? 8 swi7 instruction 001ch ffff1ch ? 9 nmi pin 0020h ffff20h ? 10 non- maskable intwd: watchdog timer 0024h ffff24h ? ? (micro dma) ? ? ? 11 int0 pin 0028h ffff28h 0ah 12 int1 pin, kwi0 to kwi3 pins 002ch ffff2ch 0bh 13 intalm0: alm0 (8192 hz) 0030h ffff30h 0ch 14 intalm1: alm1 (512 hz) 0034h ffff34h 0dh 15 intalm2: alm2 (64 hz) 0038h ffff38h 0eh 16 intalm3: alm3 (2 hz) 003ch ffff3ch 0fh 17 intalm4: alm4 (1 hz) 0040h ffff40h 10h 18 inttmr5: 8-bit timer 5 (tc5) 0044h ffff44h 11h 19 inttmr6: 8-bit timer 6 (tc6) 0048h ffff48h 12h 20 inttmr7: 8-bit timer 7 (tc7) 004ch ffff4ch 13h 21 inttmr8: 8-bit timer 8 (tc8) 0050h ffff50h 14h 22 inttmr1: 16-bit timer 1 (tc1) 0054h ffff54h 15h 23 inttmr2: 16-bit timer 2 (tc2) 0058h ffff58h 16h 24 reserved 005ch ffff5ch ? 25 reserved 0060h ffff60h ? 26 reserved 0064h ffff64h ? 27 reserved 0068h ffff68h ? 28 inttmr3: 16-bit timer 3 (tc3) 006ch ffff6ch 1bh 29 reserved 0070h ffff70h ? 30 intrx0: serial receive (channel 0) 0074h ffff74h 1dh 31 inttx0: serial transmit (channel 0) 0078h ffff78h 1eh 32 intrx1: serial receive (channel 1) 007ch ffff7ch 1fh 33 inttx1: serial transmit (channel 1) 0080h ffff80h 20h 34 reserved 0084h ffff84h ? 35 reserved 0088h ffff88h ? 36 intrx2: serial receive (channel 2) 008ch ffff8ch 23h 37 inttx2: serial transmit (channel 2) 0090h ffff90h 24h 38 intrx3: serial receive (channel 3) 0094h ffff94h 25h 39 inttx3: serial transmit (channel 3) 0098h ffff98h 26h 40 intad: ad conversion complete 009ch ffff9ch 27h 41 inttc0: micro dma complete (channel 0) 00a0h ffffa0h 42 inttc1: micro dma complete (channel 1) 00a4h ffffa4h 43 inttc2: micro dma complete (channel 2) 00a8h ffffa8h 44 inttc3: micro dma complete (channel 3) 00ach ffffach 45 maskable intrtc: rtc (alarm interrupt) 00b0h ffffb0h 2ch (reserved) : (reserved) 00b4h : 00fch ffffb4h : fffffch ? : ? tmp91cw40 2008-09-19 91cw40-31 3.4.2 micro dma in addition to general interrupt servicing, the tmp91cw40 supports a micro dma feature. interrupt requests specified with the micro dma are assigned highest priority levels among maskable interrupts regardless of the priority levels actually set. the micro dma consists of four channels so that continuous transfer can be performed using burst specification, described later. because the micro dma feature is realized in cooperation with the cpu, micro dma requests are ignored and remain pending if the cpu executes the halt instruction and enters a standby state. (1) micro dma operation if an interrupt specified with the micro dma start vector register is requested, the micro dma transfers data to the cpu assu ming the highest priority level for a maskable interrupt regardless of the priority level assigned to the interrupt source. micro dma requests are not, however, accepted when tmp91cw40 2008-09-19 91cw40-32 the micro dma supports three transfer mo des: 1 byte, 2 bytes or 4 bytes. for each transfer mode, the transfer sou rce and destination addresses can be incremented, decremented or fixed after the transfer of a single unit of data. this ability to select various mo des facilitates data transfer from i/o to memory, memory to i/o, and i/o to i/o. for detail s of transfer modes, see ?(4) transfer mode registers?. the transfer counter consists of 16 bits so that up to 65536 micro dma transfers (if the counter defaults to 0000h) can be performed for a single interrupt source. the micro dma supports 19 inte rrupt sources as shown in table 3.4.1 as well as a soft start. figure 3.4.2 shows micro dma cycles for 2-by te transfer in th e t ransfer destination address increment mode (with all address ar eas accessed with a 16 -bit data bus, no wait cycles, and even-numbered source/destination addresses). figure 3.4.2 micro dma cycles 1st to 3rd states: instruction fetch cycles (prefetching next instruction code). if three or more bytes of instructio n code are stored in the instruction queue buffer, these cycles become dummy cycles. 4th to 5th states: micro dma read cycles 6th state: dummy cycle (address bus left in the 5th state). 7th and 8th states: micro dma write cycle note 1: if the source address area uses an 8-bit bus, additional two states are needed. if the source address area uses a 16-bit bus but starts with an odd-numbered address, additional two states are needed. note 2: if the destinatin address area uses an 8-bit bus, additional two states are needed. if the destination address area uses a 16-bit bus but star ts with an odd-numbered address, additional two states are needed. output input source address + 2 address 1 state d0 d15 x1 a 0a23 dm1 dm2 dm3 dm4 dm5 dm6 dm7 dm8 note 1 note 2 rd wr / hwr destination tmp91cw40 2008-09-19 91cw40-33 (2) soft start in addition to interrupt sources, the micro dma can also be started by software. this soft start feature enables the micro dma to be started upon the detection of a write cycle to the dmar register. writing 1 to each bit in the dmar register starts a micro dma transfer in the corresponding channel. when the transfer is completed, the bit is automatically cleared to 0. only one channel can be starte d at a time. (do not write 1 to more than one bit in the dmar register at the same time.) a dmar register bit must be verified to be 0 before it can be set to 1 again. if read 1, micro dma transfer isn?t started yet. when a burst transfer is specified in the dmab register, the micro dma channel that has been once started continues transf erring data until the micro dma transfer counter reaches zero. if execute soft star t during micro dma transfer by interrupt source, micro dma transfer counter doesn?t change. don?t use read-modify-write instruction to avoid writing to other bits by mistake. symbol name address 7 6 5 4 3 2 1 0 dmar3 dmar2 dmar1 dmar0 r / w 0 0 0 0 dmar dma software request register 89h (read- modify-write instructions are prohibited) 1: dma request (3) transfer control registers the following registers in the cpu are used to control the transfer source and destination addresses. use the ?ldc cr, r? instruction to set data in these registers. channel 0 dmas0 transfer source address register 0; only lower 24 bits are used. dmad0 transfer destination address register 0; only lower 24 bits are used. dmac0 transfer counter register 0; 1 to 65536 dmam0 transfer mode register 0 channel 3 dmas3 transfer source address register 3 dmad3 transfer destination address register 3 dmac3 transfer counter register 3 dmam3 transfer mode register 3 8 bits 16 bits 32 bits tmp91cw40 2008-09-19 91cw40-34 (4) transfer mode registers: dmam0 to dmam3 (dmam0 to dmam3) 0 0 0 mode 0 0 0 z z 8 states (593 ns) byte/word transfer destination address increment mode ....................... i/o to memory (dmadn + ) (dmasn) dmacn dmacn ? 1 if dmacn = 0 then inttc occurs 12 states (889 ns) 4-byte transfer 0 0 1 z z 8 states (593 ns) byte/word transfer destination address decrement mode ...................... i/o to memory (dmadn ? ) (dmasn) dmacn dmacn ? 1 if dmacn = 0 then inttc occurs 12 states (889 ns) 4-byte transfer 0 1 0 z z 8 states (593 ns) byte/word transfer source address increment mode.............................. memory to i/o (dmadn) (dmasn +) dmacn dmacn ? 1 if dmacn = 0 then inttc occurs 12 states (889 ns) 4-byte transfer 0 1 1 z z 8 states (593 ns) byte/word transfer source address decrement mode ........................... memory to i/o (dmadn) (dmasn ?) dmacn dmacn ?1 if dmacn = 0 then inttc occurs 12 states (889 ns) 4-byte transfer 1 0 0 z z 8 states (593 ns) byte/word transfer fixed address mode ................................................. i/o to i/o (dmadn) (dmasn) dmacn dmacn ? 1 if dmacn = 0 then inttc occurs 12 states (889 ns) 4-byte transfer 1 0 1 0 0 counter mode counting the number of interrupts that have occurred dmasn dmasn + 1 dmacn dmacn ? 1 if dmacn = 0 then inttc occurs 5 states (370 ns) note 1: n: corresponding micro dma channel (0 to 3) dmadn+ /dmasn + : post-increment (incrementing the register value after transfer) dmadn? /dmasn ? : post-decrement (decrementing the register value after transfer) in the table, ?i/o? means a fixed address while ?memory? means an address that can be incrementaed or decremented. note 2: execution time: the time required to complete transfe rring a single unit of data when a 16-bit bus is used for the sour ce and destination address areas and no wait cycles are inserted. clock settings: fc = 27 mhz, cloock gear = x1 (fc) note 3: any code other than those listed above must not be written to transfer mode registers. note: the upper three bits of data written to these registers must always be ?0?. zz: 0 = byte transfer, 1 = word transfer, 2 = 4-byte transfer, 3 = reserved execution time tmp91cw40 2008-09-19 91cw40-35 3.4.3 interrupt controller figure 3.4.3 shows a block diagram of the in terrupt circuit. the left-hand side of the diagram shows the interrupt controller while the right-hand side shows the cpu?s interrupt request signal circuit and halt wakeup circuit. for each of the 25 interrupt channels there is an interrupt request flag, interrupt priority register and micro dma start vector register. th e interrupt request flag is used to latch an interrupt request issued by peripherals. this flag is cleared in the following cases: ? reset ? the cpu accepts the interrupt and reads the vector for the interrupt. ? an instruction that clears the interrupt is executed. (a dma start vector is written to the intclr register.) ? the cpu accepts a micro dma request for the interrupt. ? micro dma burst transfer for the interrupt completes. priority levels for individual interrupts can be specified using interrupt priority registers (such as inte0ad and inte1alm 0) provided for each interrupt source. six levels of priority (1 to 6) can be set. an interrupt is disabled when its priority level is set to 0 or 7. nonmaskable interrupts ( nmi pin and watchdog timer) have a fixed level of 7. if two or more interrupts having the same priority level occur simutaneously, the cpu accepts interrupts according to default priorities. reading bits 3 and 7 of an interrupt priority register obtains the status of the interrupt request flag, indicating whether an interrupt request is present for the corresponding channel. the interrupt controller determines the interrupt with the highest priority among interrupts occuring simultaneously if any, and sends it priority level and vector address to the cpu. the cpu compares that priority level with the contents of the interrupt mask register, that is, the tmp91cw40 2008-09-19 91cw40-36 i nterrup t requ est if iff = 7, then 0 micro dma st art vect or register inttc 0 inttc1 inttc 2 inttc 3 intrt c v = a0 h v = a4h v = a8h v = ach v = b0h soft s tart micro dma counter 0 interrupt 6 inttc 0 idle1 mod 30 3 3 3 1 6 1 7 2 2 4 6 34 4-input or i nt0, int1, rtc, kwi0 t o 3, al m0 to alm4 micro dma channel priority encoder priority encoder dma0v dma1v dma2v dm a3v res et i nterrupt requ es t fl ag reset re set priority setting register v = 20 h v = 24h interrupt contro ll er cpu s q r v = 28h v = 2ch v = 38h v = 3ch v = 40 h d q clr a b c dn dn + 1 dn + 2 interrupt request fl ag interrupt accept micro dma accept inte rrup t requ est flip -floprea d dn + 3 a b c interrupt vec tor v read d 2 d3 d4 d 5 d6 d7 selecto r s q r 0 1 2 3 a b d0 d1 interrupt vector v read cpu interrupt ac c e p tance fla g mi cr o d ma r eq uest halt wakeup nmi if intrq2 to 0 iff 2 to 0, then 1. intrq2 to intrq 0 if f2: 0 determine priority level res et ei1 to 7 di interrupt request signal sto p mod e micro dma channel specification reset nm i intw d int0 int1,kwi0 to kwi 3 intalm 0 intalm1 intalm 2 s interrupt vector gen er ator select highe st prio rity le vel (7 = top priority) 1 2 3 4 5 6 7 d5 d4 d3 d2 d1 d0 d q c lr dec oder y1 y2 y3 y4 y5 y6 figure 3.4.3 interrupt co ntroller block diagram tmp91cw40 2008-09-19 91cw40-37 (1) interrupt priority registers symbol name address 7 6 5 4 3 2 1 0 intad int0 iadc iadm2 iadm1 iadm0 i0c i0m2 i0m1 i0m0 r r/w r r/w inte0ad int0 & intad enable 90h 0 0 0 0 0 0 0 0 intalm0 int1 ia0c ia0m2 ia0m1 ia0m0 i1c i1m2 i1m1 i1m0 r r r r inte1alm0 int1& intalm0 enable 91h 0 0 0 0 0 0 0 0 intalm2 intalm1 ia2c ia2m2 ia2m1 ia2m0 ia1c ia1c ia1m2 ia1m0 r r/w r r/w intealm12 intalm1 & intalm2 enable 92h 0 0 0 0 0 0 0 0 intalm4 intalm3 ia4c ia4m2 ia4m1 ia4m0 ia3c ia3c ia3m2 ia3m0 r r/w r r/w intealm34 intalm3 & intalm4 enable 93h 0 0 0 0 0 0 0 0 inttmr6 (tc6) inttmr5 (tc5) itm6c itm6m2 itm6m1 itm6m0 itm5c itm5m2 itm5m1 itm5m0 r r/w r r/w intetmr56 inttmr5 & inttmr6 enable 94h 0 0 0 0 0 0 0 0 inttmr8 (tc8) inttmr7 (tc7) itm8c itm8m2 itm8m1 itm8m0 itm7c itm7m2 itm7m1 itm7m0 r r/w r r/w intetmr78 inttmr7 & inttmr8 enable 95h 0 0 0 0 0 0 0 0 inttmr2 (tc2) inttmr1 (tc1) itm2c itm2m2 itm2m1 itm2m0 itm1c itm1m2 itm1m1 itm1m0 r r/w r r/w intetmr12 inttmr1 & inttmr2 enable 96h 0 0 0 0 0 0 0 0 ? inttmr3 (tc3) ? ? ? ? itm3c itm3m2 itm3m1 itm3m0 ? ? r r/w intetmr3 inttmr3 enable 99h write ?0?. 0 0 0 0 lxxm2 lxxm1 lxxm0 function (write) 0 0 0 disable interrupt requests. 0 0 1 set interrupt priority level to 1. 0 1 0 set interrupt priority level to 2. 0 1 1 set interrupt priority level to 3. 1 0 0 set interrupt priority level to 4. 1 0 1 set interrupt priority level to 5. 1 1 0 set interrupt priority level to 6. 1 1 1 disable interrupt requests. interrupt request flag tmp91cw40 2008-09-19 91cw40-38 symbol name address 7 6 5 4 3 2 1 0 inttx0 intrx0 itx0c itx0m2 itx0m1 itx0m0 irx0c irx0m2 irx0m1 irx0m0 r r/w r r/w intes0 interrupt enable serial 0 9ah 0 0 0 0 0 0 0 0 inttx1 intrx1 itx1c itx1m2 itx1m1 itx1m0 irx1c irx1m2 irx1m1 irx1m0 r r/w r r/w intes1 interrupt enable serial 1 9bh 0 0 0 0 0 0 0 0 ? intrtc ? ? ? ? irx2c irx2m2 irx2m1 irx2m0 ? ? r r/w intrtc intrtc enable 9ch write ?0?. 0 0 0 0 inttx2 intrx2 itx2c itx2m2 itx2m1 itx2m0 irx2c irx2m2 irx2m1 irx2m0 r r/w r r/w intes2 interrupt enable serial 2 9dh 0 0 0 0 0 0 0 0 inttx3 intrx3 itx3c itx3m2 itx3m1 itx3m0 irx3c irx3m2 irx3m1 irx3m0 r r/w r r/w intes3 interrupt enable serial 3 9eh 0 0 0 0 0 0 0 0 inttc1 inttc0 itc1c itc1m2 itc1m1 itc1m0 itc0c itc0m2 itc0m1 itc0m0 r r/w r r/w intetc01 inttc0 & inttc1 enable a0h 0 0 0 0 0 0 0 0 inttc3 inttc2 itc3c itc3m2 itc3m1 itc3m0 itc2c itc2m2 itc2m1 itc2m0 r r/w r r/w intetc23 inttc2 & inttc3 enable a1h 0 0 0 0 0 0 0 0 lxxm2 lxxm1 lxxm0 function (write) 0 0 0 disable interrupt requests. 0 0 1 set interrupt priority level to 1. 0 1 0 set interrupt priority level to 2. 0 1 1 set interrupt priority level to 3. 1 0 0 set interrupt priority level to 4. 1 0 1 set interrupt priority level to 5. 1 1 0 set interrupt priority level to 6. 1 1 1 disable interrupt requests. interrupt request flag tmp91cw40 2008-09-19 91cw40-39 (2) external interrupt control symbol name address 7 6 5 4 3 2 1 0 ? ? ? i1edge i1le i0edge i0le nmiree w 0 0 0 0 0 0 0 0 iimc interrupt input control 8ch (read- modify-write instructions are prohibited) always write ?0?. int1 edge polarity 0: rising 1: falling int1 sensitivity 0: edge 1: level int0 edge polarity 0: rising 1: falling int0 sensitivity 0: edge 1: level 1: also triggered by nmi rising edge int1 sensitivity 0 edge-triggered 1 level-sensitive int0 sensitivity 0 edge-triggered 1 level-sensitive nmi rising edge enable 0 int request occurs at falling edge only 1 int request occurs at rising/falling edge note: when int1 is is set to be level-sensitive, the key-on wakeup function must be disabled. (3) interrupt request flag clear register an interrupt request flag can be cleared by writing a micro dma start vector (see table 3.4.1) to the intclr register. for example , the int0 interrupt flag can be cleared by the following register operation after execution of the di instruction. intclr 0ah clear the int0 interrupt request flag symbol name address 7 6 5 4 3 2 1 0 clrv5 clrv4 clrv3 clrv2 clrv1 clrv0 w 0 0 0 0 0 0 intclr interrupt clear control 88h (read- modify-write instructions are prohibited) w riting a dma start vector clears the corresponding interrupt request flag. tmp91cw40 2008-09-19 91cw40-40 (4) micro dma start vector registers a micro dma start vector register specifie s which interrupt source is assigned to micro dma processing. the interrupt sour ce having the micro dma start vector specified in this register is assi gned as a micro dma request source. when the micro dma transfer counter reache s zero, the interrupt controller receives a request from the cpu and generates a micro dma transfer complete interrupt for the relevant channel. then, the cpu clears th e micro dma start vector register, thus clearing the micro dma request source for the channel. if it is necessary to continue micro dma processing, the micro dma start vector register must be set again in the service routine for the micro dma transfer complete interrupt. if the same vector is set in two or more micro dma start vector registers at the same time, the channel having the smallest number takes precedence. therefore, if the same vector is set in the micro dma start vector registers of two channels, micro dma transfer is first performed with the smaller-numbered channel until it completes. unless the interrupt controller reloads the mi cro dma start vector for this channel, micro dma transfer is then performed with the larger-numbered channel (micro dma chaining). symbol name address 7 6 5 4 3 2 1 0 dma0v5 dma0v4 dma0v3 dma0v2 dma0v1 dma0v0 r/w 0 0 0 0 0 0 dma0v dma0 start vector 80h dma0 start vector dma1v5 dma1v4 dma1v3 dma1v2 dma1v1 dma1v0 r/w 0 0 0 0 0 0 dma1v dma1 start vector 81h dma1 start vector dma2v5 dma2v4 dma2v3 dma2v2 dma2v1 dma2v0 r/w 0 0 0 0 0 0 dma2v dma2 start vector 82h dma2 start vector dma3v5 dma3v4 dma3v3 dma3v2 dma3v1 dma3v0 r/w 0 0 0 0 0 0 dma3v dma3 start vector 83h dma3 start vector (5) micro dma burst specification the micro dma supports burst specification, with which a single micro dma startup can cause transfer to continue until the transfer counter register reaches zero. burst transfer can be specified by setting the dmab register bit corresponding to each micro dma channel to 1. symbol name address 7 6 5 4 3 2 1 0 dmar3 dmar2 dmar1 dmar0 r/w 0 0 0 0 dmar dma software request register 89h (read- modify-write instructions are prohibited) 1: dma soft request dmab3 dmab2 dmab1 dmab0 r/w 0 0 0 0 dmab dma burst register 8ah 1: dma burst request tmp91cw40 2008-09-19 91cw40-41 (6) precautions the instruction execution unit and the bus interface unit of this cpu operate independently. therefore, after accepting an interrupt the cpu may fetch an instruction that clears the interrupt request flag for this interrupt (note) immediately before the interrupt is about to be generated. in this case, the cpu may execute this interrupt request clear instruction after accepting the interrupt request but before reading the interrupt vector for this interrupt. if this happens, the cpu reads ?0008h? (interrupt vector cleared) and reads th e interrupt vector from address ffff08h. to avoid the above situation, make sure to execute the di instruction before an instruction for clearing an interrupt requ est flag. after the clear instruction is executed, at least one instruction must be inserted before the ei instruction is executed to re-enable interrupts.(e.g., ?nop? 1 times) if the ei instruction immediately follows the clear instruction, interrupts ma y be enabled before the interrupt flag is cleared. when the pop sr instruction is used to modify the interrupt mask level ( tmp91cw40 2008-09-19 91cw40-42 3.5 i/o ports the tmp91cw40 has a total of 69 i/o port pins. all the port pins except a few share pins with alternate functions. they can be individually programmed as general-purpose i/o or dedicated i/o for the cpu or internal functions. table 3.5.1 shows the functions of the port pins of the tmp91cw40. table 3.5.2 to table 3.5.4 give a summary of regist er sett ings used to co n trol the port pins. table 3.5.1 i/o ports port name pin name number of pins direction direction programmability p-od alternate functions port 5 p50 to p53 4 input (fixed) an0 to an3, adtrg (p53) kwi0 to kwi3 port 6 p60 1 input (fixed) int0 p61 1 input/output bit int1 p62 1 input/output bit alarm port 7 p70 1 input/output bit ecnt1 p71 1 input/output bit ecnt2 p72 1 input/output bit ecnt3, dvo , mldalm p73 1 input/output bit ecin1 p74 1 input/output bit ecin2 p75 1 input/output bit ecin3 port 8 p80 1 input/output bit tc5out p81 1 input/output bit tc6out p82 1 input/output bit tc7out p83 1 input/output bit tc8out port 9 p90 1 input/output bit txd0 p91 1 input/output bit rxd0 p92 1 input/output bit sclk0/ cts0 p93 1 input/output bit txd1 p94 1 input/output bit rxd1 p95 1 input/output bit sclk1/ cts1 port a pa0 1 input/output bit txd2 pa1 1 input/output bit rxd2 pa2 1 input/output bit sclk2/ cts2 pa3 1 input/output bit txd3 pa4 1 input/output bit rxd3 pa5 1 input/output bit sclk3/ cts3 8 output (fixed) seg0 to seg7 port 2 p20 to p27 8 input/output bit seg8 to seg15 port 1 p10 to p17 8 input/output bit seg16 to seg23 port 0 p00 to p07 8 input/output bit seg24 to seg31 port b pb0 to pb7 8 input/output bit seg32 to seg39 tmp91cw40 2008-09-19 91cw40-43 table 3.5.2 i/o port settings (1/3) i/o register settings port pin name direction/function pn pncr pnfc pnfc2 ode input port an0 to an3 inputs note 1) p50 to p53 kwi0 to kwi3 inputs note 2) port 5 p53 adtrg input note 3) n/a n/a n/a n/a input port 0 p60 int0 input n/a 1 input port 0 0 output port 1 0 p61 int1 input 0 1 input port 0 0 output port 1 0 port 6 p62 alarm output 1 1 n/a n/a input port 0 p70 to p75 output port 1 p70 ecnt1 input 0 p71 ecnt2 input 0 n/a n/a ecnt3 input 0 0 0 dvo output 1 1 0 p72 mldalm output 1 1 p73 ecin1 input 0 p74 ecin2 input 0 port 7 p75 ecin3 input 0 n/a n/a n/a input port 0 0 output port (cmos output) 1 0 0 p80 to p83 output port (open-drain output) 1 0 1 tc5out output (cmos output) 1 1 0 p80 tc5out output (open-drain output) 1 1 1 tc6out output (cmos output) 1 1 0 p81 tc6out output (open-drain output) 1 1 1 tc7out output (cmos output) 1 1 0 p82 tc7out output (open-drain output) 1 1 1 tc8out output (cmos output) 1 1 0 port 8 p83 tc8out output (open-drain output) 1 1 n/a 1 x: don?t care note 1: when p50 to p53 are used as input channels for the ad converter, the analog channel to be used is selected by the tmp91cw40 2008-09-19 91cw40-44 table 3.5.3 i/o port settings (2/3) i/o register settings port pin name direction/function pn pncr pnfc ode input port 0 0 output port (cmos output) 1 0 0 p90, p93 output port (open-drain output) 1 0 1 input port 0 p91, p94 output port 1 n/a input port 0 0 p92, p95 output port 1 0 n/a txd0 output (cmos output) 1 1 0 p90 txd0 output (open-drain output) 1 1 1 p91 rxd0 input 0 n/a sclk0 input 0 0 sclk0 output 1 1 p92 cts0 input 0 0 n/a txd1 output (cmos output) 1 1 0 p93 txd1 output (open-drain output) 1 1 1 p94 rxd1 input 0 n/a sclk1 input 0 0 sclk1 output 1 1 port 9 p95 cts1 input 0 0 n/a input port 0 0 output port (cmos output) 1 0 0 pa0, pa3 output port (open-drain output) 1 0 1 input port 0 pa1, pa4 output port 1 n/a input port 0 0 pa2, pa5 output port 1 0 n/a txd2 output (cmos output) 1 1 0 pa0 txd2 output (open-drain output) 1 1 1 pa1 rxd2 input 0 n/a sclk2 input 0 0 sclk2 output 1 1 pa2 cts2 input 0 0 n/a txd3 output (cmos output) 1 1 0 pa3 txd3 output (open-drain output) 1 1 1 pa4 rxd3 input 0 n/a sclk3 input 0 0 sclk3 output 1 1 port a pa5 cts3 input 0 0 n/a x: don?t care tmp91cw40 2008-09-19 91cw40-45 table 3.5.4 i/o port settings (3/3) i/o register settings port pin name direction/function pn pncr lcdswn mseg07 input port 0 0 output port 1 0 port 2 p00 to p07 seg8 to seg15 outputs 1 n/a input port 0 0 output port 1 0 port 1 p10 to p17 seg16 to seg23 outputs 1 n/a input port 0 0 output port 1 0 port 0 p20 to p27 seg24 to seg31 outputs 1 n/a input port 0 0 output port 1 0 port b pb0 to pb7 seg32 to seg39 outputs 1 n/a hi-z 0 0 low output (note 4) 0 1 seg seg0 to seg7 seg0 to seg7 outputs n/a n/a 1 0 x: don?t care note 4: do not set the lcdcr2 tmp91cw40 2008-09-19 91cw40-46 3.5 3.5.1 port 5 (p50 to p53) port 5 is a 4-bit input-only port that can also be used as analog input pins for the ad converter. p53 can also be used as an ad trigger input pin for the ad converter. figure 3.5.1 port 5 port 5 register 7 6 5 4 3 2 1 0 bit symbol p53 p52 p51 p50 read/write r after reset data from external port key-on wakeup enable register 7 6 5 4 3 2 1 0 bit symbol kwi3en kwi2en kwi1en kwi0en read/write w after reset 0 0 0 0 function kwi interrupt input 0: disable 1: enable figure 3.5.2 port 5 registers note 1: the kwien do not support read-modify-write operation. note 2: the ad converter mode register (admod1) is used to select the ad converter input channel to be used and to enable and disable ad conversion st art by an external trigger. note 3: the key-on wakeup enable register (kwien) is used to enable and disable key-on wakeup. kwien (03a0h) p5 (000dh) kwi0 to kwi3 internal data bus a d read conversion result register ad converter channel selector port 5 read port 5 p50 to p53 (an0 to an3/kwi0 to kwi3/ adtrg ) a dtrg (p53 only) tmp91cw40 2008-09-19 91cw40-47 3.5.2 port 6 (p60 to p62) the port 6 is compos ed of a 1-bit input port (p60) an d 2-bit input/output ports (p61 and p62) of which inputs and outputs can be specified in units of bits. a reset allows the port 6 to be put in input mode and bits 1 and 2 of the output latch register p6 are set to ?1?. besides the input/output function, the po rt 6 inputs external interrupt and outputs alarm. (1) p60 (int0) p60 can be used either as a general-purpose input port pin or an input pin for external interrupt int0. figure 3.5.3 p60 internal data bus p60 (int0) p6 read function control (bitwise) reset p6fc write level/edge select & rising/falling edge select int0 iimc tmp91cw40 2008-09-19 91cw40-48 (2) p61 (int1) p61 can be used either as a general-purpose input/output port pin or an input pin for external interrupt int1. figure 3.5.4 p61 internal data bus selector a b s p61 (int1) p6 read direction control (bitwise) p6cr write function control (bitwise) s output latch p6 write reset p6fc write level/edge select & rising/fallig edge select int1 iimc tmp91cw40 2008-09-19 91cw40-49 (3) p62 ( alarm ) p62 can be used either as a general-purpose input/output port pin or an output pin for the alarm function. figure 3.5.5 p62 p6 write reset p6 read selector a b s selector a b s p62 ( alarm ) 91fw40 p62 ( alarm , boot ) direction control (bitwise) p6cr write function control (bitwise) p6fc write s output latch internal data bus a lram boot reset 91fw40 only 91fw40 only tmp91cw40 2008-09-19 91cw40-50 port 6 register 7 6 5 4 3 2 1 0 bit symbol p62 p61 p60 read/write r/w r after reset data from external port (output latch register is set to 1.) data from external port port 6 control register 7 6 5 4 3 2 1 0 bit symbol p62c p61c read/write w after reset 0 0 function 0: input 1: output 0: input 1: output port 6 function register 7 6 5 4 3 2 1 0 bit symbol p62f p61f p60f read/write w after reset 0 0 0 function 0: port 1: alarm output 0: port 1: int1 input 0: port 1: int0 input figure 3.5.6 port 6 registers p6fc (0015h) p6 (0012h) note: the p6cr and p6fc do not support read-modify-write operation. p60 int0 input setting p6fc tmp91cw40 2008-09-19 91cw40-51 3.5 3.5.3 port 7 (p70 to p75) port 7 is a 6-bit general-purpose i/o port. each bit can be individually programmed for input or output. reset operation initializes all pins to input port pins. in addition to functioning as a general-purpose input/output port, port 7 can also function as input pins for 16-bit timers 1, 2, and 3 (ecin1, ecnt1 , ecin2, ecnt2, ecin3, ecnt3) , a divider output pin ( dvo ), a melody/alarm output pin ( mldalm ). figure 3.5.7 port 7 ecin1 ecnt1 ecin2 ecnt2 ecin3 p7 read internal data bus selector a b s p70 (ecnt1) p71 (ecnt2) p73 (ecin1) p74 (ecin2) p75 (ecin3) direction control (bitwise) r output latch p7cr write p7 write reset p write reset p7 read selector a b s selector a b s p72 (ecnt3, dvo , mldalm ) dvo bit direction (bitwise) p7cr write function control (bitwise) p7fc write s output latch internal data bus ecnt3 function control (bitwise) p7fc2 write selector a b s mldalm tmp91cw40 2008-09-19 91cw40-52 port 7 register 7 6 5 4 3 2 1 0 bit symbol p75 p74 p73 p72 p71 p70 read/write r/w after reset data from external port (output latch register is reset to 0.) port 7 control register 7 6 5 4 3 2 1 0 bit symbol p75c p74c p73c p72c p71c p70c read/write w after reset 0 0 0 0 0 0 function 0: input 1: output port 7 function register 7 6 5 4 3 2 1 0 bit symbol p72f read/write w after reset 0 function 0: port 1: dvo port 7 function register 2 7 6 5 4 3 2 1 0 bit symbol p72f2 read/write w after reset 0 function 0: port/ dvo 1: mldalm figure 3.5.8 port 7 registers p7 (0013h) p7cr (0016h) port 7 input/output setting 0 input 1 output p7fc2 (002dh) p7fc (0017h) p72 dvo output setting p7fc tmp91cw40 2008-09-19 91cw40-53 3.5.4 port 8 (p80 to p83) port 8 is a 4-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operation initializes all pins to input port pins. all bits in the output latch register (p8) are set to 1. in addition to functioning as a general-purpose input/output port , port 8 can also function as output pins for 8-bit timers. this alternate function can be enabled by writin g 1 to respective bits of the port 8 function register (p8fc). upon reset, the p8cr and p8fc registers are all initialized to 0, setting all pins as input port pins. figure 3.5.9 port 8 (p80 to p83) p8 write reset p8 read selector a b s selector a b s p80 (tc5out) p81 (tc6out) p82 (tc7out) p83 (tc8out) tc5out,tc6out tc7out,tc8out direction control (bitwise) p8cr write function control (bitwise) p8fc write s output latch internal data bus configurable as open-drain output ode tmp91cw40 2008-09-19 91cw40-54 port 8 register 7 6 5 4 3 2 1 0 bit symbol p83 p82 p81 p80 read/write r/w after reset data from external port (output latch register is set to 1.) port 8 control register 7 6 5 4 3 2 1 0 bit symbol p83c p82c p81c p80c read/write w after reset 0 0 0 0 function 0: input 1: output port 8 function register 7 6 5 4 3 2 1 0 bit symbol p83f p82f p81f p80f read/write w w w w after reset 0 0 0 0 function 0: port 1: tc8out 0: port 1: tc7out 0: port 1: tc6out 0: port 1: tc5out open-drain register 7 6 5 4 3 2 1 0 bit symbol odea3 odea0 ode93 ode90 ode83 ode82 ode81 ode80 read/write r/w after reset 0 0 0 0 0 0 0 0 function pa3 open-drain output 0: disable 1: enable pa0 open-drain output 0: disable 1: enable p93 open-drain output 0: disable 1: enable p90 open-drain output 0: disable 1: enable p83 open-drain output 0: disable 1: enable p82 open-drain output 0: disable 1: enable p81 open-drain output 0: disable 1: enable p80 open-drain output 0: disable 1: enable figure 3.5.10 port 8 registers p8fc (001bh) p8 (0018h) p8cr (001ah) note: the p8cr and p8fc do not support read-modify-write operation. port 8 input/output setting 0 input 1 output p80 tc5out output setting p8fc tmp91cw40 2008-09-19 91cw40-55 3.5.5 port 9 (p90 to p95) port 9 is a 6-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operatio n initializes all pins as input port pins. all bits in the output latch register (p9) are set to ?1?. in addition to functioning as a general-purpose input/output po rt, port 9 can also function as input/output pins for serial channels 0 and 1. this alternate function can be enabled by writing ?1? to respective bits of the port 9 function register (p9fc). upon reset the p9cr and p9fc registers are all initialized to ?0?, setting all pins as input port pins. (1) p90, p93 (txd0, txd1) p90 and p93 can be used either as general-purpose input/output port pins or txd output pins for serial channels 0 and 1. the output buffer is configurable as an open-drain output using the tmp91cw40 2008-09-19 91cw40-56 (2) p91, p94 (rxd0, rxd1) p91 and p94 can be used either as input/output port pins or rxd input pins for serial channels 0 and 1. figure 3.5.12 port 9 (p91, p94) (3) p92, p95 ( cts0 /sclk0, cts1 /sclk1) p92 and p95 can be used as general-purpose input/output port pins, cts input pins for serial channels 0 and 1, or sclk input/output pins. figure 3.5.13 port 9 (p92, p95) rxd0, rxd1 selector a bs p9 read p91 (rxd0) p94 (rxd1) direction control (bitwise) p9cr write reset s output latch internal data bus p9 write selector a b s selector a bs p92 (sclk0/ cts0 ) p95 (sclk1/ cts1 ) sclk0, sclk1 output p9 read cts0 , cts1 direction control (bitwise) p9cr write function control (bitwise) p9fc write s output latch p9 write reset sclk0, sclk1 input internal data bus tmp91cw40 2008-09-19 91cw40-57 port 9 register 7 6 5 4 3 2 1 0 bit symbol p95 p94 p93 p92 p91 p90 read/write r/w after reset data from external port (output latch register is set to 1.) port 9 control register 7 6 5 4 3 2 1 0 bit symbol p95c p94c p93c p92c p91c p90c read/write w after reset 0 0 0 0 0 0 function 0: input 1: output port 9 function register 7 6 5 4 3 2 1 0 bit symbol p95f p93f p92f p90f read/write w w w w after reset 0 0 0 0 function 0: port 1: sclk1 output 0: port 1: txd1 0: port 1: sclk0 output 0: port 1: txd0 open-drain register 7 6 5 4 3 2 1 0 bit symbol odea3 odea0 ode93 ode90 ode83 ode82 ode81 ode80 read/write r/w after reset 0 0 0 0 0 0 0 0 function pa3 open-drain output 0: disable 1: enable pa0 open-drain output 0: disable 1: enable p93 open-drain output 0: disable 1: enable p90 open-drain output 0: disable 1: enable p83 open-drain output 0: disable 1: enable p82 open-drain output 0: disable 1: enable p81 open-drain output 0: disable 1: enable p80 open-drain output 0: disable 1: enable figure 3.5.14 port 9 registers p9fc (001dh) p9cr (001ch) note 1: the p9cr and p9fc do not support read-modify-write operation. note 2: to specify the txd pin as an open-drain output, write 1 to bit 4 (for the txd0 pin) o r bit 5 (for the txd1 pin) of the ode register. the p91/rxd0 and p94/rxd1 pins do not have a register bit for selecting the port or sio function. the input to these pins is always directed to the sio as serial receive data even when they are used as general-purpose input pins. p9 (0019h) port 9 input/output setting 0 input 1 output ode (002fh) p90 txd0 output setting p9fc tmp91cw40 2008-09-19 91cw40-58 3.5.6 port a (pa0 to pa5) port a is a 6-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operatio n initialize all pins as input port pins. all bits in the output latch register (pa) ar e set to 1. in addition to functioning as a general-purpose input/output port, port a ca n also function as input/output pins for serial channels 2 and 3. this alternate function can be enabled by writing 1 in respective bits of the port a function register (pafc). upon reset, the pacr and pafc are all initialized to 0, setting all pins as input port pins. (1) pa0, pa3 (txd2, txd3) pa0 and pa3 can be used either as general-purpose input/output port pins or txd output pins for serial channels 2 and 3. the output buffer is configurable as an open-drain output using the tmp91cw40 2008-09-19 91cw40-59 (2) pa1, pa4 (rxd2, rxd3) pa1 and pa4 can be used either as general-purpose input/output port pins or rxd input pins for serial channels 2 and 3. figure 3.5.16 port a (pa1, pa4) (3) pa2, pa5 ( 2cts /sclk2, 3cts /sclk3) pa2 and pa5 can be used either as general-purpose input/output port pins, cts input pins for serial channels 2 an d 3, or sclk input/output pins. figure 3.5.17 port a (pa2, pa5) rxd2 rxd3 selector a bs pa read pa1 (rxd2) pa4 (rxd3) direction control (bitwise) p a cr write reset s output latch internal data bus p a write selector a b s selector a bs pa2 (sclk2/ 2 cts ) pa5 (sclk3/ 3 cts ) sclk2, sclk3 output pa read 2cts , 3cts direction control (bitwise) p a cr write function control (bitwise) p a fc write s output latch p a write reset sclk2, sclk3 input internal data bus tmp91cw40 2008-09-19 91cw40-60 port a register 7 6 5 4 3 2 1 0 bit symbol pa5 pa4 pa3 pa2 pa1 pa0 read/write r/w after reset data from external port (output latch register is set to 1.) port a control register 7 6 5 4 3 2 1 0 bit symbol pa5c pa4c pa3c pa2c pa1c pa0c read/write w after reset 0 0 0 0 0 0 function 0: input 1: output port a function register 7 6 5 4 3 2 1 0 bit symbol pa5f pa3f pa2f pa0f read/write w w w w after reset 0 0 0 0 function 0: port 1: sclk3 output 0: port 1: txd3 0: port 1: sclk2 output 0: port 1: txd2 open-drain register 7 6 5 4 3 2 1 0 bit symbol odea3 odea0 ode93 ode90 ode83 ode82 ode81 ode80 read/write r/w after reset 0 0 0 0 0 0 0 0 function pa3 open-drain output 0: disable 1: enable pa0 open-drain output 0: disable 1: enable p93 open-drain output 0: disable 1: enable p90 open-drain output 0: disable 1: enable p83 open-drain output 0: disable 1: enable p82 open-drain output 0: disable 1: enable p81 open-drain output 0: disable 1: enable p80 open-drain output 0: disable 1: enable figure 3.5.18 port a registers pafc (0021h) pa (001eh) pacr (0020h) note 1: the pacr and pafc do not support read-modify-write operation. note 2: to specify the txd pin as an open-drain output, write 1 to bit 6 (for the txd2 pin) or bit 7 (for the txd3 pin). the pa1/rxd2 and pa4/rxd3 pins do not have a register bit for selecting the port or sio function. the input to these pins is always directed to the sio as serial receive data even when the pins are used as general-purpos e input pins. port a input/output setting 0 input 1 output ode (002fh) pa0 txd2 output setting pafc tmp91cw40 2008-09-19 91cw40-61 3.5.7 port 2 (p20 to p27) port 2 is an 8-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operation initializes all pins as input port pins. all bits of the output latch register (p2) are set to 1. in addition to functioning as a general-purpose input/output port, port 2 can also function as lcd segment output pins. this alternate function can be enabled by writing 1 to respective bits of the lcd output control 1 register (lcdsw1). upon reset, the p2cr and lcdsw1 registers are all initialized to 0, setting all pins as input port pins. figure 3.5.19 port 2 (p20 to p27) p2 write reset p2 read selector a b s p20 to p27 (seg8 to seg15) direction control (bitwise) p2cr write function control (bitwise) lcdsw1 write output latch internal data bus seg8 to seg15 tmp91cw40 2008-09-19 91cw40-62 port 2 register 7 6 5 4 3 2 1 0 bit symbol p27 p26 p25 p24 p23 p22 p21 p20 read/write r/w after reset data from external port (output latch register is set to 1.) port 2 control register 7 6 5 4 3 2 1 0 bit symbol p27c p26c p25c p24c p23c p22c p21c p20c read/write w after reset 0 0 0 0 0 0 0 0 function 0: input 1: output lcd output control 1 register 7 6 5 4 3 2 1 0 bit symbol seg15c seg14c seg13c seg12c seg11c seg10c seg9c seg8c read/write w after reset 0 0 0 0 0 0 0 0 function 0: port 1: seg15 0: port 1: seg14 0: port 1: seg13 0: port 1: seg12 0: port 1: seg11 0: port 1: seg10 0: port 1: seg9 0: port 1: seg8 figure 3.5.20 port 2 registers note: the lcd output control register is also provided for seg0 to seg7 which do not support the port function. lcd output control 0 register 7 6 5 4 3 2 1 0 bit symbol seg7c seg6c seg5c seg4c seg3c seg2c seg1c seg0c read/write w after reset 0 0 0 0 0 0 0 0 function 0: hi-z 1: seg7 0: hi-z 1: seg6 0: hi-z 1: seg5 0: hi-z 1: seg4 0: hi-z 1: seg3 0: hi-z 1: seg2 0: hi-z 1: seg1 0: hi-z 1: seg0 lcdsw1 (03d9h) p2 (0006h) p2cr (0008h) ? ) p2cr, lcdsw1 `??? ?? segn output setting example lcdsw1 tmp91cw40 2008-09-19 91cw40-63 3.5.8 port 1 (p10 to p17) port 1 is an 8-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operation initializes all pins to input port pins. all bits of the output latch register (p1) are set to 0. in addition to functioning as a general-purpose input/output port, port 1 can also function as lcd segment output pins. this alternate function can be enabled by writ ing 1 to respective bits in the lcd output control 2 register. upon reset, the p1cr and lcdsw2 are all initialized to 0, setting all pins as input port pins. figure 3.5.21 port 1 (p10 to p17) p1 write reset p1 read selector a b s p10 to p17 (seg16 to seg23) direction control (bitwise) p1cr write function control (bitwise) lcdsw2 write output latch internal data bus seg16 to seg23 tmp91cw40 2008-09-19 91cw40-64 port 1 register 7 6 5 4 3 2 1 0 bit symbol p17 p16 p15 p14 p13 p12 p11 p10 read/write r/w after reset data from external port (output latch register is set to 0.) port 1 control register 7 6 5 4 3 2 1 0 bit symbol p17c p16c p15c p14c p13c p12c p11c p10c read/write w after reset 0 0 0 0 0 0 0 0 function 0: input 1: output lcd output control 2 register 7 6 5 4 3 2 1 0 bit symbol seg23c seg22c seg 21c seg20c seg19c seg18c seg17c seg16c read/write w after reset 0 0 0 0 0 0 0 0 function 0: port 1: seg23 0: port 1: seg22 0: port 1: seg21 0: port 1: seg20 0: port 1: seg19 0: port 1: seg18 0: port 1: seg17 0: port 1: seg16 figure 3.5.22 port 1 registers lcdsw2 (03dah) p1 (0001h) p1cr (0004h) note: the p1cr and ldcsw2 do not support read-modify-write operation. segn output setting example lcdsw2 tmp91cw40 2008-09-19 91cw40-65 3.5.9 port 0 (p00 to p07) port 0 is an 8-bit general-purpose input/ou tput port. each bit can be individually programmed for input or output. reset operation initializes all pins as input port pins. all bits of the output latch register (p0) are set to 0. in addition to functioning as a general-purpose input/output port, port 0 can also function as lcd segment output pins. this alternate function can be enabled by writing 1 to respective bits of the lcd output control 3 register. upon reset, the p0cr and lcdsw3 registers are all initialized to 0, setting all pins as input port pins. figure 3.5.23 port 0 (p00 to p07) p0 write reset p0 read selector a b s p00 to p07 (seg24 to seg31) direction control (bitwise) p0cr write function control (bitwise) lcdsw3 write output latch internal data bus seg24 to seg31 tmp91cw40 2008-09-19 91cw40-66 port 0 register 7 6 5 4 3 2 1 0 bit symbol p07 p06 p05 p04 p03 p02 p01 p00 read/write r/w after reset data from external pins (output latch register is set to 0.) port 0 control register 7 6 5 4 3 2 1 0 bit symbol p07c p06c p05c p04c p03c p02c p01c p00c read/write w after reset 0 0 0 0 0 0 0 0 function 0: input 1: output lcd output control 3 register 7 6 5 4 3 2 1 0 bit symbol seg31c seg30c seg 29c seg28c seg27c seg26c seg25c seg24c read/write w after reset 0 0 0 0 0 0 0 0 function 0: port 1: seg31 0: port 1: seg30 0: port 1: seg29 0: port 1: seg28 0: port 1: seg27 0: port 1: seg26 0: port 1: seg25 0: port 1: seg24 figure 3.5.24 port 0 registers lcdsw3 (03dbh) p0 (0000h) p0cr (0002h) note: the p0cr and lcdsw3 do not support read-modify-write operation. segn output setting example lcdsw3 tmp91cw40 2008-09-19 91cw40-67 3.5.10 port b (pb0 to pb7) port b is an 8-bit general-purpose input/output port. each bit can be individually programmed for input or output. reset operation initializes all pins as input port pins. all bits of the output latch register (pb) are set to 0. in addition to functioning as a general-purpose input/output port, port b can also function as lcd segment output pins. this alternate function can be enabled by writing 1 to respective bits of the lcd output control 4 register (lcdsw4). upon reset, the pbcr and lcdsw4 registers are all initialized to 0, setting all pins as input port pins. figure 3.5.25 port b (pb0 to pb7) pb write reset pb read selector a b s pb0 to pb7 (seg32 to seg39) direction control (bitwise) pbcr write function control (bitwise) lcdsw4 write output latch internal data bus seg32 to seg39 tmp91cw40 2008-09-19 91cw40-68 port b register 7 6 5 4 3 2 1 0 bit symbol pb7 pb6 pb5 pb4 pb3 pb2 pb1 pb0 read/write r/w after reset data from external port (output latch is set to 0.) port b control register 7 6 5 4 3 2 1 0 bit symbol pb7c pb6c pb5c pb4c pb3c pb2c pb1c pb0c read/write w after reset 0 0 0 0 0 0 0 0 function 0: input 1: output lcd output control 4 register 7 6 5 4 3 2 1 0 bit symbol seg39c seg38c seg 37c seg36c seg35c seg34c seg33c seg32c read/write w after reset 0 0 0 0 0 0 0 0 function 0: port 1: seg39 0: port 1: seg38 0: port 1: seg37 0: port 1: seg36 0: port 1: seg35 0: port 1: seg34 0: port 1: seg33 0: port 1: seg32 figure 3.5.26 port b registers lcdsw4 (03dch) pb (0024h) pbcr (0025h) note: the pbcr and lcdsw4 do not support read-modify-write operation. segn output setting example lcdsw4 tmp91cw40 2008-09-19 91cw40-69 3.6 timing generator the timing generator generates va rious system clocks to be supplied to peripheral hardware based on the basic clock (fc or fs). (1) configuration the timing generator consists of two counters, one for the high-frequency clock and one for the low-frequency clock. figure 3.6.1 configuration of the timing generator high-frequency clock ( fc ) counter fc fc/2 fc/3 fc/2 3 fc/2 5 fc/2 7 fc/2 10 fc/2 11 fc/2 12 fc/2 13 fc/2 14 fc/2 23 low-frequency clock (fs) counter fs fs/2 2 fs/2 3 fs/2 4 fs/2 5 fs/2 6 fs/2 15 tmp91cw40 2008-09-19 91cw40-70 3.7 divider output ( dvo ) the timing generator is provided with a divider output feature which enables output of approximately 50% duty pulses. this feature is us eful for driving a piezoe lectric beeper. divider output is implemented on the p72 ( dvo ) pin. note: the divider output frequency ( tmp91cw40 2008-09-19 91cw40-71 figure 3.7.2 divider output p7 tmp91cw40 2008-09-19 91cw40-72 3.8 16-bit timer/counter the tmp91cw40 has three channels of 16-bit timers (tc1, tc2 and tc3). each of the three channels operates independently, and is functionally equivalent. in the following sections, any references to tc1 also apply to other channels. 3.8.1 configuration figure 3.8.1 timer/counter 1 (tc1) tc1cr1 fc/2 23 fc/2 13 fc/2 11 fs/2 15 or fc/2 7 fs/2 5 or fc/2 3 fs/2 3 or fc/2 fs or fc 3 tc1ck sgedg comparator 16-bit up-counter h g f e y d c b a s 2 tc1m 2 tc1s 1 tc1c 0944h b y a s ecnt pin ecin pin a b y c s fc/2 12 or fs/2 4 fc/2 13 or fs/2 5 fc/2 14 or fs/2 6 2 wgpsck window pulse generator edge detector 1 tc1m 2 tc1cr2 1 seg 2 sgp 1 sgedg 2 wgpsck 0945h inttmr1 interrupt request clear request treg1al treg1ah 0940h 0941h f/f tc1sr 0946h 1 1 treg1b 0943h seg edge detector 1 10 y 11 00 s p u l se w idth measurement mode f requency measu r ement mode ti mer / even t counter mode timer/event counter mode p u l se w idth measurement mode f requency measurement mode tmp91cw40 2008-09-19 91cw40-73 3.8.2 control the timer/counter 1 (tc1) is controlled by the timer/counter 1 control registers (tc1cr1/tc1cr2), timer register (treg1a) and internal window gate pulse setting register (treg1b). timer register treg1a 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 (0941h, 0940h) treg1ah (0941h) treg1al (0940h) read/write (initial value: 0000 0000 0000 0000) internal window gate pulse setting register 7 6 5 4 3 2 1 0 treg1b (0943h) ta tb (initial value: 0000 0000) ta window gate pulse ?h? level period (16 ? ta) 2 13 /fc or (16 ? ta) 2 5 /fs [s] tb window gate pulse ?l? level period (16 ? tb) 2 13 /fc or (16 ? tb) 2 5 /fs [s] r/w note: wgpsck = 01 timer/counter 1 control register 1 7 6 5 4 3 2 1 0 tc1cr1 (0944h) tc1c tc1s tc1ck tc1m (initial value: 1000 0000) note 1: fc: high-frequency clock [hz], fs: low-frequency clock [hz], * : don?t care note 2: after the lower byte of the timer register (treg1al) is written, match detection is temporarily disabled until a write to the upper byte (treg1ah) is completed. (it is not possible to modify only the lower byte of the timer register.) also note that match detection is enabled again after one machine cycle has elapsed upon completion of a write to the upper byte. note 3: before changing the operating mode, source clock and edge selection, be sure to stop the timer/counter ( tmp91cw40 2008-09-19 91cw40-74 timer/counter 1 control register 2 7 6 5 4 3 2 1 0 tc1cr2 (0945h) seg sgp sgedg wgpsck D tc1sel (initial value: 0000 00*0) note 1: fc: high-frequency clock [hz], fs: low-frequency clock [hz], * : don?t care note 2: before setting the tc1cr2, be sure to stop the timer/counter ( tmp91cw40 2008-09-19 91cw40-75 source clocks that can be used in each operating mode (normal or idle2 mode) operating mode fc/2 23 fc/2 13 fc/2 11 or fs/2 15 fc/2 7 or fs/2 5 fc/2 3 or fs/2 3 fc/2 fc or fs ecin timer mode yes yes yes yes yes no no ? event counter mode no no no no no no no tc1cr2 tmp91cw40 2008-09-19 91cw40-76 3.8.3 functional description the timer/counter 1 has the following four operating modes: (1) timer mode in the timer mode, the counter counts up on the rising edge of the internal clock. when a match between the counter value and the treg1a register value is detected, an inttmr1 interrupt is generated and the counter is cleared. the counter continues counting up after it has been cleared. table 3.8.1 timer/counter 1 s ource clock (internal clock) source clock resolution maximum setting time tc1sel = 0 tc1sel = 1 fc = 27 mhz fs = 32.768 khz fc = 27 mhz fs = 32.768 khz fc/2 23 [hz] fc/2 13 fc/2 11 fc/2 7 fc/2 3 fs/2 15 [hz] fs/2 5 fs/2 3 ? 0.31 s 303.41 s 75.85 s 4.74 s 0.3 s 1s 0.98 ms 244 s ? ? 5.66 h 19.88 s 4.97 s 310.69 ms 19.42 ms 18.2 h 1.07 min 16 s ? ? figure 3.8.4 timer mode timing chart 1 treg1a inttmr1 interrupt command start source clock counter 0 n match detect counter clear 2 3 4 n ? 1 n 0 1 2 3 4 5 6 tmp91cw40 2008-09-19 91cw40-77 programming sequences (be sure to follow these sequences.) ? setting the timer mode with the system clock fc and the counter source clock fc/2 3 ld (tc1cr2),00h : set the tmp91cw40 2008-09-19 91cw40-78 (2) event counter mode in the event counter mode, the counter counts up on the rising edge of the ecin1 pin input. when a match between the counter value and the treg1a register value is detected, an inttmr1 interrupt is generated and the counter is cleared. then, the counter continues counting up on each rising edge of the ecin1 pin input. the maximum allowed frequency is fc/2 4 [hz] (in normal or idle2 mode) and f/2 4 [hz] (in slow or sleep mode) when tc1cr2 tmp91cw40 2008-09-19 91cw40-79 (3) pulse width measurement mode in the pulse width measurement mode, the counter counts up on the rising edge of the and pulse of the ecin1 pin input (window pulse) and the internal clock. the internal clock is selected by tc1cr1 tmp91cw40 2008-09-19 91cw40-80 programming sequences (be sure to follow these sequences.) ? setting initial values ld (tc1cr2),00h : set the tmp91cw40 2008-09-19 91cw40-81 (4) frequency measurement mode the frequency measurement mode is used to measure the frequency of the ecin1 pin input pulse. (in this mode, tc1cr1 tmp91cw40 2008-09-19 91cw40-82 figure 3.8.8 frequency meas urement mode timing chart (interrupt at the falling edge of the window gate pulse) figure 3.8.9 frequency meas urement mode timing chart (interrupt at the rising/falling edges of the window gate pulse) figure 3.8.10 frequency m easurement mode timing chart (interrupt at the rising/falling edges of the window gate pulse) counter inttmr1 interrupt ecin1 pin input window gate pulse read 1 6 0 2 3 4 5 0 1 2 3 4 5 clear ta ta tb counter inttmr1 interrupt ecin1 pin input window gate pulse 0 0 1 2 3 4 5 ta ta tb counter start mode setting 1 2 3 4 read clear 5 counter inttmr1 interrupt ecin1 pin input window gate pulse read 1 6 0 2 3 4 5 0 1 2 3 4 5 clear ta ta tb when an ecin1 port started a timer at the time of ?1?, the interrupt just after the start does not occur. tmp91cw40 2008-09-19 91cw40-83 figure 3.8.11 frequency m easurement mode timing chart (counter overlow) programming sequences (be sure to follow these sequences) ? setting initial values ld (tc1cr2),0a8h : tmp91cw40 2008-09-19 91cw40-84 3.9 8-bit timer/counter the tmp91cw40 has four channe ls of 8-bit timers (tc5,tc6 ? tc7 and tc8). these channels are configured into two modules, each comprising two channels (tc5 and tc6; tc7 and tc8). each module operates independently, and is function ally equivalent. in the following sections, any references to tc5 and tc6 al so apply to tc7 and tc8. 3.9.1 configuration figure 3.9.1 8-bit timer/counters 5 & 6 fc/2 11 or fs/2 3 fc/2 7 fc/2 5 fc/2 3 fc/3 fc/2 fc or fs tc6ck tc6cr1 a b c d e f g y s 8-bit up-counter tc6s a b y s timer or ppg mode pwm mode toggle q set clear tc6out pin inttmr6 interrupt request timer mode s a y b pwm or ppg mode decode en pwm or ppg mode 16-bit mode clear tc6m tc6s tff6 16-bit mode ttreg6 pwreg6 tff6 tc5s clear 16-bit mode fc/2 11 or fs/2 3 fc/2 7 fc/2 5 fc/2 3 fc/3 fc/2 fc or fs tc5ck tc5cr1 a b c d e f g y s 8-bit up-counter tc5m tc5s tff5 ttreg5 pwreg5 pwm mode timer mode timer mode pwm mode 16-bit mode 16-bit mode inttmr5 interrupt request toggle q set clear tc5out pin decode en tff5 pwm mode a y b s 16-bit mode overflow overflow note: depending on i/o port settings, control inputs/outputs may not become effective. for details, see the chapter on i/o port s. timer f/f6 timer f/f5 16-bit mode a b y s tmp91cw40 2008-09-19 91cw40-85 3.9.2 control the timer/counter 5 is controlled by the ti mer/counter 5 control register 1 (tc5cr1), timer/counter 5 control register 2 (tc5cr2) and two 8-bit timer registers (ttreg5 and pwreg5). timer registers 7 6 5 4 3 2 1 0 ttreg5 (0904h) (initial value: 1111 1111) r/w 7 6 5 4 3 2 1 0 pwreg5 (0908h) (initial value: 1111 1111) r/w note 1: do not change the ttreg5 value while the timer is running. note 2: in the 8-bit or 16-bit pwm mode, do not c hange the pwreg5 value while the timer is running. note 3: values that can be set in each timer register are limited depending on the timer?s operating mode. for details, see table 3.9.3 . timer/counter 5 control register 1 7 6 5 4 3 2 1 0 tc5cr1 (0900h) tff5 tc5ck tc5s tc5m (initial value: 0000 0000) tff5 timer f/f5 control 0: clear 1: set tc5sel=0 tc5sel = 1 000 001 010 011 100 101 110 fc/2 11 fc/2 7 fc/2 5 fc/2 3 fc/3 (note 6) fc/2 (note 6) fc (note 6) fs/2 3 ? ? ? ? ? fs (note 6) tc5ck operating clock select [hz] 111 ? tc5s timer start control 0: stop & clear counter 1: start tc5m operating mode select 000: 8-bit timer mode 001: reserved 010: 8-bit pulse width modulation (pwm) output mode 011: 16-bit mode (use tc6cr1 tmp91cw40 2008-09-19 91cw40-86 timer/counter 5 control register 2 7 6 5 4 3 2 1 0 tc5cr2 (0902h) ? ? ? ? ? ? ? tc5sel (initial value: **** ***0) tc5sel timer input clock control 0: fc 1: fs r/w note 1: do not set tmp91cw40 2008-09-19 91cw40-87 the timer/counter 6 is controlled by the ti mer/counter 6 control register 1 (tc6cr1), timer/counter 6 control register 2 (tc6cr2) , and two 8-bit timer registers (ttreg6 and pwreg6). timer register 7 6 5 4 3 2 1 0 ttreg6 (0905h) (initial value: 1111 1111) r/w 7 6 5 4 3 2 1 0 pwreg6 (0909h) (initial value: 1111 1111) r/w note 1: do not change the ttreg6 value while the timer is running. note 2: in the 8-bit or 16-bit pwm mode, do not c hange the pwreg6 value while the timer is running. note 3: values that can be set in each timer register are limited depending on the timer?s operating mode. for details, see table 3.9.3. timer/count er 6 control register 7 6 5 4 3 2 1 0 tc6cr1 (0911h) tff6 tc6ck tc6s tc6m (initial value: 0000 0000) tff6 timer f/f6 control 0: clear 1: set tc6sel = 0 tc6sel = 1 000 001 010 011 100 101 110 fc/2 11 fc/2 7 fc/2 5 fc/2 3 fc/3 (note 6) fc/2 (note 6) fc (note 6) fs/2 3 ? ? ? ? ? fs (note 6) tc6ck operating clock select [hz] 111 ? tc6s timer start control 0: stop & clear counter 1: start tc6m operating mode select 000: 8-bit timer mode 001: reserved 010: 8-bit pulse width modulation (pwm) output mode 011: reserved 100: 16-bit timer mode 101: reserved 110: 16-bit pulse width modulation (pwm) output mode 111: 16-bit ppg mode r/w note 1: fc: high-frequency clock [hz], fs: low-frequency clock [hz] note 2 do not change the tmp91cw40 2008-09-19 91cw40-88 timer/counter 6 control register 2 7 6 5 4 3 2 1 0 tc6cr2 (0903h) ? ? ? ? ? ? ? tc6sel (initial value: **** ***0) tc6sel timer input clock control 0: fc 1: fs r/w note 1: do not set tmp91cw40 2008-09-19 91cw40-89 table 3.9.1 source clocks that ca n be used in each operating mode (in normal or idle2 mode) operating mode fc/2 11 or fs/2 3 fc/2 7 fc/2 5 fc/2 3 fc/3 fc/2 fc or fs 8-bit timer yes yes yes yes no no no 8-bit pwm yes yes yes yes yes yes yes 16-bit timer yes yes yes yes no no no 16-bit pwm yes yes yes yes yes yes yes 16-bit ppg yes yes yes yes no no no note: in 16-bit mode (16-bit timer, 16-bit pwm, or 16-bit ppg), the source clock is s pecified by tc6cr1 tmp91cw40 2008-09-19 91cw40-90 3. 3.9 3.9.3 functional description the timer/counters 5 and 6 (tc5 and tc6) have the following five operating modes: ? 8-bit timer mode ? 8-bit pulse width modulation (pwm) output mode ? 16-bit timer mode ? 16-bit pulse width modulation (pwm) output mode ? 16-bit programmable pulse generation (ppg) mode each 16-bit mode is realized by ca scading the timer/counters 5 and 6. (1) 8-bit timer mode (tc5 and tc6) in the 8-bit timer mode, the counter counts up internal clock pulses. when a match between the counter value and the timer register (ttregj) value is detected, an inttmrj interrupt is generated and the counter is cleared. the counter then continues counting up. note 1: in the 8-bit timer mode, do not change the ttregj register value while the timer is running. in this mode, the ttregj does not have a shift register and the value written to the ttregj is reflected immediately after the write operation. therefore, if the ttregj value is changed while the timer is running, unexpected operation may result. note 2: j = 5, 6 3.9.1 3.9.2 3.9.3 table 3.9.4 source clock in 8-bi t timer mode (internal clock/tc5) source clock resolution maximum setting time tc5cr2 tmp91cw40 2008-09-19 91cw40-91 programming sequences (be sure to follow these sequences.) ? setting initial values ld (tc5cr2),00h : set the tmp91cw40 2008-09-19 91cw40-92 (2) 8-bit pulse width modulation (pwm) output mode (tc5 and tc6) this mode is used to generate puls e width modulated (pwm) signals with a resolution of 8 bits. the counter counts up internal clock pulses. when a match between the counter value and the pwregi value is detected, the timer flip-flop (f/fi) is toggled. the counter then continues count ing up. when an overflow occurs, the timer f/fi is toggled again and the counter is cleared. the output from the timer f/fi is output on the tciout pin after being inverted. when an overflow occurs, an inttmri interrupt is generated. in the pwm mode, the pwregi register is serially connected to a shift register, enabling the pwregi value to be changed while the timer is running. while the timer is running, the value written to the pwregi is shifted into the shift register and becomes valid by an inttmri interrupt. this feature makes it po ssible to change the pulse width continuously. when the timer is not running, the value written to the pwregi is immediately shifted into the shift register. when a read instruction is executed on the pwregi during pwm output, the shift register value is returned instead of the value set in the pwregi. this means that the new value written to the pwregi cannot be read out until an inttmri interrupt occurs; up to that point the previous pwregi value is read out. note 1: in the pwm mode, the pwregi register should be written to immediately after an inttmri interrupt occurred (normally in t he inttmri interrupt service routine). if a write to the pwregi and an inttmri interrupt occur simultaneously, an unstabl e value is shifted into the shift register, causing unexpected pulses to be generated until the next inttmri interrupt occurs. note 2: when the timer is stopped during pwm output, the tciout pin retains its current output state. after the timer stops, the tciout pin state can be c hanged to a desired level by using tcicr1 tmp91cw40 2008-09-19 91cw40-93 figure 3.9.5 8-bit pwm output mode timing chart (tc5) n ff n + 1 ff 1 0 n match detect tc5cr1 tmp91cw40 2008-09-19 91cw40-94 programming sequences (be sure to follow these sequences.) ? setting initial values ld (tc5cr2),00h : set the |