Part Number Hot Search : 
74HC7080 FN4233 SK70DT12 3D542ML CMD57154 AO4601 DDZ30D BCM5400
Product Description
Full Text Search
 

To Download W79E227AFG Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  preliminary w79e225a/226a/227a data sheet 8-bit microcontroller publication release date: april 15, 2008 - 1 - revision a4.0 table of contents- 1. general des cription ......................................................................................................... 5 2. features ....................................................................................................................... .......... 6 3. parts inform ation list ..................................................................................................... 7 3.1 lead free (rohs) parts informati on li st......................................................................... 7 4. pin config uration .............................................................................................................. . 8 5. pin descri ption................................................................................................................ ... 10 5.1 port 4 ......................................................................................................................... ... 12 6. memory orga nization...................................................................................................... 13 6.1 program memory (o n-chip flash) ................................................................................. 13 6.2 data me mory ................................................................................................................ 13 6.3 auxiliary sram ............................................................................................................. 14 6.4 nvm data flash............................................................................................................ 14 6.4.1 operat ion...................................................................................................................... .. 19 7. special function registers ......................................................................................... 21 8. instruction set................................................................................................................ .. 74 8.1 instruction timing.......................................................................................................... 84 8.1.1 external data memo ry access timing............................................................................ 86 9. power mana gement.......................................................................................................... 89 9.1 idle mode ...................................................................................................................... 89 9.2 power down mode ....................................................................................................... 89 10. reset cond itions............................................................................................................... 91 10.1 sources of reset............................................................................................................ 91 10.1.1 external reset .............................................................................................................. 91 10.1.2 power-on rese t (por)................................................................................................ 91 10.1.3 watchdog time r reset................................................................................................. 91 10.2 reset state ................................................................................................................... 92 11. interrupts ..................................................................................................................... ...... 93 11.1 interrupt sources .......................................................................................................... 93 11.2 priority level structure ................................................................................................. 93 11.2.1 response time ............................................................................................................ 97 12. programmable time rs/counters ............................................................................... 98 12.1 timer/counter s 0 & 1.................................................................................................... 98 12.1.1 time-base se lection .................................................................................................... 98 12.1.2 mode 0 ......................................................................................................................... 98 12.1.3 mode 1 ......................................................................................................................... 99 12.1.4 mode 2 ......................................................................................................................... 99 12.1.5 mode 3 ....................................................................................................................... 100
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 2 - revision a4.0 12.2 timer/count er 2 .......................................................................................................... 100 12.2.1 capture mode............................................................................................................. 101 12.2.2 auto-reload mode, counti ng up .................................................................................. 101 12.2.3 auto-reload mode, co unting up /down ....................................................................... 102 12.2.4 baud rate gener ator mode ....................................................................................... 103 13. watchdog timer............................................................................................................... 104 14. pulse-width-modulated (pwm) ou tputs ................................................................. 107 14.1 pwm feat ures ............................................................................................................ 107 14.2 pwm control registers .............................................................................................. 108 14.3 pwm pin st ructures ................................................................................................... 110 14.4 complementary pwm with dead-t ime and override functions .................................. 113 14.5 dead-time insertion ................................................................................................... 114 14.6 pwm output override ................................................................................................ 115 14.7 edge aligned pwm (up-counter) ................................................................................ 118 14.8 center aligned pwm (up/down counter) .................................................................... 121 14.9 single shot (u p-counter) ........................................................................................... 123 14.10 smart fault detector .............................................................................................. 126 14.11 pwm power-down/wakeup procedures ................................................................ 128 15. motion feed back module ............................................................................................. 130 15.1 input capture module (ic) .......................................................................................... 130 15.1.1 compare mode........................................................................................................... 138 15.1.2 reload mode .............................................................................................................. 138 15.2 quadrature encoder interface (qei) .......................................................................... 138 15.2.1 free-counti ng m ode ................................................................................................... 140 15.2.2 compare-coun ting mode ............................................................................................ 140 15.2.3 x2/x4 counti ng modes............................................................................................... 140 15.2.4 direction of co unt....................................................................................................... 140 15.2.5 up-count ing ............................................................................................................... 142 15.2.6 down-co unting........................................................................................................... 142 16. serial port .................................................................................................................... .... 143 16.1 mode 0 ........................................................................................................................ 143 16.2 mode 1 ........................................................................................................................ 144 16.3 mode 2 ........................................................................................................................ 145 16.4 mode 3 ........................................................................................................................ 146 16.5 framing error detection ............................................................................................. 147 16.6 multiprocessor communications................................................................................. 147 17. i2c serial ports ............................................................................................................... 149 17.1 sio port ...................................................................................................................... 149 17.2 the i2c contro l registers .......................................................................................... 149 17.2.1 slave address regi sters, i2addr ............................................................................. 150 17.2.2 data regist er, i2dat ................................................................................................. 150 17.2.3 control regist er, i2con............................................................................................. 150
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 3 - revision a4.0 17.2.4 status regist er, i2status........................................................................................ 151 17.2.5 i2c clock baud rate control, i2clk.......................................................................... 151 17.2.6 i2c time-out c ounter, i2 timer ................................................................................... 151 17.2.7 i2c maskable sl ave addr ess ..................................................................................... 152 17.3 modes of operation .................................................................................................... 152 17.3.1 master trans mitter mode ........................................................................................... 152 17.3.2 master rece iver mode ............................................................................................... 152 17.3.3 slave receiv er mode ................................................................................................. 153 17.3.4 slave transmi tter m ode ............................................................................................. 153 17.4 data transfer flow in five oper ating modes............................................................. 153 17.4.1 master/trans mitter mode ........................................................................................... 154 17.4.2 figure 17-5: master transmitter modemaster/re ceiver mode ................................... 155 17.4.3 slave/transmi tter m ode ............................................................................................. 156 17.4.4 slave/receiv er mode ................................................................................................. 157 17.4.5 gc m ode .................................................................................................................... 158 18. serial peripheral in terface (spi)............................................................................. 159 18.1 general descriptions ................................................................................................... 159 18.2 block descr iptions ....................................................................................................... 159 18.3 functional descriptions ............................................................................................... 161 18.3.1 master mode .............................................................................................................. 161 18.3.2 slave mode ................................................................................................................ 164 18.3.3 slave se lect ................................................................................................................ 168 18.3.4 /ss out put................................................................................................................... 168 18.3.5 spi i/o pi ns m ode ...................................................................................................... 169 18.3.6 programmable serial clo ck?s phase a nd pola rity ........................................................ 170 18.3.7 receive double buffe red data r egist er........................................................................ 171 18.3.8 lsb firs t enabl e .......................................................................................................... 172 18.3.9 write collisi on detec tion ............................................................................................. 172 18.3.10 transfer comple te inte rrupt ...................................................................................... 172 18.3.11 mode fa ult ............................................................................................................... 172 19. analog-to-digita l converter .................................................................................... 175 19.1 operation of adc ....................................................................................................... 175 19.2 adc resolution and analog supply ........................................................................... 176 20. timed access protection ............................................................................................ 177 21. port 4 st ructure ............................................................................................................ 179 22. in-system pr ogramming................................................................................................ 182 22.1 the loader program locate s at ldflas h memo ry .................................................... 182 22.2 the loader program locate s at apflash memory .................................................... 182 23. option bits .................................................................................................................... ..... 183 23.1 config0........................................................................................................................ 183 23.2 config1........................................................................................................................ 184 24. electrical cha racteristics....................................................................................... 185 24.1 absolute maxi mum ratings ........................................................................................ 185
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 4 - revision a4.0 24.2 dc characte ristics ...................................................................................................... 185 24.3 ac characteristics ...................................................................................................... 188 24.3.1 external clock c haracteri stics.................................................................................... 188 24.3.2 ac specif ication ......................................................................................................... 188 24.3.3 movx characteristics usin g stretch memory cycle .................................................. 189 24.4 the adc converter dc elec trical chara cteristics ................................... 191 24.5 i2c bus timing ch aracteristics .................................................................................. 191 24.6 program memory read cycle .................................................................................... 192 24.7 data memory read cy cle........................................................................................... 193 24.8 data memory write cycle........................................................................................... 193 25. typical applicat ion cir cuits ...................................................................................... 194 25.1 expanded external program memory and crystal ..................................................... 194 25.2 expanded external data me mory and o scillat or........................................................ 194 26. package dime nsion ......................................................................................................... 195 26.1 44l plcc ................................................................................................................... 195 26.2 48l lqfp (7x7x1.4mm footprint 2.0mm) ................................................................... 196 27. applicatio n note ............................................................................................................. 197 28. revision histor y .............................................................................................................. 203
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 5 - revision a4.0 1. general description the w79e22x series is a fast, 8051/52-compatible microcontroller with a redesigned processor core that eliminates wasted clock and memory cycles. typically, the w79e22x series executes instructions 1.5 to 3 times faster than that of the traditional 8051/52, depending on the type of instruction, and the overall performance is about 2.5 times better at the same crystal speed. as a result, with the fully-static cmos design, the w79e22x series can accomplish the same throughput with a lower clock speed, r educing power consumption. the w79e22x series provides 256 bytes of on-chip ram; 1/2/2 -kb of nvm data flash eprom; 1/2/2 -kb of auxiliary ram; four 8-bit, bi-directional and bit-addressable i/o ports; an additional 4 -bit port p4 and 2 -bit port p5; three 16-bit timer/counters; motion feedback module support; 2 uart serial ports; 1 channels of i2c with master/slave capability; 1 channels of serial peripheral interface (spi), 8 channels of 12 bit pwm with configurable dead time and 8 channels of 10-bit adc. these peripherals are all supported by 20 interrupt sources with 4 levels of priority. the w79e22x series also contains a 16/32/64 -kb flash eprom whose contents may be updated in-system by a loader program stored in an auxiliary, 4 -kb flash eprom. once the contents are confirmed, it can be protected for security.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 6 - revision a4.0 2. features z fully-static-design 8-bit 4t-8051 cmos microcontroller up to 40mhz. z 16/32/64 -kb of in-system-programmable flash eprom (ap flash eprom). z 4 -kb of auxiliary flash eprom for the loader pr ogram (ld flash eprom). user can optionally reboot from ld flash eprom by pull low at eit her p4.3 or p3.6 and p3.7, at external reset. z 1/2/2 -kb auxiliary ram, software-selectabl e, accessed by movx instruction. z 1/2/2 -kb of nvm data flash eprom fo r customer data storage used. z 256 bytes of scratch-pad ram. z four 8-bit bi-directional ports; port 0 has internal pull-up resisters enabled by software. z multipurpose i/o port4 (4 bits for 48l lqfp; 2 bits for 44l plcc) with chips select (cs) and boot function. z two bits bi-directional port5. z three 16-bit timers. z one 16-bit timer 3 for motion feed-back module. z motion feedback module - qei decoder and 3 inputs capture. z eight channels of 12-bit pwm:- c ? complementary paired output with programmable dead-time insertion. c ? three modes: edge aligned, center aligned and single shot. c ? output override control for bldc motor application. z 10-bit adc with 8-channel inputs. z two enhanced full-duplex uart with framing-erro r detection and automatic address recognition. z one channel of i2c with master/slave capability. z one channel of spi with master/slave capability. z software programmable access cycle to external ram/peripherals. z 20 interrupt sources with four levels of priority. z software reset function. z optional h/l state of ale/ psen during power down mode. z built-in power management. z code protection. z package: c ? lead free (rohs) plcc 44: w79e225apg c ? lead free (rohs) lqfp 48: w79e225afg c ? lead free (rohs) plcc 44: w79e226apg c ? lead free (rohs) lqfp 48: w79e226afg c ? lead free (rohs) plcc 44: w79e227apg c ? lead free (rohs) lqfp 48: W79E227AFG c
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 7 - revision a4.0 3. parts information list 3.1 lead free (rohs) parts information list part no. eprom flash size ram operating frequency operating voltage nvm flash eprom package remark up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e225apg 16kb 256b + 1kb up to 24mhz 4.5v ~ 5.5v 1kb plcc-44 pin external memory up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e225afg 16kb 256b+ 1kb up to 24mhz 4.5v ~ 5.5v 1kb lqfp-48 pin external memory up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e226apg 32kb 256b + 2kb up to 24mhz 4.5v ~ 5.5v 2kb plcc-44 pin external memory up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e226afg 32kb 256b + 2kb up to 24mhz 4.5v ~ 5.5v 2kb lqfp-48 pin external memory up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e227apg 64kb 256b + 2kb up to 24mhz 4.5v ~ 5.5v 2kb plcc-44 pin external memory up to 40mhz up to 20mhz 4.5v ~ 5.5v 2.7v [1] ~ 5.5v internal memory w 79e227afg 64kb 256b + 2kb up to 24mhz 4.5v ~ 5.5v 2kb lqfp-48 pin external memory note: 1. minimum of 3.0v operating voltage for nvm program and erase operations.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 8 - revision a4.0 4. pin configuration 13 14 15 16 17 18 19 20 21 22 25 26 27 28 29 30 31 32 33 44 43 42 41 40 39 38 37 11 10 9 8 7 6 5 4 3 2 1 w79e225 w79e226 w79e227 (lqfp 48-pin) xtal2 xtal1 p3.1, txd p3.0, rxd vdd ale 12 23 24 34 35 36 45 46 47 48 vss p4.2 p4.3 miso, ad0, p0.0 mosi, ad1, p0.1 spclk, ad2, p0.2 int2, ad4, p0.4 int3, ad5, p0.5 int4, ad6, p0.6 int5, ad7, p0.7 p3.4, t0, ic0, qea p3.5, t1, ic1, qeb ss , ad3, p0.3 ea p3.2, int0 p3.3, int1 p3.6, wr p3.7, rd
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 9 - revision a4.0 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 6 5 4 3 2 1 44 43 42 41 40 17 16 15 14 13 12 11 10 9 8 7 w79e225 w79e226 w79e227 (plcc 44-pin) xtal1 ale stadc, p4.0 adc7, p1.7 adc6, p1.6 adc5, p1.5 adc4, p1.4 rxd1, adc2, p1.2 brake, adc1, p1.1 t2, adc0, p1.0 txd1, adc3, p1.3 avss avdd p3.1, txd p3.0, rxd rst p4.1, t2ex, ic2, indx p2.0, a8, pwm0 vdd p2.1, a9, pwm1 p2.2, a10, pwm2 p2.3, a11, pwm3 p2.4, a12, pwm4 p2.5, a13, pwm5 p2.6, a14, scl p2.7, a15, sda vss xtal2 p3.4, t0, ic0, qea p3.5, t1, ic1, qeb miso, ad0, p0.0 mosi, ad1, p0.1 spclk, ad2, p0.2 int2, ad4, p0.4 int3, ad5, p0.5 int4, ad6, p0.6 int5, ad7, p0.7 ss , ad3, p0.3 psen ea p3.2, int0 p3.3, int1 p3.6, wr p3.7, rd
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 10 - revision a4.0 5. pin description symbol type initial state descriptions ea i - external access enable: this pin forces the processor to execute from external rom. the rom address and data are not presented on the bus if the ea pin is high. note: this pin has no internal pull-up or pull-down. the pin needs externally pull-up to execute from internal aprom. for executing from external aprom, the pin needs externally pull- down. the pin state is internally latched during all reset. user needs to take note that changes to /ea pin state after reset will not be effective. psen o h high program store enable: psen enables the external rom data in the port 0 address/data bu s. when internal rom access is performed, psen strobe signal will not be output from this pin. ale o h high address latch enable: ale enables the address latch that separates the address from the data on port 0. rst i l - reset: set this pin high for two machine cycles while the oscillator is running to reset the device. xtal1 i - crystal 1: crystal oscillator input or external clock input. xtal2 o - crystal 2: crystal oscillator output. v ss i - ground : ground potential. v dd i - power supply: supply voltage for operation. avdd i - analog power supply. avss i - analog ground potential. p0.0 ? p0.7 i/o d s h high-z port 0 : port 0 is an open-drain bi-directional i/o port. this port also provides a multiplexed low byte address/data bus during accesses to external memory. there is an embedded weakly pull- up resistor on each port 0 pin which can be enabled or disabled by setting or clearing of pup0, bit0 in a2h. the ports have alternate functions which are described below: p0.0, ad0, miso p0.1, ad1, mosi p0.2, ad2, spclk p0.3, ad3, /ss p0.4, ad4, int2 p0.5, ad5, int3 p0.6, ad6, int4 p0.7, ad7, int5
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 11 - revision a4.0 pin description, continued symbol type initial state descriptions p1.0 ? p1.7 i/o s h high port 1 : 8-bit, bi-directional i/o port with internal pull-ups. the ports have alternate functions which are described below: p1.0, adc0, t2 p1.1, adc1, brake p1.2, adc2, rxd1 p1.3, adc3, txd1 p1.4, adc4 p1.5, adc5 p1.6, adc6 p1.7, adc7 p2.0-p2.5 i/o s tri-state p2.6-p2.7 i/o d high-z port 2 : 8-bit, bi-directional i/o port. this port also provides the upper address bits for accesses to external memory. p2.6 to p2.7 can be software configured as i2c serial ports. p2.0 to p2.5 also provides pwm0 to pwm5 outputs. p2.0, a8, pwm0 p2.1, a9, pwm1 p2.2, a10, pwm2 p2.3, a11, pwm3 p2.4, a12, pwm4 p2.5, a13, pwm5 p2.6, a14, scl p2.7, a15, sda note: p2.6 and p2.7 are permanent open drain pins. when access to external memory beyond 16k region, user requires to add external pull-up registers (up to 2kohm) on these pins. this will result in slight incr ease in current consumption. p3.0-p3.7 i/o s h high port 3 : 8-bit, bi-directional i/o port with internal pull-ups. the ports have alternate functions which are described below: p3.0, rxd p3.1, txd p3.2, /int0 p3.3, /int1 p3.4, t0, ic0, qea p3.5, t1, ic1, qeb p3.6, /wr p3.7, /rd
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 12 - revision a4.0 pin description, continued symbol type initial state descriptions p4.0-p4.3 i/o s h high port 4 : 4-bit multipurpose programmable i/o port with alternate functions. the port 4 has four different operation modes. p4.0, stadc p4.1, t2ex, ic2 p4.2 p4.3 note: p4.2 & p4.3 are not supported in plcc44 pins package. p5.0-p5.1 i/o s tri-state port 5 : 2-bit, bit-directional i/o port. this port is not bit addressable. the alternate f unctions are described below: p5.0, pwm6 p5.1, pwm7 note: p5.0 & p5.1 are not supported in plcc44 pins package. note j type i: input, o: output, i/o: bi-directional, h: pull-hi gh, l: pull-low, d: open drain s: schmitt trigger 5.1 port 4 port 4, sfr p4 at address a5h, is a 4-bit multi purpose programmable i/o port which functions are i/o and chip-select function. it has four different operation modes: z mode 0 - p4.0 ~ p4.3 is 4-bit bi-directional i/o port which is the same as port 1. the default port 4 is a general i/o function. z mode1 - p4.0 ~ p4.3 are read data strobe signals which are synchronized with rd signal at specified addresses. these read data strobe signals can be used as chip-select signals for external peripherals. z mode2 - p4.0 ~ p4.3 are write data strobe signals which are synchronized with wr signal at specified addresses. these write data strobe signals can be used as chip-select signals for external peripherals. z mode3 - p4.0 ~ p4.3 are read/write data st robe signals which are synchronized with rd or wr signal at specified addresses. these read/writ e data strobe signals can be used as chip- select signals for external peripherals. when port 4 is configured with the feature of ch ip-select signals, the chip-select signal address range depends on the contents of the sfr p4xah, p4xal, p4cona and p4conb. p4xah and p4xal contain the 16-bit base address of p4.x. p4cona and p4conb contain the control bits to configure the port 4 operation mode.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 13 - revision a4.0 6. memory organization the w79e22x series separates the memory into tw o sections; program memory and data memory. program memory stores instruct ion op-codes, while data memory stores data or memory-mapped devices. 6.1 program memory (on-chip flash) w79e22x series includes one 16/32/64 k bytes of main flash eprom for application program (ap flash eprom) and one 4k bytes of flash eprom for loader program (ld flash eprom) to operate the in-system programming (isp) feature, and one 1/2/2 k bytes of nvm flash eprom for data storage. the 16/32/64 k bytes flash eprom is ap0 bank. the default active bank is ap0. in normal operation, the microcontroller will ex ecute the code from main flash eprom. by setting program registers, user can force the microcontrol ler to switch to programming mode which will cause it to execute the code (loader program) from t he 4k bytes of auxiliary ld flash eprom to update the contents of the 16/32/64 k bytes of main flash eprom. afte r reset, the microcontroller will executes the new application program in the main flash eprom. this isp feature makes the job easy and efficient in which the application needs to update firmware frequently without opening the chassis. 6.2 data memory w79e22x series can access up to 64kbytes of exte rnal data memory. this memory region is accessed by the movx instructions. unlike the 8051 derivatives, w79e22x ser ies contains on-chip 1/2/2 kbytes of data memory, which only can be accessed by movx instructions. these 1/2/2 kbytes of sram is between address 0000h and 03ffh/07ffh . access to the on-chip data memory is optional under software control. when enabled by dm eo bit of pmr register, a movx instruction that uses this area will go to the on-chip ram. if mo vx instruction accesses the addresses greater than 03ffh/07ffh cpu will automatically access external memo ry through port 0 and 2. when disabled, the 1/2/2 kb memory area is transparent to the sy stem memory map. any movx directed to the space between 0000h and ffffh goes to the expanded bu s on the port 0 and 2. this is the default condition. in addition, the device has the standard 256 bytes of on -chip ram. this can be accessed either by direct addressing or by indirect addressing. there are also some special function registers (sfrs), which can only be accessed by direct addressing.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 14 - revision a4.0 figure 6-1: w79e22x seriesa memory map 6.3 auxiliary sram w79e22x series has a 1/2/2 kb of data space sram which is read/write accessible and is memory mapped. this on-chip sram is accessed by the mo vx instruction. there is no conflict or overlap among the 256 bytes scratch-pad memory and the 1/2/2 kb auxiliary sram as they use different addressing modes and instructions. access to the on-chip data memory is optional under software control. set dmeo bit of pmr sfr to 1 will enable the on-chip 1/2/2 kb movx sram and at the same time ennvm bit must be cleared as nvm data uses the same instruction of movx. refer to. 6.4 nvm data flash w79e22x series 1/2/2 -kb nvm data block shown in the diagram on figure 6-1 shares the same address as aux-ram address. due to overlapping of aux-ram, nvm data memory and external data memory physical address, the following table is defined. ennvm bit (nvmcon.5) will enable read access to nvm data flash area. dme0 (pmr.0) will enable read access to aux-ram. ennvm dme0 data memory area 0 0 enable external ram read/write access by movx 0 1 enable aux-ram read/write access by movx 1 x enable nvm data memory read access by movx only. if eer or ewr is set and nvm flash erase or write control is busy, to set this bit read nvm data is invalid. table 6-1: bits setting for mo vx access to data memory area ennvm = 1 instructions nvm size = sram (1k)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 15 - revision a4.0 addr 1k addr > 1k movx a, @dptr (read) nvm 1 ext memory 1 movx a, @r0 (read) nvm 2 nop read access movx a, @r1 (read) nvm 2 nop movx @dptr, a (write) nop ext memory 1 movx @r0, a (write) nop nop write access movx @r1, a (write) nop nop table 6-2: w79e225 movx read/write access destination ennvm = 1 nvm size = sram (2k) instructions addr 2k addr > 2k movx a, @dptr (read) nvm 1 ext memory 1 movx a, @r0 (read) nvm 2 nop read access movx a, @r1 (read) nvm 2 nop movx @dptr, a (write) nop ext memory 1 movx @r0, a (write) nop nop write access movx @r1, a (write) nop nop table 6-3: w79e226/227 movx read/write access destination note: 1. a15~a0=dptr 2. a15~a8=xramah
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 16 - revision a4.0 it is partition into 16/32/32 pages area and each page has 64 bytes data as below figure. the page 0 is from 0000h ~ 003fh, page 1 is from 0040h ~ 007fh until page 31 address located at 07coh ~ 07ffh. figure 6-2: w79e225 nvm data mapping
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 17 - revision a4.0 2k bytes flash eprom page 31 64bytes page 30 64bytes | | | | | | page 03 64bytes page 02 64bytes page 01 64bytes page 00 64bytes 07ffh 07c0h 07bfh 0780h 0000h 003fh 0040h 007fh 0080h 00bfh 00c0h 00ffh 0000h 07ffh figure 6-3: w79e226/227 nvm data mapping
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 18 - revision a4.0 page start address end address page start address end address 0 0000h 003fh 16 0400h 043fh 1 0040h 007fh 17 0440h 047fh 2 0080h 00bfh 18 0480h 04bfh 3 00c0h 00ffh 19 04c0h 04ffh 4 0100h 013fh 20 0500h 053fh 5 0140h 017fh 21 0540h 057fh 6 0180h 01bfh 22 0580h 05bfh 7 01c0h 01ffh 23 05c0h 05ffh 8 0200h 023fh 24 0600h 063fh 9 0240h 027fh 25 0640h 067fh 10 0280h 02bfh 26 0680h 06bfh 11 02c0h 02ffh 27 06c0h 06ffh 12 0300h 033fh 28 0700h 073fh 13 0340h 037fh 29 0740h 077fh 14 0380h 03bfh 30 0780h 07bfh 15 03c0h 03ffh 31 07c0h 07ffh [note: page 16-31 is for w79e226/227 only] table 6-4: w79e22x series nvm page (n) area definition table it has a dedicated on-chip rc oscillator that is fix ed at 6mhz +/- 25% frequency to support clock source for the 1/2/2 k nvm data flash. the on chip oscillator is enabled only during program or erase operation, through ewr or eer in nvmcon sfr. ewr or eer bits are cleared by hardware after program or erase operation completed. the progra m/erase time is automat ically controlled by hardware. figure 6-4: nvm control
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 19 - revision a4.0 6.4.1 operation user is required to enable ennvm (nvmcon.5) bit for all nvm access (read/write/erase). before write data to nvm data, the page must be erased. a page is erased by setting page address which address will decode and enable page (n) on nvmaddrh and nvmaddrl, then set eer (nvmcon.7) and ennvm (nvmcon.5). the device will then automatic execute page erase. when completed, nvmf will be set by hardw are. nvmf should be cleared by software. interrupt request will be generated if envm (eie1.5) is enabled. eer bit will be cleared by hardware when erase is completed. the total erase time is about 5ms. for write, user must set address and data to nv maddrh/l and nvmdat, respectively. and then set ewr (nvmcon.6) and ennvm (nvmcon.5) to enable data write. when completed, the device will set nvmf flag. nvmf flag should be cleared by so ftware. similarly, interrupt request will be generated if envm (eie1.5) is enabled. the program time is about 50us. the following shows some examples of nvm operations (using w79e226/227): read nvm data is by movx a,@dptr/r0/r1 instruction: a read exceed 2 k will read the external address example1: dptr=0x07ff, r0/r1 = 0xff, xramah=0x07, ennvm=1 movx a,@dptr ? read nvm data at address 0x07ff movx a,@r0 ? read nvm data at address 0x07ff movx a,@r1 ? read nvm data at address 0x07ff example2: dptr = 0x2000, ennvm=1, dme0=0 movx a,@dptr ? read external ram dat a at address 0x2000, erase nvm by sfr register: example1: nvmaddrh = 0x07, nvmaddrl = 0xf0, page 31 will be enabled. after set eer, the page 31 will be erased. example2: nvmaddrh = 0x10, nvma ddrl = 0x00, invalid nvm eras e instruction (address exceed nvm boundary). write nvm by sfr register: example1: nvmaddrh = 0x 07, nvmaddrl = 0xf0 after set ewr, data will be written to the nvm address = 0x07f0 location. example2: nvmaddrh = 0x10, nvma ddrl = 0x00, after set ewr, invalid nvm write instruction (address exceed nvm boundary). during erase, write is invalid. likewise, during write, erase is invalid. an erase or write is invalid if nvmf is not clear by software. a write to nv maddrh and nvmaddrl is invalid during erase or write, and a write to nvmdat is invalid only during nvm write access.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 20 - revision a4.0 figure 6-5: nvm data memory control timing for security purposes, this nvm data flash provides an independent ?lock bit? located in security bits. it is used to protect the customer?s 1/2/2 k bytes of data code. it may be enabled after the external programmer finishes the programming and verifying sequence. once this bit is set to logic 0, the 1/2/2 k bytes of nvm flash eprom data can not be accessed again by external device. note: 1. nvmf can be polled or by h/w interrupt to indicate nvm data memory erase or write operation has completed. 2. while user program is erasing or writing to nvm data memory, the pc counter will continue to fetch for next instruction. 3. when uc is in idle mode and if nvm in terrupt and global interrupt are enabled, the completion of either erasing or programmi ng the nvm data memory will exit the idle condition.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 21 - revision a4.0 7. special function registers the w79e22x series uses special function regist ers (sfr) to control and monitor peripherals. the sfr reside in register locations 80-ffh and are only accessed by di rect addressing. the w79e22x series contains all the sfr present in the standard 8051/52, as well as some additional sfr, and, in some cases, unused bits in t he standard 8051/52 have new functions. sfr whose addresses end in 0 or 8 (hex) are bi t-addressable. the following table of sfr is condensed, with eight locations per row. empty locations indicate that there are no registers at these addresses. f8 eip eie1 eip1 ccl0 /pcntl cch0 /pcnth ccl1 /plscntl cch1 /plscnth intctrl f0 b spcr spsr spdr i2csaden eiph e8 eie i2con i2addr nvmaddrh i2dat i2status i2clk i2timer e0 acc adccon adch adcl pdtc1 pdtc0 pwmcon4 d8 wdcon pwmpl pwm0l nvmaddrl pwmcon1 pwm2l pwm6l pwmcon3 d0 psw pwmph pwm0h nvmdat qeicon pwm2h pwm6h wdcon2 c8 t2con t2mod rcap2l rcap2h tl2 th2 pwmcon2 pwm4l c0 scon1 sbuf1 t3mod t3con pmr fsplt adcps ta b8 ip saden saden1 povm povd pio pwmen pwm4h b0 p3 p5 rcap3l rcap3h eip1h iph a8 ie saddr saddr1 sfral sfrah sfrfd sfrcn a0 p2 xramah p4csin capcon0 capcon1 p4 ccl2 /maxcntl cch2 /maxcnth 98 scon sbuf p42al p42ah p43al p43ah nvmcon chpcon 90 p1 exif p4cona p4conb p40al p40ah p41al p41ah 88 tcon tmod tl0 tl1 th0 th1 ckcon ckcon1 80 p0 sp dpl dph tl3 th3 pcon table 7-1: special functi on register location table
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 22 - revision a4.0 symbol definition add ress msb bit_ a ddress, symbol lsb reset intctrl interrupt control register ffh - - int5ct1 int5ct0 int4ct1 i nt4ct0 int3ct1 int3ct0 xx00 0000 b cch1 /plscnth capture counter high 1 register feh cch1.7 /plscn th.7 cch1.6 /plscn th.6 cch1.5 /plscn th.5 cch1.4 /plscn th.4 cch1.3 /plscn th.3 cch1.2 /plscn th.2 cch1.1 /plscn th.1 cch1.0 /plscn th.0 0000 0000 b ccl1 /plscntl capture counter low 1 register fdh ccl1.7 /plscn tl.7 ccl1.6 /plscn tl.6 ccl1.5 /plscn tl.5 ccl1.4 /plscn tl.4 ccl1.3 /plscn tl.3 ccl1.2 /plscn tl.2 ccl1.1 /plscn tl.1 ccl1.0 /plscn tl.0 0000 0000 b cch0 /pcnth capture counter high 0 register fch cch0.7 /pcnth. 7 cch0.6 /pcnth. 6 cch0.5 /pcnth. 5 cch0.4 /pcnth. 4 cch0.3 /pcnth. 3 cch0.2 /pcnth. 2 cch0.1 /pcnth. 1 cch0.0 /pcnth. 0 0000 0000 b ccl0 /pcntl capture counter low 0 register fbh ccl0.7 /pcntl. 7 ccl0.6 /pcntl. 6 ccl0.5 /pcntl. 5 ccl0.4 /pcntl. 4 ccl0.3 /pcntl. 3 ccl0.2 /pcntl. 2 ccl0.1 /pcntl. 1 ccl0.0 /pcntl. 0 0000 0000 b eip1 extended interrupt priority 1 fah - - pnvmi pcptf pt3 pbkf ppwmf pspi xx00 0000 b eie1 interrupt enable 1 f9h - - envm ecptf et3 ebk epwm espi xx00 0000 b eip extended interrupt priority f8h (ff) ps1 (fe) px5 (fd) px4 (fc) pwdi (fb) px3 (fa) px2 (f9) - (f8) pi2c 0000 00x0 b eiph extended interrupt high priority f7h ps1h px5h px4h pwdih px3h px2h - pi2ch 0000 00x0 b i2csaden i2c slave address mask f6h i2csad en.7 i2csad en.6 i2csad en.5 i2csad en.4 i2csad en.3 i2csad en.2 i2csad en.1 i2csad en.0 1111 1110 b spdr serial peripheral data register f5h spd.7 spd.6 spd.5 spd.4 spd.3 spd.2 spd.1 spd.0 xxxx xxxxb spsr serial peripheral status register f4h spif wcol spiovf modf drss - - - 0000 0xxxb spcr serial peripheral control register f3h ssoe spe lsbfe mstr cpol cpha spr1 spr0 0000 0100 b b b register f0h (f7) (f6) (f5) (f4) (f3) (f2) (f1) (f0) 0000 0000 b i2timer i2c timer counter register efh - - - - - enti div4 tif xxxx x000b i2clk i2c clock rate eeh i2clk.7 i2clk.6 i2clk. 5 i2clk.4 i2clk.3 i2clk.2 i2clk.1 i2clk.0 0000 0000 b i2status i2c status register edh i2statu s.7 i2statu s.6 i2statu s.5 i2statu s.4 i2statu s.3 - - - 1111 1000 b i2dat i2c data ech i2dat.7 i2dat.6 i2dat.5 i 2dat.4 i2dat.3 i2dat.2 i2dat.1 i2dat.0 0000 0000 b n vmaddr h nvm high byte address ebh - - - - - nvmad drh.10 nvmad drh.9 nvmad drh.8 xxxx x000b i2addr i2c slave address eah addr.7 addr.6 addr.5 addr.4 addr.3 addr.2 addr.1 gc 0000 0000 b i2con i2c control register e9h - ens sta sto si aa i2cin - x000 000x b eie extended interrupt enable e8h (ef) es1 (ee) ex5 (ed) ex4 (ec) ewdi (eb) ex3 (ea) ex2 (e9) (e8) ei2c 0000 00x0 b pwmcon4 pwm control register 4 e7h pwmeo m pwmoo m pwm6o m pwm7o m - - - bkf 0000 xxx0b pdtc0 dead time control register 0 e6h pdtc0.7 pdtc0.6 pdtc0.5 pdtc0.4 pd tc0.3 pdtc0.2 pdtc0.1 pdtc0.0 0000 0000 b pdtc1 dead time control register 1 e5h pdtc1.7 pdtc1.6 pdtc1.5 pdtc1.4 pd tc1.3 pdtc1.2 pdtc1.1 pdtc1.0 0000 0000 b adcl adc converter result low byte e3h adclk1 adclk0 - - - - adc.1 adc.0 00xx xxxxb
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 23 - revision a4.0 continued symbol definition addr ess msb bit_ a ddress, symbol lsb reset adch adc converter result high byte e2h adc.9 adc.8 adc.7 adc.6 adc.5 adc.4 adc.3 adc.2 xxxx xxxxb adccon adc control register e1h adcen - adcex adci adcs aadr2 aadr1 aadr0 0x00 0000 b acc accumulator e0h (e7) (e6) (e5) (e4) (e3) (e2) (e1) (e0) 0000 0000 b pwmcon3 pwm control register 3 dfh pwm7b pwm6b pwm5b pwm4b pwm3b pwm2b pwm1b pwm0b 0000 0000 b pwm6l pwm 6 low bits register deh pwm6.7 pwm6.6 pwm6.5 pwm6.4 pwm6.3 pwm6.2 pwm6.1 pwm6.0 0000 0000 b pwm2l pwm 2 low bits register ddh pwm2.7 pwm2.6 pwm2.5 pwm2.4 pwm2.3 pwm2.2 pwm2.1 pwm2.0 0000 0000 b pwmcon1 pwm control register 1 dch pwmru n load pwmf clrpw m pwm6i pwm4i pwm2i pwm0i 0000 0000 b n vmaddrl nvm low byte address dbh nvmad drh.7 nvmad drh.6 nvmad drh.5 nvmad drh.4 nvmad drh.3 nvmad drh.2 nvmad drh.1 nvmad drh.8 0000 0000 b pwm0l pwm 0 low bits register dah pwm0.7 pwm0.6 pwm0.5 pwm0.4 pwm0.3 pwm0.2 pwm0.1 pwm0.0 0000 0000 b pwmpl pwm counter low register d9h pwmp.7 pwmp.6 pwmp.5 pwmp.4 pwmp.3 pwmp.2 pwmp.1 pwmp.0 0000 0000 b wdcon watch-dog control d8h (df) - (de) por (dd) - (dc) - (db) wdif (da) wtrf (d9) ewt (d8) rwt 0100 0000 b wdcon2 watch-dog control2 d7h - - - - - - - strld 0000 0000 b pwm6h pwm 6 high bits register d6h - - - - pwm6.1 1 pwm6.1 0 pwm6.9 pwm6.8 xxxx 0000b pwm2h pwm 2 high bits register d5h - - - - pwm2.1 1 pwm2.1 0 pwm2.9 pwm2.8 xxxx 0000b qeicon qei control register d4h - - - disidx dir qeim1 qeim0 qeien xxx0 0000b nvmdat nvm data d3h nvmda t.7 nvmda t.6 nvmda t.5 nvmda t.4 nvmda t.3 nvmda t.2 nvmda t.1 nvmda t.0 0000 0000 b pwm0h pwm 0 high bits register d2h - - - - pwm0.1 1 pwm0.1 0 pwm0.9 pwm0.8 xxxx 0000b pwmph pwm counter high register d1h - - - - pwmp.1 1 pwmp.1 0 pwmp.9 pwmp.8 xxxx 0000b psw program status word d0h (d7) cy (d6) ac (d5) f0 (d4) rs1 (d3) rs0 (d2) ov (d1) f1 (d0) p 0000 0000 b pwm4l pwm 4 low bits register cfh pwm4.7 pwm4.6 pwm4.5 pwm4.4 pwm4.3 pwm4.2 pwm4.1 pwm4.0 0000 0000 b pwmcon2 pwm control register 2 ceh bkch bkps bpen bken fp1 fp0 pmod1 pmod0 0000 0000 b th2 t2 reg. high cdh th2.7 th2.6 th2. 5 th2.4 th2.3 th2.2 th2.1 th2.0 0000 0000 b tl2 t2 reg. low cch tl2.7 tl2.6 tl2.5 tl2.4 tl2.3 tl2.2 tl2.1 tl2.0 0000 0000 b rcap2h t2 capture low cbh rcap2h .7 rcap2h .6 rcap2h .5 rcap2h .4 rcap2h .3 rcap2h .2 rcap2h .1 rcap2h .0 0000 0000 b rcap2l t2 capture high cah rcap2l .7 rcap2l .6 rcap2l .5 rcap2l .4 rcap2l .3 rcap2l .2 rcap2l .1 rcap2l .0 0000 0000 b t2mod timer 2 mode c9h hc5 hc4 hc3 hc2 t2cr - - dcen 0000 0xx0 b t2con timer 2 control c8h (cf) tf2 (ce) exf2 (cd) rclk (cc) tclk (cb) exen2 (ca) tr2 (c9) t c/ (c8) rl2 cp/ 0000 0000 b ta time access register c7h ta.7 ta.6 ta.5 ta.4 ta.3 ta.2 ta.1 ta.0 0000 0000 b ddio disable digital i/o c6h ddio.7 ddio.6 ddio.5 ddio.4 ddio.3 ddio.2 ddio.1 ddio.0 0000 0000 b
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 24 - revision a4.0 continued symbol definition addr ess msb bit_ a ddress, symbol lsb reset fsplt fault sampling time register c5h scmp1 scmp0 sfp1 sfp0 sfcen sfcst sfcdir lsbd 0000 0000 b pmr power management register c4h - - - - - aleoff - dme0 xxxx x0x0b t3con timer 3 control c3h tf3 - - - - tr3 - 0xxx x0x0b t3mod timer 3 mode control c2h enld icen2 icen1 icen0 t3cr - - - 0000 0xxxb sbuf1 serial buffer 1 c1h sbuf1.7 sbuf1.6 sbuf1 .5 sbuf1.4 sbuf1.3 sbuf1.2 sbuf1.1 sbuf1.0 xxxx xxxxb scon1 serial control 1 c0h (bf) sm0_1/f e_1 (be) sm1_1 (bd) sm2_1 (bc) ren_1 (bb) tb8_1 (ba) rb8_1 (b9) ti_1 (b8) ri_1 0000 0000 b pwm4h pwm 4 high bits register bfh - - - - pwm4.11 pwm4.1 0 pwm4.9 pwm4.8 xxxx 0000b pwmen pwm output enable register beh pwm7e n pwm6e n pwm5e n pwm4e n pwm3e n pwm2e n pwm1e n pwm0e n 0000 0000 b pio pwm pin output source select bdh pio7 pio6 pio5 pio4 pio3 pio2 pio1 pio0 0000 0000 b povd pwm output state registers bch povd.7 povd.6 povd.5 povd.4 povd .3 povd.2 povd.1 povd.0 0000 0000 b povm pwm output override control registers bbh povm.7 povm.6 povm.5 povm.4 povm .3 povm.2 povm.1 povm.0 0000 0000 b saden1 slave address mask 1 bah saden1 .7 saden1 .6 saden1 .5 saden1 .4 saden1 .3 saden1 .2 saden1 .1 saden1 .0 0000 0000 b saden slave address mask b9h saden. 7 saden. 6 saden. 5 saden. 4 saden. 3 saden. 2 saden. 1 saden. 0 0000 0000 b ip interrupt priority b8h (bf) (be) padc (bd) pt2 (bc) ps (bb) pt1 (ba) px1 (b9) pt0 (b8) px0 0000 0000 b iph interrupt high priority b7h - padch pt2h psh pt1h px1h pt0h px0h x000 0000 b eip1h extended interrupt high priority 1 b6h - - pnvmih pcptfh pt3h pbkfh ppwmh pspih xx00 0000 b rcap3h reload capture 3 high register b5h rcap3h .7 rcap3h .6 rcap3h .5 rcap3h .4 rcap3h .3 rcap3h .2 rcap3h .1 rcap3h .0 0000 0000 b rcap3l reload capture 3 low register b4h rcap3l .7 rcap3l .6 rcap3l .5 rcap3l .4 rcap3l .3 rcap3l .2 rcap3l .1 rcap3l .0 0000 0000 b p5 port 5 b1h - - - - - - pwm7 pwm6 xxxx xx11b p3 port 3 b0h (b7) rd (b6) wr (b5) t1/ ic1/qeb (b4) t0/ ico/qe a (b3) /int1 (b2) /int0 (b1) txd (b0) rxd 1111 1111 b sfrcn f/w flash control afh - wfwin noe nce ctrl3 ct rl2 ctrl1 ctrl0 x011 1111 b sfrfd f/w flash data aeh d7 d6 d5 d4 d3 d2 d1 d0 xxxx xxxxb sfrah f/w flash high address adh a15 a14 a13 a12 a11 a10 a9 a8 0000 0000 b sfral f/w flash low address ach a7 a6 a5 a4 a3 a2 a1 a0 0000 0000 b saddr1 slave address 1 aah saddr1 .7 saddr1 .6 saddr1 .5 saddr1 .4 saddr1 .3 saddr1 .2 saddr1 .1 saddr1 .0 0000 0000 b saddr slave address a9h saddr. 7 saddr. 6 saddr. 5 saddr. 4 saddr. 3 saddr. 2 saddr. 1 saddr. 0 0000 0000 b ie interrupt enable a8h (af) ea (ae) eadc (ad) et2 (ac) es (ab) et1 (aa) ex1 (a9) et0 (a8) ex0 0000 0000 b
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 25 - revision a4.0 continued symbol definition addr ess msb bit_ a ddress, symbol lsb reset cch2/max cnth input capture 2 high register/ maximum counter high register a7h cch2.7 /maxcn th.7 cch2.6 maxcn th.6 cch2.5 /maxcn th.5 cch2.4 /maxcn th.4 cch2.3 /maxcn th.3 cch2.2 /maxcn th.2 cch2.1 /maxcn th.1 cch2.0 /maxcn th.0 0000 0000 b ccl2/max cntl input capture 2 low register/ maximum counter low register a6h ccl2.7 /maxcn tl.7 ccl2.6 /maxcn tl.6 ccl2.5 /maxcn tl.5 ccl2.4 /maxcn tl.4 ccl2.3 /maxcn tl.3 ccl2.2 /maxcn tl.2 ccl2.1 /maxcn tl.1 ccl2.0 /maxcn tl.0 0000 0000 b p4 port 4 a5h - - - - p4.3 p4.2 t2ex/ic 2 stadc xxxx 1111b capcon1 capture control 1 register a4h - - enf2 enf1 enf0 cptf2 cptf1/ dirf cptf0/ qeif xx00 0000 b capcon0 capture control 0 register a3h cct2.1 cct2.0 cct1.1 cct1.0 cct0.1 cct0.0 ccld1 ccld0 0000 0000 b p4csin p4 cs sign a2h p43inv p42inv p41inv p40inv - pwdnh rmwfp p0up 0000 x000 b xramah ram high byte address a1h - - - - - a10 a9 a8 0000 0000 b p2 port 2 a0h (a7) a15/ sda (a6) a14/ scl (a5) a13/ pwm5 (a4) a12/ pwm4 (a3) a11/ pwm3 (a2) a10/ pwm2 (a1) a9/ pwm1 (a0) a8/ pwm0 1111 1111 b chpcon on chip programming control 9fh swrst/ reboot - ld/ap - - - ldsel enp 0000 0000 b nvmcon nvm control 9eh eer ewr ennvm - - - - nvmf 000x xxx0b p43ah hi addr. comparator of p4.3 9dh a15 a14 a13 a12 a11 a10 a9 a8 0000 0000 b p43al lo addr. comparator of p4.3 9ch a7 a6 a5 a4 a3 a2 a1 a0 0000 0000 b p42ah hi addr. comparator of p4.2 9bh a15 a14 a13 a12 a11 a10 a9 a8 0000 0000 b p42al lo addr. comparator of p4.2 9ah a7 a6 a5 a4 a3 a2 a1 a0 0000 0000 b sbuf serial buffer 99h sbuf.7 sbuf.6 sbuf. 5 sbuf.4 sbuf.3 sbuf.2 sbuf.1 sbuf.0 xxxx xxxxb scon serial control 98h (9f) sm0/fe (9e) sm1 (9d) sm2 (9c) ren (9b) tb8 (9a) rb8 (99) ti (98) ri 0000 0000 b p41ah hi addr. comparator of p4.1 97h a15 a14 a13 a12 a11 a10 a9 a8 0000 0000 b p41al lo addr. comparator of p4.1 96h a7 a6 a5 a4 a3 a2 a1 a0 0000 0000 b p40ah hi addr. comparator of p4.0 95h a15 a14 a13 a12 a11 a10 a9 a8 0000 0000 b p40al lo addr. comparator of p4.0 94h a7 a6 a5 a4 a3 a2 a1 a0 0000 0000 b p4conb p4 control register b 93h p43fun 1 p43fun 0 p43cmp 1 p43cmp 0 p42fun 1 p42fun 0 p42cmp 1 p42cmp 0 0000 0000 b p4cona p4 control register a 92h p41fun 1 p41fun 0 p41cmp 1 p41cmp 0 p40fun 1 p40fun 0 p40cmp 1 p40cmp 0 0000 0000 b exif external interrupt flag 91h ie5 ie4 ie3 ie2 - - - - 0000 xxxxb p1 port 1 90h (97) adc7 (96) adc6 (95) adc5 (94) adc4 (93) txd1/ adc3 (92) rxd1/ adc2 (91) adc1/ brake (90) t2/ adc0 1111 1111 b ckcon1 clock control 1 8fh - - - - - - ccdiv1 ccdiv0 0000 0000 b ckcon clock control 8eh wd1 wd0 t2m t1m t0m md2 md1 md0 0000 0001 b th1 timer high 1 8dh th1.7 th1.6 th1. 5 th1.4 th1.3 th1.2 th1.1 th1.0 0000 0000 b
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 26 - revision a4.0 continued symbol definition addr ess msb bit_ a ddress, symbol lsb reset th0 timer high 0 8ch th0.7 th0.6 th0. 5 th0.4 th0.3 th0.2 th0.1 th0.0 0000 0000 b tl1 timer low 1 8bh tl1.7 tl1.6 tl1.5 tl1.4 tl1.3 tl1.2 tl1.1 tl1.0 0000 0000 b tl0 timer low 0 8ah tl0.7 tl0.6 tl0.5 tl0.4 tl0.3 tl0.2 tl0.1 tl0.0 0000 0000 b tmod timer mode 89h gate t c / m1 m0 gate t c / m1 m0 0000 0000 b tcon timer control 88h (8f) tf1 (8e) tr1 (8d) tf0 (8c) tr0 (8b) ie1 (8a) it1 (89) ie0 (88) it0 0000 0000 b pcon power control 87h smod sm od0 - - gf1 gf0 pd idl 00xx 0000 b th3 timer high 3 85h th3.7 th3.6 th3. 5 th3.4 th3.3 th3.2 th3.1 th3.0 0000 0000 b tl3 timer low 3 84h tl3.7 tl3.6 tl3.5 tl3.4 tl3.3 tl3.2 tl3.1 tl3.0 0000 0000 b dph data pointer high 83h dph.7 dph.6 dp h.5 dph.4 dph.3 dph.2 dph.1 dph.0 0000 0000 b dpl data pointer low 82h dpl.7 dpl.6 dpl.5 dpl.4 dpl.3 dpl.2 dpl.1 dpl.0 0000 0000 b sp stack pointer 81h sp.7 sp.6 sp.5 sp.4 sp.3 sp.2 sp.1 sp.0 0000 0111 b p0 port 0 80h (87) int5 (86) int4 (85) int3 (84) int2 (83) /ss (82) spclk (81) mosi (80) miso 1111 1111 b table 7-2: special function registers
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 27 - revision a4.0 port 0 bit: 7 6 5 4 3 2 1 0 p0.7 p0.6 p0.5 p0.4 p0.3 p0.2 p0.1 p0.0 mnemonic: p0 address: 80h port 0 is an open-drain 8-bit bi-directional i/o port. as an alternate function port 0 can function as the multiplexed address/data bus to access off-chip me mory. during the time when ale is high, the lsb of a memory address is pres ented. when ale is low, the port transi ts to a bi-directional data bus. this bus is used for reading external rom and for reading or writing external ram memory or peripherals. when used as a memory bus, the port provides active high drivers. the reset condition of port 0 is tri- state. pull-up resistors are required when using port 0 as an i/o port. bit name function 0 p0.0 miso: spi master in slave out. 1 p0.1 mosi: spi master out slave in. 2 p0.2 spclk: spi clock. 3 p0.3 /ss: slave select. 4 p0.4 int2: external interrupt 2. 5 p0.5 int3: external interrupt 3. 6 p0.6 int4: external interrupt 4. 7 p0.7 int5: external interrupt 5. stack pointer bit: 7 6 5 4 3 2 1 0 sp.7 sp.6 sp.5 sp.4 sp.3 sp.2 sp.1 sp.0 mnemonic: sp address: 81h the stack pointer stores the scratch-pad ram addre ss where the stack begin s. in other words it always points to the top of the stack. data pointer low bit: 7 6 5 4 3 2 1 0 dpl.7 dpl.6 dpl.5 dpl.4 dpl.3 dpl.2 dpl.1 dpl.0 mnemonic: dpl address: 82h this is the low byte of the standard 8032 16-bit data pointer.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 28 - revision a4.0 data pointer high bit: 7 6 5 4 3 2 1 0 dph.7 dph.6 dph.5 dph.4 dph.3 dph.2 dph.1 dph.0 mnemonic: dph address: 83h this is the high byte of the standard 8032 16-bit data pointer. timer 3 lsb bit: 7 6 5 4 3 2 1 0 tl3.7 tl3.6 tl3.5 tl3.4 tl3.3 tl3.2 tl3.1 tl3.0 mnemonic: tl3 address: 84h bit name function 7-0 timer 3 lsb lsb of timer3 timer 3 msb bit: 7 6 5 4 3 2 1 0 th3.7 th3.6 th3.5 th3.4 th3.3 th3.2 th3.1 th3.0 mnemonic: th3 address: 85h bit name function 7-0 timer 3 msb msb of timer3 power control bit: 7 6 5 4 3 2 1 0 smod smod0 - - gf1 gf0 pd idl mnemonic: pcon address: 87h bit name function 7 smod this bit doubles the serial port baud rate in mode 1, 2, and 3 when set to 1. 6 smod0 framing error detection enable. when smod0 is set to 1, then scon.7 (scon1.7) now indicates a frame error and acts as the fe (fe_1) flag. when smod0 is 0, then scon.7 (scon1.7) acts as per the standard 8032 function. 5-4 - reserved. 3-2 gf1-0 these two bits are general purpose user flags. 1 pd setting this bit causes the device to go into the powerdown mode. in this mode all the clocks are stopped and program execution is frozen. 0 idl setting this bit causes the device to go into the idle mode. in this mode the clock to the cpu is stopped, so program ex ecution is frozen, but the clock to the serial ports, timer, pwm, adc, spi and interrupt blocks is not stopped, and these blocks continue operating unhindered.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 29 - revision a4.0 timer control bit: 7 6 5 4 3 2 1 0 tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 mnemonic: tcon address: 88h bit name function 7 tf1 timer 1 overflow flag. this bit is set when timer 1 overflows. it is cleared automatically when the program does a timer 1 interrupt service routine. software can also set or clear this bit. 6 tr1 timer 1 run control. this bit is set or cleared by software to turn timer/counter on or off. 5 tf0 timer 0 overflow flag. this bit is set when timer 0 overflows. it is cleared automatically when the program does a timer 0 interrupt service routine. software can also set or clear this bit. 4 tr0 timer 0 run control. this bit is set or cleared by software to turn timer/counter on or off. 3 ie1 interrupt 1 edge detect flag: set by hardware when an edge/level is detected on int1. this bit is cleared by hardware when the service routine is vectored to only if the interrupt was edge triggered. otherwise it follows the inverse of the pin. 2 it1 interrupt 1 type control. set/cleared by software to specify falling edge/ low level triggered external inputs. 1 ie0 interrupt 0 edge detect flag. set by hardware when an edge/level is detected on int0. this bit is cleared by hardware when the service routine is vectored to only if the interrupt was edge triggered. otherwise it follows the inverse of the pin. 0 it0 interrupt 0 type control: set/cleared by software to specify falling edge/ low level triggered external inputs.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 30 - revision a4.0 timer mode control bit: 7 6 5 4 3 2 1 0 gate t c / m1 m0 gate t c / m1 m0 timer1 timer0 mnemonic: tmod address: 89h bit name function 7 gate gating control: when this bit is set, timer 1 is enabled only while the int1 pin is high and the tr1 control bit is set. when cleared, the int1 pin has no effect, and timer 1 is enabled whenever tr1 is set. 6 t c/ timer or counter select: when clear, timer 1 is incremented by the internal clock. when set, the timer counts falling edges on the t1 pin. 5 m1 timer 1 mode select bit 1. see table below. 4 m0 timer 1 mode select bit 0. see table below. 3 gate gating control: when this bit is set, timer 0 is enabled only while the int0 pin is high and the tr0 control bit is set. when cleared, the int0 pin has no effect, and timer 0 is enabled whenever tr0 is set. 2 t c/ timer or counter select: when clear, timer 0 is incremented by the internal clock. when set, the timer counts falling edges on the t0 pin. 1 m1 timer 0 mode select bit 1. see table below. 0 m0 timer 0 mode select bit 0. see table below. m1, m0: mode select bits: m1 m0 mode 0 0 mode 0: 8-bit timer/counter tlx serves as 5-bit pre-scale. 0 1 mode 1: 16-bit timer/counter, no pre-scale. 1 0 mode 2: 8-bit timer/counter with auto-reload from thx 1 1 mode 3: (timer 0) tl0 is an 8-bit timer/counter c ontrolled by the standard timer-0 control bits. th0 is an 8-bit timer only controlled by timer-1 control bits. (timer 1) timer/counter 1 is stopped. timer 0 lsb bit: 7 6 5 4 3 2 1 0 tl0.7 tl0.6 tl0.5 tl0.4 tl0.3 tl0.2 tl0.1 tl0.0 mnemonic: tl0 address: 8ah tl0.7-0 timer 0 lsb timer 1 lsb bit: 7 6 5 4 3 2 1 0 tl1.7 tl1.6 tl1.5 tl1.4 tl1.3 tl1.2 tl1.1 tl1.0 mnemonic: tl1 address: 8bh tl1.7-0 timer 1 lsb
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 31 - revision a4.0 timer 0 msb bit: 7 6 5 4 3 2 1 0 th0.7 th0.6 th0.5 th0.4 th0.3 th0.2 th0.1 th0.0 mnemonic: th0 address: 8ch th0.7-0 timer 0 msb timer 1 msb bit: 7 6 5 4 3 2 1 0 th1.7 th1.6 th1.5 th1.4 th1.3 th1.2 th1.1 th1.0 mnemonic: th1 address: 8dh th1.7-0 timer 1 msb clock control bit: 7 6 5 4 3 2 1 0 wd1 wd0 t2m t1m t0m md2 md1 md0 mnemonic: ckcon address: 8eh bit name function 7 wd1 watchdog timer mode select bit 1. see table below. 6 wd0 watchdog timer mode select bit 0. see table below. 5 t2m timer 2 clock select: 1: divide-by-4 clock. 0: divide-by-12 clock. 4 t1m timer 1 clock select: 1: divide-by-4 clock. 0: divide-by-12 clock. 3 t0m timer 0 clock select: 1: divide-by-4 clock. 0: divide-by-12 clock. 2 md2 stretch movx select bit 2: md2, md1, and md0 select the stretch value for the movx instruction. the rd or wr strobe is stretched by the selected interval, which enables the device to access faster or slower external memory de vices or peripherals without the need for external circuits. by default, the stretch value is one. see table below. (note: when accessing on-chip sram, these bits have no effect, and the movx instruction always takes two machine cycles.) 1 md1 stretch movx select bit 1. see md2. 0 md0 stretch movx select bit 0. see md2.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 32 - revision a4.0 wd1, wd0: mode select bits: these bits determine the time-out periods for the watchdog timer. the reset time-out period is 512 clocks more than the interrupt time-out period. wd1 wd0 interrupt time-out reset time-out 0 0 2 17 2 17 + 512 0 1 2 20 2 20 + 512 1 0 2 23 2 23 + 512 1 1 2 26 2 26 + 512 md2, md1, md0: stretch movx select bits: md2 md1 md0 stretch value movx duration 0 0 0 0 2 machine cycles 0 0 1 1 3 machine cycles (default) 0 1 0 2 4 machine cycles 0 1 1 3 5 machine cycles 1 0 0 4 6 machine cycles 1 0 1 5 7 machine cycles 1 1 0 6 8 machine cycles 1 1 1 7 9 machine cycles clock control 1 bit: 7 6 5 4 3 2 1 0 - - - - - - ccdiv1 ccdiv0 mnemonic: ckcon1 address: 8fh bit name function 7-2 - reserved. 1-0 ccdiv timer 3 clock select. ccdiv1 ccdiv0 timer 3 clock 0 0 fosc 0 1 fosc/4 1 0 fosc/16 1 1 fosc/32 port 1 bit: 7 6 5 4 3 2 1 0 p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0 mnemonic: p1 address: 90h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 33 - revision a4.0 bit name function 7-0 p1 general purpose i/o port. most instructions will read t he port pins in case of a port read access, however in case of r ead-modify-write instructions, the port latch is read. some pins also have alternate input or output functions. the alternate functions are described below. alternate function1 alternate function2 p1.0 t2: external i/o for timer/counter 2 adc0: analog input0 p1.1 pwm brake adc1: analog input1 p1.2 rxd1 adc2: analog input2 p1.3 txd1 adc3: analog input3 p1.4 adc4: analog input4 p1.5 adc5: analog input5 p1.6 adc6: analog input6 p1.7 adc7: analog input7 external interrupt flag bit: 7 6 5 4 3 2 1 0 ie5 ie4 ie3 ie2 - - - - mnemonic: exif address: 91h bit name function 7 ie5 external interrupt 5 flag. set by har dware when a rising/falling/both edges is detected onint5 pin. 6 ie4 external interrupt 4 flag. set by har dware when a rising/falling/both edges is detected on int4 pin. 5 ie3 external interrupt 3 flag. set by har dware when a rising/falling/both edges is detected on int3 pin. 4 ie2 external interrupt 2 flag. set by hardw are when a rising edge is detected on int2 pin. 3-0 - reserved. port 4 control register a bit: 7 6 5 4 3 2 1 0 p41fun1 p41fun0 p41cmp1 p41cmp 0 p40fun1 p40fun0 p40cmp1 p40cmp0 mnemonic: p4cona address: 92h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 34 - revision a4.0 port 4 control register b bit: 7 6 5 4 3 2 1 0 p43fun1 p43fun0 p43cmp1 p43cmp 0 p42fun1 p42fun0 p42cmp1 p42cmp0 mnemonic: p4conb address: 93h bit name function p4xfun1, p4xfun0 port 4 alternate modes. =00: mode 0. p4.x is a general purpose i/o port which is the same as port 1. =01: mode 1. p4.x is a read strobe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xcmp1, p4xcmp0. =10: mode 2. p4.x is a write strobe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xcmp1, p4xcmp0. =11: mode 3. p4.x is a read/write str obe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xcmp1, p4xcmp0. p4xcmp1, p4xcmp0 port 4 chip-select mode address comparison: =00: compare the full address (16 bits length) with the base address registers p4xah and p4xal. =01: compare the 15 high bits (a15-a1) of address bus with the base address registers p4xah and p4xal. =10: compare the 14 high bits (a15-a2) of address bus with the base address registers p4xah and p4xal. =11: compare the 8 high bits (a15-a8) of address bus with the base address registers p4xah and p4xal. p4.0 base address low byte register bit: 7 6 5 4 3 2 1 0 a7 a6 a5 a4 a3 a2 a1 a0 mnemonic: p40al address: 94h p4.0 base address high byte register bit: 7 6 5 4 3 2 1 0 a15 a14 a13 a12 a11 a10 a9 a8 mnemonic: p40ah address: 95h p4.1 base address low byte register bit: 7 6 5 4 3 2 1 0 a7 a6 a5 a4 a3 a2 a1 a0 mnemonic: p41al address: 96h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 35 - revision a4.0 p4.1 base address high byte register bit: 7 6 5 4 3 2 1 0 a15 a14 a13 a12 a11 a10 a9 a8 mnemonic: p41ah address: 97h serial port control bit: 7 6 5 4 3 2 1 0 sm0/fe sm1 sm2 ren tb8 rb8 ti ri mnemonic: scon address: 98h bit name function 7 sm0/fe serial port mode select bit 0 or framing error flag: this bit is controlled by the smod0 bit in the pcon register. (sm0) see table below. (fe) this bit indicates an invalid stop bit. it must be manually cleared by software. 6 sm1 serial port mode select bit 1. see table below. 5 sm2 serial port clock or multi-processor communication. (mode 0) this bit controls the serial port cloc k. if set to zero, the serial port runs at a divide-by-12 clock of the oscillator. this is compatible with the standard 8051/52. if set to one, the serial clock is a di vide-by-4 clock of the oscillator. (mode 1) if sm2 is set to one, ri is not ac tivated if a valid stop bit is not received. (modes 2 / 3) this bit enables multi-proces sor communication. if sm2 is set to one, ri is not activated if rb8, the ninth data bit, is zero. 4 ren receive enable: 1: enable serial reception. 0: disable serial reception. 3 tb8 (modes 2 / 3) this is the 9th bit to transmit. this bit is set by software. 2 rb8 (mode 0) no function. (mode 1) if sm2 = 0, rb8 is t he stop bit that was received. (modes 2 / 3) this is the 9th bit that was received. 1 ti transmit interrupt flag: this flag is set by the hardware at the end of the 8th bit in mode 0 or at the beginning of the stop bi t in the other modes during serial transmission. this bit must be cleared by software. 0 ri receive interrupt flag: this flag is set by the hardware at the end of the 8th bit in mode 0 or halfway through the stop bits in the other modes during serial reception. however, sm2 can restrict this behavior. this bit can only be cleared by software. sm1, sm0: mode select bits: sm0 sm1 mode description length baud rate 0 0 0 synchronous 8 tclk divided by 4 or 12 0 1 1 asynchronous 10 variable 1 0 2 asynchronous 11 tclk divided by 32 or 64 1 1 3 asynchronous 11 variable
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 36 - revision a4.0 erial data buffer bit: 7 6 5 4 3 2 1 0 sbuf.7 sbuf.6 sbuf.5 sbuf.4 sbuf.3 sbuf.2 sbuf.1 sbuf.0 mnemonic: sbuf address: 99h bit name function 7-0 sbuf serial data is read from or written to this location. it consists of two separate 8 bit registers. one is the receive buffer, and t he other is the transmit buffer. any read access gets data from the receive data bu ffer, while write access is to the transmit data buffer. p4.2 base address low byte register bit: 7 6 5 4 3 2 1 0 a7 a6 a5 a4 a3 a2 a1 a0 mnemonic: p42al address: 9ah p4.2 base address high byte register bit: 7 6 5 4 3 2 1 0 a15 a14 a13 a12 a11 a10 a9 a8 mnemonic: p42ah address: 9bh p4.3 base address low byte register bit: 7 6 5 4 3 2 1 0 a7 a6 a5 a4 a3 a2 a1 a0 mnemonic: p43al address: 9ch p4.3 base address high byte register bit: 7 6 5 4 3 2 1 0 a15 a14 a13 a12 a11 a10 a9 a8 mnemonic: p43ah address: 9dh nvm control bit: 7 6 5 4 3 2 1 0 eer ewr ennvm - - - - nvmf mnemonic: nvmcon address: 9eh bit name function 7 eer set this bit to erase nvm data of page (n) to ffh. the nvm has 32 pages that each page has 64 bytes data memory. by select nvmaddrh and nvmaddrl of nvm addres s registers that will automatic enable page area. if set this bit, the page will be page erased, after finished, the nvmf flag will be set to ?1?, then this bit will be cleared. if nvmf flag is set, the erase and write nvm data memory are invalid.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 37 - revision a4.0 continued bit name function 6 ewr set this bit is write data to nvm data memory by nvmaddrh and nvmaddrl to decode nvm data memory. if finished, nvmf flag will be set to ?1?, and then this bit will be cleared. if nvmf flag is set, the erase and write nvm are invalid. 5 ennvm to enable read nvm data memory area, refer as below table. 0: to disable the movx instruction to read nvm data memory. 1: to enable the movx instruction to read nvm data memory, the external ram or aux-ram will be disabled. 4~1 - reserved. 0 nvmf nvm data memory erases or writes finished flag. if nvm data memory is finished by eras e or write, it will be set to ?1? by hardware and clear by software. and it will be interrupted when nvm erase/write interrupt is enabled. isp control register bit: 7 6 5 4 3 2 1 0 swrst/ hwb - ld/ap - - - ldsel enp mnemonic: chpcon address: 9fh bit name function 7 w:swrst r:hwb write access to this bit is different from read access. write this bit to 1 to force the microcon troller to reset to the initial condition, just like power-on reset. this action re -boots the microcontroller and starts normal operation. this bit w ill be cleared during the reset. read this bit to determine whether or not a hardware reboot is in progress. if cpu is rebooted by p3.6 & p3.7 or p4.3, this bit is set to 1 after the hardware reboot. note: p4.3 pin is available in 48l lqfp package only. 6 - reserved. 5 ld/ap (read-only) 0: cpu is executing ap flash eprom 1: cpu is executing ld flash eprom 4-2 - reserved. 1 ldsel (write-only) loader program location selection. this bit should be set before entering isp mode. 0: the executing program is in the 64-kb ap flash eprom. the 4-kb ld flash eprom is the destination for re-programming. 1: the executing program is in the 4-kb memory bank. the 64-kb ap flash eprom is the destination for re-programming. 0 enp flash eprom programming enable. 1: enable in-system programming mode. in this mode, erase, program and read operations are achieved. 0: disable in-system programming mode. the on-chip flash memory is read- only.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 38 - revision a4.0 the way to enter isp mode is to set enp to 1 and write ldsel properly then force cpu in idle mode, after idle mode is released cpu will restart from ap or ld rom according the value of ldsel. port 2 bit: 7 6 5 4 3 2 1 0 p2.7 p2.6 p2.5 p2.4 p2.3 p2.2 p2.1 p2.0 mnemonic: p2 address: a0h bit name function 7-0 p2 this port functions as an address bus dur ing external memory access, and as a general-purpose i/o port on devices that incorporate internal program memory. when p2 functions a non-multiplexed address bus a15-a8 the port latch cannot be used for general i/o purposes but exists to support the movx instructions. port 2 data will only be brought out on the p2.7-0 pins during indirect movx instructions. alternate function p2.0 pwm0 output. p2.1 pwm1 output. p2.2 pwm2 output. p2.3 pwm3 output. p2.4 pwm4 output. p2.5 pwm5 output. p2.6 scl, i2c serial clock. p2.7 sda, i2c serial data. xramah bit: 7 6 5 4 3 2 1 0 - - - - - a10 a9 a8 mnemonic: xramah address: a1h bit name function 7-3 - reserved. 2-0 a10-8 xramah is used for high byte addres s memory access through a15-8, when cpu executes movx with r0 (or r1) instructions. depending ennvm and dme0 setting, and address, the memory accessed may differs. table below shows the memory access destination. this device has on-chip sram at 1/2/2 k bytes. note: user should take care when accessing the memory with this instruction. access to invalid regions may cause undesirable results.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 39 - revision a4.0 port 4 chip-select polarity bit: 7 6 5 4 3 2 1 0 p43inv p42inv p41inv p40inv - pwdnh rmwfp pup0 mnemonic: p4csin address: a2h bit name function 7-4 p4xinv the active polarity of p4.x when it is set as a chip-select strobe output. high = active high. low = active low. note: x = 3,2,1,0. 3 - reserved. 2 pwdnh set pwdnh to logic 1 then ale and psen will keep high state, clear this bit to logic 0 then ale and psen will outpu t low during power down mode. 1 rmwfp control read path of instruction ?read-m odify-write?. when this bit is set, the read path of executing ?read-m odify-write? instruction is from port pin otherwise from sfr. 0 pup0 enable port 0 weak pull up. capture control 0 register bit: 7 6 5 4 3 2 1 0 cct2.1 cct2.0 cct1.1 cct1.0 cct0.1 cct0.0 ccld1 ccld0 mnemonic: capcon0 address: a3h bit name function 7-6 cct2.1-0 capture 2 edge select. cct2.1 cct2.0 description 0 0 rising edge trigger 0 1 falling edge trigger 1 0 rising and falling edge trigger 1 1 reserved. 5-4 cct1.1-0 capture 1 edge select. cct1.1 cct1.0 description 0 0 rising edge trigger 0 1 falling edge trigger 1 0 rising and falling edge trigger 1 1 reserved. 3-2 cct0.1-0 capture 0 edge select. cct0.1 cct0.0 description 0 0 rising edge trigger 0 1 falling edge trigger 1 0 rising and falling edge trigger 1 1 reserved.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 40 - revision a4.0 continued bit name function 1-0 ccld.1-0 reload trigger select. ccld1 ccld0 description 0 0 timer 3 overflow (default) 0 1 reload by capture 0 block 1 0 reload by capture 1 block 1 1 reload by capture 2 block capture control 1 register bit: 7 6 5 4 3 2 1 0 - - enf2 enf1 enf0 cptf2 cptf1/ cptf0 mnemonic: capcon1 address: a4h bit name function 7-6 - reserved. 5 enf2 enable filter for capture input 2. 4 enf1 enable filter for capture input 1. 3 enf0 enable filter for capture input 0. 2 cptf2 input capture/reload 2 interrupt flag. 1 cptf1/dirf input capture 2 flag share the same bit with dirf flag. ic mode - input capture/reload 1 interrupt flag. qei mode - direction changed interrupt flag. bit is set by hardware when direction index (dir) changes state and direction change interrupt is requested if it is enabled. dirf is cleared by software. 0 cptf0/qeif input capture 0 flag share the same bit with qei flag. ic mode ? input capture/reload 0 interrupt flag. qei mode - qei interrupt flag. 1. in free-counting mode, if pulse counter overflows or underflows. 2. in compare-counting mode, if pulse counter overflows from maximum count to zero or underflows from zero to maximum count. port 4 bit: 7 6 5 4 3 2 1 0 - - - - p4.3 p4 .2 p4.1 p4.0 mnemonic: p4 address: a5h bit name function 7-4 - reserved. 3-2 p4 gpio. 1 p4 gpio. alternate function t2ex/ic2 for time r 2 external trigger/input capture 2 respectively. 0 p4 gpio. alternate function stadc. external start adc trigger input.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 41 - revision a4.0 input capture 2/maximum counter low register bit: 7 6 5 4 3 2 1 0 ccl2.7/ maxcnt l.7 ccl2.6/ maxcnt l.6 ccl2.5/ maxcnt l.5 ccl2.4/ maxcnt l.4 ccl2.3/ maxcnt l.3 ccl2.2/ maxcnt l.2 ccl2.1/ maxcnt l.1 ccl2.0/ maxcnt l.0 mnemonic: ccl2/maxcntl address: a6h input capture 2/maximum counter high register bit: 7 6 5 4 3 2 1 0 cch2.7/ maxcnt h.7 cch2.6/ maxcnt h.6 cch2.5/ maxcnt h.5 cch2.4/ maxcnt h.4 cch2.3/ maxcnt h.3 cch2.2/ maxcnt h.2 cch2.1/ maxcnt h.1 cch2.0/ maxcnt h.0 mnemonic: cch2/maxcnth address: a7h interrupt enable bit: 7 6 5 4 3 2 1 0 ea eadc et2 es et1 ex1 et0 ex0 mnemonic: ie address: a8h bit name function 7 ea global enable: enable/disable all interrupts. 6 eadc enable adc interrupt. 5 et2 enable timer 2 interrupt. 4 es enable serial port 0 interrupts. 3 et1 enable timer 1 interrupt. 2 ex1 enable external interrupt 1. 1 et0 enable timer 0 interrupt. 0 ex0 enable external interrupt 0. slave address bit: 7 6 5 4 3 2 1 0 saddr.7 saddr.6 saddr.5 saddr.4 saddr.3 saddr.2 saddr.1 saddr.0 mnemonic: saddr address: a9h bit name function 7-0 saddr the saddr should be programmed to the given or broadcast address for serial port to which the slave processor is designated. slave address 1 bit: 7 6 5 4 3 2 1 0 saddr1.7 saddr1.6 saddr1.5 saddr1.4 saddr1.3 saddr1.2 saddr1.1 saddr1.0 mnemonic: saddr1 address: aah
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 42 - revision a4.0 bit name function 7-0 saddr1 the saddr1 should be programmed to the given or broadcast address for serial port 1 to which the slave processor is designated. isp address low byte bit: 7 6 5 4 3 2 1 0 a7 a6 a5 a4 a3 a2 a1 a0 mnemonic: sfral address: ach low byte destination address for in system programming operations. isp address high byte bit: 7 6 5 4 3 2 1 0 a15 a14 a13 a12 a11 a10 a9 a8 mnemonic: sfrah address: adh low byte destination address for in system pr ogramming operations. (sfrah, sfral) represents the address of the rom byte that will be erased, programmed or read. isp data buffer bit: 7 6 5 4 3 2 1 0 d7 d6 d5 d4 d3 d2 d1 d0 mnemonic: sfrfd address: aeh in isp mode, read/write a specific byte rom content must go through sfrfd register. isp operation modes bit: 7 6 5 4 3 2 1 0 - wfwin noe nce ctrl3 ctrl2 ctrl1 ctrl0 mnemonic: sfrcn address: afh bit name function 7 - reserved. 6 wfwin on-chip flash eprom bank select for in-system programming. 0= ap flash eprom bank is selected as destination for re-programming. 1= ld flash eprom bank is selected as destination for re-programming. 5 noe flash eprom output enable. 4 nce flash eprom chip enable. 3-0 ctrl the flash control signals.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 43 - revision a4.0 isp mode wfwin noe nce ctrl[3:0] sfrah, sfral sfrfd erase 4kb ld flash 1 1 0 0010 x x erase 16/32/64k ap flash 0 1 0 0010 x x program 4kb ld flash 1 1 0 0001 address in data in program 16/32/64kb ap flash 0 1 0 0001 address in data in read 4kb ld flash 1 0 0 0000 address in data out read 16/32/64kb ap flash 0 0 0 0000 address in data out port 3 bit: 7 6 5 4 3 2 1 0 p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 mnemonic: p3 address: b0h bit name function 7-0 p3 general purpose i/o port. each pin also has an alternate input or output function that is controlled by other sfrs. the alternate function is enabled if the corresponding port latch bit is set to 1. alternate function p3.7 rd strobe for read from external ram. p3.6 wr strobe for writ e to external ram. p3.5 t1/ic1/qeb; timer/counter 1 external count input/input capture 1/qei input b. p3.4 t0/ic0/qea; timer/counter 0 external count input/input capture 0/qei input a. p3.3 /int0 external interrupt 1. p3.2 /int1 external interrupt 0. p3.1 txd serial port output. p3.0 rxd serial port input. port 5 bit: 7 6 5 4 3 2 1 0 - - - - - - p5.1 p5.0 mnemonic: p5 address: b1h bit name function 7-2 - reserved. 1-0 p5 general purpose i/o port. each pin also has an alternate input or output function. this port can not support bit addressable.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 44 - revision a4.0 alternate function p5.1 pwm7 output function p5.0 pwm6 output function timer 3 reload lsb bit: 7 6 5 4 3 2 1 0 rcap3l.7 rcap3l.6 rcap3l.5 rcap3l.4 rcap3l.3 rcap3l.2 rcap3l.1 rcap3l.0 mnemonic: rcap3l address: b4h bit name function 7-0 rcap3l timer 3 reload lsb: this register is lsb of a 16 bit reload value when timer 3 is configured in reload mode. it served also as a compare register when timer 3 is configured as compare mode (see cmp/rl3 bit). timer 3 reload msb bit: 7 6 5 4 3 2 1 0 rcap3h.7 rcap3h.6 rcap3h.5 rcap3h.4 rcap3h.3 rcap3h.2 rcap3h.1 rcap3h.0 mnemonic: rcap3h address: b5h bit name function 7-0 rcap3h timer 3 reload msb: this register is msb of a 16 bit reload value when timer 3 is configured in reload mode. it served al so as a compare register when timer 3 is configured as compare mode (see cmp/rl3 bit). extended interrupt high priority 1 bit: 7 6 5 4 3 2 1 0 - - pnvmih pcptfh pt3h pbkfh ppwmfh pspih mnemonic: eip1 address: b6h bit name function 7-6 - reserved. 5 pnvmih nvm interrupt high priority. pnvmih = 1 sets it to highest priority level. 4 pcptfh capture/reload interrupt high priority. pc ptfh = 1 sets it to highest priority level. 3 pt3h timer 3 interrupt high priority. pt3h = 1 sets it to highest priority level. 2 pbkfh pwm brake interrupt high priority. pbkfh = 1 sets it to highest priority level. 1 ppwmfh pwm period interrupt high priority. ppw mfh = 1 sets it to highest priority level. 0 pspih spi interrupt high priority. pspih = 1 sets it to highest priority level. interrupt high priority bit: 7 6 5 4 3 2 1 0 - padch pt2h pshh pt1h px1h pt0h px0h mnemonic: iph address: b7h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 45 - revision a4.0 bit name function 7 - reserved. 6 padch this bit defines the adc interrupt high priority. padch = 1 sets it to highest priority level. 5 pt2h this bit defines the timer 2 interrupt hi gh priority. pt2h = 1 sets it to highest priority level. 4 psh this bit defines the serial port 0 interrupt high priority. psh = 1 sets it to highest priority level. 3 pt1h this bit defines the timer 1 interrupt hi gh priority. pt1h = 1 sets it to highest priority level. 2 px1h this bit defines the external interrupt 1 high priority. px1h = 1 sets it to highest priority level. 1 pt0h this bit defines the timer 0 interrupt hi gh priority. pt0h = 1 sets it to highest priority level. 0 px0h this bit defines the external interrupt 0 high priority. px0h = 1 sets it to highest priority level. interrupt priority bit: 7 6 5 4 3 2 1 0 - padc pt2 ps pt1 px1 pt0 px0 mnemonic: ip address: b8h bit name function 7 - reserved. 6 padc this bit defines the adc interrupt priority . padc = 1 sets it to higher priority level. 5 pt2 this bit defines the timer 2 interrupt priority. pt2 = 1 sets it to higher priority level. 4 ps this bit defines the serial port 0 interrupt pr iority. ps = 1 sets it to higher priority level. 3 pt1 this bit defines the timer 1 interrupt priority. pt1 = 1 sets it to higher priority level. 2 px1 this bit defines the external interrupt 1 pr iority. px1 = 1 sets it to higher priority level. 1 pt0 this bit defines the timer 0 interrupt priority. pt0 = 1 sets it to higher priority level. 0 px0 this bit defines the external interrupt 0 pr iority. px0 = 1 sets it to higher priority level.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 46 - revision a4.0 slave address mask enable bit: 7 6 5 4 3 2 1 0 saden.7 saden.6 sad en.5 saden.4 saden.3 sad en.2 saden.1 saden.0 mnemonic: saden address: b9h bit name function 7-0 saden this register enables the automatic addr ess recognition feature of the serial port. when a bit in the saden is set to 1, the same bit location in saddr will be compared with the incoming serial port data. when saden.n is 0, then the bit becomes don't care in the comparison. this register enables the automatic address recognition feature of the serial port. when all the bits of saden are 0, interrupt will occur for any incoming address. slave address mask enable 1 bit: 7 6 5 4 3 2 1 0 saden1.7 saden1.6 saden1. 5 saden1.4 saden1.3 saden1. 2 saden1.1 saden1.0 mnemonic: saden1 address: bah bit name function 7-0 saden1 this register enables the automatic addr ess recognition feature of the serial port 1. when a bit in the saden1 is set to 1, the same bit location in saddr1 will be compared with the incoming serial port data. when saden1.n is 0, then the bit becomes don't care in the comparison. this register enables the automatic address recognition feature of the serial port. when all the bits of saden1 are 0, interrupt will occur for any incoming address. pwm output override control registers bit: 7 6 5 4 3 2 1 0 povm.7 povm.6 povm.5 povm.4 povm.3 povm.2 povm.1 povm.0 mnemonic: povm address: bbh bit name function 7-0 povm pwm override mode enable bits; 0: the pwm output follows the corresponding pwm generator. 1: the pwm output is equal to corresponding bit in povd. pwm output state registers bit: 7 6 5 4 3 2 1 0 povd.7 povd.6 povd.5 povd.4 povd.3 povd.2 povd.1 povd.0 mnemonic: povd address: bch
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 47 - revision a4.0 bit name function 7-0 povd pwm override data represents the value of pwm[7:0] respectively in override mode. 1 = output on pwm i/o pin is active when the corresponding pwm output override bit is cleared. 0 = output on pwm i/o pin is inactive when the corresponding pwm output override bit is cleared. pwm pin output source select bit: 7 6 5 4 3 2 1 0 pio7 pio6 pio5 pio4 pio3 pio2 pio1 pio0 mnemonic: pio address: bdh bit name function 7-0 pio.x select pin output source from pwm or i/o register; x=0~7; pion is effective only when option bit pwmoe/pwmee/pwm6e/pwm7e is in enabled status. reset value=0; 1 = correspondent i/o pin with high source/sink current. 0 = pwmn output; n=0~7 with high source/sink current. pwm output enable register bit: 7 6 5 4 3 2 1 0 pwm7en pwm6en pwm5en pwm4en pwm3en pwm2en pwm1en pwm0en mnemonic: pwmen address: beh bit name function 6,4,2,0 pwmeen set high to enable even pwm output; e = 0,2,4,6; reset value=0; 1 = enable pwm output. 0 = disable pwm output. 7,5,3,1 pwmoen set high to enable odd pwm output; o = 1,3,5,7; reset value=0; 1 = enable pwm output. 0 = disable pwm output. pwm 4 high bits register bit: 7 6 5 4 3 2 1 0 - - - - pwm4.11 pwm4.10 pwm4.9 pwm4.8 mnemonic: pwm4h address: bfh bit name function 7~4 - reserved 3~0 pwm4.11 ~pwm4.8 the pwm 4 register bit 11~8.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 48 - revision a4.0 serial port control 1 bit: 7 6 5 4 3 2 1 0 sm0_1/fe_1 sm1_1 sm2_1 ren_1 tb8_1 rb8_1 ti_1 ri_1 mnemonic: scon1 address: c0h bit name function 7 sm0_1/ fe_1 serial port 1 mode select bit 0 or framing error flag: this bit is controlled by the smod0 bit in the pcon register. (sm0) see table below. (fe) this bit indicates an invalid stop bit. it must be manually cleared by software. 6 sm1_1 serial port 1 mode select bit 1. see table below. 5 sm2_1 serial port clock or multi-processor communication. (mode 0) this bit controls the serial port cloc k. if set to zero, the serial port runs at a divide-by-12 clock of the oscillator. this is compatible with the standard 8051/52. if set to one, the serial clock is a di vide-by-4 clock of the oscillator. (mode 1) if sm2_1 is set to one, ri_1 is not activated if a valid stop bit is not received. (modes 2 / 3) this bit enables multi-proc essor communication. if sm2_1 is set to one, ri_1 is not activated if rb 8_1, the ninth data bit, is zero. 4 ren_1 receive enable: 1: enable serial reception. 0: disable serial reception. 3 tb8_1 (modes 2 / 3) this is the 9th bit to transmit. this bit is set by software. 2 rb8_1 (mode 0) no function. (mode 1) if sm2_1 = 0, rb8_1 is t he stop bit that was received. (modes 2 / 3) this is the 9th bit that was received. 1 ti_1 transmit interrupt flag: this flag is set by the hardware at the end of the 8th bit in mode 0 or at the beginning of the stop bi t in the other modes during serial transmission. this bit must be cleared by software. 0 ri_1 receive interrupt flag: this flag is set by the hardware at the end of the 8th bit in mode 0 or halfway through the stop bits in the other modes during serial reception. however, sm2_1 can restrict this behav ior. this bit can only be cleared by software. sm1_1, sm0_1: mode select bits: sm0_1 sm1_1 mode description length baud rate 0 0 0 synchronous 8 tclk divided by 4 or 12 0 1 1 asynchronous 10 variable 1 0 2 asynchronous 11 tclk divided by 32 or 64 1 1 3 asynchronous 11 variable
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 49 - revision a4.0 serial data buffer 1 bit: 7 6 5 4 3 2 1 0 sbuf_1.7 sbuf_1.6 sbuf_1.5 sbuf_1.4 sbuf_1.3 sbuf_1.2 sbuf_1.1 sbuf_1.0 mnemonic: sbuf1 address: c1h bit name function 7-0 sbuf_1 for serial port 1. serial data is read fr om or written to this location. it actually consists of two separate 8 bit registers. one is the receive buffer, and the other is the transmit buffer. any read access gets data from the receive data buffer, while write access is to the transmit data buffer. timer 3 mode control bit: 7 6 5 4 3 2 1 0 enld icen2 icen1 icen0 t3cr - - - mnemonic: t3mod address: c2h bit name function 7 enld enable reloads from rcap3 registers to timer 3 counters. 6 icen2 capture 2 external enable. this bit enabl es the capture/reload function on the ic2 pin. an edge trigger (programmable by capcon0.cct2[1:0] bits) detected on the ic2 pin will result in capture from free running timer 3 counters to input capture 2 registers, or reload from rcap3 registers to timer 3 counters. 1 = enable. 0 = disable. 5 icen1 capture 1 external enable. this bit enabl es the capture/reload function on the ic1 pin. an edge trigger (programmable by capcon0.cct1[1:0] bits) detected on the ic1 pin will result in capture from free running timer 3 counters to input capture 1 registers, or reload from rcap3 registers to timer 3 counters. 1 = enable. 0 = disable. 4 icen0 capture 0 external enable. this bit enabl es the capture/reload function on the ic0 pin. an edge trigger (programmable by capcon0.cct0[1:0] bits) detected on the ic0 pin will result input capture fr om free running timer 3 counters to input capture 0 registers, or reload from rcap3 registers to timer 3 counters. 1 = enable. 0 = disable. 3 t3cr timer 3 capture reset. in the timer 3 capture mode this bit enables/disables hardware automatically reset timer 3 while the value in tl3 and th3 have been transferred into the input capture register (cclx, cchx). priority is given to t3cr to reset counter after capture. 2-0 - reserved.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 50 - revision a4.0 timer 3 control bit: 7 6 5 4 3 2 1 0 tf3 - - - - tr3 - cmp / rl3 mnemonic: t3con address: c3h bit name function 7 tf3 timer 3 overflows flag. this bit is set when timer 3 overflows. it is cleared only by software and set by hardware. 6-3 - reserved. 2 tr3 timer 3 run control. this bit enables/disables the operation of timer 3. halting this will preserve the current count in th3, tl3. 1 - reserved. 0 cmp / rl3 compare/reload select. this bit determines whether the timer 3 will be use for compare or reload function. 0 = timer 3 as reload mode, tf3 indicates the overflow flag 1 = timer 3 as compare mode, tf3 indicates the compare match flag. power management register bit: 7 6 5 4 3 2 1 0 - - - - - aleoff - dme0 mnemonic: pmr address: c4h bit name function 7-3 - reserved. 2 aleoff this bit disables the expression of the ale signal on the device pin during all on board program and data memory accesses . external memory accesses will automatically enable ale independent of aleoff. aleoff=0: ale expression is enabled. aleoff=1: ale expression is disabled. 1 - reserved. 0 dme0 this bit determines the on chip movx sram to be enabled or disabled. set this bit to 1 will enable the on chip 2 kb movx sram. fault sampling time register bit: 7 6 5 4 3 2 1 0 scmp1 scmp0 sfp1 sfp0 sfcen sfcst sfcdir lsbd mnemonic: fsplt address: c5h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 51 - revision a4.0 bit name function 7-6 scmp [1:0] smart fault compare value selector (read/write): 00 = 4 01 = 16 10 = 64 11 = 128 5-4 sfp[1:0] smart fault sampling frequency selector (read/write): 00 = fosc/4 01 = fosc/8 10 = fosc/16 11 = fosc/128 3 sfcen smart fault/brake counter enable (read/write): 0 = disable, and clear internal smart fault counter. 1 = enable smart fault detector. 2 sfcst smart fault/brake counter status (read only): 0 = counter is non-active. 1 = counter is active. 1 sfcdir smart fault/brake counters direction status (read only): 0 = down counting. 1 = up counting. 0 lsbd low level smart brake detector: 0 = disable low level smart brake detector. 1 = enable low level smart brake detector. it will be cleared by software. adc pin select bit: 7 6 5 4 3 2 1 0 adcps.7 adcps.6 adcps.5 adcps. 4 adcps.3 adcps.2 a dcps.1 adcps.0 mnemonic: adcps address: c6h bit name function 7-0 adcps adc input pin select. there are 8 adc input pins shared with p1.0~p1.7. its? functions are controlled by the bit value in adcps. set the bit to switch the corresponding pin to adc input port; clear the bit to disable the pin to perform adc input port. the reset value is 00h. bit corresponding pin bit corresponding pin adcps.0 p1.0 adcps.4 p1.4 adcps.1 p1.1 adcps.5 p1.5 adcps.2 p1.2 adcps.6 p1.6 adcps.3 p1.3 adcps.7 p1.7 timed access bit: 7 6 5 4 3 2 1 0 ta.7 ta.6 ta.5 ta.4 ta.3 ta.2 ta.1 ta.0 mnemonic: ta address: c7h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 52 - revision a4.0 bit name function 7-0 ta the timed access register controls the access to protected bits. to access protected bits, the user must first writ e aah to ta. this must be immediately followed by a write of 55h to ta. now a wi ndow is opened in the protected bits for three machine cycles, during which the user can write to these bits. for detail data, please refer "timed access protection" section. timer 2 control bit: 7 6 5 4 3 2 1 0 tf2 exf2 rclk tclk exen2 tr2 2 t c / 2 rl cp / mnemonic: t2con address: c8h bit name function 7 tf2 timer 2 overflows flag. this bit is set when timer 2 overflows. it is also set when the count is equal to the capture register in down count mode. it can be set only if rclk and tclk are both 0. it is clea red only by software. software can also set this bit. 6 exf2 timer 2 external flag. a negative transition on the t2ex pin (p4.1) or timer 2 underflow/overflow will cause this flag to set based on 2 rl cp / , exen2 and dcen bits. if exf2 is set by a negative transition, this flag must be cleared by software. setting this bit in software or detection of a negative transition on t2ex pin will force a timer interrupt if enabled. 5 rclk receive clock flag. this bit determines t he serial port time-base when receiving data in serial modes 1 or 3. if it is 0, then timer 1 overflow is used for baud rate generation, else timer 2 overflow is used. setting this bit forces timer 2 in baud rate generator mode. 4 tclk transmit clock flag: this bit determines the serial port time-base when transmitting data in mode 1 and 3. if it is set to 0, the timer 1 overflow is used to generate the baud rate clock; else timer 2 overflow is used. setting this bit forces timer 2 in baud rate generator mode. 3 exen2 timer 2 external enable. this bit enabl es the capture/reload function on the t2ex pin if timer 2 is not generating baud clocks for the serial port. if this bit is 0, then the t2ex pin will be ignored, el se a negative transition detected on the t2ex pin will result in capture or reload. 2 tr2 timer 2 run control. this bit enables/disabl es the operation of timer 2. halting this will preserve the current count in th2, tl2. 1 t c/ counter/timer select. this bit determines whether timer 2 will function as a timer or a counter. independent of this bit, the timer will run at 2 clocks per tick when used in baud rate generator mode. if it is set to 0, then timer 2 operates as a timer at a speed depending on t2m bit (ckcon.5), else, it will count negative edges on t2 pin. 0 rl2 cp/ capture/reload select. this bit deter mines whether the capture or reload function will be used for timer 2. if either rclk or tclk is se t, this bit will not function and the timer will function in an auto-reload mode following each overflow. if the bit is 0 then auto-reload will occur when timer 2 overflows or a falling edge is detected on t2ex if exen2 =1. if this bit is 1, then timer 2 captures will occur when a falling edge is detected on t2ex if exen2=1.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 53 - revision a4.0 timer 2 mode control bit: 7 6 5 4 3 2 1 0 hc5 hc4 hc3 hc2 t2cr - - dcen mnemonic: t2mod address: c9h bit name function 7 hc5 hardware clears int5 flag. setting this bi t allows the flag of external interrupt 5 to be automatically cleared by hardwar e while entering the interrupt service routine. 6 hc4 hardware clears int4 flag. setting this bi t allows the flag of external interrupt 4 to be automatically cleared by hardwar e while entering the interrupt service routine. 5 hc3 hardware clears int3 flag. setting this bi t allows the flag of external interrupt 3 to be automatically cleared by hardwar e while entering the interrupt service routine. 4 hc2 hardware clears int2 flag. setting this bi t allows the flag of external interrupt 2 to be automatically cleared by hardwar e while entering the interrupt service routine. 3 t2cr timer 2 capture reset. in the timer 2 capture mode this bit enables/disables hardware automatically reset timer 2 while the value in tl2 and th2 have been transferred into the capture register. 2-1 - reserved. 0 dcen down count enable. this bit, in conjunction with the t2ex pin, controls the up/down direction that timer 2 counts in 16-bit auto-reload mode. timer 2 capture lsb bit: 7 6 5 4 3 2 1 0 rcap2l. 7 rcap2l. 6 rcap2l. 5 rcap2l. 4 rcap2l. 3 rcap2l. 2 rcap2l. 1 rcap2l. 0 mnemonic: rcap2l address: cah bit name function 7-0 rcap2l timer 2 capture lsb: this register is used to capture the tl2 value when a timer 2 is configured in capture mode. rcap2l is also used as the lsb of a 16 bit reload value when timer 2 is configured in auto reload mode. timer 2 capture msb bit: 7 6 5 4 3 2 1 0 rcap2h. 7 rcap2h. 6 rcap2h. 5 rcap2h. 4 rcap2h. 3 rcap2h. 2 rcap2h. 1 rcap2h. 0 mnemonic: rcap2h address: cbh
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 54 - revision a4.0 bit name function 7-0 rcap2h timer 2 capture hsb: this register is used to capture the th2 value when a timer 2 is configured in capture mode. rc ap2h is also used as the hsb of a 16 bit reload value when timer 2 is configured in auto reload mode. timer 2 lsb bit: 7 6 5 4 3 2 1 0 tl2.7 tl2.6 tl2.5 tl2.4 tl2.3 tl2.2 tl2.1 tl2.0 mnemonic: tl2 address: cch tl2 timer 2 lsb timer 2 msb bit: 7 6 5 4 3 2 1 0 th2.7 th2.6 th2.5 th2.4 th2.3 th2.2 th2.1 th2.0 mnemonic: th2 address: cdh th2 timer 2 msb pwm control register 2 bit: 7 6 5 4 3 2 1 0 bkch bkps bpen bken fp1 fp0 pmod1 pmod0 mnemonic: pwmcon2 address: ceh bit name function 7 bkch see table below for bkch settings. 6 bkps select which brake condition triggers br ake flag. lsbd bit is described in sfr fsplt. bkps lsbd description 0 0 0 = brake is asserted if p1.1 is low. 1 0 1 = brake is asserted if p1.1 is high x 1 low level smart brake detector. 5 bpen see table below for bpen settings. 4 bken 0 = the brake is never asserted. 1 = the brake is enabled. bit name function 3-2 fp[1:0] select pwm frequency prescaler select bits. the clock source of prescaler, fpwm is in phase wi th fosc if pwmrun=1. fp[1:0] fpwm 00 f osc 01 f osc /2 10 f osc /4 11 f osc /16
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 55 - revision a4.0 continued bit name function 1-0 pmod[1:0] pwm mode selects bits: pmod[1:0] description 00 edge-aligned mode. (up counter) 01 single-shot mode. (up counter) 10 center aligned mode (up-down counter) 11 reserved brake condition table bpen bkch brake condition 0 0 brake on, (software brake and keeping brake). software brake condition. when acti ve (bpen=bkch=0, and bken=1), pwm output follows pwmnb setting. this br ake has no effect on pwmrun bit; therefore, internal pwm generator continue s to run. when the brake is released, the state of pwm output depends on the current state of pwm generator output during the release. 0 1 brake on, when pwm is not running (pwmrun=0), the pwm output condition is follow pwmnb setting. when the brake is released (by disabling bken = 0), the pwm output resumes to the state when pwm generator stop running prior to enabling the brake. brake off, when pwm is running (pwmrun=1). 1 0 brake on, when brake pin asserted, pw m output follows pwmnb setting. the pwmrun will be clear. external pin brake condition. when active (by external pin), pwm output follows pwmnb setting. pwmrun will be cleared by hardware. bkf flag will be set. when the brake is released (by de-assert ing the external pin + disabling bken = 0), the pwm output resumes to the stat e of the pwm generator output prior to the brake. 1 1 this brake condition (by brake pin) c auses bkf to be set, but pwm generator continues to run. the pwm output does not follow pwmnb, instead it output continuously as per normal without affected by the brake. pwm 4 low bits register bit: 7 6 5 4 3 2 1 0 pwm4.7 pwm4.6 pwm4.5 pwm4.4 pwm4.3 pwm4.2 pwm4.1 pwm4.0 mnemonic: pwm4l address: cfh pwm4.7-0 pwm4 low bits register. program status word bit: 7 6 5 4 3 2 1 0 cy ac f0 rs1 rs0 ov f1 p mnemonic: psw address: d0h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 56 - revision a4.0 bit name function 7 cy carry flag. set for an arithmetic operation which results in a carry being generated from the alu. it is also used as the accumulator for the bit operations. 6 ac auxiliary carry: set when the previous operation resulted in a carry (during addition) or a borrow (during subtract ion) from the high order nibble. 5 f0 user flag 0. a general purpose flag that can be set or cleared by the by software. 4-3 rs.1-0 register bank selects bits: rs1 rs2 register bank address 0 0 0 00-07h 0 1 1 08-0fh 1 0 2 10-17h 1 1 3 18-1fh 2 ov overflow flag. set when a carry was generat ed from the seventh bit but not from the 8th bit as a result of the previous operation or vice-versa. 1 f1 user flag 1. general purpose flag that can be set or cleared by the user by software. 0 p parity flag. set/cleared by hardware to indicate odd/even number of 1's in the accumulator. pwmp counter high bits register bit: 7 6 5 4 3 2 1 0 - - - - pwmp.11 pwmp.10 pwmp.9 pwmp.8 mnemonic: pwmph address: d1h bit name function 7-4 - reserved. 3-0 pwmp.11~pwmp.8 pwm counter register bits 11~8. pwm 0 high bits register bit: 7 6 5 4 3 2 1 0 - - - - pwm0.11 pwm0.10 pwm0.9 pwm0.8 mnemonic: pwm0h address: d2h bit name function 7~4 - reserved. 3~0 pwm0.11 ~pwm0.8 the pwm 0 register bit 11~8. nvm data bit: 7 6 5 4 3 2 1 0 nvmdat.7 nvmdat.6 nvmdat.5 nvmdat.4 nvmdat.3 nvmdat.2 nvmdat.1 nvmdat.0 mnemonic: nvmdat address: d3h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 57 - revision a4.0 bit name function 7~0 nvmdat.7~nvmdat.0 the nvm data write register. the read nvm data is by movx instruction. qei control register bit: 7 6 5 4 3 2 1 0 - - - disidx dir qeim1 qeim0 qeien mnemonic: qeicon address: d4h bit name function 7-5 - reserved. 4 disidx disable input capture 2 edge detection function: 0 = enable ic2 edge detection function (default). 1 = disable ic2 edge detection function. this bit is effective when qeien=1. 3 dir direction index of motion detection bit: 1 = forward (up-counting). 0 = backward (down-counting). this bit is writable and readable. 2-1 qeim[1:0] qei mode select bits: qeim1 qeim0 descriptions 0 0 x4 free-counting mode 0 1 x2 free-counting mode 1 0 x4 compare-counting mode 1 1 x2 compare-counting mode 0 qeien input module mode select bit: 0 = input module performs input c apture functions. (default value). 1 = input module works as qei. pwm 2 high bits register bit: 7 6 5 4 3 2 1 0 - - - - pwm2.11 pwm2.10 pwm2.9 pwm2.8 mnemonic: pwm2h address: d5h bit name function 7~4 - reserved 3~0 pwm2.11 ~pwm2.8 pwm 2 register bit 11~8. pwm 6 high bits register bit: 7 6 5 4 3 2 1 0 - - - - pwm6.11 pwm6.10 pwm6.9 pwm6.8 mnemonic: pwm6h address: d6h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 58 - revision a4.0 bit name function 7~4 - reserved 3~0 pwm6.11 ~pwm6.8 pwm 6 register bit 11~8. watchdog control 2 bit: 7 6 5 4 3 2 1 0 - - - - - - - strld mnemonic: wdcon2 address: d7h bit name function 7-6 - reserved. 0 strld set this bit, cpu will restart from ld flash eprom after watchdog reset. clear this bit, cpu will restart from ap fl ash eprom after watchdog reset. this register is protected by timer access (ta) register. watchdog control bit: 7 6 5 4 3 2 1 0 - por - - wdif wtrf ewt rwt mnemonic: wdcon address: d8h bit name function 7 - reserved. 6 por power-on reset flag. hardware will set this flag on a power up condition. this flag can be read or written by software. a write by software is the only way to clear this bit once it is set. 5-4 - reserved. 3 wdif watchdog timer interrupt flag. this bit is set by hardware to indicate that the time-out period has elapsed and invoke watch dog timer interrupt if enabled (ewdi=1). this bit must be clear by software. 2 wtrf watchdog timer reset flag. hardware will set this bit when the watchdog timer causes a reset if ewt= 1. software can read it but must clear it manually. a power-on reset will also clear the bit. this bit helps software in determining the cause of a reset 1 ewt enable watchdog timer reset. setting this bit will enable the watchdog timer reset function after 512 clocks delay from time out and setting wtrf flag. 0 rwt reset watchdog timer. this bit restarts the watchdog timer and helps in putting the watchdog timer into a know state. it also helps in resetting the watchdog timer before a time-out occurs. if ewdi (eie.4) is set, an interrupt will occur when time-out. if ewt is set, 512 clocks after the time-out, a system reset will occur and cpu starts from 0000h. this bit is self-clearing. the wdcon sfr is set to a 0x0x0xx0b on an ex ternal reset. wtrf is set to a 1 on a watchdog timer reset, but to a 0 on power on resets. wtrf is not altered by an external reset. por is set to 1 by a power-on reset. ewt is cleared to 0 on a power-on reset and unaffected by other resets.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 59 - revision a4.0 the wdcon sfr is set to x0xx 0000b on an external reset. wtrf is set to a 1 on a watchdog timer reset, but to a 0 on power on resets. por is set to 1 by a power-on reset. ewt is cleared to 0 on a power-on reset, reset pin reset, watch dog timer reset and isp reset. all the bits in this sfr have unrestricted read ac cess. the bits of por, wdif, ewt and rwt require timed access (ta) procedure to write. the remain ing bits have unrestricted write accesses. please refer ta register description. pwmp counter low bits register bit: 7 6 5 4 3 2 1 0 pwmp.7 pwmp.6 pwmp.5 pwmp .4 pwmp.3 pwmp.2 pwmp.1 pwmp.0 mnemonic: pwmpl address: d9h bit name function 7~0 pwmp.7 ~pwmp.0 pwm counter low bits register. pwm0 low bits register bit: 7 6 5 4 3 2 1 0 pwm0.7 pwm0.6 pwm0.5 pwm0 .4 pwm0.3 pwm0.2 pwm0.1 pwm0.0 mnemonic: pwm0l address: dah bit name function 7~0 pwm0.7 ~pwm0.0 pwm 0 low bits register. nvm low byte address bit: 7 6 5 4 3 2 1 0 nvmaddr l.7 nvmaddr l.6 nvmaddr l.5 nvmaddr l.4 nvmaddr l.3 nvmaddr l.2 nvmaddr l.1 nvmaddr l.0 mnemonic: nvmaddrl address: dbh bit name function 7~0 nvmaddrl.7~ nvmaddrl.0 nvm low byte address. pwm control register 1 bit: 7 6 5 4 3 2 1 0 pwmrun load pwmf clrpwm pwm6i pwm4i pwm2i pwm0i mnemonic: pwmcon1 address: dch
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 60 - revision a4.0 bit name function 7 pwmrun 0 = the pwm is not running. 1 = the pwm counter is running. 6 load this bit is auto cleared by hardware a fter the pwmp and pwmn are transferred to counter and compare register: 0 = the registers value of pwmp and pwmn is never loaded to counter and compare registers. 1 = the pwmp and pwmn registers load value to counter and compare registers at the counter underflow/match. 5 pwmf 12 bit counter overflow flag: 0 = the 12-bit counter is not underflow/match. 1 = the 12-bit counter is underflow/match. it will be set by hardware and cleared by software. 4 clrpwm 1 = clear 12-bit pwm counter to 000h. it will be automatically clear by hardware. 3-0 pwmxi 0 = pwm0 output is non-inverted. 1 = pwm0 output is inverted. note: x = 0,2,4,6. pwm 2 low bits register bit: 7 6 5 4 3 2 1 0 pwm2.7 pwm2.6 pwm2.5 pwm2 .4 pwm2.3 pwm2.2 pwm2.1 pwm2.0 mnemonic: pwm2l address: ddh bit name function 7~0 pwm2.7 ~pwm2.0 pwm 2 low bits register. pwm 6 low bits register bit: 7 6 5 4 3 2 1 0 pwm6.7 pwm6.6 pwm6.5 pwm6 .4 pwm6.3 pwm6.2 pwm6.1 pwm6.0 mnemonic: pwm6l address: deh bit name function 7~0 pwm6.7 ~pwm6.0 pwm 6 low bits register. pwm control register 3 bit: 7 6 5 4 3 2 1 0 pwm7b pwm6b pwm5b pwm4b pwm3b pwm2b pwm1b pwm0b mnemonic: pwmcon3 address: dfh
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 61 - revision a4.0 bit name function 7-0 pwmxb 0 = the pwm0 output is low, when brake is asserted. 1 = the pwm0 output is high, when brake is asserted. note: x = 0~7 accumulator bit: 7 6 5 4 3 2 1 0 acc.7 acc.6 acc.5 acc.4 acc.3 acc.2 acc.1 acc.0 mnemonic: acc address: e0h bit name function 7-0 acc the a or acc register is the standard 8032 accumulator adc control register bit: 7 6 5 4 3 2 1 0 adcen - adcex adci adcs aadr.2 aadr.1 aadr.0 mnemonic: adccon address: e1h bit name function 7 adcen enable a/d converter function. set a dcen to logic high to enable adc block. 6 - reserved. 5 adcex enable external start control of adc conversion by a rising edge from p4.0. adcex=0: disable external start. adce x=1: enable external start control. 4 adci a/d converting complete/interrupt flag. th is flag is set when adc conversion is completed. the adc interrupt is requested if the interrupt is enabled. adci is set by hardware and cleared by software only. 3 adcs adc start and status: set this bit to star t an a/d conversion. it may also be set by stadc if adcex is 1. this signal remains high while the adc is busy and is reset right after adci is set. notes: 1. it is recommended to clear adci before adcs is set. however, if adci is cleared and adcs is set at the same time, a new a/d conversion may start on the same channel. 2. software clearing of adcs will abort conversion in progress. 3. adc cannot start a new conversion while adcs or adci is high. 2-0 aadr select and enable analog input channel from adc0 to adc7. aadr[2:0] adc selected input aadr[2:0] adc selected input 000 adcch0 (p1.0) 100 adcch4 (p1.4) 001 adcch1 (p1.1) 101 adcch5 (p1.5) 010 adcch2 (p1.2) 110 adcch6 (p1.6) 011 adcch3 (p1.3) 111 adcch7 (p1.7)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 62 - revision a4.0 the adci and adcs control the adc conversion as below: adci adcs adc status 0 0 adc not busy; a conversion can be started. 0 1 adc busy; start of a new conversion is blocked. 1 0 conversion completed; start of a new conversion requires adci = 0. 1 1 this is an internal temporary state that user can ignore it. adc converter result high register bit: 7 6 5 4 3 2 1 0 adc.9 adc.8 adc.7 adc.6 adc.5 adc.4 adc.3 adc.2 mnemonic: adch address: e2h bit name function 7-0 adc[9:2] 8 msb of 10 bit a/d conversion result. adch is a read only register. adc converter result low register bit: 7 6 5 4 3 2 1 0 adclk.1 adclk.0 - - - - adc.1 adc.0 mnemonic: adcl address: e3h bit name function 7-6 adclk adc clock frequency select. the 10 bit adc needs a clock to drive the converting that the clock frequency may not over 4mhz. adclk[1:0] controls the frequency of the clock to adc block: adclk.1 adclk.0 adc clock frequency 0 0 crystal clock / 4 (default) 0 1 crystal clock / 8 1 0 crystal clock / 16 1 1 reserved 1-0 adc 2 lsb of 10-bit a/d conversion result. both bits are read only. pwm dead-time control register 1 bit: 7 6 5 4 3 2 1 0 pdtc1.7 pdtc1.6 pdtc1.5 pdtc1.4 pdtc1.3 pdtc1.2 pdtc1.1 pdtc1.0 mnemonic: pdtc1 address: e5h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 63 - revision a4.0 bit name function 7-6 pdtc1 dead-time clock frequency (fdt) prescaler select bits. pdtc1.7 pdtc1.6 fdt 0 0 f osc/2 0 1 f osc /4 1 0 f osc /8 1 1 f osc /16 5-0 pdtc1 dead time counter. unsigned 6 bit dead time value bits for dead time unit. dead-time = fdt * (pdtc1 [5:0]+1) pwm dead-time control register 0 bit: 7 6 5 4 3 2 1 0 pdtc0.7 pdtc0.6 pdtc0.5 pdtc0.4 pdtc0.3 pdtc0.2 pdtc0.1 pdtc0.0 mnemonic: pdtc0 address: e6h bit name function 7-4 pdtc0 control complementary pwm to delay a dead-time at every rising edge or falling edge. reset value = 0. 1 = dead-time is inserted at falling edge. 0 = dead-time is inserted at rising edge. pdtc0.4 - controls the pair of (pwm0, pwm1). pdtc0.5 - controls the pair of (pwm2, pwm3). pdtc0.6 - controls the pair of (pwm4, pwm5). pdtc0.7 - controls the pair of (pwm6, pwm7). 3-0 pdtc0 enable dead-time insertion; dead-time inse rtion is only active when the pair of complementary pwm is enabled. reset value=0. if dead-time insertion is inactive, the outputs of pin pair ar e complementary without any delay. 1 = programmable dead-time is inserted in to the pair signals of comparator output to delay the pair signals change from low to high. 0 = disable dead-time insertion. pdtc0.0 - enables the dead-time inse rtion on the pin pair (pwm0, pwm1). pdtc0.1 - enables the dead-time inse rtion on the pin pair (pwm2, pwm3). pdtc0.2 - enables the dead-time inse rtion on the pin pair (pwm4, pwm5). pdtc0.3 - enables the dead-time inse rtion on the pin pair (pwm6, pwm7). pwm control register 4 bit: 7 6 5 4 3 2 1 0 pwmeom pwmoom pwm6om pwm7om - - - bkf mnemonic: pwmcon4 address: e7h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 64 - revision a4.0 bit name function 7 pwmeom pwm channel 0, 2 and 4 output mode. 0 = disable pwm channels 0, 2 and 4 to pwm output pins. 1 = enable pwm channels 0, 2 and 4 to pwm output pins. 6 pwmoom pwm channel 1, 3 and 5 output mode. 0 = disable pwm channels 1, 3 and 5 to pwm output pins. 1 = enable pwm channels 1, 3 and 5 to pwm output pins. 5 pwm6om pwm channel 6 output mode. 0 = disable pwm channel 6 to pwm output pin. 1 = enable pwm channel 6 to pwm output pin. 4 pwm7om pwm channel 7 output mode. 0 = disable pwm channel 7 to pwm output pin. 1 = enable pwm channel 7 to pwm output pin. 3-1 - reserved. 0 bkf the external brake pin flag. 0 = the pwm is not brake. 1 = the pwm is brake by external brak e pin. it will be cleared by software. together with option bits (pwmee and pwmo e), pwmeom, pwmoom, pwm6om and pwm7om control the pwm pin structure, as follow; pwmee/pwmoe (option bits)  pwmeom/pwmoom /pwm6om/pwm7om pio.x  (x = 0-7) pin structures x 0 x tri-state 1 (d isable
 1 x quasi (i/o output) 0 (enable)  1 0 push pull (pwm output) 0 (enable)  1 1 push pull (i/o output) table 7-2: pwm pin structures (d uring internal rom execution) pwmee/pwmoe (option bits)  pwmeom/pwmoom /pwm6om/pwm7om pio.x  (x = 0-7) pin output pin structures 1 (disable) x x external access push pull  &obcmf
 x x external access push pull (strong) table 7-3: pwm pin structures (d uring external rom execution) note: pwmeom/pwmoom/pwm6om/pwm7om are cleared to zero when cpu in reset state. thus, the port pins that multi-function with pwm will be tristated on default. user is required to set the bits to 1 to enable gpio/pwm outputs.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 65 - revision a4.0 extended interrupt enable bit: 7 6 5 4 3 2 1 0 es1 ex5 ex4 ewdi ex3 ex2 - ei2c mnemonic: eie address: e8h bit name function 7 es1 enable serial port 1 interrupts. 6 ex5 enable external interrupt 5. 5 ex4 enable external interrupt 4. 4 ewdi enable watchdog timer interrupt. 3 ex3 enable external interrupt 3. 2 ex2 enable external interrupt 2. 1 - reserved. 0 ei2c enable i2c interrupt. i2c control register bit: 7 6 5 4 3 2 1 0 - ens sta sto si aa i2cin - mnemonic: i2con address: e9h bit name function 7 - reserved. 6 ens i2c serial function block enable bit. when ens=1 the i2c serial function enables. the port latches of sda and scl must be set to logic high. 5 sta i2c start flag. setting sta to logic 1 to enter master mode, the i2c hardware sends a start or repeat start condition to bus when the bus is free. 4 sto i2c stop flag. in master mode, setting sto to transmit a stop condition to bus then i2c hardware will check the bus condition if a stop condition is detected this flag will be cleared by ha rdware automatically. in a slave mode, setting sto resets i2c hardware to the defined ?not addressed? slave mode. 3 si i2c interrupt flag. when a new sio state is present in the s1sta register, the si flag is set by hardware, and if the ea and ei2c bits are both set, the i2c interrupt is requested. si mu st be cleared by software. 2 aa assert acknowledge flag. when aa=1 an acknowledged (low level to sda) will be returned during the acknowledge clock pulse on the scl line. when aa=0 an acknowledged (high level to sda) will be returned during the acknowledge clock pulse on the scl line. 1 i2cin by default it is zero and input are allows to come in through sda pin. as when it is 1 input is disallow and to prevent leakage current. during power-down mode input is disallow. 0 - reserved.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 66 - revision a4.0 i2c address register bit: 7 6 5 4 3 2 1 0 i2addr.7 i2addr.6 i2addr.5 i2addr.4 i2addr.3 i2addr.2 i2addr.1 gc mnemonic: i2addr address: eah bit name function 7-1 i2addr i2c slave address. the contents of the r egister are irrelevant when i2c is in master mode. in the slave mode, the sev en most significant bits must be loaded with the mcu?s own slave add ress. the i2c hardware will re act if the contents of i2addr are matched with the received slave address. 0 gc enable general call function. the gc bit is set the i2c port hardware will respond to general call address (00h). clear gc bit to disable general call function. nvm high byte address bit: 7 6 5 4 3 2 1 0 - - - - - nvmaddr h.10 nvmaddr h.9 nvmaddr h.8 mnemonic: nvmaddrh address: eb h bit name function 7-3 - reserved. 2-0 nvmaddrh.10 ~ nvmaddrh.8 nvm high byte address i2c data register bit: 7 6 5 4 3 2 1 0 i2dat.7 i2dat.6 i2dat.5 i2dat.4 i2dat.3 i2dat.2 i2dat.1 i2dat.0 mnemonic: i2dat address: ech i2dat.7-0 the data register of i2c channel. i2c status register bit: 7 6 5 4 3 2 1 0 b7 b6 b5 b4 b3 0 0 0 mnemonic: i2status address: edh bit name function 7-0 i2status the status register of i2c. the three leas t significant bits are always 0. the five most significant bits contain the stat us code. there are 23 possible status codes. when i2status contains f8h, no se rial interrupt is requested. all other i2status values correspond to defined i2 c states. when each of these states is entered, the i2c1 interrupt is requested (si = 1). a valid status code is present in i2status one machine cycle after si is set by hardware and is still present one machine cycle after si has been reset by software. in addition, states 00h stands for a bus error. a bus error occu rs when a start or stop condition is present at an illegal position in the form ation frame. example of illegal position are during the serial transfer of an address byte, a data byte or an acknowledge bit.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 67 - revision a4.0 i2c baud rate control register bit: 7 6 5 4 3 2 1 0 i2clk.7 i2clk.6 i2clk.5 i2clk.4 i2clk.3 i2clk.2 i2clk.1 i2clk.0 mnemonic: i2clk address: eeh bit name function 7-0 i2clk i2c clock rate control. i2c timer counter register bit: 7 6 5 4 3 2 1 0 - - - - - enti div4 tif mnemonic: i2timer address: efh bit name function 7-3 - reserved. 2 enti enable i2c 14-bits time-out counter. setting enti to logic high will firstly reset the time-out counter and then start up co unting. clearing enti disables the 14- bit time-out counter. enti can be set to logic high only when si=0. 1 div4 i2c time-out counter clock frequency selection. 0 = the clock frequency is coherent to the system clock fosc. 1 = the clock frequency is fosc/4. 0 tif i2c time-out flag. when the time-out counter overflow s hardware will set this flag and request the i2c interrupt if i2c interrupt is enabled (ei2c=1). this bit must be cleared by software. b register bit: 7 6 5 4 3 2 1 0 b.7 b.6 b.5 b.4 b.3 b.2 b.1 b.0 mnemonic: b address: f0h bit name function 7-0 b the b register is the standard 8032 accumulator. serial peripheral control register bit: 7 6 5 4 3 2 1 0 ssoe spe lsbfe mstr cpol cpha spr1 spr0 mnemonic: spcr address: f3h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 68 - revision a4.0 bit name function 7 ssoe slave select output enable bit. the ss output feature is enabled only in master mode by asserting the ssoe bit. in slav e mode (/ss) input is not affected by ssoe bit. see table below. 6 spe serial peripheral system enable bit. when the spe bit is set, spi block functi ons is enable. when modf is set, spe always reads 0. 0 = spi system disabled. 1 = spi system enabled. 5 lsbfe lsb - first enable. this bit does not affect the position of the msb and lsb in the data register. reads and writes of t he data register always have the msb in bit 7. in master mode, a change of this bit will abort a transmission in progress and force the spi system into idle state. 1 = data is transferred least significant bit first. 0 = data is transferred most significant bit first. 4 mstr master mode select bit. it is customar y to have an external pull-up resistor on lines that are driven by open drain devices. 0 = slave mode. 1 = master mode. 3 cpol clock polarity bit. when the clock polar ity bit is cleared and data is not being transferred, the spclk pin of the master device has a steady state low value. when cpol is set, spclk idles high. 2 cpha cpha clock phase bit. the clock phase bit, in conjunction with the cpol bit, controls the clock-data relationship bet ween master and slave. the cpha bit selects one of two different clocking protocols. 1-0 spr spi baud rate selection bits. these bits specify the spi baud rates. drss ssoe master mode slave mode 0 0 /ss input ( with mode fault ) /ss input ( not affected by ssoe ) 0 1 reserved /ss input ( not affected by ssoe ) 1 0 /ss general purpose i/o ( no mode fault ) /ss input ( not affected by ssoe ) 1 1 /ss output ( no mode fault ) /ss input ( not affected by ssoe ) note: in master mode, a change of lsbfe, mstr, cpol, cpha and spr [1:0] will abort a transmission in progress and force the spi system into idle state. serial peripheral status register bit: 7 6 5 4 3 2 1 0 spif wcol spiovf modf drss - - - mnemonic: spsr address: f4h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 69 - revision a4.0 bit name function 7 spif spi interrupt complete flag. spif is set upon completion of data transfer between this device and external device or when new data has been received and copied to the spdr. if spif goes high, and if espi is set, a serial peripheral interrupt is generated. when spif is se t; it must be clear by software and attempts to write spdr are inhibited if spif set. 6 wcol write collision flag. if a writer collision oc curs on spi bus, wcol is set to high by hardware. wcol must be clear by software. 5 spiovf spi overrun flag. spiovf is set if a new character is received before a previously received character is read from spdr. once this bit is set it will prevent spdr register form excepting new data and must be cleared first before any new data can be written. this flag is clear by software. 0 = no overrun. 1 = overrun detected. 4 modf spi mode error interrupt status flag. modf is set when hardware detects mode fault. this bit is cleared by software. 3 drss data register slave select. re fer to above table in spcr register. 2-0 - reserved. note: bits wcol, modf and spif are cleared by software writing ?0? to them. serial peripheral data i/o register bit: 7 6 5 4 3 2 1 0 spd.7 spd.6 spd.5 spd.4 spd.3 spd.2 spd.1 spd.0 mnemonic: spdr address: f5h bit name function 7-0 spd spdr is used when transmitting or receivi ng data on serial bus. only a write to this register initiates transmission or re ception of a byte, and this only occurs in the master device. a read of the spdr is actually a read of a buffer. to prevent an overrun and the loss of the byte that caused the overrun, the first spif must be cleared by the time a second transfer of data from the shift register to the read buffer is initiated. i2c slave address mask enable bit: 7 6 5 4 3 2 1 0 i2csade n.7 i2csade n.6 i2csade n.5 i2csade n.4 i2csade n.3 i2csade n.2 i2csade n.1 i2csade n.0 mnemonic: i2csaden address: f6h bit name function 7-0 i2csaden this register enables the automatic a ddress recognition feature of the i2c. when a bit in the i2csaden is set to 1, the same bit location in i2csaddr1 will be compared with the incoming serial port data. when i2csaden.n is 0, the bit becomes don't care in the co mparison. this register enables the automatic address recognition feature of the i2c. when all the bits of i2csaden are 0, interr upt will occur for any in coming address. the default value is 0xfe.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 70 - revision a4.0 extended interrupt high priority bit: 7 6 5 4 3 2 1 0 ps1h px5h px4h pwdih px3h px2h - pi2ch mnemonic: eiph address: f7h bit name function 7 ps1h serial port 1 interrupt high priority. ps1h = 1 sets it to highest priority level. 6 px5h external interrupt 5 high priority. px5h = 1 sets it to highest priority level. 5 px4h external interrupt 4 high priority. px4h = 1 sets it to highest priority level. 4 pwdih watchdog timer interrupt high priority. pw dih = 1 sets it to highest priority level. 3 px3h external interrupt 3 high priority. px3h = 1 sets it to highest priority level. 2 px2h external interrupt 2 high priority. px2h = 1 sets it to highest priority level. 1 - reserved. 0 pi2ch i2c interrupt high priority. pi2ch = 1 sets it to highest priority level. extended interrupt priority bit: 7 6 5 4 3 2 1 0 ps1 px5 px4 pwdi px3 px2 - pi2c mnemonic: eip address: f8h bit name function 7 ps1 serial port 1 interrupt priority. 6 px5 external interrupt 5 priority. 5 px4 external interrupt 4 priority. 4 pwdi watchdog timer interrupt priority. 3 px3 external interrupt 3 priority. 2 px2 external interrupt 2 priority. 1 - reserved. 0 pi2c i2c interrupt priority. extended interrupt enable 1 bit: 7 6 5 4 3 2 1 0 - - envm ecptf et3 ebk epwm espi mnemonic: eie1 address: f9h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 71 - revision a4.0 bit name function 7-6 - reserved. 5 envm nvm interrupt enable bit. 0 = disable nvm interrupt. 1 = enable nvm interrupt. 4 ecptf capture interrupt enable bit. 0 = disable external capture/reload interrupt. 1 = enable external capture/reload interrupt. 3 et3 timer 3 interrupt enable bit. 0 = disable timer 3 interrupt. 1 = enable timer 3 interrupt. 2 ebk brake interrupt enable bit. 0 = brake interrupt disable. 1 = brake interrupt enable. 1 epwm pwm period interrupt enable bit. 0 = pwm period system interrupts disabled. 1 = pwm period system interrupts enabled. 0 espi serial peripheral interru pt enable bit. set the espi bit to 1 to request a hardware interrupt sequence each time the spif/modf status flag is set. 0 = spi system interrupts disabled. 1 = spi system interrupts enabled. extended interrupt priority 1 bit: 7 6 5 4 3 2 1 0 - - pnvmi pcptf pt3 pbkf ppwmf pspi mnemonic: eip1 address: fah bit name function 7-6 - reserved. 5 pnvmi nvm interrupt priority 4 pcptf capture/reload interrupt priority. 3 pt3 timer 3 interrupt priority. 2 pbkf pwm brake interrupt priority. 1 ppwmf pwm period interrupt priority. 0 pspi spi interrupt priority. input capture 0/pulse read counter low register bit: 7 6 5 4 3 2 1 0 ccl0.7/ pcntl.7 ccl0.6/ pcntl.6 ccl0.5/ pcntl.5 ccl0.4/ pcntl.4 ccl0.3/ pcntl.3 ccl0.2/ pcntl.2 ccl0.1/ pcntl.1 ccl0.0/ pcntl.0 mnemonic: ccl0/pcntl address: fbh
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 72 - revision a4.0 pcntl must be read first before reading at p cnth as reading pcntl will latch the plscnth automatically into pcnth; otherwise inaccurate result is read when reading pcnth first as it will not latch the plscntl data into pcntl. input capture 0/pulse read counter high register bit: 7 6 5 4 3 2 1 0 cch0.7/ pcnth.7 cch0.6/ pcnth.6 cch0.5/ pcnth.5 cch0.4/ pcnth.4 cch0.3/ pcnth.3 cch0.2/ pcnth.2 cch0.1/ pcnth.1 cch0.0/ pcnth.0 mnemonic: cch0/pcnth address: fch pcntl must be read first before reading at p cnth as reading pcntl will latch the plscnth automatically into pcnth. input capture 1/pulse counter low register bit: 7 6 5 4 3 2 1 0 ccl1.7/ plscnt l.7 ccl1.6/ plscnt l.6 ccl1.5/ plscnt l.5 ccl1.4/ plscnt l.4 ccl1.3/ plscnt l.3 ccl1.2/ plscnt l.2 ccl1.1/ plscnt l.1 ccl1.0/ plscnt l.0 mnemonic: ccl1/plscntl address: fdh input capture 1/pulse co unter high register bit: 7 6 5 4 3 2 1 0 cch1.7/ plscnt h.7 cch1.6/ plscnt h.6 cch1.5/ plscnt h.5 cch1.4/ plscnt h.4 cch1.3/ plscnt h.3 cch1.2/ plscnt h.2 cch1.1/ plscnt h.1 cch1.0/ plscnt h.0 mnemonic: cch1/plscnth address: feh interrupt control bit: 7 6 5 4 3 2 1 0 - - int5ct1 int5ct0 int4ct1 int4ct0 int3ct1 int3ct0 mnemonic: intctrl address: ffh
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 73 - revision a4.0 bit name function 7-6 - reserved. 5-4 int5ct interrupt 5 edge select: int5ct1 int5ct0 description 0 0 rising edge trigger. 0 1 falling edge trigger. 1 0 rising and falling edge trigger. 1 1 reserved. 3-2 int4ct interrupt 4 edge select: int4ct1 int4ct0 description 0 0 rising edge trigger. 0 1 falling edge trigger. 1 0 rising and falling edge trigger. 1 1 reserved. 1-0 int3ct interrupt 3 edge select: int3ct1 int3ct0 description 0 0 rising edge trigger. 0 1 falling edge trigger. 1 0 rising and falling edge trigger. 1 1 reserved.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 74 - revision a4.0 8. instruction set the w79e22x series executes all the instructions of the standard 8051/52 family. the operations of these instructions, as well as their effects on flag and status bits, are exactly the same. however, the timing of these instructions is different in two ways. firstly, the w79e22x series machine cycle is four clock periods, while the standard-8051/52 mach ine cycle is twelve clock periods. secondly, the w79e22x series can fetch only once per machine cycle (i.e., four clocks per fetch), while the standard 8051/52 can fetch twice per machine cycle (i.e., six clocks per fetch). the timing differences create an advantage for the w79e22x series. there is only one fetch per machine cycle, so the number of machine cycles is usually equal to the number of operands in the instruction. (jumps and calls do require an additional cycle to calculate the new address.) as a result, the w79e22x series reduces the number of dummy fetches and wasted cycles, and therefore improves overall efficiency, compared to the standard 8051/52. op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio nop 00 1 1 4 12 3 add a, r0 28 1 1 4 12 3 add a, r1 29 1 1 4 12 3 add a, r2 2a 1 1 4 12 3 add a, r3 2b 1 1 4 12 3 add a, r4 2c 1 1 4 12 3 add a, r5 2d 1 1 4 12 3 add a, r6 2e 1 1 4 12 3 add a, r7 2f 1 1 4 12 3 add a, @r0 26 1 1 4 12 3 add a, @r1 27 1 1 4 12 3 add a, direct 25 2 2 8 12 1.5 add a, #data 24 2 2 8 12 1.5 addc a, r0 38 1 1 4 12 3 addc a, r1 39 1 1 4 12 3 addc a, r2 3a 1 1 4 12 3 addc a, r3 3b 1 1 4 12 3 addc a, r4 3c 1 1 4 12 3 addc a, r5 3d 1 1 4 12 3 addc a, r6 3e 1 1 4 12 3 addc a, r7 3f 1 1 4 12 3 addc a, @r0 36 1 1 4 12 3 addc a, @r1 37 1 1 4 12 3 addc a, direct 35 2 2 8 12 1.5
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 75 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio addc a, #data 34 2 2 8 12 1.5 subb a, r0 98 1 1 4 12 3 subb a, r1 99 1 1 4 12 3 subb a, r2 9a 1 1 4 12 3 subb a, r3 9b 1 1 4 12 3 subb a, r4 9c 1 1 4 12 3 subb a, r5 9d 1 1 4 12 3 subb a, r6 9e 1 1 4 12 3 subb a, r7 9f 1 1 4 12 3 subb a, @r0 96 1 1 4 12 3 subb a, @r1 97 1 1 4 12 3 subb a, direct 95 2 2 8 12 1.5 subb a, #data 94 2 2 8 12 1.5 inc a 04 1 1 4 12 3 inc r0 08 1 1 4 12 3 inc r1 09 1 1 4 12 3 inc r2 0a 1 1 4 12 3 inc r3 0b 1 1 4 12 3 inc r4 0c 1 1 4 12 3 inc r5 0d 1 1 4 12 3 inc r6 0e 1 1 4 12 3 inc r7 0f 1 1 4 12 3 inc @r0 06 1 1 4 12 3 inc @r1 07 1 1 4 12 3 inc direct 05 2 2 8 12 1.5 inc dptr a3 1 2 8 24 3 dec a 14 1 1 4 12 3 dec r0 18 1 1 4 12 3 dec r1 19 1 1 4 12 3 dec r2 1a 1 1 4 12 3 dec r3 1b 1 1 4 12 3 dec r4 1c 1 1 4 12 3
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 76 - revision a4.0 dec r5 1d 1 1 4 12 3
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 77 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio dec r6 1e 1 1 4 12 3 dec r7 1f 1 1 4 12 3 dec @r0 16 1 1 4 12 3 dec @r1 17 1 1 4 12 3 dec direct 15 2 2 8 12 1.5 mul ab a4 1 5 20 48 2.4 div ab 84 1 5 20 48 2.4 da a d4 1 1 4 12 3 anl a, r0 58 1 1 4 12 3 anl a, r1 59 1 1 4 12 3 anl a, r2 5a 1 1 4 12 3 anl a, r3 5b 1 1 4 12 3 anl a, r4 5c 1 1 4 12 3 anl a, r5 5d 1 1 4 12 3 anl a, r6 5e 1 1 4 12 3 anl a, r7 5f 1 1 4 12 3 anl a, @r0 56 1 1 4 12 3 anl a, @r1 57 1 1 4 12 3 anl a, direct 55 2 2 8 12 1.5 anl a, #data 54 2 2 8 12 1.5 anl direct, a 52 2 2 8 12 1.5 anl direct, #data 53 3 3 12 24 2 orl a, r0 48 1 1 4 12 3 orl a, r1 49 1 1 4 12 3 orl a, r2 4a 1 1 4 12 3 orl a, r3 4b 1 1 4 12 3 orl a, r4 4c 1 1 4 12 3 orl a, r5 4d 1 1 4 12 3 orl a, r6 4e 1 1 4 12 3 orl a, r7 4f 1 1 4 12 3 orl a, @r0 46 1 1 4 12 3 orl a, @r1 47 1 1 4 12 3 orl a, direct 45 2 2 8 12 1.5 orl a, #data 44 2 2 8 12 1.5
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 78 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio orl direct, a 42 2 2 8 12 1.5 orl direct, #data 43 3 3 12 24 2 xrl a, r0 68 1 1 4 12 3 xrl a, r1 69 1 1 4 12 3 xrl a, r2 6a 1 1 4 12 3 xrl a, r3 6b 1 1 4 12 3 xrl a, r4 6c 1 1 4 12 3 xrl a, r5 6d 1 1 4 12 3 xrl a, r6 6e 1 1 4 12 3 xrl a, r7 6f 1 1 4 12 3 xrl a, @r0 66 1 1 4 12 3 xrl a, @r1 67 1 1 4 12 3 xrl a, direct 65 2 2 8 12 1.5 xrl a, #data 64 2 2 8 12 1.5 xrl direct, a 62 2 2 8 12 1.5 xrl direct, #data 63 3 3 12 24 2 clr a e4 1 1 4 12 3 cpl a f4 1 1 4 12 3 rl a 23 1 1 4 12 3 rlc a 33 1 1 4 12 3 rr a 03 1 1 4 12 3 rrc a 13 1 1 4 12 3 swap a c4 1 1 4 12 3 mov a, r0 e8 1 1 4 12 3 mov a, r1 e9 1 1 4 12 3 mov a, r2 ea 1 1 4 12 3 mov a, r3 eb 1 1 4 12 3 mov a, r4 ec 1 1 4 12 3 mov a, r5 ed 1 1 4 12 3 mov a, r6 ee 1 1 4 12 3 mov a, r7 ef 1 1 4 12 3 mov a, @r0 e6 1 1 4 12 3
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 79 - revision a4.0 mov a, @r1 e7 1 1 4 12 3
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 80 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio mov a, direct e5 2 2 8 12 1.5 mov a, #data 74 2 2 8 12 1.5 mov r0, a f8 1 1 4 12 3 mov r1, a f9 1 1 4 12 3 mov r2, a fa 1 1 4 12 3 mov r3, a fb 1 1 4 12 3 mov r4, a fc 1 1 4 12 3 mov r5, a fd 1 1 4 12 3 mov r6, a fe 1 1 4 12 3 mov r7, a ff 1 1 4 12 3 mov r0, direct a8 2 2 8 12 1.5 mov r1, direct a9 2 2 8 12 1.5 mov r2, direct aa 2 2 8 12 1.5 mov r3, direct ab 2 2 8 12 1.5 mov r4, direct ac 2 2 8 12 1.5 mov r5, direct ad 2 2 8 12 1.5 mov r6, direct ae 2 2 8 12 1.5 mov r7, direct af 2 2 8 12 1.5 mov r0, #data 78 2 2 8 12 1.5 mov r1, #data 79 2 2 8 12 1.5 mov r2, #data 7a 2 2 8 12 1.5 mov r3, #data 7b 2 2 8 12 1.5 mov r4, #data 7c 2 2 8 12 1.5 mov r5, #data 7d 2 2 8 12 1.5 mov r6, #data 7e 2 2 8 12 1.5 mov r7, #data 7f 2 2 8 12 1.5 mov @r0, a f6 1 1 4 12 3 mov @r1, a f7 1 1 4 12 3 mov @r0, direct a6 2 2 8 12 1.5 mov @r1, direct a7 2 2 8 12 1.5 mov @r0, #data 76 2 2 8 12 1.5 mov @r1, #data 77 2 2 8 12 1.5 mov direct, a f5 2 2 8 12 1.5 mov direct, r0 88 2 2 8 12 1.5
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 81 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio mov direct, r1 89 2 2 8 12 1.5 mov direct, r2 8a 2 2 8 12 1.5 mov direct, r3 8b 2 2 8 12 1.5 mov direct, r4 8c 2 2 8 12 1.5 mov direct, r5 8d 2 2 8 12 1.5 mov direct, r6 8e 2 2 8 12 1.5 mov direct, r7 8f 2 2 8 12 1.5 mov direct, @r0 86 2 2 8 12 1.5 mov direct, @r1 87 2 2 8 12 1.5 mov direct, direct 85 3 3 12 24 2 mov direct, #data 75 3 3 12 24 2 mov dptr, #data 16 90 3 3 12 24 2 movc a, @a+dptr 93 1 2 8 24 3 movc a, @a+pc 83 1 2 8 24 3 movx a, @r0 e2 1 2 - 9 8 - 36 24 3 - 0.66 movx a, @r1 e3 1 2 - 9 8 - 36 24 3 - 0.66 movx a, @dptr e0 1 2 - 9 8 - 36 24 3 - 0.66 movx @r0, a f2 1 2 - 9 8 - 36 24 3 - 0.66 movx @r1, a f3 1 2 - 9 8 - 36 24 3 - 0.66 movx @dptr, a f0 1 2 - 9 8 - 36 24 3 - 0.66 push direct c0 2 2 8 24 3 pop direct d0 2 2 8 24 3 xch a, r0 c8 1 1 4 12 3 xch a, r1 c9 1 1 4 12 3 xch a, r2 ca 1 1 4 12 3 xch a, r3 cb 1 1 4 12 3 xch a, r4 cc 1 1 4 12 3 xch a, r5 cd 1 1 4 12 3 xch a, r6 ce 1 1 4 12 3 xch a, r7 cf 1 1 4 12 3 xch a, @r0 c6 1 1 4 12 3
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 82 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio xch a, @r1 c7 1 1 4 12 3 xchd a, @r0 d6 1 1 4 12 3 xchd a, @r1 d7 1 1 4 12 3 xch a, direct c5 2 2 8 12 1.5 clr c c3 1 1 4 12 3 clr bit c2 2 2 8 12 1.5 setb c d3 1 1 4 12 3 setb bit d2 2 2 8 12 1.5 cpl c b3 1 1 4 12 3 cpl bit b2 2 2 8 12 1.5 anl c, bit 82 2 2 8 24 3 anl c, /bit b0 2 2 6 24 3 orl c, bit 72 2 2 8 24 3 orl c, /bit a0 2 2 6 24 3 mov c, bit a2 2 2 8 12 1.5 mov bit, c 92 2 2 8 24 3 acall addr11 71, 91, b1, 11, 31, 51, d1, f1 2 3 12 24 2 lcall addr16 12 3 4 16 24 1.5 ret 22 1 2 8 24 3 reti 32 1 2 8 24 3 ajmp addr11 01, 21, 41, 61, 81, a1, c1, e1 2 3 12 24 2 ljmp addr16 02 3 4 16 24 1.5 jmp @a+dptr 73 1 2 6 24 3 sjmp rel 80 2 3 12 24 2 jz rel 60 2 3 12 24 2 jnz rel 70 2 3 12 24 2 jc rel 40 2 3 12 24 2 jnc rel 50 2 3 12 24 2 jb bit, rel 20 3 4 16 24 1.5 jnb bit, rel 30 3 4 16 24 1.5
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 83 - revision a4.0 continued op-code hex code bytes w79e22x series machine cycle w79e22x series clock cycles 8032 clock cycles w79e22x series vs. 8032 speed ratio jbc bit, rel 10 3 4 16 24 1.5 cjne a, direct, rel b5 3 4 16 24 1.5 cjne a, #data, rel b4 3 4 16 24 1.5 cjne @r0, #data, rel b6 3 4 16 24 1.5 cjne @r1, #data, rel b7 3 4 16 24 1.5 cjne r0, #data, rel b8 3 4 16 24 1.5 cjne r1, #data, rel b9 3 4 16 24 1.5 cjne r2, #data, rel ba 3 4 16 24 1.5 cjne r3, #data, rel bb 3 4 16 24 1.5 cjne r4, #data, rel bc 3 4 16 24 1.5 cjne r5, #data, rel bd 3 4 16 24 1.5 cjne r6, #data, rel be 3 4 16 24 1.5 cjne r7, #data, rel bf 3 4 16 24 1.5 djnz r0, rel d8 2 3 12 24 2 djnz r1, rel d9 2 3 12 24 2 djnz r5, rel dd 2 3 12 24 2 djnz r2, rel da 2 3 12 24 2 djnz r3, rel db 2 3 12 24 2 djnz r4, rel dc 2 3 12 24 2 djnz r6, rel de 2 3 12 24 2 djnz r7, rel df 2 3 12 24 2 djnz direct, rel d5 3 4 16 24 1.5 table 8-1: instruction set for w79e22x series
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 84 - revision a4.0 8.1 instruction timing this section is important because some applicatio ns use software instructions to generate timing delays. it also provides more information about timing differences between the w79e22x series and the standard 8051/52. in w79e22x series, each machine cycle is four cl ock periods long. each clock period is called a state, and each machine cycle consists of four st ates: c1, c2 c3 and c4, in order. both clock edges are used for internal timing, so the duty cycle of the clock should be as close to 50% as possible. the w79e22x series does one op-code fetch per ma chine cycle, so, in most instructions, the number of machine cycles required is equal to the nu mber of bytes in the instruction. there are 256 available op-codes. 128 of them are single-cycle in structions, so many op-c odes are executed in just four clock periods. some of the other op-codes are two-cycle instru ctions, and most of these have two-byte op-codes. however, there are some instruct ions that have one-byte instructions yet take two cycles to execute. one important example is the movx instruction. in the standard 8051/52, the movx instruction is al ways two machine cycles long. however, in the w79e22x series, the duration of this instruction is controlled by the software. it can vary from two to nine machine cycles long, and, rd and wr strobe lines are elongated proportionally. this is called stretching, and it gives a lot of flexibility when acce ssing fast and slow perip herals. it also reduces the amount of external circuitry and software overhead. the rest of the instructions are three-, four- or five -cycle instructions. at the end of this section, there are timing diagrams that provide an example of each type of instructi on (single-cycle, two-cycle, ?). in summary, there are five types of instructions in the w79e22x series, based on the number of machine cycles, and each machine cycle is four clock periods long. the standard 8051/52 has only three types of instructions, based on the number of machine cycles, but each machine cycle is twelve clock periods long. as a result, even though the number of categories is higher, each instruction in the w79e22x series runs 1.5 to 3 times faster, based on the number of clock periods, than it does in the standard 8051/52. single cycle c4 c3 c2 c1 clk ale psen ad7-0 port 2 a7-0 address a15-8 data_ in d7-0  figure 8-1: single cycle instruction timing
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 85 - revision a4.0 instruction fetch c4 c3 c2 c1 op-code address a15-8 address a15-8 ale psen pc ad7-0 port 2 clk operand fetch c4 c3 c2 c1 operand pc+1  figure 8-2: two cycles instruction timing operand operand a7-0 a7-0 a7-0 op-code address a15-8 address a15-8 address a15-8 operand fetch operand fetch instruction fetch c2 c3 c4 c2 c3 c4 c4 c3 c2 c1 c1 c1 clk ale psen ad7-0 port 2  figure 8-3: three cycles instruction timing
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 86 - revision a4.0 operand operand operand op-code address a15-8 address a15-8 address a15-8 address a15-8 a7-0 a7-0 a7-0 a7-0 operand fetch operand fetch operand fetch instruction fetch c2 c1 c4 c3 c2 c1 clk ale psen ad7-0 port 2 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3  figure 8-4: four cycles instruction timing operand operand operand op-code address a15-8 address a15-8 address a15-8 address a15-8 a7-0 a7-0 a7-0 a7-0 operand fetch operand fetch operand fetch operand fetch instruction fetch c2 c1 c4 c3 c2 c1 clk ale psen ad7-0 port 2 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3 operand a7-0 address a15-8 figure 8-5: five cycles instruction timing 8.1.1 external data memory access timing the timing for the movx instruction is another fe ature of the w79e22x series. in the standard 8051/52, the movx instruction has a fixed execution ti me of 2 machine cycles. however, in w79e22x series, the duration of the acce ss can be controlled by the user. the instruction starts off as a normal op-code fetch t hat takes four clocks. in the next machine cycle, w79e22x series puts out the external memory addres s, and the actual access occurs. the user can control the duration of this ac cess by setting the stretch value in ckcon, bits 2 ? 0. as shown in the table below, these three bits can range from zero to seven, resulting in movx instructions that take two to nine machine cycles. the default value is one, resulting in a movx instruction of three machine cycles.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 87 - revision a4.0 stretching only affects the movx instruction. there is no effect on any other instruction or its timing; it is as if the state of the cpu is held for the desired period. the timing waveforms when the stretch value is zero, one, and two are shown below. m2 m1 m0 machine cycles rd or wr strobe width in clocks rd or wr strobe width @ 25 mhz rd or wr strobe width @ 40 mhz 0 0 0 2 2 80 ns 50 ns 0 0 1 3 (default) 4 160 ns 100 ns 0 1 0 4 8 320 ns 200 ns 0 1 1 5 12 480 ns 300 ns 1 0 0 6 16 640 ns 400 ns 1 0 1 7 20 800 ns 500 ns 1 1 0 8 24 960 ns 600 ns 1 1 1 9 28 1120 ns 700 ns table 8-2: data memory cycle stretch values next instruction machine cycle second machine cycle first machine cycle last cycle of previous instruction c4 port 2 port 0 wr psen ale clk c3 c2 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a15-a8 a15-a8 a15-a8 a15-a8 a0-a7 c1 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3 c2 c1 movx instruction cycle next inst. read next inst. address movx data out movx data address movx inst. address movx inst . figure 8-6: data memory write with stretch value = 0
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 88 - revision a4.0 next instruction machine cycle third machine cycle second machine cycle first machine cycle last cycle of previous instruction c4 port 2 port 0 wr psen ale clk c3 c2 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a15-a8 a15-a8 a15-a8 a15-a8 a0-a7 c1 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3 c2 c1 movx instruction cycle next inst. read next inst. address movx data out movx data address movx inst. address movx inst. c4 c3 c2 c1 figure 8-7: data memory write with stretch value = 1 next instruction machine cycle fourth machine cycle third machine cycle second machine cycle first machine cycle last cycle of previous instruction c4 port 2 port 0 wr psen ale clk c3 c2 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a0-a7 d0-d7 a15-a8 a15-a8 a15-a8 a15-a8 a0-a7 c1 c4 c3 c2 c1 c4 c3 c2 c1 c4 c3 c2 c1 movx instruction cycle next inst. read next inst. address movx data out movx data address movx inst. address movx inst. c4 c3 c2 c1 c4 c3 c2 c1 figure 8-8: data memory write with stretch value = 2
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 89 - revision a4.0 9. power management the w79e22x series provides idle mode and po wer-down mode to control power consumption. these modes are discussed in the next two sections. 9.1 idle mode the user can put the device into idle mode by writing 1 to the bit pcon.0. the instruction that sets the idle bit is the last instruction that will be execut ed before the device goes into idle mode. in the idle mode, the clock to the cpu is halted, but not to t he interrupt, timer, watchdog timer, pwm, adc and serial ports blocks. this forces the cpu state to be frozen; the program counter, the stack pointer, the program status word, the accumulator and t he other registers hold th eir contents. the ale and psen pins are held high during the idle state. the port pins hold the logical states they had at the time idle was activated. the idle mode can be terminated in two ways. since the interrupt controller is still active, the activation of any enabled interrupt can wake up the processor. this will automatically clear the idle bit, terminate the idle mode, and the interru pt service routine (isr) will be executed. after the isr, execution of the program will continue from t he instruction which put the device into idle mode. the idle mode can also be exited by activating t he reset. the device can be put into reset either by applying a high on the external rst pin, a power on reset condition or a watchdog timer reset. the external reset pin has to be held high for at leas t two machine cycles i.e. 8 clock periods to be recognized as a valid reset. in the reset conditi on the program counter is reset to 0000h and all the sfrs are set to the reset condition. since the clo ck is already running there is no delay and execution starts immediately. in the idle mode, the watch dog timer continues to run, and if enabled, a time-out will cause a watchdog timer interrupt which will wa ke up the device. the software must reset the watchdog timer in order to preempt the reset which will occur after 512 clock periods of the time-out. when the device is exiting from an idle mode with a reset, the instruction following the one which put the device into idle mode is not executed. so there is no danger of unexpected writes. 9.2 power down mode the device can be put into power down mode by writing 1 to bit pcon.1. the instruction that does this will be the last instruction to be executed before the device goes into powe r down mode. in the power down mode, all the clocks are stopped and the dev ice comes to a halt. all activity is completely stopped and the power consumption is reduced to the lowest possible value. in this state the ale and psen pins are pulled low (if pwdnh=0). the port pins output the values held by their respective sfrs. the device will exit the power down mode with a reset or by an external interrupt pin enabled (external interrupts 0 and 1). an external reset can be used to exit the power down state. the high on rst pin terminates the power down mode, and restar ts the clock. the program execution will restart from 0000h. in the power down mode, the clock is stopped, so the watchdog timer cannot be used to provide the reset to exit power down mode. the device can be waken up from the power down mode by forcing an external interrupt pin activation, provided the corresponding interrupt is enabled, while the global enable (ea) bit is set. if these conditions are met, then either a low-level or a falling-edge at external interrupt pin will re-start the oscillator. the device will then execute the interr upt service routine for the corresponding external interrupt. after the interrupt serv ice routine is completed, the program execution returns to the instruction after one which put the device into power down mode and continues from there.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 90 - revision a4.0 mode program memory ale psen port0 port1 port2 port3 port4 port5 idle internal 1 1 data data data data data data idle external 1 1 float data address data data data power down internal 0 [1] 1 [2] 0 [1] 1 [2] data data data data data data power down external 0 [1] 1 [2] 0 [1] 1 [2] float data data data data data table 9-1: status of external pins during idle and power down note: 1. when pwdnh=0. 2. when pwdnh=1.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 91 - revision a4.0 10. reset conditions the user has several hardware related options for placing the w79e22x series into reset condition. in general, most register bits go to their reset value irrespective of the reset condition, but there are a few flags whose state depends on t he source of reset. the user can use these flags to determine the cause of reset using software. there are three ways of putting the device into reset state. they are external reset, power-on reset and watchdog reset. in general, most registers return to their default values regardless of the source of the reset, but a couple flags depend on the source. as a result, the user can use these flags to determine the cause of the reset. the rest of this section discusses the three caus es of reset and then elaborates on the reset state. 10.1 sources of reset 10.1.1 external reset the device samples the rst pin every machine cycl e during state c4. the rst pin must be held high for at least two machine cycles before the reset ci rcuitry applies an internal reset signal. thus, this reset is a synchronous operation and requires the clock to be running. the device remains in the reset state as long as rst is one and remains there up to two machine cycles after rst is deactivated. then, the devic e begins program execution at 0000h. there are no flags associated with the external reset, but, since the other two reset sources do have flags, the external reset is the cause if those flags are clear. 10.1.2 power-on reset (por) if the power supply falls below v rst , the device goes into the rese t state. when the power supply returns to proper levels, the device performs a power-on reset and sets the por flag. the software should clear the por flag, or it will be difficu lt to determine the source of future resets. 10.1.3 watchdog timer reset the watchdog timer is a free-running timer with pr ogrammable time-out intervals. the program must clear the watchdog timer before the time-out interval is reached to restart the count. if the time-out interval is reached, an interrupt flag is set. 512 cloc ks later, if the watchdog reset is enabled and the watchdog timer has not been cleared, the watchdog timer generates a reset. the reset condition is maintained by the hardware for two machine cycles , and the wtrf bit in wdcon is set. afterwards, the device begins program execution at 0000h.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 92 - revision a4.0 10.2 reset state when the device is reset, most registers return to th eir initial state. the watchdog timer is disabled if the reset source was a power-on reset. the port regi sters are set to ffh, which puts most of the port pins in a high state and makes port 0 float (as it does not have on-chip pull-up resistors). the program counter is set to 0000h, and the stack pointer is re set to 07h. after this, the device remains in the reset state as long as the reset conditions are satisfied. reset does not affect the on-chip ram, however , so ram is preserved as long as vdd remains above approximately 2 v, the minimum operating vo ltage for the ram. if vdd falls below 2 v, the ram contents are also lost. in eit her case, the stack pointer is alwa ys reset, so the stack contents are lost. the wdcon sfr bits are set/cleared in reset condition depends on the source of the reset. the wdcon sfr is set to a 0x0x0xx0b on an external reset. wtrf is set to a 1 on a watchdog timer reset, but to a 0 on power on/down resets. wtrf is not altered by an external reset. por is set to 1 by a power-on reset. ewt is cleared to 0 on a powe r-on reset and unaffected by other resets. all the bits in this sfr have unrestricted read access. por, wdif, ewt and rwt bits require timed access (ta) procedure to write. the remaining bits have unr estricted write accesses. please refer ta register description. table below lists the different reset va lues for wdcon due to different sources of reset. wdcon watch-dog control d8h (df) - (de) por (dd) - (dc) - (db) wdif (da) wtrf (d9) ewt (d8) rwt x0xx 0000b external reset x0xx 0100b watchdog reset x1xx 0000b power on reset
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 93 - revision a4.0 11. interrupts the device has a four priority level interrupt structur e with 20 interrupt sources. each of the interrupt sources has an individual priority bit, flag, interrupt vector and enable bit. in addition, all the interrupts can be globally enabled or disabled. 11.1 interrupt sources the external interrupts int0 and int1 can be either edge triggered or level triggered, depending on bits it0 and it1. the bits ie0 and ie1 in the tcon register are the flags which are checked to generate the interrupt. in the edge triggered mode, the intx inputs are sampled in every machine cycle. if the sample is high in one cycle and low in the next, then a high to low transition is detected and the interrupts request flag iex in tcon is set. the flag bit requests the interrupt. since the external interrupts are sampled every machine cycle, they have to be held high or low for at least one complete machine cycle. the iex flag is automatical ly cleared when the service routine is called. if the level triggered mode is selected, then the requesting source has to hold the pin low till the interrupt is serviced. the iex flag will not be cleared by the hardware on enteri ng the service routine. if the interrupt continues to be held low even after the serv ice routine is completed, then the processor may acknowledge another interrupt request from the same source. note that the external interrupts int2 are edge trigger only. by default, the individual interrupt flag corresponding to external interrupt 2 to 5 must be cleared manually by software. it can be configured with hardware cleared by setting the corresponding bit hcx in t2mod register. for instance, if hc2 is set hardware will clear ie2 flag after program enters the interrupt 2 servic e routine. while for int3 to int5 can detect the rising, falling or both edges which function are selectable by softwar e located in intctrl [5:0] register. the timer 0 and 1 interrupts are generated by the tf0 and tf1 flags . these flags are set by the overflow in the timer 0 and timer 1. the tf0 and tf1 flags are au tomatically cleared by the hardware when the timer interrupt is serviced. the timer 2 interrupt is generated by a logical or of the tf2 and the exf2 flags. these flags are set by overfl ow or capture/reload events in the timer 2 operation. the hardware does not clear these flags when a timer 2 interrupt is executed. software has to resolve the cause of the interrupt between tf2 and exf2 and clear the appropriate flag. when adc conversion is completed ha rdware will set flag adci to logi c high to request adc interrupt if bit eadc (ie.6) is in high state. adci is cleared by software only. the i2c function can generate interrupt, if ei2c and ea bits are enabled, when si flag is set due to a new i2c status code is generated, si flag is gener ated by hardware and must be cleared by software. the watchdog timer can be used as a system monitor or a simple timer. in either case, when the time- out count is reached, the watchdog timer interrupt flag wdif (wdcon.3) is set. if the interrupt is enabled by the enable bit eie.4, then an interrupt will occur. all the bits that generate interrupts can be set or reset by hardware, and t hereby software initiated interrupts can be generated. each of the individual interrupts can be enabled or disabled by setting or clearing a bit in the ie sfr. ie also has a gl obal enable/disable bit ea, which can be cleared to disable all interrupts. 11.2 priority level structure there are four priority levels for the interrupts; highest, high, low and lowest. the other interrupt source can be individually set to either high or low levels. naturally, a higher priority interrupt cannot be interrupted by a lower priority interrupt. howe ver there exists a predefined hierarchy amongst the interrupts themselves. this hierarchy comes into play when the interrupt controller has to resolve simultaneous requests having the same priority level. this hierarchy is defined as shown below; the interrupts are numbered starting from the highest priority to the lowest.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 94 - revision a4.0 source flag vector address flag cleared by priority level external interrupt 0 ie0 0003h hardware, follow the inverse of pin 1(highest) timer 0 overflow tf0 000bh hardware, software 2 external interrupt 1 ie1 0013h hardware, follow the inverse of pin 3 timer 1 overflow tf1 001bh hardware, software 4 serial port ri + ti 0023h software 5 timer 2 overflow tf2 + exf2 002bh software 6 a/d converter adci 0033h software 7 i2c channel i2c1 si 003bh software 8 serial port 1 ri_1 + ti_1 007bh software 9 spi interrupt spif + modf + spiovf 0083h software 10 external interrupt 2 ie2 0043h hardware, software 11 external interrupt 3 ie3 004bh hardware, software 12 external interrupt 4 ie4 0053h hardware, software 13 external interrupt 5 ie5 005bh hardware, software 14 pwm period pwmf 0073h software 15 pwm brake bkf 006bh software 16 timer 3 overflow tf3 008bh software 17 capture input/direction interrupt/qei cptf0/qeif+ cptf1/dirf+ cptf2 0093h software 18 nvm interrupt nvmf 009bh software 19 watchdog timer wdif 0063h software 20 table 11- 1: priority structure of interrupts the interrupt flags are sampled every machine cycle. in the same machine cycle, the sampled interrupts are polled and their priori ty is resolved. if certain cond itions are met, the hardware will execute an internally generated lc all instruction which will vector the proces s to the appropriate interrupt vector address. the conditions for generating the lcall are; 1. an interrupt of equal or higher prio rity is not currently being serviced. 2. the current polling cycle is the last machine cycle of the instruction currently being executed. 3. the current instruction does not involve a write to ie, eie, eie1, ip, eip, ei p1, iph, eiph or eip1h registers and is not a reti.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 95 - revision a4.0 if any of these conditions are not met, then the lcall will not be generated. the polling cycle is repeated every machine cycle, with the interrupts samp led in the same machine cycle. if an interrupt flag is active in one cycle but not responded to, and is not active when the above conditions are met, the denied interrupt will not be servic ed. this means that active inte rrupts are not remembered; every polling cycle is new. the processor responds to a valid interrupt by executing an lcall instruction to the appropriate service routine. this may or may not clear the flag which caused the interrupt. in case of timer interrupts, the tf0 or tf1 flags are cleared by hardware whenever the processor vectors to the appropriate timer service routine. in case of external interrupt, int0 and int1, the flags are cleared only if they are edge triggered. in case of serial interrupts, the flags are not cleared by hardware. in the case of timer 2 interrupt, the flags are not cl eared by hardware. the wa tchdog timer interrupt flag wdif has to be cleared by software. the hardwar e lcall behaves exactly like the software lcall instruction. this instruction save s the program counter contents onto the stack, but does not save the program status word psw. the pc is reloaded with the vector address of that interrupt which caused the lcall. these address of vector for the different sources are shown in table 11- 1: priority structure of interrupts . priority bits iph/eiph/eip1h ip/eip/eip1 interrupt priority level 0 0 level 0 (lowest priority) 0 1 level 1 1 0 level 2 1 1 level 3 (highest priority) table 11- 2: four-level interrupt priority each interrupt source can be individually programm ed to one of four priority levels by setting or clearing bits in the ip, iph, eip, eiph, eip1 and eip1h registers. an interrupt service routine in progress can be interrupted by a higher priority inte rrupt, but not by another in terrupt of the same or lower priority. the highest priority interrupt servic e cannot be interrupted by any other interrupt source. so, if two requests of different priority levels are received simultaneously, the request of higher priority level is serviced. if requests of the same priority level are receiv ed simultaneously, an internal polling sequence determines which request is serviced. this is called the arbitration ranking. note that the arbitration ranking is only used to resolve simultaneous requests of the same priority level. as below table summarizes the interrupt sources, fl ag bits, vector addresses, enable bits, priority bits, arbitration ranking, and whether each interrupt may wake up the cpu from power down mode.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 96 - revision a4.0 source flag vector address interrupt enable bits interrupt priority control bits arbitration ranking power down wakeup external interrupt 0 ie0 0003h ex0 (ie.0) iph.0,ip.0 1(highest) yes timer 0 overflow tf0 000bh et0 (ie.1) iph.1,ip.1 2 no external interrupt 1 ie1 0013h ex1 (ie.2) iph.2,ip.2 3 yes timer 1 overflow tf1 001bh et1 (ie.3) iph.3,ip.3 4 no serial port ri + ti 0023h es (ie.4) iph.4,ip.4 5 no timer 2 overflow tf2 + exf2 002bh et2 (ie.5) iph.5,ip.5 6 no a/d converter adci 0033h eadc (ie.6) iph.6,ip.6 7 no i2c channel i2c si 003bh ei2c (eie.0) eiph.0, eip.0 8 no serial port 1 ri_1 + ti_1 007bh es1 (eie.7) eiph.7, eip.7 9 no spi interrupt spif/modf/ spiovf 0083h espi (eie1.0) eip1h.0, eip1.0 10 no external interrupt 2 ie2 0043h ex2 (eie.2) eiph.2, eip.2 11 no external interrupt 3 ie3 004bh ex3 (eie.3) eiph.3, eip.3 12 no external interrupt 4 ie4 0053h ex4 (eie.5) eiph.5, eip.5 13 no external interrupt 5 ie5 005bh ex5 (eie.6) eiph.6, eip.6 14 no pwm period pwmf 0073h epwm (eie1.1) eip1h.1, eip1.1 15 no pwm brake bkf 006bh ebk (eie1.2) eip1h.2, eip1.2 16 no timer 3 overflow tf3 008bh et3 (eie1.3) eip1h.3, eip1.3 17 no capture input/direction interrupt/qei cptf0/qeif + cptf1/dirf + cptf2 0093h ecptf (eie1.4) eip1h.4, eip1.4 18 no nvm interrupt nvmf 009bh envmi (eie1.5) eip1h.5, eip1.5 19 no watchdog timer wdif 0063h ewdi (eie.4) eiph.4, eip.4 20 no table 11- 3: vector location for interrupt sources and power down wakeup
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 97 - revision a4.0 11.2.1 response time the response time for each interrupt source depends on several factors like nature of the interrupt and the instruction under progress. in the case of exter nal interrupt int0 to int5, they are sampled at c3 of every machine cycle and then t heir corresponding interrupt flags ie0 and ie1 will be set or reset. similarly, the serial port flags ri/ri_1 and ti/ti_1 ar e set in c4 of last machine cycle. the timer 0 and 1 overflow flags are set at c3 of the machine cycle in which overflow has occurred. these flag values are polled only in the next machine cycle. if a request is active and all three conditions are met, then the hardware generated lcall is executed. this call itself takes four machine cycles to be completed. thus there is a minimum time of five machine cycles between the interrupt flag being set and the interrupt service routine being executed. a longer response time should be anticipated if any of the three conditions are not met. if a higher or equal priority is being serviced, then the interrupt latency time obviously depends on the nature of the service routine currently being exec uted. if the polling cycle is not the last machine cycle of the instruction being executed, then an additional delay is introduced. the maximum response time (if no other interrupt is in service) occu rs if the device is performing a writ e to ie, ip, iph, eie, eip, eiph, eie1, eip1 or eip1h and then executes a mul or div in struction. from the time an interrupt source is activated, the longest reaction time is 12 machine cycles. this includes 1 machine cycle to detect the interrupt, 2 machine cycles to complete the ie, ip, iph, eie, eip, eiph, eie1, eip1 or eip1h access, 5 machine cycles to complete the mul or div instruction and 4 machine cycles to complete the hardware lcall to the interrupt vector location. thus in a single-interrupt system the interrupt response time will always be more than 5 machine cycles and not more than 12 machine cycles. the maximum latency of 12 machine cycle is 48 clock cycles. note that in the standard 8051 the maximum latency is 8 machine cycles which equals 96 machine cycles. this is a 50% reduction in terms of clock periods.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 98 - revision a4.0 12. programmable timers/counters the w79e22x series has three 16-bit programmable timer/counters. 12.1 timer/counters 0 & 1 tm0 and tm1 are 16-bit timer/counters, and there are n early identical. each of these timer/counters has two 8 bit registers which form the 16 bits counti ng register. for timer/counter 0, it consists of th0, the upper 8 bits register, and tl0, the lower 8 bit register. similarly timer/counter 1 has two 8 bits registers; th1 and tl1. the two timers can be configured to operate either as timers, counting machine cycles or as counters counting external inputs. when configured as a "timer", the timer counts cl ock cycles. in "counter" mode, the register is incremented on the falling edge of the corresponding ex ternal input pins, t0 for timer 0 and t1 for timer 1. the t0 and t1 inputs are sampled in every machine cycle at c4. if the sampled value is high in one machine cycle and low in the next, then a vali d high to low transition on the pin is recognized and the count register is incremented. since it takes two machine cycles to recognize a negative transition on the pin, therefore the maximum counting ra te is 1/8 of the master clock frequency. in both "timer" and "counter" mode, the count register is updated at c3. therefore, in the "timer" mode, the recognized negative transition on pin t0 and t1 can cause the count register value to be updated only in the machine cycle following the one in which the negative edge was detected. the "timer" or "counter" function is selected by the " t c/ " bit in the tmod special function register. each timer/counter has one selection bit for its own; bit 2 of tmod selects the function for timer/counter 0 and bit 6 of tmod selects the function for timer/counter 1. in addition each timer/counter can be set to operate in any one of four possible modes. the mode selection is done by bits m0 and m1 in the tmod sfr. 12.1.1 time-base selection the w79e22x series can operate like the standard 8051/52 family, counting at the rate of 1/12 of the clock speed, or in turbo mode, counting at the rate of 1/4 clock speed. the speed is controlled by the t0m and t1m bits in ckcon, and the defaul t value is zero, which uses the standard 8051/52 speed. 12.1.2 mode 0 in mode 0, the timer/counter is a 13-bit counter. the 13-bit counter consists of thx (8 msb) and the five lower bits of tlx (5 lsb). the upper three bits of tlx are ignored. the timer/counter is enabled when trx is set and either gate is 0 or int x is 1. when t c/ is 0, the timer/counter counts clock cycles; when t c/ is 1, it counts falling edges on t0 (p3.4 fo r timer 0) or t1 (p3.5 for timer 1). for clock cycles, the time base may be 1/12 or 1/ 4 clock speed, and the falling edge of the clock increments the counter. when the 13-bit value move s from 1fffh to 0000h, the timer overflow flag tfx is set, and an interrupt occurs if enabled. this is illustrated in next figure below.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 99 - revision a4.0 12.1.3 mode 1 mode 1 is the same as mode 0, except that the timer/counter is 16 bits, instead of 13 bits. figure 12-1: timer/counters 0 & 1 in mode 0 and mode 1 12.1.4 mode 2 in mode 2, the timer/counter is in the auto reload mode. in this mode, tlx acts as an 8 bits count register, while thx holds the reload value. when t he tlx register overflows from ffh to 00h, the tfx bit in tcon is set and tlx is reloaded with the contents of thx, and the counting process continues. the reload operation leaves the contents of the th x register unchanged. counting is enabled by the trx bit and proper setting of gate and int x pins. as in the other two modes 0 and 1, mode 2 allows counting of either clock cycles (clock/12 or clock/4) or pulses on pin tn. figure 12-2: timer/counter 0 & 1 in mode 2
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 100 - revision a4.0 12.1.5 mode 3 mode 3 is used when an extra 8-bit timer is needed. it has different effect on timer 0 and timer 1. tl0 and th0 become two separate 8 bits counters. tl0 uses the timer 0 control bits t c/ , gate, tr0, int0 and tf0, and it can be used to count clock cycles (clock/12 or clock/4) or falling edges on pin t0, as determined by t c/ (tmod.2). th0 becomes a clock-cycle counter (clock/12 or clock/4) and takes over the timer 1 enable bit tr1 and overflow fl ag tf1. in contrast, mode 3 simply freezes timer 1. if timer 0 is in mode 3, timer 1 can still be us ed in modes 0, 1 and 2, but it no longer has control over tr1 and tf1. therefore when timer 0 is in m ode 3, timer 1 can only count oscillator cycles, and it does not have an interrupt or flag. with these lim itations, baud rate generation is its most practical application, but other time-base functions ma y be achieved by reading the registers. figure 12-3: timer/counter mode 3 12.2 timer/counter 2 timer/counter 2 is a 16-bit up/down-counter equip ped with a capture/reload capability. the clock source for timer/counter 2 may be the external t2 pin ( t2 c / = 1) or the crystal oscillator ( t2 c / = 0), divided by 12 or 4. the clock is enabled and disabled by tr2. timer/counter 2 runs in one of four operating modes, each of which is discussed below.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 101 - revision a4.0 12.2.1 capture mode capture mode is enabled by setting rl2 cp/ in t2con to 1. in capture mode, timer/counter 2 is a 16-bit up-counter. when the counter rolls over from ffffh to 0000h, the timer overflow flag tf2 is set, and an interrupt is generated, if enabled. if the exen2 bit is set, a negative transition on the t2ex pin captures the current value of tl2 and th2 in the rcap2l and rcap2h registers. it also sets the exf2 bit in t2con, which generates an interrupt if enabled. in addition, if the t2cr bit in t2mod is set, t he w79e22x series resets timer 2 automatically after ea ch capture. this is illustrated below. (rclk,tclk, rl2 cp/ )= (0,0,1) figure 12-4: timer2 16-bit capture mode 12.2.2 auto-reload mode, counting up this mode is enabled by clearing rl2 cp/ in t2con register and dcen in t2mod. in this mode, timer/counter 2 is a 16-bit up-counter. when the counter rolls over from ffffh to 0000h, the timer overflow flag tf2 is set, and tl2 and th2 capture the contents of rcap2l and rcap2h, respectively. alternatively, if exen2 is set, a negative transition on the t2ex pin causes a reload, which also sets the exf2 bit in t2con.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 102 - revision a4.0 (rclk,tclk, rl2 cp/ )= (0,0,0) & dcen= 0 figure 12-5: 16-bit auto-reload mode, counting up 12.2.3 auto-reload mode, counting up/down this mode is enabled by clearing cp rl /2 in t2con and setting dcen in t2mod. in this mode, timer/counter 2 is a 16-bit up/down-counter, whose di rection is controlled by the t2ex pin (1 = up, 0 = down). if timer/counter 2 is counting up, an overfl ow reloads tl2 and th2 with the contents of the capture registers rcap2l and rcap2h. if timer/ counter 2 is counting down, tl2 and th2 are loaded with ffffh when the contents of timer/co unter 2 equal the capture registers rcap2l and rcap2h. regardless of direction, reloading sets the tf2 bit. it also toggles the exf2 bit, but the exf2 bit can not generate an interrupt in this mode. this is illustrated below. (rclk,tclk, rl2 cp/ )= (0,0,0) & dcen= 1 figure 12-6: 16-bit auto-reload up/down counter
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 103 - revision a4.0 12.2.4 baud rate generator mode baud rate generator mode is enabled by setting either rclk or tclk in t2con. in baud rate generator mode, timer/counter 2 is a 16-bit counter with auto-reload when the count rolls over from ffffh. however, rolling-over does not set tf2. if exen2 is set, then a negative transition on the t2ex pin sets exf2 bit in the t2con r egister and causes an interrupt request. rclk+tclk=1, rl2 cp/ =0 figure 12-7: baud rate generator mode
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 104 - revision a4.0 13. watchdog timer the watchdog timer is a free-running timer that c an be programmed to serve as a system monitor, a time-base generator or an event timer. it is basically a set of dividers that divide the system clock to determine the time-out interval. when the time- out occurs, a flag is set, which can generate an interrupt or a system reset, if enabled. the interrupt will occur if its interrupt and global interrupt enables are set. the interrupt and reset functions are independent of each other and may be used separately or together. the main use of the watchdog timer is as a syst em monitor. in case of power glitches or electromagnetic interference, the processor may be gin to execute errant code. the watchdog timer helps w79e22x series recovers from these stat es. during development, the code is first written without the watchdog interrupt or reset. then, t he watchdog interrupt is enabled to identify code locations where the interrupt occurs, and instructions are inserted to reset the watchdog timer in these locations. in the final version, the watchdog interrupt is disabled, and the watchdog reset is enabled. if errant code is executed, the watchdog ti mer is not reset at the required times, so a watchdog timer reset occurs. when used as a simple timer, the reset and interru pt functions are disabled. the watchdog timer can be started by rwt and sets the wdif flag after the selected time interval. meanwhile, the program polls the wdif flag to find out when the selected time interval has passed. al ternatively, the watchdog timer can also be used as a very long timer. in this case, the interrupt feature is enabled. figure 13-1: watchdog timer the watchdog timer should be started by rwt beca use this ensures that the timer starts from a known state. the rwt bit is self-clearing; i.e., afte r writing a 1 to this bit, the bit is automatically cleared. after setting rwt, the watchdog timer begins counting clock cycles. the time-out interval is selected by wd1 and wd0 (ckcon.7 and ckcon.6). wd1 wd0 interrupt time-out reset time-out number of clocks time @ 10 mhz time @ 11.0592 mhz time @ 25 mhz 0 0 2 17 2 17 + 512 131072 13.11 ms 11.85 ms 5.24 ms 0 1 2 20 2 20 + 512 1048576 104.86 ms 94.81 ms 41.94 ms 1 0 2 23 2 23 + 512 8388608 838.86 ms 758.52 ms 335.54 ms 1 1 2 26 2 26 + 512 67108864 6710.89 ms 6068.15 ms 2684.35 ms table 13-1: time-out values for the watchdog timer
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 105 - revision a4.0 when the selected time-out occurs, the watchd og interrupt flag wdif (wdcon.3) is set. after watchdog time-out, and if watchdog timer reset ewt (wdcon.1) is enabled, the watchdog timer will cause a reset 512 clocks later. this reset lasts two machine cycles, and the watchdog timer reset flag wtrf (wdcon.2) is set, which indicates that the watchdog timer caused the reset. rwt can be used to clear watchdog timer before a time-out occurs. the watchdog timer is disabled by a power-on/fail reset. the external reset and watchdog timer reset can not disable watchdog timer, instead it only restart the timer. the control bits that support the watchdog timer are described as below: watchdog timer control (wdcon) bit name function 7 - reserved. 6 por power-on reset flag. the hardware sets this flag during power?up, and it can only be cleared by software. this flag can also be written by software. 5-4 - reserved. 3 wdif watchdog timer interrupt flag. if the watc hdog interrupt is enabled, the hardware sets this bit to indicate that the watchdog interrupt has occurred. if the interrupt is not enabled, this bit indicates that the time-o ut period has elapsed. this bit must be cleared by software. 2 wtrf watchdog timer reset flag. if ewt is 0, the watchdog timer has no affect on this bit. otherwise, the hardware sets this bit when the watchdog timer causes a reset. it can be cleared by software or a power- fail reset. it can be also read by software, which helps determine the cause of a reset. 1 ewt enable watchdog-timer reset. set this bit to enable the watchdog timer reset function. 0 rwt reset watchdog timer. set this bit to reset the watchdog timer before a time-out occurs. this bit is automatically cleared by the hardware.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 106 - revision a4.0 the por, ewt, wdif and rwt bits are protected by the timed access procedure. this procedure prevents software, especially errant code, from a ccidentally enabling or disabling the watchdog timer. an example is provided below. org 63h mov ta,#aah mov ta,#55h clr wdif jnb execute_reset_flag,bypass_reset ; test if cpu need to reset. jmp $ ; wait to reset bypass_reset: mov ta,#aah mov ta,#55h setb rwt reti org 300h start: mov ckcon,#01h ; select 2 ^ 17 timer ; mov ckcon,#61h ; select 2 ^ 20 timer ; mov ckcon,#81h ; select 2 ^ 23 timer ; mov ckcon,#c1h ; select 2 ^ 26 timer mov ta,#aah mov ta,#55h mov wdcon,#00000011b setb ewdi setb ea jmp $ ; wait time out clock control wd1, wd0: ckcon.7, ckcon.6 - wa tchdog timer mode select bits. these two bits select the time- out interval for the watchdog timer. the reset interv al is 512 clocks longer than the selected interval. the default time-out is 2 17 clocks, the shortest time-out period.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 107 - revision a4.0 14. pulse-width-modulated (pwm) outputs 14.1 pwm features the pwm block supports the following features; z four 12-bit pwm channels or complementary pairs: ? 4 independent pwm outputs: pwm0, pwm2, pwm4 & pwm6. ? 4 complementary pwm pairs with insertion of programmable dead-time: (pwm0,pwm1), (pwm2,pwm3), (pwm4,pwm5), (pwm6,pwm7) z three operation mode: edge aligned mode, center aligned mode and single shot mode. z programmable dead-time insertion between paired pwms. z output override control for electrically commutated motor operation. z hardware/software brake protection. z support 2 independent interrupts: ? interrupt request when up/down counter comparison matched or underflow. ? interrupt request when external brake asserted. z flexible operation in debug mode. z high source/sink current. the outputs for pwm0 to pwm7 are on p2[5:0] (pwm [5:0]) and p5[1:0] (pwm [7:6]) respectively. after cpu reset, the internal output of each pw m channel depends on the output controls and polarity settings. the interval between successive output s is controlled by a 12?bit up/down counter which uses the oscillator frequency with configurable internal clock prescaler as its input. the pwm counter clock, has the frequency as the clock source f pwm = f osc /prescaler. the following figure 14-1: pwm block diagram below is the block diagram for pwm. figure 14-1: pwm block diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 108 - revision a4.0 14.2 pwm control registers the overall functioning of the pwm module is cont rolled by the contents of the pwmcon1 register. the operation of most of the control bits is stra ightforward. for example pwm0i is an invert bit for each output which causes result s in the output to have the opposite value compared to its non- inverted output. the transfer of the data from the counter and compare registers to the control registers is controlled by the pwmcon1.6 (load) while pwmcon1.7 (pwmrun) allows the pwm to be either in the run or idle state. if the brake pin is not used to control the brake function, the ?brake when pwm is not running? function can be used to cause the outputs to hav e a given state when the pwm is halted. this approach should be used only in time critical situat ions when there is not sufficient time to use the approach outlined above, since going from the brak e state to run without causing an undefined state on the outputs is not straightforward. a discussion on this topic is included in the section on pwmcon2. the brake function, which is controlled by the contents of the pwmcon2 register, is somewhat unique. in general, when brake is asserted, the eight pwm outputs are forced to a user selected state, namely the state selected by pwmcon3. as sh own in the description of the operation of the pwmcon2 register, if pwmcon2.4, bken, is a ?1? brake is asserted under the control pwmcon2.7, bkch, and pwmcon2.5, bpen. as show n, if both are a ?0?, brake is asserted. if pwmcon2.7 is a ?1?, brake is asserted when the pwmrun bit, pwmcon1.7, is a ?0?. if pwmcon2.6, bkps, is a ?1?, brake is asserted when the brake pin, p1.1, has the same polarity as pwmcon2.6. when brake is asserted in response to this pin, the pwmrun bit in pwmcon1.7 is automatically cleared, and bkf (pwmcon4.0) fl ag will be set. when both bkch and bpen are ?1?, bkf will be set when brake pin is asserted, but pwm generator continues to run. with this special condition, the pwm output does not follow pwmnb, instead it output continuously as per normal without affected by the brake. since the brake pin being asserted will automat ically clear the pwmrun (pwmcon1.7) and bkf (pwmcon4.0) flag will be set, the user program can poll this bit or enable pwm?s brake interrupt to determine when the brake pin causes a brake to occur. the other method for detecting a brake caused by the brake pin would be to tie the brake pi n to one of the external interrupt pins. this latter approach is needed if the brake signal is of insuffi cient length to ensure that it can be captured by a polling routine. when, after being asserted, the condition causing the brake is removed, the pwm outputs go to whatever state that had immediately prior to the brake. this means that in order to go from brake being asserted to having the pwm run without going through an i ndeterminate state, care must be taken. if the brake pin ca uses brake to be asserted, the fo llowing prototype code will allow the pwm to go from brake to run smoothly by so ftware polling bkf flag or enable pwm?s interrupt. ? rewrite pwmcon2 to change from brake pin enabled to s/w brake. ? write pwm (0, 2, 4, 6) compare register to always ?1?, fffh, or always ?0?, 000h, to initialize pwm output to a high or low, respectively. ? clear bkf flag. ? set pwmcon1 to enable pwmrun and load. ? poll brake pin until it is no longer active. ? poll pwmcon1 to find that load bit pwmcon1.6 is ?0?. when ?0?: ? write pwmp (0, 2, 4, and 6) counter register fo r desired pulse widths and counter reload values. ? set pwmcon1 to run and transfer.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 109 - revision a4.0 note that if a narrow pulse on the brake pin causes brake to be asserted, it may not be possible to go through the above code before the end of the pulse. in this case, in addition to the code shown, an external latch on the brake pin may be required to ensure that there is a smooth transition in going from brake to run. a compare value greater than the counter reloaded value resulted in the pwm output being high. in addition there are two specia l cases. a compare value of all zeroes, 000h, causes the output to remain permanently low. a com pare value of all ones, fffh, results in the pwm output remaining permanently high. figure 14-2: pwm time-base generator and brake function
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 110 - revision a4.0 the pwmp register fact that writes are not into the counter register that controls the counter; rather they are into a holding register. as described below t he transfer of data from this holding register, into the register which contains the actual reload value, is controlled by the user ?s program. the width of each pwm output pulse is determined by the value in the appropriate compare register. each pwm register pair of (pwmph,pwmpl), (pwm0h,pwm0l), (p wm2h,pwm2l), (pwm4h,pwm4l) and (pwm6h,pwm6l) ,in the format of 12-bit width by combini ng 4 lsb of high byte and 8 msb bits of low byte, decides the pwm period and each channel?s duty cycle. the following equations show the formula for period and duty for each pwm operation mode: edge aligned : period = (pwmp +1) * ioclock period * 1/prescaler duty = duty * ioclock period single shot : period = (pwmp) * ioclock period /prescaler (no meaning since it is not periodic) duty = (duty) * ioclock period/prescaler (for prescaler 1, 1/2/2, 1/4) (duty-1) * ioclock period /prescaler < duty < (duty) * ioclock period/prescaler (for prescaler 1/16) centre aligned : period = (pwmp* 2) * ioclock period /prescaler duty = (duty*2 - 1) * ioclock period /prescaler note: ?duty? refers to pwm0~3 register value. 14.3 pwm pin structures as show in the following diagrams, pwm pin stru ctures are controllable through pwm options bits (pwmee/pwmoe) and sfr pwmcon4 bits (pwmeom/pwmoom/pwm6om/pwm7om). pwmee/pwmoe (option bits)  pwmeom/pwmoom /pwm6om/pwm7om pio.x  (x = 0-7) pin structures x 0 x tri-state 1 (d isable
 1 x quasi (i/o output) 0 (enable)  1 0 push pull (pwm output) 0 (enable)  1 1 push pull (i/o output) table 14-1: pwm pin structures ( during internal rom execution) pwmee/pwmoe (option bits)  pwmeom/pwmoom /pwm6om/pwm7om pio.x  (x = 0-7) pin output pin structures 1 (disable) x x external access push pull  &obcmf
 x x external access push pull (strong) table 14-2: pwm pin structures ( during external rom execution)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 111 - revision a4.0 note: pwmeom/pwmoom/pwm6om/pwm7om are clear ed to zero when cpu in reset state. thus, the port pins that multi-function with pwm will be tri-stated on default. user is required to set the bits to enable gpio/pwm outputs. figure 14-3: pwm0, 2 & 4 i/o pins figure 14-4: pwm1, 3 & 5 i/o pins
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 112 - revision a4.0 figure 14-5: pwm6 i/o pin figure 14-6: pwm7 i/o pin figure 14-7: even pwm output
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 113 - revision a4.0 pwm output (pwm1,3,5,7) opol (option bit) pwm initial state 0 1 0 1 0 1 low high pwmob pwmoen in brake condition c note: o = 1,3,5,7 figure 14-8: odd pwm output 14.4 complementary pwm with dead-time and override functions in this module there are four duty-cycle generators , from 0 through 3. the total of eight pwm output pins in this module, from 0 through 7. the eight pwm outputs are grouped into output pairs of even and odd numbered outputs. in complimentary modes, the odd pwm pins must always be the complement of the corresponding even pwm pin. for example, pwm1 will be the complement of pwm0. pwm3 will be the complement of pwm2, pw m5 will be the complement of pwm4 and pwm7 will be the complement of pwm6. complementary mode is enabled only when both pwmeen and the corresponding pwmoen are set to high. the time base for the pwm module is provided by its own 12-bit timer, which also incorporates selectable prescaler options. note: pwm pairs of (pwm2, 3), (pwm4, 5) and (p wm6, 7) are in the same structure as pair of (pwm0, 1). (refer to figure 14-9 ). figure 14-9: complementary pwm with dead-time and override functions
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 114 - revision a4.0 14.5 dead-time insertion the dead time generator inserts an ?off? period called ?dead time? between the turnings off of one pin to the turning on of the complementary pin of the paired pins. this is to prevent damage to the power switching devices that will be connected to the pw m output pins. each comple mentary output pair for the pwm module has 6-bits counter used to produce the dead time insertion. each dead time unit has a rising and falling edge detector connected to the duty cycle comparison output. the dead time is loaded into the timer on the detected pwm edge event. depending on whether the edge is rising or falling, one of the transitions on the complementar y outputs is delayed until the timer counts down to zero. a timing diagram indicating the dead time insertion for one pair of pwm outputs is shown in figure 14-10 and figure 14-11 . pwm0 without dead-time pwm1 without dead-time pwm0 with dead-time pwm1 with dead-time dead-time interval note: pdtc0.4 selects insertion at rising edge figure 14-10: effect of dead-time for complementary pairs (rising edge) pwm0 without dead-time pwm1 without dead-time pwm0 with dead-time pwm1 with dead-time dead-time interval note: pdtc0.4 selects insertion at falling edge figure 14-11: effect of dead-time for complementary pairs (falling edge) note: user need to take care that power switches should not be use when pwm pair is asserted (high) at the same time. pdtco and pdtc1 have time access protection in writing access. in power inverter application, a dead time insertion avoids the upper and lower swit ches of the half bridge from being active at the same time. hence the dead time control is crucial to proper operation of a system. some amount of time must be provided between turning off of one pwm output in a complementary pair and turning on the other transistor as the power output devices cannot switch instantaneously.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 115 - revision a4.0 14.6 pwm output override figure 14-12: override flow diagram each of the pwm output channels can be manually ov erridden by using the appropriate bits in the povd and povm registers. this function allow user to drive the pwm i/o pins to specified logic states independent of the duty cycle comparison units. the pwm override bits are useful when controlling various types of electrically commut ated motor (ecm) like a bldc motor. the povd register contains eight bits, povd [7:0]. it determines which pwm i/o pi ns will be overridden. on reset, povd is 00h. the povm register contains eight bits, povm[7:0]. it determines the state of the pwm i/o pins when a particular output is overridden via the povd bits . on reset, povm is 00h. the povm[7:0] bits are active-high. when the povm[7:0] bits are set, the corresponding povd[7:0] bi t will have effect on the pwm output. when one of the povm bits is set, the output on the corresponding pwm i/o pin will be determined by the state of corresponding povd bit. when a povm bit is clear, the pwm pin will be driven to its active state. the odd channel is al ways the complement of the even channel with dead time inserted.. figure 14-13 demonstrates the override function in complementary mode.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 116 - revision a4.0 figure 14-13: override bit in complementary mode assume rising edge dead time insertion; refer to figure 14-12: override flow diagram . example: povm0 = 1 and povm1 = 0; pwm0en and pwm1en = 1; a. odd override bits have no effect in complementary mode. b. even override bit is activated, wh ich causes the odd pwm to deactivate. c. dead-time insertion. d. even pwm activated after the dead-time. e. even override bit is deactivated, wh ich causes the even pwm to deactivate. f. dead-time insertion. g. odd pwm is activated after the dead time. figure 14-14: example 1 of output even & odd override
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 117 - revision a4.0 state povm pwmeen = 1 pwmoen = 1 povd 1 1111 1111b 0110 0100b 2 1111 1111b 1010 0001b 3 1111 1111b 0000 1001b 4 1111 1111b 0001 1000b 5 1111 1111b 1001 0010b 6 1111 1111b 0100 0110b table 14-3: example 1 of output even & odd override figure 14-15: example 2 of output override state #1: povm (odd not overridenot in complementary) (pwmeen = 1, pwmoen = 0) #2: povm (odd not override in complementary) (pwmeen = 1, pwmoen = 1) #3: povm (odd with override not in complementary) (pwmeen = 1, pwmoen = 1) povd 1 0001 0100b 0001 0100b 1011 1110 0000 0000b 2 0000 0101b 0000 0101b 1010 1111 0000 0000b 3 0100 0001b 0100 0001b 1110 1011 0000 0000b 4 0101 0000b 0101 0000b 1111 1010 0000 0000b table 14-4: example 2 of output override
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 118 - revision a4.0 14.7 edge aligned pwm (up-counter) figure 14-16: edge-aligned pwm in edge-aligned pwm output mode, the 12 bits counte r will starts counting from 0 to match with the value of the duty cycle pwm0 (old). when the match occurs, it will toggle the pwm0 output waveform to low. after cpu resets, the value of pwm0 wave form at starts of counter depend on the polarity setting located in the option bits. at this point a new pwm0 (new) is written. the counter will continue counting to match with the value of the period regi ster, pwmp (old) and toggle the pwm0 waveform to high. please take note that pwm0 and pwmp is a double-buffered register used to set the duty cycle and counting period for the pwm time base respectively. for the 1 st buffer it is accessible by user while the 2 nd buffer holds the actual compare value used in the present period. load bit must be set to 1 to enable the value to be loaded in to the 2 nd buffer register when counter underflow/match. when the counter matches the pwmp (old) it will automatically update the new duty cycle register and the counter will again starts counting upwards to matc h the value pwm0 (new). at this point it will toggle the pwm0 waveform to low. new pwmp is wr itten at this point. when the counter continues counting to match the pwmp (old), again the pwm0 waveform will be toggle to high. the counter starts counting from 0 again; at this point the va lue is pwm0 (new) and pwmp (new) to be match by the counter and once the counter matches these values it will be toggle at the pwm output.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 119 - revision a4.0 set pmod[1:0] = 00 start : load = 1 pwmrun = 1, clrpwm = 1 load pwmn and pwmp to working registers ?load? auto clear by hardware (h/w) pwmni = 1? (output inverted?) pwmn output : inverted 0 if counter < pwmn 1 if counter > pwmn pwmn output : non inverted 1 if counter < pwmn 0 if counter > pwmn counter counting up counter = pwmn? pwmn output toggle counter continues counting up counter = pwmp? pwmn output toggle reset counter to zero (h/w) pwmf flag set load = 1? load new pwmp/pwmn value to working register no yes no no no yes figure 14-17: edge-aligned flow diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 120 - revision a4.0 figure 14-18: program flow for edge-aligned mode pwmp (7ff) pwm0 (3ff) pwm0 waveform pwm period pwm period pwm period pwm period pwm period figure 14-19: pwm0 edge aligned waveform output
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 121 - revision a4.0 14.8 center aligned pwm (up/down counter) pwm0 (old) pwm0 (new) pwmp (old) pwmp (new) pwm0 waveform pwm period pwm period new pwm0 is written new pwmp is written 1. 12-bit up counter matches pwmp 2. update new duty cycle register (pwm0,2,4 and 6) if load=1 3. update new pwm period register (pwmp) if load=1 figure 14-20: center-aligned mode center-aligned pwm signals are produced by the m odule when the pwm time base is configured in an up/down counting mode (see figure 14-20 ). the counter will start counting-up from 0 to match the value of pwm0 (old); this will cause the toggling of the pwm0 output to low. the cpu reset states determine the starts value of pwm0 waveform at star ts of counter lies on the polarity setting located in the option bits. at this time the new pwm0 is writ ten to the register. counter continue to count and match with the pwmp (old). upon reaching this states counter is confi gured automatically to down counting and toggle the pwm0 output when counter matches the pwm0 (old) value. interrupt request when up/down counter underflow. once the counte r reaches 0 it will update the duty cycle register with load = 1. up-counting is continues with the ma tching at pwm0 (new) follow by a low toggle at the pwm0 output. by this time the pwmp buffer is still consist of the pwmp (old) value. a new pwmp is written. so the counter will still matches with th is value and continues with down counting and matched the pwm0 (new) and toggle the pwm0 output. again updates on the pwm period register is reflected on the 3 rd cycle of the diagram by starts counting from 0 to match the pwm0 (new) and t oggle at the pwm0 output to low. counter is continuing up-counting, upon reaching the pwmp (new) it is matched. then counter is down counting automatically to match at the pwm0 (new) to get a toggle high at pwm0 output.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 122 - revision a4.0 figure 14-21: center-aligned flow diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 123 - revision a4.0 figure 14-22: pwm0 center aligned waveform output 14.9 single shot (up-counter) figure 14-23: single shot mode the single shot mode pwm module will produce single pulse output. single-pulse operation is configured when the pmod1:pmod0 bits are set to ?01? in pwmcon3 register. this mode of operation is useful for driving certain types of ecms . in this mode, the pwm counter will start counting upwards when the pwmrun is set to 1. when the counter value matches with the pwmp register, pwm interrupt will be generated if it is enable and pwmf is set and counter will reset to zero on the following input clock edge and pwmrun will be clear ed by hardware. duty cycle of pwm channels are determined by the respective pw mx registers, where x = 0,2,4,6
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 124 - revision a4.0 example steps of setting up single shot:- 1. set initial state = 0 (controlled by epol option bit) 2. pwm0en=0, povm.0=0, pwm0i=0, pwm0=0000h(f or keep comparator output in low state), pwmp=0001h(let the period as short as possible) 3. pwmrun=1(do a dummy pwmrun for loading pwm0 to compare register0, which make comparator output low always. 4. pwm0en=1, now the pwm0 pin should be still in 0 state. 5. pwmp=xxxxh(controls a period), pwm0=yyyyh(controls duty or pulse width)  pwmrun=1(this time a real pwm single shot signal user wanted. the wave form should be the upper one.  note: in single shot mode, it?s important that user sets clrpwm together with pwmrun and load in order to have pwmn and pwmp lo aded into working registers immediately.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 125 - revision a4.0 figure 14-24: single-shot flow diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 126 - revision a4.0 14.10 smart fault detector this is a brake detection logic that is new to suppo rt external brake conditions that already exist. a dedicated sfr fsplt is added for this function. the sfr consists of smart fault detector control and status bits. it basically consists of a clock divider, 8 bits counter, comparator and 4 selectable compare values. the following diagram show the general block diagram. figure 14-25: smart fault detector the smart fault detector is enabled when bit lsbd = 1 (fsplt.0). this logic detects low level brake pin. the 8 bits counter is enabled by sfcen bit lo cated in sfr fsplt.3. the counter is clock by fosc divider selectable by sfp1-0 control bits (f splt.5-4). the comparator compares the 8 bits counter value with the compare value selectable with scmp1-0 (fsplt1-0). upon initial detection of low level at brake pin, t he 8 bits counter will be active. this will cause the counter to increment. while the counter is active and there is high level detected at brake pin, the counter will decrement. see next figure for timing diagram. when the counter value reaches compare value, bkf will be asserted.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 127 - revision a4.0 figure 14-26: smart fault detector timing diagram the smart fault detector consists of 2 status bits ; sfcst and sfcdir. a sfcst show status of 8 bits counter is active or in-active, while sfcdir show s the counter?s counting direction. when sfcst = 0, sfcdir keeps its? state. the s/w can manually disable and clear the 8 bi ts counter, by clearing sfcen to 0. the following tables show the tabulate accumulated low level brake time with various fosc/x dividers and compares value, at 40mhz and 20mhz. fosc/x  1/4  1/8  1/16  1/128  scmp[1:0]  10,000,000  5,000,000  2,500,000  312,500  4  0.40us  0.80us  1.60us  12.80us  16  1.60us  3.20us  6.40us  51.20us  64  6.40us  12.80us  25.60us  204.80us  128  12.80us  25.60us  51.20us  409.60us  table 14-5: example the accumulated low level time at 40 mhz fosc/x  1/4  1/8  1/16  1/128  scmp[1:0]  5,000,000  2,500,000  1,250,000  156,250  4  0.80us  1.60us  3.20us  25.60us  16  3.20us  6.40us  12.80us  102.40us  64  12.80us  25.60us  51.20us  409.60us  128  25.60us  51.20us  102.40us  819.20us  table 14-6: example the accumulated low level time at 20 mhz
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 128 - revision a4.0 14.11 pwm power-down/wakeup procedures the following flow diagrams describe the possible pwm procedures users require to take care prior to the product power-down/wake-up. the power-down procedur e below will result in pwm output a low state after power-down. to output a high state, us ers may set pwmn to fffh and initial state set to high through option bit (epol/opol). figure 14-27: example of pwm power-down procedure (pwm output low state)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 129 - revision a4.0 figure 14-28: example of pwm wake-up from power-down procedure
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 130 - revision a4.0 15. motion feedback module motion feedback module is a peripheral module designed for motion feedback applications. this module includes two sub-modules: ? input capture module (ic). ? quadrature encoder interface (qei). there are three 16-bit registers cascaded by tw o 8-bit sfr in motion feedback module, but with different definitions in each sub-module. together with timer 3, these modules provide a number of options for motion and control applications. most of the features for the qei and ic sub-modules are fully programmable thus making a flexible periphe ral structure that can accommodate a wide range of uses. a simplified block diagram of the entire motion feedback module is shown in figure 15-2 . note: the input pins are common to the ic and qei sub-modules, only one of these two sub- modules may be used at any given time. ic sub-module is the default value upon reset. 15.1 input capture module (ic) the capture modules are function to detect and measure pulse width and period of a square wave. it supports 3 capture inputs and digital noise rejectio n filter. the modules are configured by capcon0 and capcon1 sfr registers. input capture 0, 1 & 2 have their own edge detector but share with one timer i.e. timer 3. the input capt ure pins structure are schmitt tri gger. for this operation it basically consists of; ? 3 capture module function blocks. ? timer 3 block. each capture module block consists of 2 bytes of capture registers, noise filter and programmable edge triggers. noise filter is used to filter the unw anted glitch or pulse on the trigger input pin. the noise filter can be enabled through bit enfx (capcon1). if enabled, the capture logic required to sample 4 consecutive same capt ure input value in order to recognize an edge as a capture event. a possible implementation of digital noise filter is as follow; the interval between pulses requirement for input capture is 1 machine cycle width, which is t he same as the pulse width required to guarantee a trigger for all trigger edge mode. for less than 3 system clocks, anything less than 3 clocks will not have any trigger and pulse width of 3 or more but less than 4 clocks will trigger but will not guarantee 100% because input sampling is at stage c3 of the machine cycle. figure 15-1: noise filter
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 131 - revision a4.0 the trigger option is programmable through cctx [1:0] (capcon0). it supports positive edge, negative edge and both edge triggers. each capture m odule consists of an enable, icen0~2. [note: x=0, 1, 2 for capture 0, 1, 2 block]. capture blocks are triggered by external pins ic0, ic1 and ic2, respectively. if icenx is enabled, each time the external pin triggers, the content of the free running 16 bits counter, tl3 & th3 (from timer 3 block) will be captured/transferred into the corre sponding capture register s, cclx and cchx. this action also causes the corresponding cptfx flag bit in capcon1 to be set, and generate an interrupt (if enabled by ecptf bit in sfr, eie1.4). the cptf0-2 flags are logical ?or? to the interrupt module. input capture 0~2 share one interrupt named captur e interrupt. flag is set by hardware and cleared by software. setting the t3cr bit (t3mod.3), will allow hardware to reset timer 3 automatically after the value of tl3 and th3 have been captured. priority is given to t3cr to reset counter after capture the timer value into the capture register. when rl3 cmp/ = 0 (reload mode, with t3cr=0 and enld=1), rcap3 will be loaded into timer 3 counter upon overflow. while the rest of the condition of combination of setting for t3cr and enld will reset the counter to 0000h. /pjtf 'jmufs $15' $$- $$) $bquvsf#mpdl <> <> <> *$&/ *$ $$5<> &/' <> $bquvsf #mpdl $bquvsf #mpdl /puf
*$ *$ $15' $15' 8jui 4dinjuu 5sjhhfs 'ptd %*7cz     5- 5) 3$"1- 3$"1)     53 $$%*7<> $15' $15' $15' $$-%<> $.13- &/-% 5jnfs#mpdl    5' $.13- 5.' 5.' $.13- 507' 3ftfu 5jnfs 5$3 $15' $15' $15' note:tovf3 = timer 3 overflow tmf3 = internal timer 3 flag signal. input capture 2 block (refer to figure 15-3). figure 15-2: timer3/capture/compare/reload modules
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 132 - revision a4.0 figure 15-3: input capture 2 block diagram note: when qei enabled (qeien=1), input capture 2 (ic2) still can detect edge changes. . the following table shows the bits setting for enabling input capture 2 edge detection. qeien disidx icen2 input capture 2 edge detection 0 disabled. 0 x(don?t care) 1 enabled. 0 disabled. 1 0 1 enabled. 1 1 x disabled,
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 133 - revision a4.0 figure 15-4: timing diagram for input capture
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 134 - revision a4.0 figure 15-5: program flow for measurement with ic0 between pulses with falling edge detection (acc is incremented in interrupt service routine).
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 135 - revision a4.0 figure 15-6: program flow for measurement with ic0 between pul ses with rising edge detection (acc is incremented in interrupt service routine).
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 136 - revision a4.0 figure 15-7: program flow for measurement with ic0 pulse wi dth with rising and falling edge detection (acc is incremented in interrupt service routine).
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 137 - revision a4.0 figure 15-8: compare/reload function figure 15-9: input capture 0 triggers
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 138 - revision a4.0 15.1.1 compare mode timer 3 can be configured for compare mode. the compare mode is enabled by setting the rl3 cmp/ bit to 1 in the t3con register. rcap3 will serves as a compare register. as timer 3 counting up, upon matching with rcap3 value, tf3 will be set (which will generate an interrupt request if enable timer 3 interrupt et3 is enabled) and the timer reload from 0 and starts counting again. 15.1.2 reload mode timer 3 can be also be configured for reload mode. the reload mode is enabled by clearing the rl3 cmp/ bit to 0 in the t3con register. in this mode, rcap serves as a reload register. when timer 3 overflows, a reload is generated that causes t he contents of the rcap3l and rcap3h registers to be reloaded into the tl3 and th3 registers, if enld is set. tf3 flag is set, and interrupt request is generated if enable timer 3 interrupt et3 is enabled. however, if enld = 0, timer 3 will be reload with 0, and count up again. alternatively, other reload source is also possible by the input capture pins by configuring the ccld [1:0] bit. if the icenx bit is set, then a trigger of external ic0, ic1 or ic2 pin (respectively) will also cause a reload. this action also sets the cp tf0, cptf1 or cptf2 flag bit in sfr capcon1, respectively. 15.2 quadrature encoder interface (qei) the quadrature encoder interface (qei) decodes sp eed of rotation and motion sensor information. it can be used in any application that uses quadrature encoder for feedback. the qei block supports the features as below: z two qei phase inputs: qea and qeb. z 16-bit up/down pulse counter (plscnt) with 16-bit read access latched buffer (pcnt). z four pulse counter update modes: c ? mode0: x4 free-counting mode. c ? mode1: x2 free-counting mode. c ? mode2: x4 compare-counting mode. c ? mode3: x2 compare-counting mode. z three interrupt sources: c ? pulse counter interrupt (cptf0/qeif). c ? direction index of motion detection with direction interrupt (cptf1/dirf). c ? input capture 2 interrupt (cptf2). z the three 16-bit sfrs in qei share the same addresses with the capture counter registers. input capture mode qei mode capture0 counter register (cch0, ccl0) pulse read counter register (pcnth, pcntl) capture1 counter register (cch1, ccl1) pulse counter register (plscnth, plscntl) capture2 counter register (cch2, ccl2) maximum counter register (maxcnth, maxcntl)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 139 - revision a4.0 in qei mode, ic1 and ic0 work as qeb and qea inputs respectively. qea and qeb accept the outputs from a quadrature encoded source, such as incremental optical shaft encoder. two channels, a and b, nominally 90 degrees out of phase, are required. noise filter ic0/qea noise filter ic1/qeb qei control logic maxcnt/ capture 2 register plscnt/ capture 1 register pcnt/ capture 0 register read access to low byte of pcnt compare/reload control logic direction clock mode select bits noise filter ic2 figure 15-10: qei block diagram the qei control logic detects the relation of phase lead/lag between qea and qeb to produce direction index (dir) and clock to control pulse co unter. the comparator/reload logic compares the pulse counter and maximum count and control the function of reloading pulse counter in compare- counting mode. in free-counting mode, the pulse counter will counts until the 65535 value. in compare-counting mode, the pulse co unter will count to maxcnt value. the value of the pulse counter is not affected during qei mode changes, nor when the qei is disabled altogether. in qei mode, when ic2 edge (rising/falling edge is programmable through capcon0) has been detected, cptf2 will be set (if qeien=icen2=1 and di sidx=0), and the only way to clear it is by software.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 140 - revision a4.0 cha*/chb* - qea/b after going through noise filter. see figure 15-10 . figure 15-11: qea/qeb/ic2 timing requirement. 15.2.1 free-counting mode pulse counter up or down counts according to di rection index (dir). when overflow or underflow occurs, it sets flag qeif. 15.2.2 compare-counting mode pulse counter up or down counts according to dire ction index (dir). on up counting, qeif will be asserted when plscnt overflows from maxcnt to zero on the next qea edge for x2 counting mode, and on qea/qeb edge for x4 counting mode. on down counting, qeif will be asserted when plscnt underflows from zero to maxcnt on the next qea edge for x2 counting mode, and on qea/qeb edge for x4 counting mode . this mode provides the position of a rotor to user. if a quadrature encoder output 1024 pulses to qea per round, user can write maxcnt with 4095 in x4 mode or 2047 in x2 mode and reset plscnt at initial before rotor runs. when the plscnt reaches maxcnt, it means rotor runs one round on next qea edge. 15.2.3 x2/x4 counting modes in x2 counting mode , the pulse counter increases or decreases one on every qea edge based on the phase relationship of qea and qeb signals, however:- in x4 counting mode , the pulse counter increases or decreases one on every qea and qeb edge based on the phase relationship of qea and qeb signals. 15.2.4 direction of count if qea lead qeb, the pulse counter is increased by 1. if qea lags qeb, the pulse counter is decreased by 1. the qei control logi c generates a signal that sets the dir bit (qeicon.3); this in turn determines the direction of the count. when qea leads qeb, dir is set (= 1), and the position counter increments on every active edge. when qea lags qeb, dir is cleared, and the position counter decrements on every active edge . refer to below table.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 141 - revision a4.0 previous signal detected rising falling current signal detected qea qeb qea qeb counting control (dir) 9 inc (1) qea rising 9 dec (0) 9 dec (0) qea falling 9 inc (1) 9 inc (1) qeb rising 9 dec (0) 9 inc (1) qeb falling 9 dec (0) table 15-1: direction of count figure 15-12: x4 counting mode qei x4 counting mode provides for a finer resolution of the rotor position, since the counter increments or decrements more frequently for eac h qea/qeb input pulse pair than in qei x2 mode. this mode is selected by setting the qei mode select bi ts to ?00b? or ?10b?. in this mode, the qei logic detects every edge on every qea and qeb input edges.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 142 - revision a4.0 figure 15-13: x2 counting mode qei x2 counting mode is selected by setting the qe i mode select bits (qeim1:qeim0) to ?01b? or ?11b?. in this mode, the qei logic detects every edge on the qea input only. every rising and falling edge on the qea signal clocks the pulse counter. 15.2.5 up-counting under the forward direction the dir bit is 1 when up- counting. software needs to clear the qeif flag. for the free-counting mode counter will counts until it matches 65535 and next edges on the forward direction will set the qeif high and reset the plsc nt to zero. for compare-counting mode counter counts until the maxcnt value and reload the counter to zero and starts counting up. changes of direction trigger a down-count and plscnt decreasing in counter value. for x2 mode, only cha edge will set qeif while for x4 mode both cha and chb edges will set qeif. 15.2.6 down-counting a change of direction will causes the counter to do wn-count for x2/x4 counting mode. it is indicated with the dir bit as 0 and dirf flag is set to 1. at this stage the plscnt will starts to down-count from the maxcnt value for compare-counting mode and while in free-counting mode it will starts to down-count from 65535. the pulse counter will reload with maxcnt when it down counts to zero in compare-counting mode and sets qeif to high in the next edge. in free-counting mode the counter will count to 16 bits value before it reload the pu lse counter with the value 65535 and set the qeif high in the next edge. for x2 mode, only cha edge will set qeif while for x4 mode both cha and chb edges will set qeif.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 143 - revision a4.0 16. serial port the w79e22x series has two enhanced serial ports that are functionally similar to the serial port of the original 8052 family. both the serial port s are full-duplex ports, and the w79e22x series provides additional features, such as frame er ror detection and automatic address recognition. the serial port 0 can use timer 1 or 2 as baud rate generator, but the serial port 1 only uses timer 1 as baud rate generator. however, note that if both serial ports are enabled the baud rate setting control of uart1 is also from the setting of uart0. the serial ports are capable of synchronous and asynchronous communication. in synchronous mo de, the w79e22x series generates the clock and operates in half-duplex mode. in asynchronous mode, the serial ports can simultaneously transmit and receive data. the transmit regist ers and the receive buffers are both addressed as sbuf (sbuf1 for the second serial port), but any write to sbuf/sbu f1 writes to the transmit register while any read from sbuf/sbuf1 reads from the receive buffer. both serial ports can operate in four modes, as described below. the descriptions are for serial port 0, however, it also apply to the second serial port. 16.1 mode 0 this mode provides half-duplex, synchronous communi cation with external devices. in this mode, serial data is transmitted and received on the rx d line, and the w79e22x ser ies provides the shift clock on txd, whether the device is transmitting or re ceiving. eight bits are transmitted or received per frame, lsb first. the baud rate is 1/12 or 1/4 of the oscillator frequency, as determined by the sm2 bit (scon.5; 0 = 1/12; 1 = 1/4). this programmable b aud rate is the only difference between the standard 8051/52 and the w79e22x series in mode 0. any write to sbuf starts transmission. the shift cl ock is activated, and data is shifted out on rxd until all eight bits are transmitted. if sm2 is 1, t he data appears on rxd one clock period before the falling edge of the shift clock on txd. then, the clock remains low for two clock periods before going high again. if sm2 is 0, the data appears on rxd three clock periods before the falling edge of the shift clock on txd, and the clock on txd remains low for six clock periods before going high again. this ensures that, at the receiving end, the data on the rxd line can be cl ocked on the rising edge of the shift clock or latched when the clock is low. the ti flag is set high in c1 following the end of transmission. the functional block diagram is shown below.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 144 - revision a4.0 1/12 fosc 0 tx clock rx clock ti ri tx shift tx start rx shift load sbuf shift clock ri ren sm2 clock sin parout sbuf read sbuf internal data bus serial controllor clock load parin tx start internal data bus write to sbuf sout transmit shift register serial interrupt rxd txd rxd p3.0 alternate input function p3.0 alternate output function p3.1 alternate output function 1/4 1 receive shift register figure 16-1 serial port mode 0 the serial port receives data when ren is 1 and ri is zero. the shift clock (txd) is activated, and the serial port latches data on the rising edge of the sh ift clock. the external device should, therefore, present data on the falling edge of the shift clock. th is process continues until all eight bits have been received. the ri flag is set in c1 following the last rising edge of the shift clock, which stops reception until ri is cleared by the software. 16.2 mode 1 in mode 1, full-duplex asynchronous communication is used. frames consist of ten bits transmitted on txd and received on rxd. the ten bits consist of a star t bit (0), eight data bits (lsb first), and a stop bit (1). when receiving, the stop bit goes into rb8 in scon. the baud rate in this mode is 1/16 or 1/32 of the timer 1 overflow, and since timer 1 can be se t to a wide range of values, a wide variation of baud rates is possible. transmission begins with a write to sbuf but is synchronized with the divide-by-16 counter, not the write to sbuf. the start bit is put on txd at c1 fo llowing the first roll-over of the divide-by-16 counter, and the next bit is placed at c1 following the next rollo ver. after all eight bits are transmitted, the stop bit is transmitted. the ti flag is set in the next c1 state, or the tenth ro llover of the divide-by-16 counter after the write to sbuf. reception is enabled when ren is high, and the serial port starts receivin g data when it detects a falling edge on rxd. the falling-edge detector monito rs the rxd line at 16 times the selected baud rate. when a falling edge is detected, the divide-by-16 counter is reset to align the bit boundaries with the rollovers of the counter. the 16 states of the counter divide the bit time into 16 slices. bit detection is done on a best-of-three basis using samples at the 8th, 9th and 10th counter states. if the first bit after the falling edge is not 0, the start bit is inva lid, reception is aborted immediately, and the serial port resumes looking for a falling edge on rxd. if a valid start bit is detected, the rest of the bits are shifted into sbuf. after shifting in eight data bits, the stop bit is received. then, if; 1. ri is 0, and 2. sm2 is 0 or the received stop bit is 1,
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 145 - revision a4.0 the stop bit goes into rb8, the eight data bits go into sbuf, and ri is set. otherwise, the received frame is lost. in the middle of the stop bit, the receiver resumes looking for a falling edge on rxd. 1/2 1/16 tx clock rx clock ti ri tx shift tx start rx shift load sbuf smod clock sin d8 sbuf read sbuf internal data bus serial controllor clock load parin tx start internal data bus write to sbuf sout transmit shift register serial interrupt txd rxd parout rb8 start stop 0 1 bit detector 1-to-0 detector sample 1/16 0 timer 1 overflow 1 receive shift register 01 01 tclk rclk timer 2 overflow figure 16-2 serial port mode 1 16.3 mode 2 in mode 2, full-duplex asynchronous communication is used. frames consist of eleven bits: one start bit (0), eight data bits (lsb first), a programmabl e ninth bit (tb8) and a stop bit (0). when receiving, the ninth bit is put into rb8. the baud rate is 1/ 16 or 1/32 of the oscillator frequency, as determined by smod in pcon. transmission begins with a write to sbuf but is sy nchronized with the divide-by-16 counter, not the write to sbuf. the start bit is put on txd pin at c1 following the first roll-over of the divide-by-16 counter, and the next bit is placed on txd at c1 foll owing the next rollover. after all nine bits of data are transmitted, the stop bit is transmitted. the ti flag is set in the next c1 stat e, or the 11th rollover of the divide-by-16 counter after the write to sbuf. reception is enabled when ren is high, and the serial port starts receivin g data when it detects a falling edge on rxd. the falling-edge detector monito rs the rxd line at 16 times the selected baud rate. when a falling edge is detected, the divide-by-16 counter is reset to align the bit boundaries with the rollovers of the counter. the 16 states of the counter divide the bit time into 16 slices. bit detection is done on a best-of-three basis using samples at the 8th, 9th and 10th counter states. if the first bit after the falling edge is not 0, the start bit is invalid, reception is aborted, and the serial port resumes looking for a falling edge on rxd. if a valid start bit is detected, the rest of the bits are shifted into sbuf. after shifting in nine data bits, the stop bit is received. then, if; 1. ri is 0, and 2. sm2 is 0 or the received stop bit is 1, the stop bit goes into rb8, the eight data bits go into sbuf, and ri is set. otherwise, the received frame may be lost. in the middle of the stop bit, the receiver resumes looking for a falling edge on rxd. the functional description is shown in the figure below.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 146 - revision a4.0 1/2 1/16 tx clock rx clock ti ri tx shift tx start rx shift load sbuf smod clock sin d8 sbuf read sbuf internal data bus serial controllor clock load parin tx start internal data bus write to sbuf sout transmit shift register serial interrupt txd rxd parout rb8 start stop 0 1 bit detector 1-to-0 detector sample 1/16 0 fosc/2 1 d8 tb8 receive shift register figure 16-3 serial port mode 2 16.4 mode 3 this mode is the same as mode 2, except that the baud rate is programmable. the program must select the mode and baud rate in scon before any communication can take place. timer 1 should be initialized if mode 1 or mode 3 will be used.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 147 - revision a4.0 figure 16-4 serial port mode 3 sm0 sm1 mode type baud clock frame size start bit stop bit 9th bit function 0 0 0 synch. 4 or 12 osc 8 bits no no none 0 1 1 asynch. timer 1 or 2 10 bits 1 1 none 1 0 2 asynch. 32 or 64 osc 11 bits 1 1 0, 1 1 1 3 asynch. timer 1 or 2 11 bits 1 1 0, 1 table 16-1: serial ports modes 16.5 framing error detection a frame error occurs when a valid stop bit is not det ected. this could indicate incorrect serial data communication. typically, a frame error is due to noise or contention on the serial communication line. the w79e22x series has the ability to detect frami ng errors and set a flag that can be checked by software. the frame error fe (fe_1) bit is located in scon.7 . this bit is sm0 in the standard 8051/52 family, but, in the w79e22x series, it se rves a dual function and is called sm0/fe. there are actually two separate flags, sm0 and fe. the flag that is act ually accessed as scon.7 is determined by smod0 (pcon.6). when smod0 is set to 1, the fe flag is accessed. when smod0 is set to 0, the sm0 flag is accessed. the fe bit is set to 1 by the hardware, but it mu st be cleared by the software. once fe is set, any frames received afterwards, even those without erro rs, do not clear the fe flag. the flag has to be cleared by the software. note that smod0 mu st be set to 1 while reading or writing fe. 16.6 multiprocessor communications
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 148 - revision a4.0 multiprocessor communication is available in mode s 1, 2 and 3 and makes use of the 9th data bit and the automatic address recognition feat ure. this approach eliminates the software overhead required to check every received address and greatly simplifies the program. in modes 2 and 3, address bytes are distinguished fr om data bytes by 9th bit set, which is set high in address bytes. when the master proc essor wants to transmit a block of data to one of the slaves, it first sends the address of the target slave(s). the slave processors have already set their sm2 bits high so that they are only interrupted by an addre ss byte. the automatic address recognition feature then ensures that only the addressed slave is actually interrupted. th is feature compares the received byte to the slave?s given or broadcast address and only sets the ri flag if the bytes match. this slave then clears the sm2 bit, clearing the way to receiv e the data bytes. the unaddressed slaves are not affected, as they are still waiting for their address. in mode 1, the 9th bit is the stop bit, which is 1 in valid frames. therefore, if sm2 is 1, ri is only set if a valid frame is received and if the received byte matches the given or broadcast address. the master processor can selectively communicate wi th groups of slaves using the given address or all the slaves can be addressed together using the broadcast address. the addresses for each slave are defined by the saddr and saden registers. the slave address is the 8-bit value specified in saddr. saden is a mask for the value in sadd r. if a bit position in saden is 0, then the corresponding bit position in saddr is a don't-care condition in the address comparison. only those bit positions in saddr whose corresponding bits in saden are 1 are used to obtain the given address. this provides flexibility to address multip le slaves without changing addresses in saddr. the following example shows how to setup the given addresses to addr ess different slaves. slave 1: saddr 1010 0100 saden 1111 1010 given 1010 0x0x slave 2: saddr 1010 0111 saden 1111 1001 given 1010 0xx1 the given address for slaves 1 and 2 differ in the lsb. in slave 1, it is a don't-care, while, in slave 2, it is 1. thus, to communicate with only slave 1, the master must send an address with lsb = 0 (1010 0000). similarly, bit 1 is 0 for slave 1 and don't-care for slave 2. hence, to communicate only with slave 2, the master has to transmit an address wi th bit 1 = 1 (1010 0011). if the master wishes to communicate with both slaves simultaneously, t hen the address must have bit 0 = 1 and bit 1 = 0. since bit 3 is don't-care for both slaves, two di fferent addresses can address both slaves (1010 0001 and 1010 0101). the master can communicate with all the slaves simultaneously using the broadcast address. the broadcast address is formed from the logical or of the saddr and saden r egisters. the zeros in the result are don't?care values. in most cases, t he broadcast address is ffh. in the previous case, the broadcast address is (1111111x) for slave 1 and (11111111) for slave 2. the saddr and saden registers ar e located at addresses a9h and b9h, respectively. these two registers default to 00h, so the given address and broadcast address default to xxxx xxxx (i.e., all bits don't-care), which effectively removes the multiprocessor communications feature
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 149 - revision a4.0 17. i2c serial ports the i2c bus uses two wires (scl and sda) to transfer information between devices connected to the bus. the main features of the i2c bus are: ? bi-directional data transfer between masters and slaves. ? multi-master bus (no central master). ? arbitration between simultaneously transmitting master s without corruption of serial data on the bus. ? serial clock synchronization allows devices with different bit rates to communicate via one serial bus. ? serial clock synchronization can be used as a handshake mechanism to suspend and resume serial transfer. ? the i2c bus may be used for test and diagnostic purposes. t buf stop sda scl start t hd;sta t low t hd;dat t high t f t su;dat repeated start t su;sta t su;sto stop t r figure 17-1: i2c bus timing the device?s on-chip i2c logic provides the serial interface that meets the i2c bus standard mode specification. the i2c logic handles bytes transf er autonomously. it also keeps track of serial transfers, and a status register (i2statu s) reflects the status of the i2c bus. the i2c port, scl and sda are at p2.6 and p2.7. w hen the i/o pins are used as i2c port, user must set the pins to logic high in advance. when i2c po rt is enabled by setting ens to high, the internal states will be controlled by i2con and i2c logic ha rdware. once a new status code is generated and stored in i2status, the i2c interrupt flag (si) w ill be set automatically. if both ea and ei2c are also in logic high, the i2c interrupt is requested. the 5 mo st significant bits of i2st atus stores the internal state code, the lowest 3 bits are always zero a nd the content keeps stable until si is cleared by software. 17.1 sio port the sio port is a serial i/o port, which supports all transfer modes from and to the i2c bus. the sio port handles byte transfers autonomously. to enable this port, the bit ens1 in i2con should be set to '1'. the cpu interfaces to the sio port through t he seven special function registers. the detail description of these registers can be found in the i2c control registers se ction. the sio h/w interfaces to the i2c bus via two pins: sda (p2.7, serial data line) and scl (p2.6, serial clock line). pull up resistor is needed for pin p2.6 and p2.7 for i2c operation as these are 2 open drain pins. 17.2 the i2c control registers the i2c has 1 control register (i2con) to control th e transmit/receive flow, 1 data register (i2dat) to buffer the tx/rx data, 1 status register (i2status) to catch the state of tx/rx, recognizable slave address register for slave mode use and 1 clock rate control block for master mode to generate the variable baud rate.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 150 - revision a4.0 symbol definition address msb bit_address, symbol lsb reset i2timer i2c timer counter register efh - - - - - enti div4 tif xxxx x000b i2clk i2c clock rate eeh i2clk.7 i2clk.6 i2clk.5 i2clk.4 i2clk.3 i2clk.2 i2clk.1 i2clk.0 0000 0000b i2status i2c status register edh i2stat us.7 i2stat us.6 i2stat us.5 i2stat us.4 i2stat us.3 - - - 1111 1000b i2dat i2c data ech i2dat.7 i2dat.6 i2dat.5 i2dat.4 i2dat.3 i2dat.2 i2dat.1 i2dat.0 0000 0000b i2addr i2c slave address eah addr.7 addr.6 addr.5 addr.4 addr.3 addr.2 addr.1 gc 0000 0000b i2con i2c control register e9h - ens sta sto si aa i2cin - x000 000xb i2csaden i2c maskable slave address f6h i2csad en.7 i2csad en.6 i2csad en.5 i2csad en.4 i2csad en.3 i2csad en.2 i2csad en.1 i2csad en.0 1111 1110b table 17-1: control registers of i2c ports 17.2.1 slave address registers, i2addr i2c port is equipped with one slave address register. the contents of the register are irrelevant when i2c is in master mode. in the slave mode, the sev en most significant bits must be loaded with the mcu?s own slave address. the i2c hardware will re act if the contents of i2addr are matched with the received slave address. the i2c ports support the ?general call? function. if the gc bit is set the i2c port1 hardware will respond to general call address (00h). clear gc bit to disable general call function. when gc bit is set, the device is in slave mode which can receive the gene ral call address(00h) sent by master on the i2c bus. this special slave mode is referred to as gc mode. 17.2.2 data register, i2dat this register contains a byte of serial data to be transmitted or a byte which has just been received. the cpu can read from or write to this 8-bit directly addressable sfr while it is not in the process of shifting a byte. data in i2dat remains stable as long as si is set. the msb is shifted out first.while data is being shifted out, data on the bus is simultane ously being shifted in; i2dat always contains the last data byte present on the bus. thus, in the event of arbitration lost, the transition from master transmitter to slave receiver is made with the correct data in i2dat. i2dat and the acknowledge bit form a 9-bit shift register which shifts in or out an 8-bit byte, followed by an acknowledge bit. the acknowledge bit is cont rolled by the hardware an d cannot be accessed by the cpu. serial data is shifted into i2dat on the ri sing edges of serial clock pulses on the scl line. when a byte has been shifted into i2dat, the seri al data is available in i2dat, and the acknowledge bit (ack or nack) is returned by the control logic during the ninth clock pulse. serial data is shifted out from i2dat on the falling edges of scl clock pu lses, and is shifted into i2dat on the rising edges of scl clock pulses. i2dat.7 i2dat.6 i2dat.5 i2dat.4 i2dat.3 i2dat.2 i2dat.1 i2dat.0 i2c data register: shifting direction figure 17-2: i2c data shift 17.2.3 control register, i2con the cpu can read from and write to this 8-bit, directly addressable sfr . two bits are affected by hardware: the si bit is set when the i2c hardware requests a serial interrupt, and the sto bit is cleared when a stop condition is present on the bu s. the sto bit is also cleared when ens = "0".
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 151 - revision a4.0 ens i2c serial function block enable bit. when ens=1 the i2c serial function enables. the port latches of sda1 and scl1 must be set to logic high. sta i2c start flag. setting sta to logic 1 to enter master mode, the i2c hardware sends a start or repeat start condition to bus when the bus is free. sto i2c stop flag. in master mode, setting sto to transmit a stop condition to bus then i2c hardware will check the bus condition if a stop condition is detected this flag will be cleared by hardware automatically. in a slave mode, setting sto resets i2c hardware to the ?not addressed slave mode?. si i2c port 1 interrupt flag. when a new sio st ate is present in the s1sta register, the si flag is set by hardware, and if the ea and ei2c1 bits are both set, the i2c1 interrupt is requested. si must be cleared by software. aa assert acknowledge control bit. when aa= 1 prior to address or data received, an acknowledged (low level to sda) will be returned during the acknowledge clock pulse on the scl line when; 1.) a slave is acknowle dging the address sent from master, 2.) the receiver devices are acknowledging the data s ent by transmitter. when aa=0 prior to address or data received, a not acknowledged (high level to sda) will be returned during the acknowledge clock pulse on the scl line. i2cin by default it is zero and input are allows to come in through sda pin. as when it is 1 input is disallow and to prevent leakage current. during power-down mode input is disallow. 17.2.4 status register, i2status i2status is an 8-bit read-only register. the three l east significant bits are always 0. the five most significant bits contain the status code. there are 23 possi ble status codes. when i2status contains f8h, no serial interrupt is requested. all other i2status values correspond to defined i2c ports states. when each of these states is entered, a stat us interrupt is requested (si = 1). a valid status code is present in i2status one machine cycle a fter si is set by hardware and is still present one machine cycle after si has been reset by software. in addition, state 00h stands for a bus error. a bus error occurs when a start or stop condition is present at an illegal position in the format frame. examples of illegal positions are during the serial transfer of an address byte, a data byte or an acknowledge bit. 17.2.5 i2c clock baud rate control, i2clk the data baud rate of i2c is determines by i2clk regi ster when i2c port is in a master mode. it is not important when i2c port is in a slave mode. in t he slave modes, sio will automatically synchronize with any clock frequency up to 400 khz from master i2c device. the data baud rate of i2c setting conforms to the following equation. data baud rate of i2c = f cpu / (i2clk + 1), where f cpu = f osc /4. for example, if f osc =16mhz, the i2clk=40(28h), the data baud rate of i2c = (16mhz/4)/(40+1) = 97.56k bits/sec. 17.2.6 i2c time-out counter, i2timer in w79e22x series, the i2c logic block provides a 14-bit timer-out counter that helps user to deal with bus pending problem. when si is cleared user ca n set enti=1 to start the time-out counter. if i2c bus is pended too long to get any valid signal fr om devices on bus, the time-out counter overflows cause tif=1 to request an i2c interrupt. the i2c inte rrupt is requested in the condition of either si=1 or tif=1. flags si and tif must be cleared by software.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 152 - revision a4.0 17.2.7 i2c maskable slave address this register enables the automatic address rec ognition feature of the i2c. when a bit in the i2csaden is set to 1, the same bit location in i2csaddr1 will be compared with the incoming serial port data. when i2csaden.n is 0, then the bit becomes a don't-care in the comparison. this register enables the automatic address recognition feature of the i2c. when all the bits of i2csaden are 0, interrupt will occur for any incoming address. 1 0 fosc 1/4 14-bits counter tif clear counter enti si div4 ens1 to i2c interrupt enable si figure 17-3: i2c time-out block diagram 17.3 modes of operation the on-chip i2c ports support five operation modes , master transmitter, master receiver, slave transmitter, slave receiver, and gc cal l . in a given application, i2c port may operate as a master or as a slave. in the slave mode, the i2c port hardware looks for its own slave address and the gener al call address. if one of these addresses is detected, and if the slave is willin g to receive or transmit data fr om/to master(by setting the aa bit), acknowledge pulse will be transmitted out on the 9 th clock, hence an interrupt is requested on both master and slave devices if interrupt is enabled. wh en the microcontroller wishes to become the bus master, the hardware waits until the bus is free befor e the master mode is entered so that a possible slave action is not interrupted. if bus arbitration is lo st in the master mode, i2c port switches to the slave mode immediately and can detect its own slave address in the same serial transfer. 17.3.1 master transmitter mode serial data output through sda while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the data direction bit. in this case the data direction bit (r/w) will be logic 0, and we say that a ?w? is transmitted. thus the first byte transmitted is sla+w. serial data is transmitted 8 bits at a time. after each byte is transmitted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. 17.3.2 master receiver mode in this case the data direction bit (r/w) will be logi c 1, and we say that an ?r? is transmitted. thus the first byte transmitted is sla+r. serial data is re ceived via sda while scl outputs the serial clock. serial data is received 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. start and stop conditions are output to indicate the beginning and end of a serial transfer.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 153 - revision a4.0 17.3.3 slave receiver mode serial data and the serial clock are received thr ough sda and scl. after each byte is received, an acknowledge bit is transmitted. start and stop conditions are recognized as the beginning and end of a serial transfer. address recognition is pe rformed by hardware after reception of the slave address and direction bit. 17.3.4 slave transmitter mode the first byte is received and handled as in the sl ave receiver mode. however, in this mode, the direction bit will indicate that the transfer direction is reversed. serial data is transmitted via sda while the serial clock is input through scl. start an d stop conditions are recognized as the beginning and end of a serial transfer. 17.4 data transfer flow in five operating modes the five operating modes are: master/transmi tter, master/receiver, slave/transmitter, slave/receiver and gc call. bits sta, sto and aa in i2con register will det ermine the next state of the sio hardware after si flag is cleared. upon comp lexion of the new action, a new status code will be updated and the si flag will be set. if the i2c in terrupt control bits (ea and ei2) are enabled, appropriate action or software branch of the new st atus code can be performed in the interrupt service routine. data transfers in each mode are shown in the following figures. figure 17-4: legend for i2c flow charts
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 154 - revision a4.0 17.4.1 master/transmitter mode
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 155 - revision a4.0 17.4.2 figure 17-5: master transm itter modemaster/receiver mode figure 17-6: master receiver mode
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 156 - revision a4.0 17.4.3 slave/transmitter mode figure 17-7: slave transmitter mode
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 157 - revision a4.0 17.4.4 slave/receiver mode figure 17-8: slave receiver mode
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 158 - revision a4.0 17.4.5 gc mode figure 17-9: general call address
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 159 - revision a4.0 18. serial peripheral interface (spi) 18.1 general descriptions this device consists of spi block to support high speed serial communication. it?s capable of supporting data transfer rates 5mbit/s. this device?s spi support the following features; ? master and slave mode. ? slave select output. ? programmable serial clock?s polarity and phase. ? receive double buffered data register. ? lsb first enable. ? write collision detection. ? transfer complete interrupt. 18.2 block descriptions the figure 18-1 shows spi block diagram. it prov ides an overview of spi archit ecture in this device. the main blocks of spi are the register blocks, cont rol logics, baud rate control and pin control logics; a. shift register and read data buffer. it is si ngle buffered in the transmit direction and double buffered in the receive direction. transmit data cannot be written to the shifter until the previous transfer is complete. receive logics consist of parallel read data buffer so the shifter is free to accept a second data, as the firs t received data will be transferred to the read data buffer. b. spi control block. this provide control f unctions to configure the device for spi enable, master or slave, clock phase and polarity, lsb access first selection, and slave select output enable. c. baud rate control. these control logics divide cp u clock to 4 different selectable clocks 1/8, 1/32, 1/128 and 1/2/256. its? selection is controllable through spr [1:0] bits. spr1 spr0 divider baud rate 0 0 8 5mhz 0 1 32 1.25mhz 1 0 128 312.50khz 1 1 256 156.25khz table 18-1 spi baud rate selection (f osc @ 40mhz) d. spi registers. there are three spi regi sters to support its operations, they are; ? spi control registers (spcr) ? spi status registers (spsr) ? spi data register (spdr) these registers provide control, status, data storage functions and baud rate selection control. detail bits descriptions are found at sfr sectio n. when using spi pull-up must be apply at bit pup0 = 1. e. pin control logic. controls behavior of spi interface pins.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 160 - revision a4.0 figure 18-1: spi block diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 161 - revision a4.0 18.3 functional descriptions 18.3.1 master mode the device can configure the spi to operate as a master or as a slave, through mstr bit. when the mstr bit is set, master mode is selected, when mstr bit is cleared, slave mode is selected. during master mode, only master spi device can initiate tran smission. a transmission begins by writing to the master spdr register. the bytes begin shifting out on mosi pin under the control of spclk. the master places data on mosi line a half-cycle before spclk edge that the slave device uses to latch the data bit. the ss must stay low before data transactions and stay low for the duration of the transactions. figure 18-2: master mode transmission (cpol = 0, cpha = 0)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 162 - revision a4.0 spclk cycles spclk (output, cpol=1) mosi/miso /ss (output to slave) spif master writes to spdr: 1. /ss asserted. 2. during master transmit, data is shifting out through mosi. during master receive, data is shifting in through miso. 3. spif asserted at the end of transmission. 4. /ss negated. note: when cpha = 0, /ss output must go high between successive spi characters. when cpol = 1, spclk idle high. 1 2 3 4 5 6 7 8 msb 6 5 4 3 2 1 lsb 1 2 3 4 master transfer in progress figure 18-3: master mode transmission (cpol = 1, cpha = 0)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 163 - revision a4.0 figure 18-4: master mode transmission (cpol = 0, cpha = 1)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 164 - revision a4.0 figure 18-5: master mode transmission (cpol = 1, cpha = 1) 18.3.2 slave mode when in slave mode, the spclk pin becomes input and it will be clock by another master spi device. the ss pin also becomes input. similarly, before data transmissions occurs, and remain low until the transmission completed. if ss goes high, the spi is forced into idle state. if the ss is forced to high at the middle of transmission, the transmission will be aborted and the receiving shifter buffer will be high and goes into idle states. data flows from master to slave on mosi pin and fl ows from slave to master on miso pin. the spdr is used when transmitting or receiving data on the se rial bus. only a write to this register initiates transmission or reception of a byte, and this only oc curs in the master device. at the completion of transferring a byte of data, the spif status bit is set in both the master and slave devices. a read of the spdr is actually a read of a buffer. to prevent an overrun and the loss of the byte that caused the overrun, the first spif must be cleared by the time a second transfer of data from the shift register to the read buffer is initiated.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 165 - revision a4.0 figure 18-6: slave mode transmission (cpol = 0, cpha = 0)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 166 - revision a4.0 figure 18-7: slave mode transmission (cpol = 1, cpha = 0)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 167 - revision a4.0 figure 18-8: slave mode transmission (cpol = 0, cpha = 1)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 168 - revision a4.0 figure 18-9: slave mode transmission (cpol = 1, cpha = 1) 18.3.3 slave select the slave select ( ss ) input of a slave device must be externally asserted before a master device can exchange data with the slave device. ss must be low before data transactions and must stay low for the duration of the transaction. the ss line of the master must be held high. the other three lines are dedicated to the spi whenever the serial peripheral interface is on. the state of the master and slave cpha bits affects the operation of ss . cpha settings should be identical for master and slave. when cpha = 0, the shift clock is the or of ss with spclk. in this clock phase mode, ss must go high between successive characters in an spi message. when cpha = 1, ss can be left low between successive spi characters. in cases where there is only one spi slave mcu, its ss line can be tied to vss as long as only cpha = 1 clock mode is used. 18.3.4 /ss output available in master mode only, ss output is enabled with the ssoe bit in the spcr register and drss bit in the spsr register. the ss output pin is connected to the ss input pin of the slave device. the ss output automatically goes low for each trans mission when selecting external device and it goes high during each idling state to deselect external devices.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 169 - revision a4.0 drss ssoe master mode slave mode 0 0 ss input ( with mode fault ) ss input ( not affected by ssoe ) 0 1 reserved ss input ( not affected by ssoe ) 1 0 ss general purpose i/o ( no mode fault ) ss input ( not affected by ssoe ) 1 1 ss output ( no mode fault ) ss input ( not affected by ssoe ) during master mode (with ssoe=drss= 0), mode fault will be set if ss pin is detected low. when mode fault is detected hardware w ill clear mstr bit and spe bit in the meantime it will also generated interrupt request, if espi is enabled. figure 18-10: spi interrupt request 18.3.5 spi i/o pins mode when spi is disabled (spe = 0) the corresponding i/o is following the original setting and act as a normal i/o. in the case of spi is enabled (spe = 1) the spi pins i/o mode follow the below table. for ss pin it is always at quasi-bidirectional mode w hether it is configured as master or slave. miso mosi clk /ss master input output output output *: drss=0,ssoe=0 input: drss=1, ssoe=1 slave output ** during /ss = low else input mode input input input input = quasi-bidirectional mode output = push-pull mode output* = this output mode in /ss is quasi-bidi rectional output mode. master needs to detect mode fault during master outputs /ss low. output** = in slave mode, miso is in output mode only during the time of ss =low, otherwise it must keep in i nput mode (quasi-bidirectional).
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 170 - revision a4.0 18.3.6 programmable serial clock?s phase and polarity the clock polarity cpol control bit selects acti ve high or active low spclk clock, and has no significant effect on the transfer format. the clock phase cpha control bit selects one of two different transfer protocols by sampling data on odd numbered spclk edges or on even numbered spclk edges. thus, both these bits enable selection of four possible clock formats to be used by spi system. the clock phase and polarity should be identical for the master spi device and the communicating slave device. when cpha equals 0, the ss line must be negated and reasserted between each successive serial byte. also, if the slave writes data to the spi data register (spdr) while ss is low, a write collision error results. when cpha equals 1, the ss line can remain low between successive transfers. the figures from figure 18-2 to
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 171 - revision a4.0 figure 18-9 show the spi transfer format, with different cpol and cpha. when cpha = 0, data is sample on the first edge of spclk and when cpha = 1 data is sample on the second edge of the spclk. prior to changing cpol setting, spe must be disabled first. 18.3.7 receive double buffered data register this device is single buffered in the transmit dire ction and double buffered in the receive direction. this means that new data for transmission cannot be wr itten to the shifter until the previous transfer is complete; however, received data is transferred into a parallel read data buffer so the shifter is free to accept a second serial byte. as long as the first byte is read out of the read data buffer before the next byte is ready to be transferred, no overrun condition occurs. if overrun occur, spiovf is set. second byte serial data cannot be transferred successfully into the data regi ster during overrun condition and the data register will remains the value of the prev ious byte. the figure below shows the receive data timing waveform when overrun occur.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 172 - revision a4.0 figure 18-11: spi overrun timing waveform 18.3.8 lsb first enable by default, this device transfer the spi data most significant bit first. this device provides a control bit spcr.lsbfe to allow support of transfer of spi data in least significant bit first. 18.3.9 write collision detection write collision indicates that an attempt was made to write data to the spdr wh ile a transfer was in progress. spdr is not double buffered in the transmit direction, any writes to spdr cause data to be written directly into the spi shift register. this wr ite corrupts any transfer in progress, a write collision error is generated (wcol will be set). the transfer continues undisturbed, and the write data that caused the error is not written to the shifter. a wr ite collision is normally a slave error be cause a slave has no control over when a master initiates a transfer . a master knows when a transfer is in progress, so there is no reason for a master to generate a wr ite-collision error, although the spi logic can detect write collisions in both master and slave dev ices. wcol flag is clear by software. 18.3.10 transfer complete interrupt this device consists of an interrupt flag at spif. this flag will be set upon completion of data transfer with external device, or when a new data have bee n received and copied to spdr. if interrupt is enable (through espi), the spi interrupt request wi ll be generated, if global enable bit ea is also enabled. spif is software clear. 18.3.11 mode fault error arises in a multiple-master system when mo re than one spi device simultaneously tries to be a master. this error is called a mode fault. when the spi system is configured as a master and the /ss input line goes to active low, a mode fault error has occurred ? usually because two devices have attempted to act as master at the same time. in cases where more than one device is concurrently configured as a master, there is a chance of contention between two pin drivers. for push-pull cmos drivers, this contention can cause permanent
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 173 - revision a4.0 damage. the mode fault mechanism attempts to prot ect the device by disabling the drivers. the mstr and spe control bits in the spcr associat ed with the spi are cleared by hardware and an interrupt is generated subject to masking by the espi control bit. other precautions may need to be taken to prevent dr iver damage. if two devices are made masters at the same time, mode fault does not help protect eith er one unless one of them selects the other as slave. the amount of damage possible depends on the length of time both devices attempt to act as master. modf bit is set automatically by spi hardware, if the mstr control bit is set and the slave select input pin becomes 0. this condition is not permitted in norma l operation. in the case where /ss is set, it is an output pin rather than being dedicated as the /ss i nput for the spi system. in this special case, the mode fault function is inhibited and modf remains cleared. this flag is cleared by software. the following shows the sample hardware connection and s/w flow for multi-master/slave environment. it shows how s/w handles mode fault. figure 18-12: spi multi-master slave environment
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 174 - revision a4.0 figure 18-13: spi multi-master slave s/w flow diagram
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 175 - revision a4.0 19. analog-to-digital converter the adc contains a digital-to-analog converter (dac ) that converts the co ntents of a successive approximation register to a voltage (v dac ), which is compared to the analog input voltage (vin). the output of the comparator is then fed back to the su ccessive approximation control logic that controls the successive approximati on register. this is illustrated in the figure below. figure 19-1: successive approximation adc 19.1 operation of adc a conversion can be initiated by software only or by either hardware or so ftware. the software only start mode is selected when control bit adccon.5 (adcex) =0. a conversion is then started by setting control bit adccon.3 (adcs) to 1. the hardware or software start mode is selected when adccon.5 =1, and a conversion may be started by setting adccon.3 = 1 as above or by applying a rising edge to external pin stadc (p4.0). when a conversion is started by applying a rising edge, a low level must be applied to stadc for at least one machine cycle followed by a high level for at least one machine cycle. user sets adcs to start conver ting then adcs remains high while adc is converting signal and will be automatically cleared by hardware when adc conv ersion is completed. the end of the 10-bit conversion is flagged by control bit adccon.4 (adci). the upper 8 bits of the result are held in special function register adch, and the two remaini ng bits are held in adcl.1 (adc.1) and adcl.0 (adc.0). the user may ignore the two least signifi cant bits in adcl and use the adc as an 8-bit converter (8 upper bits in adch). in any event, the total actual conversion time is 50 adc clock input cycles. control bits from adccon.0 to adccon.2 are us ed to control an analog multiplexer which selects one of eight analog channels. an a dc conversion in progress is unaffe cted by an external or software adc start. the result of a completed conversion remains unaffected provided adci = logic 1. the result of a completed conversion (adci = logic 1) remains unaffected when entering the idle mode. the device supports maximum 8 analog input ports. 8 analog input ports share the i/o pins from p1.0 to p1.7. these i/o pins are switched to analog input ports by setting the bits of adc input pin select register (ddio) to logic 1.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 176 - revision a4.0 figure 19-2: adc block diagram 19.2 adc resolution and analog supply the adc circuit has its own supply pins (av dd and av ss ) and one pins (vref+) connected to each end of the dac?s resistance-ladder that the av dd and vref+ are connected to v dd and av ss is connected to v ss . the ladder has 1023 equally spaced taps, separat ed by a resistance of ?r?. the first tap is located 0.5 r above av ss , and the last tap is located 0.5 r below vref+. this gives a total ladder resistance of 1024 r. this structure ensures that the dac is monotonic and results in a symmetrical quantization error. for input voltages between av ss and [(vref+) + ? lsb], the 10-bit result of an a/d conversion will be 0000000000b = 000h. for input voltages between [(vr ef+) ? 3/2 lsb] and vref+, the result of a conversion will be 1111111111b = 3ffh. avref+ and av ss may be between av dd + 0.2v and av ss ? 0.2 v. avref+ should be positive with respect to av ss , and the input voltage (vin) should be between avref+ and av ss . the result can always be calculated from the following formula: result = avref vin 1024 + or result = v ss v dd 1024
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 177 - revision a4.0 20. timed access protection the w79e22x series has features like the watc hdog timer, wait-state control signal and power- on/fail reset flag that are crucial to the proper operation of the system . if these features are unprotected, errant code may write cr itical control bits, resulting in incorrect operation and loss of control. to prevent this, the w79e22x series prov ides has a timed-access protection scheme that controls write access to critical bits. in this scheme, protected bits have a timed write- enable window. a write is successful only if this window is active; otherwise, the write is discarde d. the write-enable window is opened in two steps. first, the software writes aah to the timed access (t a) register. this starts a counter, which expires in three machine cycles. then, if the software writes 55h to the ta register bef ore the counter expires, the write-enable window is opened for three machine cycles. after three machine cycles, the window automatically closes, and the procedure must be repeated again to access protected bits. the suggested code for opening the write-enable window is; ta reg 0c7h ; define new register ta, located at 0c7h mov ta, #0aah mov ta, #055h five examples, some correct and some incorrect, of using timed-access protection are shown below. example 1: valid access mov ta, #0aah ; 3 m/c ; note: m/c = machine cycles mov ta, #055h ; 3 m/c mov wdcon, #00h ; 3 m/c example 2: valid access mov ta, #0aah ; 3 m/c mov ta, #055h ; 3 m/c nop ; 1 m/c setb ewt ; 2 m/c example 3: valid access mov ta, #0aah ; 3 m/c mov ta, #055h ; 3 m/c orl wdcon, #00000010b ; 3m/c example 4: invalid access mov ta, #0aah ; 3 m/c mov ta, #055h ; 3 m/c nop ; 1 m/c nop ; 1 m/c clr por ; 2 m/c
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 178 - revision a4.0 example 5: invalid access mov ta, #0aah 3 m/c nop 1 m/c mov ta, #055h 3 m/c setb ewt 2 m/c in the first three examples, the protected bits ar e written before the window closes. in example 4, however, the write occurs after the window has clos ed, so there is no change in the protected bit. in example 5, the second write to ta occurs four machin e cycles after the first write, so the timed access window in not opened at all, and the write to the protected bit fails.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 179 - revision a4.0 21. port 4 structure port 4 is a multi-function port that performs general purpose i/o port and chip-select strobe signals including read strobe, write strobe and read/write strobe signals. the 4 alternate modes are selected by p4xm1 and p4xm0. the function of chip-select st robe output provides that user can activate external devices by access to some specific address region. port 4 control register a bit: 7 6 5 4 3 2 1 0 p41m1 p41m0 p41c1 p41c0 p40m1 p40m0 p40c1 p40c0 mnemonic: p4cona address: 92h port 4 control register b bit: 7 6 5 4 3 2 1 0 p43m1 p43m0 p43c1 p43c0 p42m1 p42m0 p42c1 p42c0 mnemonic: p4conb address: 93h bit name function p4xm1, p4xm0 port 4 alternate modes. =00: mode 0. p4.x is a general purpose i/o port which is the same as port 1. =01: mode 1. p4.x is a read strobe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xc1, p4xc0. =10: mode 2. p4.x is a write strobe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xc1, p4xc0. =11: mode 3. p4.x is a read/write strobe signal for chip select purpose. the address range depends on the sfr p4xah, p4xal and bits p4xc1, p4xc0 p4xc1, p4xc0 port 4 chip-select mode address comparison: =00: compare the full address (16 bits length) with the base address registers p4xah and p4xal. =01: compare the 15 high bits (a15- a 1) of address bus with the base address registers p4xah and p4xal. =10: compare the 14 high bits (a15-a2) of address bus with the base address registers p4xah and p4xal. =11: compare the 8 high bits (a15- a 8) of address bus with the base address registers p4xah and p4xal. p40ah, p40al: the base address registers for comparator of p4.0 . p40ah contains the high-order byte of address; p40al contains the low-order byte of address. p41ah, p41al: the base address registers for comparator of p4.1 . p41ah contains the high-order byte of address; p41al contains the low-order byte of address. p42ah, p42al: the base address registers for comparator of p4.2 . p42ah contains the high-order byte of address; p42al contains the low-order byte of address.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 180 - revision a4.0 p43ah, p43al: the base address registers for comparator of p4.3 . p43ah contains the high-order byte of address; p43al contains the low-order byte of address. port 4 bit: 7 6 5 4 3 2 1 0 - - - - p4.3 p4.2 p4.1 p4.0 mnemonic: p4 address: a5h p4.3-0 port 4 is a bi-directional i/o port with internal pull-ups. port 4 chip-select polarity bit: 7 6 5 4 3 2 1 0 p43inv p42inv p42inv p40inv - pwdnh rmwfp pup0 mnemonic: p4csin address: a2h p4xinv the active polarity of p4.x when it is set as a chip-select strobe output. high = active high. low = active low. pwdnh set pwdnh to logic 1 then ale and psen will keep high state, clear this bit to logic 0 then ale and psen will output low during power down mode. rmwfp control read path of instruction ?read- modify-write?. when this bit is set, the read path of executing ?read-modify-write? instru ction is from port pin otherwise from sfr. pup0 enable port 0 weak pull up.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 181 - revision a4.0 address bus bit length selectable comparator register p4xal p4xah equal p4.x mux 4->1 p4 register p4.x read write data i/o rd_cs wr_cs rd/wr_cs p4xc0 p4xc1 p4xm0 p4xm1 p4xcsinv p4.x input data bus register pin figure 21-1 port 4 structure diagram here is an example to program the p4.0 as a write strobe signal at the i/o port address 1234h ~1237h and positive polarity, and p4.1 ~ p4.3 are used as general i/o ports. mov p40ah, #12h mov p40al, #34h ;define the base i/o address 1234h for p4.0 as an special function mov p4cona, #00001010b ;define the p4.0 as a write strobe signal pin and the compared address is [a15:a2] mov p4conb, #00h ;p4.1~p4.3 as general i/o port which are the same as port1 mov p4csin, #10h ;write the p40csinv =1 to inverse the p4.0 write strobe polarity then any instruction writes data to address from 1234h to 1237h, for example movx @dptr,a (with dptr=1234h~1237h), will generat e the positive polarity write str obe signal at pin p4.0. and the instruction of ?mov p4, #xx? will output the bi t3 to bit1 of data #xx to pin p4.3~ p4.1. note: p4.2 and p4.3 pins are available in 48l lqfp package only.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 182 - revision a4.0 22. in-system programming 22.1 the loader program locates at ldflash memory cpu is free run at apflash memory. chpcon re gister had been set #03h value before cpu has entered idle state. cpu will switch to ldflash memory and execute a reset action. h/w reboot mode will switch to ldflash memory, too. set sfrcn regist er where it locates at us er's loader program to update apflash bank 0 memory. set a swreset (c hpcon=#83h) to switch back apflash after cpu has updated apflash progra m. cpu will restart to run program from reset state. 22.2 the loader program locates at apflash memory cpu is free run at apflash memory. chpcon re gister had been set #01h value before cpu has entered idle state. set sfrcn register to update ld flash or another bank of apflash program. cpu will continue to run user's apflash program afte r cpu has updated prog ram. please refer demonstrative code to understand other detail description.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 183 - revision a4.0 23. option bits this device has two config bits (config0, config 1) that must be define at power up and can not be set after the program start of execution. those f eatures are configured through the use of two flash eprom bytes, and the flash eprom can be progra mmed and verified repeatedly. until the code inside the flash eprom is confirmed ok, the code can be protected. the pr otection of flash eprom and those operations of the configuration bits are described below. 23.1 config0 bit description b0 =0: lock data out b1 =0: movc inhibited b2 =0; 1/2/2 k data flash eprom lock bit b3 reserved b4 =1: disable h/w reboot by p3.6 and p3.7 =0: enable h/w reboot by p3.6 and p3.7 b5 =1: disable h/w reboot by p4.3 =0: enable h/w reboot by p4.3 note: support in 48l lqfp package only. b6 reserved b7 =1: crystal > 24mhz =0: crystal < 24mhz table 23-1 config0 option bits b0: lock bit this bit is used to protect the customer's program code in the w79e22x series. after the programmer finishes the programming and verifies sequence b0 can be cleared to logic 0 to protect code from reading by any access path. once this bi t is set to logic 0, both the flash eprom data and special setting registers can not be accessed again. b1: movc inhibit this bit is used to restrict the accessible region of the movc instruction. it can prevent the movc instruction in external program memory from reading the internal program code. when this bit is set to logic 0, a movc instructio n in external program memory space w ill be able to access code only in the external memory, not in the internal memory. a mo vc instruction in internal program memory space will always be able to access the rom data in both in ternal and external memory. if this bit is logic 1, there are no restrictions on the movc instruction. b4: h/w reboot with p3.6 and p3.7 if this bit is set to logic 0, enable to reboot 4k ld flash mode while rst =h, p3.6 = l and p3.7 = l state. cpu will start from ld flas h to update the user?s program. b5: h/w reboot with p4.3 if this bit is set to logic 0, enable to reboot 4k ld flash mode while rst =h and p4.3 = l state. cpu will start from ld flash to update the user?s program
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 184 - revision a4.0 b7: select clock frequency. if clock frequency is over 24mhz, then set this bit is h. if clock frequency is less than 24mhz, then clear this bit. 23.2 config1 bits name function bit 0 pwmoe pwm odd channel 1, 3 and 5 enable. 1: disable (default). 0: enable odd pwm outputs to corresponding pins. bit 1 pwmee pwm even channel 0, 2 and 4 enable. 1: disable (default) 0: enable odd pwm outputs to corresponding pins. bit 2 opol define the polarity of pwm output after cpu reset, opol controls odd pwm outputs. 1: initial output high 0: initial output low bit 3 epol define the polarity of pwm output after cpu reset, epol control even pwm outputs. 1: initial output high 0: initial output low bit 4-5 - reserved. bit 6 pwm6e pwm channel 6 output enable. 1: disable (default). 0: enable pwm6 output to corresponding pin. bit 7 pwm7e pwm channel 7 output enable. 1: disable (default). 0: enable pwm7 output to corresponding pin. table 23-2: config 1 option bits
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 185 - revision a4.0 24. electrical characteristics 24.1 absolute maximum ratings symbol parameter condition rating unit dc power supply v dd ? v ss -0.3 +7.0 v input voltage v in v ss -0.3 v dd +0.3 v operating temperature t a -40 +85 c storage temperature t st -55 +150 c note: exposure to conditions beyond t hose listed under absolute maximum ratings ma y adversely affect the life and reliability of the device. 24.2 dc characteristics (vdd ? vss = 5v 10%, ta = 25 c, fosc = 20 mhz, unless otherwise specified.) specification parameter symbol min typ max unit test conditions v dd1 4.5 5.5 v dd =4.5v ~ 5.5v @ 40mhz v dd2 2.7 5.5 v dd =2.7v ~ 5.5v @ 20mhz v dd3 4.5 5.5 v dd =4.5v ~ 5.5v @ 24mhz (external access) operating voltage v dd4 3.0 v nvm program/erase operation. run nop i dd1 - 58 65 ma v dd =5.5v at 40mhz run nop i dd2 - 37 45 ma v dd =5.5v at 20mhz run nop i dd3 - 15 20 ma v dd =3.0v at 20mhz run nop i dd4 - 12 16 ma v dd =2.7v at 20mhz rst = vdd i dd5 - 50 60 ma v dd =5.5v at 40mhz rst = vdd i dd6 - 33 38 ma v dd =5.5v at 20mhz rst = vdd i dd7 - 12 17 ma v dd =3.0v at 20mhz rst = vdd operating current i dd8 - 10 15 ma v dd =2.7v at 20mhz
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 186 - revision a4.0 dc characteristics, continued specification parameter symbol min typ max unit test conditions 35 42 ma v dd =5.5v at 40mhz (i/o high) i idle1 v dd =5.5v at 40mhz (i/o low) ma v dd =5.5v at 20mhz (i/o high) i idle2 - 20 25 ma v dd =5.5v at 20mhz (i/o low) v dd =3.0v at 20mhz (i/o high) i idle3 - 9 14 ma v dd =3.0v at 20mhz (i/o low) idle current i idle4 - 8 11 ma v dd =2.7v at 20mhz power down current i pwdn - - 10 ua v dd =2.7v~5.5v v dd =5.5v input current p1, p2, p3, p4, p5 i in1 -95 -55 10 ua v in =0v or v dd v dd =5.5v input current rst i in2 -10 50 300 ua 0 preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 187 - revision a4.0 dc characteristics, continued specification parameter symbol min typ max unit test conditions i sr11 -22 -31 -42 v dd = 4.5v, v s = 2.4v source current p2.0~p2.5, p5.0~p5.1 (push-pull mode) pwm pins i sr12 -6 -9 -13 ma v dd = 2.7v, v s = 2.0v i sr21 -200 -300 -430 v dd = 4.5v, v s = 2.4v source current p1, p2, p3, p4, p5 (quasi- bidirectional mode) i sr22 -50 -82 -115 ua v dd =2.7v, v s = 2.0v i sk11 18 22 32 v dd = 4.5v, v s = 0.45v sink current p2.0~p2.5, p5.0~p5.1 (push-pull mode) i sk12 10 15 25 ma v dd = 2.7v, v s = 0.45v i sk21 4 5 6 v dd = 4.5v, v s = 0.45v sink current p0,p1,p2, p3,p4,p5 (quasi- bidirectional mode) i sk22 3 3.5 5 ma v dd = 2.7v, v s = 0.45v v ol11 - 0.35 - v dd = 4.5v, i ol = 20 ma output low voltage p2.0~p2.5, p5.0~p5.1 (push-pull mode) v ol12 - 0.07 - v v dd = 2.7v, i ol = 3.2 ma v ol21 - 0.35 - v dd = 4.5v, i ol = 4.0 ma output low voltage p0, p1, p2, p3, p4, p5 (quasi-bidirectional mode) v ol22 - 0.35 - v v dd = 2.7v, i ol = 3.0 ma v oh11 - 3.3 - v dd = 4.5v, i oh = -20ma output high voltage p2.0~p2.5, p5.0~p5.1 (push-pull mode) v oh12 - 2.5 - v v dd = 2.7v, i oh =-3.2ma v oh21 - 4.1 - v dd = 4.5v, i oh =-100ua output high voltage p1, p2, p3, p4, p5, p6, p7 (quasi-bidirectional mode) v oh22 - 2.52 - v v dd = 2.7v, i oh = -30ua isk31 3 5 8 ma v dd =4.5v, vs = 0.45v sink current [*2] p0, p2, ale, /psen isk32 2.5 3.5 6 ma v dd =2.7v, vs = 0.45v isr31 -6 -7.5 -9 ma v dd =4.5v, vs = 2.4v source current [*2] p0, p2, ale, /psen isr32 -1 -2 -3 ma v dd =2.7v, vs = 2.0v notes: *1. rst pin is a schmitt trigger input. rs t has internal pull-low resistors about 60k . *2. p0, p2, ale and /psen are tested in the external access mode. *3. xtal1 is a cmos input. *4. pins of p1, p2, p3, p4, p5 can source a transition current when they are being externally driven from 1 to 0. the transition current reaches its maximum value when vin approximates to 2v.
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 188 - revision a4.0 24.3 ac characteristics t clcl t clcx t chc x t clch t chcl $mpdl  note: duty cycle is 50%. 24.3.1 external clo ck characteristics parameter symbol min. typ. max. units notes clock high time t chcx 12 - - ns clock low time t clcx 12 - - ns clock rise time t clch - - 10 ns clock fall time t chcl - - 10 ns 24.3.2 ac specification (v dd ? v ss = 5v 10%, ta = 25 c, fosc = 20 mhz, unless otherwise specified.) parameter symbol variable clock min. variable clock max. units oscillator frequency 1/t clcl 0 40 1 mhz oscillator frequency 1/t clcl 0 24 2 mhz ale pulse width t lhll 1.5t clcl - 5 ns address valid to ale low t avll 0.5t clcl - 5 ns address hold after ale low t llax1 0.5t clcl - 5 ns address hold after ale low for movx write t llax2 0.5t clcl - 5 ns ale low to valid instruction in t lliv 2.5t clcl - 20 ns ale low to psen low t llpl 0.5t clcl - 5 ns psen pulse width t plph 2.0t clcl - 5 ns psen low to valid instruction in t pliv 2.0t clcl - 20 ns input instruction hold after psen t pxix 0 ns input instruction float after psen t pxiz t clcl - 5 ns port 0 address to valid instr. in t aviv1 3.0t clcl - 20 ns
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 189 - revision a4.0 ac specification, continued parameter symbol variable clock min. variable clock max. units port 2 address to valid instr. in t aviv2 3.5t clcl - 20 ns psen low to address float t plaz 0 ns data hold after read t rhdx 0 ns data float after read t rhdz t clcl - 5 ns rd low to address float t rlaz 0.5t clcl - 5 ns note: 1. cpu executes the program stored in the internal apflash at v dd =5.0v 2. cpu executes the program stored in the external memory at v dd =5.0v 24.3.3 movx characteristics using stretch memory cycle parameter symbol variable clock min. variable clock max. units strech data access ale pulse width t llhl2 1.5t clcl - 5 2.0t clcl - 5 ns t mcs = 0 t mcs >0 address hold after ale low for movx write t llax2 0.5t clcl - 5 ns rd pulse width t rlrh 2.0t clcl - 5 t mcs - 10 ns t mcs = 0 t mcs >0 wr pulse width t wlwh 2.0t clcl - 5 t mcs - 10 ns t mcs = 0 t mcs >0 rd low to valid data in t rldv 2.0t clcl - 20 t mcs - 20 ns t mcs = 0 t mcs >0 data hold after read t rhdx 0 ns data float after read t rhdz t clcl - 5 2.0t clcl - 5 ns t mcs = 0 t mcs >0 ale low to valid data in t lldv 2.5t clcl - 5 t mcs + 2t clcl - 40 ns t mcs = 0 t mcs >0 port 0 address to valid data in t avdv1 3.0t clcl - 20 2.0t clcl - 5 ns t mcs = 0 t mcs >0 ale low to rd or wr low t llwl 0.5t clcl - 5 1.5t clcl - 5 0.5t clcl + 5 1.5t clcl + 5 ns t mcs = 0 t mcs >0 port 0 address to rd or wr low t avwl t clcl - 5 2.0t clcl - 5 ns t mcs = 0 t mcs >0
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 190 - revision a4.0 movx characteristics using stretch memory cycle, continud parameter symbol variable clock min. variable clock max. units strech port 2 address to rd or wr low t avwl2 1.5t clcl - 5 2.5t clcl - 5 ns t mcs = 0 t mcs >0 data valid to wr transition t qvwx -5 1.0t clcl - 5 ns t mcs = 0 t mcs >0 data hold after write t whqx t clcl - 5 2.0t clcl - 5 ns t mcs = 0 t mcs >0 rd low to address float t rlaz 0.5t clcl - 5 ns rd or wr high to ale high t whlh 0 1.0t clcl - 5 10 1.0t clcl + 5 ns t mcs = 0 t mcs >0 note: t mcs is a time period related to the stretch memory cycle se lection. the following table shows the time period of t mcs for each selection of the stretch value. m2 m1 m0 movx cycles t mcs 0 0 0 2 machine cycles 0 0 0 1 3 machine cycles 4 t clcl 0 1 0 4 machine cycles 8 t clcl 0 1 1 5 machine cycles 12 t clcl 1 0 0 6 machine cycles 16 t clcl 1 0 1 7 machine cycles 20 t clcl 1 1 0 8 machine cycles 24 t clcl 1 1 1 9 machine cycles 28 t clcl explanation of logics symbols in order to maintain compatibility with the orig inal 8051 family, this device specifies the same parameter for each device, using the same symbols. the explanation of the symbols is as follows. t time a address c clock d input data h logic level high l logic level low i instruction p psen q output data r rd signal v valid w wr signal x no longer a valid state z tri-state
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 191 - revision a4.0 24.4 the adc converter dc electrical characteristics (v dd ? v ss = 3.0~5v 10%, t a = -40~85 c, fosc = 20mhz, unless otherwise specified.) specification parameter symbol min. typ. max. unit analog input avin v ss -0.2 v dd +0.2 v adc clock adcclk 200khz - 5mhz hz conversion time t c 52t adc 1 us differential non-linearity dnl -1 - +1 lsb integral non-linearity inl -2 - +2 lsb offset error ofe -1 - +1 lsb gain error ge -1 - +1 % absolute voltage erro r ae -3 - +3 lsb notes: 1. t adc : the period time of adc input clock. 24.5 i2c bus timing characteristics standard mode i2c bus parameter symbol min. max. unit scl clock frequency f scl 0 100 khz bus free time between a stop and start condition t buf 4.7 - us hold time (repeated) start condition. after this period, the first clock pulse is generated t hd;sta 4.0 - us low period of the scl clock t low 4.7 - us high period of the scl clock t high 4.0 - us set-up time for a repeated start condition t su;sta 4.7 - us data hold time t hd;dat 5.0 - us data set-up time t su;dat 250 - ns rise time of both sda and scl signals t r - 1000 ns fall time of both sda and scl signals t f - 300 ns set-up time for stop condition t su;sto 4.0 - us capacitive load for each bus line c b - 400 pf
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 192 - revision a4.0 t buf stop sda scl start t hd;sta t low t hd;dat t high t f t su;dat repeated start t su;sta t su;sto stop t r figure 24-1: i2c bus timing 24.6 program memory read cycle t llax1 t pxiz t plaz t llpl t pxix t pliv t aviv2 t aviv1 t plph t avll address a8-a15 address a8-a15 address a0-a7 instruction in address a0-a7 port 2 port 0 psen ale t lliv t lhll 
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 193 - revision a4.0 24.7 data memory read cycle t avll t avwl1 t llax1 t whlh t rldv t rlrh t rlaz t rhdz t rhdx t avdv2 t avdv1 t llwl address a8-a15 address a0-a7 instruction in data in address a0-a7 port 2 port 0 psen rd ale t lldv  24.8 data memory write cycle t avll t avwl1 t llax2 t whlh t wlwh t qvwx t whqx t avdv2 t llwl address a8-a15 address a0-a7 instruction in data out address a0-a7 port 2 port 0 psen wr ale 
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 194 - revision a4.0 25. typical application circuits 25.1 expanded external program memory and crystal vcc vcc ad13 a15 a5 ad3 ad5 ad7 ad4 ad4 a3 a11 a1 ad0 a6 ad5 ad1 ad3 a12 ad1 a2 ad1 a7 a2 ad5 ad6 a5 ad14 ad0 ad10 ad2 ad0 a13 a8 a3 a6 ad15 ad2 ad7 ad11 ad2 a9 ad9 ad6 a7 a14 ad4 a4 ad8 a0 ad6 ad7 ad3 a10 ad12 a0 a1 a4 pin-diagram of standard 8051 ea/vp x1 x2 reset int0 int1 t0 t1 p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 p0.0 p0.1 p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7 rd wr psen ale/p txd rxd 74f373 d0 3 q0 2 d1 4 q1 5 d2 7 q2 6 d3 8 q3 9 d4 13 q4 12 d5 14 q5 15 d6 17 q6 16 d7 18 q7 19 oc 1 g 11 8.2k c2 c1 cry stal 27512 a0 10 a1 9 a2 8 a3 7 a4 6 a5 5 a6 4 a7 3 a8 25 a9 24 a10 21 a11 23 a12 2 a13 26 a14 27 a15 1 ce 20 oe 22 o0 11 o1 12 o2 13 o3 15 o4 16 o5 17 o6 18 o7 19 10u r figure 25-1: typical external program memory and crystal connections crystal c1 c2 r 16 mhz 0p~20p 0p~20p - 24 mhz 0p~12p 0p~12p - 33 mhz 10p 10p 10k~5.1k 40 mhz 1p 1p 10k~5.1k the above table shows the reference values for crystal applications. note: c1, c2, r components refer to figure above. 25.2 expanded external data memory and oscillator vcc vcc vcc oscillator ad0 ad3 ad3 a10 a4 ad5 a6 ad4 a1 ad1 a11 a5 a0 ad4 ad7 ad9 ad7 a7 ad6 ad12 a2 ad1 ad7 ad2 a6 ad5 a12 ad6 a8 a1 ad6 ad1 a3 ad0 ad14 ad10 a13 ad3 a2 a7 ad0 ad5 a4 a9 ad8 ad4 a14 a3 ad2 ad13 a5 ad11 a0 ad2 20256 cs 20 oe 22 we 27 i/o0 11 i/o1 12 i/o2 13 i/o3 15 i/o4 16 i/o5 17 i/o6 18 i/o7 19 a0 10 a1 9 a2 8 a3 7 a4 6 a5 5 a6 4 a7 3 a8 25 a9 24 a10 21 a11 23 a12 2 a13 26 a14 1 vcc 28 pin-diagram of standard 8051 ea/vp x1 x2 reset int0 int1 t0 t1 p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 p0.0 p0.1 p0.2 p0.3 p0.4 p0.5 p0.6 p0.7 p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7 rd wr psen ale/p txd rxd 74f373 d0 3 q0 2 d1 4 q1 5 d2 7 q2 6 d3 8 q3 9 d4 13 q4 12 d5 14 q5 15 d6 17 q6 16 d7 18 q7 19 oc 1 g 11 10u 8.2k figure 25-2: typical external data memory and oscillator connections
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 195 - revision a4.0 26. package dimension 26.1 44l plcc 44 40 39 29 28 18 17 7 61 l c 1 b 2 a h d d e b eh e y a a 1 seating plane d g g e symbol min nom max max nom min dimension in inch dimension in mm a b c d e h e l y a a 1 2 e b 1 h d g g d e 0.020 0.145 0.026 0.016 0.008 0.648 0.590 0.680 0.090 0.150 0.028 0.018 0.010 0.653 0.610 0.690 0.100 0.050 bsc 0.185 0.155 0.032 0.022 0.014 0.658 0.630 0.700 0.110 0.004 0.51 3.68 0.66 0.41 0.20 16.46 14.99 17.27 2.29 3.81 0.71 0.46 0.25 16.59 15.49 17.53 2.54 1.27 4.70 3.94 0.81 0.56 0.36 16.71 16.00 17.78 2.79 0.10 bsc 16.71 16.59 16.46 0.658 0.653 0.648 16.00 15.49 14.99 0.630 0.610 0.590 17.78 17.53 17.27 0.700 0.690 0.680
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 196 - revision a4.0 26.2 48l lqfp (7x7x1.4mm footprint 2.0mm)
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 197 - revision a4.0 27. application note in-system programming software examples this application note illustrates the in-system programmability of the winbond w79e22x series flash eprom microcontroller. in this ex ample, microcontroller will boot from "1'mbti bank and waiting for a key to enter in-system programming mode for re-programming the contents of 64 kb apflash. while entering in-system programming mode, micr ocontroller executes the loader program in 4kb ldflash bank. the loader program erases the 64 kb apflash then reads the new code data from external sram buffer (or through other interfaces) to update the apflash. if the customer uses the reboot mode to update his pr ogram, please enable this b3 or b4 of security bits from the writer. please refer se curity bits for detail description. example 1: ;******************************************************************************************************************* ;* example of apflash program: program will scan the p1.0. if p1.0 = 0, enters in-system ;* programming mode for updating the content of apfl ash code else executes the current rom code. ;* xtal = 24 mhz ;******************************************************************************************************************* .chip 8052 .ramchk off .symbols chpcon equ 9fh ta equ c7h sfral equ ach sfrah equ adh sfrfd equ aeh sfrcn equ afh org 0h ljmp 100h ; jump to main program ;************************************************************************ ;* timer0 service vector org = 000bh ;************************************************************************ org 00bh clr tr0 ; tr0 = 0, stop timer0 mov tl0, r6 mov th0,r7 reti ;************************************************************************ ;* apflash main program ;************************************************************************ org 100h
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 198 - revision a4.0 main_apflash: mov a, p1 ; scan p1.0 anl a, #01h cjne a, #01h, program_apflash ; if p1.0 = 0, enter in-system programming mode jmp normal_mode program_64: mov ta, #aah ; chpcon register is written protect by ta register. mov ta, #55h mov chpcon, #03h ; chpcon = 03h, enter in-system programming mode mov sfrcn, #0h mov tcon, #00h ; tr = 0 timer0 stop mov ip, #00h ; ip = 00h mov ie, #82h ; timer0 interrupt enable for wake-up from idle mode mov r6, #f0h ; tl0 = f0h mov r7, #ffh ; th0 = ffh mov tl0, r6 mov th0, r7 mov tmod, #01h ; tmod = 01h, set timer0 a 16-bit timer mov tcon, #10h ; tcon = 10h, tr0 = 1, go mov pcon, #01h ; enter idle mo de for launching the in-system programming ;************** ****************************************************************** ;* normal mode apflashb apflash program: depending user's application ;******************************************************************************** normal_mode: . ; user's application program . . . example 2: ;******************************************************************************************************************* ;* example of 4kb ldflash program: this loader program will erase the apflashb apflash first, then reads the new ;* code from external sram and program them into apflashb apflash bank. xtal = 24 mhz ;******************************************************************************************************************* .chip 8052 .ramchk off .symbols
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 199 - revision a4.0 chpcon equ 9fh ta equ c7h sfral equ ach sfrah equ adh sfrfd equ aeh sfrcn equ afh org 000h ljmp 100h ; jump to main program ;************************************************************************ ;* 1. timer0 service vector org = 0bh ;************************************************************************ org 000b clr tr0 ; tr0 = 0, stop timer0 mov tl0, r6 mov th0, r7 reti ;************************************************************************ ;* 4kb ldflash main program ;************************************************************************ org 100h main_4k: mov ta, #aah mov ta, #55h mov chpcon, #03h ; chpcon = 03h, enable in-system programming. mov sfrcn, #0h mov tcon, #00h ; tcon = 00h, tr = 0 timer0 stop mov tmod, #01h ; tmod = 01h, set timer0 a 16bit timer mov ip, #00h ; ip = 00h mov ie, #82h ; ie = 82h, timer0 interrupt enabled mov r6, #f0h mov r7, #ffh mov tl0, r6 mov th0, r7 mov tcon, #10h ; tcon = 10h, tr0 = 1, go mov pcon, #01h ; enter idle mode update_apflash: mov tcon, #00h ; tcon = 00h, tr = 0 tim0 stop
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 200 - revision a4.0 mov ip, #00h ; ip = 00h mov ie, #82h ; ie = 82h, timer0 interrupt enabled mov tmod, #01h ; tmod = 01h, mode1 mov r6,#d0h ; set wake-up time for er ase operation, about 15 ms depending on user's system clock rate. mov r7, #8ah mov tl0, r6 mov th0, r7 erase_p_4k: mov sfrcn, #22h ; sfrcn = 22h, erase apflash apflash0 ; sfrcn = a2h, erase apflash1 mov tcon, #10h ; tcon = 10h, tr0 = 1, go mov pcon, #01h ; enter idle mode (for erase operation) ;********************************************************************* ;* blank check ;********************************************************************* mov sfrcn, #0h ; sfrcn = 00h, read apflashb apflash0 ; sfrcn = 80h, read apflashb apflash1 mov sfrah, #0h ; start address = 0h mov sfral, #0h mov r6, #fdh ; set timer for read operation, about 1.5 s. mov r7, #ffh mov tl0, r6 mov th0, r7 blank_check_loop: setb tr0 ; enable timer 0 mov pcon, #01h ; enter idle mode mov a, sfrfd ; read one byte cjne a, #ffh, blank_check_error inc sfral ; next address mov a, sfral jnz blank_check_loop inc sfrah mov a, sfrah cjne a, #0h, blank_check_loop ; end address = ffffh jmp program_apflashrom blank_check_error: jmp $
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 201 - revision a4.0 ;******************************************************************************* ;* re-programming apflashb apflash bank ;******************************************************************************* program_apflashrom: mov r2, #00h ; target low byte address mov r1, #00h ; target high byte address mov dptr, #0h mov sfrah, r1 ; sfrah, target high address mov sfrcn, #21h ; sfrcn = 21h, program apflash0 ; sfrcn = a1h, program apflash1 mov r6, #9ch ; set timer for programming, about 50 s. mov r7, #ffh mov tl0, r6 mov th0, r7 prog_d_apflash: mov sfral, r2 ; sfral = low byte address call get_byte_from_pc_to_acc ; th is program is based on user?s circuit. mov @dptr, a ; save data into sram to verify code. mov sfrfd, a ; sfrfd = data in mov tcon, #10h ; tcon = 10h, tr0 = 1,go mov pcon, #01h ; enter idle mode (prorgamming) inc dptr inc r2 cjne r2, #0h, prog_d_apflash inc r1 mov sfrah, r1 cjne r1, #0h, prog_d_apflash ;***************************************************************************** ; * verify apflashb apflash bank ;***************************************************************************** mov r4, #03h ; error counter mov r6, #fdh ; set timer for read verify, about 1.5 s. mov r7, #ffh mov tl0, r6 mov th0, r7 mov dptr, #0h ; the start address of sample code mov r2, #0h ; target low byte address mov r1, #0h ; target high byte address
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 202 - revision a4.0 mov sfrah, r1 ; sfrah, target high address mov sfrcn, #00h ; sfrcn = 00h, read apflash0 ; sfrcn = 80h, read apflash1 read_verify_apflash: mov sfral,r2 ; sfral = low address mov tcon,#10h ; tcon = 10h, tr0 = 1,go mov pcon,#01h inc r2 movx a,@dptr inc dptr cjne a,sfrfd,error_apflash cjne r2,#0h,read_verify_apflash inc r1 mov sfrah,r1 cjne r1,#0h,read_verify_apflash ;****************************************************************************** ;* programming completly, software reset cpu ;****************************************************************************** mov ta, #aah mov ta, #55h mov chpcon, #83h ; software rese t. cpu will restart from apflash0 error_apflash: djnz r4, update_apflash ; if error occurs, repeat 3 times. . ; in-syst programming fail, user's process to deal with it. . . .
preliminary w79e225a/226a/227a data sheet publication release date: april 15, 2008 - 203 - revision a4.0 28. revision history revision date page description a1.0 october 18, 2007 - preliminary version initially issued a1.1 november 17, 2007 8,9 182 7 111 incorrect pin number format. re-alignment. operating voltage for nvm program/erase min at 3.0v. a dded note for minimum nvm program/erase operating voltage. updated figure 14-8. changed label ?b? to ?c?. a2.0 december 11, 2007 8, 137, 138 99, 100 111 182 35 removed indx descriptions. updated diagram for t2ex at p4.1 pin. updated diagram. posc replaced with fosc. revise the operating temperature to (-40, +85) c revise the content of uart mode select table. (sm0,sm1) is exchanged. a3.0 march 17, 2008 141 6, 7 1. modified uart descriptions. 2. add two parts of w79e226 series a4.0 april 15, 2008 68 modified cpha descriptions. important notice winbond products are not designed, intended, authorized or warranted for use as components in systems or equipment intended for surg ical implantation, at omic energy control instruments, airplane or spaceship instruments, transportation instruments, traffic signal instruments, combustion control instruments, or for other applications intended to support or sustain life. further more, winbond products are not intended for applications wherein failure of winbond products could result or lead to a situation wherein personal injury, death or severe property or environmental damage could occur. winbond customers using or selling these products fo r use in such applications do so at their own risk and agree to fully indemnify winbond for any damages resulting from such improper use or sales.


▲Up To Search▲   

 
Price & Availability of W79E227AFG

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]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X